Skip to content

Commit

Permalink
Keep menu cursors central to the item they're trying to indicate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpoike committed Apr 17, 2023
1 parent a5232cf commit 4d06516
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
31 changes: 17 additions & 14 deletions engine/client/m_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static qboolean M_MouseMoved(emenu_t *menu)
{
menu->selecteditem = option;
if (menu->cursoritem)
menu->cursoritem->common.posy = menu->selecteditem->common.posy;
menu->cursoritem->common.posy = menu->selecteditem->common.posy + (menu->selecteditem->common.height-menu->cursoritem->common.height)/2;
}
menu->tooltiptime = realtime + 1;
MenuTooltipChange(menu, menu->mouseitem->common.tooltip);
Expand Down Expand Up @@ -765,7 +765,7 @@ static void MenuDrawItems(int xpos, int ypos, menuoption_t *option, emenu_t *men
int y = ypos+option->common.posy;

if (!option->edit.slim)
y += (16-8)/2; //fat ones are twice the height on account of the text box's borders.
y += (option->common.height-8)/2; //fat ones are twice the height on account of the text box's borders.

Draw_FunStringWidth(x, y, option->edit.caption, option->edit.captionwidth, true, !menu->cursoritem && menu->selecteditem == option);
x += option->edit.captionwidth + 3*8;
Expand Down Expand Up @@ -923,6 +923,7 @@ menutext_t *MC_AddWhiteText(emenu_t *menu, int lhs, int rhs, int y, const char *
n->common.posx = lhs;
n->common.posy = y;
n->common.width = (rhs)?rhs-lhs:0;
n->common.height = 8;
n->rightalign = rightalign;
if (text)
{
Expand Down Expand Up @@ -1068,15 +1069,19 @@ menupicture_t *MC_AddCenterPicture(emenu_t *menu, int y, int height, char *picna
return MC_AddPicture(menu, x, y, width, height, picname);
}

menuoption_t *MC_AddCursorSmall(emenu_t *menu, menuresel_t *reselection, int x, int y)
menuoption_t *MC_AddCursorSmall(emenu_t *menu, menuresel_t *reselection, int x)
{
menuoption_t *n = Z_Malloc(sizeof(menucommon_t));
if (reselection)
menu->reselection = reselection;
n->common.type = mt_menucursor;
n->common.iszone = true;
n->common.posx = x;
n->common.posy = y;
n->common.height = 8;
if (!menu->selecteditem)
n->common.posy = -8;
else
n->common.posy = menu->selecteditem->common.posy + (menu->selecteditem->common.height-n->common.height)/2;

n->common.next = menu->options;
menu->options = (menuoption_t *)n;
Expand All @@ -1090,7 +1095,7 @@ menuoption_t *MC_AddCursorSmall(emenu_t *menu, menuresel_t *reselection, int x,
if (sel->common.posx == menu->reselection->x && sel->common.posy == menu->reselection->y)
{
menu->selecteditem = sel;
n->common.posy = sel->common.posy;
n->common.posy = sel->common.posy + (sel->common.height-n->common.height)/2;
break;
}
sel = M_NextSelectableItem(menu, sel, false);
Expand Down Expand Up @@ -1182,7 +1187,7 @@ menuedit_t *MC_AddEdit(emenu_t *menu, int cx, int ex, int y, char *text, char *d
n->common.posx = cx;
n->common.posy = y;
n->common.width = ex-cx+(17)*8;
n->common.height = n->slim?8:16;
n->common.height = 8 + (n->slim?0:(8*2)); //the 8bit artwork has 8*8 borders - only 4 pixels of that contains any actual data, but replacement images don't stick to that. so just treat them as the full +/- 8 extents here.
n->modified = true;
n->captionwidth = ex-cx;
n->caption = (char *)(n+1);
Expand Down Expand Up @@ -2154,7 +2159,7 @@ void M_Complex_Key(emenu_t *currentmenu, int key, int unicode)
S_LocalSound ("misc/menu1.wav");

if (currentmenu->cursoritem)
currentmenu->cursoritem->common.posy = currentmenu->selecteditem->common.posy;
currentmenu->cursoritem->common.posy = currentmenu->selecteditem->common.posy + (currentmenu->selecteditem->common.height-currentmenu->cursoritem->common.height)/2;
}
break;

Expand Down Expand Up @@ -2191,7 +2196,7 @@ void M_Complex_Key(emenu_t *currentmenu, int key, int unicode)
{
currentmenu->selecteditem = currentmenu->mouseitem;
if (currentmenu->cursoritem)
currentmenu->cursoritem->common.posy = currentmenu->selecteditem->common.posy;
currentmenu->cursoritem->common.posy = currentmenu->selecteditem->common.posy + (currentmenu->selecteditem->common.height-currentmenu->cursoritem->common.height)/2;
break;
}
else if (key == K_MWHEELUP)
Expand Down Expand Up @@ -2220,7 +2225,7 @@ void M_Complex_Key(emenu_t *currentmenu, int key, int unicode)
S_LocalSound ("misc/menu1.wav");

if (currentmenu->cursoritem)
currentmenu->cursoritem->common.posy = currentmenu->selecteditem->common.posy;
currentmenu->cursoritem->common.posy = currentmenu->selecteditem->common.posy + (currentmenu->selecteditem->common.height-currentmenu->cursoritem->common.height)/2;
break; //require a double-click when selecting...
}
//fall through
Expand Down Expand Up @@ -2621,13 +2626,13 @@ void M_Menu_Main_f (void)
if (b)
{
mainm->selecteditem = (menuoption_t*)b;
mainm->cursoritem->common.posy = mainm->selecteditem->common.posy;
mainm->cursoritem->common.posy = mainm->selecteditem->common.posy + (mainm->selecteditem->common.height-mainm->cursoritem->common.height)/2;
}
}

int MC_AddBulk(struct emenu_s *menu, menuresel_t *resel, menubulk_t *bulk, int xstart, int xtextend, int y)
{
int selectedy = y, last_y = y;
int last_y = y;
menuoption_t *selected = NULL;

while (bulk)
Expand Down Expand Up @@ -2755,9 +2760,7 @@ int MC_AddBulk(struct emenu_s *menu, menuresel_t *resel, menubulk_t *bulk, int x
}

menu->selecteditem = selected;
if (selected)
selectedy = selected->common.posy;
menu->cursoritem = (menuoption_t*)MC_AddCursorSmall(menu, resel, xtextend + 8, selectedy);
menu->cursoritem = (menuoption_t*)MC_AddCursorSmall(menu, resel, xtextend + 8);
return y;
}
#endif
26 changes: 16 additions & 10 deletions engine/client/m_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ void M_Menu_Setup_f (void)
menucustom_t *ci;
menubutton_t *b;
static menuresel_t resel;
int y;

#ifdef Q2CLIENT
if (M_GameType() == MGT_QUAKE2) //quake2 main menu.
Expand Down Expand Up @@ -469,7 +470,7 @@ void M_Menu_Setup_f (void)
cu->draw = MSetupQ2_TransDraw;
cu->key = MSetupQ2_ChangeSkin;

menu->cursoritem = (menuoption_t*)MC_AddCursorSmall(menu, &resel, 54, 32);
menu->cursoritem = (menuoption_t*)MC_AddCursorSmall(menu, &resel, 54);
return;
}
#endif
Expand All @@ -480,9 +481,10 @@ void M_Menu_Setup_f (void)

// MC_AddPicture(menu, 72, 32, Draw_CachePic ("gfx/mp_menu.lmp") );

y = 40;
menu->selecteditem = (menuoption_t*)
(info->nameedit = MC_AddEdit(menu, 64, 160, 40, "Your name", name.string));
(info->teamedit = MC_AddEdit(menu, 64, 160, 56, "Your team", team.string));
(info->nameedit = MC_AddEdit(menu, 64, 160, y, "Your name", name.string)); y+= info->nameedit->common.height;
(info->teamedit = MC_AddEdit(menu, 64, 160, y, "Your team", team.string)); y+= info->teamedit->common.height;
#ifdef HEXEN2
info->ticlass = -1;
if (M_GameType() == MGT_HEXEN2)
Expand All @@ -497,29 +499,33 @@ void M_Menu_Setup_f (void)
NULL
};
cvar_t *pc = Cvar_Get("cl_playerclass", "1", CVAR_USERINFO|CVAR_ARCHIVE, "Hexen2");
(info->classedit = MC_AddCombo(menu, 64, 160, 72, "Your class", (const char **)classnames, pc->ival-1));
(info->classedit = MC_AddCombo(menu, 64, 160, y, "Your class", (const char **)classnames, pc->ival-1)); y+= info->classedit->common.height;
}
else
#endif
{
MC_AddPicture(menu, 16, 4, 32, 144, "gfx/qplaque.lmp");
MC_AddCenterPicture(menu, 4, 24, "gfx/p_multi.lmp");

(info->skinedit = MC_AddEdit(menu, 64, 160, 72, "Your skin", skin.string));
(info->skinedit = MC_AddEdit(menu, 64, 160, y, "Your skin", skin.string)); y+= info->skinedit->common.height;
}

