diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index 0de9f6336..6eb4fe3f8 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -30,6 +30,12 @@ + + True + + + True + diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 0f459c912..b542dc1d8 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -435,6 +435,7 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer SettingsSingleFileGenerator @@ -474,6 +475,7 @@ + @@ -567,7 +569,7 @@ PreserveNewest - + diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs index bfcfda60b..56031a7e0 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs @@ -44,7 +44,7 @@ namespace Artemis.Modules.Games.CounterStrike return; if (Directory.Exists(((CounterStrikeSettings) GameSettings).GameDirectory + "/csgo/cfg")) { - var cfgFile = Resources.gamestateConfiguration.Replace("{{port}}", + var cfgFile = Resources.csgoGamestateConfiguration.Replace("{{port}}", MainManager.GameStateWebServer.Port.ToString()); File.WriteAllText( ((CounterStrikeSettings) GameSettings).GameDirectory + "/csgo/cfg/gamestate_integration_artemis.cfg", diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2.Designer.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2.Designer.cs index 6f9530bef..f40fe2afa 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2.Designer.cs +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2.Designer.cs @@ -46,5 +46,29 @@ namespace Artemis.Modules.Games.Dota2 { this["GameDirectory"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool CanCastAbility { + get { + return ((bool)(this["CanCastAbility"])); + } + set { + this["CanCastAbility"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool ShowHealth { + get { + return ((bool)(this["ShowHealth"])); + } + set { + this["ShowHealth"] = value; + } + } } } diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2.settings b/Artemis/Artemis/Modules/Games/Dota2/Dota2.settings index a9a33f1de..7444214e6 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2.settings +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2.settings @@ -8,5 +8,11 @@ + + True + + + True + \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs index a5fbff92b..64e4d7176 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs @@ -1,12 +1,15 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; +using Artemis.KeyboardProviders; using Artemis.Managers; using Artemis.Models; using Artemis.Utilities.GameState; +using Artemis.Utilities.Keyboard; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -14,6 +17,8 @@ namespace Artemis.Modules.Games.Dota2 { class Dota2Model : GameModel { + + private KeyboardRegion _topRow; public Dota2Model(MainManager mainManager, Dota2Settings settings) : base(mainManager) { Settings = settings; @@ -29,50 +34,81 @@ namespace Artemis.Modules.Games.Dota2 public Dota2Settings Settings { get; set; } public JObject D2Json { get; set; } public int Scale { get; set; } + public KeyboardRectangle HealthRect { get; set; } + #endregion public override void Dispose() { - Initialized = false; + Initialized = false; MainManager.GameStateWebServer.GameDataReceived -= HandleGameData; } public override void Enable() { Initialized = false; - + _topRow = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "TopRow"); + HealthRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, _topRow.TopLeft.X, + new List(), + LinearGradientMode.Horizontal) + { Height = Scale, ContainedBrush = false }; MainManager.GameStateWebServer.GameDataReceived += HandleGameData; Initialized = true; } public override void Update() { - throw new NotImplementedException(); + if (D2Json == null) + return; + + if (Settings.CanCastAbility) + UpdateAbilities(); + if (Settings.ShowHealth) + UpdateHealth(); + } + + private void UpdateHealth() + { + var health = D2Json["hero"]["health_percent"]; + if((int)health > 66) + HealthRect.Colors = new List { Color.Lime }; + else if ((int) health > 33) + HealthRect.Colors = new List {Color.Yellow}; + else + HealthRect.Colors = new List {Color.Red}; + + } + + private void UpdateAbilities() + { + //Update keys according to the abilities they take. } public override Bitmap GenerateBitmap() { - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); - - using (var g = Graphics.FromImage(bitmap)) - { - g.Clear(Color.Transparent); - } + var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + + using (var g = Graphics.FromImage(bitmap)) + { + g.Clear(Color.Transparent); + HealthRect.Draw(g); + } return bitmap; } - public void HandleGameData(object sender, GameDataReceivedEventArgs e) - { - var jsonString = e.Json.ToString(); - - // Ensure it's CS:GO JSON - if (!jsonString.Contains("Dota 2")) - return; - - // Parse the JSON - D2Json = JsonConvert.DeserializeObject(jsonString); + + public void HandleGameData(object sender, GameDataReceivedEventArgs e) + { + var jsonString = e.Json.ToString(); + + // Ensure it's Dota 2 JSON + if (!jsonString.Contains("Dota 2")) + return; + + // Parse the JSON + D2Json = JsonConvert.DeserializeObject(jsonString); } } } diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2Settings.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2Settings.cs index 6ee180183..f9a87cd21 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2Settings.cs +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2Settings.cs @@ -18,23 +18,31 @@ namespace Artemis.Modules.Games.Dota2 #region Variables public string GameDirectory { get; set; } + public bool CanCastAbility { get; set; } + public bool ShowHealth { get; set; } #endregion public override void Load() { + ShowHealth = Dota2.Default.ShowHealth; + CanCastAbility = Dota2.Default.CanCastAbility; Enabled = Dota2.Default.Enabled; GameDirectory = Dota2.Default.GameDirectory; } public override void Save() { + Dota2.Default.ShowHealth = ShowHealth; + Dota2.Default.CanCastAbility = CanCastAbility; Dota2.Default.Enabled = Enabled; Dota2.Default.GameDirectory = GameDirectory; } public override void ToDefault() { + ShowHealth = true; + CanCastAbility = true; Enabled = false; GameDirectory = string.Empty; } diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2View.xaml b/Artemis/Artemis/Modules/Games/Dota2/Dota2View.xaml index 903ad837d..5a90707c4 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2View.xaml +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2View.xaml @@ -1,59 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -