Subversion Repositories eduke32

Rev

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