mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 01:42:02 +00:00
Implemented keybinds on layers
This commit is contained in:
parent
e051918486
commit
992d79a43f
@ -364,6 +364,7 @@
|
|||||||
<Compile Include="Managers\LuaManager.cs" />
|
<Compile Include="Managers\LuaManager.cs" />
|
||||||
<Compile Include="Managers\MainManager.cs" />
|
<Compile Include="Managers\MainManager.cs" />
|
||||||
<Compile Include="Managers\PreviewManager.cs" />
|
<Compile Include="Managers\PreviewManager.cs" />
|
||||||
|
<Compile Include="Models\KeybindModel.cs" />
|
||||||
<Compile Include="Models\LayerEditorModel.cs" />
|
<Compile Include="Models\LayerEditorModel.cs" />
|
||||||
<Compile Include="Models\ProfileEditorModel.cs" />
|
<Compile Include="Models\ProfileEditorModel.cs" />
|
||||||
<Compile Include="Modules\Abstract\ModuleDataModel.cs" />
|
<Compile Include="Modules\Abstract\ModuleDataModel.cs" />
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Artemis.Models;
|
||||||
using Artemis.Utilities.Keyboard;
|
using Artemis.Utilities.Keyboard;
|
||||||
using MahApps.Metro.Controls;
|
using MahApps.Metro.Controls;
|
||||||
using KeyEventArgs = System.Windows.Forms.KeyEventArgs;
|
using KeyEventArgs = System.Windows.Forms.KeyEventArgs;
|
||||||
@ -10,76 +11,77 @@ namespace Artemis.Managers
|
|||||||
{
|
{
|
||||||
public static class KeybindManager
|
public static class KeybindManager
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<HotKey, Action> HotKeys;
|
private static readonly List<KeybindModel> KeybindModels = new List<KeybindModel>();
|
||||||
|
|
||||||
static KeybindManager()
|
static KeybindManager()
|
||||||
{
|
{
|
||||||
KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback;
|
KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback;
|
||||||
HotKeys = new Dictionary<HotKey, Action>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
private static void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
// Don't trigger if none of the modifiers are held down
|
|
||||||
if (!e.Alt && !e.Control && !e.Shift)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Don't trigger if the key itself is a modifier
|
// Don't trigger if the key itself is a modifier
|
||||||
if (e.KeyCode == Keys.LShiftKey || e.KeyCode == Keys.RShiftKey ||
|
if (e.KeyCode == Keys.LShiftKey || e.KeyCode == Keys.RShiftKey ||
|
||||||
e.KeyCode == Keys.LControlKey || e.KeyCode == Keys.RControlKey ||
|
e.KeyCode == Keys.LControlKey || e.KeyCode == Keys.RControlKey ||
|
||||||
e.KeyCode == Keys.LMenu || e.KeyCode == Keys.RMenu)
|
e.KeyCode == Keys.LMenu || e.KeyCode == Keys.RMenu)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Create a WPF ModifierKeys enum
|
||||||
|
var modifiers = ModifierKeysFromBooleans(e.Alt, e.Control, e.Shift);
|
||||||
|
|
||||||
|
// Create a HotKey object for comparison
|
||||||
|
var hotKey = new HotKey(KeyInterop.KeyFromVirtualKey(e.KeyValue), modifiers);
|
||||||
|
|
||||||
|
foreach (var keybindModel in KeybindModels)
|
||||||
|
keybindModel.InvokeIfMatched(hotKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddOrUpdate(KeybindModel keybindModel)
|
||||||
|
{
|
||||||
|
var existing = KeybindModels.FirstOrDefault(k => k.Name == keybindModel.Name);
|
||||||
|
if (existing != null)
|
||||||
|
KeybindModels.Remove(existing);
|
||||||
|
|
||||||
|
KeybindModels.Add(keybindModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Remove(KeybindModel keybindModel)
|
||||||
|
{
|
||||||
|
if (KeybindModels.Contains(keybindModel))
|
||||||
|
KeybindModels.Remove(keybindModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Remove(string name)
|
||||||
|
{
|
||||||
|
var existing = KeybindModels.FirstOrDefault(k => k.Name == name);
|
||||||
|
if (existing != null)
|
||||||
|
KeybindModels.Remove(existing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Clear()
|
||||||
|
{
|
||||||
|
// TODO: Re-add future global keybinds here or just exclude them from the clear
|
||||||
|
KeybindModels.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModifierKeys ModifierKeysFromBooleans(bool alt, bool control, bool shift)
|
||||||
|
{
|
||||||
// Create a WPF ModifierKeys enum
|
// Create a WPF ModifierKeys enum
|
||||||
var modifiers = ModifierKeys.None;
|
var modifiers = ModifierKeys.None;
|
||||||
if (e.Alt)
|
if (alt)
|
||||||
modifiers = ModifierKeys.Alt;
|
modifiers = ModifierKeys.Alt;
|
||||||
if (e.Control)
|
if (control)
|
||||||
if (modifiers == ModifierKeys.None)
|
if (modifiers == ModifierKeys.None)
|
||||||
modifiers = ModifierKeys.Control;
|
modifiers = ModifierKeys.Control;
|
||||||
else
|
else
|
||||||
modifiers |= ModifierKeys.Control;
|
modifiers |= ModifierKeys.Control;
|
||||||
if (e.Shift)
|
if (shift)
|
||||||
if (modifiers == ModifierKeys.None)
|
if (modifiers == ModifierKeys.None)
|
||||||
modifiers = ModifierKeys.Shift;
|
modifiers = ModifierKeys.Shift;
|
||||||
else
|
else
|
||||||
modifiers |= ModifierKeys.Shift;
|
modifiers |= ModifierKeys.Shift;
|
||||||
|
|
||||||
// Create a HotKey object for comparison
|
return modifiers;
|
||||||
var hotKey = new HotKey(KeyInterop.KeyFromVirtualKey(e.KeyValue), modifiers);
|
|
||||||
|
|
||||||
// If the hotkey is present, invoke the action related to it
|
|
||||||
if (HotKeys.ContainsKey(hotKey))
|
|
||||||
HotKeys[hotKey].Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Registers a hotkey and executes the provided action when the hotkey is pressed
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hotKey">The hotkey to register</param>
|
|
||||||
/// <param name="action">The action to invoke on press</param>
|
|
||||||
/// <returns>Returns true if key registed, false if already in use</returns>
|
|
||||||
public static bool RegisterHotkey(HotKey hotKey, Action action)
|
|
||||||
{
|
|
||||||
if (HotKeys.ContainsKey(hotKey))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
HotKeys.Add(hotKey, action);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Unregister the given hotkey
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hotKey">The hotkey to unregister</param>
|
|
||||||
/// <returns>Returns true if unregistered, false if not found</returns>
|
|
||||||
public static bool UnregisterHotkey(HotKey hotKey)
|
|
||||||
{
|
|
||||||
if (!HotKeys.ContainsKey(hotKey))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
HotKeys.Remove(hotKey);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
25
Artemis/Artemis/Models/KeybindModel.cs
Normal file
25
Artemis/Artemis/Models/KeybindModel.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using MahApps.Metro.Controls;
|
||||||
|
|
||||||
|
namespace Artemis.Models
|
||||||
|
{
|
||||||
|
public class KeybindModel
|
||||||
|
{
|
||||||
|
public KeybindModel(string name, HotKey hotKey, Action action)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
HotKey = hotKey;
|
||||||
|
Action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public HotKey HotKey { get; set; }
|
||||||
|
public Action Action { get; set; }
|
||||||
|
|
||||||
|
public void InvokeIfMatched(HotKey hotKey)
|
||||||
|
{
|
||||||
|
if (hotKey.Equals(HotKey))
|
||||||
|
Action.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Forms;
|
||||||
using Artemis.Modules.Abstract;
|
using Artemis.Modules.Abstract;
|
||||||
using Artemis.Profiles.Layers.Interfaces;
|
using Artemis.Profiles.Layers.Interfaces;
|
||||||
using Artemis.Profiles.Layers.Models;
|
using Artemis.Profiles.Layers.Models;
|
||||||
@ -8,21 +10,52 @@ namespace Artemis.Profiles.Layers.Conditions
|
|||||||
{
|
{
|
||||||
public class DataModelCondition : ILayerCondition
|
public class DataModelCondition : ILayerCondition
|
||||||
{
|
{
|
||||||
|
private DateTime _lastKeypress;
|
||||||
|
public bool HotKeyMet { get; set; }
|
||||||
|
private static readonly TimeSpan Delay = TimeSpan.FromMilliseconds((SystemParameters.KeyboardDelay + 1) * 250);
|
||||||
|
|
||||||
public bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel)
|
public bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel)
|
||||||
{
|
{
|
||||||
lock (layerModel.Properties.Conditions)
|
lock (layerModel.Properties.Conditions)
|
||||||
{
|
{
|
||||||
|
var checkConditions = layerModel.Properties.Conditions.Where(c => !c.Field.Contains("hotkey"));
|
||||||
|
var conditionMet = false;
|
||||||
switch (layerModel.Properties.ConditionType)
|
switch (layerModel.Properties.ConditionType)
|
||||||
{
|
{
|
||||||
case ConditionType.AnyMet:
|
case ConditionType.AnyMet:
|
||||||
return layerModel.Properties.Conditions.Any(cm => cm.ConditionMet(dataModel));
|
conditionMet = HotKeyMet || checkConditions.Any(cm => cm.ConditionMet(dataModel));
|
||||||
|
break;
|
||||||
case ConditionType.AllMet:
|
case ConditionType.AllMet:
|
||||||
return layerModel.Properties.Conditions.All(cm => cm.ConditionMet(dataModel));
|
conditionMet = HotKeyMet && checkConditions.All(cm => cm.ConditionMet(dataModel));
|
||||||
|
break;
|
||||||
case ConditionType.NoneMet:
|
case ConditionType.NoneMet:
|
||||||
return !layerModel.Properties.Conditions.Any(cm => cm.ConditionMet(dataModel));
|
conditionMet = !HotKeyMet && !checkConditions.Any(cm => cm.ConditionMet(dataModel));
|
||||||
default:
|
break;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is a held down keybind on it, reset every 2 frames, after 500 ms
|
||||||
|
if (layerModel.Properties.Conditions.Any(c => c.Operator == "held") && DateTime.Now - _lastKeypress > Delay)
|
||||||
|
HotKeyMet = false;
|
||||||
|
|
||||||
|
return conditionMet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void KeybindTask(LayerConditionModel condition)
|
||||||
|
{
|
||||||
|
_lastKeypress = DateTime.Now;
|
||||||
|
switch (condition.Field)
|
||||||
|
{
|
||||||
|
case "hotkeyEnable":
|
||||||
|
HotKeyMet = true;
|
||||||
|
break;
|
||||||
|
case "hotkeyDisable":
|
||||||
|
HotKeyMet = false;
|
||||||
|
break;
|
||||||
|
case "hotkeyToggle":
|
||||||
|
HotKeyMet = !HotKeyMet;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,37 +1,60 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using Artemis.Modules.Abstract;
|
using Artemis.Modules.Abstract;
|
||||||
using Artemis.Profiles.Layers.Interfaces;
|
using Artemis.Profiles.Layers.Interfaces;
|
||||||
using Artemis.Profiles.Layers.Models;
|
using Artemis.Profiles.Layers.Models;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Conditions
|
namespace Artemis.Profiles.Layers.Conditions
|
||||||
{
|
{
|
||||||
public class EventCondition : ILayerCondition
|
public class EventCondition : ILayerCondition
|
||||||
{
|
{
|
||||||
|
[JsonIgnore]
|
||||||
|
public bool HotKeyMet { get;set; }
|
||||||
|
|
||||||
public bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel)
|
public bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel)
|
||||||
{
|
{
|
||||||
lock (layerModel.Properties.Conditions)
|
lock (layerModel.Properties.Conditions)
|
||||||
{
|
{
|
||||||
|
var checkConditions = layerModel.Properties.Conditions.Where(c => !c.Field.Contains("hotkey"));
|
||||||
var conditionsMet = false;
|
var conditionsMet = false;
|
||||||
switch (layerModel.Properties.ConditionType)
|
switch (layerModel.Properties.ConditionType)
|
||||||
{
|
{
|
||||||
case ConditionType.AnyMet:
|
case ConditionType.AnyMet:
|
||||||
conditionsMet = layerModel.Properties.Conditions.Any(cm => cm.ConditionMet(dataModel));
|
conditionsMet = HotKeyMet || checkConditions.Any(cm => cm.ConditionMet(dataModel));
|
||||||
break;
|
break;
|
||||||
case ConditionType.AllMet:
|
case ConditionType.AllMet:
|
||||||
conditionsMet = layerModel.Properties.Conditions.All(cm => cm.ConditionMet(dataModel));
|
conditionsMet = HotKeyMet && checkConditions.All(cm => cm.ConditionMet(dataModel));
|
||||||
break;
|
break;
|
||||||
case ConditionType.NoneMet:
|
case ConditionType.NoneMet:
|
||||||
conditionsMet = !layerModel.Properties.Conditions.Any(cm => cm.ConditionMet(dataModel));
|
conditionsMet = !HotKeyMet && !checkConditions.Any(cm => cm.ConditionMet(dataModel));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
layerModel.EventProperties.Update(layerModel, conditionsMet);
|
layerModel.EventProperties.Update(layerModel, conditionsMet);
|
||||||
|
|
||||||
if (conditionsMet && layerModel.EventProperties.CanTrigger)
|
if (conditionsMet)
|
||||||
layerModel.EventProperties.TriggerEvent(layerModel);
|
layerModel.EventProperties.TriggerEvent(layerModel);
|
||||||
|
if (layerModel.EventProperties.MustStop(layerModel))
|
||||||
|
HotKeyMet = false;
|
||||||
|
|
||||||
return layerModel.EventProperties.MustDraw;
|
return layerModel.EventProperties.MustDraw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void KeybindTask(LayerConditionModel condition)
|
||||||
|
{
|
||||||
|
switch (condition.Field)
|
||||||
|
{
|
||||||
|
case "hotkeyEnable":
|
||||||
|
HotKeyMet = true;
|
||||||
|
break;
|
||||||
|
case "hotkeyDisable":
|
||||||
|
HotKeyMet = false;
|
||||||
|
break;
|
||||||
|
case "hotkeyToggle":
|
||||||
|
HotKeyMet = !HotKeyMet;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,5 +6,6 @@ namespace Artemis.Profiles.Layers.Interfaces
|
|||||||
public interface ILayerCondition
|
public interface ILayerCondition
|
||||||
{
|
{
|
||||||
bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel);
|
bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel);
|
||||||
|
void KeybindTask(LayerConditionModel condition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,6 +3,7 @@ using System.Globalization;
|
|||||||
using Artemis.Modules.Abstract;
|
using Artemis.Modules.Abstract;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
using DynamicExpresso;
|
using DynamicExpresso;
|
||||||
|
using MahApps.Metro.Controls;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Models
|
namespace Artemis.Profiles.Layers.Models
|
||||||
{
|
{
|
||||||
@ -20,6 +21,7 @@ namespace Artemis.Profiles.Layers.Models
|
|||||||
public string Value { get; set; }
|
public string Value { get; set; }
|
||||||
public string Operator { get; set; }
|
public string Operator { get; set; }
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
|
public HotKey HotKey { get; set; }
|
||||||
|
|
||||||
public bool ConditionMet(ModuleDataModel subject)
|
public bool ConditionMet(ModuleDataModel subject)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -184,11 +185,13 @@ namespace Artemis.Profiles
|
|||||||
|
|
||||||
public void Activate(LuaManager luaManager)
|
public void Activate(LuaManager luaManager)
|
||||||
{
|
{
|
||||||
|
ApplyKeybinds();
|
||||||
luaManager.SetupLua(this);
|
luaManager.SetupLua(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deactivate(LuaManager luaManager)
|
public void Deactivate(LuaManager luaManager)
|
||||||
{
|
{
|
||||||
|
KeybindManager.Clear();
|
||||||
luaManager.ClearLua();
|
luaManager.ClearLua();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +213,24 @@ namespace Artemis.Profiles
|
|||||||
return layer;
|
return layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ApplyKeybinds()
|
||||||
|
{
|
||||||
|
foreach (var layerModel in Layers)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
var action = new Action(() => layerModel.LayerCondition.KeybindTask(condition));
|
||||||
|
var kb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, action);
|
||||||
|
KeybindManager.AddOrUpdate(kb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Compare
|
#region Compare
|
||||||
|
|
||||||
protected bool Equals(ProfileModel other)
|
protected bool Equals(ProfileModel other)
|
||||||
|
|||||||
@ -319,6 +319,9 @@ namespace Artemis.ViewModels
|
|||||||
{
|
{
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
SelectedLayer = selectModel;
|
SelectedLayer = selectModel;
|
||||||
|
|
||||||
|
// Let the profile reapply keybinds after messing with layers
|
||||||
|
SelectedProfile.ApplyKeybinds();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using Artemis.Profiles.Layers.Models;
|
using Artemis.Profiles.Layers.Models;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
using MahApps.Metro.Controls;
|
||||||
|
|
||||||
namespace Artemis.ViewModels.Profiles
|
namespace Artemis.ViewModels.Profiles
|
||||||
{
|
{
|
||||||
@ -18,14 +19,14 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
private readonly NamedOperator[] _hotkeyOperators =
|
private readonly NamedOperator[] _hotkeyOperators =
|
||||||
{
|
{
|
||||||
new NamedOperator("Pressed", "enable"),
|
new NamedOperator("Pressed", "enable"),
|
||||||
new NamedOperator("Held down", "disable")
|
new NamedOperator("Held down", "held")
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly GeneralHelpers.PropertyCollection[] _hotkeyProperties =
|
private readonly GeneralHelpers.PropertyCollection[] _hotkeyProperties =
|
||||||
{
|
{
|
||||||
new GeneralHelpers.PropertyCollection {Display = "Enable when hotkey", Type = "hotkeyEnable"},
|
new GeneralHelpers.PropertyCollection {Display = "Enable when hotkey", Type = "hotkeyEnable", Path = "hotkeyEnable"},
|
||||||
new GeneralHelpers.PropertyCollection {Display = "Disable when hotkey", Type = "hotkeyDisable"},
|
new GeneralHelpers.PropertyCollection {Display = "Disable when hotkey", Type = "hotkeyDisable", Path = "hotkeyDisable"},
|
||||||
new GeneralHelpers.PropertyCollection {Display = "Toggle when hotkey", Type = "hotkeyToggle"}
|
new GeneralHelpers.PropertyCollection {Display = "Toggle when hotkey", Type = "hotkeyToggle", Path = "hotkeyToggle"}
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly NamedOperator[] _int32Operators =
|
private readonly NamedOperator[] _int32Operators =
|
||||||
@ -53,11 +54,14 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
new NamedOperator("Ends with", ".EndsWith")
|
new NamedOperator("Ends with", ".EndsWith")
|
||||||
};
|
};
|
||||||
|
|
||||||
private bool _enumValueIsVisible;
|
private HotKey _hotKey;
|
||||||
|
|
||||||
private bool _keybindIsVisible;
|
private bool _keybindIsVisible;
|
||||||
private GeneralHelpers.PropertyCollection _selectedDataModelProp;
|
private GeneralHelpers.PropertyCollection _selectedDataModelProp;
|
||||||
private string _selectedEnum;
|
private string _selectedDropdownValue;
|
||||||
private NamedOperator _selectedOperator;
|
private NamedOperator _selectedOperator;
|
||||||
|
|
||||||
|
private bool _userDropdownValueIsVisible;
|
||||||
private string _userValue;
|
private string _userValue;
|
||||||
private bool _userValueIsVisible;
|
private bool _userValueIsVisible;
|
||||||
|
|
||||||
@ -67,7 +71,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
|
|
||||||
ConditionModel = conditionModel;
|
ConditionModel = conditionModel;
|
||||||
Operators = new BindableCollection<NamedOperator>();
|
Operators = new BindableCollection<NamedOperator>();
|
||||||
Enums = new BindableCollection<string>();
|
DropdownValues = new BindableCollection<string>();
|
||||||
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>(_hotkeyProperties);
|
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>(_hotkeyProperties);
|
||||||
DataModelProps.AddRange(editorViewModel.DataModelProps);
|
DataModelProps.AddRange(editorViewModel.DataModelProps);
|
||||||
|
|
||||||
@ -80,7 +84,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
public BindableCollection<GeneralHelpers.PropertyCollection> DataModelProps { get; set; }
|
public BindableCollection<GeneralHelpers.PropertyCollection> DataModelProps { get; set; }
|
||||||
|
|
||||||
public BindableCollection<NamedOperator> Operators { get; set; }
|
public BindableCollection<NamedOperator> Operators { get; set; }
|
||||||
public BindableCollection<string> Enums { get; set; }
|
public BindableCollection<string> DropdownValues { get; set; }
|
||||||
|
|
||||||
public string UserValue
|
public string UserValue
|
||||||
{
|
{
|
||||||
@ -93,6 +97,17 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HotKey HotKey
|
||||||
|
{
|
||||||
|
get { return _hotKey; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (Equals(value, _hotKey)) return;
|
||||||
|
_hotKey = value;
|
||||||
|
NotifyOfPropertyChange(() => HotKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public GeneralHelpers.PropertyCollection SelectedDataModelProp
|
public GeneralHelpers.PropertyCollection SelectedDataModelProp
|
||||||
{
|
{
|
||||||
get { return _selectedDataModelProp; }
|
get { return _selectedDataModelProp; }
|
||||||
@ -116,14 +131,14 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool EnumValueIsVisible
|
public bool UserDropdownValueIsVisible
|
||||||
{
|
{
|
||||||
get { return _enumValueIsVisible; }
|
get { return _userDropdownValueIsVisible; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == _enumValueIsVisible) return;
|
if (value == _userDropdownValueIsVisible) return;
|
||||||
_enumValueIsVisible = value;
|
_userDropdownValueIsVisible = value;
|
||||||
NotifyOfPropertyChange(() => EnumValueIsVisible);
|
NotifyOfPropertyChange(() => UserDropdownValueIsVisible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,14 +164,14 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SelectedEnum
|
public string SelectedDropdownValue
|
||||||
{
|
{
|
||||||
get { return _selectedEnum; }
|
get { return _selectedDropdownValue; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == _selectedEnum) return;
|
if (value == _selectedDropdownValue) return;
|
||||||
_selectedEnum = value;
|
_selectedDropdownValue = value;
|
||||||
NotifyOfPropertyChange(() => SelectedEnum);
|
NotifyOfPropertyChange(() => SelectedDropdownValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,9 +183,10 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
SelectedDataModelProp = DataModelProps.FirstOrDefault(m => m.Path == ConditionModel.Field);
|
SelectedDataModelProp = DataModelProps.FirstOrDefault(m => m.Path == ConditionModel.Field);
|
||||||
// Select the operator
|
// Select the operator
|
||||||
SelectedOperator = Operators.FirstOrDefault(o => o.Value == ConditionModel.Operator);
|
SelectedOperator = Operators.FirstOrDefault(o => o.Value == ConditionModel.Operator);
|
||||||
|
HotKey = ConditionModel.HotKey;
|
||||||
|
|
||||||
if (ConditionModel.Type == "Enum" || ConditionModel.Type == "Boolean")
|
if (ConditionModel.Type == "Enum" || ConditionModel.Type == "Boolean")
|
||||||
SelectedEnum = ConditionModel.Value;
|
SelectedDropdownValue = ConditionModel.Value;
|
||||||
else
|
else
|
||||||
UserValue = ConditionModel.Value;
|
UserValue = ConditionModel.Value;
|
||||||
|
|
||||||
@ -182,9 +198,10 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
ConditionModel.Field = SelectedDataModelProp.Path;
|
ConditionModel.Field = SelectedDataModelProp.Path;
|
||||||
ConditionModel.Operator = SelectedOperator.Value;
|
ConditionModel.Operator = SelectedOperator.Value;
|
||||||
ConditionModel.Type = SelectedDataModelProp.Type;
|
ConditionModel.Type = SelectedDataModelProp.Type;
|
||||||
|
ConditionModel.HotKey = HotKey;
|
||||||
|
|
||||||
if (ConditionModel.Type == "Enum" || ConditionModel.Type == "Boolean")
|
if (ConditionModel.Type == "Enum" || ConditionModel.Type == "Boolean")
|
||||||
ConditionModel.Value = SelectedEnum;
|
ConditionModel.Value = SelectedDropdownValue;
|
||||||
else
|
else
|
||||||
ConditionModel.Value = UserValue;
|
ConditionModel.Value = UserValue;
|
||||||
}
|
}
|
||||||
@ -197,7 +214,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
public void SetupPropertyInput()
|
public void SetupPropertyInput()
|
||||||
{
|
{
|
||||||
Operators.Clear();
|
Operators.Clear();
|
||||||
Enums.Clear();
|
DropdownValues.Clear();
|
||||||
|
|
||||||
switch (SelectedDataModelProp.Type)
|
switch (SelectedDataModelProp.Type)
|
||||||
{
|
{
|
||||||
@ -208,9 +225,9 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
break;
|
break;
|
||||||
case "Boolean":
|
case "Boolean":
|
||||||
Operators.AddRange(_boolOperators);
|
Operators.AddRange(_boolOperators);
|
||||||
Enums.Add("True");
|
DropdownValues.Add("True");
|
||||||
Enums.Add("False");
|
DropdownValues.Add("False");
|
||||||
EnumValueIsVisible = true;
|
UserDropdownValueIsVisible = true;
|
||||||
break;
|
break;
|
||||||
case "String":
|
case "String":
|
||||||
Operators.AddRange(_stringOperators);
|
Operators.AddRange(_stringOperators);
|
||||||
@ -242,14 +259,14 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
Operators.Add(new NamedOperator("Increased", "increased"));
|
Operators.Add(new NamedOperator("Increased", "increased"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupUserValueInput();
|
SetupUserValueInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupUserValueInput()
|
private void SetupUserValueInput()
|
||||||
{
|
{
|
||||||
UserValueIsVisible = false;
|
UserValueIsVisible = false;
|
||||||
EnumValueIsVisible = false;
|
UserDropdownValueIsVisible = false;
|
||||||
KeybindIsVisible = false;
|
KeybindIsVisible = false;
|
||||||
|
|
||||||
// Event operators don't have any form of input
|
// Event operators don't have any form of input
|
||||||
@ -257,19 +274,19 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
SelectedOperator.Value == "increased")
|
SelectedOperator.Value == "increased")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (SelectedDataModelProp.Type.Contains("hotkey"))
|
if (SelectedDataModelProp.Type != null && SelectedDataModelProp.Type.Contains("hotkey"))
|
||||||
{
|
{
|
||||||
KeybindIsVisible = true;
|
KeybindIsVisible = true;
|
||||||
}
|
}
|
||||||
else if (SelectedDataModelProp.Type == "Boolean")
|
else if (SelectedDataModelProp.Type == "Boolean")
|
||||||
{
|
{
|
||||||
EnumValueIsVisible = true;
|
UserDropdownValueIsVisible = true;
|
||||||
}
|
}
|
||||||
else if (SelectedDataModelProp.EnumValues != null)
|
else if (SelectedDataModelProp.EnumValues != null)
|
||||||
{
|
{
|
||||||
Enums.Clear();
|
DropdownValues.Clear();
|
||||||
Enums.AddRange(SelectedDataModelProp.EnumValues);
|
DropdownValues.AddRange(SelectedDataModelProp.EnumValues);
|
||||||
EnumValueIsVisible = true;
|
UserDropdownValueIsVisible = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -52,13 +52,13 @@
|
|||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<StackPanel Grid.Column="0" x:Name="KeybindIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
<StackPanel Grid.Column="0" x:Name="KeybindIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||||
<controls:HotKeyBox x:Name="Keybind" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110" Watermark="Enter keybind" AreModifierKeysRequired="True" />
|
<controls:HotKeyBox HotKey="{Binding Path=HotKey}" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110" Watermark="Enter keybind" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Grid.Column="0" x:Name="UserValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
<StackPanel Grid.Column="0" x:Name="UserValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||||
<TextBox x:Name="UserValue" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110" controls:TextBoxHelper.Watermark="Enter value" />
|
<TextBox x:Name="UserValue" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110" controls:TextBoxHelper.Watermark="Enter value" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Grid.Column="0" x:Name="EnumValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
<StackPanel Grid.Column="0" x:Name="UserDropdownValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||||
<ComboBox x:Name="Enums" Width="110" MaxDropDownHeight="125" HorizontalAlignment="Center"
|
<ComboBox x:Name="DropdownValues" Width="110" MaxDropDownHeight="125" HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Top" />
|
VerticalAlignment="Top" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Button Grid.Column="1" x:Name="Delete" Width="26" Height="26" Style="{DynamicResource SquareButtonStyle}"
|
<Button Grid.Column="1" x:Name="Delete" Width="26" Height="26" Style="{DynamicResource SquareButtonStyle}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user