Skip to content

Commit 3cf1bca

Browse files
committed
Menu Setup
1 parent cde5f88 commit 3cf1bca

File tree

2 files changed

+156
-63
lines changed

2 files changed

+156
-63
lines changed

prboom2/src/m_menu.c

Lines changed: 153 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@
135135
#define S_CREDIT 0x00200000 // killough 10/98: credit
136136
#define S_THERMO 0x00400000 // Slider for choosing a value
137137
#define S_CHOICE 0x00800000 // this item has several values
138-
// #define S_ 0x01000000
138+
#define S_DISABLED 0x01000000
139139
#define S_NAME 0x02000000
140140
#define S_RESET_Y 0x04000000
141-
// #define S_ 0x08000000
141+
#define S_FUNC 0x08000000
142142
// #define S_ 0x10000000
143143
// #define S_ 0x20000000
144144
#define S_STR 0x40000000 // need to refactor things...
@@ -150,9 +150,9 @@
150150
* S_HASDEFPTR = the set of items whose var field points to default array
151151
*/
152152

153-
#define S_SHOWDESC (S_LABEL|S_TITLE|S_YESNO|S_CRITEM|S_COLOR|S_PREV|S_NEXT|S_INPUT|S_WEAP|S_NUM|S_FILE|S_CREDIT|S_CHOICE|S_THERMO|S_NAME)
153+
#define S_SHOWDESC (S_LABEL|S_TITLE|S_YESNO|S_CRITEM|S_COLOR|S_PREV|S_NEXT|S_INPUT|S_WEAP|S_NUM|S_FILE|S_CREDIT|S_CHOICE|S_FUNC|S_THERMO|S_NAME)
154154

155-
#define S_SHOWSET (S_YESNO|S_CRITEM|S_COLOR|S_INPUT|S_WEAP|S_NUM|S_FILE|S_CHOICE|S_THERMO|S_NAME)
155+
#define S_SHOWSET (S_YESNO|S_CRITEM|S_COLOR|S_INPUT|S_WEAP|S_NUM|S_FILE|S_CHOICE|S_FUNC|S_THERMO|S_NAME)
156156

157157
#define S_STRING (S_FILE|S_NAME)
158158

@@ -171,6 +171,7 @@ static dboolean set_keybnd_active = false; // in key binding setup screens
171171
static dboolean set_display_active = false;
172172
static dboolean set_demos_active = false; // in demos setup screen
173173
static dboolean set_compatibility_active = false;
174+
static dboolean set_skill_builder_active = false;
174175
static dboolean set_weapon_active = false; // in weapons setup screen
175176
static dboolean set_auto_active = false; // in automap setup screen
176177
static dboolean level_table_active = false;
@@ -1656,6 +1657,40 @@ static void M_SetSetupMenuItemOn (const int x)
16561657
}
16571658
}
16581659

