Rev 987 | Rev 989 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
194 | terminx | 1 | #ifndef RENDERTYPEWIN |
2 | #error Only for Windows |
||
3 | #endif |
||
4 | |||
5 | #include "duke3d.h" |
||
219 | terminx | 6 | #include "sounds.h" |
194 | terminx | 7 | |
8 | #include "build.h" |
||
9 | #include "winlayer.h" |
||
10 | #include "compat.h" |
||
11 | |||
241 | terminx | 12 | #include "grpscan.h" |
214 | terminx | 13 | |
194 | terminx | 14 | #define WIN32_LEAN_AND_MEAN |
15 | #include <windows.h> |
||
16 | #include <windowsx.h> |
||
17 | #define _WIN32_IE 0x0300 |
||
18 | #include <commctrl.h> |
||
19 | #include <stdio.h> |
||
20 | |||
21 | #include "startwin.game.h" |
||
22 | |||
23 | #define TAB_CONFIG 0 |
||
214 | terminx | 24 | #define TAB_GAME 1 |
25 | #define TAB_MESSAGES 2 |
||
194 | terminx | 26 | |
219 | terminx | 27 | static struct audioenumdrv *wavedevs = NULL; |
28 | |||
335 | terminx | 29 | static struct |
30 | { |
||
222 | terminx | 31 | int fullscreen; |
32 | int xdim, ydim, bpp; |
||
33 | int forcesetup; |
||
34 | int usemouse, usejoy; |
||
35 | char selectedgrp[BMAX_PATH+1]; |
||
241 | terminx | 36 | int game; |
886 | terminx | 37 | int crcval; // for finding the grp in the list again |
984 | terminx | 38 | char *gamedir; |
335 | terminx | 39 | } |
40 | settings; |
||
194 | terminx | 41 | |
42 | static HWND startupdlg = NULL; |
||
335 | terminx | 43 | static HWND pages[3] = |
559 | terminx | 44 | { |
45 | NULL, NULL, NULL |
||
46 | }; |
||
197 | terminx | 47 | static int done = -1, mode = TAB_CONFIG; |
194 | terminx | 48 | |
984 | terminx | 49 | static CACHE1D_FIND_REC *finddirs=NULL; |
50 | static int numdirs=0; |
||
51 | |||
987 | terminx | 52 | static void clearfilenames(void) |
984 | terminx | 53 | { |
54 | klistfree(finddirs); |
||
55 | finddirs = NULL; |
||
56 | numdirs = 0; |
||
57 | } |
||
58 | |||
987 | terminx | 59 | static int getfilenames(char *path) |
984 | terminx | 60 | { |
61 | CACHE1D_FIND_REC *r; |
||
62 | |||
63 | clearfilenames(); |
||
64 | finddirs = klistpath(path,"*",CACHE1D_FIND_DIR); |
||
65 | for (r = finddirs; r; r=r->next) numdirs++; |
||
66 | return(0); |
||
67 | } |
||
68 | |||
219 | terminx | 69 | #define POPULATE_VIDEO 1 |
70 | #define POPULATE_CONFIG 2 |
||
71 | #define POPULATE_GAME 4 |
||
985 | terminx | 72 | #define POPULATE_GAMEDIRS 8 |
219 | terminx | 73 | |
988 | terminx | 74 | extern char TEXCACHEDIR[]; |
75 | |||
214 | terminx | 76 | static void PopulateForm(int pgs) |
194 | terminx | 77 | { |
222 | terminx | 78 | HWND hwnd; |
79 | char buf[256]; |
||
80 | int i,j; |
||
219 | terminx | 81 | |
335 | terminx | 82 | if (pgs & POPULATE_VIDEO) |
83 | { |
||
222 | terminx | 84 | int mode; |
194 | terminx | 85 | |
222 | terminx | 86 | hwnd = GetDlgItem(pages[TAB_CONFIG], IDCVMODE); |
194 | terminx | 87 | |
222 | terminx | 88 | mode = checkvideomode(&settings.xdim, &settings.ydim, settings.bpp, settings.fullscreen, 1); |
335 | terminx | 89 | if (mode < 0) |
90 | { |
||
222 | terminx | 91 | int cd[] = { 32, 24, 16, 15, 8, 0 }; |
335 | terminx | 92 | for (i=0; cd[i];) |
93 | { |
||
94 | if (cd[i] >= settings.bpp) i++; |
||
95 | else break; |
||
96 | } |
||
97 | for (; cd[i]; i++) |
||
98 | { |
||
222 | terminx | 99 | mode = checkvideomode(&settings.xdim, &settings.ydim, cd[i], settings.fullscreen, 1); |
100 | if (mode < 0) continue; |
||
101 | settings.bpp = cd[i]; |
||
102 | break; |
||
103 | } |
||
104 | } |
||
214 | terminx | 105 | |
222 | terminx | 106 | Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), (settings.fullscreen ? BST_CHECKED : BST_UNCHECKED)); |
649 | terminx | 107 | (void)ComboBox_ResetContent(hwnd); |
335 | terminx | 108 | for (i=0; i<validmodecnt; i++) |
109 | { |
||
222 | terminx | 110 | if (validmode[i].fs != settings.fullscreen) continue; |
214 | terminx | 111 | |
222 | terminx | 112 | // all modes get added to the 3D mode list |
584 | terminx | 113 | Bsprintf(buf, "%d x %d %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp); |
222 | terminx | 114 | j = ComboBox_AddString(hwnd, buf); |
649 | terminx | 115 | (void)ComboBox_SetItemData(hwnd, j, i); |
723 | terminx | 116 | if (i == mode)(void)ComboBox_SetCurSel(hwnd, j); |
222 | terminx | 117 | } |
118 | } |
||
214 | terminx | 119 | |
335 | terminx | 120 | if (pgs & POPULATE_CONFIG) |
121 | { |
||
222 | terminx | 122 | struct audioenumdev *d; |
123 | char *n; |
||
219 | terminx | 124 | |
222 | terminx | 125 | hwnd = GetDlgItem(pages[TAB_CONFIG], IDCSOUNDDRV); |
649 | terminx | 126 | (void)ComboBox_ResetContent(hwnd); |
335 | terminx | 127 | if (wavedevs) |
128 | { |
||
222 | terminx | 129 | d = wavedevs->devs; |
335 | terminx | 130 | for (i=0; wavedevs->drvs[i]; i++) |
131 | { |
||
222 | terminx | 132 | strcpy(buf, wavedevs->drvs[i]); |
335 | terminx | 133 | if (d->devs) |
134 | { |
||
222 | terminx | 135 | strcat(buf, ":"); |
136 | n = buf + strlen(buf); |
||
335 | terminx | 137 | for (j=0; d->devs[j]; j++) |
138 | { |
||
222 | terminx | 139 | strcpy(n, d->devs[j]); |
649 | terminx | 140 | (void)ComboBox_AddString(hwnd, buf); |
222 | terminx | 141 | } |
335 | terminx | 142 | } |
143 | else |
||
144 | { |
||
649 | terminx | 145 | (void)ComboBox_AddString(hwnd, buf); |
222 | terminx | 146 | } |
147 | d = d->next; |
||
148 | } |
||
149 | } |
||
219 | terminx | 150 | |
222 | terminx | 151 | Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED)); |
219 | terminx | 152 | |
222 | terminx | 153 | Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), (settings.usemouse ? BST_CHECKED : BST_UNCHECKED)); |
154 | Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), (settings.usejoy ? BST_CHECKED : BST_UNCHECKED)); |
||
155 | } |
||
194 | terminx | 156 | |
335 | terminx | 157 | if (pgs & POPULATE_GAME) |
158 | { |
||
222 | terminx | 159 | struct grpfile *fg; |
160 | int i, j; |
||
161 | char buf[128+BMAX_PATH]; |
||
194 | terminx | 162 | |
222 | terminx | 163 | hwnd = GetDlgItem(pages[TAB_GAME], IDGDATA); |
194 | terminx | 164 | |
335 | terminx | 165 | for (fg = foundgrps; fg; fg=fg->next) |
166 | { |
||
241 | terminx | 167 | for (i = 0; i<numgrpfiles; i++) if (fg->crcval == grpfiles[i].crcval) break; |
222 | terminx | 168 | if (i == numgrpfiles) continue; // unrecognised grp file |
169 | Bsprintf(buf, "%s\t%s", grpfiles[i].name, fg->name); |
||
170 | j = ListBox_AddString(hwnd, buf); |
||
649 | terminx | 171 | (void)ListBox_SetItemData(hwnd, j, (LPARAM)fg); |
723 | terminx | 172 | if (!Bstrcasecmp(fg->name, settings.selectedgrp))(void)ListBox_SetCurSel(hwnd, j); |
222 | terminx | 173 | } |
174 | } |
||
984 | terminx | 175 | |
985 | terminx | 176 | if (pgs & POPULATE_GAMEDIRS) |
984 | terminx | 177 | { |
178 | CACHE1D_FIND_REC *dirs = NULL; |
||
179 | |||
180 | hwnd = GetDlgItem(pages[TAB_GAME], IDGGAMEDIR); |
||
181 | |||
182 | getfilenames("/"); |
||
183 | (void)ComboBox_ResetContent(hwnd); |
||
184 | j = ComboBox_AddString(hwnd, "None"); |
||
185 | (void)ComboBox_SetItemData(hwnd, j, 0); |
||
985 | terminx | 186 | (void)ComboBox_SetCurSel(hwnd, j); |
984 | terminx | 187 | for (dirs=finddirs,i=1; dirs != NULL; dirs=dirs->next,i++) |
188 | { |
||
988 | terminx | 189 | if (Bstrcmp(TEXCACHEDIR,dirs->name) == 0) continue; |
984 | terminx | 190 | Bsprintf(buf, "%s", dirs->name); |
191 | j = ComboBox_AddString(hwnd, buf); |
||
192 | (void)ComboBox_SetItemData(hwnd, j, i); |
||
985 | terminx | 193 | if (Bstrcmp(dirs->name,settings.gamedir) == 0) |
194 | (void)ComboBox_SetCurSel(hwnd, j); |
||
984 | terminx | 195 | } |
196 | } |
||
194 | terminx | 197 | } |
198 | |||
199 | static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
200 | { |
||
335 | terminx | 201 | switch (uMsg) |
202 | { |
||
337 | terminx | 203 | case WM_COMMAND: |
204 | switch (LOWORD(wParam)) |
||
205 | { |
||
206 | case IDCFULLSCREEN: |
||
207 | settings.fullscreen = !settings.fullscreen; |
||
208 | PopulateForm(POPULATE_VIDEO); |
||
209 | return TRUE; |
||
210 | case IDCVMODE: |
||
211 | if (HIWORD(wParam) == CBN_SELCHANGE) |
||
335 | terminx | 212 | { |
337 | terminx | 213 | int i; |
214 | i = ComboBox_GetCurSel((HWND)lParam); |
||
215 | if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); |
||
216 | if (i != CB_ERR) |
||
217 | { |
||
218 | settings.xdim = validmode[i].xdim; |
||
219 | settings.ydim = validmode[i].ydim; |
||
220 | settings.bpp = validmode[i].bpp; |
||
221 | } |
||
222 | terminx | 222 | } |
337 | terminx | 223 | return TRUE; |
224 | case IDCALWAYSSHOW: |
||
225 | settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED; |
||
226 | return TRUE; |
||
227 | case IDCINPUTMOUSE: |
||
228 | settings.usemouse = IsDlgButtonChecked(hwndDlg, IDCINPUTMOUSE) == BST_CHECKED; |
||
229 | return TRUE; |
||
230 | case IDCINPUTJOY: |
||
231 | settings.usejoy = IsDlgButtonChecked(hwndDlg, IDCINPUTJOY) == BST_CHECKED; |
||
232 | return TRUE; |
||
331 | terminx | 233 | default: |
234 | break; |
||
337 | terminx | 235 | } |
236 | break; |
||
237 | default: |
||
238 | break; |
||
222 | terminx | 239 | } |
240 | return FALSE; |
||
194 | terminx | 241 | } |
242 | |||
214 | terminx | 243 | static INT_PTR CALLBACK GamePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
244 | { |
||
654 | terminx | 245 | UNREFERENCED_PARAMETER(hwndDlg); |
335 | terminx | 246 | switch (uMsg) |
247 | { |
||
337 | terminx | 248 | case WM_COMMAND: |
249 | switch (LOWORD(wParam)) |
||
250 | { |
||
251 | case IDGDATA: |
||
252 | { |
||
253 | int i; |
||
254 | if (HIWORD(wParam) != LBN_SELCHANGE) break; |
||
255 | i = ListBox_GetCurSel((HWND)lParam); |
||
256 | if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i); |
||
257 | if (i != CB_ERR) |
||
335 | terminx | 258 | { |
337 | terminx | 259 | strcpy(settings.selectedgrp, ((struct grpfile*)i)->name); |
260 | settings.game = ((struct grpfile*)i)->game; |
||
886 | terminx | 261 | settings.crcval = ((struct grpfile*)i)->crcval; |
222 | terminx | 262 | } |
337 | terminx | 263 | return TRUE; |
264 | } |
||
984 | terminx | 265 | case IDGGAMEDIR: |
266 | if (HIWORD(wParam) == CBN_SELCHANGE) |
||
267 | { |
||
268 | int i,j; |
||
269 | CACHE1D_FIND_REC *dir = NULL; |
||
270 | i = ComboBox_GetCurSel((HWND)lParam); |
||
271 | if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); |
||
272 | if (i != CB_ERR) |
||
273 | { |
||
274 | for (j=0,dir=finddirs;dir != NULL;dir=dir->next,j++) |
||
275 | if (j == i) |
||
276 | { |
||
277 | if (i==0) settings.gamedir = NULL; |
||
278 | else settings.gamedir = dir->prev->name; |
||
279 | break; |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | return TRUE; |
||
331 | terminx | 284 | default: |
285 | break; |
||
337 | terminx | 286 | } |
287 | break; |
||
288 | default: |
||
289 | break; |
||
222 | terminx | 290 | } |
291 | return FALSE; |
||
214 | terminx | 292 | } |
194 | terminx | 293 | |
294 | |||
214 | terminx | 295 | |
194 | terminx | 296 | static void SetPage(int n) |
297 | { |
||
222 | terminx | 298 | HWND tab; |
299 | int cur; |
||
300 | tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); |
||
301 | cur = (int)SendMessage(tab, TCM_GETCURSEL,0,0); |
||
302 | ShowWindow(pages[cur],SW_HIDE); |
||
303 | SendMessage(tab, TCM_SETCURSEL, n, 0); |
||
304 | ShowWindow(pages[n],SW_SHOW); |
||
305 | mode = n; |
||
196 | terminx | 306 | |
222 | terminx | 307 | SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL)); |
194 | terminx | 308 | } |
309 | |||
310 | static void EnableConfig(int n) |
||
311 | { |
||
222 | terminx | 312 | //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n); |
313 | EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n); |
||
314 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n); |
||
315 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n); |
||
316 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), n); |
||
317 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), n); |
||
214 | terminx | 318 | |
222 | terminx | 319 | EnableWindow(GetDlgItem(pages[TAB_GAME], IDGDATA), n); |
984 | terminx | 320 | EnableWindow(GetDlgItem(pages[TAB_GAME], IDGGAMEDIR), n); |
194 | terminx | 321 | } |
322 | |||
323 | static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
324 | { |
||
222 | terminx | 325 | static HBITMAP hbmp = NULL; |
326 | HDC hdc; |
||
194 | terminx | 327 | |
335 | terminx | 328 | switch (uMsg) |
329 | { |
||
337 | terminx | 330 | case WM_INITDIALOG: |
331 | { |
||
332 | HWND hwnd; |
||
333 | RECT r, rdlg, chrome, rtab, rcancel, rstart; |
||
334 | int xoffset = 0, yoffset = 0; |
||
194 | terminx | 335 | |
337 | terminx | 336 | // Fetch the positions (in screen coordinates) of all the windows we need to tweak |
337 | ZeroMemory(&chrome, sizeof(chrome)); |
||
338 | AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE); |
||
339 | GetWindowRect(hwndDlg, &rdlg); |
||
340 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab); |
||
341 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel); |
||
342 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart); |
||
194 | terminx | 343 | |
337 | terminx | 344 | // Knock off the non-client area of the main dialogue to give just the client area |
345 | rdlg.left -= chrome.left; |
||
346 | rdlg.top -= chrome.top; |
||
347 | rdlg.right -= chrome.right; |
||
348 | rdlg.bottom -= chrome.bottom; |
||
194 | terminx | 349 | |
337 | terminx | 350 | // Translate them to client-relative coordinates wrt the main dialogue window |
351 | rtab.right -= rtab.left - 1; |
||
352 | rtab.bottom -= rtab.top - 1; |
||
353 | rtab.left -= rdlg.left; |
||
354 | rtab.top -= rdlg.top; |
||
194 | terminx | 355 | |
337 | terminx | 356 | rcancel.right -= rcancel.left - 1; |
357 | rcancel.bottom -= rcancel.top - 1; |
||
358 | rcancel.left -= rdlg.left; |
||
359 | rcancel.top -= rdlg.top; |
||
194 | terminx | 360 | |
337 | terminx | 361 | rstart.right -= rstart.left - 1; |
362 | rstart.bottom -= rstart.top - 1; |
||
363 | rstart.left -= rdlg.left; |
||
364 | rstart.top -= rdlg.top; |
||
194 | terminx | 365 | |
337 | terminx | 366 | // And then convert the main dialogue coordinates to just width/length |
367 | rdlg.right -= rdlg.left - 1; |
||
368 | rdlg.bottom -= rdlg.top - 1; |
||
369 | rdlg.left = 0; |
||
370 | rdlg.top = 0; |
||
194 | terminx | 371 | |
337 | terminx | 372 | // Load the bitmap into the bitmap control and fetch its dimensions |
373 | hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP)); |
||
374 | hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP); |
||
375 | SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp); |
||
376 | GetClientRect(hwnd, &r); |
||
377 | xoffset = r.right; |
||
378 | yoffset = r.bottom - rdlg.bottom; |
||
194 | terminx | 379 | |
337 | terminx | 380 | // Shift and resize the controls that require it |
381 | rtab.left += xoffset; |
||
382 | rtab.bottom += yoffset; |
||
383 | rcancel.left += xoffset; |
||
384 | rcancel.top += yoffset; |
||
385 | rstart.left += xoffset; |
||
386 | rstart.top += yoffset; |
||
387 | rdlg.right += xoffset; |
||
388 | rdlg.bottom += yoffset; |
||
194 | terminx | 389 | |
337 | terminx | 390 | // Move the controls to their new positions |
391 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE); |
||
392 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE); |
||
393 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE); |
||
194 | terminx | 394 | |
337 | terminx | 395 | // Move the main dialogue to the centre of the screen |
396 | hdc = GetDC(NULL); |
||
397 | rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2; |
||
398 | rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2; |
||
399 | ReleaseDC(NULL, hdc); |
||
400 | MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left, |
||
401 | rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE); |
||
194 | terminx | 402 | |
337 | terminx | 403 | // Add tabs to the tab control |
404 | { |
||
405 | TCITEM tab; |
||
194 | terminx | 406 | |
337 | terminx | 407 | hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL); |
194 | terminx | 408 | |
337 | terminx | 409 | ZeroMemory(&tab, sizeof(tab)); |
410 | tab.mask = TCIF_TEXT; |
||
411 | tab.pszText = TEXT("Configuration"); |
||
412 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab); |
||
413 | tab.mask = TCIF_TEXT; |
||
414 | tab.pszText = TEXT("Game"); |
||
415 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_GAME, (LPARAM)&tab); |
||
416 | tab.mask = TCIF_TEXT; |
||
417 | tab.pszText = TEXT("Messages"); |
||
418 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab); |
||
194 | terminx | 419 | |
337 | terminx | 420 | // Work out the position and size of the area inside the tab control for the pages |
421 | ZeroMemory(&r, sizeof(r)); |
||
422 | GetClientRect(hwnd, &r); |
||
423 | SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r); |
||
424 | r.right -= r.left-1; |
||
425 | r.bottom -= r.top-1; |
||
426 | r.top += rtab.top; |
||
427 | r.left += rtab.left; |
||
194 | terminx | 428 | |
337 | terminx | 429 | // Create the pages and position them in the tab control, but hide them |
430 | pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(), |
||
431 | MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc); |
||
432 | pages[TAB_GAME] = CreateDialog((HINSTANCE)win_gethinstance(), |
||
433 | MAKEINTRESOURCE(WIN_STARTWINPAGE_GAME), hwndDlg, GamePageProc); |
||
434 | pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES); |
||
435 | SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
436 | SetWindowPos(pages[TAB_GAME], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
437 | SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
194 | terminx | 438 | |
337 | terminx | 439 | // Tell the editfield acting as the console to exclude the width of the scrollbar |
440 | GetClientRect(pages[TAB_MESSAGES],&r); |
||
441 | r.right -= GetSystemMetrics(SM_CXVSCROLL)+4; |
||
442 | r.left = r.top = 0; |
||
443 | SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r); |
||
194 | terminx | 444 | |
337 | terminx | 445 | // Set a tab stop in the game data listbox |
446 | { |
||
447 | DWORD tabs[1] = { 150 }; |
||
649 | terminx | 448 | (void)ListBox_SetTabStops(GetDlgItem(pages[TAB_GAME], IDGDATA), 1, tabs); |
337 | terminx | 449 | } |
335 | terminx | 450 | |
337 | terminx | 451 | SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START)); |
452 | SetWindowText(hwndDlg, apptitle); |
||
335 | terminx | 453 | } |
337 | terminx | 454 | return FALSE; |
455 | } |
||
335 | terminx | 456 | |
337 | terminx | 457 | case WM_NOTIFY: |
458 | { |
||
459 | LPNMHDR nmhdr = (LPNMHDR)lParam; |
||
460 | int cur; |
||
461 | if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break; |
||
462 | cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); |
||
463 | switch (nmhdr->code) |
||
335 | terminx | 464 | { |
337 | terminx | 465 | case TCN_SELCHANGING: |
466 | { |
||
467 | if (cur < 0 || !pages[cur]) break; |
||
468 | ShowWindow(pages[cur],SW_HIDE); |
||
469 | return TRUE; |
||
222 | terminx | 470 | } |
337 | terminx | 471 | case TCN_SELCHANGE: |
472 | { |
||
473 | if (cur < 0 || !pages[cur]) break; |
||
474 | ShowWindow(pages[cur],SW_SHOW); |
||
331 | terminx | 475 | return TRUE; |
337 | terminx | 476 | } |
477 | } |
||
478 | break; |
||
479 | } |
||
194 | terminx | 480 | |
337 | terminx | 481 | case WM_CLOSE: |
482 | if (mode == TAB_CONFIG) done = 0; |
||
483 | else quitevent++; |
||
484 | return TRUE; |
||
194 | terminx | 485 | |
337 | terminx | 486 | case WM_DESTROY: |
487 | if (hbmp) |
||
488 | { |
||
489 | DeleteObject(hbmp); |
||
490 | hbmp = NULL; |
||
491 | } |
||
194 | terminx | 492 | |
337 | terminx | 493 | if (pages[TAB_GAME]) |
494 | { |
||
495 | DestroyWindow(pages[TAB_GAME]); |
||
496 | pages[TAB_GAME] = NULL; |
||
497 | } |
||
214 | terminx | 498 | |
337 | terminx | 499 | if (pages[TAB_CONFIG]) |
500 | { |
||
501 | DestroyWindow(pages[TAB_CONFIG]); |
||
502 | pages[TAB_CONFIG] = NULL; |
||
503 | } |
||
504 | |||
505 | startupdlg = NULL; |
||
506 | return TRUE; |
||
507 | |||
508 | case WM_COMMAND: |
||
509 | switch (LOWORD(wParam)) |
||
510 | { |
||
511 | case WIN_STARTWIN_CANCEL: |
||
512 | if (mode == TAB_CONFIG) done = 0; |
||
513 | else quitevent++; |
||
335 | terminx | 514 | return TRUE; |
337 | terminx | 515 | case WIN_STARTWIN_START: |
516 | done = 1; |
||
517 | return TRUE; |
||
518 | } |
||
519 | return FALSE; |
||
194 | terminx | 520 | |
337 | terminx | 521 | case WM_CTLCOLORSTATIC: |
522 | if ((HWND)lParam == pages[TAB_MESSAGES]) |
||
523 | return (BOOL)GetSysColorBrush(COLOR_WINDOW); |
||
524 | break; |
||
194 | terminx | 525 | |
337 | terminx | 526 | default: |
527 | break; |
||
222 | terminx | 528 | } |
529 | |||
530 | return FALSE; |
||
194 | terminx | 531 | } |
532 | |||
533 | |||
534 | int startwin_open(void) |
||
535 | { |
||
222 | terminx | 536 | INITCOMMONCONTROLSEX icc; |
537 | if (startupdlg) return 1; |
||
538 | icc.dwSize = sizeof(icc); |
||
539 | icc.dwICC = ICC_TAB_CLASSES; |
||
540 | InitCommonControlsEx(&icc); |
||
541 | startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); |
||
335 | terminx | 542 | if (startupdlg) |
543 | { |
||
222 | terminx | 544 | SetPage(TAB_MESSAGES); |
545 | EnableConfig(0); |
||
546 | return 0; |
||
547 | } |
||
548 | return -1; |
||
194 | terminx | 549 | } |
550 | |||
551 | int startwin_close(void) |
||
552 | { |
||
222 | terminx | 553 | if (!startupdlg) return 1; |
554 | DestroyWindow(startupdlg); |
||
555 | startupdlg = NULL; |
||
556 | return 0; |
||
194 | terminx | 557 | } |
558 | |||
559 | int startwin_puts(const char *buf) |
||
560 | { |
||
222 | terminx | 561 | const char *p = NULL, *q = NULL; |
851 | terminx | 562 | static char workbuf[1024]; |
222 | terminx | 563 | static int newline = 0; |
564 | int curlen, linesbefore, linesafter; |
||
565 | HWND edctl; |
||
566 | int vis; |
||
851 | terminx | 567 | static HWND dactrl = NULL; |
194 | terminx | 568 | |
222 | terminx | 569 | if (!startupdlg) return 1; |
194 | terminx | 570 | |
222 | terminx | 571 | edctl = pages[TAB_MESSAGES]; |
572 | if (!edctl) return -1; |
||
194 | terminx | 573 | |
851 | terminx | 574 | if (!dactrl) dactrl = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); |
222 | terminx | 575 | |
851 | terminx | 576 | vis = ((int)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES); |
577 | |||
222 | terminx | 578 | if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); |
579 | curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); |
||
580 | SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); |
||
581 | linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); |
||
582 | p = buf; |
||
335 | terminx | 583 | while (*p) |
584 | { |
||
585 | if (newline) |
||
586 | { |
||
222 | terminx | 587 | SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); |
588 | newline = 0; |
||
589 | } |
||
590 | q = p; |
||
591 | while (*q && *q != '\n') q++; |
||
592 | memcpy(workbuf, p, q-p); |
||
335 | terminx | 593 | if (*q == '\n') |
594 | { |
||
595 | if (!q[1]) |
||
596 | { |
||
222 | terminx | 597 | newline = 1; |
598 | workbuf[q-p] = 0; |
||
335 | terminx | 599 | } |
600 | else |
||
601 | { |
||
222 | terminx | 602 | workbuf[q-p] = '\r'; |
603 | workbuf[q-p+1] = '\n'; |
||
604 | workbuf[q-p+2] = 0; |
||
605 | } |
||
606 | p = q+1; |
||
335 | terminx | 607 | } |
608 | else |
||
609 | { |
||
222 | terminx | 610 | workbuf[q-p] = 0; |
611 | p = q; |
||
612 | } |
||
613 | SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); |
||
614 | } |
||
615 | linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); |
||
616 | SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); |
||
617 | if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); |
||
618 | return 0; |
||
194 | terminx | 619 | } |
620 | |||
621 | int startwin_settitle(const char *str) |
||
622 | { |
||
222 | terminx | 623 | if (!startupdlg) return 1; |
624 | SetWindowText(startupdlg, str); |
||
625 | return 0; |
||
194 | terminx | 626 | } |
627 | |||
628 | int startwin_idle(void *v) |
||
629 | { |
||
222 | terminx | 630 | if (!startupdlg || !IsWindow(startupdlg)) return 0; |
631 | if (IsDialogMessage(startupdlg, (MSG*)v)) return 1; |
||
632 | return 0; |
||
194 | terminx | 633 | } |
634 | |||
886 | terminx | 635 | extern char *duke3dgrp, *duke3dgrpstring; |
984 | terminx | 636 | extern char mod_dir[BMAX_PATH]; |
214 | terminx | 637 | |
194 | terminx | 638 | int startwin_run(void) |
639 | { |
||
222 | terminx | 640 | MSG msg; |
641 | if (!startupdlg) return 1; |
||
194 | terminx | 642 | |
222 | terminx | 643 | done = -1; |
194 | terminx | 644 | |
219 | terminx | 645 | #ifdef JFAUD |
222 | terminx | 646 | EnumAudioDevs(&wavedevs, NULL, NULL); |
219 | terminx | 647 | #endif |
222 | terminx | 648 | SetPage(TAB_CONFIG); |
649 | EnableConfig(1); |
||
194 | terminx | 650 | |
563 | terminx | 651 | settings.fullscreen = ud.config.ScreenMode; |
652 | settings.xdim = ud.config.ScreenWidth; |
||
653 | settings.ydim = ud.config.ScreenHeight; |
||
654 | settings.bpp = ud.config.ScreenBPP; |
||
655 | settings.forcesetup = ud.config.ForceSetup; |
||
656 | settings.usemouse = ud.config.UseMouse; |
||
657 | settings.usejoy = ud.config.UseJoystick; |
||
561 | terminx | 658 | settings.game = g_GameType; |
886 | terminx | 659 | // settings.crcval = 0; |
222 | terminx | 660 | strncpy(settings.selectedgrp, duke3dgrp, BMAX_PATH); |
984 | terminx | 661 | settings.gamedir = mod_dir; |
222 | terminx | 662 | PopulateForm(-1); |
194 | terminx | 663 | |
335 | terminx | 664 | while (done < 0) |
665 | { |
||
666 | switch (GetMessage(&msg, NULL, 0,0)) |
||
667 | { |
||
337 | terminx | 668 | case 0: |
669 | done = 1; |
||
670 | break; |
||
671 | case -1: |
||
672 | return -1; |
||
673 | default: |
||
674 | if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; |
||
675 | TranslateMessage(&msg); |
||
676 | DispatchMessage(&msg); |
||
677 | break; |
||
222 | terminx | 678 | } |
679 | } |
||
194 | terminx | 680 | |
222 | terminx | 681 | SetPage(TAB_MESSAGES); |
682 | EnableConfig(0); |
||
335 | terminx | 683 | if (done) |
684 | { |
||
886 | terminx | 685 | int i; |
686 | |||
563 | terminx | 687 | ud.config.ScreenMode = settings.fullscreen; |
688 | ud.config.ScreenWidth = settings.xdim; |
||
689 | ud.config.ScreenHeight = settings.ydim; |
||
690 | ud.config.ScreenBPP = settings.bpp; |
||
691 | ud.config.ForceSetup = settings.forcesetup; |
||
692 | ud.config.UseMouse = settings.usemouse; |
||
693 | ud.config.UseJoystick = settings.usejoy; |
||
222 | terminx | 694 | duke3dgrp = settings.selectedgrp; |
561 | terminx | 695 | g_GameType = settings.game; |
985 | terminx | 696 | |
697 | if (settings.gamedir != NULL) |
||
984 | terminx | 698 | { |
699 | addsearchpath(settings.gamedir); |
||
700 | Bstrcpy(mod_dir,settings.gamedir); |
||
701 | } |
||
985 | terminx | 702 | else Bsprintf(mod_dir,"None"); |
886 | terminx | 703 | |
704 | for (i = 0; i<numgrpfiles; i++) if (settings.crcval == grpfiles[i].crcval) break; |
||
705 | if (i != numgrpfiles) |
||
706 | duke3dgrpstring = (char *)grpfiles[i].name; |
||
222 | terminx | 707 | } |
194 | terminx | 708 | |
335 | terminx | 709 | if (wavedevs) |
710 | { |
||
222 | terminx | 711 | struct audioenumdev *d, *e; |
712 | free(wavedevs->drvs); |
||
335 | terminx | 713 | for (e=wavedevs->devs; e; e=d) |
714 | { |
||
222 | terminx | 715 | d = e->next; |
716 | if (e->devs) free(e->devs); |
||
717 | free(e); |
||
718 | } |
||
719 | free(wavedevs); |
||
720 | } |
||
219 | terminx | 721 | |
222 | terminx | 722 | return done; |
194 | terminx | 723 | } |
724 |