1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Reworked key-held keybind

This commit is contained in:
SpoinkyNL 2017-02-21 22:16:03 +01:00
parent 9d1a274b72
commit ef19348e53
6 changed files with 55 additions and 65 deletions

View File

@ -37,7 +37,7 @@ namespace Artemis.Managers
var hotKey = new HotKey(KeyInterop.KeyFromVirtualKey(keyEventArgs.KeyValue), modifiers); var hotKey = new HotKey(KeyInterop.KeyFromVirtualKey(keyEventArgs.KeyValue), modifiers);
foreach (var keybindModel in KeybindModels) foreach (var keybindModel in KeybindModels)
keybindModel.InvokeIfMatched(hotKey, keyType); keybindModel.InvokeIfMatched(hotKey, keyType);
} }
private static void ProcessMouse(MouseEventArgs mouseEventArgs, KeyType keyType) private static void ProcessMouse(MouseEventArgs mouseEventArgs, KeyType keyType)

View File

@ -34,7 +34,7 @@ namespace Artemis.Models
return; return;
if (hotKey.Equals(HotKey)) if (hotKey.Equals(HotKey))
Action?.Invoke(); Action?.Invoke();
} }
public void InvokeIfMatched(MouseButtons mouseButtons, KeyType keyType) public void InvokeIfMatched(MouseButtons mouseButtons, KeyType keyType)

View File

@ -1,11 +1,39 @@
using Artemis.Modules.Abstract; using Artemis.Modules.Abstract;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Newtonsoft.Json;
namespace Artemis.Profiles.Layers.Abstract namespace Artemis.Profiles.Layers.Abstract
{ {
public abstract class LayerCondition public abstract class LayerCondition
{ {
[JsonIgnore]
public bool HotKeyMet { get; set; }
public abstract bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel); public abstract bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel);
public abstract void KeybindTask(LayerConditionModel condition);
public void KeyDownTask(LayerConditionModel condition)
{
switch (condition.Field)
{
case "hotkeyEnable":
HotKeyMet = true;
break;
case "hotkeyDisable":
HotKeyMet = false;
break;
case "hotkeyToggle":
HotKeyMet = !HotKeyMet;
break;
}
}
public void KeyUpTask(LayerConditionModel condition)
{
if (condition.Field == "hotkeyEnable")
HotKeyMet = false;
else
HotKeyMet = true;
}
} }
} }

View File

@ -1,24 +1,18 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows;
using Artemis.Modules.Abstract; using Artemis.Modules.Abstract;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
namespace Artemis.Profiles.Layers.Conditions namespace Artemis.Profiles.Layers.Conditions
{ {
public class DataModelCondition : LayerCondition public class DataModelCondition : LayerCondition
{ {
public bool HotKeyMet { get; set; }
public override bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel) public override bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel)
{ {
lock (layerModel.Properties.Conditions) lock (layerModel.Properties.Conditions)
{ {
var checkConditions = layerModel.Properties.Conditions var checkConditions = layerModel.Properties.Conditions.Where(c => c.Field != null && !c.Field.Contains("hotkey")).ToList();
.Where(c => c.Field != null && !c.Field.Contains("hotkey")).ToList();
if (checkConditions.Count == layerModel.Properties.Conditions.Count) if (checkConditions.Count == layerModel.Properties.Conditions.Count)
return SimpleConditionsMet(layerModel, dataModel, checkConditions); return SimpleConditionsMet(layerModel, dataModel, checkConditions);
@ -41,24 +35,7 @@ namespace Artemis.Profiles.Layers.Conditions
} }
} }
public override void KeybindTask(LayerConditionModel condition) private static bool SimpleConditionsMet(LayerModel layerModel, ModuleDataModel dataModel, IEnumerable<LayerConditionModel> checkConditions)
{
switch (condition.Field)
{
case "hotkeyEnable":
HotKeyMet = true;
break;
case "hotkeyDisable":
HotKeyMet = false;
break;
case "hotkeyToggle":
HotKeyMet = !HotKeyMet;
break;
}
}
private static bool SimpleConditionsMet(LayerModel layerModel, ModuleDataModel dataModel,
IEnumerable<LayerConditionModel> checkConditions)
{ {
switch (layerModel.Properties.ConditionType) switch (layerModel.Properties.ConditionType)
{ {
@ -73,4 +50,4 @@ namespace Artemis.Profiles.Layers.Conditions
} }
} }
} }
} }

View File

