From 863b4e9bbddf38bbdb30948c6a0a3ca30ef55784 Mon Sep 17 00:00:00 2001 From: Robin Redeker Date: Sat, 16 Mar 2002 00:14:24 +0000 Subject: [PATCH] Improved the menu code a bit, made style cleaner and added some comments to my menu code. --- cs-code/controls_o.qc | 3 + cs-code/menu.qc | 2 +- cs-code/options.qc | 316 +++++++++++++++++++++++++++++----------- cs-code/options_util.qc | 122 +++++++++++++--- doc/QCMenuCondingStyle | 2 +- 5 files changed, 340 insertions(+), 105 deletions(-) diff --git a/cs-code/controls_o.qc b/cs-code/controls_o.qc index 46e8d0bd6..9a59d54e4 100644 --- a/cs-code/controls_o.qc +++ b/cs-code/controls_o.qc @@ -25,6 +25,7 @@ string [NUM_BINDED_KEYS] key_bindings = "messagemode", "screenshot", #define NUM_MISC_KEYS NUM_BASIC_KEYS + 4 + "impulse 0", "impulse 1", "impulse 2", "impulse 3", @@ -69,6 +70,8 @@ void () load_keybindings = } }; +//**** BINDINGS OPTIONS + integer (string text, integer key) control_bind_f = { local string binding; diff --git a/cs-code/menu.qc b/cs-code/menu.qc index 29663a448..47d173290 100644 --- a/cs-code/menu.qc +++ b/cs-code/menu.qc @@ -480,7 +480,7 @@ void () main_menu = default: break; } - options_menu (); + MENU_options (); help_menu (); Menu_Item (54, 112, "", quit_f, 0); Menu_End (); diff --git a/cs-code/options.qc b/cs-code/options.qc index e5449b304..a666ef8ad 100644 --- a/cs-code/options.qc +++ b/cs-code/options.qc @@ -1,3 +1,33 @@ +/* + options.qc + + Options menu + + 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 +*/ + +/* + some definitions of border values for + different things +*/ #define MIN_GAMMA 0.4 #define MAX_GAMMA 3 #define GAMMA_STEP 0.1 @@ -14,9 +44,19 @@ #define MAX_VOLUME 1.5 #define VOLUME_STEP 0.1 -//**** VIDEO OPTIONS +/**************************** + * VIDEO OPTIONS + * Video settings menu code + ****************************/ + -integer (string text, integer key) video_options_f = +/* + CB_video_options + + Menu event callback for video options +*/ +integer (string text, integer key) +CB_video_options = { local integer selected_crosshair; local float val; @@ -47,21 +87,28 @@ integer (string text, integer key) video_options_f = switch (text) { case "gamma": val = cvar("vid_gamma"); - val = min_max_cnt(MIN_GAMMA, MAX_GAMMA, GAMMA_STEP, val, (key == QFK_RIGHT) && (key != QFK_LEFT)); + val = min_max_cnt(MIN_GAMMA, MAX_GAMMA, GAMMA_STEP, val, + (key == QFK_RIGHT) && (key != QFK_LEFT)); cvar_set("vid_gamma", ftos(val)); break; case "viewsize": val = cvar("viewsize"); - val = min_max_cnt(MIN_VIEWSIZE, MAX_VIEWSIZE, VIEWSIZE_STEP, val, (key == QFK_RIGHT) && (key != QFK_LEFT)); + val = min_max_cnt(MIN_VIEWSIZE, MAX_VIEWSIZE, VIEWSIZE_STEP, val, + (key == QFK_RIGHT) && (key != QFK_LEFT)); cvar_set("viewsize", ftos(val)); break; } return 0; }; -integer () options_video_draw = +/* + DRAW_video_options + + Drawing function for the video options menu +*/ +integer () +DRAW_video_options = { - local string tmp = ftos(cvar("crosshair")); local integer spacing = 120; local integer bar_pad; @@ -69,66 +116,83 @@ integer () options_video_draw = Draw_CenterPic (160, 4, "gfx/p_option.lmp"); Draw_String (54, 40, "Video"); Draw_String (54, 50, "-----"); - draw_val_item (70, 60, spacing, "Fullscreen", get_cvar_state ("vid_fullscreen")); - draw_val_item (70, 70, spacing, "Crosshair", tmp); - draw_val_item (70, 80, spacing, "Show fps", get_cvar_state ("show_fps")); - draw_val_item (70, 90, spacing, "Show time", get_cvar_state ("show_time")); + draw_val_item (70, 60, spacing, "Fullscreen", + cvar("vid_fullscreen") ? "On" : "Off"); + draw_val_item (70, 70, spacing, "Crosshair", ftos(cvar("crosshair"))); + draw_val_item (70, 80, spacing, "Show fps", + cvar("show_fps") ? "On" : "Off"); + draw_val_item (70, 90, spacing, "Show time", + cvar("show_time") ? "On" : "Off"); bar_pad = 90; Draw_String (70, bar_pad + 10, "Gamma:"); - draw_perc_bar (118, bar_pad + 10, 15, to_percentage (MIN_GAMMA, MAX_GAMMA, cvar("vid_gamma"))); + draw_perc_bar (118, bar_pad + 10, 15, + to_percentage (MIN_GAMMA, MAX_GAMMA, cvar("vid_gamma"))); Draw_String (118 + (15 + 4)*8 , bar_pad + 10, ftos(cvar("vid_gamma"))); Draw_String (70, bar_pad + 20, "Viewsize:"); - draw_perc_bar (142, bar_pad + 20, 12, to_percentage (MIN_VIEWSIZE, MAX_VIEWSIZE, cvar("viewsize"))); + draw_perc_bar (142, bar_pad + 20, 12, + to_percentage (MIN_VIEWSIZE, MAX_VIEWSIZE, cvar("viewsize"))); Draw_String (142 + (12 + 4)*8 , bar_pad + 20, ftos(cvar("viewsize"))); opt_cursor (62, (Menu_GetIndex() * 10) + 60); return 1; }; -void () options_video_menu = +/* + MENU_video_options + + Menu function for the video options menu. +*/ +void () +MENU_video_options = { local integer bar_pad; Menu_Begin (54, 50, "Video"); Menu_FadeScreen (1); - Menu_Draw (options_video_draw); + Menu_Draw (DRAW_video_options); - Menu_Item (54, 60, "fullscreen", video_options_f, 0); - Menu_Item (54, 70, "crosshair", video_options_f, 0); - Menu_Item (54, 80, "fps", video_options_f, 0); - Menu_Item (54, 80, "time", video_options_f, 0); + Menu_Item (54, 60, "fullscreen", CB_video_options, 0); + Menu_Item (54, 70, "crosshair", CB_video_options, 0); + Menu_Item (54, 80, "fps", CB_video_options, 0); + Menu_Item (54, 80, "time", CB_video_options, 0); bar_pad = 90; - Menu_Item (54, bar_pad + 10, "gamma", video_options_f, 1); - Menu_Item (54, bar_pad + 20, "viewsize", video_options_f, 1); + Menu_Item (54, bar_pad + 10, "gamma", CB_video_options, 1); + Menu_Item (54, bar_pad + 20, "viewsize", CB_video_options, 1); Menu_End (); }; -//**** AUDIO OPTIONS +/************************************* + * AUDIO OPTIONS + * Code for the audio settings menu + *************************************/ -integer (string text, integer key) audio_volume_f = +/* + CB_audio_options + + Callback for the audio settings. +*/ +integer (string text, integer key) +CB_audio_options = { local float volume; volume = cvar("volume"); - if(key == QFK_RIGHT) { - volume += VOLUME_STEP; - } else if(key == QFK_LEFT) { - volume -= VOLUME_STEP; - } - - if(volume > MAX_VOLUME) { - volume = MIN_VOLUME; - } else if(volume < MIN_VOLUME) { - volume = MAX_VOLUME; - } + volume = min_max_cnt(MIN_VOLUME, MAX_VOLUME, VOLUME_STEP, volume, (key == QFK_RIGHT) && (key != QFK_LEFT)); cvar_set("volume", ftos(volume)); + return 0; }; -integer () options_audio_draw = +/* + DRAW_audio_options + + Draws the audio options menu +*/ +integer () +DRAW_audio_options = { local string tmp = ftos(cvar("crosshair")); local integer spacing = 120; @@ -141,29 +205,45 @@ integer () options_audio_draw = bar_pad = 50; Draw_String (70, bar_pad + 10, "Volume:"); - draw_perc_bar (126, bar_pad + 10, 15, to_percentage (MIN_VOLUME, MAX_VOLUME, cvar("volume"))); + draw_perc_bar (126, bar_pad + 10, 15, + to_percentage (MIN_VOLUME, MAX_VOLUME, cvar("volume")) ); Draw_String (126 + (15 + 4)*8 , bar_pad + 10, ftos(cvar("volume"))); opt_cursor (62, (Menu_GetIndex() * 10) + 60); return 1; }; -void () options_audio_menu = +/* + MENU_audio_options + + Makes the audio menu +*/ +void () +MENU_audio_options = { local integer bar_pad; Menu_Begin (54, 60, "Audio"); Menu_FadeScreen (1); - Menu_Draw (options_audio_draw); + Menu_Draw (DRAW_audio_options); bar_pad = 0; - Menu_Item (54, bar_pad + 10, "volume", audio_volume_f, 1); + Menu_Item (54, bar_pad + 10, "volume", CB_audio_options, 1); Menu_End (); }; -//**** CONTROL OPTIONS +/************************ + * CONTROL OPTIONS + * Control setting code + ************************/ -integer (string text, integer key) control_options_f = +/* + CB_control_options + + Callback for control options +*/ +integer (string text, integer key) +CB_control_options = { local float val; @@ -185,6 +265,12 @@ integer (string text, integer key) control_options_f = case "freelook": Cbuf_AddText ("toggle freelook\n"); break; + case "lookspring": + Cbuf_AddText ("toggle lookspring\n"); + break; + case "lookstrafe": + Cbuf_AddText ("toggle lookstrafe\n"); + break; case "m_pitch": if(cvar("m_pitch") < 0) { Cbuf_AddText ("set m_pitch 0.022\n"); @@ -205,100 +291,164 @@ integer (string text, integer key) control_options_f = switch (text) { case "mouseamp": val = cvar("in_mouse_amp"); - val = min_max_cnt(MIN_MOUSE_AMP, MAX_MOUSE_AMP, MOUSE_AMP_STEP, val, (key == QFK_RIGHT) && (key != QFK_LEFT)); + val = min_max_cnt(MIN_MOUSE_AMP, MAX_MOUSE_AMP, MOUSE_AMP_STEP, val, + (key == QFK_RIGHT) && (key != QFK_LEFT)); cvar_set("in_mouse_amp", ftos(val)); break; } return 0; }; -integer () options_controls_draw = +/* + DRAW_control_options + + Draws the control option menu +*/ +integer () +DRAW_control_options = { - local string tmp; local integer cursor_pad = 0, spacing = 120, bar_pad; - - Draw_Pic (16, 4, "gfx/qplaque.lmp"); - Draw_CenterPic (160,4, "gfx/p_option.lmp"); + Draw_Pic (16, 4, "gfx/qplaque.lmp"); + Draw_CenterPic (160, 4, "gfx/p_option.lmp"); Draw_String (54, 40, "Controls"); Draw_String (54, 50, "--------"); Draw_String (70, 60, "Bindings"); - draw_val_item (70, 70, spacing, "Grab mouse", get_cvar_state ("in_grab")); - tmp = cvar("cl_forwardspeed") < 400 ? "Off" : "On"; - draw_val_item (70, 80, spacing, "Auto run", tmp); - draw_val_item (70, 90, spacing, "Freelook", get_cvar_state ("freelook")); + draw_val_item (70, 70, spacing, "Grab mouse", cvar("in_grab") ? "On" : "Off"); + draw_val_item (70, 80, spacing, "Auto run", cvar("cl_forwardspeed") < 400 ? "Off" : "On"); + draw_val_item (70, 90, spacing, "Mouse Invert", cvar("m_pitch") < 0 ? "On" : "Off"); bar_pad = 90; - Draw_String (70, bar_pad + 10, "Mouse amp:"); - draw_perc_bar (150, bar_pad + 10, 12, to_percentage (MIN_MOUSE_AMP, MAX_MOUSE_AMP, cvar("in_mouse_amp"))); - Draw_String (150 + (12 + 4)*8 , bar_pad + 10, ftos(cvar("in_mouse_amp"))); + Draw_String (70, bar_pad + 10, "Mouse amp:"); + draw_perc_bar (150, bar_pad + 10, 12, to_percentage (MIN_MOUSE_AMP, MAX_MOUSE_AMP, cvar("in_mouse_amp"))); + Draw_String (150 + (12 + 4)*8 , bar_pad + 10, ftos(cvar("in_mouse_amp"))); - tmp = cvar("m_pitch") < 0 ? "On" : "Off"; - draw_val_item (70, 110, spacing, "Mouse Invert", tmp); + draw_val_item (70, 110, spacing, "Freelook", cvar("freelook") ? "On" : "Off"); + draw_val_item (70, 120, spacing, "Lookspring", cvar("lookspring") ? "On" : "Off"); + draw_val_item (70, 130, spacing, "Lookstrafe", cvar("lookstrafe") ? "On" : "Off"); opt_cursor (62, (Menu_GetIndex() * 10) + 60 + cursor_pad); + return 1; }; -void () options_controls_menu = +/* + MENU_control_options + + Menu make function for control options +*/ +void () +MENU_control_options = { Menu_Begin (54, 40, "Controls"); Menu_FadeScreen (1); Menu_CenterPic (160, 4, "gfx/p_option.lmp"); - Menu_Draw (options_controls_draw); + Menu_Draw (DRAW_control_options); control_bind_menu (); - Menu_Item (54, 70, "in_grab", control_options_f, 0); - Menu_Item (54, 80, "autorun", control_options_f, 0); - Menu_Item (54, 90, "freelook", control_options_f, 0); - Menu_Item (54, 100, "mouseamp", control_options_f, 1); - Menu_Item (54, 110, "m_pitch", control_options_f, 0); - Menu_Item (54, 120, "cl_autorecord", control_options_f, 0); + Menu_Item (54, 70, "in_grab", CB_control_options, 0); + Menu_Item (54, 80, "autorun", CB_control_options, 0); + Menu_Item (54, 90, "m_pitch", CB_control_options, 0); + Menu_Item (54, 100, "mouseamp", CB_control_options, 1); + Menu_Item (54, 110, "freelook", CB_control_options, 0); + Menu_Item (54, 120, "lookspring", CB_control_options, 0); + Menu_Item (54, 130, "lookstrafe", CB_control_options, 0); Menu_End (); }; -integer () options_features_draw = -{ - local string tmp; - local integer cursor_pad = 0, spacing = 120; +/*********************************************** + * FEATURES OPTIONS + * Code of settings for special features of QF + ***********************************************/ +/* + CB_feature_options + + Callback for feature settings +*/ +integer (string text, integer key) +CB_feature_options = +{ + switch (text) { + case "cl_autorecord": + Cbuf_AddText ("toggle cl_autorecord\n"); + break; + case "cl_fraglog": + Cbuf_AddText ("toggle cl_fraglog\n"); + break; + } + return 0; +}; + +/* + DRAW_feature_options + + Draws the feature option menu +*/ +integer () +DRAW_feature_options = +{ + local integer cursor_pad = 0, spacing = 120; Draw_Pic (16, 4, "gfx/qplaque.lmp"); Draw_CenterPic (160,4, "gfx/p_option.lmp"); Draw_String (54, 40, "Features"); Draw_String (54, 50, "--------"); - tmp = cvar("cl_autorecord") != 0 ? "On" : "Off"; - draw_val_item (70, 60, spacing, "Auto Record", tmp); - tmp = cvar("cl_fraglog") != 0 ? "On" : "Off"; - draw_val_item (70, 70, spacing, "Fraglogging", tmp); + draw_val_item (70, 60, spacing, "Auto Record", + cvar("cl_autorecord") != 0 ? "On" : "Off"); + draw_val_item (70, 70, spacing, "Fraglogging", + cvar("cl_fraglog") != 0 ? "On" : "Off"); opt_cursor (62, (Menu_GetIndex() * 10) + 60 + cursor_pad); return 1; }; -void () options_features_menu = +/* + MENU_feature_options + + Makes the feature option menu +*/ +void () +MENU_feature_options = { Menu_Begin (54, 70, "Features"); Menu_FadeScreen (1); Menu_CenterPic (160, 4, "gfx/p_option.lmp"); - Menu_Draw (options_features_draw); - Menu_Item (54, 70, "cl_autorecord", control_options_f, 0); - Menu_Item (54, 80, "cl_fraglog", control_options_f, 0); + Menu_Draw (DRAW_feature_options); + Menu_Item (54, 70, "cl_autorecord", CB_feature_options, 0); + Menu_Item (54, 80, "cl_fraglog", CB_feature_options, 0); Menu_End (); }; -integer (integer key, integer unicode, integer down) options_keyevent = +/************************* + * 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 load_keybindings(); set_key_flag = 0; + return 0; }; -//**** MAIN OPTIONS MENU -void () options_menu = +/* + MENU_options + + Makes the main options menu +*/ +void () +MENU_options = { local integer spacing = 120; @@ -306,11 +456,11 @@ void () options_menu = Menu_FadeScreen (1); Menu_Pic (16, 4, "gfx/qplaque.lmp"); Menu_CenterPic (160, 4, "gfx/p_option.lmp"); - Menu_KeyEvent (options_keyevent); - options_controls_menu (); - options_video_menu (); - options_audio_menu (); - options_features_menu (); + Menu_KeyEvent (CB_options); + MENU_control_options (); + MENU_video_options (); + MENU_audio_options (); + MENU_feature_options (); Menu_End (); }; diff --git a/cs-code/options_util.qc b/cs-code/options_util.qc index 07faf8d75..a2187965b 100644 --- a/cs-code/options_util.qc +++ b/cs-code/options_util.qc @@ -1,38 +1,87 @@ -float time; -void (integer x, integer y) opt_cursor = +/* + options_util.qc + + Utilities for the options menu + + 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 +*/ + + +float time; // holds current time + +/* + opt_cursor + + function for drawing the cursor +*/ +void (integer x, integer y) +opt_cursor = { + // use time becaus we want a nice rotaing cursor Draw_Character (x, y, 12 + (integer (time * 4) & 1)); }; -string (string cvarstr) get_cvar_state = -{ - if(cvar(cvarstr)) { - return("On"); - } else { - return("Off"); - } -}; -void (integer x, integer y, integer size, integer perc_val) draw_perc_bar = + +/* + draw_perc_bar + + Draws a percentage bar by giving its size (in + chars), x and y position and the percentage from 0 to 100 +*/ +void (integer x, integer y, integer size, integer perc_val) +draw_perc_bar = { local float perc; local integer i; + if(perc_val > 100) { perc_val = 100; } else if(perc_val < 0) { perc_val = 0; } - perc = itof(perc_val) / (100/itof(size)); - Draw_Character (x, y, 128); + perc = itof(perc_val) / ( 100 / itof(size) ); + + /* 128, 129, 130 and 131 are special characters for scrollbars */ + Draw_Character (x, y, 128); // draw beginning for (i = 0; i <= size; i++) { - Draw_Character (x + ((i+1)*8), y, 129); + Draw_Character (x + ((i+1)*8), y, 129); // draw the borders } - Draw_Character (x + ((i+1)*8), y, 130); - Draw_Character (x + ((ftoi(perc) + 1) * 8), y, 131); + Draw_Character (x + ((i+1)*8), y, 130); // draw last char + Draw_Character (x + ((ftoi(perc) + 1) * 8), y, 131); // draw slider }; -void (integer x, integer y, integer spacing, string spacechar, string label, string valstr) draw_item = + + +/* + draw_item + + Draws a item with a specific spacing between + label and value to positions x, y. + Used as helper function for draw_val_item. +*/ +void (integer x, integer y, integer spacing, string spacechar, + string label, string valstr) +draw_item = { local integer i; Draw_String (x, y, label); @@ -42,12 +91,32 @@ void (integer x, integer y, integer spacing, string spacechar, string label, str Draw_String (x + spacing, y, valstr); }; -void (integer x, integer y, integer spacing, string label, string valstr) draw_val_item = + +/* + draw_val_item + + Draws a nice menu item. + Use this function for a consistent look of menu items! + Example: +