redone the input system so you can know do keybindings with say etc

This commit is contained in:
Magnus Auvinen 2008-03-01 20:03:04 +00:00
parent 0747c2dff9
commit 08c4c8e0b7
14 changed files with 539 additions and 272 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View file

@ -1306,26 +1306,6 @@ static void client_run()
}
}
/* screenshot button */
if(inp_key_down(config.key_screenshot))
gfx_screenshot();
/* some debug keys */
/*
if(config.debug)
{
if(inp_key_pressed(KEY_F1))
inp_mouse_mode_absolute();
if(inp_key_pressed(KEY_F2))
inp_mouse_mode_relative();
if(inp_key_pressed(KEY_F5))
{
ack_game_tick = -1;
client_send_input();
}
}*/
/* panic quit button */
if(inp_key_pressed(KEY_LCTRL) && inp_key_pressed(KEY_LSHIFT) && inp_key_pressed('Q'))
break;
@ -1455,12 +1435,23 @@ static void con_ping(void *result, void *user_data)
ping_start_time = time_get();
}
static void con_screenshot(void *result, void *user_data)
{
gfx_screenshot();
}
static void client_register_commands()
{
MACRO_REGISTER_COMMAND("quit", "", con_quit, 0x0);
MACRO_REGISTER_COMMAND("connect", "s", con_connect, 0x0);
MACRO_REGISTER_COMMAND("disconnect", "", con_disconnect, 0x0);
MACRO_REGISTER_COMMAND("ping", "", con_ping, 0x0);
MACRO_REGISTER_COMMAND("screenshot", "", con_screenshot, 0x0);
}
void client_save_line(const char *line)
{
engine_config_write_line(line);
}
int editor_main(int argc, char **argv);
@ -1485,6 +1476,7 @@ int main(int argc, char **argv)
if(engine_config_write_start() == 0)
{
config_save();
modc_save_config();
engine_config_write_stop();
}

View file

@ -56,12 +56,13 @@ enum
static INPUT_EVENT input_events[INPUT_BUFFER_SIZE];
static int num_events = 0;
static void add_event(char c, int key)
static void add_event(char c, int key, int flags)
{
if(num_events != INPUT_BUFFER_SIZE)
{
input_events[num_events].ch = c;
input_events[num_events].key = key;
input_events[num_events].flags = flags;
num_events++;
}
}
@ -87,17 +88,18 @@ INPUT_EVENT inp_get_event(int index)
return input_events[index];
}
static void char_callback(int character, int action)
{
if(action == GLFW_PRESS && character < 256)
add_event((char)character, 0);
add_event((char)character, 0, 0);
}
static void key_callback(int key, int action)
{
if(action == GLFW_PRESS)
add_event(0, key);
add_event(0, key, INPFLAG_PRESS);
else
add_event(0, key, INPFLAG_RELEASE);
if(action == GLFW_PRESS)
input_count[input_current^1][key].presses++;
@ -109,7 +111,9 @@ static void key_callback(int key, int action)
static void mousebutton_callback(int button, int action)
{
if(action == GLFW_PRESS)
add_event(0, KEY_MOUSE_FIRST+button);
add_event(0, KEY_MOUSE_FIRST+button, INPFLAG_PRESS);
else
add_event(0, KEY_MOUSE_FIRST+button, INPFLAG_RELEASE);
if(action == GLFW_PRESS)
input_count[input_current^1][KEY_MOUSE_FIRST+button].presses++;
@ -136,7 +140,8 @@ static void mousewheel_callback(int pos)
input_count[input_current^1][KEY_MOUSE_WHEEL_UP].releases++;
}
add_event(0, KEY_MOUSE_WHEEL_UP);
add_event(0, KEY_MOUSE_WHEEL_UP, INPFLAG_PRESS);
add_event(0, KEY_MOUSE_WHEEL_UP, INPFLAG_RELEASE);
}
else if(pos < 0)
{
@ -146,7 +151,8 @@ static void mousewheel_callback(int pos)
input_count[input_current^1][KEY_MOUSE_WHEEL_DOWN].releases++;
}
add_event(0, KEY_MOUSE_WHEEL_DOWN);
add_event(0, KEY_MOUSE_WHEEL_DOWN, INPFLAG_PRESS);
add_event(0, KEY_MOUSE_WHEEL_DOWN, INPFLAG_RELEASE);
}
glfwSetMouseWheel(0);
}

