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 70 by douglas, 2003-03-11T19:48:27-08:00 vs.
Revision 88 by douglas, 2003-03-15T20:18:13-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 + #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          }
131  
132 + #ifdef _WIN32
133          GlobalFree(argv);
134 + #endif
135  
136          if (debug) cerr << "file = " << file << "\n";
137  
# Line 111 | Line 140 | int WINAPI WinMain(HINSTANCE hInstance,
140          {
141                  error = "Could not open " + file + ".";
142  
143 + #ifdef _WIN32
144                  MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR);
145 + #else
146 +                message(NULL, error, "Bad File", GTK_MESSAGE_ERROR);
147 + #endif
148                  return 1;
149          }
150  
151 + #ifdef _WIN32
152          DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector);
153 + #else
154 +        MapSelector selector;
155 + #endif
156  
157          delete config;
158  
159 + #ifdef _WIN32
160          if (debug)
161          {
162                  cout << "Press enter key to exit . . .";
163                  cin.get();
164          }
165 + #endif
166  
167          return 0;
168   }
169  
170 + #ifdef _WIN32
171 +
172   int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
173   {
174          switch (uMsg)
# Line 152 | Line 193 | int CALLBACK selector(HWND hwndDlg, UINT
193                          GetCurrentDirectory(MAX_PATH + 1, directory);
194                          if (debug) cerr << "directory = " << directory << "\n";
195  
196 <                        char* data = new char[MAX_PATH + 1];
196 >                        char* data = new char[strlen(directory) + 12];
197                          sprintf(data, "%s\\data\\*.mix", directory);
198                          delete [] directory;
199                          if (debug) cerr << "data = " << data << "\n";
# Line 269 | Line 310 | int CALLBACK selector(HWND hwndDlg, UINT
310                          }
311                          break;
312                  case IDC_UP_MAP:
313 <                        cout << "STUB: up\a\n";
313 >                        {
314 >                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
315 >                                        LB_GETSELCOUNT, 0, 0);
316 >                                unsigned* ups = new unsigned[count];
317 >
318 >                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
319 >                                        count, long(ups));
320 >
321 >                                unsigned insert = ups[0] - 1;
322 >
323 >                                if (debug) cerr << "ups = {\n";
324 >                                for (unsigned index = 0; index < count; index++)
325 >                                {
326 >                                        if (debug) cerr << "   [" << index << "] = " << ups[index]
327 >                                                << "\n";
328 >
329 >                                        char* up = new char[SendMessage(GetDlgItem(hwndDlg,
330 >                                                IDC_SELECTED), LB_GETTEXTLEN, ups[index], 0) + 1];
331 >
332 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT,
333 >                                                ups[index], long(up));
334 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
335 >                                                LB_DELETESTRING, ups[index], 0);
336 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
337 >                                                LB_INSERTSTRING, insert, long(up));
338 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL,
339 >                                                true, insert++);
340 >                                }
341 >                                if (debug) cerr << "}\n";
342 >
343 >                                delete [] ups;
344 >
345 >                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
346 >                                        LB_GETSEL, 0, 0) == 0)
347 >                                {
348 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true);
349 >                                }
350 >                                else
351 >                                {
352 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
353 >                                }
354 >
355 >                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
356 >                                        LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED
357 >                                        ), LB_GETCOUNT, 0, 0) - 1, 0) == 0)
358 >                                {
359 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true);
360 >                                }
361 >                        }
362                          break;
363                  case IDC_DOWN_MAP:
364 <                        cout << "STUB: down\a\n";
364 >                        {
365 >                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
366 >                                        LB_GETSELCOUNT, 0, 0);
367 >                                unsigned* downs = new unsigned[count];
368 >
369 >                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
370 >                                        count, long(downs));
371 >
372 >                                unsigned insert = downs[count - 1] + 1;
373 >
374 >                                if (debug) cerr << "downs = {\n";
375 >                                for (unsigned index = count; index > 0; index--)
376 >                                {
377 >                                        if (debug) cerr << "   [" << index << "] = " << downs[index
378 >                                                - 1] << "\n";
379 >
380 >                                        char* down = new char[SendMessage(GetDlgItem(hwndDlg,
381 >                                                IDC_SELECTED), LB_GETTEXTLEN, downs[index - 1], 0) +
382 >                                                1];
383 >
384 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT,
385 >                                                downs[index - 1], long(down));
386 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
387 >                                                LB_DELETESTRING, downs[index - 1], 0);
388 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
389 >                                                LB_INSERTSTRING, insert, long(down));
390 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL,
391 >                                                true, insert--);
392 >                                }
393 >                                if (debug) cerr << "}\n";
394 >
395 >                                delete [] downs;
396 >
397 >                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
398 >                                        LB_GETSEL, 0, 0) == 0)
399 >                                {
400 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true);
401 >                                }
402 >
403 >                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
404 >                                        LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED
405 >                                        ), LB_GETCOUNT, 0, 0) - 1, 0) == 0)
406 >                                {
407 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true);
408 >                                }
409 >                                else
410 >                                {
411 >                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
412 >                                }
413 >                        }
414                          break;
415                  case IDC_AVAILABLE:
416                          switch (HIWORD(wParam))
# Line 335 | Line 473 | int CALLBACK selector(HWND hwndDlg, UINT
473  
474          return false;
475   }
476 +
477 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines