feature(BuildCalc) Added reset button, can change micro delay, and can alter timing interval again
This commit is contained in:
@@ -2,31 +2,35 @@
|
||||
|
||||
namespace Services.Immortal;
|
||||
|
||||
public class KeyService : IKeyService {
|
||||
public class KeyService : IKeyService
|
||||
{
|
||||
private static readonly List<string> PressedKeys = new();
|
||||
private string? _hotkey;
|
||||
private string _hotkeyGroup = "C";
|
||||
private bool _isHoldingSpace;
|
||||
|
||||
private event Action? OnChange;
|
||||
|
||||
|
||||
public void Subscribe(Action? action) {
|
||||
public void Subscribe(Action? action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action? action) {
|
||||
public void Unsubscribe(Action? action)
|
||||
{
|
||||
OnChange -= action;
|
||||
}
|
||||
|
||||
public bool AddPressedKey(string key) {
|
||||
public bool AddPressedKey(string key)
|
||||
{
|
||||
_hotkey = null;
|
||||
|
||||
if (PressedKeys.Count > 0) return false;
|
||||
var pressedKey = key.ToUpper();
|
||||
|
||||
if (pressedKey.Equals(" ") || pressedKey.Equals("SPACE")) {
|
||||
if (!_isHoldingSpace) {
|
||||
if (pressedKey.Equals(" ") || pressedKey.Equals("SPACE"))
|
||||
{
|
||||
if (!_isHoldingSpace)
|
||||
{
|
||||
_isHoldingSpace = true;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
@@ -34,7 +38,8 @@ public class KeyService : IKeyService {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PressedKeys.Contains(pressedKey)) {
|
||||
if (!PressedKeys.Contains(pressedKey))
|
||||
{
|
||||
if (HotkeyModel.KeyGroups.Contains(pressedKey)) _hotkeyGroup = pressedKey;
|
||||
|
||||
if (HotkeyModel.HotKeys.Contains(pressedKey)) _hotkey = pressedKey;
|
||||
@@ -47,16 +52,20 @@ public class KeyService : IKeyService {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<string> GetAllPressedKeys() {
|
||||
public List<string> GetAllPressedKeys()
|
||||
{
|
||||
return PressedKeys;
|
||||
}
|
||||
|
||||
public bool RemovePressedKey(string key) {
|
||||
public bool RemovePressedKey(string key)
|
||||
{
|
||||
_hotkey = null;
|
||||
|
||||
var pressedKey = key.ToUpper();
|
||||
if (pressedKey.Equals(" ") || pressedKey.Equals("SPACE")) {
|
||||
if (_isHoldingSpace || true) {
|
||||
if (pressedKey.Equals(" ") || pressedKey.Equals("SPACE"))
|
||||
{
|
||||
if (_isHoldingSpace || true)
|
||||
{
|
||||
_isHoldingSpace = false;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
@@ -64,7 +73,8 @@ public class KeyService : IKeyService {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PressedKeys.Contains(pressedKey)) {
|
||||
if (PressedKeys.Contains(pressedKey))
|
||||
{
|
||||
PressedKeys.Remove(pressedKey);
|
||||
NotifyDataChanged();
|
||||
return true;
|
||||
@@ -73,20 +83,25 @@ public class KeyService : IKeyService {
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsHoldingSpace() {
|
||||
public bool IsHoldingSpace()
|
||||
{
|
||||
return _isHoldingSpace;
|
||||
}
|
||||
|
||||
public string? GetHotkey() {
|
||||
public string? GetHotkey()
|
||||
{
|
||||
return _hotkey;
|
||||
}
|
||||
|
||||
public string GetHotkeyGroup() {
|
||||
public string GetHotkeyGroup()
|
||||
{
|
||||
return _hotkeyGroup;
|
||||
}
|
||||
|
||||
private void NotifyDataChanged() {
|
||||
private event Action? OnChange;
|
||||
|
||||
private void NotifyDataChanged()
|
||||
{
|
||||
OnChange?.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user