View file

@ -42,11 +42,8 @@ MACRO_CONFIG_INT(gfx_fsaa_samples, 0, 0, 16)
MACRO_CONFIG_INT(gfx_refresh_rate, 0, 0, 0)
MACRO_CONFIG_INT(gfx_debug_resizable, 0, 0, 0)
MACRO_CONFIG_INT(key_screenshot, 267, 32, 512)
MACRO_CONFIG_INT(inp_mousesens, 100, 5, 100000)
/*MACRO_CONFIG_STR(masterserver, 128, "master.teewars.com")*/
MACRO_CONFIG_STR(sv_name, 128, "unnamed server")
MACRO_CONFIG_STR(sv_bindaddr, 128, "")
MACRO_CONFIG_INT(sv_port, 8303, 0, 0)

View file

@ -340,10 +340,14 @@ void console_print(const char *str)
print_callback(str);
}
void console_execute_line(const char *str)
void console_execute_line_stroked(int stroke, const char *str)
{
LEXER_RESULT result;
int error;
char strokestr[8] = {'0', 0};
if(stroke)
strokestr[0] = '1';
if ((error = lex(str, &result)))
printf("ERROR: %d\n", error);
@ -356,6 +360,25 @@ void console_execute_line(const char *str)
command = console_find_command(name);
if(command)
{
int is_stroke_command = 0;
if(name[0] == '+')
{
/* insert the stroke direction token */
int i;
for(i = result.num_tokens-2; i > 1; i--)
{
result.tokens[i+1] = result.tokens[i];
}
result.tokens[1].type = TOKEN_INT;
result.tokens[1].stored_string = strokestr;
result.num_tokens++;
is_stroke_command = 1;
}
if(stroke || is_stroke_command)
{
if (console_validate(command, &result))
{
@ -366,6 +389,7 @@ void console_execute_line(const char *str)
else
command->callback(&result, command->user_data);
}
}
else
{
char buf[256];
@ -375,6 +399,12 @@ void console_execute_line(const char *str)
}
}
void console_execute_line(const char *str)
{
console_execute_line_stroked(1, str);
}
void console_execute_file(const char *filename)
{
IOHANDLE file;

View file

@ -19,6 +19,7 @@ typedef struct COMMAND_t
void console_init();
void console_register(COMMAND *cmd);
void console_execute_line(const char *str);
void console_execute_line_stroked(int stroke, const char *str);
void console_execute_file(const char *filename);
void console_print(const char *str);
void console_register_print_callback(void (*callback)(const char *));

View file

@ -10,8 +10,16 @@
/*
Structure: INPUT_EVENT
*/
enum
{
INPFLAG_PRESS=1,
INPFLAG_RELEASE=2,
INPFLAG_REPEAT=4
};
typedef struct
{
int flags;
char ch;
int key;
} INPUT_EVENT;

View file

@ -716,8 +716,8 @@ static void server_process_client_packet(NETPACKET *packet)
server_send_msg(cid);
clients[cid].authed = 1;
dbg_msg("server", "cid=%d authed", cid);
server_send_rcon_line(cid, "Authentication successful. Remote console access granted.");
dbg_msg("server", "cid=%d authed", cid);
}
else
{

View file

@ -33,7 +33,9 @@ int input_target_lock = 0;
int chat_mode = CHATMODE_NONE;
bool menu_active = false;
bool menu_game_active = false;
static bool emoticon_selector_active = false;
int emoticon_selector_active = 0;
int scoreboard_active = 0;
static int emoticon_selected_emote = -1;
tuning_params tuning;
@ -438,12 +440,7 @@ static void draw_circle(float x, float y, float r, int segments)
static vec2 emoticon_selector_mouse;
void emoticon_selector_reset()
{
emoticon_selector_mouse = vec2(0, 0);
}
int emoticon_selector_render()
void emoticon_selector_render()
{
int x, y;
inp_mouse_relative(&x, &y);
@ -458,17 +455,8 @@ int emoticon_selector_render()
if (selected_angle < 0)
selected_angle += 2*pi;
bool return_now = false;
int selected_emoticon = -1;
if (length(emoticon_selector_mouse) > 100)
selected_emoticon = (int)(selected_angle / (2*pi) * 12.0f);
if(!inp_key_pressed(config.key_emoticon))
{
return_now = true;
emoticon_selector_active = false;
}
emoticon_selected_emote = (int)(selected_angle / (2*pi) * 12.0f);
RECT screen = *ui_screen();
@ -491,7 +479,7 @@ int emoticon_selector_render()
if (angle > pi)
angle -= 2*pi;
bool selected = selected_emoticon == i;
bool selected = emoticon_selected_emote == i;
float size = selected ? 96 : 64;
@ -508,8 +496,6 @@ int emoticon_selector_render()
gfx_setcolor(1,1,1,1);
gfx_quads_drawTL(emoticon_selector_mouse.x+screen.w/2,emoticon_selector_mouse.y+screen.h/2,24,24);
gfx_quads_end();
return return_now ? selected_emoticon : -1;
}
void render_goals(float x, float y, float w)
@ -715,7 +701,7 @@ void render_scoreboard(float x, float y, float w, int team, const char *title)
y += 50.0f;
}
}
/*
static int do_input(int *v, int key)
{
*v += inp_key_presses(key) + inp_key_releases(key);
@ -724,6 +710,27 @@ static int do_input(int *v, int key)
*v &= INPUT_STATE_MASK;
return (*v&1);
}*/
void chat_say(int team, const char *line)
{
// send chat message
msg_pack_start(MSG_SAY, MSGFLAG_VITAL);
msg_pack_int(team);
msg_pack_string(line, 512);
msg_pack_end();
client_send_msg();
}
void chat_enable_mode(int team)
{
if(team)
chat_mode = CHATMODE_TEAM;
else
chat_mode = CHATMODE_ALL;
mem_zero(chat_input, sizeof(chat_input));
chat_input_len = 0;
}
void render_game()
@ -792,17 +799,7 @@ void render_game()
{
// send message
if(chat_input_len)
{
// send chat message
msg_pack_start(MSG_SAY, MSGFLAG_VITAL);
if(chat_mode == CHATMODE_ALL)
msg_pack_int(0);
else
msg_pack_int(1);
msg_pack_string(chat_input, 512);
msg_pack_end();
client_send_msg();
}
chat_say(chat_mode == CHATMODE_ALL ? 0 : 1, chat_input);
chat_mode = CHATMODE_NONE;
}
@ -831,23 +828,6 @@ void render_game()
}
}
}
else
{
if(chat_mode == CHATMODE_NONE)
{
if(inp_key_down(config.key_chat))
chat_mode = CHATMODE_ALL;
if(inp_key_down(config.key_teamchat))
chat_mode = CHATMODE_TEAM;
if(chat_mode != CHATMODE_NONE)
{
mem_zero(chat_input, sizeof(chat_input));
chat_input_len = 0;
}
}
}
}
if (!menu_active)
@ -889,6 +869,7 @@ void render_game()
// update some input
if(!menu_active && chat_mode == CHATMODE_NONE)
{
/*
bool do_direct = false;
if(!emoticon_selector_active)
@ -933,7 +914,7 @@ void render_game()
}
if(do_direct) // do direct input if wanted
client_direct_input((int *)&input_data, sizeof(input_data));
client_direct_input((int *)&input_data, sizeof(input_data));*/
}
@ -1402,27 +1383,21 @@ void render_game()
return;
}
if(chat_mode == CHATMODE_NONE && !menu_active && !spectate)
{
if(!emoticon_selector_active && inp_key_pressed(config.key_emoticon))
{
emoticon_selector_active = true;
emoticon_selector_reset();
}
}
else
emoticon_selector_active = false;
// do emoticon
if(emoticon_selector_active)
emoticon_selector_render();
else
{
int emoticon = emoticon_selector_render();
if (emoticon != -1)
emoticon_selector_mouse = vec2(0,0);
if(emoticon_selected_emote != -1)
{
send_emoticon(emoticon);
emoticon_selector_active = false;
send_emoticon(emoticon_selected_emote);
emoticon_selected_emote = -1;
}
}
// render debug stuff
if(config.debug && netobjects.local_character && netobjects.local_prev_character)
{
gfx_mapscreen(0, 0, 300*gfx_screenaspect(), 300);
@ -1436,7 +1411,7 @@ void render_game()
}
// render score board
if(inp_key_pressed(KEY_TAB) || // user requested
if(scoreboard_active || // user requested
(!spectate && (!netobjects.local_character || netobjects.local_character->health < 0)) || // not spectating and is dead
(netobjects.gameobj && netobjects.gameobj->game_over) // game over
)

View file

@ -82,6 +82,9 @@ extern int chat_mode;
void chat_add_line(int client_id, int team, const char *line);
void chat_reset();
extern int emoticon_selector_active; // TODO: ugly
extern int scoreboard_active; // TODO: ugly
// client data
struct client_data
{
@ -125,6 +128,11 @@ void process_events(int snaptype);
void clear_object_pointers();
void reset_projectile_particles();
void send_info(bool start);
void send_emoticon(int emoticon);
void chat_say(int team, const char *line);
void chat_enable_mode(int team);
inline vec2 random_dir() { return normalize(vec2(frandom()-0.5f, frandom()-0.5f)); }
@ -202,3 +210,8 @@ void flow_dbg_render();
void flow_init();
void flow_update();
//
void binds_save();
void binds_set(int keyid, const char *str);
const char *binds_get(int keyid);

View file

@ -84,6 +84,8 @@ public:
}
}
if(e.flags&INPFLAG_PRESS)
{
if(e.key == KEY_BACKSPACE)
{
if(input_len > 0)
@ -153,6 +155,7 @@ public:
}
}
}
}
void print_line(const char *line)
{
@ -204,18 +207,19 @@ static void con_team(void *result, void *user_data)
send_switch_team(new_team);
}
/*
static void con_history(void *result, void *user_data)
static void con_say(void *result, void *user_data)
{
char *entry = (char *)ringbuf_first(console_history);
while (entry)
{
dbg_msg("console/history", entry);
entry = (char *)ringbuf_next(console_history, entry);
const char *str;
console_result_string(result, 1, &str);
chat_say(0, str);
}
static void con_sayteam(void *result, void *user_data)
{
const char *str;
console_result_string(result, 1, &str);
chat_say(1, str);
}
}*/
void send_kill(int client_id);
@ -224,12 +228,219 @@ static void con_kill(void *result, void *user_data)
send_kill(-1);
}
static char keybindings[KEY_LAST][128] = {{0}};
const char *binds_get(int keyid)
{
if(keyid > 0 && keyid < KEY_LAST)
return keybindings[keyid];
return "";
}
void binds_set(int keyid, const char *str)
{
if(keyid < 0 && keyid >= KEY_LAST)
return;
str_copy(keybindings[keyid], str, sizeof(keybindings[keyid]));
if(!keybindings[keyid][0])
dbg_msg("binds", "unbound %s (%d)", inp_key_name(keyid), keyid);
else
dbg_msg("binds", "bound %s (%d) = %s", inp_key_name(keyid), keyid, keybindings[keyid]);
}
static int get_key_id(const char *key_name)
{
int i = atoi(key_name);
if(i > 0 && i < KEY_LAST)
return i; // numeric
// search for key
for(int i = 0; i < KEY_LAST; i++)
{
if(strcmp(key_name, inp_key_name(i)) == 0)
return i;
}
return 0;
}
static void con_binds_set(void *result, void *user_data)
{
const char *key_name;
const char *bind_str;
console_result_string(result, 1, &key_name);
console_result_string(result, 2, &bind_str);
int id = get_key_id(key_name);
if(!id)
{
dbg_msg("binds", "key %s not found", key_name);
return;
}
binds_set(id, bind_str);
}
static void con_binds_remove(void *result, void *user_data)
{
const char *key_name;
console_result_string(result, 1, &key_name);
int id = get_key_id(key_name);
if(!id)
{
dbg_msg("binds", "key %s not found", key_name);
return;
}
binds_set(id, "");
}
static void con_binds_dump(void *result, void *user_data)
{
for(int i = 0; i < KEY_LAST; i++)
{
if(keybindings[i][0] == 0)
continue;
dbg_msg("binds", "%s (%d) = %s", inp_key_name(i), i, keybindings[i]);
}
}
void binds_save()
{
char buffer[256];
for(int i = 0; i < KEY_LAST; i++)
{
if(keybindings[i][0] == 0)
continue;
str_format(buffer, sizeof(buffer), "binds_set %s \"%s\"", inp_key_name(i), keybindings[i]);
client_save_line(buffer);
}
}
static void con_key_input_state(void *result, void *user_data)
{
int i;
console_result_int(result, 1, &i);
((int *)user_data)[0] = i;
}
static void con_key_input_counter(void *result, void *user_data)
{
int stroke;
int *v = (int *)user_data;
console_result_int(result, 1, &stroke);
if(((*v)&1) != stroke)
(*v)++;
*v &= INPUT_STATE_MASK;
}
static void con_key_input_weapon(void *result, void *user_data)
{
int w = (char *)user_data - (char *)0;
int stroke;
console_result_int(result, 1, &stroke);
if(stroke)
input_data.wanted_weapon = w;
}
static void con_chat(void *result, void *user_data)
{
const char *mode;
console_result_string(result, 1, &mode);
if(strcmp(mode, "all") == 0)
chat_enable_mode(0);
else if(strcmp(mode, "team") == 0)
chat_enable_mode(1);
else
dbg_msg("console", "expected all or team as mode");
}
static void con_toggle_local_console(void *result, void *user_data)
{
console_toggle(0);
}
static void con_toggle_remote_console(void *result, void *user_data)
{
console_toggle(1);
}
static void con_emote(void *result, void *user_data)
{
int emote;
console_result_int(result, 1, &emote);
send_emoticon(emote);
}
void client_console_init()
{
console_register_print_callback(client_console_print);
//
MACRO_REGISTER_COMMAND("toggle_local_console", "", con_toggle_local_console, 0x0);
MACRO_REGISTER_COMMAND("toggle_remote_console", "", con_toggle_remote_console, 0x0);
//
MACRO_REGISTER_COMMAND("team", "i", con_team, 0x0);
//MACRO_REGISTER_COMMAND("history", "", con_history, 0x0);
MACRO_REGISTER_COMMAND("kill", "", con_kill, 0x0);
// bindings
MACRO_REGISTER_COMMAND("binds_set", "ss", con_binds_set, 0x0);
MACRO_REGISTER_COMMAND("binds_remove", "s", con_binds_remove, 0x0);
MACRO_REGISTER_COMMAND("binds_dump", "", con_binds_dump, 0x0);
// chatting
MACRO_REGISTER_COMMAND("say", "s", con_say, 0x0);
MACRO_REGISTER_COMMAND("say_team", "s", con_sayteam, 0x0);
MACRO_REGISTER_COMMAND("chat", "s", con_chat, 0x0);
MACRO_REGISTER_COMMAND("emote", "i", con_emote, 0);
// game commands
MACRO_REGISTER_COMMAND("+left", "i", con_key_input_state, &input_data.left);
MACRO_REGISTER_COMMAND("+right", "i", con_key_input_state, &input_data.right);
MACRO_REGISTER_COMMAND("+jump", "i", con_key_input_state, &input_data.jump);
MACRO_REGISTER_COMMAND("+hook", "i", con_key_input_state, &input_data.hook);
MACRO_REGISTER_COMMAND("+fire", "i", con_key_input_counter, &input_data.fire);
MACRO_REGISTER_COMMAND("+weapon1", "i", con_key_input_weapon, (void *)1);
MACRO_REGISTER_COMMAND("+weapon2", "i", con_key_input_weapon, (void *)2);
MACRO_REGISTER_COMMAND("+weapon3", "i", con_key_input_weapon, (void *)3);
MACRO_REGISTER_COMMAND("+weapon4", "i", con_key_input_weapon, (void *)4);
MACRO_REGISTER_COMMAND("+weapon5", "i", con_key_input_weapon, (void *)5);
MACRO_REGISTER_COMMAND("+nextweapon", "i", con_key_input_counter, &input_data.next_weapon);
MACRO_REGISTER_COMMAND("+prevweapon", "i", con_key_input_counter, &input_data.prev_weapon);
MACRO_REGISTER_COMMAND("+emote", "i", con_key_input_state, &emoticon_selector_active);
MACRO_REGISTER_COMMAND("+scoreboard", "i", con_key_input_state, &scoreboard_active);
// set default key bindings
binds_set(KEY_F1, "toggle_local_console");
binds_set(KEY_F2, "toggle_remote_console");
binds_set(KEY_TAB, "+scoreboard");
binds_set(KEY_F10, "screenshot");
binds_set('A', "+left");
binds_set('D', "+right");
binds_set(KEY_SPACE, "+jump");
binds_set(KEY_MOUSE_1, "+fire");
binds_set(KEY_MOUSE_2, "+hook");
binds_set(KEY_LSHIFT, "+emote");
binds_set('1', "+weapon1");
binds_set('2', "+weapon2");
binds_set('3', "+weapon3");
binds_set('4', "+weapon4");
binds_set('5', "+weapon5");
binds_set(KEY_MOUSE_WHEEL_UP, "+prevweapon");
binds_set(KEY_MOUSE_WHEEL_DOWN, "+nextweapon");
binds_set('T', "chat all");
binds_set('Y', "chat team");
}
void console_handle_input()
@ -240,13 +451,24 @@ void console_handle_input()
{
INPUT_EVENT e = inp_get_event(i);
if (e.key == config.key_toggleconsole)
console_toggle(0);
else if (e.key == config.key_toggleconsole+1)
console_toggle(1);
else if(console_active())
if(console_active())
{
if(e.key == KEY_ESC && e.flags&INPFLAG_PRESS)
console_toggle(console_type);
else
current_console()->handle_event(e);
}
else
{
if(e.key > 0 && e.key < KEY_LAST && keybindings[e.key][0] != 0)
{
int stroke = 0;
if(e.flags&INPFLAG_PRESS)
stroke = 1;
console_execute_line_stroked(stroke, keybindings[e.key]);
}
}
}
if(was_active || console_active())
{
@ -325,7 +547,7 @@ void console_render()
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
// do shadow
// do console shadow
gfx_texture_set(-1);
gfx_quads_begin();
gfx_setcolorvertex(0, 0,0,0, 0.5f);
@ -343,6 +565,16 @@ void console_render()
gfx_setcolor(0.4f, 0.2f, 0.2f,0.9f);
gfx_quads_setsubset(0,-console_height*0.075f,screen.w*0.075f*0.5f,0);
gfx_quads_drawTL(0,0,screen.w,console_height);
gfx_quads_end();
// do small bar shadow
gfx_texture_set(-1);
gfx_quads_begin();
gfx_setcolorvertex(0, 0,0,0, 0.0f);
gfx_setcolorvertex(1, 0,0,0, 0.0f);
gfx_setcolorvertex(2, 0,0,0, 0.25f);
gfx_setcolorvertex(3, 0,0,0, 0.25f);
gfx_quads_drawTL(0,console_height-20,screen.w,10);
gfx_quads_end();
// do the lower bar

View file

@ -31,6 +31,8 @@ extern "C" void modc_console_init()
client_console_init();
}
//binds_save()
static void load_sounds_thread(void *)
{
// load sounds
@ -112,6 +114,11 @@ extern "C" void modc_init()
dbg_msg("", "%f.2ms", ((end-start)*1000)/(float)time_freq());
}
extern "C" void modc_save_config()
{
binds_save();
}
extern "C" void modc_entergame()
{
}
@ -355,6 +362,31 @@ extern "C" void modc_rcon_line(const char *line)
extern "C" int modc_snap_input(int *data)
{
static NETOBJ_PLAYER_INPUT last_data = {0};
// update player state
if(chat_mode != CHATMODE_NONE)
input_data.player_state = PLAYERSTATE_CHATTING;
else if(menu_active)
input_data.player_state = PLAYERSTATE_IN_MENU;
else
input_data.player_state = PLAYERSTATE_PLAYING;
last_data.player_state = input_data.player_state;
// we freeze the input if chat or menu is activated
if(menu_active || chat_mode != CHATMODE_NONE || console_active())
{
last_data.left = 0;
last_data.right = 0;
last_data.hook = 0;
last_data.jump = 0;
input_data = last_data;
mem_copy(data, &input_data, sizeof(input_data));
return sizeof(input_data);
}
picked_up_weapon = -1;
if(!input_target_lock)
@ -365,33 +397,9 @@ extern "C" int modc_snap_input(int *data)
if(!input_data.target_x && !input_data.target_y)
input_data.target_y = 1;
}
input_target_lock = 0;
if(chat_mode != CHATMODE_NONE)
input_data.player_state = PLAYERSTATE_CHATTING;
else if(menu_active)
input_data.player_state = PLAYERSTATE_IN_MENU;
else
{
input_data.player_state = PLAYERSTATE_PLAYING;
// TODO: this doesn't feel too pretty... look into it?
if (console_active())
{
input_data.left = 0;
input_data.right = 0;
input_data.hook = 0;
input_data.jump = 0;
}
else
{
input_data.left = inp_key_state(config.key_move_left);
input_data.right = inp_key_state(config.key_move_right);
input_data.hook = inp_key_state(config.key_hook);
input_data.jump = inp_key_state(config.key_jump);
}
}
// stress testing
if(config.dbg_stress)
{
@ -409,6 +417,7 @@ extern "C" int modc_snap_input(int *data)
}
// copy and return size
last_data = input_data;
mem_copy(data, &input_data, sizeof(input_data));
return sizeof(input_data);
}