ci = MC_AddCustom(menu, 172+32, 88, NULL, 0, NULL);
ci = MC_AddCustom(menu, 172+32, y, NULL, 0, NULL);
ci->draw = MSetup_TransDraw;
ci->key = NULL;

MC_AddCommand(menu, 64, 160, 96, "Top colour", SetupMenuColour);
MC_AddCommand(menu, 64, 160, 120, "Lower colour", SetupMenuColour);
MC_AddCommand(menu, 64, 160, y+8, "Top colour", SetupMenuColour);
MC_AddCommand(menu, 64, 160, y+32, "Lower colour", SetupMenuColour);
y+= 16;
y+=4;

b = MC_AddConsoleCommand(menu, 64, 204, 168, "Network Settings", "menu_network\n");
b->common.tooltip = "Change network and client prediction settings.";
y += b->common.height;
b = MC_AddConsoleCommand(menu, 64, 204, 176, "Teamplay Settings", "menu_teamplay\n");
b->common.tooltip = "Change teamplay macro settings.";
menu->cursoritem = (menuoption_t*)MC_AddCursorSmall(menu, &resel, 54, 32);
y += b->common.height;
menu->cursoritem = (menuoption_t*)MC_AddCursorSmall(menu, &resel, 54);


info->lowercolour = bottomcolor.value;
Expand Down Expand Up @@ -766,7 +772,7 @@ void M_Menu_GameOptions_f (void)
MC_AddCommand (menu, 64, 160, y, "Start game", MultiBeginGame);y+=16;