1660+
static dboolean M_ItemSelected(const setup_menu_t *s)
1661+
{
1662+
int flags = s->m_flags;
1663+
1664+
if (s == current_setup_menu + set_menu_itemon && whichSkull && !(flags & S_NOSELECT))
1665+
{
1666+
return true;
1667+
}
1668+
1669+
return false;
1670+
}
1671+
1672+
static void M_BlinkingArrowRight(const setup_menu_t *s)
1673+
{
1674+
int flags = s->m_flags;
1675+
1676+
if (!M_ItemSelected(s))
1677+
{
1678+
return;
1679+
}
1680+
1681+
if (flags & (S_CHOICE | S_CRITEM | S_THERMO))
1682+
{
1683+
if (!setup_select)
1684+
{
1685+
strcat(menu_buffer, " <");
1686+
}
1687+
}
1688+
else if (!setup_select)
1689+
{
1690+
strcat(menu_buffer, " <");
1691+
}
1692+
}
1693+
16591694
static void M_UpdateSetupMenu(setup_menu_t *new_setup_menu)
16601695
{
16611696
current_setup_menu = new_setup_menu;
@@ -1797,6 +1832,47 @@ static int entry_index;
17971832
static char entry_string_index[ENTRY_STRING_BFR_SIZE]; // points to new strings while editing
17981833
static int choice_value;
17991834

1835+
/////////////////////////////
1836+
//
1837+
// M_ItemDisabled
1838+
//
1839+
// Disable certain menu options based on various conditions:
1840+
// StrictMode, Complevel, and more!
1841+
//
1842+
//
1843+
1844+
static dboolean M_ItemDisabled(const setup_menu_t* s)
1845+
{
1846+
// Strict Mode
1847+
if (dsda_StrictMode() && dsda_IsStrictConfig(s->config_id))
1848+
return true;
1849+
1850+
return false;
1851+
}
1852+
1853+
/////////////////////////////
1854+
//
1855+
// Menu Text Colors
1856+
//
1857+
//
1858+
1859+
static int GetItemColor(int flags)
1860+
{
1861+
return (flags & S_TITLE && flags & S_DISABLED) ? cr_title + CR_DARKEN :
1862+
flags & S_DISABLED ? cr_label + CR_DARKEN : flags & (S_SELECT|S_TC_SEL) ? cr_label_edit :
1863+
flags & S_HILITE ? cr_label_highlight :
1864+
flags & (S_TITLE|S_NEXT|S_PREV) ? cr_title :
1865+
cr_label; // killough 10/98
1866+
}
1867+
1868+
static int GetOptionColor(int flags)
1869+
{
1870+
return flags & S_DISABLED ? cr_value + CR_DARKEN :
1871+
flags & S_SELECT ? cr_value_edit :
1872+
flags & S_HILITE ? cr_value_highlight :
1873+
cr_value;
1874+
}
1875+
18001876
/////////////////////////////
18011877
//
18021878
// phares 4/18/98:
@@ -1810,31 +1886,39 @@ static int choice_value;
18101886
static void M_DrawItem(const setup_menu_t* s, int y)
18111887
{
18121888
int x = s->m_x;
1889+
const char text[66];
18131890
int flags = s->m_flags;
18141891
char *p, *t;
18151892
int w = 0;
1816-
int color =
1817-
dsda_StrictMode() && dsda_IsStrictConfig(s->config_id) ? cr_label + CR_DARKEN :
1818-
flags & (S_SELECT|S_TC_SEL) ? cr_label_edit :
1819-
flags & S_HILITE ? cr_label_highlight :
1820-
flags & (S_TITLE|S_NEXT|S_PREV) ? cr_title :
1821-
cr_label; // killough 10/98
1893+
int color;
1894+
1895+
if (M_ItemDisabled(s))
1896+
flags |= S_DISABLED;
1897+
1898+
color = GetItemColor(flags);
1899+
1900+
sprintf(text, "%s%s", s->m_text, (flags & S_FUNC) ? ". . ." : "");
18221901

18231902
/* killough 10/98:
18241903
* Enhance to support multiline text separated by newlines.
18251904
* This supports multiline items on horizontally-crowded menus.
18261905
*/
18271906

1828-
for (p = t = Z_Strdup(s->m_text); (p = strtok(p,"\n")); y += 8, p = NULL)
1829-
{ /* killough 10/98: support left-justification: */
1830-
if (flags & S_CENTER)
1831-
w = M_GetPixelWidth(p) / 2;
1832-
else if (!(flags & S_LEFTJUST))
1833-
w = M_GetPixelWidth(p) + 4;
1834-
M_DrawString(x - w, y ,color, p);
1835-
// print a blinking "arrow" next to the currently highlighted menu item
1836-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !(flags & S_NOSELECT))
1837-
M_DrawString(x - w - 8, y, color, ">");
1907+
for (p = t = Z_Strdup(text); (p = strtok(p,"\n")); y += 8, p = NULL)
1908+
{ /* killough 10/98: support left-justification: */
1909+
w = M_GetPixelWidth(p);
1910+
1911+
if (!(flags & S_LEFTJUST))
1912+
x -= (w + 4);
1913+
1914+
M_DrawString(x, y , color, p);
1915+
1916+
// print a blinking left "arrow" before highlighted menu item
1917+
if (M_ItemSelected(s))
1918+
M_DrawString(x - 8, y, color, ">");
1919+
// print a blinking right "arrow" after function
1920+
if (M_ItemSelected(s) && (flags & S_FUNC))
1921+
M_DrawString(x + w, y, color, " <");
18381922
}
18391923
Z_Free(t);
18401924
}
@@ -1865,19 +1949,17 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
18651949
// Determine color of the text. This may or may not be used later,
18661950
// depending on whether the item is a text string or not.
18671951

1868-
color =
1869-
dsda_StrictMode() && dsda_IsStrictConfig(s->config_id) ? cr_value + CR_DARKEN :
1870-
flags & S_SELECT ? cr_value_edit :
1871-
flags & S_HILITE ? cr_value_highlight :
1872-
cr_value;
1952+
if (M_ItemDisabled(s))
1953+
flags |= S_DISABLED;
1954+
1955+
color = GetOptionColor(flags);
18731956

18741957
// Is the item a YES/NO item?
18751958

18761959
if (flags & S_YESNO) {
18771960
strcpy(menu_buffer, dsda_IntConfig(s->config_id) ? "YES" : "NO");
18781961

1879-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
1880-
strcat(menu_buffer, " <");
1962+
M_BlinkingArrowRight(s);
18811963
M_DrawMenuString(x,y,color);
18821964
return;
18831965
}
@@ -1900,12 +1982,11 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
19001982
if (flags & S_CRITEM)
19011983
{
19021984
color = value;
1903-
if (dsda_StrictMode() && dsda_IsStrictConfig(s->config_id))
1985+
if (flags & S_DISABLED)
19041986
color += CR_DARKEN;
19051987
}
19061988
}
1907-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
1908-
strcat(menu_buffer, " <");
1989+
M_BlinkingArrowRight(s);
19091990
M_DrawMenuString(x, y, color);
19101991
return;
19111992
}
@@ -1962,9 +2043,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
19622043
if (!any_input)
19632044
M_GetKeyString(0, 0);
19642045

