ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/RenegadeMapSelector/RenegadeMapSelector.cpp
(Generate patch)

Comparing trunk/RenegadeMapSelector/RenegadeMapSelector.cpp (file contents):
Revision 69 by douglas, 2003-03-11T18:39:01-08:00 vs.
Revision 94 by douglas, 2003-03-22T13:53:44-08:00

# Line 4 | Line 4
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];
# Line 63 | Line 72 | inline void munge(void)
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
# Line 72 | Line 83 | int WINAPI WinMain(HINSTANCE hInstance,
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";
# Line 96 | Line 119 | int WINAPI WinMain(HINSTANCE hInstance,
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  
# Line 111 | Line 153 | int WINAPI WinMain(HINSTANCE hInstance,
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 <        if (debug) cin.get();
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)
# Line 148 | Line 207 | int CALLBACK selector(HWND hwndDlg, UINT
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";
# Line 175 | Line 234 | int CALLBACK selector(HWND hwndDlg, UINT
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                          }
# Line 203 | Line 262 | int CALLBACK selector(HWND hwndDlg, UINT
262                          EndDialog(hwndDlg, wParam);
263                          return true;
264                  case IDC_ADD_MAP:
265 +                        {
266 +                                unsigned count = SendMessage(GetDlgItem(hwndDlg,
267 +                                        IDC_AVAILABLE), LB_GETSELCOUNT, 0, 0);
268 +                                unsigned* additions = new unsigned[count];
269 +
270 +                                SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_GETSELITEMS,
271 +                                        count, long(additions));
272 +
273 +                                if (debug) cerr << "additions = {\n";
274 +                                for (unsigned index = 0; index < count; index++)
275 +                                {
276 +                                        if (debug) cerr << "   [" << index << "] = " <<
277 +                                                additions[index] << "\n";
278 +
279 +                                        char* name = new char[SendMessage(GetDlgItem(hwndDlg,
280 +                                                IDC_AVAILABLE), LB_GETTEXTLEN, additions[index], 0) + 1
281 +                                                ];
282 +
283 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_GETTEXT,
284 +                                                additions[index], long(name));
285 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
286 +                                                LB_ADDSTRING, 0, long(name));
287 +
288 +                                        delete [] name;
289 +                                }
290 +                                if (debug) cerr << "}\n";
291 +
292 +                                delete [] additions;
293 +
294 +                                SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_SETSEL,
295 +                                        false, -1);
296 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), false);
297 +                        }
298                          break;
299                  case IDC_REMOVE_MAP:
300 +                        {
301 +                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
302 +                                        LB_GETSELCOUNT, 0, 0);
303 +                                unsigned* removals = new unsigned[count];
304 +
305 +                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
306 +                                        count, long(removals));
307 +
308 +                                if (debug) cerr << "removals = {\n";
309 +                                for (unsigned index = count; index > 0; index--)
310 +                                {
311 +                                        if (debug) cerr << "   [" << index - 1 << "] = " <<
312 +                                                removals[index - 1] << "\n";
313 +
314 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
315 +                                                LB_DELETESTRING, removals[index - 1], 0);
316 +                                }
317 +                                if (debug) cerr << "}\n";
318 +
319 +                                delete [] removals;
320 +
321 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), false);
322 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
323 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
324 +                        }
325                          break;
326                  case IDC_UP_MAP:
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 +                        {
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))
# Line 271 | Line 487 | int CALLBACK selector(HWND hwndDlg, UINT
487  
488          return false;
489   }
490 +
491 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines