4 |
|
// |
5 |
|
// RenegadeMapSelector.cpp |
6 |
|
|
7 |
+ |
#include "RenegadeMapSelector.h" |
8 |
+ |
#include "RenegadeConfig.h" |
9 |
+ |
|
10 |
|
#ifdef _WIN32 |
11 |
+ |
|
12 |
|
#include <io.h> |
13 |
|
#include <fcntl.h> |
14 |
|
#include "resource.h" |
11 |
– |
#endif |
15 |
|
|
16 |
< |
#include "RenegadeMapSelector.h" |
17 |
< |
#include "RenegadeConfig.h" |
16 |
> |
#else |
17 |
> |
|
18 |
> |
#include "MapSelector.h" |
19 |
> |
|
20 |
> |
#endif |
21 |
|
|
22 |
|
bool debug = false; |
23 |
|
string program; |
24 |
|
RenegadeConfig* config; |
25 |
|
|
26 |
|
#ifndef _WIN32 |
27 |
+ |
|
28 |
|
inline string fix(const string& ansi) { return ansi; } |
29 |
< |
inline void munge(void) { return; } |
29 |
> |
inline void munge(void) { debug = true; } |
30 |
> |
|
31 |
|
#else |
32 |
+ |
|
33 |
|
inline string fix(const wstring& wide) |
34 |
|
{ |
35 |
|
char* buffer = new char[wide.length() + 1]; |
72 |
|
|
73 |
|
debug = true; |
74 |
|
} |
75 |
+ |
|
76 |
|
#endif |
77 |
|
|
78 |
+ |
#ifdef _WIN32 |
79 |
|
int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); |
80 |
|
|
81 |
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR |
83 |
|
{ |
84 |
|
int argc; |
85 |
|
unsigned short** argv = CommandLineToArgvW(GetCommandLineW(), &argc); |
86 |
+ |
#else |
87 |
+ |
void selector(void); |
88 |
+ |
|
89 |
+ |
int main(int argc, char* argv[]) |
90 |
+ |
{ |
91 |
+ |
if (!gtk_init_check(&argc, &argv)) |
92 |
+ |
{ |
93 |
+ |
cerr << argv[0] << ": Cannot open display, need a clue-by-four?\n"; |
94 |
+ |
|
95 |
+ |
return 1; |
96 |
+ |
} |
97 |
+ |
#endif |
98 |
|
|
99 |
|
string error; |
100 |
|
string file = "svrcfg_cnc.ini"; |
119 |
|
{ |
120 |
|
error = "The argument -file must be followed by a filename."; |
121 |
|
|
122 |
+ |
cerr << program << ": " << error << "\n"; |
123 |
+ |
#ifdef _WIN32 |
124 |
|
MessageBox(NULL, error.c_str(), "Bad Arguments", MB_ICONERROR); |
125 |
+ |
#else |
126 |
+ |
message(NULL, error, "Bad Arguments", GTK_MESSAGE_ERROR); |
127 |
+ |
#endif |
128 |
|
return 1; |
129 |
|
} |
130 |
|
} |
131 |
+ |
else |
132 |
+ |
{ |
133 |
+ |
error = "The argument " + arg + " is not a valid argument."; |
134 |
+ |
|
135 |
+ |
cerr << program << ": " << error << "\n"; |
136 |
+ |
#ifdef _WIN32 |
137 |
+ |
MessageBox(NULL, error.c_str(), "Unknown Arguments", MB_ICONWARNING |
138 |
+ |
); |
139 |
+ |
#else |
140 |
+ |
message(NULL, error, "Unknown Arguments", GTK_MESSAGE_WARNING); |
141 |
+ |
#endif |
142 |
+ |
} |
143 |
|
} |
144 |
|
|
145 |
+ |
#ifdef _WIN32 |
146 |
|
GlobalFree(argv); |
147 |
+ |
#endif |
148 |
|
|
149 |
|
if (debug) cerr << "file = " << file << "\n"; |
150 |
|
|
153 |
|
{ |
154 |
|
error = "Could not open " + file + "."; |
155 |
|
|
156 |
+ |
cerr << program << ": " << error << "\n"; |
157 |
+ |
#ifdef _WIN32 |
158 |
|
MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR); |
159 |
+ |
#else |
160 |
+ |
message(NULL, error, "Bad File", GTK_MESSAGE_ERROR); |
161 |
+ |
#endif |
162 |
|
return 1; |
163 |
|
} |
164 |
|
|
165 |
+ |
#ifdef _WIN32 |
166 |
|
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector); |
167 |
+ |
#else |
168 |
+ |
MapSelector selector; |
169 |
+ |
#endif |
170 |
|
|
171 |
|
delete config; |
172 |
|
|
173 |
+ |
#ifdef _WIN32 |
174 |
|
if (debug) |
175 |
|
{ |
176 |
|
cout << "Press enter key to exit . . ."; |
177 |
|
cin.get(); |
178 |
|
} |
179 |
+ |
#endif |
180 |
|
|
181 |
|
return 0; |
182 |
|
} |
183 |
|
|
184 |
+ |
#ifdef _WIN32 |
185 |
+ |
|
186 |
|
int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
187 |
|
{ |
188 |
|
switch (uMsg) |
207 |
|
GetCurrentDirectory(MAX_PATH + 1, directory); |
208 |
|
if (debug) cerr << "directory = " << directory << "\n"; |
209 |
|
|
210 |
< |
char* data = new char[MAX_PATH + 1]; |
210 |
> |
char* data = new char[strlen(directory) + 12]; |
211 |
|
sprintf(data, "%s\\data\\*.mix", directory); |
212 |
|
delete [] directory; |
213 |
|
if (debug) cerr << "data = " << data << "\n"; |
234 |
|
if (GetListBoxInfo(GetDlgItem(hwndDlg, IDC_SELECTED)) == 0) |
235 |
|
{ |
236 |
|
MessageBox(hwndDlg, "You need at least one map.", "No Maps", |
237 |
< |
MB_ICONEXCLAMATION); |
237 |
> |
MB_ICONINFORMATION); |
238 |
|
|
239 |
|
return false; |
240 |
|
} |
324 |
|
} |
325 |
|
break; |
326 |
|
case IDC_UP_MAP: |
327 |
< |
cout << "STUB: up\a\n"; |
327 |
> |
{ |
328 |
> |
unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
329 |
> |
LB_GETSELCOUNT, 0, 0); |
330 |
> |
unsigned* ups = new unsigned[count]; |
331 |
> |
|
332 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS, |
333 |
> |
count, long(ups)); |
334 |
> |
|
335 |
> |
unsigned insert = ups[0] - 1; |
336 |
> |
|
337 |
> |
if (debug) cerr << "ups = {\n"; |
338 |
> |
for (unsigned index = 0; index < count; index++) |
339 |
> |
{ |
340 |
> |
if (debug) cerr << " [" << index << "] = " << ups[index] |
341 |
> |
<< "\n"; |
342 |
> |
|
343 |
> |
char* up = new char[SendMessage(GetDlgItem(hwndDlg, |
344 |
> |
IDC_SELECTED), LB_GETTEXTLEN, ups[index], 0) + 1]; |
345 |
> |
|
346 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT, |
347 |
> |
ups[index], long(up)); |
348 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
349 |
> |
LB_DELETESTRING, ups[index], 0); |
350 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
351 |
> |
LB_INSERTSTRING, insert, long(up)); |
352 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL, |
353 |
> |
true, insert++); |
354 |
> |
} |
355 |
> |
if (debug) cerr << "}\n"; |
356 |
> |
|
357 |
> |
delete [] ups; |
358 |
> |
|
359 |
> |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
360 |
> |
LB_GETSEL, 0, 0) == 0) |
361 |
> |
{ |
362 |
> |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true); |
363 |
> |
} |
364 |
> |
else |
365 |
> |
{ |
366 |
> |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false); |
367 |
> |
} |
368 |
> |
|
369 |
> |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
370 |
> |
LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED |
371 |
> |
), LB_GETCOUNT, 0, 0) - 1, 0) == 0) |
372 |
> |
{ |
373 |
> |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true); |
374 |
> |
} |
375 |
> |
} |
376 |
|
break; |
377 |
|
case IDC_DOWN_MAP: |
378 |
< |
cout << "STUB: down\a\n"; |
378 |
> |
{ |
379 |
> |
unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
380 |
> |
LB_GETSELCOUNT, 0, 0); |
381 |
> |
unsigned* downs = new unsigned[count]; |
382 |
> |
|
383 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS, |
384 |
> |
count, long(downs)); |
385 |
> |
|
386 |
> |
unsigned insert = downs[count - 1] + 1; |
387 |
> |
|
388 |
> |
if (debug) cerr << "downs = {\n"; |
389 |
> |
for (unsigned index = count; index > 0; index--) |
390 |
> |
{ |
391 |
> |
if (debug) cerr << " [" << index << "] = " << downs[index |
392 |
> |
- 1] << "\n"; |
393 |
> |
|
394 |
> |
char* down = new char[SendMessage(GetDlgItem(hwndDlg, |
395 |
> |
IDC_SELECTED), LB_GETTEXTLEN, downs[index - 1], 0) + |
396 |
> |
1]; |
397 |
> |
|
398 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT, |
399 |
> |
downs[index - 1], long(down)); |
400 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
401 |
> |
LB_DELETESTRING, downs[index - 1], 0); |
402 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
403 |
> |
LB_INSERTSTRING, insert, long(down)); |
404 |
> |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL, |
405 |
> |
true, insert--); |
406 |
> |
} |
407 |
> |
if (debug) cerr << "}\n"; |
408 |
> |
|
409 |
> |
delete [] downs; |
410 |
> |
|
411 |
> |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
412 |
> |
LB_GETSEL, 0, 0) == 0) |
413 |
> |
{ |
414 |
> |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true); |
415 |
> |
} |
416 |
> |
|
417 |
> |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
418 |
> |
LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED |
419 |
> |
), LB_GETCOUNT, 0, 0) - 1, 0) == 0) |
420 |
> |
{ |
421 |
> |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true); |
422 |
> |
} |
423 |
> |
else |
424 |
> |
{ |
425 |
> |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false); |
426 |
> |
} |
427 |
> |
} |
428 |
|
break; |
429 |
|
case IDC_AVAILABLE: |
430 |
|
switch (HIWORD(wParam)) |
487 |
|
|
488 |
|
return false; |
489 |
|
} |
490 |
+ |
|
491 |
+ |
#endif |