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.
This commit is contained in:
Robin Redeker 2002-03-16 20:22:01 +00:00
parent f3ee5d7bdc
commit adca50e52b
11 changed files with 304 additions and 73 deletions

View file

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

View file

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

45
cs-code/inputline_util.qc Normal file
View file

@ -0,0 +1,45 @@
/*
inputline_util.qc
Utilities for the inputline
Copyright (C) 2002 Robin Redeker <elmex@x-paste.de>
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

View file

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

View file

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

54
cs-code/menu_util.qc Normal file
View file

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

View file

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

View file

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

View file

@ -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:
/*

View file

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

View file

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