Skip to content

Commit 1c440b2

Browse files
author
Aytackydln
committed
add iCUE states/events window
1 parent a244233 commit 1c440b2

File tree

10 files changed

+230
-2
lines changed

10 files changed

+230
-2
lines changed

Project-Aurora/Project-Aurora/Modules/Icue/IcueGsi.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class IcueGsi
1111
public HashSet<string> States { get; } = [];
1212
public Dictionary<string, long> EventTimestamps { get; } = [];
1313
public string GameName { get; private set; } = string.Empty;
14+
public Dictionary<string, IcueGsiStateStore> StateStore { get; } = new();
1415

1516
private GsiHandler? _gsiHandler;
1617

@@ -24,6 +25,8 @@ public void SetGsiHandler(GsiHandler gsiHandler, IcueGsiConnectionEventArgs e)
2425

2526
GameName = e.GameName;
2627
GameChanged?.Invoke(this, EventArgs.Empty);
28+
29+
StateStore.TryAdd(GameName, new IcueGsiStateStore(GameName));
2730
}
2831

2932
public void ClearGsiHandler()
@@ -47,6 +50,7 @@ public void ClearGsiHandler()
4750
private void OnStateAdded(object? sender, IcueStateEventArgs icueStateEventArgs)
4851
{
4952
States.Add(icueStateEventArgs.StateName);
53+
StateStore[GameName].AddState(icueStateEventArgs.StateName);
5054
}
5155

5256
private void OnStateRemoved(object? sender, IcueStateEventArgs icueStateEventArgs)
@@ -62,6 +66,7 @@ private void OnStatesCleared(object? sender, EventArgs e)
6266
private void OnEventAdded(object? sender, IcueStateEventArgs icueStateEventArgs)
6367
{
6468
EventTimestamps[icueStateEventArgs.StateName] = DateTimeOffset.Now.ToUnixTimeMilliseconds();
69+
StateStore[GameName].AddEvent(icueStateEventArgs.StateName);
6570
EventReceived?.Invoke(this, icueStateEventArgs);
6671
}
6772
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace AuroraRgb.Modules.Icue;
5+
6+
public sealed class IcueGsiStateStore(string gameName)
7+
{
8+
private readonly HashSet<string> _states = [];
9+
private readonly HashSet<string> _events = [];
10+
11+
public event EventHandler? StateChanged;
12+
13+
public string GameName { get; } = gameName;
14+
15+
public IReadOnlySet<string> States => _states;
16+
17+
public IReadOnlySet<string> Events => _events;
18+
19+
public void AddState(string state)
20+
{
21+
if (_states.Add(state))
22+
StateChanged?.Invoke(this, EventArgs.Empty);
23+
}
24+
25+
public void AddEvent(string state)
26+
{
27+
if (_events.Add(state))
28+
StateChanged?.Invoke(this, EventArgs.Empty);
29+
}
30+
}

Project-Aurora/Project-Aurora/Settings/Controls/Wrappers/ControlCorsairIcueWrapper.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<Label x:Name="IcueCurrentSdkApplicationLabel" Grid.Row="2" Grid.Column="2" Width="300" Content="application name"
3939
Margin="5 0 5 0" Padding="0" VerticalAlignment="Center" HorizontalAlignment="Left" />
4040
<Label Grid.Row="3" Grid.Column="0" Content="Current GS Application:" Margin="5 0 5 0" Padding="0" VerticalAlignment="Center" />
41+
<Button Grid.Row="3" Grid.Column="1" Width="100" Click="VariablesButton_OnClick">State/Events</Button>
4142
<Label x:Name="IcueCurrentGsApplicationLabel" Grid.Row="3" Grid.Column="2" Width="300" Content="application name"
4243
Margin="5 0 5 0" Padding="0" VerticalAlignment="Center" HorizontalAlignment="Left" />
4344

