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

Comparing trunk/RenegadeMapSelector/RenegadeMapSelector.cpp (file contents):
Revision 73 by douglas, 2003-03-11T20:33:33-08:00 vs.
Revision 90 by douglas, 2003-03-15T22:15:08-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) { 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
# Line 74 | Line 84 | int WINAPI WinMain(HINSTANCE hInstance,
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;
# Line 103 | Line 121 | int main(int argc, char* argv[])
121  
122   #ifdef _WIN32
123                                  MessageBox(NULL, error.c_str(), "Bad Arguments", MB_ICONERROR);
124 + #else
125 +                                message(NULL, error, "Bad Arguments", GTK_MESSAGE_ERROR);
126   #endif
127                                  return 1;
128                          }
129                  }
130 +                else
131 +                {
132 +                        error = "The argument " + arg + " is not a valid argument.";
133 +
134 + #ifdef _WIN32
135 +                        MessageBox(NULL, error.c_str(), "Unknown Arguments", MB_ICONWARNING
136 +                                );
137 + #else
138 +                        message(NULL, error, "Unknown Arguments", GTK_MESSAGE_WARNING);
139 + #endif
140 +                }
141          }
142  
143   #ifdef _WIN32
# Line 122 | Line 153 | int main(int argc, char* argv[])
153  
154   #ifdef _WIN32
155                  MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR);
156 + #else
157 +                message(NULL, error, "Bad File", GTK_MESSAGE_ERROR);
158   #endif
159                  return 1;
160          }
161  
162   #ifdef _WIN32
163          DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector);
164 + #else
165 +        MapSelector selector;
166   #endif
167  
168          delete config;
# Line 144 | Line 179 | int main(int argc, char* argv[])
179   }
180  
181   #ifdef _WIN32
182 +
183   int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
184   {
185          switch (uMsg)
# Line 168 | Line 204 | int CALLBACK selector(HWND hwndDlg, UINT
204                          GetCurrentDirectory(MAX_PATH + 1, directory);
205                          if (debug) cerr << "directory = " << directory << "\n";
206  
207 <                        char* data = new char[MAX_PATH + 1];
207 >                        char* data = new char[strlen(directory) + 12];
208                          sprintf(data, "%s\\data\\*.mix", directory);
209                          delete [] directory;
210                          if (debug) cerr << "data = " << data << "\n";
# Line 195 | Line 231 | int CALLBACK selector(HWND hwndDlg, UINT
231                          if (GetListBoxInfo(GetDlgItem(hwndDlg, IDC_SELECTED)) == 0)
232                          {
233                                  MessageBox(hwndDlg, "You need at least one map.", "No Maps",
234 <                                        MB_ICONEXCLAMATION);
234 >                                        MB_ICONINFORMATION);
235  
236                                  return false;
237                          }
# Line 285 | Line 321 | int CALLBACK selector(HWND hwndDlg, UINT
321                          }
322                          break;
323                  case IDC_UP_MAP:
324 <                        cout << "STUB: up\a\n";
324 >                        {
325 >                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
326 >                                        LB_GETSELCOUNT, 0, 0);
327 >                                unsigned* ups = new unsigned[count];
328 >
329 >                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
330 >                                        count, long(ups));
331 >
332 >                                unsigned insert = ups[0] - 1;
333 >
334 >                                if (debug) cerr << "ups = {\n";
335 >                                for (unsigned index = 0; index < count; index++)
336 >                                {
337 >                                        if (debug) cerr << "   [" << index << "] = " << ups[index]
338 >                                                << "\n";
339 >
340 >                                        char* up = new char[SendMessage(GetDlgItem(hwndDlg,
341 >                                                IDC_SELECTED), LB_GETTEXTLEN, ups[index], 0) + 1];
342 >
343 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT,
344 >                                                ups[index], long(up));
345 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
346 >                                                LB_DELETESTRING, ups[index], 0);
347 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
348 >                                                LB_INSERTSTRING, insert, long(up));
349 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL,
350 >                                                true, insert++);
351 >                                }
352 >                                if (debug) cerr << "}\n";
353 >
354 >                                delete [] ups;
355 >
356 >                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
357 >                                        LB_GETSEL, 0, 0) == 0)
358 >                                {
359 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true);
360 >                                }
361 >                                else
362 >                                {
363 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
364 >                                }
365 >
366 >                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
367 >                                        LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED
368 >                                        ), LB_GETCOUNT, 0, 0) - 1, 0) == 0)
369 >                                {
370 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true);
371 >                                }
372 >                        }
373                          break;
374                  case IDC_DOWN_MAP:
375 <                        cout << "STUB: down\a\n";
375 >                        {
376 >                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
377 >                                        LB_GETSELCOUNT, 0, 0);
378 >                                unsigned* downs = new unsigned[count];
379 >
380 >                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
381 >                                        count, long(downs));
382 >
383 >                                unsigned insert = downs[count - 1] + 1;
384 >
385 >                                if (debug) cerr << "downs = {\n";
386 >                                for (unsigned index = count; index > 0; index--)
387 >                                {
388 >                                        if (debug) cerr << "   [" << index << "] = " << downs[index
389 >                                                - 1] << "\n";
390 >
391 >                                        char* down = new char[SendMessage(GetDlgItem(hwndDlg,
392 >                                                IDC_SELECTED), LB_GETTEXTLEN, downs[index - 1], 0) +
393 >                                                1];
394 >
395 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT,
396 >                                                downs[index - 1], long(down));
397 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
398 >                                                LB_DELETESTRING, downs[index - 1], 0);
399 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
400 >                                                LB_INSERTSTRING, insert, long(down));
401 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL,
402 >                                                true, insert--);
403 >                                }
404 >                                if (debug) cerr << "}\n";
405 >
406 >                                delete [] downs;
407 >
408 >                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
409 >                                        LB_GETSEL, 0, 0) == 0)
410 >                                {
411 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true);
412 >                                }
413 >
414 >                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
415 >                                        LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED
416 >                                        ), LB_GETCOUNT, 0, 0) - 1, 0) == 0)
417 >                                {
418 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true);
419 >                                }
420 >                                else
421 >                                {
422 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
423 >                                }
424 >                        }
425                          break;
426                  case IDC_AVAILABLE:
427                          switch (HIWORD(wParam))
# Line 351 | Line 484 | int CALLBACK selector(HWND hwndDlg, UINT
484  
485          return false;
486   }
487 +
488   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines