diff --git a/LenovoLegionToolkit.Lib.Automation/AutomationProcessor.cs b/LenovoLegionToolkit.Lib.Automation/AutomationProcessor.cs index c4c34f368a..83d8dbe405 100644 --- a/LenovoLegionToolkit.Lib.Automation/AutomationProcessor.cs +++ b/LenovoLegionToolkit.Lib.Automation/AutomationProcessor.cs @@ -7,6 +7,7 @@ using LenovoLegionToolkit.Lib.Automation.Pipeline; using LenovoLegionToolkit.Lib.Automation.Pipeline.Triggers; using LenovoLegionToolkit.Lib.Automation.Utils; +using LenovoLegionToolkit.Lib.Controllers.GodMode; using LenovoLegionToolkit.Lib.Listeners; using LenovoLegionToolkit.Lib.Utils; using NeoSmart.AsyncLock; @@ -19,6 +20,7 @@ public class AutomationProcessor private readonly NativeWindowsMessageListener _nativeWindowsMessageListener; private readonly PowerStateListener _powerStateListener; private readonly PowerModeListener _powerModeListener; + private readonly GodModeController _godModeController; private readonly GameAutoListener _gameAutoListener; private readonly ProcessAutoListener _processAutoListener; private readonly TimeAutoListener _timeAutoListener; @@ -38,6 +40,7 @@ public AutomationProcessor(AutomationSettings settings, NativeWindowsMessageListener nativeWindowsMessageListener, PowerStateListener powerStateListener, PowerModeListener powerModeListener, + GodModeController godModeController, GameAutoListener gameAutoListener, ProcessAutoListener processAutoListener, TimeAutoListener timeAutoListener, @@ -47,6 +50,7 @@ public AutomationProcessor(AutomationSettings settings, _nativeWindowsMessageListener = nativeWindowsMessageListener ?? throw new ArgumentNullException(nameof(nativeWindowsMessageListener)); _powerStateListener = powerStateListener ?? throw new ArgumentNullException(nameof(powerStateListener)); _powerModeListener = powerModeListener ?? throw new ArgumentNullException(nameof(powerModeListener)); + _godModeController = godModeController ?? throw new ArgumentNullException(nameof(godModeController)); _gameAutoListener = gameAutoListener ?? throw new ArgumentNullException(nameof(gameAutoListener)); _processAutoListener = processAutoListener ?? throw new ArgumentNullException(nameof(processAutoListener)); _timeAutoListener = timeAutoListener ?? throw new ArgumentNullException(nameof(timeAutoListener)); @@ -61,7 +65,8 @@ public async Task InitializeAsync() { _nativeWindowsMessageListener.Changed += NativeWindowsMessageListener_Changed; _powerStateListener.Changed += PowerStateListener_Changed; - _powerModeListener.Changed += PowerModeListenerOnChanged; + _powerModeListener.Changed += PowerModeListener_Changed; + _godModeController.PresetChanged += GodModeController_PresetChanged; _pipelines = _settings.Store.Pipelines.ToList(); @@ -254,12 +259,18 @@ private async void PowerStateListener_Changed(object? sender, EventArgs _) await ProcessEvent(e).ConfigureAwait(false); } - private async void PowerModeListenerOnChanged(object? sender, PowerModeState powerModeState) + private async void PowerModeListener_Changed(object? sender, PowerModeState powerModeState) { var e = new PowerModeAutomationEvent { PowerModeState = powerModeState }; await ProcessEvent(e).ConfigureAwait(false); } + private async void GodModeController_PresetChanged(object? sender, Guid presetId) + { + var e = new CustomModePresetAutomationEvent { Id = presetId }; + await ProcessEvent(e).ConfigureAwait(false); + } + private async void GameAutoListener_Changed(object? sender, bool started) { var e = new GameAutomationEvent { Started = started }; diff --git a/LenovoLegionToolkit.Lib.Automation/IAutomationEvent.cs b/LenovoLegionToolkit.Lib.Automation/IAutomationEvent.cs index 159ddf354d..6ce3071269 100644 --- a/LenovoLegionToolkit.Lib.Automation/IAutomationEvent.cs +++ b/LenovoLegionToolkit.Lib.Automation/IAutomationEvent.cs @@ -18,6 +18,11 @@ public struct PowerStateAutomationEvent : IAutomationEvent { } public PowerModeState PowerModeState { get; init; } } +public readonly struct CustomModePresetAutomationEvent : IAutomationEvent +{ + public Guid Id { get; init; } +} + public readonly struct GameAutomationEvent : IAutomationEvent { public bool Started { get; init; } diff --git a/LenovoLegionToolkit.Lib.Automation/Pipeline/AutomationPipeline.cs b/LenovoLegionToolkit.Lib.Automation/Pipeline/AutomationPipeline.cs index def0f86854..46d83f7989 100644 --- a/LenovoLegionToolkit.Lib.Automation/Pipeline/AutomationPipeline.cs +++ b/LenovoLegionToolkit.Lib.Automation/Pipeline/AutomationPipeline.cs @@ -13,6 +13,7 @@ namespace LenovoLegionToolkit.Lib.Automation.Pipeline; public class AutomationPipeline { + // ReSharper disable once PropertyCanBeMadeInitOnly.Global public Guid Id { get; set; } = Guid.NewGuid(); public string? IconName { get; set; } @@ -21,8 +22,10 @@ public class AutomationPipeline public IAutomationPipelineTrigger? Trigger { get; set; } + // ReSharper disable once PropertyCanBeMadeInitOnly.Global public List Steps { get; set; } = new(); + // ReSharper disable once PropertyCanBeMadeInitOnly.Global public bool IsExclusive { get; set; } = true; [JsonIgnore] diff --git a/LenovoLegionToolkit.Lib.Automation/Pipeline/Triggers/GodModePresetChangedAutomationPipelineTrigger.cs b/LenovoLegionToolkit.Lib.Automation/Pipeline/Triggers/GodModePresetChangedAutomationPipelineTrigger.cs new file mode 100644 index 0000000000..f2a405a9a0 --- /dev/null +++ b/LenovoLegionToolkit.Lib.Automation/Pipeline/Triggers/GodModePresetChangedAutomationPipelineTrigger.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading.Tasks; +using LenovoLegionToolkit.Lib.Automation.Resources; +using LenovoLegionToolkit.Lib.Controllers.GodMode; +using Newtonsoft.Json; + +namespace LenovoLegionToolkit.Lib.Automation.Pipeline.Triggers; + +public class GodModePresetChangedAutomationPipelineTrigger : IGodModePresetChangedAutomationPipelineTrigger +{ + [JsonIgnore] + public string DisplayName => Resource.GodModePresetChangedAutomationPipelineTrigger_DisplayName; + + public Guid PresetId { get; } + + [JsonConstructor] + public GodModePresetChangedAutomationPipelineTrigger(Guid presetId) + { + PresetId = presetId; + } + + public Task IsMatchingEvent(IAutomationEvent automationEvent) + { + if (automationEvent is not CustomModePresetAutomationEvent e) + return Task.FromResult(false); + + return Task.FromResult(e.Id == PresetId); + } + + public async Task IsMatchingState() + { + var controller = IoCContainer.Resolve(); + return PresetId == await controller.GetActivePresetIdAsync().ConfigureAwait(false); + } + + public void UpdateEnvironment(ref AutomationEnvironment environment) { /* Ignored */ } + + public IAutomationPipelineTrigger DeepCopy() => new GodModePresetChangedAutomationPipelineTrigger(PresetId); + + public IGodModePresetChangedAutomationPipelineTrigger DeepCopy(Guid presetId) => new GodModePresetChangedAutomationPipelineTrigger(presetId); + + public override bool Equals(object? obj) + { + return obj is GodModePresetChangedAutomationPipelineTrigger t && PresetId == t.PresetId; + } + + public override int GetHashCode() => HashCode.Combine(PresetId); + + public override string ToString() => $"{nameof(PresetId)}: {PresetId}"; +} diff --git a/LenovoLegionToolkit.Lib.Automation/Pipeline/Triggers/IAutomationPipelineTrigger.cs b/LenovoLegionToolkit.Lib.Automation/Pipeline/Triggers/IAutomationPipelineTrigger.cs index 2fcc982b76..b516617f4a 100644 --- a/LenovoLegionToolkit.Lib.Automation/Pipeline/Triggers/IAutomationPipelineTrigger.cs +++ b/LenovoLegionToolkit.Lib.Automation/Pipeline/Triggers/IAutomationPipelineTrigger.cs @@ -38,6 +38,13 @@ public interface IPowerModeAutomationPipelineTrigger : IAutomationPipelineTrigge IPowerModeAutomationPipelineTrigger DeepCopy(PowerModeState powerModeState); } +public interface IGodModePresetChangedAutomationPipelineTrigger : IAutomationPipelineTrigger +{ + Guid PresetId { get; } + + IGodModePresetChangedAutomationPipelineTrigger DeepCopy(Guid powerModeState); +} + public interface IGameAutomationPipelineTrigger : IDisallowDuplicatesAutomationPipelineTrigger { } public interface IProcessesAutomationPipelineTrigger : IAutomationPipelineTrigger diff --git a/LenovoLegionToolkit.Lib.Automation/Resources/Resource.Designer.cs b/LenovoLegionToolkit.Lib.Automation/Resources/Resource.Designer.cs index f67213adc9..d368ba36ac 100644 --- a/LenovoLegionToolkit.Lib.Automation/Resources/Resource.Designer.cs +++ b/LenovoLegionToolkit.Lib.Automation/Resources/Resource.Designer.cs @@ -177,6 +177,15 @@ public static string GamesStopAutomationPipelineTrigger_DisplayName { } } + /// + /// Looks up a localized string similar to When Custom Mode preset changes. + /// + public static string GodModePresetChangedAutomationPipelineTrigger_DisplayName { + get { + return ResourceManager.GetString("GodModePresetChangedAutomationPipelineTrigger_DisplayName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Lid closed. /// diff --git a/LenovoLegionToolkit.Lib.Automation/Resources/Resource.resx b/LenovoLegionToolkit.Lib.Automation/Resources/Resource.resx index 869c5dab86..ae6f0a30f3 100644 --- a/LenovoLegionToolkit.Lib.Automation/Resources/Resource.resx +++ b/LenovoLegionToolkit.Lib.Automation/Resources/Resource.resx @@ -193,4 +193,7 @@ On + + When Custom Mode preset changes + \ No newline at end of file diff --git a/LenovoLegionToolkit.Lib/Controllers/GodMode/AbstractGodModeController.cs b/LenovoLegionToolkit.Lib/Controllers/GodMode/AbstractGodModeController.cs index 022583ccc2..d5cc4a65f2 100644 --- a/LenovoLegionToolkit.Lib/Controllers/GodMode/AbstractGodModeController.cs +++ b/LenovoLegionToolkit.Lib/Controllers/GodMode/AbstractGodModeController.cs @@ -16,6 +16,8 @@ public abstract class AbstractGodModeController : IGodModeController protected readonly VantageDisabler VantageDisabler; protected readonly LegionZoneDisabler LegionZoneDisabler; + public event EventHandler? PresetChanged; + protected AbstractGodModeController(GodModeSettings settings, VantageDisabler vantageDisabler, LegionZoneDisabler legionZoneDisabler) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); @@ -27,6 +29,8 @@ protected AbstractGodModeController(GodModeSettings settings, VantageDisabler va public abstract Task NeedsLegionZoneDisabledAsync(); + public Task GetActivePresetIdAsync() => Task.FromResult(_settings.Store.ActivePresetId); + public Task GetActivePresetNameAsync() { var store = _settings.Store; @@ -121,7 +125,9 @@ public Task GetDefaultFanTableAsync() protected abstract Task GetDefaultStateAsync(); - protected async Task GetActivePresetAsync() + protected void RaisePresetChanged(Guid presetId) => PresetChanged?.Invoke(this, presetId); + + protected async Task<(Guid, GodModeSettings.GodModeSettingsStore.Preset)> GetActivePresetAsync() { if (!IsValidStore(_settings.Store)) { @@ -136,7 +142,7 @@ public Task GetDefaultFanTableAsync() var presets = _settings.Store.Presets; if (presets.TryGetValue(activePresetId, out var activePreset)) - return activePreset; + return (activePresetId, activePreset); throw new InvalidOperationException($"Preset with ID {activePresetId} not found."); } diff --git a/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeController.cs b/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeController.cs index af711ba32d..c620717b07 100644 --- a/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeController.cs +++ b/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeController.cs @@ -10,6 +10,20 @@ public class GodModeController : IGodModeController private readonly IGodModeController _controllerV1; private readonly IGodModeController _controllerV2; + public event EventHandler? PresetChanged + { + add + { + _controllerV1.PresetChanged += value; + _controllerV2.PresetChanged += value; + } + remove + { + _controllerV1.PresetChanged -= value; + _controllerV2.PresetChanged -= value; + } + } + public GodModeController(GodModeControllerV1 controllerV1, GodModeControllerV2 controllerV2) { _controllerV1 = controllerV1 ?? throw new ArgumentNullException(nameof(controllerV1)); @@ -28,6 +42,12 @@ public async Task NeedsLegionZoneDisabledAsync() return await controller.NeedsLegionZoneDisabledAsync().ConfigureAwait(false); } + public async Task GetActivePresetIdAsync() + { + var controller = await GetControllerAsync().ConfigureAwait(false); + return await controller.GetActivePresetIdAsync().ConfigureAwait(false); + } + public async Task GetActivePresetNameAsync() { var controller = await GetControllerAsync().ConfigureAwait(false); diff --git a/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeControllerV1.cs b/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeControllerV1.cs index f336d87be5..58747d7724 100644 --- a/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeControllerV1.cs +++ b/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeControllerV1.cs @@ -29,7 +29,7 @@ public override async Task ApplyStateAsync() if (Log.Instance.IsTraceEnabled) Log.Instance.Trace($"Applying state..."); - var preset = await GetActivePresetAsync().ConfigureAwait(false); + var (presetId, preset) = await GetActivePresetAsync().ConfigureAwait(false); var cpuLongTermPowerLimit = preset.CPULongTermPowerLimit; var cpuShortTermPowerLimit = preset.CPUShortTermPowerLimit; @@ -252,8 +252,10 @@ public override async Task ApplyStateAsync() } } + RaisePresetChanged(presetId); + if (Log.Instance.IsTraceEnabled) - Log.Instance.Trace($"State applied."); + Log.Instance.Trace($"State applied. [name={preset.Name}, id={presetId}]"); } public override Task GetMinimumFanTableAsync() diff --git a/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeControllerV2.cs b/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeControllerV2.cs index c5c59e433e..2e190f20a8 100644 --- a/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeControllerV2.cs +++ b/LenovoLegionToolkit.Lib/Controllers/GodMode/GodModeControllerV2.cs @@ -36,7 +36,7 @@ public override async Task ApplyStateAsync() if (Log.Instance.IsTraceEnabled) Log.Instance.Trace($"Applying state..."); - var preset = await GetActivePresetAsync().ConfigureAwait(false); + var (presetId, preset) = await GetActivePresetAsync().ConfigureAwait(false); var settings = new Dictionary { @@ -132,8 +132,10 @@ public override async Task ApplyStateAsync() } } + RaisePresetChanged(presetId); + if (Log.Instance.IsTraceEnabled) - Log.Instance.Trace($"State applied."); + Log.Instance.Trace($"State applied. [name={preset.Name}, id={presetId}]"); } public override Task GetMinimumFanTableAsync() diff --git a/LenovoLegionToolkit.Lib/Controllers/GodMode/IGodModeController.cs b/LenovoLegionToolkit.Lib/Controllers/GodMode/IGodModeController.cs index 1d6d3c3c92..193d76e55a 100644 --- a/LenovoLegionToolkit.Lib/Controllers/GodMode/IGodModeController.cs +++ b/LenovoLegionToolkit.Lib/Controllers/GodMode/IGodModeController.cs @@ -1,12 +1,15 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; namespace LenovoLegionToolkit.Lib.Controllers.GodMode; public interface IGodModeController { + event EventHandler PresetChanged; Task NeedsVantageDisabledAsync(); Task NeedsLegionZoneDisabledAsync(); + Task GetActivePresetIdAsync(); Task GetActivePresetNameAsync(); Task GetStateAsync(); Task SetStateAsync(GodModeState state); diff --git a/LenovoLegionToolkit.WPF/Controls/Automation/AutomationPipelineControl.cs b/LenovoLegionToolkit.WPF/Controls/Automation/AutomationPipelineControl.cs index 81956c7131..26f983e711 100644 --- a/LenovoLegionToolkit.WPF/Controls/Automation/AutomationPipelineControl.cs +++ b/LenovoLegionToolkit.WPF/Controls/Automation/AutomationPipelineControl.cs @@ -11,6 +11,7 @@ using LenovoLegionToolkit.Lib.Automation.Pipeline.Triggers; using LenovoLegionToolkit.Lib.Automation.Steps; using LenovoLegionToolkit.Lib.Extensions; +using LenovoLegionToolkit.Lib.Settings; using LenovoLegionToolkit.Lib.Utils; using LenovoLegionToolkit.WPF.Controls.Automation.Steps; using LenovoLegionToolkit.WPF.Extensions; @@ -29,6 +30,7 @@ public class AutomationPipelineControl : UserControl private readonly TaskCompletionSource _initializedTaskCompletionSource = new(); private readonly AutomationProcessor _automationProcessor = IoCContainer.Resolve(); + private readonly GodModeSettings _godModeSettings = IoCContainer.Resolve(); private readonly CardExpander _cardExpander = new() { @@ -249,6 +251,15 @@ private string GenerateSubtitle() if (AutomationPipeline.Trigger is IPowerModeAutomationPipelineTrigger pm) result += $" | {Resource.AutomationPipelineControl_SubtitlePart_PowerMode}: {pm.PowerModeState.GetDisplayName()}"; + if (AutomationPipeline.Trigger is IGodModePresetChangedAutomationPipelineTrigger gmpt) + { + var name = _godModeSettings.Store.Presets.Where(kv => kv.Key == gmpt.PresetId) + .Select(kv => kv.Value.Name) + .DefaultIfEmpty("-") + .First(); + result += $" | {Resource.AutomationPipelineControl_SubtitlePart_Preset}: {name}"; + } + if (AutomationPipeline.Trigger is IProcessesAutomationPipelineTrigger pt && pt.Processes.Any()) result += $" | {Resource.AutomationPipelineControl_SubtitlePart_Apps}: {string.Join(", ", pt.Processes.Select(p => p.Name))}"; diff --git a/LenovoLegionToolkit.WPF/Extensions/AutomationPipelineTriggerExtensions.cs b/LenovoLegionToolkit.WPF/Extensions/AutomationPipelineTriggerExtensions.cs index 4bdd57f274..626e43baa7 100644 --- a/LenovoLegionToolkit.WPF/Extensions/AutomationPipelineTriggerExtensions.cs +++ b/LenovoLegionToolkit.WPF/Extensions/AutomationPipelineTriggerExtensions.cs @@ -10,6 +10,7 @@ public static class AutomationPipelineTriggerExtensions { IPowerStateAutomationPipelineTrigger => SymbolRegular.BatteryCharge24, IPowerModeAutomationPipelineTrigger => SymbolRegular.Gauge24, + IGodModePresetChangedAutomationPipelineTrigger => SymbolRegular.Gauge24, IGameAutomationPipelineTrigger => SymbolRegular.XboxController24, IProcessesAutomationPipelineTrigger => SymbolRegular.WindowConsole20, IUserInactivityPipelineTrigger => SymbolRegular.ClockAlarm24, diff --git a/LenovoLegionToolkit.WPF/Resources/Resource.Designer.cs b/LenovoLegionToolkit.WPF/Resources/Resource.Designer.cs index ab301923cb..97f080e2ef 100644 --- a/LenovoLegionToolkit.WPF/Resources/Resource.Designer.cs +++ b/LenovoLegionToolkit.WPF/Resources/Resource.Designer.cs @@ -611,6 +611,15 @@ public static string AutomationPipelineControl_SubtitlePart_PowerMode { } } + /// + /// Looks up a localized string similar to Preset. + /// + public static string AutomationPipelineControl_SubtitlePart_Preset { + get { + return ResourceManager.GetString("AutomationPipelineControl_SubtitlePart_Preset", resourceCulture); + } + } + /// /// Looks up a localized string similar to Unnamed. /// diff --git a/LenovoLegionToolkit.WPF/Resources/Resource.resx b/LenovoLegionToolkit.WPF/Resources/Resource.resx index a15539c796..743396a89a 100644 --- a/LenovoLegionToolkit.WPF/Resources/Resource.resx +++ b/LenovoLegionToolkit.WPF/Resources/Resource.resx @@ -1928,4 +1928,7 @@ Requires restart. Show notification + + Preset + \ No newline at end of file diff --git a/LenovoLegionToolkit.WPF/Windows/Automation/AutomationPipelineTriggerConfigurationWindow.xaml.cs b/LenovoLegionToolkit.WPF/Windows/Automation/AutomationPipelineTriggerConfigurationWindow.xaml.cs index 69b3896eae..3b7f6f474b 100644 --- a/LenovoLegionToolkit.WPF/Windows/Automation/AutomationPipelineTriggerConfigurationWindow.xaml.cs +++ b/LenovoLegionToolkit.WPF/Windows/Automation/AutomationPipelineTriggerConfigurationWindow.xaml.cs @@ -93,6 +93,7 @@ private void CancelButton_Click(object sender, RoutedEventArgs e) private static bool IsValid(IAutomationPipelineTrigger trigger) => trigger switch { IPowerModeAutomationPipelineTrigger => true, + IGodModePresetChangedAutomationPipelineTrigger => true, IProcessesAutomationPipelineTrigger => true, IUserInactivityPipelineTrigger ut when ut.InactivityTimeSpan > TimeSpan.Zero => true, ITimeAutomationPipelineTrigger => true, @@ -102,6 +103,7 @@ private void CancelButton_Click(object sender, RoutedEventArgs e) private static IAutomationPipelineTriggerTabItemContent? Create(IAutomationPipelineTrigger trigger) => trigger switch { IPowerModeAutomationPipelineTrigger pmt => new PowerModeAutomationPipelineTriggerTabItemContent(pmt), + IGodModePresetChangedAutomationPipelineTrigger gmpt => new GodModePresetPipelineTriggerTabItemContent(gmpt), IProcessesAutomationPipelineTrigger pt => new ProcessAutomationPipelineTriggerTabItemControl(pt), IUserInactivityPipelineTrigger ut when ut.InactivityTimeSpan > TimeSpan.Zero => new UserInactivityPipelineTriggerTabItemContent(ut), ITimeAutomationPipelineTrigger tt => new TimeAutomationPipelineTriggerTabItemContent(tt), diff --git a/LenovoLegionToolkit.WPF/Windows/Automation/CreateAutomationPipelineWindow.xaml.cs b/LenovoLegionToolkit.WPF/Windows/Automation/CreateAutomationPipelineWindow.xaml.cs index e7e91abb6e..d2e7e959fc 100644 --- a/LenovoLegionToolkit.WPF/Windows/Automation/CreateAutomationPipelineWindow.xaml.cs +++ b/LenovoLegionToolkit.WPF/Windows/Automation/CreateAutomationPipelineWindow.xaml.cs @@ -23,6 +23,7 @@ public partial class CreateAutomationPipelineWindow new LowWattageACAdapterConnectedAutomationPipelineTrigger(), new ACAdapterDisconnectedAutomationPipelineTrigger(), new PowerModeAutomationPipelineTrigger(PowerModeState.Balance), + new GodModePresetChangedAutomationPipelineTrigger(Guid.Empty), new GamesAreRunningAutomationPipelineTrigger(), new GamesStopAutomationPipelineTrigger(), new ProcessesAreRunningAutomationPipelineTrigger(Array.Empty()), diff --git a/LenovoLegionToolkit.WPF/Windows/Automation/TabItemContent/GodModePresetPipelineTriggerTabItemContent.xaml b/LenovoLegionToolkit.WPF/Windows/Automation/TabItemContent/GodModePresetPipelineTriggerTabItemContent.xaml new file mode 100644 index 0000000000..08ac349805 --- /dev/null +++ b/LenovoLegionToolkit.WPF/Windows/Automation/TabItemContent/GodModePresetPipelineTriggerTabItemContent.xaml @@ -0,0 +1,14 @@ + + + + + diff --git a/LenovoLegionToolkit.WPF/Windows/Automation/TabItemContent/GodModePresetPipelineTriggerTabItemContent.xaml.cs b/LenovoLegionToolkit.WPF/Windows/Automation/TabItemContent/GodModePresetPipelineTriggerTabItemContent.xaml.cs new file mode 100644 index 0000000000..d401f39b1f --- /dev/null +++ b/LenovoLegionToolkit.WPF/Windows/Automation/TabItemContent/GodModePresetPipelineTriggerTabItemContent.xaml.cs @@ -0,0 +1,48 @@ +using System; +using System.Linq; +using System.Windows.Controls; +using LenovoLegionToolkit.Lib; +using LenovoLegionToolkit.Lib.Automation.Pipeline.Triggers; +using LenovoLegionToolkit.Lib.Settings; + +namespace LenovoLegionToolkit.WPF.Windows.Automation.TabItemContent; + +public partial class GodModePresetPipelineTriggerTabItemContent : IAutomationPipelineTriggerTabItemContent +{ + private readonly GodModeSettings _settings = IoCContainer.Resolve(); + + private readonly IGodModePresetChangedAutomationPipelineTrigger _trigger; + + public GodModePresetPipelineTriggerTabItemContent(IGodModePresetChangedAutomationPipelineTrigger trigger) + { + _trigger = trigger; + + InitializeComponent(); + } + + public IGodModePresetChangedAutomationPipelineTrigger GetTrigger() + { + var state = _content.Children + .OfType() + .Where(r => r.IsChecked ?? false) + .Select(r => (Guid)r.Tag) + .DefaultIfEmpty(Guid.Empty) + .FirstOrDefault(); + return _trigger.DeepCopy(state); + } + + private void GodModePresetPipelineItem_Initialized(object? sender, EventArgs e) + { + foreach (var (guid, preset) in _settings.Store.Presets) + { + var radio = new RadioButton + { + Content = preset.Name, + Tag = guid, + IsChecked = guid == _trigger.PresetId, + Margin = new(0, 0, 0, 8) + }; + _content.Children.Add(radio); + } + } +} \ No newline at end of file