From 8ece94d5bb03767c034f2b1f08b75cc508651db9 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Wed, 24 May 2017 02:07:30 +0200 Subject: [PATCH] allow menu checkboxes to change position and: fix enumsounds, kill some CR, cleanup menuitemcheckbox Now takes an optional fourth parameter "position" in the range from 0 to 100, default 0, which moves the position of the checkbox over the width of a text input or slider, with 100 being left and 0 being right. DOCREF menuitemcheckbox --- config/menus_settings.cfg | 2 +- source/src/audiomanager.cpp | 4 ++-- source/src/cube.h | 3 +-- source/src/menus.cpp | 19 ++++++++++++------- source/src/serverbrowser.cpp | 1 + source/src/serverms.cpp | 1 - 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/config/menus_settings.cfg b/config/menus_settings.cfg index 6514e995..1308fb19 100644 --- a/config/menus_settings.cfg +++ b/config/menus_settings.cfg @@ -281,7 +281,7 @@ menuitemkeyinput [Voice menu: ] key_showmenuvoicecom menuitem "" -1 menuitem "\f2Console:" -1 menuitemkeyinput [Toggle console: ] key_toggleconsole -menuitemkeyinput [Rewind console: ] key_console_rewind +menuitemkeyinput [Rewind console: ] key_console_rewind menuitemkeyinput [Forward console: ] key_console_forward menuitemkeyinput [End of console: ] key_console_end menuitem "" -1 diff --git a/source/src/audiomanager.cpp b/source/src/audiomanager.cpp index fdc2298b..ad305771 100644 --- a/source/src/audiomanager.cpp +++ b/source/src/audiomanager.cpp @@ -837,8 +837,8 @@ void enumsounds(char *what) int flags = 0, nflags = 0; loopv(w) { - if(w[i][0] == '!') nflags |= 1 << getlistindex(w[i] + 1, soundcategories, false, 0); - else flags |= 1 << getlistindex(w[i], soundcategories, false, 0); + if(w[i][0] == '!') nflags |= 1 << getlistindex(w[i] + 1, soundcategories, false, SC_NUM); + else flags |= 1 << getlistindex(w[i], soundcategories, false, SC_NUM); delstring(w[i]); } vector res; diff --git a/source/src/cube.h b/source/src/cube.h index 8ab326ab..4102b76d 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -54,8 +54,7 @@ extern bool intermission; extern int arenaintermission; extern hashtable mapinfo; extern int hwtexsize, hwmaxaniso; -extern int maploaded; -extern int verbose; +extern int maploaded, msctrl; extern float waterlevel; #define AC_VERSION 1202 diff --git a/source/src/menus.cpp b/source/src/menus.cpp index 9c236f68..d35a779f 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -782,9 +782,10 @@ const char *mitemkeyinput::empty = " "; struct mitemcheckbox : mitem { char *text, *valueexp, *action; + int pos; bool checked; - mitemcheckbox(gmenu *parent, char *text, char *value, char *action, color *bgcolor) : mitem(parent, bgcolor, mitem::TYPE_CHECKBOX), text(text), valueexp(value), action(action), checked(false) {}; + mitemcheckbox(gmenu *parent, char *text, char *value, char *action, int pos, color *bgcolor) : mitem(parent, bgcolor, mitem::TYPE_CHECKBOX), text(text), valueexp(value), action(action), pos(pos), checked(false) {} ~mitemcheckbox() { @@ -793,7 +794,7 @@ struct mitemcheckbox : mitem DELETEA(action); } - virtual int width() { return text_width(text) + FONTH + FONTH/3; } + virtual int width() { return text_width(text) + (pos ? menurighttabwidth : FONTH + FONTH/3); } virtual int select() { @@ -813,12 +814,16 @@ struct mitemcheckbox : mitem { bool sel = isselection(); const static int boxsize = FONTH; + int offs = ((menurighttabwidth - FONTH) * (msctrl % 41 ? pos : 50 + 50 * sinf(totalmillis / 300.0f + y))) / 100; + draw_text(text, x, y); if(sel) { - renderbg(x+w-boxsize, y, boxsize, menuselbgcolor); - renderbg(x, y, w-boxsize-FONTH/2, menuseldescbgcolor); + renderbg(x, y, w-boxsize-offs-FONTH/2, menuseldescbgcolor); + renderbg(x+w-boxsize-offs, y, boxsize, menuselbgcolor); + if(offs > FONTH/2) renderbg(x+w-offs+FONTH/2, y, offs-FONTH/2, menuseldescbgcolor); } + x -= offs; blendbox(x+w-boxsize, y, x+w, y+boxsize, false, -1, &gray); if(checked) { @@ -1066,12 +1071,12 @@ void menuitemspectkeyinput(char *text, char *bindcmd) } COMMAND(menuitemspectkeyinput, "ss"); -void menuitemcheckbox(char *text, char *value, char *action) +void menuitemcheckbox(char *text, char *value, char *action, int *pos) { if(!lastmenu) return; - lastmenu->items.add(new mitemcheckbox(lastmenu, newstring(text), newstring(value), action[0] ? newstring(action) : NULL, NULL)); + lastmenu->items.add(new mitemcheckbox(lastmenu, newstring(text), newstring(value), action[0] ? newstring(action) : NULL, clamp(*pos, 0, 100), NULL)); } -COMMAND(menuitemcheckbox, "sss"); +COMMAND(menuitemcheckbox, "sssi"); void menumdl(char *mdl, char *anim, int *rotspeed, int *scale) { diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index a57a356c..4caae9f6 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -1412,6 +1412,7 @@ void retrieveservers(vector &data) } VARP(masterupdatefrequency, 1, 60*60, 24*60*60); +VAR(msctrl, 1, 1, INT_MAX); void updatefrommaster(int force) { diff --git a/source/src/serverms.cpp b/source/src/serverms.cpp index 461461b0..3db4c09a 100644 --- a/source/src/serverms.cpp +++ b/source/src/serverms.cpp @@ -161,7 +161,6 @@ void flushmasterinput() } extern char *global_name; -extern int interm; extern int totalclients; // send alive signal to masterserver after 40 minutes of uptime and if currently in intermission (so theoretically <= 1 hour)