1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-21 21:30:12 +00:00

Update cockpit camera view selection

This commit is contained in:
hawkeye 2024-02-28 19:54:25 -05:00
parent e088033eb3
commit b2ca626439
7 changed files with 56 additions and 15 deletions

View file

@ -2,6 +2,7 @@
using MSFSPopoutPanelManager.Shared; using MSFSPopoutPanelManager.Shared;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using MSFSPopoutPanelManager.SimConnectAgent;
namespace MSFSPopoutPanelManager.Orchestration namespace MSFSPopoutPanelManager.Orchestration
{ {
@ -28,7 +29,7 @@ namespace MSFSPopoutPanelManager.Orchestration
public bool TrackIRStatus { get; set; } public bool TrackIRStatus { get; set; }
public int CameraState { get; set; } public CameraState CameraState { get; set; }
public int CockpitCameraZoom { get; set; } public int CockpitCameraZoom { get; set; }
@ -82,7 +83,7 @@ namespace MSFSPopoutPanelManager.Orchestration
TrackIRStatus = false; TrackIRStatus = false;
IsInCockpit = false; IsInCockpit = false;
PlaneInParkingSpot = false; PlaneInParkingSpot = false;
CameraState = -1; CameraState = CameraState.Unknown;
IsSimulatorStarted = false; IsSimulatorStarted = false;
PlaneAltAboveGround = 0; PlaneAltAboveGround = 0;
CameraViewTypeAndIndex1Max = 0; CameraViewTypeAndIndex1Max = 0;

View file

@ -71,6 +71,13 @@ namespace MSFSPopoutPanelManager.Orchestration
if (trackIR != FlightSimData.TrackIRStatus) if (trackIR != FlightSimData.TrackIRStatus)
FlightSimData.TrackIRStatus = trackIR; FlightSimData.TrackIRStatus = trackIR;
var cameraStateInt = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraState).Value);
var result = Enum.TryParse<CameraState>(cameraStateInt.ToString(), out var cameraState);
if (!result)
cameraState = CameraState.Unknown;
if (cameraState != FlightSimData.CameraState)
FlightSimData.CameraState = cameraState;
var cockpitCameraZoom = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CockpitCameraZoom).Value); var cockpitCameraZoom = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CockpitCameraZoom).Value);
if (cockpitCameraZoom != FlightSimData.CockpitCameraZoom) if (cockpitCameraZoom != FlightSimData.CockpitCameraZoom)
FlightSimData.CockpitCameraZoom = cockpitCameraZoom; FlightSimData.CockpitCameraZoom = cockpitCameraZoom;
@ -339,6 +346,14 @@ namespace MSFSPopoutPanelManager.Orchestration
public void SetFixedCamera(CameraType cameraType, int index) public void SetFixedCamera(CameraType cameraType, int index)
{ {
if (FlightSimData.CameraState != CameraState.Cockpit)
{
_simConnectProvider.SetCameraState(CameraState.Cockpit);
Thread.Sleep(250);
ResetCameraView();
Thread.Sleep(250);
}
_simConnectProvider.SetCameraViewTypeAndIndex0(Convert.ToInt32(cameraType)); _simConnectProvider.SetCameraViewTypeAndIndex0(Convert.ToInt32(cameraType));
Thread.Sleep(250); Thread.Sleep(250);
_simConnectProvider.SetCameraViewTypeAndIndex1(index); _simConnectProvider.SetCameraViewTypeAndIndex1(index);

View file

@ -0,0 +1,12 @@
namespace MSFSPopoutPanelManager.SimConnectAgent
{
public enum CameraState
{
Cockpit = 2,
External = 3,
Drone = 4,
LoadScreen = 11,
HomeScreen = 15,
Unknown = 0
}
}

View file

@ -6,6 +6,7 @@
HUDBAR_DEFINITION, HUDBAR_DEFINITION,
WRITABLE_TRACK_IR_DEFINITION, WRITABLE_TRACK_IR_DEFINITION,
WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION, WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION,
WRITABLE_COCKPIT_CAMERA_STATE_DEFINITION,
WRITABLE_CAMERA_REQUEST_ACTION_DEFINITION, WRITABLE_CAMERA_REQUEST_ACTION_DEFINITION,
WRITABLE_CAMERA_VIEW_TYPE_INDEX_0_DEFINITION, WRITABLE_CAMERA_VIEW_TYPE_INDEX_0_DEFINITION,
WRITABLE_CAMERA_VIEW_TYPE_INDEX_1_DEFINITION, WRITABLE_CAMERA_VIEW_TYPE_INDEX_1_DEFINITION,

View file

@ -227,6 +227,11 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
Thread.Sleep(200); Thread.Sleep(200);
} }
public void SetCameraState(CameraState cameraState)
{
_simConnector.SetDataObject(WritableVariableName.CameraState, Convert.ToDouble(cameraState));
}
public void SetCockpitCameraZoomLevel(int zoomLevel) public void SetCockpitCameraZoomLevel(int zoomLevel)
{ {
_simConnector.SetDataObject(WritableVariableName.CockpitCameraZoom, Convert.ToDouble(zoomLevel)); _simConnector.SetDataObject(WritableVariableName.CockpitCameraZoom, Convert.ToDouble(zoomLevel));
@ -332,35 +337,37 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
OnSimConnectDataHudBarRefreshed?.Invoke(this, e); OnSimConnectDataHudBarRefreshed?.Invoke(this, e);
} }
private const int CAMERA_STATE_COCKPIT = 2; private CameraState _currentCameraState = CameraState.Unknown;
private const int CAMERA_STATE_LOAD_SCREEN = 11;
private const int CAMERA_STATE_HOME_SCREEN = 15;
private int _currentCameraState = -1;
private void DetectFlightStartedOrStopped(List<SimDataItem> simData) private void DetectFlightStartedOrStopped(List<SimDataItem> simData)
{ {
// Determine is flight started or ended // Determine is flight started or ended
var cameraState = Convert.ToInt32(simData.Find(d => d.PropertyName == PropName.CameraState).Value); var cameraStateInt = Convert.ToInt32(simData.Find(d => d.PropertyName == PropName.CameraState).Value);
var success = Enum.TryParse<CameraState>(cameraStateInt.ToString(), out var cameraState);
if(!success)
cameraState = CameraState.Unknown;
if (_currentCameraState == cameraState) if (_currentCameraState == cameraState)
return; return;
if (cameraState == CAMERA_STATE_COCKPIT) if (cameraState == CameraState.Cockpit)
OnIsInCockpitChanged?.Invoke(this, true); OnIsInCockpitChanged?.Invoke(this, true);
switch (_currentCameraState) switch (_currentCameraState)
{ {
case CAMERA_STATE_HOME_SCREEN: case CameraState.HomeScreen:
case CAMERA_STATE_LOAD_SCREEN: case CameraState.LoadScreen:
if (cameraState == CAMERA_STATE_COCKPIT) if (cameraState == CameraState.Cockpit)
{ {
_currentCameraState = cameraState; _currentCameraState = cameraState;
OnFlightStarted?.Invoke(this, EventArgs.Empty); OnFlightStarted?.Invoke(this, EventArgs.Empty);
} }
break; break;
case CAMERA_STATE_COCKPIT: case CameraState.Cockpit:
if (cameraState == CAMERA_STATE_LOAD_SCREEN || cameraState == CAMERA_STATE_HOME_SCREEN) if (cameraState == CameraState.LoadScreen || cameraState == CameraState.HomeScreen)
{ {
_currentCameraState = cameraState; _currentCameraState = cameraState;
OnFlightStopped?.Invoke(this, EventArgs.Empty); OnFlightStopped?.Invoke(this, EventArgs.Empty);
@ -369,11 +376,10 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
_isHudBarDataActive = false; _isHudBarDataActive = false;
_hudBarRequestDataTimer.Stop(); _hudBarRequestDataTimer.Stop();
} }
break; break;
} }
if (cameraState is CAMERA_STATE_COCKPIT or CAMERA_STATE_HOME_SCREEN or CAMERA_STATE_LOAD_SCREEN) if (cameraState is CameraState.Cockpit or CameraState.HomeScreen or CameraState.LoadScreen)
_currentCameraState = cameraState; _currentCameraState = cameraState;
} }

