From adca50e52be01a975835990deda0f1ce8a05dece Mon Sep 17 00:00:00 2001 From: Robin Redeker Date: Sat, 16 Mar 2002 20:22:01 +0000 Subject: [PATCH] Did further working on the menu code. Added a _unfinished_ Player options-submenu, for setting the name, top-/bottomcolor. Added Draw_Fill and such to the progs api. Added some comments. --- cs-code/controls_o.qc | 2 + cs-code/draw_def.qc | 1 + cs-code/inputline_util.qc | 45 ++++++++ cs-code/menu.qc | 54 --------- cs-code/menu.src.in | 2 + cs-code/menu_util.qc | 54 +++++++++ cs-code/options.qc | 173 ++++++++++++++++++++++++++--- cs-code/string_def.qc | 3 + doc/QCMenuCondingStyle | 3 +- libs/gamecode/builtins/bi_string.c | 21 ++++ libs/video/renderer/r_progs.c | 19 ++++ 11 files changed, 304 insertions(+), 73 deletions(-) create mode 100644 cs-code/inputline_util.qc create mode 100644 cs-code/menu_util.qc diff --git a/cs-code/controls_o.qc b/cs-code/controls_o.qc index bb44453be..9b68b6df2 100644 --- a/cs-code/controls_o.qc +++ b/cs-code/controls_o.qc @@ -411,6 +411,8 @@ MENU_control_binding = init_binding_hash (); // init the keybinding hashes load_keybindings (); // load the keybindings into hashes + set_key_flag = 0; + Menu_Begin (54, 60, "Bindings"); Menu_Pic (16, 4, "gfx/qplaque.lmp"); Menu_CenterPic (160, 4, "gfx/p_option.lmp"); diff --git a/cs-code/draw_def.qc b/cs-code/draw_def.qc index 6fba19279..a9ced3f53 100644 --- a/cs-code/draw_def.qc +++ b/cs-code/draw_def.qc @@ -4,3 +4,4 @@ void (integer x, integer y, integer chr) Draw_Character = #0; void (integer x, integer y, string text) Draw_String = #0; void (integer x, integer y, string text, integer n) Draw_nString = #0; void (integer x, integer y, string text) Draw_AltString = #0; +void (integer x, integer y, integer w, integer h, integer c) Draw_Fill = #0; diff --git a/cs-code/inputline_util.qc b/cs-code/inputline_util.qc new file mode 100644 index 000000000..a49d41ad3 --- /dev/null +++ b/cs-code/inputline_util.qc @@ -0,0 +1,45 @@ +/* + inputline_util.qc + + Utilities for the inputline + + Copyright (C) 2002 Robin Redeker + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA +*/ + + +/* + InputLine_SetText + + Inserts characters of a string into + a inputline. +*/ +#ifdef BUG_ELMEX +void (inputline_t il, string str) +InputLine_SetText = +{ + local integer i, charint; + charint = String_GetChar(str,0); + for(i = 0; charint != 0; i++) { + InputLine_Process(il, String_GetChar(str,i)); + charint = String_GetChar(str,i); + } +}; +#endif diff --git a/cs-code/menu.qc b/cs-code/menu.qc index 47d173290..4172c1e7e 100644 --- a/cs-code/menu.qc +++ b/cs-code/menu.qc @@ -3,7 +3,6 @@ float () traceon = #0; string () gametype = #0; string (...) sprintf = #0; -float time; entity self; .float nextthink; .float frame; @@ -11,15 +10,6 @@ entity self; integer do_single_player; -string [6] dot = { - "gfx/menudot1.lmp", - "gfx/menudot2.lmp", - "gfx/menudot3.lmp", - "gfx/menudot4.lmp", - "gfx/menudot5.lmp", - "gfx/menudot6.lmp", -}; - string [32] quitMessage = { /* .........1.........2.... */ " Are you gonna quit ", @@ -64,50 +54,6 @@ string [32] quitMessage = { }; integer quit_index; -void (integer x, integer y) spinner = -{ - Draw_Pic (x, y, dot[integer(time * 10) % 6]); -}; - -void (integer x, integer y, integer width, integer lines) text_box = -{ - local integer cx, cy, n; - local string p; - - cx = x; - cy = y; - Draw_Pic (cx, cy, "gfx/box_tl.lmp"); - for (n = 0; n < lines; n++) { - cy += 8; - Draw_Pic (cx, cy, "gfx/box_ml.lmp"); - } - Draw_Pic (cx, cy + 8, "gfx/box_bl.lmp"); - - cx += 8; - while (width > 0) { - cy = y; - Draw_Pic (cx, cy, "gfx/box_tm.lmp"); - p = "gfx/box_mm.lmp"; - for (n = 0; n < lines; n++) { - cy += 8; - if (n == 1) - p = "gfx/box_mm2.lmp"; - Draw_Pic (cx, cy, p); - } - Draw_Pic (cx, cy + 8, "gfx/box_bm.lmp"); - width -= 2; - cx += 16; - } - - cy = y; - Draw_Pic (cx, cy, "gfx/box_tr.lmp"); - for (n = 0; n < lines; n++) { - cy += 8; - Draw_Pic (cx, cy, "gfx/box_mr.lmp"); - } - Draw_Pic (cx, cy + 8, "gfx/box_br.lmp"); -}; - // ********* LOAD / SAVE #define MAX_SAVEGAMES 12 diff --git a/cs-code/menu.src.in b/cs-code/menu.src.in index 6e7ca00a9..fa14f16d4 100644 --- a/cs-code/menu.src.in +++ b/cs-code/menu.src.in @@ -10,6 +10,8 @@ menu.dat @srcdir@/string_def.qc @srcdir@/stringh_def.qc +@srcdir@/inputline_util.qc +@srcdir@/menu_util.qc @srcdir@/options_util.qc @srcdir@/controls_o.qc diff --git a/cs-code/menu_util.qc b/cs-code/menu_util.qc new file mode 100644 index 000000000..1b421f802 --- /dev/null +++ b/cs-code/menu_util.qc @@ -0,0 +1,54 @@ +float time; + +string [6] dot = { + "gfx/menudot1.lmp", + "gfx/menudot2.lmp", + "gfx/menudot3.lmp", + "gfx/menudot4.lmp", + "gfx/menudot5.lmp", + "gfx/menudot6.lmp", +}; + +void (integer x, integer y) spinner = +{ + Draw_Pic (x, y, dot[integer(time * 10) % 6]); +}; + +void (integer x, integer y, integer width, integer lines) text_box = +{ + local integer cx, cy, n; + local string p; + + cx = x; + cy = y; + Draw_Pic (cx, cy, "gfx/box_tl.lmp"); + for (n = 0; n < lines; n++) { + cy += 8; + Draw_Pic (cx, cy, "gfx/box_ml.lmp"); + } + Draw_Pic (cx, cy + 8, "gfx/box_bl.lmp"); + + cx += 8; + while (width > 0) { + cy = y; + Draw_Pic (cx, cy, "gfx/box_tm.lmp"); + p = "gfx/box_mm.lmp"; + for (n = 0; n < lines; n++) { + cy += 8; + if (n == 1) + p = "gfx/box_mm2.lmp"; + Draw_Pic (cx, cy, p); + } + Draw_Pic (cx, cy + 8, "gfx/box_bm.lmp"); + width -= 2; + cx += 16; + } + + cy = y; + Draw_Pic (cx, cy, "gfx/box_tr.lmp"); + for (n = 0; n < lines; n++) { + cy += 8; + Draw_Pic (cx, cy, "gfx/box_mr.lmp"); + } + Draw_Pic (cx, cy + 8, "gfx/box_br.lmp"); +}; diff --git a/cs-code/options.qc b/cs-code/options.qc index e983411ed..4a11a9c9a 100644 --- a/cs-code/options.qc +++ b/cs-code/options.qc @@ -44,6 +44,10 @@ #define MAX_VOLUME 1.5 #define VOLUME_STEP 0.1 +#define MIN_COLOR 0 +#define MAX_COLOR 13 +#define COLOR_STEP 1 + /**************************** * VIDEO OPTIONS * Video settings menu code @@ -179,6 +183,9 @@ CB_audio_options = { local float volume; + if(!(key == QFK_RIGHT || key == QFK_LEFT )) { + return 0; + } volume = cvar("volume"); volume = min_max_cnt(MIN_VOLUME, MAX_VOLUME, VOLUME_STEP, volume, (key == QFK_RIGHT) && (key != QFK_LEFT)); @@ -424,26 +431,156 @@ MENU_feature_options = Menu_End (); }; + +/*************************************************** + * PLAYER OPTIONS + * Player settings, generally name, team, and color + ***************************************************/ + +// input for playername +string player_config_playername; +inputline_t player_config_plname_il; + +// this holds active inputline pointer +inputline_t player_config_iactive; + +// table for cursor-positions +#define NUM_PLAYERCONFIG_CMDS 3 +integer [NUM_PLAYERCONFIG_CMDS] player_config_cursor_tbl = { 68, 90, 105 }; +integer player_config_cursor; + +// array, which holds commands for this menu +string [NUM_PLAYERCONFIG_CMDS] player_config_vals = { + "", + "topcolor", + "bottomcolor" +}; + + +integer (integer key, integer unicode, integer down) +KEYEV_player_options = +{ + local float colortmp; + + switch (key) { + case QFK_DOWN: + case QFM_WHEEL_DOWN: + if (!player_config_iactive) { + player_config_cursor ++; + player_config_cursor %= NUM_PLAYERCONFIG_CMDS; + } + break; + case QFK_UP: + case QFM_WHEEL_UP: + if (!player_config_iactive) { + player_config_cursor += NUM_PLAYERCONFIG_CMDS - 1; + player_config_cursor %= NUM_PLAYERCONFIG_CMDS; + } + break; + case QFK_RETURN: + if (player_config_iactive) { + player_config_iactive = NIL; + } else { + if (player_config_cursor == 0) { + player_config_iactive = player_config_plname_il; + } + } + break; + } + if(key != QFK_RETURN && player_config_iactive) { + InputLine_Process (player_config_iactive, key >= 256 ? key : unicode); + } + + if(!(key == QFK_RIGHT || key == QFK_LEFT )) { + return 1; + } + + switch (player_config_vals[player_config_cursor]) { + case "topcolor": + colortmp = cvar("topcolor"); + colortmp = min_max_cnt(MIN_COLOR, MAX_COLOR, COLOR_STEP, colortmp, + (key == QFK_RIGHT) && (key != QFK_LEFT)); + cvar_set("topcolor", ftos(colortmp)); + break; + case "bottomcolor": + colortmp = cvar("bottomcolor"); + colortmp = min_max_cnt(MIN_COLOR, MAX_COLOR, COLOR_STEP, colortmp, + (key == QFK_RIGHT) && (key != QFK_LEFT)); + cvar_set("bottomcolor", ftos(colortmp)); + break; + } + + + return 1; +}; + + +/* + DRAW_player_options + + Draws the player option menu +*/ +integer () +DRAW_player_options = +{ + local integer cursor_pad = 0, spacing = 120; +#define PLAYER_CONF_Y_PAD 60 + + Draw_Pic (16, 4, "gfx/qplaque.lmp"); + Draw_CenterPic (160,4, "gfx/p_option.lmp"); + Draw_String (54, 40, "Player"); + Draw_String (54, 50, "--------"); + + + text_box(70, PLAYER_CONF_Y_PAD, 17, 1); + InputLine_Draw (player_config_plname_il, 70, PLAYER_CONF_Y_PAD + 8, + player_config_iactive != NIL); + + + draw_val_item (70, PLAYER_CONF_Y_PAD + 30, spacing, "Top color", + " " + ftos(cvar("topcolor"))); + draw_val_item (70, PLAYER_CONF_Y_PAD + 45, spacing, "Bottom color", + " " + ftos(cvar("bottomcolor"))); + + // Draw nice color boxes + text_box(192, PLAYER_CONF_Y_PAD + 30 - 8, 1, 1); + Draw_Fill (200, PLAYER_CONF_Y_PAD + 30, 16, 8, + ftoi(cvar("topcolor"))*16+8); + + text_box(192, PLAYER_CONF_Y_PAD + 45 - 8, 1, 1); + Draw_Fill (200, PLAYER_CONF_Y_PAD + 45, 16, 8, + ftoi(cvar("bottomcolor"))*16+8); + + opt_cursor (62, player_config_cursor_tbl[player_config_cursor]); + return 1; +}; + + +/* + MENU_player_options + + Makes the player option menu +*/ +void () +MENU_player_options = +{ + player_config_plname_il = InputLine_Create (4, 18, ' '); + InputLine_SetWidth (player_config_plname_il, 18); + player_config_iactive = NIL; + + Menu_Begin (54, 80, "Player"); + Menu_FadeScreen (1); + Menu_KeyEvent (KEYEV_player_options); + Menu_Draw (DRAW_player_options); + Menu_End (); +}; + + /************************* * MAIN OPTIONS * Main options menu code *************************/ -/* - CB_options - - Callback for main options menu -*/ -integer (integer key, integer unicode, integer down) -CB_options = -{ - // pre-loading of the bindings and set_key_flag == 0 - set_key_flag = 0; - - return 0; -}; - - /* MENU_options @@ -458,12 +595,12 @@ MENU_options = Menu_FadeScreen (1); Menu_Pic (16, 4, "gfx/qplaque.lmp"); Menu_CenterPic (160, 4, "gfx/p_option.lmp"); - Menu_KeyEvent (CB_options); MENU_control_options (); - MENU_video_options (); - MENU_audio_options (); + MENU_video_options (); + MENU_audio_options (); MENU_feature_options (); + MENU_player_options (); Menu_End (); }; diff --git a/cs-code/string_def.qc b/cs-code/string_def.qc index de98fc548..f8df3e118 100644 --- a/cs-code/string_def.qc +++ b/cs-code/string_def.qc @@ -1,3 +1,6 @@ string (integer old, integer new, string str) String_ReplaceChar = #0; string (integer pos, integer len, string str) String_Cut = #0; integer (string str) String_Len = #0; +#ifdef BUG_ELMEX +integer (string str, integer pos) String_GetChar = #0; +#endif diff --git a/doc/QCMenuCondingStyle b/doc/QCMenuCondingStyle index 1f524763b..b77c23ca6 100644 --- a/doc/QCMenuCondingStyle +++ b/doc/QCMenuCondingStyle @@ -8,9 +8,10 @@ describes in the file "CodingStyle" in doc/ But you may use not the same prefixes. Use these prefixes where it makes sense: -CB_ Input callback +CB_ Menu_Item callback MENU_ Menu making function DRAW_ Draw +KEYEV_ Keyevent callback Comment functions like this: /* diff --git a/libs/gamecode/builtins/bi_string.c b/libs/gamecode/builtins/bi_string.c index 3ff48e93c..65669ba36 100644 --- a/libs/gamecode/builtins/bi_string.c +++ b/libs/gamecode/builtins/bi_string.c @@ -101,10 +101,31 @@ bi_String_Len (progs_t *pr) G_INT (pr, OFS_RETURN) = strlen(str); } +/* + bi_String_GetChar + + Gives the intervalue of a character in + a string +*/ +static void +bi_String_GetChar (progs_t *pr) +{ + const char *str = G_STRING (pr, OFS_PARM0); + int pos = G_INT (pr, OFS_PARM1); + int ret = 0; + + if(pos > 0 && pos < strlen(str)) { + ret = (int)str[pos]; + } + G_INT (pr, OFS_RETURN) = ret; +} + + void String_Progs_Init (progs_t *pr) { PR_AddBuiltin (pr, "String_ReplaceChar", bi_String_ReplaceChar, -1); PR_AddBuiltin (pr, "String_Cut", bi_String_Cut, -1); PR_AddBuiltin (pr, "String_Len", bi_String_Len, -1); + PR_AddBuiltin (pr, "String_GetChar", bi_String_GetChar, -1); } diff --git a/libs/video/renderer/r_progs.c b/libs/video/renderer/r_progs.c index 8f1186972..ce98b2faa 100644 --- a/libs/video/renderer/r_progs.c +++ b/libs/video/renderer/r_progs.c @@ -107,6 +107,24 @@ bi_Draw_AltString (progs_t *pr) Draw_AltString (x, y, text); } +/* + bi_Draw_Fill + + Draws a filled area with a color + (only a wrapper function to original qf-api) +*/ +static void +bi_Draw_Fill (progs_t *pr) +{ + int x = G_INT (pr, OFS_PARM0); + int y = G_INT (pr, OFS_PARM1); + int w = G_INT (pr, OFS_PARM2); + int h = G_INT (pr, OFS_PARM3); + int color = G_INT (pr, OFS_PARM4); + + Draw_Fill (x, y, w, h, color); +} + void R_Progs_Init (progs_t *pr) { @@ -116,4 +134,5 @@ R_Progs_Init (progs_t *pr) PR_AddBuiltin (pr, "Draw_String", bi_Draw_String, -1); PR_AddBuiltin (pr, "Draw_nString", bi_Draw_nString, -1); PR_AddBuiltin (pr, "Draw_AltString", bi_Draw_AltString, -1); + PR_AddBuiltin (pr, "Draw_Fill", bi_Draw_Fill, -1); }