Subversion Repositories eduke32

Rev

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