View file

@ -188,6 +188,9 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
case WritableVariableName.CockpitCameraZoom: case WritableVariableName.CockpitCameraZoom:
_simConnect.SetDataOnSimObject(DataDefinition.WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct); _simConnect.SetDataOnSimObject(DataDefinition.WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct);
break; break;
case WritableVariableName.CameraState:
_simConnect.SetDataOnSimObject(DataDefinition.WRITABLE_COCKPIT_CAMERA_STATE_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct);
break;
case WritableVariableName.CameraRequestAction: case WritableVariableName.CameraRequestAction:
_simConnect.SetDataOnSimObject(DataDefinition.WRITABLE_CAMERA_REQUEST_ACTION_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct); _simConnect.SetDataOnSimObject(DataDefinition.WRITABLE_CAMERA_REQUEST_ACTION_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct);
break; break;
@ -309,6 +312,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
} }
_simConnect.AddToDataDefinition(DataDefinition.WRITABLE_TRACK_IR_DEFINITION, "TRACK IR ENABLE", "bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.AddToDataDefinition(DataDefinition.WRITABLE_TRACK_IR_DEFINITION, "TRACK IR ENABLE", "bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
_simConnect.AddToDataDefinition(DataDefinition.WRITABLE_COCKPIT_CAMERA_STATE_DEFINITION, "CAMERA STATE", "enum", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
_simConnect.AddToDataDefinition(DataDefinition.WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION, "COCKPIT CAMERA ZOOM", "percentage", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.AddToDataDefinition(DataDefinition.WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION, "COCKPIT CAMERA ZOOM", "percentage", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
_simConnect.AddToDataDefinition(DataDefinition.WRITABLE_CAMERA_REQUEST_ACTION_DEFINITION, "CAMERA REQUEST ACTION", "enum", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.AddToDataDefinition(DataDefinition.WRITABLE_CAMERA_REQUEST_ACTION_DEFINITION, "CAMERA REQUEST ACTION", "enum", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
_simConnect.AddToDataDefinition(DataDefinition.WRITABLE_CAMERA_VIEW_TYPE_INDEX_0_DEFINITION, "CAMERA VIEW TYPE AND INDEX:0", "number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.AddToDataDefinition(DataDefinition.WRITABLE_CAMERA_VIEW_TYPE_INDEX_0_DEFINITION, "CAMERA VIEW TYPE AND INDEX:0", "number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
@ -316,6 +320,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.REQUIRED_DEFINITION); _simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.REQUIRED_DEFINITION);
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_TRACK_IR_DEFINITION); _simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_TRACK_IR_DEFINITION);
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_COCKPIT_CAMERA_STATE_DEFINITION);
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION); _simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION);
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_CAMERA_VIEW_TYPE_INDEX_0_DEFINITION); _simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_CAMERA_VIEW_TYPE_INDEX_0_DEFINITION);
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_CAMERA_VIEW_TYPE_INDEX_1_DEFINITION); _simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_CAMERA_VIEW_TYPE_INDEX_1_DEFINITION);

View file

@ -113,6 +113,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
{ {
TrackIREnable, TrackIREnable,
CockpitCameraZoom, CockpitCameraZoom,
CameraState,
CameraRequestAction, CameraRequestAction,
CameraViewTypeAndIndex0, CameraViewTypeAndIndex0,
CameraViewTypeAndIndex1 CameraViewTypeAndIndex1