From 66aa2e8d049a5823c1844b199bbb0f66613f02af Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 17 Feb 2016 19:56:07 +0100 Subject: [PATCH] Implemented enabling/disabling games and overlays --- Artemis/Artemis/Artemis.csproj | 1 + Artemis/Artemis/Models/EffectModel.cs | 4 ++ Artemis/Artemis/Models/GameModel.cs | 2 +- Artemis/Artemis/Models/MainModel.cs | 13 ++++-- Artemis/Artemis/Models/OverlayModel.cs | 1 + .../Games/CounterStrike/CounterStrikeModel.cs | 40 +++++++++---------- .../CounterStrike/CounterStrikeSettings.cs | 6 +-- .../CounterStrike/CounterStrikeView.xaml | 6 ++- .../CounterStrike/CounterStrikeViewModel.cs | 33 ++++++++------- .../Games/RocketLeague/RocketLeague.settings | 4 +- .../Games/RocketLeague/RocketLeagueModel.cs | 26 +++++------- .../RocketLeague/RocketLeagueSettings.cs | 6 +-- .../Games/RocketLeague/RocketLeagueView.xaml | 5 ++- .../RocketLeague/RocketLeagueViewModel.cs | 5 +++ .../Games/Witcher3/RocketLeagueSettings.cs | 31 ++++++++++++++ .../Modules/Games/Witcher3/Witcher3Model.cs | 12 +++--- .../Modules/Games/Witcher3/Witcher3View.xaml | 19 +++++++-- .../Games/Witcher3/Witcher3ViewModel.cs | 40 +++++++++++-------- .../Overlays/VolumeDisplay/VolumeDisplay.cs | 2 +- .../VolumeDisplay/VolumeDisplayModel.cs | 2 - .../VolumeDisplay/VolumeDisplayView.xaml | 1 + .../VolumeDisplay/VolumeDisplayViewModel.cs | 2 +- 22 files changed, 166 insertions(+), 95 deletions(-) create mode 100644 Artemis/Artemis/Modules/Games/Witcher3/RocketLeagueSettings.cs diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 12aa1c42e..5592755fb 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -232,6 +232,7 @@ True + True True diff --git a/Artemis/Artemis/Models/EffectModel.cs b/Artemis/Artemis/Models/EffectModel.cs index 27a1fac9b..72679de3e 100644 --- a/Artemis/Artemis/Models/EffectModel.cs +++ b/Artemis/Artemis/Models/EffectModel.cs @@ -5,6 +5,8 @@ namespace Artemis.Models { public abstract class EffectModel : IDisposable { + public delegate void SettingsUpdateHandler(EffectSettings settings); + public MainModel MainModel; public string Name; @@ -13,6 +15,8 @@ namespace Artemis.Models MainModel = mainModel; } + public event SettingsUpdateHandler SettingsUpdateEvent; + public abstract void Dispose(); // Called on creation diff --git a/Artemis/Artemis/Models/GameModel.cs b/Artemis/Artemis/Models/GameModel.cs index 8a30ac30f..b1addf204 100644 --- a/Artemis/Artemis/Models/GameModel.cs +++ b/Artemis/Artemis/Models/GameModel.cs @@ -2,7 +2,7 @@ { public abstract class GameModel : EffectModel { - public abstract bool Enabled(); + public bool Enabled; public string ProcessName; protected GameModel(MainModel mainModel) : base(mainModel) diff --git a/Artemis/Artemis/Models/MainModel.cs b/Artemis/Artemis/Models/MainModel.cs index 82a2b0417..63fc3f3fa 100644 --- a/Artemis/Artemis/Models/MainModel.cs +++ b/Artemis/Artemis/Models/MainModel.cs @@ -111,7 +111,7 @@ namespace Artemis.Models // Game models are only used if they are enabled var gameModel = effectModel as GameModel; if (gameModel != null) - if (!gameModel.Enabled()) + if (!gameModel.Enabled) return; if (ActiveEffect != null && effectModel.Name == ActiveEffect.Name) @@ -204,8 +204,15 @@ namespace Artemis.Models if (process.HasExited) continue; - ChangeEffect(effectModel); - foundProcess = true; + // If the active effect is a disabled game model, disable it + var model = ActiveEffect as GameModel; + if (model != null && !model.Enabled) + LoadLastEffect(); + else + { + ChangeEffect(effectModel); + foundProcess = true; + } } // If no game process is found, but the active effect still belongs to a game, diff --git a/Artemis/Artemis/Models/OverlayModel.cs b/Artemis/Artemis/Models/OverlayModel.cs index bd0646fa4..11988a1f1 100644 --- a/Artemis/Artemis/Models/OverlayModel.cs +++ b/Artemis/Artemis/Models/OverlayModel.cs @@ -11,6 +11,7 @@ namespace Artemis.Models { } + // Overlay Enabled() and Dispose() is called when changing the Enabled value public bool Enabled { get { return _enabled; } diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index 6f20c63ba..d7cef57e7 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -14,16 +14,17 @@ namespace Artemis.Modules.Games.CounterStrike { public class CounterStrikeModel : GameModel { - private readonly CounterStrikeSettings _settings; - public CounterStrikeModel(MainModel mainModel, CounterStrikeSettings settings) : base(mainModel) { - _settings = settings; + Settings = settings; Name = "CounterStrike"; ProcessName = "csgo"; Scale = 4; + Enabled = Settings.Enabled; } + public CounterStrikeSettings Settings { get; set; } + public KeyboardRectangle EventRect { get; set; } public KeyboardRectangle TeamRect { get; set; } public KeyboardRectangle AmmoRect { get; set; } @@ -34,11 +35,6 @@ namespace Artemis.Modules.Games.CounterStrike public int Scale { get; set; } - public override bool Enabled() - { - return _settings.Enabled; - } - public override void Dispose() { MainModel.GameStateWebServer.GameDataReceived -= HandleGameData; @@ -50,9 +46,9 @@ namespace Artemis.Modules.Games.CounterStrike AmmoRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 0, new List(), LinearGradientMode.Horizontal) {Height = Scale, ContainedBrush = false}; TeamRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 1, new List(), - LinearGradientMode.Horizontal) {Height = (MainModel.ActiveKeyboard.Height*Scale) - Scale}; + LinearGradientMode.Horizontal) {Height = MainModel.ActiveKeyboard.Height*Scale - Scale}; EventRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 1, new List(), - LinearGradientMode.Horizontal) {Height = (MainModel.ActiveKeyboard.Height*Scale) - Scale}; + LinearGradientMode.Horizontal) {Height = MainModel.ActiveKeyboard.Height*Scale - Scale}; MainModel.GameStateWebServer.GameDataReceived += HandleGameData; } @@ -61,15 +57,15 @@ namespace Artemis.Modules.Games.CounterStrike if (CsJson == null) return; - if (_settings.AmmoEnabled) + if (Settings.AmmoEnabled) UpdateAmmo(); - if (_settings.TeamColorEnabled) + if (Settings.TeamColorEnabled) UpdateTeam(); - if (_settings.LowHpEnabled) + if (Settings.LowHpEnabled) UpdateHealth(); - if (_settings.FlashEnabled) + if (Settings.FlashEnabled) UpdateFlash(); - if (_settings.SmokeEnabled) + if (Settings.SmokeEnabled) UpdateSmoke(); } @@ -82,7 +78,7 @@ namespace Artemis.Modules.Games.CounterStrike if (health > 25 || health < 1) return; - TeamRect.Colors = new List {Color.Red, Color.OrangeRed, Color.Red, Color.OrangeRed }; + TeamRect.Colors = new List {Color.Red, Color.OrangeRed, Color.Red, Color.OrangeRed}; } private void UpdateSmoke() @@ -93,9 +89,9 @@ namespace Artemis.Modules.Games.CounterStrike var smoked = CsJson["player"]["state"]["smoked"].Value(); if (smoked == 0 && !DrawingSmoke) return; - + EventRect.Colors = new List {Color.FromArgb(smoked, 255, 255, 255)}; - DrawingSmoke = (smoked != 0); + DrawingSmoke = smoked != 0; } private void UpdateFlash() @@ -108,7 +104,7 @@ namespace Artemis.Modules.Games.CounterStrike return; EventRect.Colors = new List {Color.FromArgb(flashed, 255, 255, 255)}; - DrawingFlash = (flashed != 0); + DrawingFlash = flashed != 0; } private void UpdateTeam() @@ -150,11 +146,11 @@ namespace Artemis.Modules.Games.CounterStrike return; var ammoPercentage = (int) Math.Ceiling(100.00/maxAmmo)*ammo; - AmmoRect.Width = ((int) Math.Floor((16/100.00)*ammoPercentage))*Scale; + AmmoRect.Width = (int) Math.Floor(16/100.00*ammoPercentage)*Scale; AmmoRect.Colors = new List { - ColorHelpers.ToDrawingColor(_settings.AmmoMainColor), - ColorHelpers.ToDrawingColor(_settings.AmmoSecondaryColor) + ColorHelpers.ToDrawingColor(Settings.AmmoMainColor), + ColorHelpers.ToDrawingColor(Settings.AmmoSecondaryColor) }; // Low ammo indicator diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeSettings.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeSettings.cs index 75be4ac51..d29f47922 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeSettings.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeSettings.cs @@ -22,7 +22,7 @@ namespace Artemis.Modules.Games.CounterStrike public bool SmokeEnabled { get; set; } public bool LowHpEnabled { get; set; } - public override sealed void Load() + public sealed override void Load() { Enabled = CounterStrike.Default.Enabled; GameDirectory = CounterStrike.Default.GameDirectory; @@ -37,7 +37,7 @@ namespace Artemis.Modules.Games.CounterStrike LowHpEnabled = CounterStrike.Default.LowHpEnabled; } - public override sealed void Save() + public sealed override void Save() { CounterStrike.Default.Enabled = Enabled; CounterStrike.Default.GameDirectory = GameDirectory; @@ -54,7 +54,7 @@ namespace Artemis.Modules.Games.CounterStrike CounterStrike.Default.Save(); } - public override sealed void ToDefault() + public sealed override void ToDefault() { Enabled = true; GameDirectory = string.Empty; diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml index 937022705..724ebe87a 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml @@ -11,7 +11,7 @@ - + @@ -37,7 +37,9 @@ diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs index 6f5bcd90b..8ce25fd99 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs @@ -41,6 +41,25 @@ namespace Artemis.Modules.Games.CounterStrike public static string Name => "CS:GO"; public string Content => "Counter-Strike: GO Content"; + public void SaveSettings() + { + CounterStrikeSettings?.Save(); + } + + public void ResetSettings() + { + // TODO: Confirmation dialog (Generic MVVM approach) + CounterStrikeSettings.ToDefault(); + NotifyOfPropertyChange(() => CounterStrikeSettings); + + SaveSettings(); + } + + public void ToggleEffect() + { + CounterStrikeModel.Enabled = _counterStrikeSettings.Enabled; + } + public void BrowseDirectory() { var dialog = new FolderBrowserDialog {SelectedPath = CounterStrikeSettings.GameDirectory}; @@ -70,19 +89,5 @@ namespace Artemis.Modules.Games.CounterStrike CounterStrikeSettings.GameDirectory = string.Empty; NotifyOfPropertyChange(() => CounterStrikeSettings); } - - public void SaveSettings() - { - CounterStrikeSettings?.Save(); - } - - public void ResetSettings() - { - // TODO: Confirmation dialog (Generic MVVM approach) - CounterStrikeSettings.ToDefault(); - NotifyOfPropertyChange(() => CounterStrikeSettings); - - SaveSettings(); - } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeague.settings b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeague.settings index 58f5de73e..44ad08314 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeague.settings +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeague.settings @@ -1,5 +1,7 @@  - + + diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs index 8d19978cb..3fe1ae557 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs @@ -16,7 +16,6 @@ namespace Artemis.Modules.Games.RocketLeague { public class RocketLeagueModel : GameModel { - private readonly RocketLeagueSettings _settings; private int _boostAmount; private bool _boostGrowing; private KeyboardRectangle _boostRect; @@ -26,17 +25,14 @@ namespace Artemis.Modules.Games.RocketLeague public RocketLeagueModel(MainModel mainModel, RocketLeagueSettings settings) : base(mainModel) { + Settings = settings; Name = "RocketLeague"; ProcessName = "RocketLeague"; Scale = 4; - - _settings = settings; + Enabled = Settings.Enabled; } - public override bool Enabled() - { - return _settings.Enabled; - } + public RocketLeagueSettings Settings { get; set; } public int Scale { get; set; } @@ -49,8 +45,8 @@ namespace Artemis.Modules.Games.RocketLeague { _boostRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 0, new List { - ColorHelpers.ToDrawingColor(_settings.MainColor), - ColorHelpers.ToDrawingColor(_settings.SecondaryColor) + ColorHelpers.ToDrawingColor(Settings.MainColor), + ColorHelpers.ToDrawingColor(Settings.SecondaryColor) }, LinearGradientMode.Horizontal); MemoryHelpers.GetPointers(); @@ -80,11 +76,11 @@ namespace Artemis.Modules.Games.RocketLeague if (_boostAmount > 100) _boostAmount = 100; - _boostRect.Width = (int) Math.Ceiling(((MainModel.ActiveKeyboard.Width*Scale)/100.00)*_boostAmount); + _boostRect.Width = (int) Math.Ceiling(MainModel.ActiveKeyboard.Width*Scale/100.00*_boostAmount); _boostRect.Colors = new List { - ColorHelpers.ToDrawingColor(_settings.MainColor), - ColorHelpers.ToDrawingColor(_settings.SecondaryColor) + ColorHelpers.ToDrawingColor(Settings.MainColor), + ColorHelpers.ToDrawingColor(Settings.SecondaryColor) }; Task.Run(() => GrowIfHigher()); @@ -102,7 +98,7 @@ namespace Artemis.Modules.Games.RocketLeague var differenceStep = difference/amountOfSteps; var differenceStepRest = difference%amountOfSteps; _boostAmount = _previousBoost; - _boostRect.Width = (int) Math.Ceiling(((MainModel.ActiveKeyboard.Width*Scale)/100.00)*_boostAmount); + _boostRect.Width = (int) Math.Ceiling(MainModel.ActiveKeyboard.Width*Scale/100.00*_boostAmount); for (var i = 0; i < amountOfSteps; i++) { @@ -110,10 +106,10 @@ namespace Artemis.Modules.Games.RocketLeague { differenceStepRest -= 1; _boostAmount += 1; - _boostRect.Width = (int) Math.Ceiling(((MainModel.ActiveKeyboard.Width*Scale)/100.00)*_boostAmount); + _boostRect.Width = (int) Math.Ceiling(MainModel.ActiveKeyboard.Width*Scale/100.00*_boostAmount); } _boostAmount += differenceStep; - _boostRect.Width = (int) Math.Ceiling(((MainModel.ActiveKeyboard.Width*Scale)/100.00)*_boostAmount); + _boostRect.Width = (int) Math.Ceiling(MainModel.ActiveKeyboard.Width*Scale/100.00*_boostAmount); Thread.Sleep(50); } diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueSettings.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueSettings.cs index 34de983a6..2947b8ae5 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueSettings.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueSettings.cs @@ -14,14 +14,14 @@ namespace Artemis.Modules.Games.RocketLeague public Color MainColor { get; set; } public Color SecondaryColor { get; set; } - public override sealed void Load() + public sealed override void Load() { Enabled = RocketLeague.Default.Enabled; MainColor = RocketLeague.Default.MainColor; SecondaryColor = RocketLeague.Default.SecondaryColor; } - public override sealed void Save() + public sealed override void Save() { RocketLeague.Default.Enabled = Enabled; RocketLeague.Default.MainColor = MainColor; @@ -30,7 +30,7 @@ namespace Artemis.Modules.Games.RocketLeague RocketLeague.Default.Save(); } - public override sealed void ToDefault() + public sealed override void ToDefault() { Enabled = true; MainColor = Color.FromArgb(255, 255, 80, 0); diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueView.xaml b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueView.xaml index dea114a08..de8718bc1 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueView.xaml +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueView.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" + xmlns:cal="http://www.caliburnproject.org" mc:Ignorable="d" d:DesignHeight="476.986" d:DesignWidth="538.772"> @@ -31,7 +32,9 @@ diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs index 99035e2f5..9aaaf2c4a 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs @@ -51,5 +51,10 @@ namespace Artemis.Modules.Games.RocketLeague SaveSettings(); } + + public void ToggleEffect() + { + RocketLeagueModel.Enabled = _rocketLeagueSettings.Enabled; + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Witcher3/RocketLeagueSettings.cs b/Artemis/Artemis/Modules/Games/Witcher3/RocketLeagueSettings.cs new file mode 100644 index 000000000..88c560f5f --- /dev/null +++ b/Artemis/Artemis/Modules/Games/Witcher3/RocketLeagueSettings.cs @@ -0,0 +1,31 @@ +using Artemis.Models; + +namespace Artemis.Modules.Games.Witcher3 +{ + public class Witcher3Settings : EffectSettings + { + public Witcher3Settings() + { + Load(); + } + + public bool Enabled { get; set; } + + public sealed override void Load() + { + Enabled = Witcher3.Default.Enabled; + } + + public sealed override void Save() + { + Witcher3.Default.Enabled = Enabled; + + Witcher3.Default.Save(); + } + + public sealed override void ToDefault() + { + Enabled = true; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs index 74a6d2e97..ff23fd6b8 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs @@ -6,7 +6,6 @@ using System.Drawing.Drawing2D; using System.IO; using System.Text.RegularExpressions; using Artemis.Models; -using Artemis.Modules.Games.RocketLeague; using Artemis.Utilities.Keyboard; namespace Artemis.Modules.Games.Witcher3 @@ -18,22 +17,21 @@ namespace Artemis.Modules.Games.Witcher3 private KeyboardRectangle _signRect; private string _witcherSettings; - public Witcher3Model(MainModel mainModel, RocketLeagueSettings settings) : base(mainModel) + public Witcher3Model(MainModel mainModel, Witcher3Settings settings) : base(mainModel) { + Settings = settings; Name = "Witcher3"; ProcessName = "witcher3"; Scale = 4; + Enabled = Settings.Enabled; _updateSw = new Stopwatch(); _signRegex = new Regex("ActiveSign=(.*)", RegexOptions.Compiled); } - public int Scale { get; set; } + public Witcher3Settings Settings { get; set; } - public override bool Enabled() - { - return true; // TODO - } + public int Scale { get; set; } public override void Dispose() { diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3View.xaml b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3View.xaml index cdc90c8a4..3321b1567 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3View.xaml +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3View.xaml @@ -3,19 +3,21 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:cal="http://www.caliburnproject.org" mc:Ignorable="d" d:DesignHeight="386.842" d:DesignWidth="554.887"> - + +