View file

@ -225,6 +225,8 @@ int ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float fo
}
}
if(e.flags&INPFLAG_PRESS)
{
if (k == KEY_BACKSPACE && at_index > 0)
{
memmove(str + at_index - 1, str + at_index, len - at_index + 1);
@ -243,6 +245,7 @@ int ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float fo
else if (k == KEY_END)
at_index = len;
}
}
r = 1;
}
@ -421,7 +424,7 @@ int ui_do_key_reader(void *id, const RECT *rect, int key)
for(int i = 0; i < inp_num_events(); i++)
{
INPUT_EVENT e = inp_get_event(i);
if(e.key && e.key != KEY_ESC)
if(e.flags&INPFLAG_PRESS && e.key && e.key != KEY_ESC)
{
new_key = e.key;
ui_set_active_item(0);
@ -443,8 +446,13 @@ int ui_do_key_reader(void *id, const RECT *rect, int key)
// draw
if (ui_active_item() == id)
ui_draw_keyselect_button(id, "???", 0, rect, 0);
else
{
if(key == 0)
ui_draw_keyselect_button(id, "", 0, rect, 0);
else
ui_draw_keyselect_button(id, inp_key_name(key), 0, rect, 0);
}
return new_key;
}
@ -1296,33 +1304,50 @@ static void menu2_render_settings_controls(RECT main_view)
typedef struct
{
char name[32];
int *key;
char *name;
char *command;
int keyid;
} KEYINFO;
const KEYINFO keys[] =
KEYINFO keys[] =
{
{ "Move Left:", &config.key_move_left },
{ "Move Right:", &config.key_move_right },
{ "Jump:", &config.key_jump },
{ "Fire:", &config.key_fire },
{ "Hook:", &config.key_hook },
{ "Hammer:", &config.key_weapon1 },
{ "Pistol:", &config.key_weapon2 },
{ "Shotgun:", &config.key_weapon3 },
{ "Grenade:", &config.key_weapon4 },
{ "Rifle:", &config.key_weapon5 },
{ "Next Weapon:", &config.key_next_weapon },
{ "Prev. Weapon:", &config.key_prev_weapon },
{ "Emoticon:", &config.key_emoticon },
{ "Chat:", &config.key_chat },
{ "Team Chat:", &config.key_teamchat },
{ "Toggle Console:", &config.key_toggleconsole },
{ "Screenshot:", &config.key_screenshot },
{ "Move Left:", "+left", 0},
{ "Move Right:", "+right", 0 },
{ "Jump:", "+jump", 0 },
{ "Fire:", "+fire", 0 },
{ "Hook:", "+hook", 0 },
{ "Hammer:", "+weapon1", 0 },
{ "Pistol:", "+weapon2", 0 },
{ "Shotgun:", "+weapon3", 0 },
{ "Grenade:", "+weapon4", 0 },
{ "Rifle:", "+weapon5", 0 },
{ "Next Weapon:", "+nextweapon", 0 },
{ "Prev. Weapon:", "+prevweapon", 0 },
{ "Emoticon:", "+emote", 0 },
{ "Chat:", "chat all", 0 },
{ "Team Chat:", "chat team", 0 },
{ "Console:", "toggle_local_console", 0 },
{ "RemoteConsole:", "toggle_remote_console", 0 },
{ "Screenshot:", "screenshot", 0 },
};
const int key_count = sizeof(keys) / sizeof(KEYINFO);
// this is kinda slow, but whatever
for(int keyid = 0; keyid < KEY_LAST; keyid++)
{
const char *bind = binds_get(keyid);
if(!bind[0])
continue;
for(int i = 0; i < key_count; i++)
if(strcmp(bind, keys[i].command) == 0)
{
keys[i].keyid = keyid;
break;
}
}
for (int i = 0; i < key_count; i++)
{
KEYINFO key = keys[i];
@ -1331,7 +1356,13 @@ static void menu2_render_settings_controls(RECT main_view)
ui_vsplit_l(&button, 110.0f, &label, &button);
ui_do_label(&label, key.name, 14.0f, -1);
*key.key = ui_do_key_reader(key.key, &button, *key.key);
int oldid = key.keyid;
int newid = ui_do_key_reader(keys[i].name, &button, oldid);
if(newid != oldid)
{
binds_set(oldid, "");
binds_set(newid, keys[i].command);
}
ui_hsplit_t(&main_view, 5.0f, 0, &main_view);
}
}