1965-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
1966-
strcat(menu_buffer, " <");
1967-
2046+
M_BlinkingArrowRight(s);
19682047
M_DrawMenuString(x, y, color);
19692048

19702049
return;
@@ -2049,8 +2128,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
20492128
// Draw the setting for the item
20502129

20512130
strcpy(menu_buffer, text);
2052-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
2053-
strcat(menu_buffer, " <");
2131+
M_BlinkingArrowRight(s);
20542132
M_DrawMenuString(x, y, color);
20552133
return;
20562134
}
@@ -2081,8 +2159,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
20812159
}
20822160
}
20832161

2084-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
2085-
strcat(menu_buffer, " <");
2162+
M_BlinkingArrowRight(s);
20862163
M_DrawMenuString(x,y,color);
20872164
return;
20882165
}
@@ -2092,8 +2169,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
20922169

20932170
sprintf(menu_buffer, "%d", dsda_IntConfig(s->config_id));
20942171

2095-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
2096-
strcat(menu_buffer, " <");
2172+
M_BlinkingArrowRight(s);
20972173
M_DrawMenuString(x + 80, y + 3, color);
20982174
return;
20992175
}
@@ -2302,7 +2378,7 @@ static void M_DrawInstructions(void)
23022378
// are changing an item or just sitting on it.
23032379

