diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 187addca8..2181a19b4 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -491,6 +491,7 @@ + @@ -685,6 +686,7 @@ + @@ -735,6 +737,9 @@ KeyboardPropertiesView.xaml + + LayerKeybindView.xaml + LayerConditionView.xaml @@ -984,6 +989,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/Artemis/Artemis/DeviceProviders/Artemis/NoneKeyboard.cs b/Artemis/Artemis/DeviceProviders/Artemis/NoneKeyboard.cs index eceed8187..c2221c6c7 100644 --- a/Artemis/Artemis/DeviceProviders/Artemis/NoneKeyboard.cs +++ b/Artemis/Artemis/DeviceProviders/Artemis/NoneKeyboard.cs @@ -14,7 +14,7 @@ namespace Artemis.DeviceProviders.Artemis CantEnableText = "Waaaaah, this should not be happening!"; Height = 1; Width = 1; - PreviewSettings = new PreviewSettings(new Thickness(0, 0, 0, 0), Resources.none); + PreviewSettings = new PreviewSettings(new Rect(), Resources.none); } public override void Disable() diff --git a/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProL.cs b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProL.cs index bb5a9f4d0..e71fc43e3 100644 --- a/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProL.cs +++ b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProL.cs @@ -28,7 +28,7 @@ namespace Artemis.DeviceProviders.CoolerMaster Height = 6; Width = 22; - PreviewSettings = new PreviewSettings(new Thickness(-2, -5, 0, 0), Resources.masterkeys_pro_l); + PreviewSettings = new PreviewSettings(new Rect(17, 13, 812, 219), Resources.masterkeys_pro_l); _generalSettings = SettingsProvider.Load(); } @@ -89,4 +89,4 @@ namespace Artemis.DeviceProviders.CoolerMaster } } } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProS.cs b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProS.cs index 8745e56b7..a9275316e 100644 --- a/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProS.cs +++ b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProS.cs @@ -28,7 +28,7 @@ namespace Artemis.DeviceProviders.CoolerMaster Height = 6; Width = 18; - PreviewSettings = new PreviewSettings(new Thickness(0, 0, 0, 0), Resources.masterkeys_pro_s); + PreviewSettings = new PreviewSettings(new Rect(13, 12, 657, 219), Resources.masterkeys_pro_s); _generalSettings = SettingsProvider.Load(); } @@ -89,4 +89,4 @@ namespace Artemis.DeviceProviders.CoolerMaster } } } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboard.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboard.cs index 21c0cf413..5d4c9b212 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboard.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboard.cs @@ -55,7 +55,7 @@ namespace Artemis.DeviceProviders.Corsair Height = 7; Width = 25; Slug = "corsair-k95-rgb"; - PreviewSettings = new PreviewSettings(new Thickness(12, -12, 12, 5), Resources.k95); + PreviewSettings = new PreviewSettings(new Rect(20, 26, 1066, 282), Resources.k95); break; case "K70 RGB": case "K70 RGB RAPIDFIRE": @@ -63,7 +63,7 @@ namespace Artemis.DeviceProviders.Corsair Height = 7; Width = 21; Slug = "corsair-k70-rgb"; - PreviewSettings = new PreviewSettings(new Thickness(12, -12, 12, 5), Resources.k70); + PreviewSettings = new PreviewSettings(new Rect(15, 26, 929, 282), Resources.k70); break; case "K65 RGB": case "CGK65 RGB": @@ -72,13 +72,13 @@ namespace Artemis.DeviceProviders.Corsair Height = 7; Width = 18; Slug = "corsair-k65-rgb"; - PreviewSettings = new PreviewSettings(new Thickness(12, -12, 12, 5), Resources.k65); + PreviewSettings = new PreviewSettings(new Rect(15, 30, 747, 363), Resources.k65); break; case "STRAFE RGB": Height = 7; Width = 22; Slug = "corsair-strafe-rgb"; - PreviewSettings = new PreviewSettings(new Thickness(12, -12, 12, 5), Resources.strafe); + PreviewSettings = new PreviewSettings(new Rect(23, 30, 984, 375), Resources.strafe); break; } @@ -154,7 +154,7 @@ namespace Artemis.DeviceProviders.Corsair return null; var center = cueLed.LedRectangle.GetCenter(); - return new KeyMatch(keyCode, (int)(center.X * widthMultiplier), (int)(center.Y * heightMultiplier)); + return new KeyMatch(keyCode, (int) (center.X * widthMultiplier), (int) (center.Y * heightMultiplier)); } } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/DeviceProviders/KeyboardProvider.cs b/Artemis/Artemis/DeviceProviders/KeyboardProvider.cs index 98fc47144..c2d767bca 100644 --- a/Artemis/Artemis/DeviceProviders/KeyboardProvider.cs +++ b/Artemis/Artemis/DeviceProviders/KeyboardProvider.cs @@ -4,6 +4,8 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; +using System.Windows.Media.Imaging; +using Artemis.Utilities; using MahApps.Metro.Controls.Dialogs; using Size = System.Windows.Size; @@ -31,9 +33,9 @@ namespace Artemis.DeviceProviders /// Returns a bitmap matching the keyboard's dimensions using the provided scale /// /// - public Bitmap KeyboardBitmap(int scale = 4) => new Bitmap(Width*scale, Height*scale); + public Bitmap KeyboardBitmap(int scale = 4) => new Bitmap(Width * scale, Height * scale); - public Rect KeyboardRectangle(int scale = 4) => new Rect(new Size(Width*scale, Height*scale)); + public Rect KeyboardRectangle(int scale = 4) => new Rect(new Size(Width * scale, Height * scale)); /// /// Runs CanEnable asynchronously multiple times until successful, cancelled or max tries reached @@ -56,7 +58,7 @@ namespace Artemis.DeviceProviders return false; } // Updated progress to indicate how much tries are left - dialog.SetProgress(0.1*tries); + dialog.SetProgress(0.1 * tries); } if (CanEnable()) @@ -115,13 +117,16 @@ namespace Artemis.DeviceProviders public struct PreviewSettings { - public Thickness Margin { get; set; } - public Bitmap Image { get; set; } + public Rect OverlayRectangle { get; set; } + public Rect BackgroundRectangle { get; set; } + public BitmapImage Image { get; set; } - public PreviewSettings(Thickness margin, Bitmap image) + public PreviewSettings(Rect overlayRectangle, Bitmap bitmap) { - Margin = margin; - Image = image; + OverlayRectangle = overlayRectangle; + BackgroundRectangle = new Rect(0, 0, bitmap.Width, bitmap.Height); + Image = ImageUtilities.BitmapToBitmapImage(bitmap); + Image.Freeze(); } } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/DeviceProviders/Logitech/G810.cs b/Artemis/Artemis/DeviceProviders/Logitech/G810.cs index b1496acb7..75b82713d 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/G810.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/G810.cs @@ -22,7 +22,7 @@ namespace Artemis.DeviceProviders.Logitech "If needed, you can select a different keyboard in Artemis under settings."; Height = 6; Width = 21; - PreviewSettings = new PreviewSettings(new Thickness(0, 35, 0, 0), Resources.g810); + PreviewSettings = new PreviewSettings(new Rect(19, 70, 1010, 269), Resources.g810); _generalSettings = SettingsProvider.Load(); } diff --git a/Artemis/Artemis/DeviceProviders/Logitech/G910.cs b/Artemis/Artemis/DeviceProviders/Logitech/G910.cs index 5e90e32f5..7339d8fac 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/G910.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/G910.cs @@ -24,7 +24,7 @@ namespace Artemis.DeviceProviders.Logitech "If needed, you can select a different keyboard in Artemis under settings."; Height = 7; Width = 22; - PreviewSettings = new PreviewSettings(new Thickness(20, -55, 20, 65), Resources.g910); + PreviewSettings = new PreviewSettings(new Rect(34, 18, 916, 272), Resources.g910); _generalSettings = SettingsProvider.Load(); } @@ -54,7 +54,7 @@ namespace Artemis.DeviceProviders.Logitech /// public override void DrawBitmap(Bitmap bitmap) { - using (var croppedBitmap = new Bitmap(21*4, 6*4)) + using (var croppedBitmap = new Bitmap(21 * 4, 6 * 4)) { // Deal with non-standard DPI croppedBitmap.SetResolution(96, 96); @@ -91,11 +91,11 @@ namespace Artemis.DeviceProviders.Logitech private void SetLogitechColorFromCoordinates(Bitmap bitmap, KeyboardNames key, int x, int y) { var color = bitmap.GetPixel(x, y); - var rPer = (int) Math.Round(color.R/2.55); - var gPer = (int) Math.Round(color.G/2.55); - var bPer = (int) Math.Round(color.B/2.55); + var rPer = (int) Math.Round(color.R / 2.55); + var gPer = (int) Math.Round(color.G / 2.55); + var bPer = (int) Math.Round(color.B / 2.55); LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(key, rPer, gPer, bPer); } } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/DeviceProviders/Razer/BlackWidow.cs b/Artemis/Artemis/DeviceProviders/Razer/BlackWidow.cs index 036545fbf..bc185fc6c 100644 --- a/Artemis/Artemis/DeviceProviders/Razer/BlackWidow.cs +++ b/Artemis/Artemis/DeviceProviders/Razer/BlackWidow.cs @@ -27,7 +27,7 @@ namespace Artemis.DeviceProviders.Razer Height = Constants.MaxRows; Width = Constants.MaxColumns; - PreviewSettings = new PreviewSettings(new Thickness(0, -15, 0, 0), Resources.blackwidow); + PreviewSettings = new PreviewSettings(new Rect(26, 56, 906, 234), Resources.blackwidow); _generalSettings = SettingsProvider.Load(); } @@ -72,4 +72,4 @@ namespace Artemis.DeviceProviders.Razer } } } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/Managers/KeybindManager.cs b/Artemis/Artemis/Managers/KeybindManager.cs index b75ee5741..ff4e8a6ba 100644 --- a/Artemis/Artemis/Managers/KeybindManager.cs +++ b/Artemis/Artemis/Managers/KeybindManager.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Windows.Forms; using System.Windows.Input; @@ -16,13 +17,13 @@ namespace Artemis.Managers static KeybindManager() { - KeyboardHook.KeyDownCallback += args => ProcessKey(args, KeyType.KeyDown); - KeyboardHook.KeyUpCallback += args => ProcessKey(args, KeyType.KeyUp); - KeyboardHook.MouseDownCallback += args => ProcessMouse(args, KeyType.MouseDown); - KeyboardHook.MouseUpCallback += args => ProcessMouse(args, KeyType.MouseUp); + KeyboardHook.KeyDownCallback += args => ProcessKey(args, PressType.Down); + KeyboardHook.KeyUpCallback += args => ProcessKey(args, PressType.Up); + KeyboardHook.MouseDownCallback += args => ProcessMouse(args, PressType.Down); + KeyboardHook.MouseUpCallback += args => ProcessMouse(args, PressType.Up); } - private static void ProcessKey(KeyEventArgs keyEventArgs, KeyType keyType) + private static void ProcessKey(KeyEventArgs keyEventArgs, PressType pressType) { // Don't trigger if the key itself is a modifier if (keyEventArgs.KeyCode == Keys.LShiftKey || keyEventArgs.KeyCode == Keys.RShiftKey || @@ -37,17 +38,20 @@ namespace Artemis.Managers var hotKey = new HotKey(KeyInterop.KeyFromVirtualKey(keyEventArgs.KeyValue), modifiers); foreach (var keybindModel in KeybindModels) - keybindModel.InvokeIfMatched(hotKey, keyType); + keybindModel.InvokeIfMatched(hotKey, pressType); } - private static void ProcessMouse(MouseEventArgs mouseEventArgs, KeyType keyType) + private static void ProcessMouse(MouseEventArgs mouseEventArgs, PressType pressType) { foreach (var keybindModel in KeybindModels) - keybindModel.InvokeIfMatched(mouseEventArgs.Button, keyType); + keybindModel.InvokeIfMatched(mouseEventArgs.Button, pressType); } public static void AddOrUpdate(KeybindModel keybindModel) { + if (keybindModel == null) + return; + var existing = KeybindModels.FirstOrDefault(k => k.Name == keybindModel.Name); if (existing != null) KeybindModels.Remove(existing); diff --git a/Artemis/Artemis/Models/KeybindModel.cs b/Artemis/Artemis/Models/KeybindModel.cs index 1b4587648..062e8b7c0 100644 --- a/Artemis/Artemis/Models/KeybindModel.cs +++ b/Artemis/Artemis/Models/KeybindModel.cs @@ -6,40 +6,40 @@ namespace Artemis.Models { public class KeybindModel { - public KeybindModel(string name, HotKey hotKey, KeyType keyType, Action action) + public KeybindModel(string name, HotKey hotKey, PressType pressType, Action action) { Name = name; HotKey = hotKey; - KeyType = keyType; + PressType = pressType; Action = action; } - public KeybindModel(string name, MouseButtons mouseButtons, KeyType keyType, Action action) + public KeybindModel(string name, MouseButtons mouseButtons, PressType pressType, Action action) { Name = name; MouseButtons = mouseButtons; - KeyType = keyType; + PressType = pressType; Action = action; } public string Name { get; set; } public HotKey HotKey { get; set; } - public MouseButtons MouseButtons { get; } - public KeyType KeyType { get; set; } + public MouseButtons? MouseButtons { get; } + public PressType PressType { get; set; } public Action Action { get; set; } - public void InvokeIfMatched(HotKey hotKey, KeyType keyType) + public void InvokeIfMatched(HotKey hotKey, PressType pressType) { - if (HotKey == null || hotKey == null || KeyType != keyType) + if (HotKey == null || hotKey == null || PressType != pressType) return; if (hotKey.Equals(HotKey)) Action?.Invoke(); } - public void InvokeIfMatched(MouseButtons mouseButtons, KeyType keyType) + public void InvokeIfMatched(MouseButtons mouseButtons, PressType pressType) { - if (KeyType != keyType) + if (PressType != pressType) return; if (mouseButtons.Equals(MouseButtons)) @@ -47,11 +47,9 @@ namespace Artemis.Models } } - public enum KeyType + public enum PressType { - KeyDown, - KeyUp, - MouseDown, - MouseUp + Down, + Up } } diff --git a/Artemis/Artemis/Modules/General/Bubbles/Bubble.cs b/Artemis/Artemis/Modules/General/Bubbles/Bubble.cs index 8f4976c92..90fb662b6 100644 --- a/Artemis/Artemis/Modules/General/Bubbles/Bubble.cs +++ b/Artemis/Artemis/Modules/General/Bubbles/Bubble.cs @@ -1,5 +1,7 @@ -using System.Drawing; -using System.Windows; +using System.Windows; +using System.Windows.Media; +using Artemis.Utilities; +using Color = System.Drawing.Color; using Point = System.Windows.Point; namespace Artemis.Modules.General.Bubbles @@ -20,7 +22,7 @@ namespace Artemis.Modules.General.Bubbles #region Properties & Fields - private Brush _brush; + private SolidColorBrush _brush; private Color _color; @@ -30,7 +32,7 @@ namespace Artemis.Modules.General.Bubbles set { _color = value; - _brush = new SolidBrush(_color); + _brush = new SolidColorBrush(ColorHelpers.ToMediaColor(_color)); } } @@ -45,10 +47,10 @@ namespace Artemis.Modules.General.Bubbles public void CheckCollision(Rect border) { if (Position.X - Radius < border.X || Position.X + Radius > border.X + border.Width) - Direction = new Vector(Direction.X*-1, Direction.Y); + Direction = new Vector(Direction.X * -1, Direction.Y); if (Position.Y - Radius < border.Y || Position.Y + Radius > border.Y + border.Height) - Direction = new Vector(Direction.X, Direction.Y*-1); + Direction = new Vector(Direction.X, Direction.Y * -1); } public void Move() @@ -56,11 +58,11 @@ namespace Artemis.Modules.General.Bubbles Position += Direction; } - public void Draw(Graphics g) + public void Draw(DrawingContext drawingContext) { - g.FillEllipse(_brush, (float) Position.X - Radius, (float) Position.Y - Radius, Radius*2, Radius*2); + drawingContext.DrawEllipse(_brush, new Pen(_brush, 1), new Point((float) Position.X - Radius, (float) Position.Y - Radius), Radius * 2, Radius * 2); } #endregion } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/Modules/General/Bubbles/BubblesModel.cs b/Artemis/Artemis/Modules/General/Bubbles/BubblesModel.cs index 06c45100d..d3f95b795 100644 --- a/Artemis/Artemis/Modules/General/Bubbles/BubblesModel.cs +++ b/Artemis/Artemis/Modules/General/Bubbles/BubblesModel.cs @@ -93,11 +93,9 @@ namespace Artemis.Modules.General.Bubbles public override void Render(FrameModel frameModel, bool keyboardOnly) { - using (var g = Graphics.FromImage(frameModel.KeyboardBitmap)) - { - foreach (var bubble in _bubbles) - bubble.Draw(g); - } + var c = frameModel.KeyboardModel.GetDrawingContext(); + foreach (var bubble in _bubbles) + bubble.Draw(c); } #endregion diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerKeybindModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerKeybindModel.cs new file mode 100644 index 000000000..1a693976b --- /dev/null +++ b/Artemis/Artemis/Profiles/Layers/Models/LayerKeybindModel.cs @@ -0,0 +1,101 @@ +using System; +using System.Windows.Forms; +using Artemis.Managers; +using Artemis.Models; +using MahApps.Metro.Controls; + +namespace Artemis.Profiles.Layers.Models +{ + public class LayerKeybindModel + { + private KeybindModel _downKeybind; + private KeybindModel _upKeybind; + + public ToggleType ToggleType { get; set; } + public HotKey HotKey { get; set; } + public MouseButtons? MouseButtons { get; set; } + + public void Unregister() + { + if (_downKeybind != null) + { + KeybindManager.Remove(_downKeybind); + _downKeybind = null; + } + if (_upKeybind != null) + { + KeybindManager.Remove(_upKeybind); + _upKeybind = null; + } + } + + internal void Register(LayerModel layerModel, int index) + { + Unregister(); + + // Bind EnableHeldDown or DisableHeldDOwn + if (ToggleType == ToggleType.EnableHeldDown || ToggleType == ToggleType.DisableHeldDown) + { + Action downAction = null; + Action upAction = null; + switch (ToggleType) + { + case ToggleType.EnableHeldDown: + downAction = () => layerModel.RenderAllowed = true; + upAction = () => layerModel.RenderAllowed = false; + break; + case ToggleType.DisableHeldDown: + downAction = () => layerModel.RenderAllowed = false; + upAction = () => layerModel.RenderAllowed = true; + break; + } + + // Either bind HotKey or mouse buttons depending on what isn't null + if (HotKey != null) + { + _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", HotKey, PressType.Down, downAction); + _upKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-up", HotKey, PressType.Up, upAction); + } + else if (MouseButtons != null) + { + _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", MouseButtons.Value, PressType.Down, downAction); + _upKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-up", MouseButtons.Value, PressType.Up, upAction); + } + KeybindManager.AddOrUpdate(_downKeybind); + KeybindManager.AddOrUpdate(_upKeybind); + return; + } + + // Bind Enable, Disable or Toggle + Action action = null; + switch (ToggleType) + { + case ToggleType.Enable: + action = () => layerModel.RenderAllowed = true; + break; + case ToggleType.Disable: + action = () => layerModel.RenderAllowed = false; + break; + case ToggleType.Toggle: + action = () => layerModel.RenderAllowed = !layerModel.RenderAllowed; + break; + } + + // Either bind HotKey or mouse buttons depending on what isn't null + if (HotKey != null) + _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", HotKey, PressType.Down, action); + else if (MouseButtons != null) + _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", MouseButtons.Value, PressType.Down, action); + KeybindManager.AddOrUpdate(_downKeybind); + } + } + + public enum ToggleType + { + Enable, + Disable, + Toggle, + EnableHeldDown, + DisableHeldDown + } +} diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs index de7a5e7f1..eec55dbb9 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs @@ -39,7 +39,7 @@ namespace Artemis.Profiles.Layers.Models /// /// /// - public bool ConditionsMet(ModuleDataModel dataModel) + public bool AreConditionsMet(ModuleDataModel dataModel) { // Conditions are not even checked if the layer isn't enabled return Enabled && LayerCondition.ConditionsMet(this, dataModel); @@ -92,7 +92,7 @@ namespace Artemis.Profiles.Layers.Models /// public void Draw(ModuleDataModel dataModel, DrawingContext c, bool preview, bool updateAnimations) { - if (Brush == null) + if (Brush == null || !preview && !RenderAllowed) return; LayerType.Draw(this, c); @@ -107,14 +107,12 @@ namespace Artemis.Profiles.Layers.Models // If the type is an event, set it up if (IsEvent && EventProperties == null) - { EventProperties = new KeyboardEventPropertiesModel { ExpirationType = ExpirationType.Time, Length = new TimeSpan(0, 0, 1), TriggerDelay = new TimeSpan(0) }; - } } /// @@ -221,19 +219,15 @@ namespace Artemis.Profiles.Layers.Models if (Parent != null) { foreach (var child in Parent.Children.OrderBy(c => c.Order)) - { if (child.Order >= source.Order) child.Order++; - } Parent.Children.Add(source); } else if (Profile != null) { foreach (var layer in Profile.Layers.OrderBy(l => l.Order)) - { if (layer.Order >= source.Order) layer.Order++; - } Profile.Layers.Add(source); } } @@ -247,7 +241,7 @@ namespace Artemis.Profiles.Layers.Models if (height < 0) height = 0; - return new Rect(X*scale, Y*scale, width*scale, height*scale); + return new Rect(X * scale, Y * scale, width * scale, height * scale); } /// @@ -267,10 +261,8 @@ namespace Artemis.Profiles.Layers.Models continue; if (!ignoreConditions) - { - if (!layerModel.ConditionsMet(dataModel)) + if (!layerModel.AreConditionsMet(dataModel)) continue; - } layers.Add(layerModel); layers.AddRange(layerModel.GetRenderLayers(dataModel, keyboardOnly, ignoreConditions)); @@ -287,6 +279,24 @@ namespace Artemis.Profiles.Layers.Models LayerCondition = new DataModelCondition(); } + public void SetupKeybinds() + { + // Clean up old keybinds + RemoveKeybinds(); + + for (var index = 0; index < Properties.LayerKeybindModels.Count; index++) + { + var keybindModel = Properties.LayerKeybindModels[index]; + keybindModel.Register(this, index); + } + } + + public void RemoveKeybinds() + { + foreach (var keybindModel in Properties.LayerKeybindModels) + keybindModel.Unregister(); + } + #region Properties #region Layer type properties @@ -302,6 +312,7 @@ namespace Artemis.Profiles.Layers.Models public string Name { get; set; } public int Order { get; set; } public bool Enabled { get; set; } + public bool RenderAllowed { get; set; } public bool Expanded { get; set; } public bool IsEvent { get; set; } public LayerPropertiesModel Properties { get; set; } @@ -391,7 +402,7 @@ namespace Artemis.Profiles.Layers.Models get { return Profile; } set { Profile = value; } } - + #endregion } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs index c8720f1a4..c1ec39f17 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs @@ -25,6 +25,7 @@ namespace Artemis.Profiles.Layers.Models Opacity = source.Opacity; AnimationSpeed = source.AnimationSpeed; Conditions = source.Conditions; + LayerKeybindModels = source.LayerKeybindModels; ConditionType = source.ConditionType; DynamicProperties = source.DynamicProperties; Brush = source.Brush; @@ -50,7 +51,8 @@ namespace Artemis.Profiles.Layers.Models public string HeightEase { get; set; } public string OpacityEase { get; set; } public ConditionType ConditionType { get; set; } - public List Conditions { get; set; } = new List(); + public List Conditions { get; set; } = new List(); + public List LayerKeybindModels { get; set; } = new List(); public List DynamicProperties { get; set; } = new List(); [JsonConverter(typeof(BrushJsonConverter))] diff --git a/Artemis/Artemis/Profiles/Layers/Types/ConicalBrush/ConicalBrushPropertiesView.xaml b/Artemis/Artemis/Profiles/Layers/Types/ConicalBrush/ConicalBrushPropertiesView.xaml index d2a9ad61b..b406c297d 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/ConicalBrush/ConicalBrushPropertiesView.xaml +++ b/Artemis/Artemis/Profiles/Layers/Types/ConicalBrush/ConicalBrushPropertiesView.xaml @@ -10,27 +10,23 @@ - - - - + + + + - - - - - - - - + + + + + + + - - + diff --git a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericPropertiesView.xaml b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericPropertiesView.xaml index 7745310f3..a093f1de5 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericPropertiesView.xaml +++ b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericPropertiesView.xaml @@ -4,73 +4,57 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ncore="http://schemas.ncore.com/wpf/xaml/colorbox" - xmlns:ObjectModel="clr-namespace:System.Collections.ObjectModel;assembly=System" x:Class="Artemis.Profiles.Layers.Types.Generic.GenericPropertiesView" mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="500"> + - - - - + + + + - - - - - - + + + + + - - + /// Name of the keybind /// Hotkey in string format, per example: ALT+CTRL+SHIFT+D - /// The key type, either key up or key down + /// The key type, either key up or key down /// LUA function to call /// Optional arguments for the passed function - public void SetKeybind(string name, string hotKey, KeyType keyType, DynValue function, params DynValue[] args) + public void SetKeybind(string name, string hotKey, PressType pressType, DynValue function, params DynValue[] args) { - if (keyType != KeyType.KeyDown && keyType != KeyType.KeyUp) - throw new ScriptRuntimeException("Key type must either be KeyDown or KeyUp."); + if (pressType != PressType.Down && pressType != PressType.Up) + throw new ScriptRuntimeException("Key type must either be Down or Up."); var modifierKeys = ModifierKeys.None; var key = Key.System; @@ -59,8 +59,8 @@ namespace Artemis.Profiles.Lua.Modules var hk = new HotKey(key, modifierKeys); var model = args != null - ? new KeybindModel("LUA-" + name, hk, keyType, () => LuaManager.Call(function, args)) - : new KeybindModel("LUA-" + name, hk, keyType, () => LuaManager.Call(function)); + ? new KeybindModel("LUA-" + name, hk, pressType, () => LuaManager.Call(function, args)) + : new KeybindModel("LUA-" + name, hk, pressType, () => LuaManager.Call(function)); KeybindManager.AddOrUpdate(model); diff --git a/Artemis/Artemis/Profiles/ProfileModel.cs b/Artemis/Artemis/Profiles/ProfileModel.cs index b74841a87..eea4ad237 100644 --- a/Artemis/Artemis/Profiles/ProfileModel.cs +++ b/Artemis/Artemis/Profiles/ProfileModel.cs @@ -92,7 +92,7 @@ namespace Artemis.Profiles continue; if (!ignoreConditions) - if (!layerModel.ConditionsMet(dataModel)) + if (!layerModel.AreConditionsMet(dataModel)) continue; layers.Add(layerModel); @@ -223,45 +223,14 @@ namespace Artemis.Profiles public void ApplyKeybinds() { -// _profileBinds.Clear(); -// foreach (var layerModel in GetLayers()) -// { -// for (var index = 0; index < layerModel.Properties.Conditions.Count; index++) -// { -// var condition = layerModel.Properties.Conditions[index]; -// if (condition.Field == null || !condition.Field.Contains("hotkey")) -// continue; -// -// // Create an action for the layer, the layer's specific condition type handles activation -// if (condition.Operator == "held") -// { -// var downAction = new Action(() => layerModel.LayerCondition.KeyDownTask(condition)); -// var downKb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-down-{index}", condition.HotKey, KeyType.KeyDown, downAction); -// var upAction = new Action(() => layerModel.LayerCondition.KeyUpTask(condition)); -// var upKb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-up-{index}", condition.HotKey, KeyType.KeyUp, upAction); -// -// KeybindManager.AddOrUpdate(downKb); -// KeybindManager.AddOrUpdate(upKb); -// _profileBinds.Add(downKb); -// _profileBinds.Add(upKb); -// } -// else -// { -// var action = new Action(() => layerModel.LayerCondition.KeyDownTask(condition)); -// var kb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, KeyType.KeyDown, action); -// -// KeybindManager.AddOrUpdate(kb); -// _profileBinds.Add(kb); -// } -// } -// } + foreach (var layerModel in GetLayers()) + layerModel.SetupKeybinds(); } public void ClearKeybinds() { -// foreach (var keybindModel in _profileBinds) -// KeybindManager.Remove(keybindModel); -// _profileBinds.Clear(); + foreach (var layerModel in GetLayers()) + layerModel.RemoveKeybinds(); } #region Compare @@ -275,9 +244,12 @@ namespace Artemis.Profiles public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; + if (ReferenceEquals(null, obj)) + return false; + if (ReferenceEquals(this, obj)) + return true; + if (obj.GetType() != GetType()) + return false; return Equals((ProfileModel) obj); } diff --git a/Artemis/Artemis/Utilities/ImageUtilities.cs b/Artemis/Artemis/Utilities/ImageUtilities.cs index 71bc16df9..79a202919 100644 --- a/Artemis/Artemis/Utilities/ImageUtilities.cs +++ b/Artemis/Artemis/Utilities/ImageUtilities.cs @@ -54,7 +54,7 @@ namespace Artemis.Utilities bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); - + return bitmapImage; } } diff --git a/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs b/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs index 8d89ea92b..e4091b62e 100644 --- a/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs @@ -44,7 +44,9 @@ namespace Artemis.ViewModels // Setup existing conditions var conditions = ProposedLayer.Properties.Conditions.Select(c => new LayerConditionViewModel(this, c)); + var keyBinds = ProposedLayer.Properties.LayerKeybindModels.Select(c => new LayerKeybindViewModel(this, c)); LayerConditionVms = new BindableCollection(conditions); + LayerKeybindVms = new BindableCollection(keyBinds); PropertyChanged += PropertiesViewModelHandler; @@ -60,6 +62,7 @@ namespace Artemis.ViewModels public BindableCollection LayerTypes { get; set; } public BindableCollection DataModelProps { get; set; } public BindableCollection LayerConditionVms { get; set; } + public BindableCollection LayerKeybindVms { get; set; } public bool KeyboardGridIsVisible => ProposedLayer.LayerType is KeyboardType; public bool GifGridIsVisible => ProposedLayer.LayerType is KeyboardGifType; @@ -68,7 +71,8 @@ namespace Artemis.ViewModels get { return _layer; } set { - if (Equals(value, _layer)) return; + if (Equals(value, _layer)) + return; _layer = value; NotifyOfPropertyChange(() => Layer); } @@ -81,7 +85,8 @@ namespace Artemis.ViewModels get { return _proposedLayer; } set { - if (Equals(value, _proposedLayer)) return; + if (Equals(value, _proposedLayer)) + return; _proposedLayer = value; NotifyOfPropertyChange(() => ProposedLayer); } @@ -92,7 +97,8 @@ namespace Artemis.ViewModels get { return _layerPropertiesViewModel; } set { - if (Equals(value, _layerPropertiesViewModel)) return; + if (Equals(value, _layerPropertiesViewModel)) + return; _layerPropertiesViewModel = value; NotifyOfPropertyChange(() => LayerPropertiesViewModel); } @@ -103,7 +109,8 @@ namespace Artemis.ViewModels get { return _eventPropertiesViewModel; } set { - if (Equals(value, _eventPropertiesViewModel)) return; + if (Equals(value, _eventPropertiesViewModel)) + return; _eventPropertiesViewModel = value; NotifyOfPropertyChange(() => EventPropertiesViewModel); } @@ -114,7 +121,8 @@ namespace Artemis.ViewModels get { return _selectedLayerType; } set { - if (Equals(value, _selectedLayerType)) return; + if (Equals(value, _selectedLayerType)) + return; _selectedLayerType = value; NotifyOfPropertyChange(() => SelectedLayerType); } @@ -167,15 +175,27 @@ namespace Artemis.ViewModels LayerConditionVms.Add(new LayerConditionViewModel(this, condition)); } + public void AddKeybind() + { + var keybind = new LayerKeybindModel(); + LayerKeybindVms.Add(new LayerKeybindViewModel(this, keybind)); + } + public void Apply() { LayerPropertiesViewModel?.ApplyProperties(); Layer.Properties.DynamicProperties.Clear(); JsonConvert.PopulateObject(JsonConvert.SerializeObject(ProposedLayer), Layer); + Layer.Properties.Conditions.Clear(); foreach (var conditionViewModel in LayerConditionVms) - Layer.Properties.Conditions.Add(conditionViewModel.ConditionModel); + Layer.Properties.Conditions.Add(conditionViewModel.ConditionModel); + + Layer.Properties.LayerKeybindModels.Clear(); + foreach (var layerKeybindViewModel in LayerKeybindVms) + Layer.Properties.LayerKeybindModels.Add(layerKeybindViewModel.LayerKeybindModel); + // TODO: EventPropVM must have layer too if (EventPropertiesViewModel != null) @@ -190,13 +210,6 @@ namespace Artemis.ViewModels DialogService.ShowErrorMessageBox("Couldn't find or access the provided GIF file."); } - public void DeleteCondition(LayerConditionViewModel layerConditionViewModel, - LayerConditionModel layerConditionModel) - { - LayerConditionVms.Remove(layerConditionViewModel); - Layer.Properties.Conditions.Remove(layerConditionModel); - } - public override async void CanClose(Action callback) { // Create a fake layer and apply the properties to it @@ -204,9 +217,17 @@ namespace Artemis.ViewModels // TODO: EventPropVM must have layer too if (EventPropertiesViewModel != null) ProposedLayer.EventProperties = EventPropertiesViewModel.GetAppliedProperties(); + ProposedLayer.Properties.Conditions.Clear(); foreach (var conditionViewModel in LayerConditionVms) - ProposedLayer.Properties.Conditions.Add(conditionViewModel.ConditionModel); + ProposedLayer.Properties.Conditions.Add(conditionViewModel.ConditionModel); + + ProposedLayer.Properties.LayerKeybindModels.Clear(); + foreach (var layerKeybindViewModel in LayerKeybindVms) + ProposedLayer.Properties.LayerKeybindModels.Add(layerKeybindViewModel.LayerKeybindModel); + + // Ignore this property as it isn't user input + ProposedLayer.RenderAllowed = Layer.RenderAllowed; // If not a keyboard, ignore size and position if ((ProposedLayer.LayerType.DrawType != DrawType.Keyboard) || !ProposedLayer.LayerType.ShowInEdtor) @@ -236,9 +257,8 @@ namespace Artemis.ViewModels return; } - var close = await DialogService - .ShowQuestionMessageBox("Unsaved changes", "Do you want to discard your changes?"); + var close = await DialogService.ShowQuestionMessageBox("Unsaved changes", "Do you want to discard your changes?"); callback(close.Value); } } -} \ No newline at end of file +} diff --git a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs index 51cb959bd..a46c22ed1 100644 --- a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -65,8 +66,8 @@ namespace Artemis.ViewModels _loopManager = loopManager; _moduleModel = moduleModel; _dialogService = dialogService; - _copyKeybind = new KeybindModel("copy", new HotKey(Key.C, ModifierKeys.Control), KeyType.KeyDown, LayerToClipboard); - _pasteKeybind = new KeybindModel("paste", new HotKey(Key.V, ModifierKeys.Control), KeyType.KeyDown, ClipboardToLayer); + _copyKeybind = new KeybindModel("copy", new HotKey(Key.C, ModifierKeys.Control), PressType.Down, LayerToClipboard); + _pasteKeybind = new KeybindModel("paste", new HotKey(Key.V, ModifierKeys.Control), PressType.Up, ClipboardToLayer); ProfileNames = new ObservableCollection(); Layers = new ObservableCollection(); @@ -197,10 +198,8 @@ namespace Artemis.ViewModels NotifyOfPropertyChange(() => LayerSelected); } } - - public ImageSource KeyboardImage => ImageUtilities.BitmapToBitmapImage(_deviceManager.ActiveKeyboard?.PreviewSettings.Image ?? Resources.none); + public ProfileModel SelectedProfile => _moduleModel?.ProfileModel; - public PreviewSettings? PreviewSettings => _deviceManager.ActiveKeyboard?.PreviewSettings; public bool ProfileSelected => SelectedProfile != null; public bool LayerSelected => SelectedProfile != null && SelectedLayer != null; public bool EditorEnabled => SelectedProfile != null && !SelectedProfile.IsDefault && _deviceManager.ActiveKeyboard != null; @@ -507,8 +506,7 @@ namespace Artemis.ViewModels private void LoopManagerOnRenderCompleted(object sender, EventArgs eventArgs) { // Besides the usual checks, also check if the ActiveKeyboard isn't the NoneKeyboard - if (SelectedProfile == null || _deviceManager.ActiveKeyboard == null || - _deviceManager.ActiveKeyboard.Slug == "none") + if (SelectedProfile == null || _deviceManager.ActiveKeyboard == null || _deviceManager.ActiveKeyboard.Slug == "none") { KeyboardPreview = null; @@ -519,6 +517,28 @@ namespace Artemis.ViewModels return; } + var renderedLayers = RenderLayers(); + var visual = new DrawingVisual(); + var previewSettings = _deviceManager.ActiveKeyboard.PreviewSettings; + using (var drawingContext = visual.RenderOpen()) + { + var baseRect = new Rect(0, 0, previewSettings.BackgroundRectangle.Width, previewSettings.BackgroundRectangle.Height); + drawingContext.PushClip(new RectangleGeometry(baseRect)); + // Draw the keyboard image + drawingContext.DrawImage(previewSettings.Image, baseRect); + // Draw the layers semi-transparent + drawingContext.PushOpacity(0.8); + drawingContext.DrawImage(renderedLayers, previewSettings.OverlayRectangle); + drawingContext.Pop(); + drawingContext.Pop(); + } + var drawnPreview = new DrawingImage(visual.Drawing); + drawnPreview.Freeze(); + KeyboardPreview = drawnPreview; + } + + private DrawingImage RenderLayers() + { var renderLayers = GetRenderLayers(); // Draw the current frame to the preview var keyboardRect = _deviceManager.ActiveKeyboard.KeyboardRectangle(); @@ -544,7 +564,7 @@ namespace Artemis.ViewModels var preview = new DrawingImage(); preview.Freeze(); KeyboardPreview = preview; - return; + return new DrawingImage(); } var pen = new Pen(new SolidColorBrush((Color) accentColor), 0.4); @@ -578,11 +598,12 @@ namespace Artemis.ViewModels } var drawnPreview = new DrawingImage(visual.Drawing); drawnPreview.Freeze(); - KeyboardPreview = drawnPreview; // Setup layers for the next frame if (_moduleModel.IsInitialized && ActiveWindowHelper.MainWindowActive) _moduleModel.PreviewLayers = renderLayers; + + return drawnPreview; } public List GetRenderLayers() @@ -681,13 +702,21 @@ namespace Artemis.ViewModels private Point GetScaledPosition(MouseEventArgs e) { + var previewSettings = _deviceManager.ActiveKeyboard.PreviewSettings; + var sourceImage = (Image) e.OriginalSource; var pos = e.GetPosition(sourceImage); + var widthScale = sourceImage.ActualWidth / _deviceManager.ActiveKeyboard.PreviewSettings.BackgroundRectangle.Width; + var heightScale = sourceImage.ActualHeight / _deviceManager.ActiveKeyboard.PreviewSettings.BackgroundRectangle.Height; + + // Remove the preview settings' offset from the cursor postion + pos.X = pos.X - (previewSettings.OverlayRectangle.X * widthScale); + pos.Y = pos.Y - (previewSettings.OverlayRectangle.Y * heightScale); // Scale the X and Y position down to match the keyboard's physical size and thus the layer positions - pos.X = pos.X * (SelectedProfile.Width / sourceImage.ActualWidth); - pos.Y = pos.Y * (SelectedProfile.Height / sourceImage.ActualHeight); - + pos.X = pos.X * (SelectedProfile.Width / (previewSettings.OverlayRectangle.Width*widthScale)); + pos.Y = pos.Y * (SelectedProfile.Height / (previewSettings.OverlayRectangle.Height * heightScale)); + return pos; } @@ -866,12 +895,10 @@ namespace Artemis.ViewModels } /// - /// Handles chaning the active keyboard, updating the preview image and profiles collection + /// Handles chaning the active keyboard, updating the profiles collection /// private void DeviceManagerOnOnKeyboardChanged(object sender, KeyboardChangedEventArgs e) { - NotifyOfPropertyChange(() => PreviewSettings); - NotifyOfPropertyChange(() => KeyboardImage); LoadProfiles(); } diff --git a/Artemis/Artemis/ViewModels/Profiles/LayerConditionViewModel.cs b/Artemis/Artemis/ViewModels/Profiles/LayerConditionViewModel.cs index 031447180..c0fc4d2f1 100644 --- a/Artemis/Artemis/ViewModels/Profiles/LayerConditionViewModel.cs +++ b/Artemis/Artemis/ViewModels/Profiles/LayerConditionViewModel.cs @@ -299,7 +299,7 @@ namespace Artemis.ViewModels.Profiles /// public void Delete() { - _editorViewModel.DeleteCondition(this, ConditionModel); + _editorViewModel.LayerConditionVms.Remove(this); } public struct NamedOperator diff --git a/Artemis/Artemis/ViewModels/Profiles/LayerKeybindViewModel.cs b/Artemis/Artemis/ViewModels/Profiles/LayerKeybindViewModel.cs new file mode 100644 index 000000000..3203850dd --- /dev/null +++ b/Artemis/Artemis/ViewModels/Profiles/LayerKeybindViewModel.cs @@ -0,0 +1,126 @@ +using System.ComponentModel; +using System.Windows.Forms; +using Artemis.Profiles.Layers.Models; +using MahApps.Metro.Controls; +using Screen = Caliburn.Micro.Screen; + +namespace Artemis.ViewModels.Profiles +{ + public sealed class LayerKeybindViewModel : Screen + { + private readonly LayerEditorViewModel _editorViewModel; + + private HotKey _hotKey; + private MouseButtons _mouseButtons; + private ToggleType _toggleType; + + public LayerKeybindViewModel(LayerEditorViewModel editorViewModel, LayerKeybindModel layerKeybindModel) + { + _editorViewModel = editorViewModel; + LayerKeybindModel = layerKeybindModel; + + PropertyChanged += MapViewToModel; + MapModelToView(); + } + + private void MapViewToModel(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == "MouseButtonsVisible" || e.PropertyName == "HotkeyVisible") + return; + + if (MouseButtonsVisible) + SetMouseBind(); + else + SetKeyBind(); + } + + private void MapModelToView() + { + PropertyChanged -= MapViewToModel; + + if (LayerKeybindModel.MouseButtons != null) + MouseButtons = LayerKeybindModel.MouseButtons.Value; + HotKey = LayerKeybindModel.HotKey; + ToggleType = LayerKeybindModel.ToggleType; + + PropertyChanged += MapViewToModel; + } + + public LayerKeybindModel LayerKeybindModel { get; set; } + + + public bool MouseButtonsVisible => LayerKeybindModel.MouseButtons != null; + public bool HotkeyVisible => LayerKeybindModel.MouseButtons == null; + + public MouseButtons MouseButtons + { + get { return _mouseButtons; } + set + { + if (value == _mouseButtons) + return; + _mouseButtons = value; + NotifyOfPropertyChange(() => MouseButtons); + } + } + + public HotKey HotKey + { + get { return _hotKey; } + set + { + if (Equals(value, _hotKey)) + return; + _hotKey = value; + NotifyOfPropertyChange(() => HotKey); + } + } + + public ToggleType ToggleType + { + get { return _toggleType; } + set + { + if (value == _toggleType) + return; + _toggleType = value; + NotifyOfPropertyChange(() => ToggleType); + } + } + + public void ToggleBindType() + { + if (MouseButtonsVisible) + SetKeyBind(); + else + SetMouseBind(); + } + + public void SetMouseBind() + { + LayerKeybindModel.Unregister(); + LayerKeybindModel.HotKey = null; + LayerKeybindModel.MouseButtons = MouseButtons; + LayerKeybindModel.ToggleType = ToggleType; + + NotifyOfPropertyChange(() => HotkeyVisible); + NotifyOfPropertyChange(() => MouseButtonsVisible); + } + + public void SetKeyBind() + { + LayerKeybindModel.Unregister(); + LayerKeybindModel.HotKey = HotKey; + LayerKeybindModel.MouseButtons = null; + LayerKeybindModel.ToggleType = ToggleType; + + NotifyOfPropertyChange(() => HotkeyVisible); + NotifyOfPropertyChange(() => MouseButtonsVisible); + } + + public void Delete() + { + _editorViewModel.LayerKeybindVms.Remove(this); + } + } +} diff --git a/Artemis/Artemis/Views/LayerEditorView.xaml b/Artemis/Artemis/Views/LayerEditorView.xaml index 6310666b2..5c25c13cb 100644 --- a/Artemis/Artemis/Views/LayerEditorView.xaml +++ b/Artemis/Artemis/Views/LayerEditorView.xaml @@ -32,7 +32,7 @@ - + - +