Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layer switch set to true for correct Stream Deck #395

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/DCSFlightpanels/DCSFlightpanels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</Authors>
<PackageId>DCSFlightpanels (DCSFP)</PackageId>
<Version>1.0.0</Version>
<AssemblyVersion>4.10.2</AssemblyVersion>
<AssemblyVersion>4.10.3</AssemblyVersion>
<FileVersion>
</FileVersion>
<ApplicationIcon>flightpanels02_8Rc_icon.ico</ApplicationIcon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/NonVisuals/Panels/StreamDeck/ActionTypeLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void Navigate(CancellationToken threadCancellationToken)

case LayerNavType.SwitchToSpecificLayer:
{
_streamDeckPanel.SelectedLayerName = TargetLayer;
_streamDeckPanel.SwitchToLayer(TargetLayer, true, false);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/NonVisuals/Panels/StreamDeck/Events/SDEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions Source/NonVisuals/Panels/StreamDeck/Panels/StreamDeckPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> LayerNameList
Expand All @@ -69,7 +73,6 @@ public StreamDeckLayer HomeLayer
public StreamDeckLayer SelectedLayer
{
get => _streamDeckLayerHandler.SelectedLayer;
set => _streamDeckLayerHandler.SelectedLayer = value;
}

public bool HasLayers
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down
67 changes: 33 additions & 34 deletions Source/NonVisuals/Panels/StreamDeck/StreamDeckLayerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace NonVisuals.Panels.StreamDeck
using Events;

using Panels;
using Newtonsoft.Json.Linq;

public class StreamDeckLayerHandler : IDisposable
{
Expand Down Expand Up @@ -84,8 +85,6 @@ public StreamDeckLayer SelectedLayer
CheckHomeLayerExists();
return GetLayer(_selectedLayerName);
}

set => SetSelectedLayer(value.Name);
}


Expand Down Expand Up @@ -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);
}
}

Expand All @@ -198,7 +197,7 @@ public bool AddLayer(StreamDeckLayer streamDeckLayer)
LayerList.Add(streamDeckLayer);
}

SetSelectedLayer(streamDeckLayer.Name);
SetSelectedLayer(streamDeckLayer.Name, true, false);
return true;
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
Loading