mirror of
https://github.com/hawkeye-stan/msfs-popout-panel-manager.git
synced 2024-11-24 06:40:09 +00:00
Update cockpit camera view selection
This commit is contained in:
parent
e088033eb3
commit
b2ca626439
7 changed files with 56 additions and 15 deletions
|
@ -2,6 +2,7 @@
|
|||
using MSFSPopoutPanelManager.Shared;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using MSFSPopoutPanelManager.SimConnectAgent;
|
||||
|
||||
namespace MSFSPopoutPanelManager.Orchestration
|
||||
{
|
||||
|
@ -28,7 +29,7 @@ namespace MSFSPopoutPanelManager.Orchestration
|
|||
|
||||
public bool TrackIRStatus { get; set; }
|
||||
|
||||
public int CameraState { get; set; }
|
||||
public CameraState CameraState { get; set; }
|
||||
|
||||
public int CockpitCameraZoom { get; set; }
|
||||
|
||||
|
@ -82,7 +83,7 @@ namespace MSFSPopoutPanelManager.Orchestration
|
|||
TrackIRStatus = false;
|
||||
IsInCockpit = false;
|
||||
PlaneInParkingSpot = false;
|
||||
CameraState = -1;
|
||||
CameraState = CameraState.Unknown;
|
||||
IsSimulatorStarted = false;
|
||||
PlaneAltAboveGround = 0;
|
||||
CameraViewTypeAndIndex1Max = 0;
|
||||
|
|
|
@ -71,6 +71,13 @@ namespace MSFSPopoutPanelManager.Orchestration
|
|||
if (trackIR != FlightSimData.TrackIRStatus)
|
||||
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);
|
||||
if (cockpitCameraZoom != FlightSimData.CockpitCameraZoom)
|
||||
FlightSimData.CockpitCameraZoom = cockpitCameraZoom;
|
||||
|
@ -339,6 +346,14 @@ namespace MSFSPopoutPanelManager.Orchestration
|
|||
|
||||
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));
|
||||
Thread.Sleep(250);
|
||||
_simConnectProvider.SetCameraViewTypeAndIndex1(index);
|
||||
|
|
12
SimconnectAgent/CameraState.cs
Normal file
12
SimconnectAgent/CameraState.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace MSFSPopoutPanelManager.SimConnectAgent
|
||||
{
|
||||
public enum CameraState
|
||||
{
|
||||
Cockpit = 2,
|
||||
External = 3,
|
||||
Drone = 4,
|
||||
LoadScreen = 11,
|
||||
HomeScreen = 15,
|
||||
Unknown = 0
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
HUDBAR_DEFINITION,
|
||||
WRITABLE_TRACK_IR_DEFINITION,
|
||||
WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION,
|
||||
WRITABLE_COCKPIT_CAMERA_STATE_DEFINITION,
|
||||
WRITABLE_CAMERA_REQUEST_ACTION_DEFINITION,
|
||||
WRITABLE_CAMERA_VIEW_TYPE_INDEX_0_DEFINITION,
|
||||
WRITABLE_CAMERA_VIEW_TYPE_INDEX_1_DEFINITION,
|
||||
|
|
|
@ -227,6 +227,11 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
|
|||
Thread.Sleep(200);
|
||||
}
|
||||
|
||||
public void SetCameraState(CameraState cameraState)
|
||||
{
|
||||
_simConnector.SetDataObject(WritableVariableName.CameraState, Convert.ToDouble(cameraState));
|
||||
}
|
||||
|
||||
public void SetCockpitCameraZoomLevel(int zoomLevel)
|
||||
{
|
||||
_simConnector.SetDataObject(WritableVariableName.CockpitCameraZoom, Convert.ToDouble(zoomLevel));
|
||||
|
@ -332,35 +337,37 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
|
|||
OnSimConnectDataHudBarRefreshed?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private const int CAMERA_STATE_COCKPIT = 2;
|
||||
private const int CAMERA_STATE_LOAD_SCREEN = 11;
|
||||
private const int CAMERA_STATE_HOME_SCREEN = 15;
|
||||
private int _currentCameraState = -1;
|
||||
private CameraState _currentCameraState = CameraState.Unknown;
|
||||
|
||||
private void DetectFlightStartedOrStopped(List<SimDataItem> simData)
|
||||
{
|
||||
// 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)
|
||||
return;
|
||||
|
||||
if (cameraState == CAMERA_STATE_COCKPIT)
|
||||
if (cameraState == CameraState.Cockpit)
|
||||
OnIsInCockpitChanged?.Invoke(this, true);
|
||||
|
||||
|
||||
switch (_currentCameraState)
|
||||
{
|
||||
case CAMERA_STATE_HOME_SCREEN:
|
||||
case CAMERA_STATE_LOAD_SCREEN:
|
||||
if (cameraState == CAMERA_STATE_COCKPIT)
|
||||
case CameraState.HomeScreen:
|
||||
case CameraState.LoadScreen:
|
||||
if (cameraState == CameraState.Cockpit)
|
||||
{
|
||||
_currentCameraState = cameraState;
|
||||
OnFlightStarted?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
break;
|
||||
case CAMERA_STATE_COCKPIT:
|
||||
if (cameraState == CAMERA_STATE_LOAD_SCREEN || cameraState == CAMERA_STATE_HOME_SCREEN)
|
||||
case CameraState.Cockpit:
|
||||
if (cameraState == CameraState.LoadScreen || cameraState == CameraState.HomeScreen)
|
||||
{
|
||||
_currentCameraState = cameraState;
|
||||
OnFlightStopped?.Invoke(this, EventArgs.Empty);
|
||||
|
@ -369,11 +376,10 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
|
|||
_isHudBarDataActive = false;
|
||||
_hudBarRequestDataTimer.Stop();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -188,6 +188,9 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
|
|||
case WritableVariableName.CockpitCameraZoom:
|
||||
_simConnect.SetDataOnSimObject(DataDefinition.WRITABLE_COCKPIT_CAMERA_ZOOM_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct);
|
||||
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:
|
||||
_simConnect.SetDataOnSimObject(DataDefinition.WRITABLE_CAMERA_REQUEST_ACTION_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct);
|
||||
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_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_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);
|
||||
|
@ -316,6 +320,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
|
|||
|
||||
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.REQUIRED_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_CAMERA_VIEW_TYPE_INDEX_0_DEFINITION);
|
||||
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DataDefinition.WRITABLE_CAMERA_VIEW_TYPE_INDEX_1_DEFINITION);
|
||||
|
|
|
@ -113,6 +113,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
|
|||
{
|
||||
TrackIREnable,
|
||||
CockpitCameraZoom,
|
||||
CameraState,
|
||||
CameraRequestAction,
|
||||
CameraViewTypeAndIndex0,
|
||||
CameraViewTypeAndIndex1
|
||||
|
|
Loading…
Reference in a new issue