Rev 989 | Rev 991 | 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 | { |
||
990 | terminx | 189 | if (Bstrcasecmp(TEXCACHEDIR,dirs->name) == 0) continue; |
989 | terminx | 190 | j = ComboBox_AddString(hwnd, dirs->name); |
984 | terminx | 191 | (void)ComboBox_SetItemData(hwnd, j, i); |
990 | terminx | 192 | if (Bstrcasecmp(dirs->name,settings.gamedir) == 0) |
985 | terminx | 193 | (void)ComboBox_SetCurSel(hwnd, j); |
984 | terminx | 194 | } |
195 | } |
||
194 | terminx | 196 | } |
197 | |||
198 | static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
199 | { |
||
335 | terminx | 200 | switch (uMsg) |
201 | { |
||
337 | terminx | 202 | case WM_COMMAND: |
203 | switch (LOWORD(wParam)) |
||
204 | { |
||
205 | case IDCFULLSCREEN: |
||
206 | settings.fullscreen = !settings.fullscreen; |
||
207 | PopulateForm(POPULATE_VIDEO); |
||
208 | return TRUE; |
||
209 | case IDCVMODE: |
||
210 | if (HIWORD(wParam) == CBN_SELCHANGE) |
||
335 | terminx | 211 | { |
337 | terminx | 212 | int i; |
213 | i = ComboBox_GetCurSel((HWND)lParam); |
||
214 | if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); |
||
215 | if (i != CB_ERR) |
||
216 | { |
||
217 | settings.xdim = validmode[i].xdim; |
||
218 | settings.ydim = validmode[i].ydim; |
||
219 | settings.bpp = validmode[i].bpp; |
||
220 | } |
||
222 | terminx | 221 | } |
337 | terminx | 222 | return TRUE; |
223 | case IDCALWAYSSHOW: |
||
224 | settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED; |
||
225 | return TRUE; |
||
226 | case IDCINPUTMOUSE: |
||
227 | settings.usemouse = IsDlgButtonChecked(hwndDlg, IDCINPUTMOUSE) == BST_CHECKED; |
||
228 | return TRUE; |
||
229 | case IDCINPUTJOY: |
||
230 | settings.usejoy = IsDlgButtonChecked(hwndDlg, IDCINPUTJOY) == BST_CHECKED; |
||
231 | return TRUE; |
||
331 | terminx | 232 | default: |
233 | break; |
||
337 | terminx | 234 | } |
235 | break; |
||
236 | default: |
||
237 | break; |
||
222 | terminx | 238 | } |
239 | return FALSE; |
||
194 | terminx | 240 | } |
241 | |||
214 | terminx | 242 | static INT_PTR CALLBACK GamePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
243 | { |
||
654 | terminx | 244 | UNREFERENCED_PARAMETER(hwndDlg); |
335 | terminx | 245 | switch (uMsg) |
246 | { |
||
337 | terminx | 247 | case WM_COMMAND: |
248 | switch (LOWORD(wParam)) |
||
249 | { |
||
250 | case IDGDATA: |
||
251 | { |
||
252 | int i; |
||
253 | if (HIWORD(wParam) != LBN_SELCHANGE) break; |
||
254 | i = ListBox_GetCurSel((HWND)lParam); |
||
255 | if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i); |
||
256 | if (i != CB_ERR) |
||
335 | terminx | 257 | { |
337 | terminx | 258 | strcpy(settings.selectedgrp, ((struct grpfile*)i)->name); |
259 | settings.game = ((struct grpfile*)i)->game; |
||
886 | terminx | 260 | settings.crcval = ((struct grpfile*)i)->crcval; |
222 | terminx | 261 | } |
337 | terminx | 262 | return TRUE; |
263 | } |
||
984 | terminx | 264 | case IDGGAMEDIR: |
265 | if (HIWORD(wParam) == CBN_SELCHANGE) |
||
266 | { |
||
267 | int i,j; |
||
268 | CACHE1D_FIND_REC *dir = NULL; |
||
269 | i = ComboBox_GetCurSel((HWND)lParam); |
||
270 | if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); |
||
271 | if (i != CB_ERR) |
||
272 | { |
||
273 | for (j=0,dir=finddirs;dir != NULL;dir=dir->next,j++) |
||
274 | if (j == i) |
||
275 | { |
||
276 | if (i==0) settings.gamedir = NULL; |
||
277 | else settings.gamedir = dir->prev->name; |
||
278 | break; |
||
279 | } |
||
280 | } |
||
281 | } |
||
282 | return TRUE; |
||
331 | terminx | 283 | default: |
284 | break; |
||
337 | terminx | 285 | } |
286 | break; |
||
287 | default: |
||
288 | break; |
||
222 | terminx | 289 | } |
290 | return FALSE; |
||
214 | terminx | 291 | } |
194 | terminx | 292 | |
293 | |||
214 | terminx | 294 | |
194 | terminx | 295 | static void SetPage(int n) |
296 | { |
||
222 | terminx | 297 | HWND tab; |
298 | int cur; |
||
299 | tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); |
||
300 | cur = (int)SendMessage(tab, TCM_GETCURSEL,0,0); |
||
301 | ShowWindow(pages[cur],SW_HIDE); |
||
302 | SendMessage(tab, TCM_SETCURSEL, n, 0); |
||
303 | ShowWindow(pages[n],SW_SHOW); |
||
304 | mode = n; |
||
196 | terminx | 305 | |
222 | terminx | 306 | SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL)); |
194 | terminx | 307 | } |
308 | |||
309 | static void EnableConfig(int n) |
||
310 | { |
||
222 | terminx | 311 | //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n); |
312 | EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n); |
||
313 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n); |
||
314 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n); |
||
315 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), n); |
||
316 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), n); |
||
214 | terminx | 317 | |
222 | terminx | 318 | EnableWindow(GetDlgItem(pages[TAB_GAME], IDGDATA), n); |
984 | terminx | 319 | EnableWindow(GetDlgItem(pages[TAB_GAME], IDGGAMEDIR), n); |
194 | terminx | 320 | } |
321 | |||
322 | static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
323 | { |
||
222 | terminx | 324 | static HBITMAP hbmp = NULL; |
325 | HDC hdc; |
||
194 | terminx | 326 | |
335 | terminx | 327 | switch (uMsg) |
328 | { |
||
337 | terminx | 329 | case WM_INITDIALOG: |
330 | { |
||
331 | HWND hwnd; |
||
332 | RECT r, rdlg, chrome, rtab, rcancel, rstart; |
||
333 | int xoffset = 0, yoffset = 0; |
||
194 | terminx | 334 | |
337 | terminx | 335 | // Fetch the positions (in screen coordinates) of all the windows we need to tweak |
336 | ZeroMemory(&chrome, sizeof(chrome)); |
||
337 | AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE); |
||
338 | GetWindowRect(hwndDlg, &rdlg); |
||
339 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab); |
||
340 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel); |
||
341 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart); |
||
194 | terminx | 342 | |
337 | terminx | 343 | // Knock off the non-client area of the main dialogue to give just the client area |
344 | rdlg.left -= chrome.left; |
||
345 | rdlg.top -= chrome.top; |
||
346 | rdlg.right -= chrome.right; |
||
347 | rdlg.bottom -= chrome.bottom; |
||
194 | terminx | 348 | |
337 | terminx | 349 | // Translate them to client-relative coordinates wrt the main dialogue window |
350 | rtab.right -= rtab.left - 1; |
||
351 | rtab.bottom -= rtab.top - 1; |
||
352 | rtab.left -= rdlg.left; |
||
353 | rtab.top -= rdlg.top; |
||
194 | terminx | 354 | |
337 | terminx | 355 | rcancel.right -= rcancel.left - 1; |
356 | rcancel.bottom -= rcancel.top - 1; |
||
357 | rcancel.left -= rdlg.left; |
||
358 | rcancel.top -= rdlg.top; |
||
194 | terminx | 359 | |
337 | terminx | 360 | rstart.right -= rstart.left - 1; |
361 | rstart.bottom -= rstart.top - 1; |
||
362 | rstart.left -= rdlg.left; |
||
363 | rstart.top -= rdlg.top; |
||
194 | terminx | 364 | |
337 | terminx | 365 | // And then convert the main dialogue coordinates to just width/length |
366 | rdlg.right -= rdlg.left - 1; |
||
367 | rdlg.bottom -= rdlg.top - 1; |
||
368 | rdlg.left = 0; |
||
369 | rdlg.top = 0; |
||
194 | terminx | 370 | |
337 | terminx | 371 | // Load the bitmap into the bitmap control and fetch its dimensions |
372 | hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP)); |
||
373 | hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP); |
||
374 | SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp); |
||
375 | GetClientRect(hwnd, &r); |
||
376 | xoffset = r.right; |
||
377 | yoffset = r.bottom - rdlg.bottom; |
||
194 | terminx | 378 | |
337 | terminx | 379 | // Shift and resize the controls that require it |
380 | rtab.left += xoffset; |
||
381 | rtab.bottom += yoffset; |
||
382 | rcancel.left += xoffset; |
||
383 | rcancel.top += yoffset; |
||
384 | rstart.left += xoffset; |
||
385 | rstart.top += yoffset; |
||
386 | rdlg.right += xoffset; |
||
387 | rdlg.bottom += yoffset; |
||
194 | terminx | 388 | |
337 | terminx | 389 | // Move the controls to their new positions |
390 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE); |
||
391 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE); |
||
392 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE); |
||
194 | terminx | 393 | |
337 | terminx | 394 | // Move the main dialogue to the centre of the screen |
395 | hdc = GetDC(NULL); |
||
396 | rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2; |
||
397 | rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2; |
||
398 | ReleaseDC(NULL, hdc); |
||
399 | MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left, |
||
400 | rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE); |
||
194 | terminx | 401 | |
337 | terminx | 402 | // Add tabs to the tab control |
403 | { |
||
404 | TCITEM tab; |
||
194 | terminx | 405 | |
337 | terminx | 406 | hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL); |
194 | terminx | 407 | |
337 | terminx | 408 | ZeroMemory(&tab, sizeof(tab)); |
409 | tab.mask = TCIF_TEXT; |
||
410 | tab.pszText = TEXT("Configuration"); |
||
411 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab); |
||
412 | tab.mask = TCIF_TEXT; |
||
413 | tab.pszText = TEXT("Game"); |
||
414 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_GAME, (LPARAM)&tab); |
||
415 | tab.mask = TCIF_TEXT; |
||
416 | tab.pszText = TEXT("Messages"); |
||
417 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab); |
||
194 | terminx | 418 | |
337 | terminx | 419 | // Work out the position and size of the area inside the tab control for the pages |
420 | ZeroMemory(&r, sizeof(r)); |
||
421 | GetClientRect(hwnd, &r); |
||
422 | SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r); |
||
423 | r.right -= r.left-1; |
||
424 | r.bottom -= r.top-1; |
||
425 | r.top += rtab.top; |
||
426 | r.left += rtab.left; |
||
194 | terminx | 427 | |
337 | terminx | 428 | // Create the pages and position them in the tab control, but hide them |
429 | pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(), |
||
430 | MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc); |
||
431 | pages[TAB_GAME] = CreateDialog((HINSTANCE)win_gethinstance(), |
||
432 | MAKEINTRESOURCE(WIN_STARTWINPAGE_GAME), hwndDlg, GamePageProc); |
||
433 | pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES); |
||
434 | SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
435 | SetWindowPos(pages[TAB_GAME], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
436 | SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
194 | terminx | 437 | |
337 | terminx | 438 | // Tell the editfield acting as the console to exclude the width of the scrollbar |
439 | GetClientRect(pages[TAB_MESSAGES],&r); |
||
440 | r.right -= GetSystemMetrics(SM_CXVSCROLL)+4; |
||
441 | r.left = r.top = 0; |
||
442 | SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r); |
||
194 | terminx | 443 | |
337 | terminx | 444 | // Set a tab stop in the game data listbox |
445 | { |
||
446 | DWORD tabs[1] = { 150 }; |
||
649 | terminx | 447 | (void)ListBox_SetTabStops(GetDlgItem(pages[TAB_GAME], IDGDATA), 1, tabs); |
337 | terminx | 448 | } |
335 | terminx | 449 | |
337 | terminx | 450 | SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START)); |
451 | SetWindowText(hwndDlg, apptitle); |
||
335 | terminx | 452 | } |
337 | terminx | 453 | return FALSE; |
454 | } |
||
335 | terminx | 455 | |
337 | terminx | 456 | case WM_NOTIFY: |
457 | { |
||
458 | LPNMHDR nmhdr = (LPNMHDR)lParam; |
||
459 | int cur; |
||
460 | if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break; |
||
461 | cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); |
||
462 | switch (nmhdr->code) |
||
335 | terminx | 463 | { |
337 | terminx | 464 | case TCN_SELCHANGING: |
465 | { |
||
466 | if (cur < 0 || !pages[cur]) break; |
||
467 | ShowWindow(pages[cur],SW_HIDE); |
||
468 | return TRUE; |
||
222 | terminx | 469 | } |
337 | terminx | 470 | case TCN_SELCHANGE: |
471 | { |
||
472 | if (cur < 0 || !pages[cur]) break; |
||
473 | ShowWindow(pages[cur],SW_SHOW); |
||
331 | terminx | 474 | return TRUE; |
337 | terminx | 475 | } |
476 | } |
||
477 | break; |
||
478 | } |
||
194 | terminx | 479 | |
337 | terminx | 480 | case WM_CLOSE: |
481 | if (mode == TAB_CONFIG) done = 0; |
||
482 | else quitevent++; |
||
483 | return TRUE; |
||
194 | terminx | 484 | |
337 | terminx | 485 | case WM_DESTROY: |
486 | if (hbmp) |
||
487 | { |
||
488 | DeleteObject(hbmp); |
||
489 | hbmp = NULL; |
||
490 | } |
||
194 | terminx | 491 | |
337 | terminx | 492 | if (pages[TAB_GAME]) |
493 | { |
||
494 | DestroyWindow(pages[TAB_GAME]); |
||
495 | pages[TAB_GAME] = NULL; |
||
496 | } |
||
214 | terminx | 497 | |
337 | terminx | 498 | if (pages[TAB_CONFIG]) |
499 | { |
||
500 | DestroyWindow(pages[TAB_CONFIG]); |
||
501 | pages[TAB_CONFIG] = NULL; |
||
502 | } |
||
503 | |||
504 | startupdlg = NULL; |
||
505 | return TRUE; |
||
506 | |||
507 | case WM_COMMAND: |
||
508 | switch (LOWORD(wParam)) |
||
509 | { |
||
510 | case WIN_STARTWIN_CANCEL: |
||
511 | if (mode == TAB_CONFIG) done = 0; |
||
512 | else quitevent++; |
||
335 | terminx | 513 | return TRUE; |
337 | terminx | 514 | case WIN_STARTWIN_START: |
515 | done = 1; |
||
516 | return TRUE; |
||
517 | } |
||
518 | return FALSE; |
||
194 | terminx | 519 | |
337 | terminx | 520 | case WM_CTLCOLORSTATIC: |
521 | if ((HWND)lParam == pages[TAB_MESSAGES]) |
||
522 | return (BOOL)GetSysColorBrush(COLOR_WINDOW); |
||
523 | break; |
||
194 | terminx | 524 | |
337 | terminx | 525 | default: |
526 | break; |
||
222 | terminx | 527 | } |
528 | |||
529 | return FALSE; |
||
194 | terminx | 530 | } |
531 | |||
532 | |||
533 | int startwin_open(void) |
||
534 | { |
||
222 | terminx | 535 | INITCOMMONCONTROLSEX icc; |
536 | if (startupdlg) return 1; |
||
537 | icc.dwSize = sizeof(icc); |
||
538 | icc.dwICC = ICC_TAB_CLASSES; |
||
539 | InitCommonControlsEx(&icc); |
||
540 | startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); |
||
335 | terminx | 541 | if (startupdlg) |
542 | { |
||
222 | terminx | 543 | SetPage(TAB_MESSAGES); |
544 | EnableConfig(0); |
||
545 | return 0; |
||
546 | } |
||
547 | return -1; |
||
194 | terminx | 548 | } |
549 | |||
550 | int startwin_close(void) |
||
551 | { |
||
222 | terminx | 552 | if (!startupdlg) return 1; |
553 | DestroyWindow(startupdlg); |
||
554 | startupdlg = NULL; |
||
555 | return 0; |
||
194 | terminx | 556 | } |
557 | |||
558 | int startwin_puts(const char *buf) |
||
559 | { |
||
222 | terminx | 560 | const char *p = NULL, *q = NULL; |
851 | terminx | 561 | static char workbuf[1024]; |
222 | terminx | 562 | static int newline = 0; |
563 | int curlen, linesbefore, linesafter; |
||
564 | HWND edctl; |
||
565 | int vis; |
||
851 | terminx | 566 | static HWND dactrl = NULL; |
194 | terminx | 567 | |
222 | terminx | 568 | if (!startupdlg) return 1; |
194 | terminx | 569 | |
222 | terminx | 570 | edctl = pages[TAB_MESSAGES]; |
571 | if (!edctl) return -1; |
||
194 | terminx | 572 | |
851 | terminx | 573 | if (!dactrl) dactrl = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); |
222 | terminx | 574 | |
851 | terminx | 575 | vis = ((int)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES); |
576 | |||
222 | terminx | 577 | if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); |
578 | curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); |
||
579 | SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); |
||
580 | linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); |
||
581 | p = buf; |
||
335 | terminx | 582 | while (*p) |
583 | { |
||
584 | if (newline) |
||
585 | { |
||
222 | terminx | 586 | SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); |
587 | newline = 0; |
||
588 | } |
||
589 | q = p; |
||
590 | while (*q && *q != '\n') q++; |
||
591 | memcpy(workbuf, p, q-p); |
||
335 | terminx | 592 | if (*q == '\n') |
593 | { |
||
594 | if (!q[1]) |
||
595 | { |
||
222 | terminx | 596 | newline = 1; |
597 | workbuf[q-p] = 0; |
||
335 | terminx | 598 | } |
599 | else |
||
600 | { |
||
222 | terminx | 601 | workbuf[q-p] = '\r'; |
602 | workbuf[q-p+1] = '\n'; |
||
603 | workbuf[q-p+2] = 0; |
||
604 | } |
||
605 | p = q+1; |
||
335 | terminx | 606 | } |
607 | else |
||
608 | { |
||
222 | terminx | 609 | workbuf[q-p] = 0; |
610 | p = q; |
||
611 | } |
||
612 | SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); |
||
613 | } |
||
614 | linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); |
||
615 | SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); |
||
616 | if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); |
||
617 | return 0; |
||
194 | terminx | 618 | } |
619 | |||
620 | int startwin_settitle(const char *str) |
||
621 | { |
||
222 | terminx | 622 | if (!startupdlg) return 1; |
623 | SetWindowText(startupdlg, str); |
||
624 | return 0; |
||
194 | terminx | 625 | } |
626 | |||
627 | int startwin_idle(void *v) |
||
628 | { |
||
222 | terminx | 629 | if (!startupdlg || !IsWindow(startupdlg)) return 0; |
630 | if (IsDialogMessage(startupdlg, (MSG*)v)) return 1; |
||
631 | return 0; |
||
194 | terminx | 632 | } |
633 | |||
886 | terminx | 634 | extern char *duke3dgrp, *duke3dgrpstring; |
984 | terminx | 635 | extern char mod_dir[BMAX_PATH]; |
214 | terminx | 636 | |
194 | terminx | 637 | int startwin_run(void) |
638 | { |
||
222 | terminx | 639 | MSG msg; |
640 | if (!startupdlg) return 1; |
||
194 | terminx | 641 | |
222 | terminx | 642 | done = -1; |
194 | terminx | 643 | |
219 | terminx | 644 | #ifdef JFAUD |
222 | terminx | 645 | EnumAudioDevs(&wavedevs, NULL, NULL); |
219 | terminx | 646 | #endif |
222 | terminx | 647 | SetPage(TAB_CONFIG); |
648 | EnableConfig(1); |
||
194 | terminx | 649 | |
563 | terminx | 650 | settings.fullscreen = ud.config.ScreenMode; |
651 | settings.xdim = ud.config.ScreenWidth; |
||
652 | settings.ydim = ud.config.ScreenHeight; |
||
653 | settings.bpp = ud.config.ScreenBPP; |
||
654 | settings.forcesetup = ud.config.ForceSetup; |
||
655 | settings.usemouse = ud.config.UseMouse; |
||
656 | settings.usejoy = ud.config.UseJoystick; |
||
561 | terminx | 657 | settings.game = g_GameType; |
886 | terminx | 658 | // settings.crcval = 0; |
222 | terminx | 659 | strncpy(settings.selectedgrp, duke3dgrp, BMAX_PATH); |
984 | terminx | 660 | settings.gamedir = mod_dir; |
222 | terminx | 661 | PopulateForm(-1); |
194 | terminx | 662 | |
335 | terminx | 663 | while (done < 0) |
664 | { |
||
665 | switch (GetMessage(&msg, NULL, 0,0)) |
||
666 | { |
||
337 | terminx | 667 | case 0: |
668 | done = 1; |
||
669 | break; |
||
670 | case -1: |
||
671 | return -1; |
||
672 | default: |
||
673 | if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; |
||
674 | TranslateMessage(&msg); |
||
675 | DispatchMessage(&msg); |
||
676 | break; |
||
222 | terminx | 677 | } |
678 | } |
||
194 | terminx | 679 | |
222 | terminx | 680 | SetPage(TAB_MESSAGES); |
681 | EnableConfig(0); |
||
335 | terminx | 682 | if (done) |
683 | { |
||
886 | terminx | 684 | int i; |
685 | |||
563 | terminx | 686 | ud.config.ScreenMode = settings.fullscreen; |
687 | ud.config.ScreenWidth = settings.xdim; |
||
688 | ud.config.ScreenHeight = settings.ydim; |
||
689 | ud.config.ScreenBPP = settings.bpp; |
||
690 | ud.config.ForceSetup = settings.forcesetup; |
||
691 | ud.config.UseMouse = settings.usemouse; |
||
692 | ud.config.UseJoystick = settings.usejoy; |
||
222 | terminx | 693 | duke3dgrp = settings.selectedgrp; |
561 | terminx | 694 | g_GameType = settings.game; |
990 | terminx | 695 | |
985 | terminx | 696 | if (settings.gamedir != NULL) |
984 | terminx | 697 | { |
698 | addsearchpath(settings.gamedir); |
||
699 | Bstrcpy(mod_dir,settings.gamedir); |
||
700 | } |
||
989 | terminx | 701 | else Bsprintf(mod_dir,"/"); |
886 | terminx | 702 | |
703 | for (i = 0; i<numgrpfiles; i++) if (settings.crcval == grpfiles[i].crcval) break; |
||
704 | if (i != numgrpfiles) |
||
705 | duke3dgrpstring = (char *)grpfiles[i].name; |
||
222 | terminx | 706 | } |
194 | terminx | 707 | |
335 | terminx | 708 | if (wavedevs) |
709 | { |
||
222 | terminx | 710 | struct audioenumdev *d, *e; |
711 | free(wavedevs->drvs); |
||
335 | terminx | 712 | for (e=wavedevs->devs; e; e=d) |
713 | { |
||
222 | terminx | 714 | d = e->next; |
715 | if (e->devs) free(e->devs); |
||
716 | free(e); |
||
717 | } |
||
718 | free(wavedevs); |
||
719 | } |
||
219 | terminx | 720 | |
222 | terminx | 721 | return done; |
194 | terminx | 722 | } |
723 |