forked from mvdhout1992/RA2_YR_Config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
256 lines (207 loc) · 10.2 KB
/
MainForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Nyerguds.Ini;
using System.IO;
namespace RA2_YR_Config
{
public partial class MainForm : Form
{
public static IniFile RA2INI, RA2MDINI, KeyboardINI, KeyboardMDINI;
public static string RA2INIPath = Program.path + "ra2.ini";
public static string RA2MDINIPath = Program.path + "ra2md.ini";
public static string KeyboardINIPath = Program.path + "keyboard.ini";
public static string KeyboardMDINIPath = Program.path + "keyboardmd.ini";
public static GameHotkeys GameHotkeysRA2 = new GameHotkeys();
public static GameHotkeys GameHotkeysYR = new GameHotkeys();
public MainForm()
{
InitializeComponent();
}
public void Load_Or_Create_INI(ref IniFile Ini, string path, string RawIniText)
{
if (File.Exists(path)) Ini = new IniFile(path);
else Ini = new IniFile(path, RawIniText);
}
private void MainForm_Load(object sender, EventArgs e)
{
Load_Settings();
}
private void Load_Settings_INI_Files()
{
Load_Or_Create_INI(ref RA2INI, RA2INIPath, Properties.Resources.ra2ini);
Load_Or_Create_INI(ref RA2MDINI, RA2MDINIPath, Properties.Resources.ra2mdini);
Load_Or_Create_INI(ref KeyboardINI, KeyboardINIPath, Properties.Resources.keyboardini);
Load_Or_Create_INI(ref KeyboardMDINI, KeyboardMDINIPath, Properties.Resources.keyboardmdini);
}
private void OkButton_Click(object sender, EventArgs e)
{
Save_Settings(RA2INI);
Save_Settings(RA2MDINI);
Application.Exit();
}
private void CancelButton_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void ResetButton_Click(object sender, EventArgs e)
{
Load_Settings();
}
private void ApplyButton_Click(object sender, EventArgs e)
{
Save_Settings(RA2INI);
Save_Settings(RA2MDINI);
}
private void Load_Settings()
{
Load_Settings_INI_Files();
Load_Resolutions(cmbResolutionRA2, RA2INI);
Load_Hotkey_Editor(HotkeyEditorDataGridRA2, GameHotkeysRA2, KeyboardINI);
Load_Hotkey_Editor(HotkeyEditorDataGridYR, GameHotkeysYR, KeyboardMDINI);
try
{
trbrScrollRateRA2.Value = RA2INI.GetIntValue("Options", "ScrollRate", 1);
trbrDetailLevelRA2.Value= RA2INI.GetIntValue("Options", "DetailLevel", 2);
trbrVoiceVolumeRA2.Value = Convert.ToInt32( RA2INI.GetFloatValue("Audio", "VoiceVolume", 0.3) * 20 );
trbrAudioVolumeRA2.Value = Convert.ToInt32( RA2INI.GetFloatValue("Audio", "SoundVolume", 0.3) * 20 );
trbrMusicVolumeRA2.Value = Convert.ToInt32( RA2INI.GetFloatValue("Audio", "ScoreVolume", 0.3) * 20 );
}
catch
{
}
chbAllowVRAMSidebarRA2.Checked = RA2INI.GetBoolValue("Video", "AllowVRAMSidebar", false);
chbVideoBackBufferRA2.Checked = RA2INI.GetBoolValue("Video", "VideoBackBuffer", true);
chbShowToolTipsRA2.Checked = RA2INI.GetBoolValue("Options", "ToolTips", true);
chbShowTargetLinesRA2.Checked = RA2INI.GetBoolValue("Options", "UnitActionLines", true);
chbShowHiddenObjectsRA2.Checked = RA2INI.GetBoolValue("Options", "ShowHidden", true);
chbWindowedModeRA2.Checked = RA2INI.GetBoolValue("Video", "Windowed", false);
chbUseGraphicsPatchRA2.Checked = RA2INI.GetBoolValue("Video", "UseGraphicsPatch", true);
chbRepeatMusicRA2.Checked = RA2INI.GetBoolValue("Audio", "IsScoreRepeat", true);
chbShuffleMusicRA2.Checked = RA2INI.GetBoolValue("Audio", "IsScoreShuffle", true);
}
private void Load_Resolutions(ComboBox cmbox, IniFile Inifile)
{
List<String> resolutions = screenres.ScreenResolutionOperations.getScreenResolutions(640, 400, 16);
String resolution = getCurrentGameRes(Inifile);
cmbox.DataSource = resolutions;
if (resolutions.Contains(resolution))
cmbox.SelectedIndex = resolutions.IndexOf(resolution);
}
private void Load_Hotkey_Editor(DataGridView dgv, GameHotkeys ghks, IniFile inifile)
{
int HotkeysLoadedNum = ghks.Load_Hotkeys(inifile);
if (HotkeysLoadedNum != 0)
{
dgv.Rows.Clear();
dgv.Rows.Add(HotkeysLoadedNum);
for (int i = 0; i < HotkeysLoadedNum; i++)
{
dgv.Rows[i].Cells[0].Value = ghks.Get_Hotkey(i).HotkeyName;
dgv.Rows[i].Cells[1].Value = ghks.Hotkey_Display_Value(i);
}
}
}
private void Save_Settings(IniFile game)
{
GameHotkeysRA2.Save_Hotkeys(KeyboardINI);
GameHotkeysYR.Save_Hotkeys(KeyboardMDINI);
game.SetFloatValue("Audio", "VoiceVolume", ((double)trbrVoiceVolumeRA2.Value / 20));
game.SetFloatValue("Audio", "SoundVolume", ((double)trbrAudioVolumeRA2.Value / 20));
game.SetFloatValue("Audio", "ScoreVolume", ((double)trbrMusicVolumeRA2.Value / 20));
game.SetIntValue("Options", "ScrollRate", trbrScrollRateRA2.Value);
game.SetIntValue("Options", "DetailLevel", trbrDetailLevelRA2.Value);
var res = cmbResolutionRA2.SelectedItem.ToString().Split('x');
game.SetStringValue("Video", "ScreenWidth", res[0]);
game.SetStringValue("Video", "ScreenHeight", res[1]);
game.SetBoolValue("Video", "AllowVRAMSidebar", chbAllowVRAMSidebarRA2.Checked);
game.SetBoolValue("Video", "VideoBackBuffer", chbVideoBackBufferRA2.Checked);
game.SetBoolValue("Options", "ToolTips", chbShowToolTipsRA2.Checked);
game.SetBoolValue("Options", "UnitActionLines", chbShowTargetLinesRA2.Checked);
game.SetBoolValue("Options", "ShowHidden", chbShowHiddenObjectsRA2.Checked);
game.SetBoolValue("Video", "Windowed", chbWindowedModeRA2.Checked);
game.SetBoolValue("Video", "UseGraphicsPatch", chbUseGraphicsPatchRA2.Checked);
game.SetBoolValue("Audio", "IsScoreRepeat", chbRepeatMusicRA2.Checked);
game.SetBoolValue("Audio", "IsScoreShuffle", chbShuffleMusicRA2.Checked);
game.WriteIni();
}
private void HotkeyEditorDataGridRA2_KeyDown(object sender, KeyEventArgs e)
{
Hotkey_Editor_Key_Down(e, HotkeyEditorDataGridRA2, GameHotkeysRA2);
}
private void HotkeyEditorDataGridYR_KeyDown(object sender, KeyEventArgs e)
{
Hotkey_Editor_Key_Down(e, HotkeyEditorDataGridYR, GameHotkeysYR);
}
private void Hotkey_Editor_Key_Down(KeyEventArgs e, DataGridView dgv, GameHotkeys ghks)
{
e.SuppressKeyPress = true;
if (e.Modifiers != Keys.None && (e.KeyCode == Keys.Menu || e.KeyCode == Keys.ControlKey
|| e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.RControlKey
|| e.KeyCode == Keys.RMenu || e.KeyCode == Keys.RShiftKey))
{
dgv.CurrentCell.Value = "";
if ((int)(e.Modifiers & Keys.Control) == (int)Keys.Control)
dgv.CurrentCell.Value += "Crl+";
if ((int)(e.Modifiers & Keys.Alt) == (int)Keys.Alt)
dgv.CurrentCell.Value += "Alt+";
if ((int)(e.Modifiers & Keys.Shift) == (int)Keys.Shift)
dgv.CurrentCell.Value += "Shift";
return;
}
if (!dgv.Visible || dgv.CurrentCell == null) return;
if (dgv.CurrentCell.ColumnIndex == 0)
dgv.CurrentCell = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[1];
ghks.Set_Hotkey_Value(e, dgv.CurrentCell.RowIndex);
dgv.CurrentCell.Value = ghks.Hotkey_Display_Value(dgv.CurrentCell.RowIndex);
}
private void HotkeyEditorDataGridRA2_MouseEnter(object sender, EventArgs e)
{
Hotkey_Editor_Mouse_Enter(HotkeyEditorDataGridRA2);
}
private void HotkeyEditorDataGridYR_MouseEnter(object sender, EventArgs e)
{
Hotkey_Editor_Mouse_Enter(HotkeyEditorDataGridYR);
}
private void Hotkey_Editor_Mouse_Enter(DataGridView dgv)
{
dgv.Select();
}
public String getCurrentGameRes(IniFile inifile)
{
bool success;
int width = 800;
int height = 600;
width = inifile.GetIntValue("Video", "ScreenWidth", 800, out success);
if (success)
height = inifile.GetIntValue("Video", "ScreenHeight", 600, out success);
return width + "x" + height;
}
private void HotkeyEditorDataGridRA2_KeyUp(object sender, KeyEventArgs e)
{
Set_Datagrid_Current_Cell_Value_To_Internal_GameHotkey_Data(HotkeyEditorDataGridRA2, GameHotkeysRA2);
}
private void HotkeyEditorDataGridYR_KeyUp(object sender, KeyEventArgs e)
{
Set_Datagrid_Current_Cell_Value_To_Internal_GameHotkey_Data(HotkeyEditorDataGridYR, GameHotkeysYR);
}
private void Set_Datagrid_Current_Cell_Value_To_Internal_GameHotkey_Data(DataGridView dgv, GameHotkeys ghks)
{
dgv.CurrentCell.Value = ghks.Hotkey_Display_Value(dgv.CurrentCell.RowIndex);
}
private void ButResetToDefaultHotkeysYR_Click(object sender, EventArgs e)
{
IniFile OrigKeyboardMDINI = new IniFile("", Properties.Resources.keyboardmdini);
Load_Hotkey_Editor(HotkeyEditorDataGridYR, GameHotkeysYR, OrigKeyboardMDINI);
}
private void butResetToDefaultHotkeysRA2_Click(object sender, EventArgs e)
{
IniFile OrigKeyboardINI = new IniFile("", Properties.Resources.keyboardini);
Load_Hotkey_Editor(HotkeyEditorDataGridRA2, GameHotkeysRA2, OrigKeyboardINI);
}
}
}