y+=4;
info->hostnameedit = MC_AddEdit (menu, 64, 160, y, "Hostname", name.string);y+=16;
info->hostnameedit = MC_AddEdit (menu, 64, 160, y, "Hostname", name.string);y+=info->hostnameedit->common.height;
info->publicgame = MC_AddCombo (menu, 64, 160, y, "Public", publicoptions, bound(0, sv_public.ival+1, 4));y+=8;
y+=4;

Expand Down
25 changes: 14 additions & 11 deletions engine/client/m_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,20 @@ void M_Menu_Options_f (void)
MC_AddFrameEnd(menu, framey);

menu->predraw = M_Options_Predraw;
o = NULL;
if (!o && !m_preset_chosen.ival)
o = M_FindButton(menu, "fps_preset\n");
if (!resel.x)
{
o = NULL;
if (!o && !m_preset_chosen.ival)
o = M_FindButton(menu, "fps_preset\n");
#ifdef PACKAGEMANAGER
if (!o && PM_AreSourcesNew(false))
o = M_FindButton(menu, "menu_download\n");
if (!o && PM_AreSourcesNew(false))
o = M_FindButton(menu, "menu_download\n");
#endif
if (o)
{
menu->selecteditem = (menuoption_t*)o;
menu->cursoritem->common.posy = o->common.posy;
if (o)
{
menu->selecteditem = (menuoption_t*)o;
menu->cursoritem->common.posy = o->common.posy + (o->common.height-menu->cursoritem->common.height)/2;
}
}
}

Expand Down Expand Up @@ -1344,7 +1347,7 @@ static void M_Menu_Preset_Predraw(emenu_t *menu)
}
}
M_Menu_ApplyGravity(menu->options);
menu->cursoritem->common.posy = menu->selecteditem->common.posy; //make sure it shows the right place still
menu->cursoritem->common.posy = menu->selecteditem->common.posy + (menu->selecteditem->common.height-menu->cursoritem->common.height)/2;

if (forcereload)
Cbuf_InsertText("\nfs_restart\nvid_reload\n", RESTRICT_LOCAL, true);
Expand Down Expand Up @@ -1427,7 +1430,7 @@ void M_Menu_Preset_f (void)
if (presetoption[item])
{
menu->selecteditem = presetoption[item];
menu->cursoritem->common.posy = menu->selecteditem->common.posy;
menu->cursoritem->common.posy = menu->selecteditem->common.posy + (menu->selecteditem->common.height-menu->cursoritem->common.height)/2;
}

//so they can actually see the preset they're picking.
Expand Down
2 changes: 1 addition & 1 deletion engine/client/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ menupicture_t *MC_AddPicture(emenu_t *menu, int x, int y, int width, int height,
menupicture_t *MC_AddSelectablePicture(emenu_t *menu, int x, int y, int height, char *picname);
menupicture_t *MC_AddCenterPicture(emenu_t *menu, int y, int height, char *picname);
menupicture_t *MC_AddCursor(emenu_t *menu, menuresel_t *resel, int x, int y);
menuoption_t *MC_AddCursorSmall(emenu_t *menu, menuresel_t *reselection, int x, int y);
menuoption_t *MC_AddCursorSmall(emenu_t *menu, menuresel_t *reselection, int x);
menuslider_t *MC_AddSlider(emenu_t *menu, int tx, int sx, int y, const char *text, cvar_t *var, float min, float max, float delta);
menucheck_t *MC_AddCheckBox(emenu_t *menu, int tx, int cx, int y, const char *text, cvar_t *var, int cvarbitmask);
menucheck_t *MC_AddCheckBoxFunc(emenu_t *menu, int tx, int cx, int y, const char *text, qboolean (*func) (menucheck_t *option, emenu_t *menu, chk_set_t set), int bits);
Expand Down

0 comments on commit 4d06516

Please sign in to comment.