23042380
if (setup_select) {
2305-
switch (flags & (S_INPUT | S_YESNO | S_WEAP | S_NUM | S_COLOR | S_CRITEM | S_FILE | S_CHOICE | S_THERMO | S_NAME)) {
2381+
switch (flags & (S_INPUT | S_YESNO | S_WEAP | S_NUM | S_COLOR | S_CRITEM | S_FILE | S_CHOICE | S_FUNC | S_THERMO | S_NAME)) {
23062382
case S_INPUT:
23072383
M_DrawInstructionString(cr_info_edit, "Press key or button for this action");
23082384
break;
@@ -2333,13 +2409,18 @@ static void M_DrawInstructions(void)
23332409
case S_NAME:
23342410
M_DrawInstructionString(cr_info_edit, "Type / edit author and Press ENTER");
23352411
break;
2412+
case S_FUNC:
2413+
M_DrawInstructionString(cr_info_edit, "Press ENTER key to confirm");
2414+
break;
23362415
default:
23372416
break;
23382417
}
23392418
}
23402419
else {
23412420
if (flags & S_INPUT)
23422421
M_DrawInstructionString(cr_info_highlight, "Press Enter to Change, Del to Clear");
2422+
else if (flags & S_FUNC)
2423+
M_DrawInstructionString(cr_info_highlight, "Press Enter to Select");
23432424
else
23442425
M_DrawInstructionString(cr_info_highlight, "Press Enter to Change");
23452426
}
@@ -2351,6 +2432,7 @@ static void M_DrawInstructions(void)
23512432
#define FINAL_ENTRY { 0, S_SKIP | S_END, m_null }
23522433
#define EMPTY_LINE { 0, S_SKIP, m_null }
23532434
#define NEW_COLUMN { 0, S_SKIP | S_RESET_Y, m_null }
2435+
#define FUNCTION(action_name, flags, offset_x, action_func) { action_name, !flags ? (S_FUNC) : (S_FUNC | flags), m_null, offset_x, .action = action_func }
23542436

23552437
static void M_EnterSetup(menu_t *menu, dboolean *setup_flag, setup_menu_t *setup_menu)
23562438
{
@@ -4894,6 +4976,22 @@ static dboolean M_SetupCommonSelectResponder(int ch, int action, event_t* ev)
48944976
return true;
48954977
}
48964978

4979+
if (ptr1->m_flags & S_FUNC && action == MENU_ENTER)
4980+
{
4981+
if (M_ItemDisabled(ptr1))
4982+
{
4983+
S_StartVoidSound(g_sfx_oof);
4984+
return true;
4985+
}
4986+
else if (ptr1->action)
4987+
{
4988+
ptr1->action();
4989+
}
4990+
4991+
M_SelectDone(ptr1);
4992+
return true;
4993+
}
4994+
48974995
if (ptr1->m_flags & (S_NUM | S_CRITEM)) // number?
48984996
{
48994997
if (setup_gather) { // gathering keys for a value?
@@ -5098,7 +5196,7 @@ static dboolean M_SetupNavigationResponder(int ch, int action, event_t* ev)
50985196
{
50995197
int flags = ptr1->m_flags;
51005198

5101-
if (dsda_StrictMode() && dsda_IsStrictConfig(ptr1->config_id))
5199+
if (M_ItemDisabled(ptr1))
51025200
return true;
51035201

51045202
// You've selected an item to change. Highlight it, post a new
@@ -5234,7 +5332,7 @@ static dboolean M_SetupResponder(int ch, int action, event_t* ev)
52345332
return true;
52355333

52365334
// killough 10/98: consolidate handling into one place:
5237-
if (set_general_active || set_demos_active || set_display_active)
5335+
if (set_general_active || set_demos_active || set_display_active || set_compatibility_active)
52385336
if (M_StringResponder(ch, action, ev))
52395337
return true;
52405338

@@ -6166,30 +6264,22 @@ void M_Drawer (void)
61666264
if (
61676265
currentMenu->menuitems[i].status != -1 && (
61686266
!currentMenu->menuitems[i].name[0] || !W_LumpNameExists(currentMenu->menuitems[i].name)
6169-
)
6267+
) && !(currentMenu->menuitems[i].flags & MENUF_OPTLUMP)
61706268
)
61716269
++lumps_missing;
61726270

6173-
if (!lumps_missing)
6174-
for (i = 0; i < max; i++)
6175-
{
6176-
if (currentMenu->menuitems[i].name[0])
6177-
V_DrawNamePatch(x, y, 0, currentMenu->menuitems[i].name,
6178-
currentMenu->menuitems[i].color, VPT_STRETCH);
6179-
6180-
y += LINEHEIGHT;
6181-
}
6182-
else
6183-
for (i = 0; i < max; i++)
6184-
{
6185-
const char *alttext = currentMenu->menuitems[i].alttext;
6186-
6187-
if (alttext)
6188-
M_WriteText(x, y + 8 - (M_StringHeight(alttext) / 2),
6189-
alttext, currentMenu->menuitems[i].color);
6190-
6191-
y += LINEHEIGHT;
6192-
}
6271+
for (i = 0; i < max; i++)
6272+
{
6273+
const char *alttext = currentMenu->menuitems[i].alttext;
6274+
if (!lumps_missing && currentMenu->menuitems[i].name[0] &&
6275+
!(currentMenu->menuitems[i].flags & MENUF_OPTLUMP))
6276+
V_DrawNamePatch(x, y, 0, currentMenu->menuitems[i].name,
6277+
currentMenu->menuitems[i].color, VPT_STRETCH);
6278+
else if (alttext)
6279+
M_WriteText(x, y + 8 - (M_StringHeight(alttext) / 2),
6280+
alttext, currentMenu->menuitems[i].color);
6281+
y += LINEHEIGHT;
6282+
}
61936283

61946284
// DRAW SKULL
61956285
if (max > 0)

prboom2/src/m_menu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ typedef struct setup_menu_s
127127
int input; // composite input identifier
128128
const char **selectstrings; /* list of strings for choice value */
129129
struct setup_menu_s *menu; /* next or prev menu */
130+
void (*action)(void); // killough 10/98: function to call after changing
130131
} setup_menu_t;
131132

132133
//
@@ -145,9 +146,11 @@ typedef struct
145146
char alphaKey; // hotkey in menu
146147
const char *alttext;
147148
int color;
149+
byte flags;
148150
} menuitem_t;
149151

150152
#define MENUF_TEXTINPUT 0x01
153+
#define MENUF_OPTLUMP 0x02 // make graphic lump optional
151154

152155
typedef struct menu_s
153156
{

0 commit comments

Comments
 (0)