-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameData.cpp
executable file
·247 lines (200 loc) · 8.66 KB
/
gameData.cpp
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
#include <cstdlib>
#include <iterator>
#include "gameData.h"
#include "wx/hashset.h"
BEGIN_EVENT_TABLE(gameDataDialog, wxDialog)
EVT_LISTBOX(ID_gameTitle, gameDataDialog::onGameSelect)
EVT_CHAR_HOOK(gameDataDialog::onChar)
EVT_BUTTON(wxID_OK, gameDataDialog::onOK)
EVT_TEXT(ID_searchBox, gameDataDialog::SearchUpdate)
EVT_TEXT_ENTER(ID_searchBox, gameDataDialog::Search)
EVT_SEARCHCTRL_SEARCH_BTN(ID_searchBox, gameDataDialog::Search)
EVT_SET_FOCUS(gameDataDialog::setFocus)
END_EVENT_TABLE()
WX_DECLARE_HASH_SET(wxString, wxStringHash, wxStringEqual, MyPrefix);
//WX_DECLARE_STRING_HASH_MAP( wxString, MyPrefix );
gameDataDialog::gameDataDialog(wxWindow* parent, wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size, long style)
: wxDialog(parent, id, title, pos, size, style) {
windowWithFocus=wxNOT_FOUND;
selectedInfo = wxNOT_FOUND;
Desc1 = new wxStaticText(this, ID_Desc1, wxS("Game Title"), wxPoint(0, 20), wxDefaultSize, 0);
Desc2 = new wxStaticText(this, ID_Desc2, wxS("Game ID"), wxPoint(330, 80), wxDefaultSize, 0);
Desc3 = new wxStaticText(this, ID_Desc3, wxS("Region"), wxPoint(330, 230), wxDefaultSize, 0);
RegionDesc = new wxStaticText(this, ID_RegionDesc, wxS(""), wxPoint(330, 265), wxDefaultSize);
//line=new wxStaticLine(this,wxID_ANY,wxPoint(0,380),wxSize(-1,-1),wxLI_HORIZONTAL);
gameName = new wxListBox(this, ID_gameTitle, wxPoint(0, 80), wxSize(300, 350),
0,NULL, wxLB_SINGLE);
gameID = new wxChoice(this, ID_gameID, wxPoint(330, 115), wxSize(75, 30));
gameNum = new wxTextCtrl(this, ID_gameID, wxS(""), wxPoint(415, 115), wxSize(50, 30), 0, wxTextValidator(wxFILTER_NUMERIC));
gameNum->SetMaxLength(5);
searchBox = new wxSearchCtrl(this, ID_searchBox, wxS(""), wxPoint(0, 50), wxSize(300, -1), wxTE_PROCESS_ENTER);
searchBox->ShowSearchButton(true);
generateGameList();
sizer = CreateButtonSizer(wxOK | wxCANCEL | wxNO_DEFAULT);
sizer->SetDimension(300, 480, -1, -1);
searchBox->SetFocus();
}
void gameDataDialog::onGameSelect(wxCommandEvent&event) {
selectedInfo = gameName->GetSelection();
int result = gameID->FindString(gameInfo.gameIDcode[selectedInfo]);
gameNum->SetValue(gameInfo.gameIDnum[selectedInfo]);
if (result != wxNOT_FOUND)
gameID->SetSelection(result);
RegionDesc->SetLabel(gameInfo.region[selectedInfo]);
event.Skip();
}
wxArrayString gameDataDialog::PrefixList(){
return gameID->GetStrings();
}
void gameDataDialog::generateGameList() {
gameInfo.gameIDcode.Alloc(10152);
gameInfo.gameIDnum.Alloc(10152);
gameInfo.gameTitle.Alloc(10152);
gameInfo.region.Alloc(10152);
gameInfo.saveDesc.Alloc(10152);
gameInfo.saveFolder.Alloc(10152);
gameInfo.scannerID.Alloc(10152);
gameInfo.videoFormat.Alloc(10152);
wxFileInputStream input(wxS("gameinfo.txt"));
if (!input.IsOk() || input.Eof()) {
Close();
return;
}
wxTextInputStream infile(input);
wxString dataline;
wxArrayString lineTokenizer;
MyPrefix codeprefix;
wxRegEx TitleRegion(wxS("^(.*)(\\[.+\\]).*$"), wxRE_EXTENDED); //Removes the region from the game saveDesc
wxRegEx SaveSplit(wxS("^([[:alpha:]]+)(.*)"), wxRE_EXTENDED);
dataline = infile.ReadLine();
while (input.IsOk() && !input.Eof()) {
lineTokenizer = wxStringTokenize(dataline, wxS(";"), wxTOKEN_RET_EMPTY_ALL);
wxArrayString fgameID = wxStringTokenize(lineTokenizer[tGameID], wxS("-"), wxTOKEN_RET_EMPTY_ALL); //Splits GameId form:"<code>-<num>" into full game ID
codeprefix.insert(fgameID[0]);
gameInfo.gameIDcode.Add(fgameID[0]);
if(fgameID.size()>1)
gameInfo.gameIDnum.Add(fgameID[1]);
else
gameInfo.gameIDnum.Add(wxT("NULL"));
if (SaveSplit.Matches(lineTokenizer[tSaveFolder])) {
gameInfo.saveIDcode.Add(SaveSplit.GetMatch(lineTokenizer[tSaveFolder], 1));
gameInfo.saveIDnum.Add(SaveSplit.GetMatch(lineTokenizer[tSaveFolder], 2));
}
gameInfo.saveFolder.Add(lineTokenizer[tSaveFolder]);
if (TitleRegion.Matches(lineTokenizer[tSaveDesc])) {
gameInfo.saveDesc.Add(TitleRegion.GetMatch(lineTokenizer[tSaveDesc], 1).Trim());
gameInfo.region.Add(TitleRegion.GetMatch(lineTokenizer[tSaveDesc], 2));
}
gameInfo.gameTitle.Add(lineTokenizer[tGameName]);
gameInfo.videoFormat.Add(lineTokenizer[tVideoFormat]);
gameInfo.scannerID.Add(lineTokenizer[tScanID]);
dataline = infile.ReadLine();
}
gameName->Set(gameInfo.gameTitle);
for (MyPrefix::iterator it = codeprefix.begin(); it != codeprefix.end(); ++it) {
gameID->Append(*it);
}
gameName->SetSelection(0);
}
void gameDataDialog::onOK(wxCommandEvent& WXUNUSED(event)) {
m_gameIDcode = gameID->GetStringSelection();
m_gameIDnum = gameNum->GetValue();
m_region = RegionDesc->GetLabel();
if (selectedInfo != wxNOT_FOUND) {
m_saveIDcode= gameInfo.saveIDcode[selectedInfo];
m_saveIDnum= gameInfo.saveIDnum[selectedInfo];
m_saveFolder = gameInfo.saveFolder[selectedInfo];
m_saveDesc = gameInfo.saveDesc[selectedInfo];
m_gameTitle = gameInfo.gameTitle[selectedInfo];
m_videoFormat = gameInfo.videoFormat[selectedInfo];
m_scannerID = gameInfo.scannerID[selectedInfo];
}
EndModal(wxID_OK);
}
void gameDataDialog::onChar(wxKeyEvent& event) {
if (gameName->GetId()==windowWithFocus) {
wxString text_to_search = (wxChar) event.GetKeyCode();
int selection = 0;
selection = gameName->GetSelection();
int count = gameName->GetCount();
if (count != 0) {
for (int i = selection + 1; i != selection; i = (i+1) % count) {
wxString choice = gameName->GetString(i).Lower();
if (choice.StartsWith(text_to_search)) {
gameName->SetSelection(i);
break;
}
}
}
}
event.Skip();
}
void gameDataDialog::setFocus(wxFocusEvent& event){
windowWithFocus=event.GetId();
event.Skip();
}
void gameDataDialog::Search(wxCommandEvent& event) {
wxString text_to_search = searchBox->GetValue().Lower();
int selection = 0;
selection = gameName->GetSelection();
int count = gameName->GetCount();
if (count != 0) {
for (int i = selection + 1; i != selection; i = (i+1) % count) {
wxString choice = gameName->GetString(i).Lower();
if (choice.StartsWith(text_to_search)) {
gameName->SetSelection(i);
selectedInfo = gameName->GetSelection();
int result = gameID->FindString(gameInfo.gameIDcode[selectedInfo]);
gameNum->SetValue(gameInfo.gameIDnum[selectedInfo]);
if (result != wxNOT_FOUND)
gameID->SetSelection(result);
RegionDesc->SetLabel(gameInfo.region[selectedInfo]);
break;
}
}
}
event.Skip();
}
void gameDataDialog::SearchUpdate(wxCommandEvent& event) {
wxString text_to_search = searchBox->GetValue().Lower();
int selection = 0;
selection = gameName->GetSelection();
int count = gameName->GetCount();
wxString choice;
int num = 0;
if (count != 0) {
for (int i = selection; num < count; i = (1 + i) % count, num++) {
choice = gameName->GetString(i).Lower();
if (choice.StartsWith(text_to_search)) {
//std::cout <<(char*)choice.char_str()<<'\n';
gameName->SetSelection(i);
selectedInfo = gameName->GetSelection();
int result = gameID->FindString(gameInfo.gameIDcode[selectedInfo]);
gameNum->SetValue(gameInfo.gameIDnum[selectedInfo]);
if (result != wxNOT_FOUND)
gameID->SetSelection(result);
RegionDesc->SetLabel(gameInfo.region[selectedInfo]);
break;
}
}
}
event.Skip();
}
void gameDataDialog::SearchID(const wxString& searchID, gameData& metaData){
for(unsigned int i=0;i<gameInfo.scannerID.GetCount();i++){
if(searchID==gameInfo.scannerID[i]){
metaData.gameID=gameInfo.scannerID[i];
metaData.gameIDcode=gameInfo.gameIDcode[i];
metaData.gameIDnum=gameInfo.gameIDnum[i];
metaData.saveID=gameInfo.saveFolder[i];
metaData.saveIDcode=gameInfo.saveIDcode[i];
metaData.saveIDnum=gameInfo.saveIDnum[i];
metaData.saveDesc=gameInfo.saveDesc[i];
metaData.region=gameInfo.region[i];
metaData.gameTitle=gameInfo.gameTitle[i];
break;
}
}
return;
}