fixed sending of new player info when player changes something in the info

This commit is contained in:
Magnus Auvinen 2008-10-20 23:38:23 +00:00
parent 15217d8458
commit 6224fc7763
4 changed files with 42 additions and 15 deletions

View file

@ -86,6 +86,7 @@ MENUS::MENUS()
game_page = PAGE_GAME;
need_restart = false;
need_sendinfo = false;
menu_active = true;
escape_pressed = false;
@ -245,6 +246,7 @@ int MENUS::ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, f
memmove(str + at_index + 1, str + at_index, len - at_index + 1);
str[at_index] = c;
at_index++;
r = 1;
}
}
@ -254,9 +256,13 @@ int MENUS::ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, f
{
memmove(str + at_index - 1, str + at_index, len - at_index + 1);
at_index--;
r = 1;
}
else if (k == KEY_DEL && at_index < len)
{
memmove(str + at_index, str + at_index + 1, len - at_index);
r = 1;
}
else if (k == KEY_ENTER)
ui_clear_last_active_item();
else if (k == KEY_LEFT && at_index > 0)
@ -269,8 +275,6 @@ int MENUS::ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, f
at_index = len;
}
}
r = 1;
}
bool just_got_active = false;
@ -889,6 +893,17 @@ int MENUS::render()
return 0;
}
void MENUS::set_active(bool active)
{
menu_active = active;
if(!menu_active && need_sendinfo)
{
gameclient.send_info(false);
need_sendinfo = false;
}
}
void MENUS::on_reset()
{
}
@ -920,7 +935,7 @@ bool MENUS::on_input(INPUT_EVENT e)
if(e.key == KEY_ESC)
{
escape_pressed = true;
menu_active = !menu_active;
set_active(!is_active());
return true;
}
else if(e.key == KEY_ENTER)
@ -930,7 +945,7 @@ bool MENUS::on_input(INPUT_EVENT e)
}
}
if(menu_active)
if(is_active())
{
if(num_inputevents < MAX_INPUTEVENTS)
inputevents[num_inputevents++] = e;
@ -962,14 +977,14 @@ void MENUS::on_statechange(int new_state, int old_state)
else if (new_state == CLIENTSTATE_ONLINE || new_state == CLIENTSTATE_DEMOPLAYBACK)
{
popup = POPUP_NONE;
menu_active = false;
set_active(false);
}
}
void MENUS::on_render()
{
if(client_state() != CLIENTSTATE_ONLINE && client_state() != CLIENTSTATE_DEMOPLAYBACK)
menu_active = true;
set_active(true);
if(client_state() == CLIENTSTATE_DEMOPLAYBACK)
{
@ -978,7 +993,7 @@ void MENUS::on_render()
render_demoplayer(screen);
}
if(!menu_active)
if(!is_active())
{
escape_pressed = false;
enter_pressed = false;

View file

@ -106,6 +106,7 @@ class MENUS : public COMPONENT
// for graphic settings
bool need_restart;
bool need_sendinfo;
//
bool escape_pressed;
@ -161,6 +162,7 @@ class MENUS : public COMPONENT
void render_settings_sound(RECT main_view);
void render_settings(RECT main_view);
void set_active(bool active);
public:
static MENUS_KEYBINDER binder;

View file

@ -44,7 +44,7 @@ void MENUS::render_game(RECT main_view)
if(ui_do_button(&spectate_button, "Spectate", 0, &button, ui_draw_menu_button, 0))
{
gameclient.send_switch_team(-1);
menu_active = false;
set_active(false);
}
}
@ -58,7 +58,7 @@ void MENUS::render_game(RECT main_view)
if(ui_do_button(&spectate_button, "Join Red", 0, &button, ui_draw_menu_button, 0))
{
gameclient.send_switch_team(0);
menu_active = false;
set_active(false);
}
}
@ -70,7 +70,7 @@ void MENUS::render_game(RECT main_view)
if(ui_do_button(&spectate_button, "Join Blue", 0, &button, ui_draw_menu_button, 0))
{
gameclient.send_switch_team(1);
menu_active = false;
set_active(false);
}
}
}
@ -84,7 +84,7 @@ void MENUS::render_game(RECT main_view)
if(ui_do_button(&spectate_button, "Join Game", 0, &button, ui_draw_menu_button, 0))
{
gameclient.send_switch_team(0);
menu_active = false;
set_active(false);
}
}
}
@ -390,7 +390,7 @@ void MENUS::render_servercontrol(RECT main_view)
gameclient.snap.player_infos[callvote_selectedplayer])
{
gameclient.voting->callvote_kick(callvote_selectedplayer);
menu_active = false;
set_active(false);
}
}
}

View file

@ -57,7 +57,8 @@ void MENUS::render_settings_player(RECT main_view)
ui_do_label(&button, "Name:", 14.0, -1);
ui_vsplit_l(&button, 80.0f, 0, &button);
ui_vsplit_l(&button, 180.0f, &button, 0);
ui_do_edit_box(config.player_name, &button, config.player_name, sizeof(config.player_name), 14.0f);
if(ui_do_edit_box(config.player_name, &button, config.player_name, sizeof(config.player_name), 14.0f))
need_sendinfo = true;
static int dynamic_camera_button = 0;
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
@ -98,7 +99,10 @@ void MENUS::render_settings_player(RECT main_view)
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.player_color_body, "Custom colors", config.player_use_custom_color, &button, ui_draw_checkbox, 0))
{
config.player_use_custom_color = config.player_use_custom_color?0:1;
need_sendinfo = true;
}
if(config.player_use_custom_color)
{
@ -136,7 +140,10 @@ void MENUS::render_settings_player(RECT main_view)
ui_do_label(&text, labels[s], 15.0f, -1);
}
if(*colors[i] != color)
need_sendinfo = true;
*colors[i] = color;
ui_hsplit_t(&main_view, 5.0f, 0, &main_view);
}
@ -208,8 +215,11 @@ void MENUS::render_settings_player(RECT main_view)
ui_vsplit_l(&button, 50.0f, &icon, &text);
if(ui_do_button(s, "", selected, &button, ui_draw_list_row, 0))
{
config_set_player_skin(&config, s->name);
need_sendinfo = true;
}
ui_hsplit_t(&text, 12.0f, 0, &text); // some margin from the top
ui_do_label(&text, buf, 18.0f, 0);