-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSettings_KeybindsControl.cs
More file actions
147 lines (136 loc) · 4.76 KB
/
Copy pathSettings_KeybindsControl.cs
File metadata and controls
147 lines (136 loc) · 4.76 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MarsClientLauncher
{
public partial class Settings_KeybindsControl : UserControl
{
public Settings_KeybindsControl()
{
InitializeComponent();
picker.DrawItem += Picker_DrawItem;
int curve = 10;
Form1.SetBorderCurve(curve, addButton);
Form1.SetBorderCurve(curve, deleteButton);
Form1.SetBorderCurve(curve, editButton);
Form1.SetBorderCurve(curve, confirmButton);
}
private void Picker_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if (e.State == DrawItemState.Focus)
e.DrawFocusRectangle();
int i = e.Index;
int c = picker.Items.Count;
if (i < 0 || i >= c) return;
object obj = picker.Items[i];
string txt = (obj == null) ?
"Null Object?" : obj.ToString();
using(Brush b = new SolidBrush(e.ForeColor))
{
e.Graphics.TextRenderingHint = System.Drawing
.Text.TextRenderingHint.ClearTypeGridFit;
e.Graphics.DrawString(txt, e.Font, b, e.Bounds);
}
}
public bool enabled = false;
Point enabledPos, disabledPos;
Timer timer;
private void Settings_KeybindsControl_Load(object sender, EventArgs e)
{
enabledPos = new Point(SettingsMenu.SETTINGS_TAB_X, 74);
disabledPos = enabledPos;
disabledPos.X += Size.Width;
Location = disabledPos;
timer = new Timer();
timer.Interval = 16;
timer.Tick += Timer_Tick;
timer.Start();
editButton.Enabled = false;
deleteButton.Enabled = false;
UpdateBox();
}
public static int Interpolate(int a, int b, double t)
{
return (int)((1 - t) * a + t * b);
}
private void UpdateBox()
{
picker.Items.Clear();
if (Data.keybinds == null) return;
foreach (var kb in Data.keybinds.keybinds)
picker.Items.Add(kb);
}
private void editButton_Click(object sender, EventArgs e)
{
Keybind toEdit = (Keybind)picker.SelectedItem;
if (toEdit == null) return;
using (SingleKeybindEditor edit = new SingleKeybindEditor(toEdit))
{
edit.ShowDialog();
ApplyKeybindAfterEditing(edit, true, toEdit);
editButton.Enabled = false;
deleteButton.Enabled = false;
}
}
private void deleteButton_Click(object sender, EventArgs e)
{
Keybind toDelete = (Keybind)picker.SelectedItem;
if (toDelete == null) return;
Data.keybinds.DeleteKeybind(toDelete);
if (Data.keybinds.keybinds.Count == 0)
{
editButton.Enabled = false;
deleteButton.Enabled = false;
}
UpdateBox();
}
private void confirmButton_Click(object sender, EventArgs e)
{
enabled = false;
}
private void addButton_Click(object sender, EventArgs e)
{
using (SingleKeybindEditor edit = new SingleKeybindEditor())
{
edit.ShowDialog();
ApplyKeybindAfterEditing(edit, false, null);
}
}
private void Timer_Tick(object sender, EventArgs e)
{
// Animate left or right.
Point loc = Location;
int curX = loc.X;
int goalX;
if (enabled)
goalX = enabledPos.X;
else
goalX = disabledPos.X;
int n = Interpolate(curX, goalX, 0.2);
loc.X = n;
Location = loc;
}
private void picker_SelectedIndexChanged(object sender, EventArgs e)
{
editButton.Enabled = true;
deleteButton.Enabled = true;
}
private void ApplyKeybindAfterEditing(SingleKeybindEditor editor, bool edited, Keybind toReplace)
{
if (!editor.confirmed) return;
Keybind kb = editor.keybind;
if (edited)
Data.keybinds.ReplaceKeybind(toReplace, kb);
else
Data.keybinds.AddKeybind(kb);
UpdateBox();
}
}
}