Skip to content

Commit be974ca

Browse files
committed
Menu Pre-Setup
1 parent 70db526 commit be974ca

File tree

2 files changed

+136
-65
lines changed

2 files changed

+136
-65
lines changed

prboom2/src/m_menu.c

Lines changed: 133 additions & 65 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

@@ -757,6 +757,7 @@ void M_ChooseSkill(int choice)
757757
message = s_NIGHTMARE; // Ty 03/27/98 - externalized
758758

759759
M_StartMessage(message, M_VerifySkill, true);
760+
M_SetupNextMenu(&ReadDef1); // Clear in-menu variables when "no" or "ESC"
760761

761762
return;
762763
}
@@ -1656,6 +1657,22 @@ 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+
return true;
1666+
1667+
return false;
1668+
}
1669+
1670+
static void M_BlinkingArrowRight(const setup_menu_t *s)
1671+
{
1672+
if (M_ItemSelected(s) && !setup_select)
1673+
strcat(menu_buffer, " <");
1674+
}
1675+
16591676
static void M_UpdateSetupMenu(setup_menu_t *new_setup_menu)
16601677
{
16611678
current_setup_menu = new_setup_menu;
@@ -1797,6 +1814,48 @@ static int entry_index;
17971814
static char entry_string_index[ENTRY_STRING_BFR_SIZE]; // points to new strings while editing
17981815
static int choice_value;
17991816

1817+
/////////////////////////////
1818+
//
1819+
// M_ItemDisabled
1820+
//
1821+
// Disable certain menu options based on various conditions:
1822+
// StrictMode, Complevel, and more!
1823+
//
1824+
//
1825+
1826+
static dboolean M_ItemDisabled(const setup_menu_t* s)
1827+
{
1828+
// Strict Mode
1829+
if (dsda_StrictMode() && dsda_IsStrictConfig(s->config_id))
1830+
return true;
1831+
1832+
return false;
1833+
}
1834+
1835+
/////////////////////////////
1836+
//
1837+
// Menu Text Colors
1838+
//
1839+
//
1840+
1841+
static int GetItemColor(int flags)
1842+
{
1843+
return (flags & S_TITLE && flags & S_DISABLED) ? cr_title + CR_DARKEN :
1844+
flags & S_DISABLED ? cr_label + CR_DARKEN :
1845+
flags & (S_SELECT|S_TC_SEL) ? cr_label_edit :
1846+
flags & S_HILITE ? cr_label_highlight :
1847+
flags & (S_TITLE|S_NEXT|S_PREV) ? cr_title :
1848+
cr_label; // killough 10/98
1849+
}
1850+
1851+
static int GetOptionColor(int flags)
1852+
{
1853+
return flags & S_DISABLED ? cr_value + CR_DARKEN :
1854+
flags & S_SELECT ? cr_value_edit :
1855+
flags & S_HILITE ? cr_value_highlight :
1856+
cr_value;
1857+
}
1858+
18001859
/////////////////////////////
18011860
//
18021861
// phares 4/18/98:
@@ -1810,31 +1869,42 @@ static int choice_value;
18101869
static void M_DrawItem(const setup_menu_t* s, int y)
18111870
{
18121871
int x = s->m_x;
1872+
char text[66];
18131873
int flags = s->m_flags;
18141874
char *p, *t;
18151875
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
1876+
int color;
1877+
1878+
if (M_ItemDisabled(s))
1879+
flags |= S_DISABLED;
1880+
1881+
color = GetItemColor(flags);
1882+
1883+
// Add ". . ." to function
1884+
sprintf(text, "%s%s", s->m_text, (flags & S_FUNC) ? ". . ." : "");
18221885

18231886
/* killough 10/98:
18241887
* Enhance to support multiline text separated by newlines.
18251888
* This supports multiline items on horizontally-crowded menus.
18261889
*/
18271890

1828-
for (p = t = Z_Strdup(s->m_text); (p = strtok(p,"\n")); y += 8, p = NULL)
1891+
for (p = t = Z_Strdup(text); (p = strtok(p,"\n")); y += 8, p = NULL)
18291892
{ /* 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, ">");
1893+
w = M_GetPixelWidth(p);
1894+
1895+
if (!(flags & S_LEFTJUST))
1896+
x -= (w + 4);
1897+
1898+
M_DrawString(x, y, color, p);
1899+
1900+
// print a blinking left "arrow" before highlighted menu item
1901+
if (M_ItemSelected(s))
1902+
M_DrawString(x - 8, y, color, ">");
1903+
1904+
// print a blinking right "arrow" after highlighted function
1905+
if (flags & S_FUNC)
1906+
if (M_ItemSelected(s) && !setup_select)
1907+
M_DrawString(x + w, y, color, " <");
18381908
}
18391909
Z_Free(t);
18401910
}
@@ -1865,19 +1935,17 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
18651935
// Determine color of the text. This may or may not be used later,
18661936
// depending on whether the item is a text string or not.
18671937

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;
1938+
if (M_ItemDisabled(s))
1939+
flags |= S_DISABLED;
1940+
1941+
color = GetOptionColor(flags);
18731942

18741943
// Is the item a YES/NO item?
18751944

18761945
if (flags & S_YESNO) {
18771946
strcpy(menu_buffer, dsda_IntConfig(s->config_id) ? "YES" : "NO");
18781947

1879-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
1880-
strcat(menu_buffer, " <");
1948+
M_BlinkingArrowRight(s);
18811949
M_DrawMenuString(x,y,color);
18821950
return;
18831951
}
@@ -1900,12 +1968,11 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
19001968
if (flags & S_CRITEM)
19011969
{
19021970
color = value;
1903-
if (dsda_StrictMode() && dsda_IsStrictConfig(s->config_id))
1971+
if (M_ItemDisabled(s))
19041972
color += CR_DARKEN;
19051973
}
19061974
}
1907-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
1908-
strcat(menu_buffer, " <");
1975+
M_BlinkingArrowRight(s);
19091976
M_DrawMenuString(x, y, color);
19101977
return;
19111978
}
@@ -1962,9 +2029,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
19622029
if (!any_input)
19632030
M_GetKeyString(0, 0);
19642031

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

19702035
return;
@@ -1991,8 +2056,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
19912056

19922057
if (!ch) // don't show this item in automap mode
19932058
V_DrawNamePatch(x+1,y,0,"M_PALNO", CR_DEFAULT, VPT_STRETCH);
1994-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
1995-
M_DrawString(x + 8, y, color, " <");
2059+
M_BlinkingArrowRight(s);
19962060
return;
19972061
}
19982062

@@ -2049,8 +2113,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
20492113
// Draw the setting for the item
20502114

20512115
strcpy(menu_buffer, text);
2052-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
2053-
strcat(menu_buffer, " <");
2116+
M_BlinkingArrowRight(s);
20542117
M_DrawMenuString(x, y, color);
20552118
return;
20562119
}
@@ -2081,8 +2144,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
20812144
}
20822145
}
20832146

2084-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
2085-
strcat(menu_buffer, " <");
2147+
M_BlinkingArrowRight(s);
20862148
M_DrawMenuString(x,y,color);
20872149
return;
20882150
}
@@ -2092,8 +2154,7 @@ static void M_DrawSetting(const setup_menu_t* s, int y)
20922154

20932155
sprintf(menu_buffer, "%d", dsda_IntConfig(s->config_id));
20942156

2095-
if (s == current_setup_menu + set_menu_itemon && whichSkull && !setup_select)
2096-
strcat(menu_buffer, " <");
2157+
M_BlinkingArrowRight(s);
20972158
M_DrawMenuString(x + 80, y + 3, color);
20982159
return;
20992160
}
@@ -2340,6 +2401,8 @@ static void M_DrawInstructions(void)
23402401
else {
23412402
if (flags & S_INPUT)
23422403
M_DrawInstructionString(cr_info_highlight, "Press Enter to Change, Del to Clear");
2404+
else if (flags & S_FUNC)
2405+
M_DrawInstructionString(cr_info_highlight, "Press Enter to Select");
23432406
else
23442407
M_DrawInstructionString(cr_info_highlight, "Press Enter to Change");
23452408
}
@@ -2351,6 +2414,7 @@ static void M_DrawInstructions(void)
23512414
#define FINAL_ENTRY { 0, S_SKIP | S_END, m_null }
23522415
#define EMPTY_LINE { 0, S_SKIP, m_null }
23532416
#define NEW_COLUMN { 0, S_SKIP | S_RESET_Y, m_null }
2417+
#define FUNCTION(action_name, flags, offset_x, action_func) { action_name, !flags ? (S_FUNC) : (S_FUNC | flags), m_null, offset_x, .action = action_func }
23542418

23552419
static void M_EnterSetup(menu_t *menu, dboolean *setup_flag, setup_menu_t *setup_menu)
23562420
{
@@ -3756,7 +3820,7 @@ static void M_BuildLevelTable(void)
37563820
if (map->best_skill) {
37573821
dsda_StringPrintF(&m_text, "%d", map->best_skill);
37583822
entry->m_text = m_text.string;
3759-
if (map->best_skill == num_skills)
3823+
if (map->best_skill == num_og_skills)
37603824
entry->m_flags |= S_TC_SEL;
37613825
}
37623826
else {
@@ -4875,11 +4939,23 @@ static dboolean M_LevelTableResponder(int ch, int action, event_t* ev)
48754939

48764940
static dboolean M_SetupCommonSelectResponder(int ch, int action, event_t* ev)
48774941
{
4942+
setup_menu_t* ptr1 = current_setup_menu + set_menu_itemon;
4943+
4944+
// Execute functions
4945+
if (ptr1->m_flags & S_FUNC)
4946+
{
4947+
if (action == MENU_ENTER) {
4948+
if (ptr1->action)
4949+
ptr1->action();
4950+
4951+
M_SelectDone(ptr1);
4952+
return true;
4953+
}
4954+
}
4955+
48784956
// changing an entry
48794957
if (setup_select)
48804958
{
4881-
setup_menu_t* ptr1 = current_setup_menu + set_menu_itemon;
4882-
48834959
if (action == MENU_ESCAPE) // Exit key = no change
48844960
{
48854961
M_SelectDone(ptr1); // phares 4/17/98
@@ -5100,7 +5176,7 @@ static dboolean M_SetupNavigationResponder(int ch, int action, event_t* ev)
51005176
{
51015177
int flags = ptr1->m_flags;
51025178

5103-
if (dsda_StrictMode() && dsda_IsStrictConfig(ptr1->config_id))
5179+
if (M_ItemDisabled(ptr1))
51045180
return true;
51055181

51065182
// You've selected an item to change. Highlight it, post a new
@@ -6168,30 +6244,22 @@ void M_Drawer (void)
61686244
if (
61696245
currentMenu->menuitems[i].status != -1 && (
61706246
!currentMenu->menuitems[i].name[0] || !W_LumpNameExists(currentMenu->menuitems[i].name)
6171-
)
6247+
) && !(currentMenu->menuitems[i].flags & MENUF_OPTLUMP)
61726248
)
61736249
++lumps_missing;
61746250

6175-
if (!lumps_missing)
6176-
for (i = 0; i < max; i++)
6177-
{
6178-
if (currentMenu->menuitems[i].name[0])
6179-
V_DrawNamePatch(x, y, 0, currentMenu->menuitems[i].name,
6180-
currentMenu->menuitems[i].color, VPT_STRETCH);
6181-
6182-
y += LINEHEIGHT;
6183-
}
6184-
else
6185-
for (i = 0; i < max; i++)
6186-
{
6187-
const char *alttext = currentMenu->menuitems[i].alttext;
6188-
6189-
if (alttext)
6190-
M_WriteText(x, y + 8 - (M_StringHeight(alttext) / 2),
6191-
alttext, currentMenu->menuitems[i].color);
6192-
6193-
y += LINEHEIGHT;
6194-
}
6251+
for (i = 0; i < max; i++)
6252+
{
6253+
const char *alttext = currentMenu->menuitems[i].alttext;
6254+
if (!lumps_missing && currentMenu->menuitems[i].name[0] &&
6255+
!(currentMenu->menuitems[i].flags & MENUF_OPTLUMP))
6256+
V_DrawNamePatch(x, y, 0, currentMenu->menuitems[i].name,
6257+
currentMenu->menuitems[i].color, VPT_STRETCH);
6258+
else if (alttext)
6259+
M_WriteText(x, y + 8 - (M_StringHeight(alttext) / 2),
6260+
alttext, currentMenu->menuitems[i].color);
6261+
y += LINEHEIGHT;
6262+
}
61956263

61966264
// DRAW SKULL
61976265
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)