Project-Aurora/Project-Aurora/Settings/Controls/Wrappers/ControlCorsairIcueWrapper.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,10 @@ private void SetProcessRunningLabel(bool isRunning)
143143
IcueRunningStatus.Foreground = Brushes.Green;
144144
}
145145
}
146+
147+
private void VariablesButton_OnClick(object sender, RoutedEventArgs e)
148+
{
149+
var window = new Window_IcueVariables();
150+
window.Show();
151+
}
146152
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<UserControl x:Class="AuroraRgb.Settings.Controls.Wrappers.Control_IcueGameVariables"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:icue="clr-namespace:AuroraRgb.Modules.Icue"
7+
mc:Ignorable="d"
8+
Unloaded="Control_IcueGameVariables_OnUnloaded"
9+
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance icue:IcueGsiStateStore }">
10+
<StackPanel>
11+
<TextBlock Text="{Binding GameName}" />
12+
<StackPanel Orientation="Horizontal">
13+
<Border BorderBrush="BlueViolet" BorderThickness="1" Margin="4">
14+
<StackPanel>
15+
<TextBlock>State Variables</TextBlock>
16+
<Separator/>
17+
<StackPanel Name="StatesList" />
18+
</StackPanel>
19+
</Border>
20+
<Border BorderBrush="BlueViolet" BorderThickness="1" Margin="4">
21+
<StackPanel>
22+
<TextBlock>Event Variables</TextBlock>
23+
<Separator/>
24+
<StackPanel Name="EventsList" />
25+
</StackPanel>
26+
</Border>
27+
</StackPanel>
28+
</StackPanel>
29+
</UserControl>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using AuroraRgb.Modules.Icue;
5+
6+
namespace AuroraRgb.Settings.Controls.Wrappers;
7+
8+
public partial class Control_IcueGameVariables
9+
{
10+
private IcueGsiStateStore? _gameStorage;
11+
12+
public IcueGsiStateStore? GameStorage
13+
{
14+
get => (IcueGsiStateStore?)GetValue(GameStorageProperty);
15+
set => SetValue(GameStorageProperty, value);
16+
}
17+
18+
public static readonly DependencyProperty GameStorageProperty =
19+
DependencyProperty.Register(
20+
nameof(GameStorage),
21+
typeof(IcueGsiStateStore),
22+
typeof(Control_IcueGameVariables),
23+
new PropertyMetadata(null, OnGameStorageChanged));
24+
25+
26+
public Control_IcueGameVariables()
27+
{
28+
InitializeComponent();
29+
}
30+
31+
private static void OnGameStorageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
32+
{
33+
var control = (Control_IcueGameVariables)d;
34+
35+
if (e.OldValue is IcueGsiStateStore oldStore)
36+
oldStore.StateChanged -= control.GameStorageOnStateChanged;
37+
38+
control._gameStorage = e.NewValue as IcueGsiStateStore;
39+
control.DataContext = control._gameStorage;
40+
41+
if (control._gameStorage is not null)
42+
{
43+
control._gameStorage.StateChanged += control.GameStorageOnStateChanged;
44+
control.RefreshLists();
45+
}
46+
else
47+
{
48+
control.ClearLists();
49+
}
50+
}
51+
52+
private void Control_IcueGameVariables_OnUnloaded(object sender, RoutedEventArgs e)
53+
{
54+
if (_gameStorage is not null)
55+
_gameStorage.StateChanged -= GameStorageOnStateChanged;
56+
}
57+
58+
private void GameStorageOnStateChanged(object? sender, EventArgs e)
59+
{
60+
Dispatcher.Invoke(RefreshLists);
61+
}
62+
63+
private void RefreshLists()
64+
{
65+
if (_gameStorage is null) { ClearLists(); return; }
66+
67+
StatesList.Children.Clear();
68+
foreach (var state in _gameStorage.States)
69+
StatesList.Children.Add(new TextBlock { Text = state });
70+
71+
EventsList.Children.Clear();
72+
foreach (var ev in _gameStorage.Events)
73+
EventsList.Children.Add(new TextBlock { Text = ev });
74+
}
75+
76+
private void ClearLists()
77+
{
78+
StatesList.Children.Clear();
79+
EventsList.Children.Clear();
80+
}
81+
}

