The option-menus now have a better layout and

the control-binding-submenu works a lot better now too.
I added some string-functions for the API.
This commit is contained in:
Robin Redeker 2002-02-02 09:38:25 +00:00
parent 67d53f4e56
commit 2ac4ab161a
5 changed files with 70 additions and 33 deletions

View file

@ -5,7 +5,7 @@ string [NUM_BINDED_KEYS] key_bindings =
"impulse 10",
"+jump"
};
string [NUM_BINDED_KEYS] key_bindings_keys =
string [NUM_BINDED_KEYS] key_bindings_desc =
{
"none",
"none",
@ -14,24 +14,35 @@ string [NUM_BINDED_KEYS] key_bindings_keys =
integer set_key_flag;
string (integer key, integer bindnum) make_key_desc =
{
local integer keynum;
local string keyname;
keynum = Key_LookupBinding(IMT_0, bindnum, key_bindings[key]);
if(keynum == -1) {
keyname = "none";
} else {
keyname = Key_KeynumToString(keynum);
// cut away the "K_"
keyname = String_Cut(0, 2, keyname);
}
return keyname;
};
void () load_keybindings =
{
local integer i, keynum;
for(i = 0;i < NUM_BINDED_KEYS; i++) {
keynum = Key_LookupBinding(IMT_0, key_bindings[i]);
if(keynum == -1) {
key_bindings_keys[i] = "<none>";
} else {
key_bindings_keys[i] = Key_KeynumToString(keynum);
}
key_bindings_desc[i] = make_key_desc(i, 1) + "," + make_key_desc(i, 2);
}
};
integer (string text, integer key) control_bind_f =
{
local string binding;
local integer retval = 0;
local integer retval = 0, bindcnt = 0;
switch (text) {
case "set_attack_key":
@ -46,17 +57,21 @@ integer (string text, integer key) control_bind_f =
}
if(set_key_flag) {
Key_SetBinding (IMT_0, key, binding);
bindcnt = Key_CountBinding(IMT_0, binding);
if(bindcnt < 2) {
Key_SetBinding (IMT_0, key, binding);
}
// else: not bind
set_key_flag = 0;
retval = 1;
} else {
if(key == QFK_RETURN) {
set_key_flag = 1;
if(Key_CountBinding(IMT_0, binding) < 2)
set_key_flag = 1;
retval = 1;
} else if(key == QFK_BACKSPACE) {
Key_SetBinding (IMT_0, Key_LookupBinding(IMT_0, binding), "");
} else if(key == QFK_BACKSPACE || key == QFK_DELETE) {
Key_SetBinding (IMT_0, Key_LookupBinding(IMT_0, 1, binding), "");
retval = 1;
}
@ -68,15 +83,18 @@ integer (string text, integer key) control_bind_f =
integer () control_bind_draw =
{
local integer cursor_pad = 0;
local integer cursor_pad = 50, bind_desc_pad;
Draw_String (20, 20, "Attack: " + key_bindings_keys[0]);
Draw_String (20, 30, "Next weapon: " + key_bindings_keys[1]);
Draw_String (20, 40, "Jump/Swim up: " + key_bindings_keys[2]);
Draw_String (20, 70, "Backspace => Del binding");
Draw_String (20, 80, "Enter => New binding");
bind_desc_pad = 120;
opt_cursor (12, (Menu_GetIndex() * 10) + 20 + cursor_pad);
Draw_String (20, 20, "Backspace/Delete: Del binding");
Draw_String (20, 30, "Enter: New binding");
draw_val_item (20, 50, bind_desc_pad, "Attack", key_bindings_desc[0]);
draw_val_item (20, 60, bind_desc_pad, "Next weapon", key_bindings_desc[1]);
draw_val_item (20, 70, bind_desc_pad, "Jump/Swin up", key_bindings_desc[2]);
opt_cursor (12, (Menu_GetIndex() * 10) + cursor_pad);
return 1;
};
@ -86,10 +104,10 @@ void () control_bind_menu =
Menu_Begin (54, 90, "Bindings");
Menu_FadeScreen (1);
Menu_Draw (control_bind_draw);
// Menu_KeyEvent (control_bind_keyevent);
Menu_Item (20, 20, "set_attack_key", control_bind_f, 1);
Menu_Item (20, 30, "set_next_weap_key", control_bind_f, 1);
Menu_Item (20, 40, "set_jump_key", control_bind_f, 1);
Menu_Item (20, 50, "set_attack_key", control_bind_f, 1);
Menu_Item (20, 60, "set_next_weap_key", control_bind_f, 1);
Menu_Item (20, 70, "set_jump_key", control_bind_f, 1);
Menu_End ();
};

View file

@ -1,4 +1,5 @@
#include "QF/keys.h"
string (integer target, integer keynum, string binding) Key_SetBinding = #0;
integer (integer target, string binding) Key_LookupBinding = #0;
integer (integer target, integer bindnum, string binding) Key_LookupBinding = #0;
integer (integer target, string binding) Key_CountBinding = #0;
string (integer keynum) Key_KeynumToString = #0;

View file

@ -73,16 +73,19 @@ integer () gamma_to_percentage =
integer () options_video_draw =
{
local string tmp = ftos(cvar("crosshair"));
local integer spacing = 120;
Draw_Pic (16, 4, "gfx/qplaque.lmp");
Draw_CenterPic (160, 4, "gfx/p_option.lmp");
Draw_String (54, 40, "Video");
Draw_String (54, 50, "-----");
Draw_String (70, 60, "Fullscreen: " + get_cvar_state("vid_fullscreen"));
Draw_String (70, 70, "Crosshair: " + tmp);
draw_val_item (70, 60, spacing, "Fullscreen", get_cvar_state ("vid_fullscreen"));
draw_val_item (70, 70, spacing, "Crosshair", tmp);
Draw_String (70, 80, "Gamma:");
draw_perc_bar (118, 80, 15, gamma_to_percentage());
Draw_String (118 + (15 + 4)*8 , 80, ftos(cvar("vid_gamma")));
opt_cursor (62, (Menu_GetIndex() * 10) + 60);
return 1;
};
@ -130,22 +133,22 @@ integer (integer key, integer unicode, integer down) options_controls_keyevent =
integer () options_controls_draw =
{
local string tmp;
local integer cursor_pad = 0;
local integer cursor_pad = 0, spacing = 120;
Draw_Pic (16, 4, "gfx/qplaque.lmp");
Draw_CenterPic (160, 4, "gfx/p_option.lmp");
Draw_CenterPic (160,4, "gfx/p_option.lmp");
Draw_String (54, 40, "Controls");
Draw_String (54, 50, "--------");
Draw_String (70, 60, "Grab mouse: " + get_cvar_state ("in_grab"));
draw_val_item (70, 60, spacing, "Grab mouse", get_cvar_state ("in_grab"));
tmp = "On";
if(cvar("cl_forwardspeed") < 400) {
tmp = "Off";
}
Draw_String (70, 70, "Auto run: " + tmp);
draw_val_item (70, 70, spacing, "Auto run", tmp);
Draw_String (70, 80, "Bindings");
opt_cursor (62, (Menu_GetIndex() * 10) + 60 + cursor_pad);
opt_cursor (62, (Menu_GetIndex() * 10) + 60 + cursor_pad);
return 1;
};

View file

@ -29,3 +29,17 @@ void (integer x, integer y, integer size, integer perc_val) draw_perc_bar =
Draw_String (x + ((i+1)*8), y, "]");
Draw_Character (x + ((perc + 1) * 8), y, '*');
};
void (integer x, integer y, integer spacing, string spacechar, string label, string valstr) draw_item =
{
local integer i;
Draw_String (x, y, label);
for (i = x + String_Len(label)*8; i < (x+spacing); i+=8) {
Draw_String (i, y, spacechar);
}
Draw_String (x + spacing, y, valstr);
};
void (integer x, integer y, integer spacing, string label, string valstr) draw_val_item =
{
draw_item (x, y, spacing, ".", label, ":" + valstr);
};

View file

@ -1,2 +1,3 @@
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;