forked from Biotronic/TweakScale
-
Notifications
You must be signed in to change notification settings - Fork 23
/
HotkeyAble.cs
72 lines (63 loc) · 2.09 KB
/
HotkeyAble.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Collections.Generic;
using UnityEngine;
using KSP.IO;
namespace TweakScale
{
class Hotkeyable
{
private readonly OSD _osd;
private readonly string _name;
private readonly Hotkey _tempDisable;
private readonly Hotkey _toggle;
private bool _state;
private readonly PluginConfiguration _config;
public bool State {
get { return _state && !_tempDisable.IsTriggered; }
}
public Hotkeyable(OSD osd, string name, ICollection<KeyCode> tempDisableDefault, ICollection<KeyCode> toggleDefault, bool state)
{
_config = HotkeyManager.Instance.Config;
_osd = osd;
_name = name;
_tempDisable = new Hotkey("Disable " + name, tempDisableDefault);
_toggle = new Hotkey("Toggle " + name, toggleDefault);
_state = state;
Load();
}
public Hotkeyable(OSD osd, string name, string tempDisableDefault, string toggleDefault, bool state)
{
_config = HotkeyManager.Instance.Config;
_osd = osd;
_name = name;
_tempDisable = new Hotkey("Disable " + name, tempDisableDefault);
_toggle = new Hotkey("Toggle " + name, toggleDefault);
_state = state;
Load();
}
private void Load()
{
Debug.Log("Getting value. Currently: " + _state);
_state = _config.GetValue(_name, _state);
Debug.Log("New value: " + _state);
_config.SetValue(_name, _state);
_config.save();
}
public void Update()
{
if (!_toggle.IsTriggered)
return;
_state = !_state;
_osd.Info(_name + (_state ? " enabled." : " disabled."));
_config.SetValue(_name, _state);
_config.save();
}
public static bool operator true(Hotkeyable a)
{
return a.State;
}
public static bool operator false(Hotkeyable a)
{
return !a.State;
}
}
}