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 66 by douglas, 2003-03-11T14:43:01-08:00 vs.
Revision 73 by douglas, 2003-03-11T20:33:33-08:00

# Line 7 | Line 7
7   #ifdef _WIN32
8   #include <io.h>
9   #include <fcntl.h>
10 + #include "resource.h"
11   #endif
12  
13   #include "RenegadeMapSelector.h"
14 < #include "resource.h"
14 > #include "RenegadeConfig.h"
15  
16   bool debug = false;
17   string program;
18 + RenegadeConfig* config;
19  
20   #ifndef _WIN32
21   inline string fix(const string& ansi) { return ansi; }
22 + inline void munge(void) { debug = true; }
23   #else
24   inline string fix(const wstring& wide)
25   {
# Line 31 | Line 34 | inline string fix(const wstring& wide)
34          return ansi;
35   }
36  
37 < inline munge(void)
37 > inline void munge(void)
38   {
39 +        if (debug) return;
40 +
41          AllocConsole();
42          SetConsoleTitle("Renegade Map Selector");
43  
# Line 55 | Line 60 | inline munge(void)
60          cin.sync_with_stdio();
61          cout.sync_with_stdio();
62          cerr.sync_with_stdio();
63 +
64 +        debug = true;
65   }
66   #endif
67  
68 + #ifdef _WIN32
69   int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
70  
71   int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
# Line 65 | Line 73 | int WINAPI WinMain(HINSTANCE hInstance,
73   {
74          int argc;
75          unsigned short** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
76 + #else
77 + int main(int argc, char* argv[])
78 + {
79 + #endif
80 +
81 +        string error;
82 +        string file = "svrcfg_cnc.ini";
83  
84          program = fix(argv[0]);
85  
# Line 74 | Line 89 | int WINAPI WinMain(HINSTANCE hInstance,
89  
90                  if (arg == "-D")
91                  {
92 <                        debug = true;
92 >                        munge();
93 >                }
94 >                else if (arg == "-file")
95 >                {
96 >                        if (++index < argc)
97 >                        {
98 >                                file = fix(argv[index]);
99 >                        }
100 >                        else
101 >                        {
102 >                                error = "The argument -file must be followed by a filename.";
103 >
104 > #ifdef _WIN32
105 >                                MessageBox(NULL, error.c_str(), "Bad Arguments", MB_ICONERROR);
106 > #endif
107 >                                return 1;
108 >                        }
109                  }
110          }
111  
112 <        if (debug) munge();
112 > #ifdef _WIN32
113 >        GlobalFree(argv);
114 > #endif
115 >
116 >        if (debug) cerr << "file = " << file << "\n";
117 >
118 >        config = new RenegadeConfig(file);
119 >        if (!config->load())
120 >        {
121 >                error = "Could not open " + file + ".";
122 >
123 > #ifdef _WIN32
124 >                MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR);
125 > #endif
126 >                return 1;
127 >        }
128  
129 + #ifdef _WIN32
130          DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector);
131 + #endif
132 +
133 +        delete config;
134 +
135 + #ifdef _WIN32
136 +        if (debug)
137 +        {
138 +                cout << "Press enter key to exit . . .";
139 +                cin.get();
140 +        }
141 + #endif
142  
85        if (debug) FreeConsole();
86        GlobalFree(argv);
143          return 0;
144   }
145  
146 + #ifdef _WIN32
147   int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
148   {
149          switch (uMsg)
# Line 117 | Line 174 | int CALLBACK selector(HWND hwndDlg, UINT
174                          if (debug) cerr << "data = " << data << "\n";
175  
176                          DlgDirList(hwndDlg, data, IDC_AVAILABLE, 0, DDL_ARCHIVE);
177 +                        SetCurrentDirectory("..");
178  
179                          delete [] data;
180                  }
181 +                {
182 +                        vector<string> maps = config->getMaps();
183 +
184 +                        for (unsigned index = 0; index < maps.size(); index++)
185 +                        {
186 +                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_ADDSTRING, 0,
187 +                                        long(maps[index].c_str()));
188 +                        }
189 +                }
190                  break;
191          case WM_COMMAND:
192                  switch (LOWORD(wParam))
193                  {
194                  case IDOK:
195 <                        //
195 >                        if (GetListBoxInfo(GetDlgItem(hwndDlg, IDC_SELECTED)) == 0)
196 >                        {
197 >                                MessageBox(hwndDlg, "You need at least one map.", "No Maps",
198 >                                        MB_ICONEXCLAMATION);
199 >
200 >                                return false;
201 >                        }
202 >                        else
203 >                        {
204 >                                vector<string> maps;
205 >
206 >                                for (unsigned index = 0; index < GetListBoxInfo(GetDlgItem(
207 >                                        hwndDlg, IDC_SELECTED)); index++)
208 >                                {
209 >                                        char* name = new char[SendMessage(GetDlgItem(hwndDlg,
210 >                                                IDC_SELECTED), LB_GETTEXTLEN, index, 0) + 1];
211 >
212 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT,
213 >                                                index, long(name));
214 >                                        maps.push_back(name);
215 >
216 >                                        delete [] name;
217 >                                }
218 >
219 >                                config->setMaps(maps);
220 >                        }
221 >                        config->save();
222                  case IDCANCEL:
223                          EndDialog(hwndDlg, wParam);
224                          return true;
225 +                case IDC_ADD_MAP:
226 +                        {
227 +                                unsigned count = SendMessage(GetDlgItem(hwndDlg,
228 +                                        IDC_AVAILABLE), LB_GETSELCOUNT, 0, 0);
229 +                                unsigned* additions = new unsigned[count];
230 +
231 +                                SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_GETSELITEMS,
232 +                                        count, long(additions));
233 +
234 +                                if (debug) cerr << "additions = {\n";
235 +                                for (unsigned index = 0; index < count; index++)
236 +                                {
237 +                                        if (debug) cerr << "   [" << index << "] = " <<
238 +                                                additions[index] << "\n";
239 +
240 +                                        char* name = new char[SendMessage(GetDlgItem(hwndDlg,
241 +                                                IDC_AVAILABLE), LB_GETTEXTLEN, additions[index], 0) + 1
242 +                                                ];
243 +
244 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_GETTEXT,
245 +                                                additions[index], long(name));
246 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
247 +                                                LB_ADDSTRING, 0, long(name));
248 +
249 +                                        delete [] name;
250 +                                }
251 +                                if (debug) cerr << "}\n";
252 +
253 +                                delete [] additions;
254 +
255 +                                SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_SETSEL,
256 +                                        false, -1);
257 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), false);
258 +                        }
259 +                        break;
260 +                case IDC_REMOVE_MAP:
261 +                        {
262 +                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
263 +                                        LB_GETSELCOUNT, 0, 0);
264 +                                unsigned* removals = new unsigned[count];
265 +
266 +                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
267 +                                        count, long(removals));
268 +
269 +                                if (debug) cerr << "removals = {\n";
270 +                                for (unsigned index = count; index > 0; index--)
271 +                                {
272 +                                        if (debug) cerr << "   [" << index - 1 << "] = " <<
273 +                                                removals[index - 1] << "\n";
274 +
275 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
276 +                                                LB_DELETESTRING, removals[index - 1], 0);
277 +                                }
278 +                                if (debug) cerr << "}\n";
279 +
280 +                                delete [] removals;
281 +
282 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), false);
283 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
284 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
285 +                        }
286 +                        break;
287 +                case IDC_UP_MAP:
288 +                        cout << "STUB: up\a\n";
289 +                        break;
290 +                case IDC_DOWN_MAP:
291 +                        cout << "STUB: down\a\n";
292 +                        break;
293 +                case IDC_AVAILABLE:
294 +                        switch (HIWORD(wParam))
295 +                        {
296 +                        case LBN_SELCHANGE:
297 +                                if (SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE),
298 +                                        LB_GETSELCOUNT, 0, 0) > 0)
299 +                                {
300 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), true);
301 +                                }
302 +                                else
303 +                                {
304 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), false);
305 +                                }
306 +                                break;
307 +                        }
308 +                        break;
309 +                case IDC_SELECTED:
310 +                        switch (HIWORD(wParam))
311 +                        {
312 +                        case LBN_SELCHANGE:
313 +                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
314 +                                        LB_GETSELCOUNT, 0, 0) > 0)
315 +                                {
316 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), true);
317 +                                        
318 +                                        if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
319 +                                                LB_GETSEL, 0, 0) == 0)
320 +                                        {
321 +                                                EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true);
322 +                                        }
323 +                                        else
324 +                                        {
325 +                                                EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
326 +                                        }
327 +
328 +                                        if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
329 +                                                LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED
330 +                                                ), LB_GETCOUNT, 0, 0) - 1, 0) == 0)
331 +                                        {
332 +                                                EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true);
333 +                                        }
334 +                                        else
335 +                                        {
336 +                                                EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
337 +                                        }
338 +                                }
339 +                                else
340 +                                {
341 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), false);
342 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
343 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
344 +                                }
345 +                                break;
346 +                        }
347 +                        break;
348                  }
349                  break;
350          }
351  
352          return false;
353   }
354 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines