From d39708f043c28141f00cf4d9cf720b4e43dbf075 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 10 May 2014 17:26:41 +0000 Subject: [PATCH] tweak the binds menu. adding spacers, titles, and tooltips. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4653 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/m_items.c | 21 ++++++++++++--------- engine/client/m_script.c | 2 +- engine/client/menu.c | 16 +++++++++++++--- engine/client/menu.h | 2 +- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/engine/client/m_items.c b/engine/client/m_items.c index 00fcbf11..a483ba9d 100644 --- a/engine/client/m_items.c +++ b/engine/client/m_items.c @@ -665,16 +665,14 @@ static void MenuDraw(menu_t *menu) menutext_t *MC_AddWhiteText(menu_t *menu, int lhs, int rhs, int y, const char *text, qboolean rightalign) { - menutext_t *n = Z_Malloc(sizeof(menutext_t)); + menutext_t *n = Z_Malloc(sizeof(menutext_t) + (text?strlen(text):0)+1); n->common.type = mt_text; n->common.iszone = true; n->common.posx = lhs; n->common.posy = y; - n->common.width = rhs?rhs-lhs:0; - n->text = text; - - if (rightalign && text) - n->common.posx -= strlen(text)*8; + n->common.width = (rhs && rightalign)?rhs-lhs:0; + n->text = (char*)(n+1); + strcpy((char*)(n+1), (text?text:"")); n->common.next = menu->options; menu->options = (menuoption_t *)n; @@ -704,14 +702,14 @@ menutext_t *MC_AddBufferedText(menu_t *menu, int lhs, int rhs, int y, const char menutext_t *MC_AddRedText(menu_t *menu, int lhs, int rhs, int y, const char *text, qboolean rightalign) { menutext_t *n; - n = MC_AddWhiteText(menu, lhs, rhs, y, text, false); + n = MC_AddWhiteText(menu, lhs, rhs, y, text, rightalign); n->isred = true; return n; } -menubind_t *MC_AddBind(menu_t *menu, int cx, int bx, int y, const char *caption, char *command) +menubind_t *MC_AddBind(menu_t *menu, int cx, int bx, int y, const char *caption, char *command, char *tooltip) { - menubind_t *n = Z_Malloc(sizeof(*n) + strlen(caption)+1 + strlen(command)+1); + menubind_t *n = Z_Malloc(sizeof(*n) + strlen(caption)+1 + strlen(command)+1 + (tooltip?strlen(tooltip)+1:0)); n->common.type = mt_bind; n->common.iszone = true; n->common.posx = cx; @@ -721,6 +719,11 @@ menubind_t *MC_AddBind(menu_t *menu, int cx, int bx, int y, const char *caption, strcpy(n->caption, caption); n->command = n->caption+strlen(n->caption)+1; strcpy(n->command, command); + if (tooltip) + { + n->common.tooltip = n->command+strlen(n->command)+1; + strcpy(n->common.tooltip, tooltip); + } n->common.width = n->captionwidth + 64; n->common.height = 8; diff --git a/engine/client/m_script.c b/engine/client/m_script.c index cbc4031c..f35b673d 100644 --- a/engine/client/m_script.c +++ b/engine/client/m_script.c @@ -291,7 +291,7 @@ void M_MenuS_Bind_f (void) if (!*caption) caption = command; - MC_AddBind(menu_script, x, x+160, y, command, caption); + MC_AddBind(menu_script, x, x+160, y, command, caption, NULL); } void M_MenuS_Comboi_f (void) diff --git a/engine/client/menu.c b/engine/client/menu.c index 53e0c4ed..23819870 100644 --- a/engine/client/menu.c +++ b/engine/client/menu.c @@ -435,9 +435,19 @@ void M_Menu_Keys_f (void) char line[1024]; while(VFS_GETS(bindslist, line, sizeof(line))) { + char *cmd, *desc, *tip; Cmd_TokenizeString(line, false, false); - MC_AddBind(menu, 16, 170, y, Cmd_Argv(1), Cmd_Argv(0)); - y += 8; + cmd = Cmd_Argv(0); + desc = Cmd_Argv(1); + tip = Cmd_Argv(2); + if (*cmd) + { + if (strcmp(cmd, "-")) //lines with a command of "-" are spacers/comments. + MC_AddBind(menu, (320-(int)vid.width)/2, 170, y, desc, cmd, tip); + else if (*desc) + MC_AddRedText(menu, (320-(int)vid.width)/2, 170, y, desc, true); + y += 8; + } } VFS_CLOSE(bindslist); return; @@ -445,7 +455,7 @@ void M_Menu_Keys_f (void) while (bindnames->name) { - MC_AddBind(menu, 16, 170, y, bindnames->name, bindnames->command); + MC_AddBind(menu, 16, 170, y, bindnames->name, bindnames->command, NULL); y += 8; bindnames++; diff --git a/engine/client/menu.h b/engine/client/menu.h index 2aacc79b..81ee7957 100644 --- a/engine/client/menu.h +++ b/engine/client/menu.h @@ -293,7 +293,7 @@ typedef struct menu_s { menutext_t *MC_AddBufferedText(menu_t *menu, int lhs, int rhs, int y, const char *text, qboolean rightalign, qboolean red); menutext_t *MC_AddRedText(menu_t *menu, int lhs, int rhs, int y, const char *text, qboolean rightalign); menutext_t *MC_AddWhiteText(menu_t *menu, int lhs, int rhs, int y, const char *text, qboolean rightalign); -menubind_t *MC_AddBind(menu_t *menu, int cx, int bx, int y, const char *caption, char *command); +menubind_t *MC_AddBind(menu_t *menu, int cx, int bx, int y, const char *caption, char *command, char *tooltip); menubox_t *MC_AddBox(menu_t *menu, int x, int y, int width, int height); menupicture_t *MC_AddPicture(menu_t *menu, int x, int y, int width, int height, char *picname); menupicture_t *MC_AddSelectablePicture(menu_t *menu, int x, int y, char *picname);