Project-Aurora/Project-Aurora/Settings/Controls/Window_ChromaSettings.xaml renamed to Project-Aurora/Project-Aurora/Settings/Controls/Wrappers/Window_ChromaSettings.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<fluentWpf:AcrylicWindow x:Class="AuroraRgb.Settings.Controls.Window_ChromaSettings"
1+
<fluentWpf:AcrylicWindow x:Class="AuroraRgb.Settings.Controls.Wrappers.Window_ChromaSettings"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

Project-Aurora/Project-Aurora/Settings/Controls/Window_ChromaSettings.xaml.cs renamed to Project-Aurora/Project-Aurora/Settings/Controls/Wrappers/Window_ChromaSettings.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using AuroraRgb.Modules.Razer;
55
using AuroraRgb.Utils;
66

7-
namespace AuroraRgb.Settings.Controls;
7+
namespace AuroraRgb.Settings.Controls.Wrappers;
88

99
public partial class Window_ChromaSettings : IDisposable
1010
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<fluentWpf:AcrylicWindow x:Class="AuroraRgb.Settings.Controls.Wrappers.Window_IcueVariables"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:AuroraRgb.Settings.Controls.Wrappers"
7+
xmlns:icue="clr-namespace:AuroraRgb.Modules.Icue"
8+
xmlns:fluentWpf="clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF"
9+
mc:Ignorable="d"
10+
Title="Window_IcueVariables" Height="450" Width="800" d:DataContext="{d:DesignInstance local:Window_IcueVariables}">
11+
<Grid>
12+
<TextBlock Name="EmptyText">iCUE integration's state and event names will appear as supported games are run.</TextBlock>
13+
<ListView ItemsSource="{Binding StateStore}">
14+
<ListView.ItemContainerStyle>
15+
<Style TargetType="ListViewItem">
16+
<Setter Property="Focusable" Value="false"/>
17+
</Style>
18+
</ListView.ItemContainerStyle>
19+
<ListView.ItemTemplate>
20+
<DataTemplate DataType="{x:Type icue:IcueGsiStateStore}">
21+
<local:Control_IcueGameVariables GameStorage="{Binding}" />
22+
</DataTemplate>
23+
</ListView.ItemTemplate>
24+
</ListView>
25+
</Grid>
26+
</fluentWpf:AcrylicWindow>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
using AuroraRgb.Modules;
4+
using AuroraRgb.Modules.Icue;
5+
using AuroraRgb.Utils;
6+
7+
namespace AuroraRgb.Settings.Controls.Wrappers;
8+
9+
public partial class Window_IcueVariables : IDisposable
10+
{
11+
private readonly TransparencyComponent _transparencyComponent;
12+
public ObservableCollection<IcueGsiStateStore> StateStore { get; }
13+
14+
public Window_IcueVariables()
15+
{
16+
var gsi = IcueModule.AuroraIcueServer.Gsi;
17+
StateStore = new ObservableCollection<IcueGsiStateStore>(gsi.StateStore.Values);
18+
gsi.GameChanged += GsiOnGameChanged;
19+
20+
InitializeComponent();
21+
22+
// Set the DataContext to the window so XAML can bind to the StateStore property
23+
DataContext = this;
24+
UpdateEmptyTextVisibility();
25+
26+
_transparencyComponent = new TransparencyComponent(this, null);
27+
}
28+
29+
private void GsiOnGameChanged(object? sender, EventArgs e)
30+
{
31+
var gsi = IcueModule.AuroraIcueServer.Gsi;
32+
Dispatcher.Invoke(() =>
33+
{
34+
StateStore.Clear();
35+
foreach (var store in gsi.StateStore.Values)
36+
StateStore.Add(store);
37+
UpdateEmptyTextVisibility();
38+
});
39+
}
40+
41+
private void UpdateEmptyTextVisibility()
42+
{
43+
EmptyText.Visibility = StateStore.Count == 0 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
44+
}
45+
46+
public void Dispose()
47+
{
48+
_transparencyComponent.Dispose();
49+
}
50+
}

0 commit comments

Comments
 (0)