Пример #1
0
void MENUS::on_statechange(int new_state, int old_state)
{
	if(new_state == CLIENTSTATE_OFFLINE)
	{
		popup = POPUP_NONE;
		if(client_error_string() && client_error_string()[0] != 0)
		{
			if(strstr(client_error_string(), "password"))
			{
				popup = POPUP_PASSWORD;
				ui_set_hot_item(&config.password);
				ui_set_active_item(&config.password);
			}
			else
				popup = POPUP_DISCONNECTED;
		}	}
	else if(new_state == CLIENTSTATE_LOADING)
	{
		popup = POPUP_CONNECTING;
		client_serverinfo_request();
	}
	else if(new_state == CLIENTSTATE_CONNECTING)
		popup = POPUP_CONNECTING;
	else if (new_state == CLIENTSTATE_ONLINE || new_state == CLIENTSTATE_DEMOPLAYBACK)
	{
		popup = POPUP_NONE;
		set_active(false);
	}
}
Пример #2
0
float MENUS::ui_do_scrollbar_h(const void *id, const RECT *rect, float current)
{
	RECT handle;
	static float offset_x;
	ui_vsplit_l(rect, 33, &handle, 0);

	handle.x += (rect->w-handle.w)*current;

	/* logic */
    float ret = current;
    int inside = ui_mouse_inside(&handle);

	if(ui_active_item() == id)
	{
		if(!ui_mouse_button(0))
			ui_set_active_item(0);
		
		float min = rect->x;
		float max = rect->w-handle.w;
		float cur = ui_mouse_x()-offset_x;
		ret = (cur-min)/max;
		if(ret < 0.0f) ret = 0.0f;
		if(ret > 1.0f) ret = 1.0f;
	}
	else if(ui_hot_item() == id)
	{
		if(ui_mouse_button(0))
		{
			ui_set_active_item(id);
			offset_x = ui_mouse_x()-handle.x;
		}
	}
	
	if(inside)
		ui_set_hot_item(id);

	// render
	RECT rail;
	ui_hmargin(rect, 5.0f, &rail);
	ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f);

	RECT slider = handle;
	slider.h = rail.y-slider.y;
	ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_T, 2.5f);
	slider.y = rail.y+rail.h;
	ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_B, 2.5f);

	slider = handle;
	ui_margin(&slider, 5.0f, &slider);
	ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f);
	
    return ret;
}
Пример #3
0
int MENUS::ui_do_key_reader(void *id, const RECT *rect, int key)
{
	// process
	static void *grabbed_id = 0;
	static bool mouse_released = true;
	int inside = ui_mouse_inside(rect);
	int new_key = key;
	
	if(!ui_mouse_button(0) && grabbed_id == id)
		mouse_released = true;

	if(ui_active_item() == id)
	{
		if(binder.got_key)
		{
			new_key = binder.key.key;
			binder.got_key = false;
			ui_set_active_item(0);
			mouse_released = false;
			grabbed_id = id;
		}
	}
	else if(ui_hot_item() == id)
	{
		if(ui_mouse_button(0) && mouse_released)
		{
			binder.take_key = true;
			binder.got_key = false;
			ui_set_active_item(id);
		}
	}
	
	if(inside)
		ui_set_hot_item(id);

	// 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;
}
Пример #4
0
void ui_do_popup_menu()
{
	for(int i = 0; i < ui_num_popups; i++)
	{
		bool inside = ui_mouse_inside(&ui_popups[i].rect);
		ui_set_hot_item(&ui_popups[i].id);
		
		if(ui_active_item() == &ui_popups[i].id)
		{
			if(!ui_mouse_button(0))
			{
				if(!inside)
					ui_num_popups--;
				ui_set_active_item(0);
			}
		}
		else if(ui_hot_item() == &ui_popups[i].id)
		{
			if(ui_mouse_button(0))
				ui_set_active_item(&ui_popups[i].id);
		}
		
		int corners = CORNER_ALL;
		if(ui_popups[i].is_menu)
			corners = CORNER_R|CORNER_B;
		
		RECT r = ui_popups[i].rect;
		ui_draw_rect(&r, vec4(0.5f,0.5f,0.5f,0.75f), corners, 3.0f);
		ui_margin(&r, 1.0f, &r);
		ui_draw_rect(&r, vec4(0,0,0,0.75f), corners, 3.0f);
		ui_margin(&r, 4.0f, &r);
		
		if(ui_popups[i].func(r))
			ui_num_popups--;
			
		if(inp_key_down(KEY_ESCAPE))
			ui_num_popups--;
	}
}
Пример #5
0
int MENUS::ui_do_edit_box(void *id, const RECT *rect, char *str, unsigned str_size, float font_size, bool hidden)
{
    int inside = ui_mouse_inside(rect);
	int r = 0;
	static int at_index = 0;

	if(ui_last_active_item() == id)
	{
		int len = strlen(str);
			
		if (inside && ui_mouse_button(0))
		{
			int mx_rel = (int)(ui_mouse_x() - rect->x);

			for (int i = 1; i <= len; i++)
			{
				if (gfx_text_width(0, font_size, str, i) + 10 > mx_rel)
				{
					at_index = i - 1;
					break;
				}

				if (i == len)
					at_index = len;
			}
		}

		for(int i = 0; i < num_inputevents; i++)
		{
			len = strlen(str);
			LINEINPUT::manipulate(inputevents[i], str, str_size, &len, &at_index);
		}
	}

	bool just_got_active = false;
	
	if(ui_active_item() == id)
	{
		if(!ui_mouse_button(0))
			ui_set_active_item(0);
	}
	else if(ui_hot_item() == id)
	{
		if(ui_mouse_button(0))
		{
			if (ui_last_active_item() != id)
				just_got_active = true;
			ui_set_active_item(id);
		}
	}
	
	if(inside)
		ui_set_hot_item(id);

	RECT textbox = *rect;
	ui_draw_rect(&textbox, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
	ui_vmargin(&textbox, 5.0f, &textbox);
	
	const char *display_str = str;
	char stars[128];
	
	if(hidden)
	{
		unsigned s = strlen(str);
		if(s >= sizeof(stars))
			s = sizeof(stars)-1;
		memset(stars, '*', s);
		stars[s] = 0;
		display_str = stars;
	}

	ui_do_label(&textbox, display_str, font_size, -1);
	
	if (ui_last_active_item() == id && !just_got_active)
	{
		float w = gfx_text_width(0, font_size, display_str, at_index);
		textbox.x += w*ui_scale();
		ui_do_label(&textbox, "_", font_size, -1);
	}

	return r;
}
Пример #6
0
void MENUS::render_demoplayer(RECT main_view)
{
	const DEMOPLAYBACK_INFO *info = client_demoplayer_getinfo();
	
	const float seekbar_height = 15.0f;
	const float buttonbar_height = 20.0f;
	const float margins = 5.0f;
	float total_height;
	
	if(menu_active)
	{
		total_height = seekbar_height+buttonbar_height+margins*3;
	/*
	else
		total_height = seekbar_height+margins*2;
	*/
	
		ui_hsplit_b(&main_view, total_height, 0, &main_view);
		ui_vsplit_l(&main_view, 250.0f, 0, &main_view);
		ui_vsplit_r(&main_view, 250.0f, &main_view, 0);
	
		ui_draw_rect(&main_view, color_tabbar_active, CORNER_T, 10.0f);
		
		ui_margin(&main_view, 5.0f, &main_view);
	}
	
	RECT seekbar, buttonbar;
	
	if(menu_active)
	{
		ui_hsplit_t(&main_view, seekbar_height, &seekbar, &buttonbar);
		ui_hsplit_t(&buttonbar, margins, 0, &buttonbar);
	}
	/*
	else
		seekbar = main_view;
	*/
	
	// do seekbar
	if(menu_active)
	{
		static int seekbar_id = 0;
		void *id = &seekbar_id;
		char buffer[128];
		
		ui_draw_rect(&seekbar, vec4(0,0,0,0.5f), CORNER_ALL, 5.0f);
		
		int current_tick = info->current_tick - info->first_tick;
		int total_ticks = info->last_tick - info->first_tick;
		
		float amount = current_tick/(float)total_ticks;
		
		RECT filledbar = seekbar;
		filledbar.w = 10.0f + (filledbar.w-10.0f)*amount;
		
		ui_draw_rect(&filledbar, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
		
		str_format(buffer, sizeof(buffer), "%d:%02d / %d:%02d",
			current_tick/SERVER_TICK_SPEED/60, (current_tick/SERVER_TICK_SPEED)%60,
			total_ticks/SERVER_TICK_SPEED/60, (total_ticks/SERVER_TICK_SPEED)%60);
		ui_do_label(&seekbar, buffer, seekbar.h*0.70f, 0);

		// do the logic
	    int inside = ui_mouse_inside(&seekbar);
			
		if(ui_active_item() == id)
		{
			if(!ui_mouse_button(0))
				ui_set_active_item(0);
			else
			{
				float amount = (ui_mouse_x()-seekbar.x)/(float)seekbar.w;
				if(amount > 0 && amount < 1.0f)
				{
					gameclient.on_reset();
					gameclient.suppress_events = true;
					client_demoplayer_setpos(amount);
					gameclient.suppress_events = false;
				}
			}
		}
		else if(ui_hot_item() == id)
		{
			if(ui_mouse_button(0))
				ui_set_active_item(id);
		}		
		
		if(inside)
			ui_set_hot_item(id);
	}	
	

	if(menu_active)
	{
		// do buttons
		RECT button;

		// pause button
		ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar);
		static int pause_button = 0;
		if(ui_do_button(&pause_button, "| |", info->paused, &button, ui_draw_demoplayer_button, 0))
			client_demoplayer_setpause(!info->paused);
		
		// play button
		ui_vsplit_l(&buttonbar, margins, 0, &buttonbar);
		ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar);
		static int play_button = 0;
		if(ui_do_button(&play_button, ">", !info->paused, &button, ui_draw_demoplayer_button, 0))
		{
			client_demoplayer_setpause(0);
			client_demoplayer_setspeed(1.0f);
		}

		// slowdown
		ui_vsplit_l(&buttonbar, margins, 0, &buttonbar);
		ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar);
		static int slowdown_button = 0;
		if(ui_do_button(&slowdown_button, "<<", 0, &button, ui_draw_demoplayer_button, 0))
		{
			if(info->speed > 4.0f) client_demoplayer_setspeed(4.0f);
			else if(info->speed > 2.0f) client_demoplayer_setspeed(2.0f);
			else if(info->speed > 1.0f) client_demoplayer_setspeed(1.0f);
			else if(info->speed > 0.5f) client_demoplayer_setspeed(0.5f);
			else client_demoplayer_setspeed(0.05f);
		}
		
		// fastforward
		ui_vsplit_l(&buttonbar, margins, 0, &buttonbar);
		ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar);
		static int fastforward_button = 0;
		if(ui_do_button(&fastforward_button, ">>", 0, &button, ui_draw_demoplayer_button, 0))
		{
			if(info->speed < 0.5f) client_demoplayer_setspeed(0.5f);
			else if(info->speed < 1.0f) client_demoplayer_setspeed(1.0f);
			else if(info->speed < 2.0f) client_demoplayer_setspeed(2.0f);
			else if(info->speed < 4.0f) client_demoplayer_setspeed(4.0f);
			else client_demoplayer_setspeed(8.0f);
		}

		// speed meter
		ui_vsplit_l(&buttonbar, margins*3, 0, &buttonbar);
		char buffer[64];
		if(info->speed >= 1.0f)
			str_format(buffer, sizeof(buffer), "x%.0f", info->speed);
		else
			str_format(buffer, sizeof(buffer), "x%.1f", info->speed);
		ui_do_label(&buttonbar, buffer, button.h*0.7f, -1);

		// exit button
		ui_vsplit_r(&buttonbar, buttonbar_height*3, &buttonbar, &button);
		static int exit_button = 0;
		if(ui_do_button(&exit_button, "Exit", 0, &button, ui_draw_demoplayer_button, 0))
			client_disconnect();
	}
}