From dd5889ec3e38279e65673fad7df905462a41d10f Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Tue, 31 May 2016 18:45:26 +0200 Subject: [PATCH] Cleaned up margins in views, improved Corsair mouse/headset null-handling. Added theme switching (WIP) --- Artemis/Artemis/App.config | 3 + Artemis/Artemis/App.xaml | 4 +- Artemis/Artemis/Artemis.csproj | 4 +- .../Corsair/CorsairHeadsets.cs | 42 +++---- .../DeviceProviders/Corsair/CorsairMice.cs | 51 ++++----- .../DeviceProviders/Corsair/CorsairRGB.cs | 44 ++++---- Artemis/Artemis/Models/Profiles/LayerModel.cs | 2 +- .../Artemis/Models/Profiles/ProfileModel.cs | 2 +- .../CounterStrike/CounterStrikeView.xaml | 10 +- .../Modules/Games/Dota2/Dota2View.xaml | 9 +- .../Games/TheDivision/TheDivisionView.xaml | 14 +-- .../Modules/Games/Witcher3/Witcher3View.xaml | 11 +- Artemis/Artemis/Settings/General.Designer.cs | 12 ++ Artemis/Artemis/Settings/General.settings | 7 +- Artemis/Artemis/Settings/GeneralSettings.cs | 40 +++++++ .../Flyouts/FlyoutSettingsViewModel.cs | 20 +++- .../Profiles/ProfileEditorViewModel.cs | 5 + .../ViewModels/Profiles/ProfileViewModel.cs | 9 +- .../Views/Flyouts/FlyoutSettingsView.xaml | 33 +++--- .../Views/Profiles/ProfileEditorView.xaml | 106 ++++++++++-------- 20 files changed, 251 insertions(+), 177 deletions(-) diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index 9734b6d7c..b9c62fe8d 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -264,6 +264,9 @@ True + + Light + diff --git a/Artemis/Artemis/App.xaml b/Artemis/Artemis/App.xaml index 7acc3be4c..2221243e0 100644 --- a/Artemis/Artemis/App.xaml +++ b/Artemis/Artemis/App.xaml @@ -15,9 +15,9 @@ + - + diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 0bd2cfdc5..bb57d99e2 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -670,10 +670,10 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile - + Designer MSBuild:Compile diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairHeadsets.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairHeadsets.cs index e52bfc626..ea1c38f01 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairHeadsets.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairHeadsets.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Threading; using System.Windows; using System.Windows.Media; @@ -33,7 +34,7 @@ namespace Artemis.DeviceProviders.Corsair public override void Disable() { if (CueSDK.ProtocolDetails != null) - CueSDK.Reinitialize(true); + CueSDK.Reinitialize(); } public override void UpdateDevice(Brush brush) @@ -65,36 +66,29 @@ namespace Artemis.DeviceProviders.Corsair private static bool CanInitializeSdk() { - // Try for about 10 seconds, in case CUE isn't started yet - var tries = 0; - while (tries < 9) + // If already initialized, return result right away + if (CueSDK.ProtocolDetails != null) + return CueSDK.HeadsetSDK != null; + + // Else try to enable the SDK + for (var tries = 0; tries < 9; tries++) { + if (CueSDK.ProtocolDetails != null) + break; + try { - if (CueSDK.ProtocolDetails == null) - CueSDK.Initialize(true); - else - return true; + CueSDK.Initialize(); } - catch (CUEException e) + catch (Exception) { - if (e.Error != CorsairError.ServerNotFound) - return true; - - tries++; - Thread.Sleep(1000); - continue; + Thread.Sleep(2000); } - catch (WrapperException) - { - CueSDK.Reinitialize(true); - return true; - } - - return true; } - return false; + if (CueSDK.ProtocolDetails == null) + return false; + return CueSDK.HeadsetSDK != null; } } } \ No newline at end of file diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs index 3f272988e..f417b4615 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs @@ -1,25 +1,25 @@ -using System.Linq; +using System; +using System.Linq; using System.Threading; using System.Windows; using System.Windows.Media; using Artemis.Utilities; using CUE.NET; using CUE.NET.Devices.Generic.Enums; -using CUE.NET.Exceptions; using Ninject.Extensions.Logging; namespace Artemis.DeviceProviders.Corsair { internal class CorsairMice : DeviceProvider { - public ILogger Logger { get; set; } - public CorsairMice(ILogger logger) { Logger = logger; Type = DeviceType.Mouse; } + public ILogger Logger { get; set; } + public override bool TryEnable() { CanUse = CanInitializeSdk(); @@ -33,7 +33,7 @@ namespace Artemis.DeviceProviders.Corsair public override void Disable() { if (CueSDK.ProtocolDetails != null) - CueSDK.Reinitialize(true); + CueSDK.Reinitialize(); } public override void UpdateDevice(Brush brush) @@ -42,7 +42,7 @@ namespace Artemis.DeviceProviders.Corsair return; var leds = CueSDK.MouseSDK.Leds.Count(); - var rect = new Rect(new Size(leds*20, leds* 20)); + var rect = new Rect(new Size(leds*20, leds*20)); var img = brush.Dispatcher.Invoke(() => { var visual = new DrawingVisual(); @@ -57,7 +57,7 @@ namespace Artemis.DeviceProviders.Corsair { corsairLed.Color = ledIndex == 0 ? img.GetPixel(0, 0) - : img.GetPixel((ledIndex + 1) * 20 - 1, (ledIndex + 1) * 20 - 1); + : img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1); ledIndex++; } @@ -66,36 +66,29 @@ namespace Artemis.DeviceProviders.Corsair private static bool CanInitializeSdk() { - // Try for about 10 seconds, in case CUE isn't started yet - var tries = 0; - while (tries < 9) + // If already initialized, return result right away + if (CueSDK.ProtocolDetails != null) + return CueSDK.MouseSDK != null; + + // Else try to enable the SDK + for (var tries = 0; tries < 9; tries++) { + if (CueSDK.ProtocolDetails != null) + break; + try { - if (CueSDK.ProtocolDetails == null) - CueSDK.Initialize(true); - else - return true; + CueSDK.Initialize(); } - catch (CUEException e) + catch (Exception) { - if (e.Error != CorsairError.ServerNotFound) - return true; - - tries++; - Thread.Sleep(1000); - continue; + Thread.Sleep(2000); } - catch (WrapperException) - { - CueSDK.Reinitialize(true); - return true; - } - - return true; } - return false; + if (CueSDK.ProtocolDetails == null) + return false; + return CueSDK.MouseSDK != null; } } } \ No newline at end of file diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs index 8c27d6a6e..a59430fb6 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs @@ -1,13 +1,12 @@ -using System.Drawing; +using System; +using System.Drawing; using System.Threading; using System.Windows; using Artemis.Properties; using Artemis.Utilities; using CUE.NET; using CUE.NET.Brushes; -using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Keyboard; -using CUE.NET.Exceptions; namespace Artemis.DeviceProviders.Corsair { @@ -26,34 +25,29 @@ namespace Artemis.DeviceProviders.Corsair public override bool CanEnable() { - // Try for about 10 seconds, in case CUE isn't started yet - var tries = 0; - while (tries < 9) + // If already initialized, return result right away + if (CueSDK.ProtocolDetails != null) + return CueSDK.KeyboardSDK != null; + + // Else try to enable the SDK + for (var tries = 0; tries < 9; tries++) { + if (CueSDK.ProtocolDetails != null) + break; + try { - if (CueSDK.ProtocolDetails == null) - CueSDK.Initialize(true); + CueSDK.Initialize(); } - catch (CUEException e) + catch (Exception) { - if (e.Error == CorsairError.ServerNotFound) - { - tries++; - Thread.Sleep(1000); - continue; - } + Thread.Sleep(2000); } - catch (WrapperException) - { - CueSDK.Reinitialize(true); - return true; - } - - return true; } - return false; + if (CueSDK.ProtocolDetails == null) + return false; + return CueSDK.KeyboardSDK != null; } /// @@ -62,7 +56,7 @@ namespace Artemis.DeviceProviders.Corsair public override void Enable() { if (CueSDK.ProtocolDetails == null) - CueSDK.Initialize(true); + CueSDK.Initialize(); _keyboard = CueSDK.KeyboardSDK; switch (_keyboard.DeviceInfo.Model) @@ -93,7 +87,7 @@ namespace Artemis.DeviceProviders.Corsair public override void Disable() { if (CueSDK.ProtocolDetails != null) - CueSDK.Reinitialize(true); + CueSDK.Reinitialize(); } /// diff --git a/Artemis/Artemis/Models/Profiles/LayerModel.cs b/Artemis/Artemis/Models/Profiles/LayerModel.cs index 524e62b94..1fb1d94d6 100644 --- a/Artemis/Artemis/Models/Profiles/LayerModel.cs +++ b/Artemis/Artemis/Models/Profiles/LayerModel.cs @@ -19,10 +19,10 @@ namespace Artemis.Models.Profiles } public string Name { get; set; } + public int Order { get; set; } public LayerType LayerType { get; set; } public bool Enabled { get; set; } public bool Expanded { get; set; } - public int Order { get; set; } public LayerPropertiesModel Properties { get; set; } public ChildItemCollection Children { get; } diff --git a/Artemis/Artemis/Models/Profiles/ProfileModel.cs b/Artemis/Artemis/Models/Profiles/ProfileModel.cs index 58c30b6dd..99bd715da 100644 --- a/Artemis/Artemis/Models/Profiles/ProfileModel.cs +++ b/Artemis/Artemis/Models/Profiles/ProfileModel.cs @@ -26,9 +26,9 @@ namespace Artemis.Models.Profiles public ChildItemCollection Layers { get; } public string Name { get; set; } + public bool IsDefault { get; set; } public string KeyboardName { get; set; } public string GameName { get; set; } - public bool IsDefault { get; set; } [XmlIgnore] public DrawingVisual DrawingVisual { get; set; } diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml index ac9c61744..0f4f26545 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml @@ -7,14 +7,14 @@ mc:Ignorable="d" d:DesignHeight="476.986" d:DesignWidth="538.772"> - + - + @@ -39,8 +39,8 @@ -