@ -2,23 +2,17 @@
using System.Linq; using System.Linq;
using Artemis.Modules.Abstract; using Artemis.Modules.Abstract;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
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 : LayerCondition public class EventCondition : LayerCondition
{ {
[JsonIgnore]
public bool HotKeyMet { get; set; }
public override bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel) public override bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel)
{ {
lock (layerModel.Properties.Conditions) lock (layerModel.Properties.Conditions)
{ {
var checkConditions = layerModel.Properties.Conditions var checkConditions = layerModel.Properties.Conditions.Where(c => c.Field != null && !c.Field.Contains("hotkey")).ToList();
.Where(c => c.Field != null && !c.Field.Contains("hotkey")).ToList();
if (checkConditions.Count == layerModel.Properties.Conditions.Count) if (checkConditions.Count == layerModel.Properties.Conditions.Count)
return SimpleConditionsMet(layerModel, dataModel, checkConditions); return SimpleConditionsMet(layerModel, dataModel, checkConditions);
@ -48,24 +42,8 @@ namespace Artemis.Profiles.Layers.Conditions
} }
} }
public override void KeybindTask(LayerConditionModel condition)
{
switch (condition.Field)
{
case "hotkeyEnable":
HotKeyMet = true;
break;
case "hotkeyDisable":
HotKeyMet = false;
break;
case "hotkeyToggle":
HotKeyMet = !HotKeyMet;
break;
}
}
private static bool SimpleConditionsMet(LayerModel layerModel, ModuleDataModel dataModel, private static bool SimpleConditionsMet(LayerModel layerModel, ModuleDataModel dataModel, IEnumerable<LayerConditionModel> checkConditions)
IEnumerable<LayerConditionModel> checkConditions)
{ {
switch (layerModel.Properties.ConditionType) switch (layerModel.Properties.ConditionType)
{ {
@ -80,4 +58,4 @@ namespace Artemis.Profiles.Layers.Conditions
} }
} }
} }
} }

View File

@ -19,10 +19,13 @@ namespace Artemis.Profiles
public class ProfileModel public class ProfileModel
{ {
private readonly char[] _invalidFileNameChars; private readonly char[] _invalidFileNameChars;
private List<KeybindModel> _profileBinds;
public ProfileModel() public ProfileModel()
{ {
_invalidFileNameChars = Path.GetInvalidFileNameChars(); _invalidFileNameChars = Path.GetInvalidFileNameChars();
_profileBinds = new List<KeybindModel>();
Layers = new ChildItemCollection<ProfileModel, LayerModel>(this); Layers = new ChildItemCollection<ProfileModel, LayerModel>(this);
OnProfileUpdatedEvent += OnOnProfileUpdatedEvent; OnProfileUpdatedEvent += OnOnProfileUpdatedEvent;
} }
@ -220,6 +223,7 @@ namespace Artemis.Profiles
public void ApplyKeybinds() public void ApplyKeybinds()
{ {
_profileBinds.Clear();
foreach (var layerModel in GetLayers()) foreach (var layerModel in GetLayers())
{ {
for (var index = 0; index < layerModel.Properties.Conditions.Count; index++) for (var index = 0; index < layerModel.Properties.Conditions.Count; index++)
@ -231,18 +235,23 @@ namespace Artemis.Profiles
// Create an action for the layer, the layer's specific condition type handles activation // Create an action for the layer, the layer's specific condition type handles activation
if (condition.Operator == "held") if (condition.Operator == "held")
{ {
var downAction = new Action(() => layerModel.LayerCondition.KeybindTask(condition)); var downAction = new Action(() => layerModel.LayerCondition.KeyDownTask(condition));
var downKb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, KeyType.KeyDown, downAction); var downKb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-down-{index}", condition.HotKey, KeyType.KeyDown, downAction);
var upAction = new Action(() => layerModel.LayerCondition.KeybindTask(condition)); var upAction = new Action(() => layerModel.LayerCondition.KeyUpTask(condition));
var upKb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, KeyType.KeyUp, upAction); var upKb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-up-{index}", condition.HotKey, KeyType.KeyUp, upAction);
KeybindManager.AddOrUpdate(downKb); KeybindManager.AddOrUpdate(downKb);
KeybindManager.AddOrUpdate(upKb); KeybindManager.AddOrUpdate(upKb);
_profileBinds.Add(downKb);
_profileBinds.Add(upKb);
} }
else else
{ {
var action = new Action(() => layerModel.LayerCondition.KeybindTask(condition)); var action = new Action(() => layerModel.LayerCondition.KeyDownTask(condition));
var kb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, KeyType.KeyDown, action); var kb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, KeyType.KeyDown, action);
KeybindManager.AddOrUpdate(kb); KeybindManager.AddOrUpdate(kb);
_profileBinds.Add(kb);
} }
} }
} }
@ -250,11 +259,9 @@ namespace Artemis.Profiles
public void ClearKeybinds() public void ClearKeybinds()
{ {
foreach (var layerModel in GetLayers()) foreach (var keybindModel in _profileBinds)
{ KeybindManager.Remove(keybindModel);
for (var index = 0; index < layerModel.Properties.Conditions.Count; index++) _profileBinds.Clear();
KeybindManager.Remove($"{GameName}-{Name}-{layerModel.Name}-{index}");
}
} }
#region Compare #region Compare