Keep menu cursors central to the item they're trying to indicate.

This commit is contained in:
Shpoike 2023-02-20 08:21:56 +00:00
parent a5232cfecd
commit 4d06516fb2
4 changed files with 49 additions and 37 deletions

View file

@ -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);
@ -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;
@ -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)
{
@ -1068,7 +1069,7 @@ 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)
@ -1076,7 +1077,11 @@ menuoption_t *MC_AddCursorSmall(emenu_t *menu, menuresel_t *reselection, int x,
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;
@ -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);
@ -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);
@ -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;
@ -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)
@ -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
@ -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)
@ -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

View file

@ -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.
@ -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
@ -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)
@ -497,7 +499,7 @@ 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
@ -505,21 +507,25 @@ void M_Menu_Setup_f (void)
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;
@ -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;

View file

@ -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");
#ifdef PACKAGEMANAGER
if (!o && PM_AreSourcesNew(false))
o = M_FindButton(menu, "menu_download\n");
#endif
if (o)
if (!resel.x)
{
menu->selecteditem = (menuoption_t*)o;
menu->cursoritem->common.posy = o->common.posy;
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");
#endif
if (o)
{
menu->selecteditem = (menuoption_t*)o;
menu->cursoritem->common.posy = o->common.posy + (o->common.height-menu->cursoritem->common.height)/2;
}
}
}
@ -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);
@ -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.

View file

@ -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);