-
-
Notifications
You must be signed in to change notification settings - Fork 460
/
GameGenieCodeForm.cs
147 lines (129 loc) · 5.7 KB
/
GameGenieCodeForm.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
using com.clusterrr.hakchi_gui.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace com.clusterrr.hakchi_gui
{
public partial class GameGenieCodeForm : Form
{
private readonly NesMiniApplication FGame;
private GameGenieDataBase FGameGenieDataBase;
private List<string> OtherCodes;
public GameGenieCodeForm(NesMiniApplication AGame)
{
InitializeComponent();
FGame = AGame;
FGameGenieDataBase = new GameGenieDataBase(FGame);
this.Text += string.Format(": {0}", FGame.Name);
LoadGameGenieCodes();
}
private void LoadGameGenieCodes()
{
checkedListBoxGameCode.Items.Clear();
var lCodeSorted = FGameGenieDataBase.GameCodes.OrderBy(o => o.Description);
var lSelectedCode = (FGame as NesMiniApplication).GameGenie.ToUpper().Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var code in lCodeSorted)
checkedListBoxGameCode.Items.Add(code, lSelectedCode.Contains(code.Code.ToUpper().Trim()));
OtherCodes = new List<string>();
var knownCodes = from o in lCodeSorted select o.Code.ToUpper().Trim();
foreach (var code in lSelectedCode)
{
if (!knownCodes.Contains(code.ToUpper().Trim()))
OtherCodes.Add(code);
}
}
private void SaveSelectedCodes()
{
var selected = new List<string>();
foreach (GameGenieCode code in checkedListBoxGameCode.CheckedItems)
selected.Add(code.Code);
selected.AddRange(OtherCodes);
(FGame as NesMiniApplication).GameGenie = string.Join(",", selected.ToArray());
}
private void buttonOk_Click(object sender, EventArgs e)
{
SaveSelectedCodes();
DialogResult = System.Windows.Forms.DialogResult.OK;
}
private void GameGenieForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (FGameGenieDataBase.Modified)
FGameGenieDataBase.Save();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
GameGenieCodeAddModForm lForm = new GameGenieCodeAddModForm(FGame);
if (lForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var newCode = lForm.Code.ToUpper().Trim();
GameGenieCode lCode = null;
foreach (GameGenieCode Code in checkedListBoxGameCode.Items)
{
if (Code.Code.ToUpper().Trim() == newCode)
{
lCode = Code;
break;
}
}
if (lCode != null)
{
if (MessageBox.Show(this, Resources.GGCodeExists, Resources.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
lCode.Description = lForm.Description;
FGameGenieDataBase.ModifyCode(lCode);
}
}
else
{
GameGenieCode lNewCode = new GameGenieCode(newCode, lForm.Description);
FGameGenieDataBase.AddCode(lNewCode);
LoadGameGenieCodes();
}
}
}
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
var i = (int)(sender as ToolStripMenuItem).Tag;
GameGenieCode lCode = (GameGenieCode)checkedListBoxGameCode.Items[i];
GameGenieCodeAddModForm lForm = new GameGenieCodeAddModForm(FGame);
lForm.Code = lCode.Code;
lForm.Description = lCode.Description;
if (lForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
lCode.Code = lForm.Code;
lCode.Description = lForm.Description;
FGameGenieDataBase.ModifyCode(lCode);
}
}
private void removeToolStripMenuItem_Click(object sender, EventArgs e)
{
var i = (int)(sender as ToolStripMenuItem).Tag;
GameGenieCode lCode = (GameGenieCode)checkedListBoxGameCode.Items[i];
if (MessageBox.Show(this, string.Format(Resources.GGCodeDelete, lCode.Description),
Resources.AreYouSure, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
FGameGenieDataBase.DeleteCode(lCode);
checkedListBoxGameCode.Items.Remove(lCode);
}
}
private void buttonImport_Click(object sender, EventArgs e)
{
if (ofdXmlFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
FGameGenieDataBase.ImportCodes(ofdXmlFile.FileName);
LoadGameGenieCodes();
}
}
private void checkedListBoxGameCode_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
var i = checkedListBoxGameCode.IndexFromPoint(e.X, e.Y);
removeToolStripMenuItem.Tag = editToolStripMenuItem.Tag = i;
removeToolStripMenuItem.Enabled = editToolStripMenuItem.Enabled = i >= 0;
contextMenuStrip.Show(sender as Control, e.X, e.Y);
}
}
}
}