diff --git a/Source/DCSFlightpanels/DCSFlightpanels.csproj b/Source/DCSFlightpanels/DCSFlightpanels.csproj index 7cef9f071..d266ec535 100644 --- a/Source/DCSFlightpanels/DCSFlightpanels.csproj +++ b/Source/DCSFlightpanels/DCSFlightpanels.csproj @@ -28,7 +28,7 @@ DCSFlightpanels (DCSFP) 1.0.0 - 4.10.2 + 4.10.3 flightpanels02_8Rc_icon.ico diff --git a/Source/DCSFlightpanels/PanelUserControls/StreamDeckUserControl.xaml.cs b/Source/DCSFlightpanels/PanelUserControls/StreamDeckUserControl.xaml.cs index 0809ad4d5..0bf5971e6 100644 --- a/Source/DCSFlightpanels/PanelUserControls/StreamDeckUserControl.xaml.cs +++ b/Source/DCSFlightpanels/PanelUserControls/StreamDeckUserControl.xaml.cs @@ -268,7 +268,7 @@ private void ComboBoxLayers_OnDropDownClosed(object sender, EventArgs e) { return; } - _streamDeckPanel.SelectedLayerName = ComboBoxLayers.Text; + _streamDeckPanel.SwitchToLayer(ComboBoxLayers.Text, true, false); } catch (Exception ex) { diff --git a/Source/NonVisuals/Panels/StreamDeck/ActionTypeLayer.cs b/Source/NonVisuals/Panels/StreamDeck/ActionTypeLayer.cs index 127a8f19c..39205a930 100644 --- a/Source/NonVisuals/Panels/StreamDeck/ActionTypeLayer.cs +++ b/Source/NonVisuals/Panels/StreamDeck/ActionTypeLayer.cs @@ -144,7 +144,7 @@ public void Navigate(CancellationToken threadCancellationToken) case LayerNavType.SwitchToSpecificLayer: { - _streamDeckPanel.SelectedLayerName = TargetLayer; + _streamDeckPanel.SwitchToLayer(TargetLayer, true, false); break; } } diff --git a/Source/NonVisuals/Panels/StreamDeck/Events/SDEventHandler.cs b/Source/NonVisuals/Panels/StreamDeck/Events/SDEventHandler.cs index e937e258c..baf0c6ef9 100644 --- a/Source/NonVisuals/Panels/StreamDeck/Events/SDEventHandler.cs +++ b/Source/NonVisuals/Panels/StreamDeck/Events/SDEventHandler.cs @@ -155,9 +155,9 @@ public static bool OnStreamDeckShowNewLayerEventSubscribed() return OnStreamDeckShowNewLayerEventHandler != null && OnStreamDeckShowNewLayerEventHandler.GetInvocationList().Length > 0; } - public static void LayerSwitched(object sender, string bindingHash, string layerName) + public static void LayerSwitched(object sender, string bindingHash, string layerName, bool switchedByUser, bool remotelySwitched) { - var eventArgs = new StreamDeckShowNewLayerArgs { SelectedLayerName = layerName, BindingHash = bindingHash }; + var eventArgs = new StreamDeckShowNewLayerArgs { SelectedLayerName = layerName, BindingHash = bindingHash, SwitchedByUser = switchedByUser, RemotelySwitched = remotelySwitched}; OnStreamDeckShowNewLayerEventHandler?.Invoke(sender, eventArgs); } diff --git a/Source/NonVisuals/Panels/StreamDeck/Events/StreamDeckPanelEvents.cs b/Source/NonVisuals/Panels/StreamDeck/Events/StreamDeckPanelEvents.cs index 5a0866b68..998cfcc48 100644 --- a/Source/NonVisuals/Panels/StreamDeck/Events/StreamDeckPanelEvents.cs +++ b/Source/NonVisuals/Panels/StreamDeck/Events/StreamDeckPanelEvents.cs @@ -40,6 +40,8 @@ public class StreamDeckShowNewLayerArgs : EventArgs */ public string BindingHash { get; init; } public string SelectedLayerName { get; init; } + public bool SwitchedByUser { get; init; } + public bool RemotelySwitched { get; init; } } public class RemoteStreamDeckShowNewLayerArgs : EventArgs diff --git a/Source/NonVisuals/Panels/StreamDeck/Panels/StreamDeckPanel.cs b/Source/NonVisuals/Panels/StreamDeck/Panels/StreamDeckPanel.cs index a512452a5..39c318c52 100644 --- a/Source/NonVisuals/Panels/StreamDeck/Panels/StreamDeckPanel.cs +++ b/Source/NonVisuals/Panels/StreamDeck/Panels/StreamDeckPanel.cs @@ -48,7 +48,11 @@ public class StreamDeckPanel : GamingPanel, INvStreamDeckListener, IStreamDeckCo public string SelectedLayerName { get => _streamDeckLayerHandler.SelectedLayerName; - set => _streamDeckLayerHandler.SelectedLayerName = value; + } + + public void SwitchToLayer(string layerName, bool switchedByUser, bool remotelySwitched) + { + _streamDeckLayerHandler.SwitchToLayer(layerName, switchedByUser, remotelySwitched); } public List LayerNameList @@ -69,7 +73,6 @@ public StreamDeckLayer HomeLayer public StreamDeckLayer SelectedLayer { get => _streamDeckLayerHandler.SelectedLayer; - set => _streamDeckLayerHandler.SelectedLayer = value; } public bool HasLayers @@ -445,9 +448,10 @@ public void LayerSwitched(object sender, StreamDeckShowNewLayerArgs e) { try { - _layerSwitched = true; - if (BindingHash == e.BindingHash) - { } + if (BindingHash == e.BindingHash && !e.RemotelySwitched && e.SwitchedByUser) + { + _layerSwitched = true; + } } catch (Exception ex) { @@ -461,7 +465,7 @@ public void RemoteLayerSwitch(object sender, RemoteStreamDeckShowNewLayerArgs e) { if (e.RemoteBindingHash == BindingHash && _streamDeckLayerHandler.LayerExists(e.SelectedLayerName)) { - _streamDeckLayerHandler.SelectedLayerName = e.SelectedLayerName; + _streamDeckLayerHandler.SwitchToLayer(e.SelectedLayerName, true, true); } } catch (Exception ex) diff --git a/Source/NonVisuals/Panels/StreamDeck/StreamDeckLayerHandler.cs b/Source/NonVisuals/Panels/StreamDeck/StreamDeckLayerHandler.cs index 5d7d5cfaf..c2ea459fd 100644 --- a/Source/NonVisuals/Panels/StreamDeck/StreamDeckLayerHandler.cs +++ b/Source/NonVisuals/Panels/StreamDeck/StreamDeckLayerHandler.cs @@ -16,6 +16,7 @@ namespace NonVisuals.Panels.StreamDeck using Events; using Panels; + using Newtonsoft.Json.Linq; public class StreamDeckLayerHandler : IDisposable { @@ -84,8 +85,6 @@ public StreamDeckLayer SelectedLayer CheckHomeLayerExists(); return GetLayer(_selectedLayerName); } - - set => SetSelectedLayer(value.Name); } @@ -174,15 +173,15 @@ private void CheckHomeLayerExists() CheckSelectedLayer(); } - public void CheckSelectedLayer() + private void CheckSelectedLayer() { if (!string.IsNullOrEmpty(_selectedLayerName) && _layerList.FindAll(o => o.Name == _selectedLayerName).Count == 1) { - SetSelectedLayer(_selectedLayerName); + SetSelectedLayer(_selectedLayerName, false, false); } else { - SetSelectedLayer(StreamDeckConstants.HOME_LAYER_NAME); + SetSelectedLayer(StreamDeckConstants.HOME_LAYER_NAME, false, false); } } @@ -198,7 +197,7 @@ public bool AddLayer(StreamDeckLayer streamDeckLayer) LayerList.Add(streamDeckLayer); } - SetSelectedLayer(streamDeckLayer.Name); + SetSelectedLayer(streamDeckLayer.Name, true, false); return true; } @@ -225,11 +224,11 @@ public void DeleteLayer(string layerName) } else if (_layerList.Count > 0) { - SetSelectedLayer(_layerList[0].Name); + SetSelectedLayer(_layerList[0].Name, true, false); } else { - SetSelectedLayer(null); + SetSelectedLayer(null, false, false); } } @@ -262,28 +261,6 @@ public string SelectedLayerName CheckHomeLayerExists(); return _selectedLayerName; } - - set - { - if (LayerList.Count == 0) - { - return; - } - - if (string.IsNullOrEmpty(value)) - { - return; - } - - bool found = _layerList.Exists(x => x.Name == value); - - if (!found) - { - throw new Exception($"StreamDeckLayerHandler : Failed to find layer with name {value} in order to mark it selected."); - } - - SetSelectedLayer(value); - } } public void ClearAllFaces() @@ -332,13 +309,13 @@ public void ShowPreviousLayer() { var tmpLayer = _layerHistory.Last(); _layerHistory.RemoveAt(_layerHistory.Count - 1); - SetSelectedLayer(tmpLayer); + SetSelectedLayer(tmpLayer, true, false); } } public void ShowHomeLayer() { - SetSelectedLayer(StreamDeckConstants.HOME_LAYER_NAME); + SetSelectedLayer(StreamDeckConstants.HOME_LAYER_NAME, true, false); } private void MarkAllButtonsHiddenAndClearFaces() @@ -350,7 +327,29 @@ private void MarkAllButtonsHiddenAndClearFaces() } } - private void SetSelectedLayer(string layerName) + public void SwitchToLayer(string layerName, bool switchedByUser, bool remotelySwitched) + { + if (LayerList.Count == 0) + { + return; + } + + if (string.IsNullOrEmpty(layerName)) + { + return; + } + + var found = _layerList.Exists(x => x.Name == layerName); + + if (!found) + { + throw new Exception($"StreamDeckLayerHandler : Failed to find layer with name {layerName} in order to mark it selected."); + } + + SetSelectedLayer(layerName, switchedByUser, remotelySwitched); + } + + private void SetSelectedLayer(string layerName, bool switchedByUser, bool remotelySwitched) { if (layerName == _selectedLayerName && _jsonImported == false) { @@ -384,7 +383,7 @@ private void SetSelectedLayer(string layerName) selectedLayer.IsVisible = true; - SDEventHandler.LayerSwitched(this, _streamDeckPanel.BindingHash, _selectedLayerName); + SDEventHandler.LayerSwitched(this, _streamDeckPanel.BindingHash, _selectedLayerName, switchedByUser, remotelySwitched); } public int SelectedButtonNumber