View file

@ -1,31 +1,4 @@
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
MACRO_CONFIG_INT(key_move_left, 'A', 32, 512)
MACRO_CONFIG_INT(key_move_right, 'D', 32, 512)
MACRO_CONFIG_INT(key_jump, 32, 32, 512)
MACRO_CONFIG_INT(key_fire, 384, 32, 512)
MACRO_CONFIG_INT(key_hook, 385, 32, 512)
MACRO_CONFIG_INT(key_weapon1, '1', 32, 512)
MACRO_CONFIG_INT(key_weapon2, '2', 32, 512)
MACRO_CONFIG_INT(key_weapon3, '3', 32, 512)
MACRO_CONFIG_INT(key_weapon4, '4', 32, 512)
MACRO_CONFIG_INT(key_weapon5, '5', 32, 512)
MACRO_CONFIG_INT(key_weapon6, '6', 32, 512)
MACRO_CONFIG_INT(key_weapon7, '7', 32, 512)
MACRO_CONFIG_INT(key_next_weapon, 382, 32, 512)
MACRO_CONFIG_INT(key_prev_weapon, 383, 32, 512)
MACRO_CONFIG_INT(key_emoticon, 'E', 32, 512)
MACRO_CONFIG_INT(key_chat, 'T', 32, 512)
MACRO_CONFIG_INT(key_teamchat, 'Y', 32, 512)
/*MACRO_CONFIG_INT(key_console, 256+2, 32, 512)
MACRO_CONFIG_INT(key_remoteconsole, 256+3, 32, 512)*/
MACRO_CONFIG_INT(key_toggleconsole, 256+2, 32, 512)
MACRO_CONFIG_INT(cl_predict, 1, 0, 1)
MACRO_CONFIG_INT(cl_nameplates, 0, 0, 1)
MACRO_CONFIG_INT(cl_nameplates_always, 0, 0, 1)