This repository has been archived by the owner on Oct 15, 2018. It is now read-only.
/
Settings.cs
207 lines (167 loc) · 9.07 KB
/
Settings.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
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms;
using IniParser;
using Unbroken.LaunchBox.Plugins;
namespace PCSX2_Configurator
{
public partial class SettingsForm : Form
{
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button != MouseButtons.Left) return;
Capture = false;
var msg = Message.Create(Handle, 0XA1, new IntPtr(2), IntPtr.Zero);
WndProc(ref msg);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(BackColor), e.ClipRectangle);
e.Graphics.DrawImage(Image.FromFile(Utilities.PluginDirectory + "\\Assets\\background.png"), new Rectangle(0, 0, Width, Height));
}
private static Image _checkmark;
private static PrivateFontCollection _privateFontCollection;
public SettingsForm()
{
InitializeComponent();
_checkmark = new Bitmap(Image.FromFile(Utilities.PluginDirectory + "\\Assets\\checkmark.png"), new Size(16 * Width / 400, 16 * Height / 400));
LoadFont();
LoadFromIniFile();
Icon = Utilities.EmulatorIcon;
}
private void LoadFont()
{
_privateFontCollection = new PrivateFontCollection();
_privateFontCollection.AddFontFile(Utilities.PluginDirectory + "\\Assets\\FixedsysExcelsiorAscii.ttf");
var fixedsys9 = new Font(_privateFontCollection.Families[0], 9, FontStyle.Regular);
var fixedsys10 = new Font(_privateFontCollection.Families[0], 10, FontStyle.Regular);
useIndependantMemoryCardsLBL.Font = fixedsys10;
useFileSettingsLBL.Font = fixedsys10;
useWindowSettingsLBL.Font = fixedsys10;
useLogSettingsLBL.Font = fixedsys10;
useFolderSettingsLBL.Font = fixedsys10;
useVMSettingsLBL.Font = fixedsys10;
useGSdxPluginSettingsLBL.Font = fixedsys10;
useSPU2xPluginSettingsLBL.Font = fixedsys10;
useLilyPadPluginSettingsLBL.Font = fixedsys10;
configDirLBL.Font = fixedsys9;
configDirTXT.Font = fixedsys9;
}
private void LoadFromIniFile()
{
var iniParser = new FileIniDataParser();
var pluginSettings = iniParser.ReadFile(Utilities.SettingsFile)["PCSX2_Configurator"];
if (bool.Parse(pluginSettings["UseIndependantMemoryCards"]))
useIndependantMemoryCardsCHK.Image = _checkmark;
if (bool.Parse(pluginSettings["UseCurrentFileSettings"]))
useCurrentFileSettingsCHK.Image = _checkmark;
if (bool.Parse(pluginSettings["UseCurrentWindowSettings"]))
useCurrentWindowSettingsCHK.Image = _checkmark;
if (bool.Parse(pluginSettings["UseCurrentLogSettings"]))
useCurrentLogSettingsCHK.Image = _checkmark;
if (bool.Parse(pluginSettings["UseCurrentFolderSettings"]))
useCurrentFolderSettingsCHK.Image = _checkmark;
if (bool.Parse(pluginSettings["UseCurrentVMSettings"]))
useCurrentVMSettingsCHK.Image = _checkmark;
if (bool.Parse(pluginSettings["UseCurrentGSdxPluginSettings"]))
useCurrentGSdxPluginSettingsCHK.Image = _checkmark;
if (bool.Parse(pluginSettings["UseCurrentSPU2xPluginSettings"]))
useCurrentSPU2xPluginSettingsCHK.Image = _checkmark;
if (bool.Parse(pluginSettings["UseCurrentLilyPadPluginSettings"]))
useCurrentLilyPadPluginSettingsCHK.Image = _checkmark;
configDirTXT.Text = pluginSettings["ConfigsDirectoryPath"];
}
private void WriteToIniFile()
{
var iniParser = new FileIniDataParser();
var pluginSettings = iniParser.ReadFile(Utilities.SettingsFile);
pluginSettings["PCSX2_Configurator"]["UseIndependantMemoryCards"] = (useIndependantMemoryCardsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["UseCurrentFileSettings"] = (useCurrentFileSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["UseCurrentWindowSettings"] = (useCurrentWindowSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["UseCurrentLogSettings"] = (useCurrentLogSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["AllowAllSettings"] = (useCurrentFolderSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["UseCurrentFolderSettings"] = (useCurrentWindowSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["UseCurrentVMSettings"] = (useCurrentVMSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["UseCurrentGSdxPluginSettings"] = (useCurrentGSdxPluginSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["UseCurrentLilyPadPluginSettings"] = (useCurrentLilyPadPluginSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["UseCurrentSPU2xPluginSettings"] = (useCurrentSPU2xPluginSettingsCHK.Image == _checkmark).ToString();
pluginSettings["PCSX2_Configurator"]["ConfigsDirectoryPath"] = configDirTXT.Text;
iniParser.WriteFile(Utilities.SettingsFile, pluginSettings);
}
private void ConfigDirBTN_Click(object sender, EventArgs e)
{
if (configDirDLG.ShowDialog() == DialogResult.OK)
{
configDirTXT.Text = configDirDLG.SelectedPath;
}
}
private void CloseBTN_Click(object sender, EventArgs e)
{
WriteToIniFile();
Close();
}
private void UseIndependantMemoryCardsCHK_Click(object sender, EventArgs e)
{
useIndependantMemoryCardsCHK.Image = (useIndependantMemoryCardsCHK.Image != _checkmark) ? _checkmark : null;
}
private void UseCurrentFileSettingsCHK_Click(object sender, EventArgs e)
{
useCurrentFileSettingsCHK.Image = (useCurrentFileSettingsCHK.Image != _checkmark) ? _checkmark : null;
}
private void UseCurrentWindowSettingsCHK_Click(object sender, EventArgs e)
{
useCurrentWindowSettingsCHK.Image = (useCurrentWindowSettingsCHK.Image != _checkmark) ? _checkmark : null;
}
private void UseCurrentLogSettingsCHK_Click(object sender, EventArgs e)
{
useCurrentLogSettingsCHK.Image = (useCurrentLogSettingsCHK.Image != _checkmark) ? _checkmark : null;
}
private void UseCurrentFolderSettingsCHK_Click(object sender, EventArgs e)
{
useCurrentFolderSettingsCHK.Image = (useCurrentFolderSettingsCHK.Image != _checkmark) ? _checkmark : null;
}
private void UseCurrentVMSettingsCHK_Click(object sender, EventArgs e)
{
useCurrentVMSettingsCHK.Image = (useCurrentVMSettingsCHK.Image != _checkmark) ? _checkmark : null;
}
private void UseCurrentGSdxPluginSettingsCHK_Click(object sender, EventArgs e)
{
useCurrentGSdxPluginSettingsCHK.Image = (useCurrentGSdxPluginSettingsCHK.Image != _checkmark) ? _checkmark : null;
}
private void UseCurrentSPU2xPluginSettingsCHK_Click(object sender, EventArgs e)
{
useCurrentSPU2xPluginSettingsCHK.Image = (useCurrentSPU2xPluginSettingsCHK.Image != _checkmark) ? _checkmark : null;
}
private void UseCurrentLilyPadPluginSettingsCHK_Click(object sender, EventArgs e)
{
useCurrentLilyPadPluginSettingsCHK.Image = (useCurrentLilyPadPluginSettingsCHK.Image != _checkmark) ? _checkmark : null;
}
}
public class SettingsPlugin : ISystemMenuItemPlugin
{
private static SettingsForm _settingsForm;
public string Caption => "PCSX2 Configurator Settings";
public Image IconImage => Utilities.EmulatorIcon?.ToBitmap();
public bool ShowInLaunchBox => true;
public bool ShowInBigBox => false;
public bool AllowInBigBoxWhenLocked => ShowInBigBox;
public void OnSelected()
{
if (Utilities.FullEmulatorPath == null)
{
MessageBox.Show($@"PCSX2 Could Not Not Be Found{Environment.NewLine}Please Add PCSX2 as an Emulator and Restart LaunchBox", @"PCSX2 Configurator");
}
else
{
_settingsForm?.Close();
_settingsForm = new SettingsForm { StartPosition = FormStartPosition.Manual };
_settingsForm.Location = new Point(
PluginHelper.LaunchBoxMainForm.Location.X + (int)((PluginHelper.LaunchBoxMainForm.Width - _settingsForm.Width) * 0.5f),
PluginHelper.LaunchBoxMainForm.Location.Y + (int)((PluginHelper.LaunchBoxMainForm.Height - _settingsForm.Height) * 0.5f));
_settingsForm.Show();
}
}
}
}