forked from dexyfex/CodeWalker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsForm.cs
324 lines (272 loc) · 11.9 KB
/
SettingsForm.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
using CodeWalker.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CodeWalker
{
public partial class SettingsForm : Form
{
private WorldForm worldForm;
private KeyBindings keyBindings = new KeyBindings(Settings.Default.KeyBindings);
private string selKeyBinding = "";
private Keys selKeyBindingVal = Keys.None;
private float camSensitivity = Settings.Default.CameraSensitivity;
private float camSmoothing = Settings.Default.CameraSmoothing;
private bool mouseinvert = Settings.Default.MouseInvert;
public SettingsForm(WorldForm owner)
{
InitializeComponent();
worldForm = owner;
var allkeys = Enum.GetValues(typeof(Keys));
foreach (var keyval in allkeys)
{
KeyBindingComboBox.Items.Add(keyval);
}
LoadKeyBindings();
LoadMouseSettings();
LoadAdvancedSettings();
}
private void LoadKeyBindings()
{
KeyBindingsListView.Items.Clear();
AddKeyBinding("Move Forwards", keyBindings.MoveForward);
AddKeyBinding("Move Backwards", keyBindings.MoveBackward);
AddKeyBinding("Move Left", keyBindings.MoveLeft);
AddKeyBinding("Move Right", keyBindings.MoveRight);
AddKeyBinding("Move Up", keyBindings.MoveUp);
AddKeyBinding("Move Down", keyBindings.MoveDown);
AddKeyBinding("Move Slower / Zoom In", keyBindings.MoveSlowerZoomIn);
AddKeyBinding("Move Faster / Zoom Out", keyBindings.MoveFasterZoomOut);
AddKeyBinding("Toggle Mouse Select", keyBindings.ToggleMouseSelect);
AddKeyBinding("Toggle Toolbar", keyBindings.ToggleToolbar);
AddKeyBinding("Exit Edit Mode", keyBindings.ExitEditMode);
AddKeyBinding("Edit Position", keyBindings.EditPosition);
AddKeyBinding("Edit Rotation", keyBindings.EditRotation);
AddKeyBinding("Edit Scale", keyBindings.EditScale);
AddKeyBinding("First Person Mode", keyBindings.FirstPerson);
}
private void LoadMouseSettings()
{
CameraSensitivityUpDown.Value = (decimal)camSensitivity * 1000;
CameraSmoothingUpDown.Value = (decimal)camSmoothing;
MouseInvertCheckBox.Checked = mouseinvert;
}
private void LoadAdvancedSettings()
{
FolderTextBox.Text = GTAFolder.CurrentGTAFolder;
ExcludeFoldersTextBox.Text = Settings.Default.ExcludeFolders;
ShadowCascadesUpDown.Value = Settings.Default.ShadowCascades;
CacheSizeUpDown.Value = Math.Min(Math.Max(Settings.Default.CacheSize / 1048576, CacheSizeUpDown.Minimum), CacheSizeUpDown.Maximum);
CacheTimeUpDown.Value = Math.Min(Math.Max((decimal)Settings.Default.CacheTime, CacheTimeUpDown.Minimum), CacheTimeUpDown.Maximum);
GPUCacheTimeUpDown.Value = Math.Min(Math.Max((decimal)Settings.Default.GPUCacheTime, GPUCacheTimeUpDown.Minimum), GPUCacheTimeUpDown.Maximum);
GPUFlushTimeUpDown.Value = Math.Min(Math.Max((decimal)Settings.Default.GPUCacheFlushTime, GPUFlushTimeUpDown.Minimum), GPUFlushTimeUpDown.Maximum);
GeometryCacheSizeUpDown.Value = Math.Min(Math.Max(Settings.Default.GPUGeometryCacheSize / 1048576, GeometryCacheSizeUpDown.Minimum), GeometryCacheSizeUpDown.Maximum);
TextureCacheSizeUpDown.Value = Math.Min(Math.Max(Settings.Default.GPUTextureCacheSize / 1048576, TextureCacheSizeUpDown.Minimum), TextureCacheSizeUpDown.Maximum);
CollisionCacheSizeUpDown.Value = Math.Min(Math.Max(Settings.Default.GPUBoundCompCacheSize / 1048576, CollisionCacheSizeUpDown.Minimum), CollisionCacheSizeUpDown.Maximum);
}
private void AddKeyBinding(string text, Keys key)
{
var lvi = KeyBindingsListView.Items.Add(text);
lvi.SubItems.Add(key.ToString());
lvi.Tag = key;
}
public void SelectTab(string tab)
{
switch (tab)
{
case "Controls":
MainTabControl.SelectedTab = ControlsTabPage;
break;
case "Advanced":
MainTabControl.SelectedTab = AdvancedTabPage;
break;
}
}
private void UpdateKeyBindingsListViewItem(string item, Keys val)
{
foreach (ListViewItem lvi in KeyBindingsListView.Items)
{
if (lvi.Text == item)
{
lvi.SubItems[1].Text = val.ToString();
lvi.Tag = val;
break;
}
}
}
private void KeyBindingsListView_SelectedIndexChanged(object sender, EventArgs e)
{
var sel = (KeyBindingsListView.SelectedItems.Count == 1) ? KeyBindingsListView.SelectedItems[0] : null;
if (sel != null)
{
selKeyBinding = sel.Text;
selKeyBindingVal = (Keys)sel.Tag;
KeyBindingNameLabel.Text = selKeyBinding;
KeyBindingComboBox.SelectedItem = sel.Tag;
KeyBindingComboBox.Enabled = true;
KeyBindButton.Enabled = true;
}
else
{
selKeyBinding = string.Empty;
selKeyBindingVal = Keys.None;
KeyBindingNameLabel.Text = "(No binding selected)";
KeyBindingComboBox.SelectedItem = null;
KeyBindingComboBox.Enabled = false;
KeyBindButton.Enabled = false;
}
}
private void KeyBindingComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(selKeyBinding))
{
Keys val = (Keys)KeyBindingComboBox.SelectedItem;
if (val != selKeyBindingVal)
{
selKeyBindingVal = val;
keyBindings.SetBinding(selKeyBinding, val);
UpdateKeyBindingsListViewItem(selKeyBinding, val);
Settings.Default.KeyBindings = keyBindings.GetSetting();
if (worldForm != null)
{
worldForm.SetKeyBindings(keyBindings);
}
}
}
}
private void KeyBindButton_Click(object sender, EventArgs e)
{
KeyBindForm f = new KeyBindForm();
f.SelectedKey = selKeyBindingVal;
if (f.ShowDialog() == DialogResult.OK)
{
var val = f.SelectedKey;
selKeyBindingVal = val;
KeyBindingComboBox.SelectedItem = val;
keyBindings.SetBinding(selKeyBinding, val);
UpdateKeyBindingsListViewItem(selKeyBinding, val);
Settings.Default.KeyBindings = keyBindings.GetSetting();
if (worldForm != null)
{
worldForm.SetKeyBindings(keyBindings);
}
}
}
private void CameraSensitivityUpDown_ValueChanged(object sender, EventArgs e)
{
camSensitivity = (float)CameraSensitivityUpDown.Value * 0.001f;
Settings.Default.CameraSensitivity = camSensitivity;
if (worldForm != null)
{
worldForm.SetCameraSensitivity(camSensitivity, camSmoothing);
}
}
private void CameraSmoothingUpDown_ValueChanged(object sender, EventArgs e)
{
camSmoothing = (float)CameraSmoothingUpDown.Value;
Settings.Default.CameraSmoothing = camSmoothing;
if (worldForm != null)
{
worldForm.SetCameraSensitivity(camSensitivity, camSmoothing);
}
}
private void MouseInvertCheckBox_CheckedChanged(object sender, EventArgs e)
{
mouseinvert = MouseInvertCheckBox.Checked;
Settings.Default.MouseInvert = mouseinvert;
if (worldForm != null)
{
worldForm.SetMouseInverted(mouseinvert);
}
}
private void SaveButton_Click(object sender, EventArgs e)
{
//apply and save the settings.
Settings.Default.KeyBindings = keyBindings.GetSetting();
Settings.Default.CameraSensitivity = camSensitivity;
Settings.Default.CameraSmoothing = camSmoothing;
Settings.Default.Save();
DoneButton.Text = "Done";
}
private void DoneButton_Click(object sender, EventArgs e)
{
Close();
}
private void ResetButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to reset all CodeWalker settings to their default values?", "Confirm reset settings to defaults", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
var k = Settings.Default.Key;
Settings.Default.Reset();
Settings.Default.Key = k;
Settings.Default.Save();
KeyBindingsListView.SelectedItems.Clear();
keyBindings = new KeyBindings(Settings.Default.KeyBindings);
LoadKeyBindings();
camSensitivity = Settings.Default.CameraSensitivity;
camSmoothing = Settings.Default.CameraSmoothing;
LoadMouseSettings();
LoadAdvancedSettings();
if (worldForm != null)
{
worldForm.SetKeyBindings(keyBindings);
worldForm.SetCameraSensitivity(camSensitivity, camSmoothing);
}
}
}
private void SettingsForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (worldForm != null)
{
worldForm.OnSettingsFormClosed();
}
}
private void FolderBrowseButton_Click(object sender, EventArgs e)
{
GTAFolder.UpdateGTAFolder(false);
FolderTextBox.Text = GTAFolder.CurrentGTAFolder;
}
private void ExcludeFoldersTextBox_TextChanged(object sender, EventArgs e)
{
Settings.Default.ExcludeFolders = ExcludeFoldersTextBox.Text;
}
private void ShadowCascadesUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.ShadowCascades = (int)ShadowCascadesUpDown.Value;
}
private void CacheTimeUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.CacheTime = (double)CacheTimeUpDown.Value;
}
private void CacheSizeUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.CacheSize = (long)CacheSizeUpDown.Value * 1048576;
}
private void GPUCacheTimeUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.GPUCacheTime = (double)GPUCacheTimeUpDown.Value;
}
private void GPUFlushTimeUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.GPUCacheFlushTime = (double)GPUFlushTimeUpDown.Value;
}
private void GeometryCacheSizeUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.GPUGeometryCacheSize = (long)GeometryCacheSizeUpDown.Value * 1048576;
}
private void TextureCacheSizeUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.GPUTextureCacheSize = (long)TextureCacheSizeUpDown.Value * 1048576;
}
private void CollisionCacheSizeUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.GPUBoundCompCacheSize = (long)CollisionCacheSizeUpDown.Value * 1048576;
}
}
}