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:
parent
9d1a274b72
commit
ef19348e53
@ -37,7 +37,7 @@ namespace Artemis.Managers
|
||||
var hotKey = new HotKey(KeyInterop.KeyFromVirtualKey(keyEventArgs.KeyValue), modifiers);
|
||||
|
||||
foreach (var keybindModel in KeybindModels)
|
||||
keybindModel.InvokeIfMatched(hotKey, keyType);
|
||||
keybindModel.InvokeIfMatched(hotKey, keyType);
|
||||
}
|
||||
|
||||
private static void ProcessMouse(MouseEventArgs mouseEventArgs, KeyType keyType)
|
||||
|
||||
@ -34,7 +34,7 @@ namespace Artemis.Models
|
||||
return;
|
||||
|
||||
if (hotKey.Equals(HotKey))
|
||||
Action?.Invoke();
|
||||
Action?.Invoke();
|
||||
}
|
||||
|
||||
public void InvokeIfMatched(MouseButtons mouseButtons, KeyType keyType)
|
||||
|
||||
@ -1,11 +1,39 @@
|
||||
using Artemis.Modules.Abstract;
|
||||
using Artemis.Profiles.Layers.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Profiles.Layers.Abstract
|
||||
{
|
||||
public abstract class LayerCondition
|
||||
{
|
||||
[JsonIgnore]
|
||||
public bool HotKeyMet { get; set; }
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Artemis.Modules.Abstract;
|
||||
using Artemis.Profiles.Layers.Abstract;
|
||||
using Artemis.Profiles.Layers.Interfaces;
|
||||
using Artemis.Profiles.Layers.Models;
|
||||
|
||||
namespace Artemis.Profiles.Layers.Conditions
|
||||
{
|
||||
public class DataModelCondition : LayerCondition
|
||||
{
|
||||
public bool HotKeyMet { get; set; }
|
||||
|
||||
public override bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel)
|
||||
{
|
||||
lock (layerModel.Properties.Conditions)
|
||||
{
|
||||
var checkConditions = layerModel.Properties.Conditions
|
||||
.Where(c => c.Field != null && !c.Field.Contains("hotkey")).ToList();
|
||||
var checkConditions = layerModel.Properties.Conditions.Where(c => c.Field != null && !c.Field.Contains("hotkey")).ToList();
|
||||
|
||||
if (checkConditions.Count == layerModel.Properties.Conditions.Count)
|
||||
return SimpleConditionsMet(layerModel, dataModel, checkConditions);
|
||||
@ -41,24 +35,7 @@ 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,
|
||||
IEnumerable<LayerConditionModel> checkConditions)
|
||||
private static bool SimpleConditionsMet(LayerModel layerModel, ModuleDataModel dataModel, IEnumerable<LayerConditionModel> checkConditions)
|
||||
{
|
||||
switch (layerModel.Properties.ConditionType)
|
||||
{
|
||||
@ -73,4 +50,4 @@ namespace Artemis.Profiles.Layers.Conditions
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,23 +2,17 @@
|
||||
using System.Linq;
|
||||
using Artemis.Modules.Abstract;
|
||||
using Artemis.Profiles.Layers.Abstract;
|
||||
using Artemis.Profiles.Layers.Interfaces;
|
||||
using Artemis.Profiles.Layers.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Profiles.Layers.Conditions
|
||||
{
|
||||
public class EventCondition : LayerCondition
|
||||
{
|
||||
[JsonIgnore]
|
||||
public bool HotKeyMet { get; set; }
|
||||
|
||||
public override bool ConditionsMet(LayerModel layerModel, ModuleDataModel dataModel)
|
||||
{
|
||||
lock (layerModel.Properties.Conditions)
|
||||
{
|
||||
var checkConditions = layerModel.Properties.Conditions
|
||||
.Where(c => c.Field != null && !c.Field.Contains("hotkey")).ToList();
|
||||
var checkConditions = layerModel.Properties.Conditions.Where(c => c.Field != null && !c.Field.Contains("hotkey")).ToList();
|
||||
|
||||
if (checkConditions.Count == layerModel.Properties.Conditions.Count)
|
||||
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,
|
||||
IEnumerable<LayerConditionModel> checkConditions)
|
||||
private static bool SimpleConditionsMet(LayerModel layerModel, ModuleDataModel dataModel, IEnumerable<LayerConditionModel> checkConditions)
|
||||
{
|
||||
switch (layerModel.Properties.ConditionType)
|
||||
{
|
||||
@ -80,4 +58,4 @@ namespace Artemis.Profiles.Layers.Conditions
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,10 +19,13 @@ namespace Artemis.Profiles
|
||||
public class ProfileModel
|
||||
{
|
||||
private readonly char[] _invalidFileNameChars;
|
||||
private List<KeybindModel> _profileBinds;
|
||||
|
||||
public ProfileModel()
|
||||
{
|
||||
_invalidFileNameChars = Path.GetInvalidFileNameChars();
|
||||
_profileBinds = new List<KeybindModel>();
|
||||
|
||||
Layers = new ChildItemCollection<ProfileModel, LayerModel>(this);
|
||||
OnProfileUpdatedEvent += OnOnProfileUpdatedEvent;
|
||||
}
|
||||
@ -220,6 +223,7 @@ namespace Artemis.Profiles
|
||||
|
||||
public void ApplyKeybinds()
|
||||
{
|
||||
_profileBinds.Clear();
|
||||
foreach (var layerModel in GetLayers())
|
||||
{
|
||||
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
|
||||
if (condition.Operator == "held")
|
||||
{
|
||||
var downAction = new Action(() => layerModel.LayerCondition.KeybindTask(condition));
|
||||
var downKb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, KeyType.KeyDown, downAction);
|
||||
var upAction = new Action(() => layerModel.LayerCondition.KeybindTask(condition));
|
||||
var upKb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, KeyType.KeyUp, upAction);
|
||||
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.KeybindTask(condition));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -250,11 +259,9 @@ namespace Artemis.Profiles
|
||||
|
||||
public void ClearKeybinds()
|
||||
{
|
||||
foreach (var layerModel in GetLayers())
|
||||
{
|
||||
for (var index = 0; index < layerModel.Properties.Conditions.Count; index++)
|
||||
KeybindManager.Remove($"{GameName}-{Name}-{layerModel.Name}-{index}");
|
||||
}
|
||||
foreach (var keybindModel in _profileBinds)
|
||||
KeybindManager.Remove(keybindModel);
|
||||
_profileBinds.Clear();
|
||||
}
|
||||
|
||||
#region Compare
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user