Subversion Repositories eduke32

Rev

Rev 8760 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1677 terminx 1
//-------------------------------------------------------------------------
2
/*
5661 terminx 3
Copyright (C) 2016 EDuke32 developers and contributors
1677 terminx 4
 
5
This file is part of EDuke32.
6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
4541 hendricks2 19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
1677 terminx 20
*/
21
//-------------------------------------------------------------------------
22
 
4747 terminx 23
#ifndef menus_h_
24
#define menus_h_
1677 terminx 25
 
8760 terminx 26
#include "common.h"
4496 hendricks2 27
#include "compat.h"
8760 terminx 28
#include "pragmas.h"
29
#include "vfs.h"
1677 terminx 30
 
4766 hendricks2 31
#ifdef __cplusplus
32
extern "C" {
33
#endif
34
 
4852 hendricks2 35
#if defined EDUKE32_TOUCH_DEVICES
8569 terminx 36
# define EDUKE32_RETAIL_MENU
6013 terminx 37
# define EDUKE32_ANDROID_MENU
4609 terminx 38
#endif
39
 
6013 terminx 40
// #define EDUKE32_SIMPLE_MENU
4609 terminx 41
 
3084 terminx 42
enum MenuIndex_t {
4496 hendricks2 43
    MENU_NULL           = INT32_MIN, // sentinel for "do nothing"
44
    MENU_CLOSE          = -2, // sentinel for "close the menu"/"no menu"
45
    MENU_PREVIOUS       = -1, // sentinel for "go to previous menu"
3084 terminx 46
    MENU_MAIN           = 0,
47
    MENU_MAIN_INGAME    = 50,
48
    MENU_EPISODE        = 100,
49
    MENU_USERMAP        = 101,
7930 hendricks2 50
    MENU_NEWGAMECUSTOM  = 102,
51
    MENU_NEWGAMECUSTOMSUB = 103,
3084 terminx 52
    MENU_SKILL          = 110,
4496 hendricks2 53
    MENU_GAMESETUP      = 200,
3084 terminx 54
    MENU_OPTIONS        = 202,
55
    MENU_VIDEOSETUP     = 203,
56
    MENU_KEYBOARDSETUP  = 204,
4399 hendricks2 57
    MENU_MOUSESETUP     = 205,
58
    MENU_JOYSTICKSETUP  = 206,
59
    MENU_JOYSTICKBTNS   = 207,
60
    MENU_JOYSTICKAXES   = 208,
4496 hendricks2 61
    MENU_KEYBOARDKEYS   = 209,
62
    MENU_MOUSEBTNS      = 210,
63
    MENU_JOYSTICKAXIS   = 213,
4993 terminx 64
    MENU_TOUCHSETUP     = 214,
5652 terminx 65
    MENU_TOUCHSENS      = 215,
66
    MENU_TOUCHBUTTONS   = 216,
7134 terminx 67
    MENU_CONTROLS       = 220,
5408 terminx 68
    MENU_POLYMOST       = 230,
4399 hendricks2 69
    MENU_COLCORR        = 231,
70
    MENU_COLCORR_INGAME = 232,
7134 terminx 71
    MENU_SCREENSETUP    = 233,
72
    MENU_DISPLAYSETUP   = 234,
5408 terminx 73
    MENU_POLYMER        = 240,
3084 terminx 74
    MENU_LOAD           = 300,
4399 hendricks2 75
    MENU_SAVE           = 350,
3084 terminx 76
    MENU_STORY          = 400,
77
    MENU_F1HELP         = 401,
78
    MENU_QUIT           = 500,
79
    MENU_QUITTOTITLE    = 501,
4496 hendricks2 80
    MENU_QUIT_INGAME    = 502,
4399 hendricks2 81
    MENU_NETSETUP       = 600,
82
    MENU_NETWAITMASTER  = 601,
83
    MENU_NETWAITVOTES   = 603,
3084 terminx 84
    MENU_SOUND          = 700,
85
    MENU_SOUND_INGAME   = 701,
8760 terminx 86
    MENU_SOUND_DEVSETUP = 702,
87
    MENU_SOUND_SF2      = 703,
6742 hendricks2 88
    MENU_SAVESETUP      = 750,
6750 hendricks2 89
    MENU_SAVECLEANVERIFY = 751,
8114 terminx 90
    MENU_RESETSTATSVERIFY = 752,
5084 hendricks2 91
    MENU_CHEATS         = 800,
92
    MENU_CHEATENTRY     = 801,
93
    MENU_CHEAT_WARP     = 802,
94
    MENU_CHEAT_SKILL    = 803,
3084 terminx 95
    MENU_CREDITS        = 990,
96
    MENU_CREDITS2       = 991,
97
    MENU_CREDITS3       = 992,
98
    MENU_CREDITS4       = 993,
99
    MENU_CREDITS5       = 994,
4399 hendricks2 100
    MENU_LOADVERIFY     = 1000,
6750 hendricks2 101
    MENU_LOADDELVERIFY  = 1100,
4399 hendricks2 102
    MENU_NEWVERIFY      = 1500,
103
    MENU_SAVEVERIFY     = 2000,
6750 hendricks2 104
    MENU_SAVEDELVERIFY  = 2100,
7971 hendricks2 105
    MENU_COLCORRRESETVERIFY = 2200,
106
    MENU_KEYSRESETVERIFY = 2201,
107
    MENU_KEYSCLASSICVERIFY = 2202,
108
    MENU_JOYSTANDARDVERIFY = 2203,
109
    MENU_JOYPROVERIFY   = 2204,
110
    MENU_JOYCLEARVERIFY = 2205,
3084 terminx 111
    MENU_ADULTPASSWORD  = 10001,
4399 hendricks2 112
    MENU_RESETPLAYER    = 15000,
3084 terminx 113
    MENU_BUYDUKE        = 20000,
4399 hendricks2 114
    MENU_NETWORK        = 20001,
115
    MENU_PLAYER         = 20002,
116
    MENU_MACROS         = 20004,
117
    MENU_NETHOST        = 20010,
118
    MENU_NETOPTIONS     = 20011,
4496 hendricks2 119
    MENU_NETUSERMAP     = 20012,
4399 hendricks2 120
    MENU_NETJOIN        = 20020,
4496 hendricks2 121
};
3084 terminx 122
 
4496 hendricks2 123
 
124
 
125
typedef int32_t MenuID_t;
126
 
127
 
4688 hendricks2 128
typedef enum MenuAnimationType_t
129
{ // Note: This enum is for logical categories, not visual types.
130
    MA_None,
131
    MA_Return,
132
    MA_Advance,
133
} MenuAnimationType_t;
4496 hendricks2 134
 
135
// a subset of screentext parameters, restricted because menus require accessibility
4778 hendricks2 136
typedef struct MenuFont_t
4496 hendricks2 137
{
6613 hendricks2 138
//    int32_t xspace, yline;
6195 hendricks2 139
    vec2_t emptychar, between;
6196 hendricks2 140
    int32_t zoom;
6203 hendricks2 141
    int32_t cursorLeftPosition, cursorCenterPosition, cursorScale;
4496 hendricks2 142
    int32_t textflags;
6195 hendricks2 143
    int16_t tilenum;
6613 hendricks2 144
    // selected shade glows, deselected shade is used by Blood, disabled shade is used by SW
145
    int8_t shade_deselected, shade_disabled;
146
    uint8_t pal;
147
    uint8_t pal_selected, pal_deselected, pal_disabled;
148
    uint8_t pal_selected_right, pal_deselected_right, pal_disabled_right;
6196 hendricks2 149
 
6255 hendricks2 150
    int32_t get_yline() const { return mulscale16(emptychar.y, zoom); }
4778 hendricks2 151
} MenuFont_t;
4496 hendricks2 152
 
153
 
154
 
155
typedef enum MenuEntryType_t
156
{
157
    Dummy,
158
    Link,
159
    Option,
160
    Custom2Col,
161
    RangeInt32,
162
    RangeFloat,
6403 hendricks2 163
#ifdef MENU_ENABLE_RANGEDOUBLE
4496 hendricks2 164
    RangeDouble,
6403 hendricks2 165
#endif
4496 hendricks2 166
    String,
4778 hendricks2 167
    Spacer,
4496 hendricks2 168
} MenuEntryType_t;
169
 
4778 hendricks2 170
typedef struct MenuEntryFormat_t
171
{
172
    int32_t marginBottom;
173
    int32_t indent;
174
    int32_t width; // 0: center, >0: width of the label column (left-aligned options), <0: -width of everything (right-aligned)
175
} MenuEntryFormat_t;
4496 hendricks2 176
 
4778 hendricks2 177
 
178
typedef struct MenuMenuFormat_t
4496 hendricks2 179
{
180
    vec2_t pos;
4682 hendricks2 181
    int32_t bottomcutoff; // >0: the bottom edge of the menu before automatic scrolling kicks in, <0: -total height for vertical justification
4778 hendricks2 182
} MenuMenuFormat_t;
4496 hendricks2 183
 
184
typedef struct MenuLink_t
185
{
186
    // traits
187
    MenuID_t linkID;
4688 hendricks2 188
    MenuAnimationType_t animation;
4496 hendricks2 189
} MenuLink_t;
190
typedef struct MenuOptionSet_t
191
{
192
    // traits
5547 terminx 193
    char const **optionNames;
4496 hendricks2 194
    int32_t *optionValues; // If NULL, the identity of currentOption is assumed.
4778 hendricks2 195
 
196
    // pop-up list appearance
197
    MenuMenuFormat_t *menuFormat;
198
    MenuEntryFormat_t *entryFormat;
199
    MenuFont_t *font;
200
 
201
    // traits
4496 hendricks2 202
    int32_t numOptions;
203
 
4778 hendricks2 204
    // pop-up list state
4496 hendricks2 205
    int32_t currentEntry;
206
    int32_t scrollPos;
4778 hendricks2 207
 
208
    // appearance
209
    uint8_t features; // bit 1 = disable left/right arrows, bit 2 = disable list
6197 hendricks2 210
 
6255 hendricks2 211
    int32_t getMarginBottom() const { return mulscale16(entryFormat->marginBottom, font->zoom); }
212
    int32_t getIndent() const { return mulscale16(entryFormat->indent, font->zoom); }
4496 hendricks2 213
} MenuOptionSet_t;
214
typedef struct MenuOption_t
215
{
216
    // appearance
4778 hendricks2 217
    MenuFont_t *font;
4496 hendricks2 218
 
219
    // traits
220
    MenuOptionSet_t *options; // so that common sets such as Yes/No, On/Off can be reused
221
 
222
    // effect
223
    int32_t *data;
224
 
225
    // state
226
    int32_t currentOption;
227
} MenuOption_t;
228
typedef struct MenuCustom2Col_t
229
{
4778 hendricks2 230
    // effect
231
    uint8_t *column[2];
5547 terminx 232
    char const **key;
4778 hendricks2 233
 
4496 hendricks2 234
    // appearance
4778 hendricks2 235
    MenuFont_t *font;
4496 hendricks2 236
 
4778 hendricks2 237
    // effect
4496 hendricks2 238
    size_t numvalid;
239
 
4778 hendricks2 240
    // appearance
241
    int32_t columnWidth;
4496 hendricks2 242
 
243
    // state
244
    int8_t screenOpen;
245
} MenuCustom2Col_t;
4866 hendricks2 246
 
247
enum MenuRangeFlags_t
248
{
249
    DisplayTypeInteger = 1,
250
    DisplayTypePercent = 2,
251
    DisplayTypeNormalizedDecimal = 3,
252
    DisplayTypeMask = (1<<0)|(1<<1),
253
 
254
    EnforceIntervals = 1<<7,
255
};
4496 hendricks2 256
typedef struct MenuRangeInt32_t
257
{
4778 hendricks2 258
    // effect
259
    int32_t *variable;
260
 
4496 hendricks2 261
    // appearance
4778 hendricks2 262
    MenuFont_t *font;
4496 hendricks2 263
 
264
    // traits
265
    int32_t min;
266
    int32_t max;
4778 hendricks2 267
    int32_t onehundredpercent; // 0 implies max
4496 hendricks2 268
    int32_t steps;
269
 
4866 hendricks2 270
    uint8_t flags;
4496 hendricks2 271
} MenuRangeInt32_t;
272
typedef struct MenuRangeFloat_t
273
{
4778 hendricks2 274
    // effect
275
    float *variable;
276
 
4496 hendricks2 277
    // appearance
4778 hendricks2 278
    MenuFont_t *font;
4496 hendricks2 279
 
280
    // traits
281
    float min;
282
    float max;
4778 hendricks2 283
    float onehundredpercent; // 0 implies 1.0
4496 hendricks2 284
    int32_t steps;
285
 
4866 hendricks2 286
    uint8_t flags;
4496 hendricks2 287
} MenuRangeFloat_t;
6403 hendricks2 288
#ifdef MENU_ENABLE_RANGEDOUBLE
4496 hendricks2 289
typedef struct MenuRangeDouble_t
290
{
4778 hendricks2 291
    // effect
292
    double *variable;
293
 
4496 hendricks2 294
    // appearance
4778 hendricks2 295
    MenuFont_t *font;
4496 hendricks2 296
 
297
    // traits
298
    double min;
299
    double max;
4778 hendricks2 300
    double onehundredpercent; // 0 implies 1.0
4496 hendricks2 301
    int32_t steps;
302
 
4866 hendricks2 303
    uint8_t flags;
4496 hendricks2 304
} MenuRangeDouble_t;
6403 hendricks2 305
#endif
4496 hendricks2 306
typedef struct MenuString_t
307
{
4778 hendricks2 308
    // state
309
    char* editfield;
310
 
311
    // effect
312
    char* variable;
313
 
4496 hendricks2 314
    // appearance
4778 hendricks2 315
    MenuFont_t *font;
4496 hendricks2 316
 
317
    // effect
6530 hendricks2 318
    int32_t bufsize;
4496 hendricks2 319
    int32_t flags;
320
} MenuString_t;
4778 hendricks2 321
typedef struct MenuSpacer_t
322
{
323
    int32_t height;
324
} MenuSpacer_t;
4496 hendricks2 325
 
4855 hendricks2 326
// For internal use only.
327
enum MenuEntryFlags_t
328
{
6204 hendricks2 329
    MEF_Disabled = 1<<0,
6205 hendricks2 330
    MEF_LookDisabled = 1<<1,
6676 hendricks2 331
    MEF_Hidden = 1<<2,
4855 hendricks2 332
};
4496 hendricks2 333
 
334
typedef struct MenuEntry_t
335
{
336
    // traits
337
    const char *name;
338
 
4778 hendricks2 339
    // appearance
340
    MenuFont_t *font;
341
    MenuEntryFormat_t *format;
342
 
343
    void *entry;
4496 hendricks2 344
    MenuEntryType_t type;
345
 
346
    // state
4855 hendricks2 347
    int32_t flags;
4496 hendricks2 348
    int32_t ytop, ybottom;
6197 hendricks2 349
 
6255 hendricks2 350
    int32_t getMarginBottom() const { return mulscale16(format->marginBottom, font->zoom); }
351
    int32_t getIndent() const { return mulscale16(format->indent, font->zoom); }
6200 hendricks2 352
    int32_t getHeight() const
6199 hendricks2 353
    {
6255 hendricks2 354
        return type == Spacer ? mulscale16(((MenuSpacer_t *)entry)->height, font->zoom) : font->get_yline();
6199 hendricks2 355
    }
4496 hendricks2 356
} MenuEntry_t;
357
 
358
 
359
typedef enum MenuType_t
360
{
361
    Menu,
362
    Panel,
363
    Verify,
364
    Message,
5083 hendricks2 365
    TextForm,
4496 hendricks2 366
    FileSelect,
367
} MenuType_t;
368
 
369
typedef struct MenuMenu_t
370
{
371
    const char *title;
372
 
4778 hendricks2 373
    MenuMenuFormat_t *format;
374
 
375
    MenuEntry_t **entrylist;
376
    int32_t numEntries;
377
 
4496 hendricks2 378
    // state
4778 hendricks2 379
    int32_t currentEntry, currentColumn;
5693 hendricks2 380
    int32_t scrollPos;
4496 hendricks2 381
} MenuMenu_t;
382
typedef struct MenuPanel_t
383
{
384
    const char *title;
385
 
386
    MenuID_t previousID;
4688 hendricks2 387
    MenuAnimationType_t previousAnimation;
4496 hendricks2 388
    MenuID_t nextID;
4688 hendricks2 389
    MenuAnimationType_t nextAnimation;
4496 hendricks2 390
} MenuPanel_t;
391
typedef struct MenuVerify_t
392
{
393
    vec2_t cursorpos;
394
 
395
    MenuID_t linkID;
4688 hendricks2 396
    MenuAnimationType_t animation;
4496 hendricks2 397
} MenuVerify_t;
398
typedef struct MenuMessage_t
399
{
400
    vec2_t cursorpos;
401
 
402
    MenuID_t linkID;
4688 hendricks2 403
    MenuAnimationType_t animation;
4496 hendricks2 404
} MenuMessage_t;
5083 hendricks2 405
enum MenuTextFormFlags_t
4496 hendricks2 406
{
5083 hendricks2 407
    MTF_Password = 1<<0,
408
};
409
typedef struct MenuTextForm_t
410
{
4778 hendricks2 411
    // state
412
    char *input;
413
 
4496 hendricks2 414
    // traits
5083 hendricks2 415
    const char *instructions;
6530 hendricks2 416
    int32_t bufsize;
5083 hendricks2 417
    uint8_t flags;
418
} MenuTextForm_t;
4496 hendricks2 419
typedef struct MenuFileSelect_t
420
{
421
    const char *title;
422
 
423
    // appearance
4851 hendricks2 424
    MenuMenuFormat_t *format[2];
4778 hendricks2 425
    MenuFont_t *font[2];
4496 hendricks2 426
 
427
    // traits
7999 hendricks2 428
    const char * startdir;
4496 hendricks2 429
    const char *pattern;
430
    char *destination;
431
 
432
    // state
8199 terminx 433
    BUILDVFS_FIND_REC *findhigh[2];
4778 hendricks2 434
    int32_t scrollPos[2];
4851 hendricks2 435
 
436
    // appearance
437
    int32_t marginBottom[2];
438
 
439
    // state
4496 hendricks2 440
    fnlist_t fnlist;
4778 hendricks2 441
    int32_t currentList;
6197 hendricks2 442
 
6255 hendricks2 443
    int32_t getMarginBottom(size_t index) const { return mulscale16(marginBottom[index], font[index]->zoom); }
4496 hendricks2 444
} MenuFileSelect_t;
445
 
446
typedef struct Menu_t
447
{
4778 hendricks2 448
    void *object;
4496 hendricks2 449
    MenuID_t menuID;
450
    MenuID_t parentID;
4688 hendricks2 451
    MenuAnimationType_t parentAnimation;
4496 hendricks2 452
    MenuType_t type;
453
} Menu_t;
454
 
5663 terminx 455
typedef struct MenuAnimation_t
456
{
457
    int32_t(*out)(struct MenuAnimation_t *);
458
    int32_t(*in)(struct MenuAnimation_t *);
4688 hendricks2 459
 
5663 terminx 460
    Menu_t *previous;
461
    Menu_t *current;
462
 
463
    int32_t start;
464
    int32_t length;
465
} MenuAnimation_t;
466
 
467
extern MenuAnimation_t m_animation;
468
 
4496 hendricks2 469
extern MenuID_t g_currentMenu;
470
extern Menu_t *m_currentMenu;
471
 
1677 terminx 472
extern int32_t g_quitDeadline;
473
extern int32_t voting;
7134 terminx 474
int Menu_Change(MenuID_t cm);
5923 terminx 475
void Menu_AnimateChange(int32_t cm, MenuAnimationType_t animtype);
476
int32_t Menu_IsTextInput(Menu_t *cm);
7133 terminx 477
int G_CheckPlayerColor(int color);
5923 terminx 478
void Menu_Init(void);
7114 terminx 479
void Menu_Open(uint8_t playerID);
480
void Menu_Close(uint8_t playerID);
1677 terminx 481
void M_DisplayMenus(void);
2207 helixhorne 482
 
6613 hendricks2 483
extern MenuFont_t MF_Redfont, MF_Bluefont, MF_Minifont;
6209 hendricks2 484
 
4919 terminx 485
#define M_MOUSETIMEOUT 210
4854 hendricks2 486
extern int32_t m_mouselastactivity;
487
 
488
#if defined EDUKE32_TOUCH_DEVICES
5169 hendricks2 489
# define MOUSEALPHA 0
6685 hendricks2 490
# define CURSORALPHA (255/3)
4854 hendricks2 491
# define MOUSEACTIVECONDITIONAL(condition) (condition)
4856 hendricks2 492
# define MOUSEWATCHPOINTCONDITIONAL(condition) (condition)
4854 hendricks2 493
#else
4856 hendricks2 494
extern int32_t m_mousewake_watchpoint, m_menuchange_watchpoint;
5124 hendricks2 495
// alpha increments of 3 --> 255 / 3 = 85 --> round up to power of 2 --> 128 --> divide by 2 --> 64 alphatabs required
5900 hendricks2 496
// use 16 anyway :P
6829 terminx 497
# define MOUSEUSEALPHA (videoGetRenderMode() != REND_CLASSIC || numalphatabs >= 15)
8050 pogokeen 498
# define MOUSEALPHA (MOUSEUSEALPHA ? clamp(((int32_t) totalclock - m_mouselastactivity - 90)*3, 0, 255) : 0)
499
# define CURSORALPHA (MOUSEUSEALPHA ? clamp(((int32_t) totalclock - m_mouselastactivity - 90)*2 + (255/3), (255/3), 255) : 255/3)
4854 hendricks2 500
# define MOUSEACTIVECONDITION (totalclock - m_mouselastactivity < M_MOUSETIMEOUT)
501
# define MOUSEACTIVECONDITIONAL(condition) (MOUSEACTIVECONDITION && (condition))
7899 hendricks2 502
# define MOUSEINACTIVECONDITIONAL(condition) ((!(g_player[myconnectindex].ps->gm & MODE_MENU) || !MOUSEACTIVECONDITION) && (condition))
4856 hendricks2 503
# define MOUSEWATCHPOINTCONDITIONAL(condition) ((condition) || m_mousewake_watchpoint || m_menuchange_watchpoint == 3)
4854 hendricks2 504
#endif
505
 
7930 hendricks2 506
#define MAXMENUGAMEPLAYENTRIES 7
507
 
508
enum MenuGameplayEntryFlags
509
{
510
    MGE_Locked = 1u<<0u,
511
    MGE_Hidden = 1u<<1u,
7998 hendricks2 512
    MGE_UserContent = 1u<<2u,
7930 hendricks2 513
};
514
 
515
typedef struct MenuGameplayEntry
516
{
517
    char name[64];
518
    uint8_t flags;
519
 
520
    bool isValid() const { return name[0] != '\0'; }
521
} MenuGameplayEntry;
522
 
523
typedef struct MenuGameplayStemEntry
524
{
525
    MenuGameplayEntry entry;
526
    MenuGameplayEntry subentries[MAXMENUGAMEPLAYENTRIES];
527
} MenuGameplayStemEntry;
528
 
529
extern MenuGameplayStemEntry g_MenuGameplayEntries[MAXMENUGAMEPLAYENTRIES];
530
 
531
extern MenuEntry_t ME_NEWGAMECUSTOMENTRIES[MAXMENUGAMEPLAYENTRIES];
532
extern MenuEntry_t ME_NEWGAMECUSTOMSUBENTRIES[MAXMENUGAMEPLAYENTRIES][MAXMENUGAMEPLAYENTRIES];
533
 
4766 hendricks2 534
#ifdef __cplusplus
535
}
1677 terminx 536
#endif
4766 hendricks2 537
 
538
#endif