ddnet/src/game/client/gc_menu.cpp

2027 lines
55 KiB
C++
Raw Normal View History

2007-11-25 19:42:40 +00:00
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
2007-11-04 21:36:03 +00:00
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
2007-12-15 10:24:49 +00:00
#include <game/g_math.h>
#include <game/g_vmath.h>
2007-11-04 21:36:03 +00:00
extern "C" {
2007-12-15 10:24:49 +00:00
#include <engine/e_system.h>
#include <engine/e_client_interface.h>
2007-12-15 10:24:49 +00:00
#include <engine/e_config.h>
2007-12-24 13:09:34 +00:00
#include <engine/client/ec_font.h>
2007-11-04 21:36:03 +00:00
}
2007-12-15 10:24:49 +00:00
#include "../g_version.h"
#include "../g_protocol.h"
2007-11-04 21:36:03 +00:00
2007-12-15 10:24:49 +00:00
#include "../generated/gc_data.h"
#include "gc_render.h"
2008-01-12 17:09:00 +00:00
#include "gc_anim.h"
2007-12-15 10:24:49 +00:00
#include "gc_skin.h"
2008-01-12 15:07:57 +00:00
#include "gc_ui.h"
2007-11-04 21:36:03 +00:00
#include <mastersrv/mastersrv.h>
extern data_container *data;
2007-11-18 14:49:56 +00:00
// abit uglyness
extern const obj_player_info *local_info;
extern const obj_game *gameobj;
2007-11-18 14:49:56 +00:00
extern bool menu_active;
extern bool menu_game_active;
2007-11-18 14:49:56 +00:00
2007-12-19 20:30:09 +00:00
static bool need_restart = false;
2007-12-09 17:25:16 +00:00
enum
{
POPUP_NONE=0,
2007-12-16 22:34:43 +00:00
POPUP_FIRST_LAUNCH,
2007-12-09 17:25:16 +00:00
POPUP_CONNECTING,
POPUP_DISCONNECTED,
POPUP_PASSWORD,
POPUP_QUIT,
};
static int popup = POPUP_NONE;
2007-11-18 14:49:56 +00:00
2007-11-05 23:05:02 +00:00
static vec4 gui_color(0.65f,0.78f,0.9f, 0.5f);
2007-11-04 21:36:03 +00:00
2007-11-04 22:30:08 +00:00
static vec4 color_tabbar_inactive_outgame(0,0,0,0.25f);
static vec4 color_tabbar_active_outgame(0,0,0,0.5f);
static float color_ingame_scale_i = 0.5f;
static float color_ingame_scale_a = 0.2f;
static vec4 color_tabbar_inactive_ingame(gui_color.r*color_ingame_scale_i, gui_color.g*color_ingame_scale_i, gui_color.b*color_ingame_scale_i,0.75f);
static vec4 color_tabbar_active_ingame(gui_color.r*color_ingame_scale_a, gui_color.g*color_ingame_scale_a, gui_color.b*color_ingame_scale_a,0.85f);
static vec4 color_tabbar_inactive = color_tabbar_inactive_outgame;
static vec4 color_tabbar_active = color_tabbar_active_outgame;
2007-11-04 21:36:03 +00:00
enum
{
PAGE_NEWS=0,
PAGE_INTERNET,
PAGE_LAN,
PAGE_FAVORITES,
PAGE_SETTINGS,
PAGE_SYSTEM,
2007-11-04 21:36:03 +00:00
};
2008-01-12 15:07:57 +00:00
static void ui_draw_browse_icon(int what, const RECT *r)
{
gfx_texture_set(data->images[IMAGE_BROWSEICONS].id);
gfx_quads_begin();
2007-12-09 13:17:11 +00:00
select_sprite(SPRITE_BROWSE_PROGRESS1); // default
if(what == -1)
{
}
else if(what <= 100)
{
2007-12-09 13:17:11 +00:00
if(what < 66)
select_sprite(SPRITE_BROWSE_PROGRESS2);
else
select_sprite(SPRITE_BROWSE_PROGRESS3);
}
2007-12-09 13:17:11 +00:00
else if(what&0x100)
{
select_sprite(SPRITE_BROWSE_LOCK);
}
gfx_quads_drawTL(r->x,r->y,r->w,r->h);
gfx_quads_end();
}
2008-01-12 15:07:57 +00:00
static void ui_draw_menu_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
2007-11-04 21:36:03 +00:00
{
2008-01-12 15:07:57 +00:00
ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
ui_do_label(r, text, 18.0f, 0);
2007-11-04 22:30:08 +00:00
}
2008-01-12 15:07:57 +00:00
static void ui_draw_keyselect_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
2007-11-04 22:30:08 +00:00
{
2008-01-12 15:07:57 +00:00
ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
ui_do_label(r, text, 14.0f, 0);
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
static void ui_draw_menu_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
2007-11-04 21:36:03 +00:00
{
if(checked)
2008-01-12 15:07:57 +00:00
ui_draw_rect(r, color_tabbar_active, CORNER_T, 10.0f);
2007-11-04 21:36:03 +00:00
else
2008-01-12 15:07:57 +00:00
ui_draw_rect(r, color_tabbar_inactive, CORNER_T, 10.0f);
ui_do_label(r, text, 22.0f, 0);
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
static void ui_draw_settings_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
2007-11-04 21:36:03 +00:00
{
if(checked)
2008-01-12 15:07:57 +00:00
ui_draw_rect(r, color_tabbar_active, CORNER_R, 10.0f);
2007-11-04 21:36:03 +00:00
else
2008-01-12 15:07:57 +00:00
ui_draw_rect(r, color_tabbar_inactive, CORNER_R, 10.0f);
ui_do_label(r, text, 20.0f, 0);
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
static void ui_draw_grid_header(const void *id, const char *text, int checked, const RECT *r, const void *extra)
2007-11-04 21:36:03 +00:00
{
if(checked)
2008-01-12 15:07:57 +00:00
ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_T, 5.0f);
2007-11-04 21:36:03 +00:00
RECT t;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(r, 5.0f, 0, &t);
ui_do_label(&t, text, 14.0f, -1);
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
static void ui_draw_list_row(const void *id, const char *text, int checked, const RECT *r, const void *extra)
2007-11-04 21:36:03 +00:00
{
if(checked)
{
RECT sr = *r;
2008-01-12 15:07:57 +00:00
ui_margin(&sr, 1.5f, &sr);
ui_draw_rect(&sr, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f);
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
ui_do_label(r, text, 14.0f, -1);
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
static void ui_draw_checkbox_common(const void *id, const char *text, const char *boxtext, const RECT *r)
2007-11-04 21:36:03 +00:00
{
RECT c = *r;
RECT t = *r;
c.w = c.h;
t.x += c.w;
t.w -= c.w;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&t, 5.0f, 0, &t);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_margin(&c, 2.0f, &c);
ui_draw_rect(&c, vec4(1,1,1,0.25f), CORNER_ALL, 3.0f);
2008-01-11 16:48:34 +00:00
c.y += 2;
2008-01-12 15:07:57 +00:00
ui_do_label(&c, boxtext, 12.0f, 0);
ui_do_label(&t, text, 14.0f, -1);
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
static void ui_draw_checkbox(const void *id, const char *text, int checked, const RECT *r, const void *extra)
2007-11-05 23:05:02 +00:00
{
2008-01-12 15:07:57 +00:00
ui_draw_checkbox_common(id, text, checked?"X":"", r);
2007-11-05 23:05:02 +00:00
}
2008-01-12 12:08:26 +00:00
2008-01-12 15:07:57 +00:00
static void ui_draw_checkbox_number(const void *id, const char *text, int checked, const RECT *r, const void *extra)
2007-11-04 21:36:03 +00:00
{
char buf[16];
sprintf(buf, "%d", checked);
2008-01-12 15:07:57 +00:00
ui_draw_checkbox_common(id, text, buf, r);
2007-11-04 21:36:03 +00:00
}
2008-01-13 16:30:30 +00:00
int ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float font_size, bool hidden=false)
2007-11-04 21:36:03 +00:00
{
2008-01-12 12:27:55 +00:00
int inside = ui_mouse_inside(rect);
2007-11-04 21:36:03 +00:00
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++)
{
2008-01-13 16:30:30 +00:00
if (gfx_text_width(0, font_size, str, i) + 10 > mx_rel)
2007-11-04 21:36:03 +00:00
{
at_index = i - 1;
break;
}
if (i == len)
at_index = len;
}
}
if (at_index > len)
at_index = len;
2008-01-12 12:08:26 +00:00
for(int i = 0; i < inp_num_events(); i++)
2007-11-04 21:36:03 +00:00
{
INPUT_EVENT e = inp_get_event(i);
2008-01-12 12:08:26 +00:00
char c = e.ch;
int k = e.key;
if (!(c >= 0 && c < 32))
2007-11-04 21:36:03 +00:00
{
2008-01-12 12:08:26 +00:00
if (len < str_size - 1 && at_index < str_size - 1)
{
memmove(str + at_index + 1, str + at_index, len - at_index + 1);
str[at_index] = c;
at_index++;
}
2007-11-04 21:36:03 +00:00
}
2008-01-12 12:08:26 +00:00
if (k == KEY_BACKSPACE && at_index > 0)
{
memmove(str + at_index - 1, str + at_index, len - at_index + 1);
at_index--;
}
else if (k == KEY_DEL && at_index < len)
memmove(str + at_index, str + at_index + 1, len - at_index);
else if (k == KEY_ENTER)
ui_clear_last_active_item();
else if (k == KEY_LEFT && at_index > 0)
at_index--;
else if (k == KEY_RIGHT && at_index < len)
at_index++;
else if (k == KEY_HOME)
at_index = 0;
else if (k == KEY_END)
at_index = len;
2007-11-04 21:36:03 +00:00
}
2008-01-12 12:08:26 +00:00
2007-11-04 21:36:03 +00:00
r = 1;
}
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;
2008-01-12 15:07:57 +00:00
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;
}
2008-01-13 16:30:30 +00:00
ui_do_label(&textbox, display_str, font_size, -1);
2007-11-04 21:36:03 +00:00
if (ui_last_active_item() == id && !just_got_active)
{
2008-01-13 16:30:30 +00:00
float w = gfx_text_width(0, font_size, display_str, at_index);
2008-01-12 15:07:57 +00:00
textbox.x += w*ui_scale();
2008-01-13 16:30:30 +00:00
ui_do_label(&textbox, "_", font_size, -1);
2007-11-04 21:36:03 +00:00
}
return r;
}
2008-01-12 15:07:57 +00:00
float ui_do_scrollbar_v(const void *id, const RECT *rect, float current)
2007-11-04 21:36:03 +00:00
{
RECT handle;
static float offset_y;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(rect, 33, &handle, 0);
2007-11-04 21:36:03 +00:00
handle.y += (rect->h-handle.h)*current;
/* logic */
float ret = current;
2008-01-12 12:27:55 +00:00
int inside = ui_mouse_inside(&handle);
2007-11-04 21:36:03 +00:00
if(ui_active_item() == id)
{
if(!ui_mouse_button(0))
ui_set_active_item(0);
float min = rect->y;
float max = rect->h-handle.h;
float cur = ui_mouse_y()-offset_y;
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_y = ui_mouse_y()-handle.y;
}
}
if(inside)
ui_set_hot_item(id);
// render
RECT rail;
2008-01-12 15:07:57 +00:00
ui_vmargin(rect, 5.0f, &rail);
ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f);
2007-11-04 21:36:03 +00:00
RECT slider = handle;
slider.w = rail.x-slider.x;
2008-01-12 15:07:57 +00:00
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_L, 2.5f);
2007-11-04 21:36:03 +00:00
slider.x = rail.x+rail.w;
2008-01-12 15:07:57 +00:00
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_R, 2.5f);
2007-11-04 21:36:03 +00:00
slider = handle;
2008-01-12 15:07:57 +00:00
ui_margin(&slider, 5.0f, &slider);
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_ALL, 2.5f);
2007-11-04 21:36:03 +00:00
return ret;
}
2008-01-12 15:07:57 +00:00
float ui_do_scrollbar_h(const void *id, const RECT *rect, float current)
{
RECT handle;
static float offset_x;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(rect, 33, &handle, 0);
handle.x += (rect->w-handle.w)*current;
/* logic */
float ret = current;
2008-01-12 12:27:55 +00:00
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;
2008-01-12 15:07:57 +00:00
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;
2008-01-12 15:07:57 +00:00
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_T, 2.5f);
slider.y = rail.y+rail.h;
2008-01-12 15:07:57 +00:00
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_B, 2.5f);
slider = handle;
2008-01-12 15:07:57 +00:00
ui_margin(&slider, 5.0f, &slider);
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_ALL, 2.5f);
return ret;
}
2008-01-12 15:07:57 +00:00
int ui_do_key_reader(void *id, const RECT *rect, int key)
2007-11-04 21:36:03 +00:00
{
// process
static bool mouse_released = true;
2008-01-12 12:27:55 +00:00
int inside = ui_mouse_inside(rect);
2007-11-04 21:36:03 +00:00
int new_key = key;
if(!ui_mouse_button(0))
mouse_released = true;
if(ui_active_item() == id)
{
2008-01-12 12:08:26 +00:00
for(int i = 0; i < inp_num_events(); i++)
2007-11-04 21:36:03 +00:00
{
INPUT_EVENT e = inp_get_event(i);
2008-01-12 12:08:26 +00:00
if(e.key && e.key != KEY_ESC)
{
new_key = e.key;
ui_set_active_item(0);
mouse_released = false;
inp_clear_events();
break;
}
2007-11-04 21:36:03 +00:00
}
}
else if(ui_hot_item() == id)
{
if(ui_mouse_button(0) && mouse_released)
ui_set_active_item(id);
}
if(inside)
ui_set_hot_item(id);
// draw
if (ui_active_item() == id)
2008-01-12 15:07:57 +00:00
ui_draw_keyselect_button(id, "???", 0, rect, 0);
2007-11-04 21:36:03 +00:00
else
2008-01-12 15:07:57 +00:00
ui_draw_keyselect_button(id, inp_key_name(key), 0, rect, 0);
2007-11-04 21:36:03 +00:00
return new_key;
}
static int menu2_render_menubar(RECT r)
{
RECT box = r;
RECT button;
int active_page = config.ui_page;
int new_page = -1;
if(menu_game_active)
active_page = -1;
2007-11-04 22:30:08 +00:00
if(client_state() == CLIENTSTATE_OFFLINE)
{
if(0) // this is not done yet
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&box, 90.0f, &button, &box);
static int news_button=0;
2008-01-12 15:07:57 +00:00
if (ui_do_button(&news_button, "News", active_page==PAGE_NEWS, &button, ui_draw_menu_tab_button, 0))
new_page = PAGE_NEWS;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&box, 30.0f, 0, &box);
}
2007-11-04 22:30:08 +00:00
}
else
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&box, 90.0f, &button, &box);
2007-11-04 22:30:08 +00:00
static int game_button=0;
2008-01-12 15:07:57 +00:00
if (ui_do_button(&game_button, "Game", menu_game_active, &button, ui_draw_menu_tab_button, 0))
menu_game_active = true;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&box, 30.0f, 0, &box);
2007-11-04 22:30:08 +00:00
}
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&box, 110.0f, &button, &box);
2007-11-04 21:36:03 +00:00
static int internet_button=0;
2008-01-12 15:07:57 +00:00
if (ui_do_button(&internet_button, "Internet", active_page==PAGE_INTERNET, &button, ui_draw_menu_tab_button, 0))
{
client_serverbrowse_refresh(0);
new_page = PAGE_INTERNET;
}
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&box, 4.0f, 0, &box);
ui_vsplit_l(&box, 90.0f, &button, &box);
2007-11-04 21:36:03 +00:00
static int lan_button=0;
2008-01-12 15:07:57 +00:00
if (ui_do_button(&lan_button, "LAN", active_page==PAGE_LAN, &button, ui_draw_menu_tab_button, 0))
{
client_serverbrowse_refresh(1);
new_page = PAGE_LAN;
}
2007-11-04 21:36:03 +00:00
if(0) // this one is not done yet
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&box, 4.0f, 0, &box);
ui_vsplit_l(&box, 120.0f, &button, &box);
static int favorites_button=0;
2008-01-12 15:07:57 +00:00
if (ui_do_button(&favorites_button, "Favorites", active_page==PAGE_FAVORITES, &button, ui_draw_menu_tab_button, 0))
new_page = PAGE_FAVORITES;
}
2007-11-04 21:36:03 +00:00
/*
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&box, 110.0f, &box, &button);
static int system_button=0;
2008-01-12 15:07:57 +00:00
if (ui_do_button(&system_button, "System", config.ui_page==PAGE_SYSTEM, &button, ui_draw_menu_tab_button, 0))
config.ui_page = PAGE_SYSTEM;
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&box, 30.0f, &box, 0);
*/
2007-12-09 17:25:16 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&box, 110.0f, &box, &button);
2007-12-09 17:25:16 +00:00
static int quit_button=0;
2008-01-12 15:07:57 +00:00
if (ui_do_button(&quit_button, "Quit", 0, &button, ui_draw_menu_tab_button, 0))
2007-12-09 17:25:16 +00:00
popup = POPUP_QUIT;
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&box, 10.0f, &box, &button);
ui_vsplit_r(&box, 110.0f, &box, &button);
2007-11-04 21:36:03 +00:00
static int settings_button=0;
2008-01-12 15:07:57 +00:00
if (ui_do_button(&settings_button, "Settings", active_page==PAGE_SETTINGS, &button, ui_draw_menu_tab_button, 0))
new_page = PAGE_SETTINGS;
if(new_page != -1)
{
config.ui_page = new_page;
menu_game_active = false;
}
2007-11-04 21:36:03 +00:00
return 0;
}
static void menu2_render_background()
{
2008-01-12 15:07:57 +00:00
RECT s = *ui_screen();
2007-12-17 00:44:03 +00:00
gfx_texture_set(-1);
2007-11-04 21:36:03 +00:00
gfx_quads_begin();
2007-12-17 00:44:03 +00:00
vec4 bottom(gui_color.r*0.6f, gui_color.g*0.6f, gui_color.b*0.6f, 1.0f);
vec4 top(gui_color.r, gui_color.g, gui_color.b, 1.0f);
gfx_setcolorvertex(0, top.r, top.g, top.b, top.a);
gfx_setcolorvertex(1, top.r, top.g, top.b, top.a);
gfx_setcolorvertex(2, bottom.r, bottom.g, bottom.b, bottom.a);
gfx_setcolorvertex(3, bottom.r, bottom.g, bottom.b, bottom.a);
gfx_quads_drawTL(0, 0, s.w, s.h);
2007-11-04 21:36:03 +00:00
gfx_quads_end();
2007-12-17 00:44:03 +00:00
if(data->images[IMAGE_BANNER].id != 0)
{
gfx_texture_set(data->images[IMAGE_BANNER].id);
gfx_quads_begin();
gfx_setcolor(0,0,0,0.05f);
gfx_quads_setrotation(-pi/4+0.15f);
gfx_quads_draw(400, 300, 1000, 250);
gfx_quads_end();
}
2007-11-04 21:36:03 +00:00
}
2007-12-25 14:49:51 +00:00
extern "C" void *gfx_font_set;
2007-12-15 13:19:44 +00:00
void render_loading(float percent)
{
// need up date this here to get correct
vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);
2008-01-12 15:07:57 +00:00
RECT screen = *ui_screen();
2007-12-15 13:19:44 +00:00
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
2007-12-17 00:44:03 +00:00
menu2_render_background();
2007-12-15 13:19:44 +00:00
float tw;
float w = 700;
float h = 200;
float x = screen.w/2-w/2;
float y = screen.h/2-h/2;
gfx_blend_normal();
gfx_texture_set(-1);
gfx_quads_begin();
gfx_setcolor(0,0,0,0.50f);
draw_round_rect(x, y, w, h, 40.0f);
gfx_quads_end();
const char *caption = "Loading";
2008-01-12 15:07:57 +00:00
tw = gfx_text_width(0, 48.0f, caption, -1);
2008-01-12 12:27:55 +00:00
RECT r;
r.x = x+w/2;
r.y = y+20;
ui_do_label(&r, caption, 48.0f, 0, -1);
2007-12-15 13:19:44 +00:00
gfx_texture_set(-1);
gfx_quads_begin();
2007-12-17 00:44:03 +00:00
gfx_setcolor(1,1,1,0.75f);
2007-12-15 13:19:44 +00:00
draw_round_rect(x+40, y+h-75, (w-80)*percent, 25, 5.0f);
gfx_quads_end();
gfx_swap();
}
2007-11-04 21:36:03 +00:00
static void menu2_render_serverbrowser(RECT main_view)
{
2008-01-12 15:07:57 +00:00
ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
2007-11-04 21:36:03 +00:00
RECT view;
2008-01-12 15:07:57 +00:00
ui_margin(&main_view, 10.0f, &view);
2007-11-04 21:36:03 +00:00
RECT headers;
RECT filters;
RECT status;
RECT toolbox;
2008-01-11 16:48:34 +00:00
RECT server_details;
RECT server_scoreboard;
2008-01-12 15:07:57 +00:00
//ui_hsplit_t(&view, 20.0f, &status, &view);
ui_hsplit_b(&view, 110.0f, &view, &filters);
2008-01-11 16:48:34 +00:00
// split off a piece for details and scoreboard
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&view, 200.0f, &view, &server_details);
2008-01-11 16:48:34 +00:00
// server list
2008-01-13 22:03:32 +00:00
ui_hsplit_t(&view, 16.0f, &headers, &view);
2008-01-12 15:07:57 +00:00
//ui_hsplit_b(&view, 110.0f, &view, &filters);
ui_hsplit_b(&view, 5.0f, &view, 0);
ui_hsplit_b(&view, 20.0f, &view, &status);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
//ui_vsplit_r(&filters, 300.0f, &filters, &toolbox);
//ui_vsplit_r(&filters, 150.0f, &filters, 0);
2007-12-15 13:19:44 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_mid(&filters, &filters, &toolbox);
ui_vsplit_r(&filters, 50.0f, &filters, 0);
2007-11-04 21:36:03 +00:00
// split of the scrollbar
2008-01-12 15:07:57 +00:00
ui_draw_rect(&headers, vec4(1,1,1,0.25f), CORNER_T, 5.0f);
ui_vsplit_r(&headers, 20.0f, &headers, 0);
2007-11-04 21:36:03 +00:00
struct column
{
int id;
int sort;
const char *caption;
int direction;
float width;
int flags;
RECT rect;
RECT spacer;
};
enum
{
FIXED=1,
SPACER=2,
2007-11-08 09:11:32 +00:00
COL_FLAGS=0,
2007-11-04 21:36:03 +00:00
COL_NAME,
2007-11-08 09:11:32 +00:00
COL_GAMETYPE,
2007-11-04 21:36:03 +00:00
COL_MAP,
COL_PLAYERS,
COL_PING,
2007-11-08 09:11:32 +00:00
COL_PROGRESS,
COL_VERSION,
2007-11-04 21:36:03 +00:00
};
static column cols[] = {
2007-11-08 09:11:32 +00:00
{-1, -1, " ", -1, 10.0f, 0, {0}, {0}},
{COL_FLAGS, -1, " ", -1, 20.0f, 0, {0}, {0}},
2007-11-04 21:36:03 +00:00
{COL_NAME, BROWSESORT_NAME, "Name", 0, 300.0f, 0, {0}, {0}},
2007-11-08 09:11:32 +00:00
{COL_GAMETYPE, BROWSESORT_GAMETYPE, "Type", 1, 50.0f, 0, {0}, {0}},
2007-11-04 21:36:03 +00:00
{COL_MAP, BROWSESORT_MAP, "Map", 1, 100.0f, 0, {0}, {0}},
{COL_PLAYERS, BROWSESORT_NUMPLAYERS, "Players", 1, 60.0f, 0, {0}, {0}},
{-1, -1, " ", 1, 10.0f, 0, {0}, {0}},
2008-01-11 16:48:34 +00:00
//{COL_VERSION, -1, "Ver", 1, 45.0f, FIXED, {0}, {0}},
{-1, -1, " ", 1, 5.0f, 0, {0}, {0}},
2008-01-11 16:48:34 +00:00
//{COL_PROGRESS, BROWSESORT_PROGRESSION, "%", 1, 20.0f, FIXED, {0}, {0}},
2008-01-13 22:03:32 +00:00
{COL_PING, BROWSESORT_PING, "Ping", 1, 25.0f, FIXED, {0}, {0}},
2007-11-04 21:36:03 +00:00
};
int num_cols = sizeof(cols)/sizeof(column);
// do layout
for(int i = 0; i < num_cols; i++)
{
if(cols[i].direction == -1)
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&headers, cols[i].width, &cols[i].rect, &headers);
2007-11-04 21:36:03 +00:00
if(i+1 < num_cols)
{
//cols[i].flags |= SPACER;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&headers, 2, &cols[i].spacer, &headers);
2007-11-04 21:36:03 +00:00
}
}
}
for(int i = num_cols-1; i >= 0; i--)
{
if(cols[i].direction == 1)
{
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&headers, cols[i].width, &headers, &cols[i].rect);
ui_vsplit_r(&headers, 2, &headers, &cols[i].spacer);
2007-11-04 21:36:03 +00:00
}
}
2007-11-04 21:36:03 +00:00
for(int i = 0; i < num_cols; i++)
{
if(cols[i].direction == 0)
cols[i].rect = headers;
}
// do headers
for(int i = 0; i < num_cols; i++)
{
2008-01-12 15:07:57 +00:00
if(ui_do_button(cols[i].caption, cols[i].caption, config.b_sort == cols[i].sort, &cols[i].rect, ui_draw_grid_header, 0))
2007-11-08 09:11:32 +00:00
{
if(cols[i].sort != -1)
2007-12-16 23:09:36 +00:00
{
if(config.b_sort == cols[i].sort)
config.b_sort_order ^= 1;
else
config.b_sort_order = 0;
2007-11-08 09:11:32 +00:00
config.b_sort = cols[i].sort;
2007-12-16 23:09:36 +00:00
}
2007-11-08 09:11:32 +00:00
}
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
ui_draw_rect(&view, vec4(0,0,0,0.15f), 0, 0);
2007-11-05 23:05:02 +00:00
2007-11-04 21:36:03 +00:00
RECT scroll;
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&view, 15, &view, &scroll);
2007-11-04 21:36:03 +00:00
int num_servers = client_serverbrowse_sorted_num();
int num = (int)(view.h/cols[0].rect.h);
static int scrollbar = 0;
static float scrollvalue = 0;
2008-01-12 12:08:26 +00:00
//static int selected_index = -1;
2008-01-12 15:07:57 +00:00
ui_hmargin(&scroll, 5.0f, &scroll);
scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue);
int scrollnum = num_servers-num+10;
if(scrollnum > 0)
{
if(inp_key_presses(KEY_MOUSE_WHEEL_UP))
scrollvalue -= 1.0f/scrollnum;
if(inp_key_presses(KEY_MOUSE_WHEEL_DOWN))
scrollvalue += 1.0f/scrollnum;
if(scrollvalue < 0) scrollvalue = 0;
if(scrollvalue > 1) scrollvalue = 1;
}
else
scrollnum = 0;
2007-11-04 21:36:03 +00:00
// set clipping
2008-01-12 15:07:57 +00:00
ui_clip_enable(&view);
int start = (int)(scrollnum*scrollvalue);
2007-11-04 21:36:03 +00:00
if(start < 0)
start = 0;
2007-12-18 21:13:09 +00:00
RECT original_view = view;
view.y -= scrollvalue*scrollnum*cols[0].rect.h;
2007-11-04 21:36:03 +00:00
2008-01-12 12:08:26 +00:00
int new_selected = -1;
int selected_index = -1;
2007-11-08 09:11:32 +00:00
for (int i = 0; i < num_servers; i++)
2007-11-04 21:36:03 +00:00
{
int item_index = i;
2007-11-05 23:05:02 +00:00
SERVER_INFO *item = client_serverbrowse_sorted_get(item_index);
2007-11-04 21:36:03 +00:00
RECT row;
RECT select_hit_box;
2007-11-04 21:36:03 +00:00
2008-01-12 12:08:26 +00:00
int selected = strcmp(item->address, config.ui_server_address) == 0; //selected_index==item_index;
2007-11-04 21:36:03 +00:00
2008-01-13 22:03:32 +00:00
/*
2008-01-12 12:08:26 +00:00
if(selected)
2007-11-04 21:36:03 +00:00
{
2008-01-12 12:08:26 +00:00
selected_index = i;
2007-11-08 09:11:32 +00:00
// selected server, draw the players on it
2007-11-05 23:05:02 +00:00
RECT whole;
int h = (item->num_players+2)/3;
2007-11-08 09:11:32 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&view, 25.0f+h*15.0f, &whole, &view);
select_hit_box = whole;
2007-11-05 23:05:02 +00:00
RECT r = whole;
2008-01-12 15:07:57 +00:00
ui_margin(&r, 1.5f, &r);
ui_draw_rect(&r, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&whole, 20.0f, &row, &whole);
ui_vsplit_l(&whole, 50.0f, 0, &whole);
2007-11-05 23:05:02 +00:00
for(int p = 0; p < item->num_players; p+=3)
{
RECT player_row;
RECT player_rect;
RECT player_score;
RECT player_name;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&whole, 15.0f, &player_row, &whole);
2007-11-05 23:05:02 +00:00
for(int a = 0; a < 3; a++)
{
if(p+a >= item->num_players)
break;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&player_row, 170.0f, &player_rect, &player_row);
ui_vsplit_l(&player_rect, 30.0f, &player_score, &player_name);
ui_vsplit_l(&player_name, 10.0f, 0, &player_name);
2007-11-05 23:05:02 +00:00
char buf[32];
sprintf(buf, "%d", item->player_scores[p+a]);
2008-01-12 15:07:57 +00:00
ui_do_label(&player_score, buf, 12.0f, 1);
ui_do_label(&player_name, item->player_names[p+a], 12.0f, -1);
2007-11-05 23:05:02 +00:00
}
}
//k += h*3/4;
2007-11-05 23:05:02 +00:00
}
else
{
2008-01-13 22:03:32 +00:00
*/
ui_hsplit_t(&view, 17.0f, &row, &view);
select_hit_box = row;
2008-01-13 22:03:32 +00:00
//}
if(selected)
{
selected_index = i;
RECT r = row;
ui_margin(&r, 1.5f, &r);
ui_draw_rect(&r, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f);
}
2007-11-04 21:36:03 +00:00
2007-12-18 21:13:09 +00:00
// make sure that only those in view can be selected
if(row.y+row.h > original_view.y)
2007-12-09 13:17:11 +00:00
{
if(select_hit_box.y < original_view.y) // clip the selection
{
select_hit_box.h -= original_view.y-select_hit_box.y;
select_hit_box.y = original_view.y;
}
2008-01-12 15:07:57 +00:00
if(ui_do_button(item, "", selected, &select_hit_box, 0, 0))
2007-12-18 21:13:09 +00:00
{
new_selected = item_index;
}
2007-12-09 13:17:11 +00:00
}
2007-12-18 21:13:09 +00:00
// check if we need to do more
if(row.y > original_view.y+original_view.h)
break;
2007-12-09 13:17:11 +00:00
2007-11-04 21:36:03 +00:00
for(int c = 0; c < num_cols; c++)
{
RECT button;
char temp[64];
button.x = cols[c].rect.x;
button.y = row.y;
button.h = row.h;
button.w = cols[c].rect.w;
2007-12-09 13:17:11 +00:00
//int s = 0;
2007-11-04 21:36:03 +00:00
int id = cols[c].id;
2008-01-12 15:07:57 +00:00
//s = ui_do_button(item, "L", l, &button, ui_draw_browse_icon, 0);
2007-12-09 13:17:11 +00:00
2007-11-08 09:11:32 +00:00
if(id == COL_FLAGS)
2007-11-04 21:36:03 +00:00
{
2007-11-08 09:11:32 +00:00
if(item->flags&1)
2008-01-12 15:07:57 +00:00
ui_draw_browse_icon(0x100, &button);
2007-11-04 21:36:03 +00:00
}
else if(id == COL_NAME)
2008-01-13 22:03:32 +00:00
ui_do_label(&button, item->name, 12.0f, -1);
2007-11-04 21:36:03 +00:00
else if(id == COL_MAP)
2008-01-13 22:03:32 +00:00
ui_do_label(&button, item->map, 12.0f, -1);
2007-11-04 21:36:03 +00:00
else if(id == COL_PLAYERS)
{
sprintf(temp, "%i/%i", item->num_players, item->max_players);
2008-01-13 22:03:32 +00:00
ui_do_label(&button, temp, 12.0f, 1);
2007-11-04 21:36:03 +00:00
}
else if(id == COL_PING)
{
sprintf(temp, "%i", item->latency);
2008-01-13 22:03:32 +00:00
ui_do_label(&button, temp, 12.0f, 1);
2007-11-04 21:36:03 +00:00
}
2007-11-08 09:11:32 +00:00
else if(id == COL_PROGRESS)
{
if(item->progression > 100)
item->progression = 100;
2008-01-12 15:07:57 +00:00
ui_draw_browse_icon(item->progression, &button);
2007-11-08 09:11:32 +00:00
}
else if(id == COL_VERSION)
{
const char *version = item->version;
if(strcmp(version, "0.3 e2d7973c6647a13c") == 0) // TODO: remove me later on
version = "0.3.0";
2008-01-13 22:03:32 +00:00
ui_do_label(&button, version, 12.0f, 1);
}
2007-11-08 09:11:32 +00:00
else if(id == COL_GAMETYPE)
{
const char *type = "???";
if(item->game_type == GAMETYPE_DM) type = "DM";
else if(item->game_type == GAMETYPE_TDM) type = "TDM";
else if(item->game_type == GAMETYPE_CTF) type = "CTF";
2008-01-13 22:03:32 +00:00
ui_do_label(&button, type, 12.0f, 0);
2007-11-08 09:11:32 +00:00
}
2007-11-04 21:36:03 +00:00
}
}
2008-01-12 15:07:57 +00:00
ui_clip_disable();
2007-11-04 21:36:03 +00:00
2008-01-12 12:08:26 +00:00
if(new_selected != -1)
{
// select the new server
SERVER_INFO *item = client_serverbrowse_sorted_get(new_selected);
strncpy(config.ui_server_address, item->address, sizeof(config.ui_server_address));
if(inp_mouse_doubleclick())
client_connect(config.ui_server_address);
}
2008-01-11 16:48:34 +00:00
SERVER_INFO *selected_server = client_serverbrowse_sorted_get(selected_index);
RECT server_header;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&server_details, 10.0f, 0x0, &server_details);
2008-01-11 16:48:34 +00:00
// split off a piece to use for scoreboard
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&server_details, 140.0f, &server_details, &server_scoreboard);
ui_hsplit_b(&server_details, 10.0f, &server_details, 0x0);
2008-01-11 16:48:34 +00:00
// server details
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&server_details, 20.0f, &server_header, &server_details);
ui_draw_rect(&server_header, vec4(1,1,1,0.25f), CORNER_T, 4.0f);
ui_draw_rect(&server_details, vec4(0,0,0,0.15f), CORNER_B, 4.0f);
ui_vsplit_l(&server_header, 8.0f, 0x0, &server_header);
ui_do_label(&server_header, "Server Details: ", 14.0f, -1);
2008-01-11 16:48:34 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details);
2008-01-11 16:48:34 +00:00
2008-01-12 15:07:57 +00:00
ui_margin(&server_details, 3.0f, &server_details);
2008-01-11 16:48:34 +00:00
if (selected_server)
{
const float row_height = 18.0f;
RECT row;
static char *labels[] = { "Version:", "Game Type:", "Progression:", "Ping:" };
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&server_details, row_height, &row, &server_details);
ui_do_label(&row, selected_server->name, 15.0f, -1);
2008-01-11 16:48:34 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&server_details, row_height, &row, &server_details);
ui_vsplit_l(&row, 1.0f, 0x0, &row);
ui_do_label(&row, selected_server->address, 14.0f, -1);
2008-01-11 16:48:34 +00:00
RECT left_column;
RECT right_column;
2007-11-08 09:11:32 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details);
ui_vsplit_l(&server_details, 80.0f, &left_column, &right_column);
2008-01-11 16:48:34 +00:00
for (int i = 0; i < 4; i++)
{
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&left_column, 15.0f, &row, &left_column);
ui_do_label(&row, labels[i], 13.0f, -1);
2008-01-11 16:48:34 +00:00
}
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, selected_server->version, 13.0f, -1);
2008-01-11 16:48:34 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
2008-01-11 16:48:34 +00:00
static char *game_types[] = { "DM", "TDM", "CTF" };
if (selected_server->game_type >= 0 && selected_server->game_type < (int)(sizeof(game_types)/sizeof(*game_types)))
2008-01-12 15:07:57 +00:00
ui_do_label(&row, game_types[selected_server->game_type], 13.0f, -1);
2008-01-11 16:48:34 +00:00
char temp[16];
2008-01-12 12:08:26 +00:00
if(selected_server->progression < 0)
sprintf(temp, "N/A");
else
sprintf(temp, "%d%%", selected_server->progression);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, temp, 13.0f, -1);
2008-01-11 16:48:34 +00:00
sprintf(temp, "%d", selected_server->latency);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, temp, 13.0f, -1);
2008-01-11 16:48:34 +00:00
}
// server scoreboard
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&server_scoreboard, 10.0f, &server_scoreboard, 0x0);
ui_hsplit_t(&server_scoreboard, 20.0f, &server_header, &server_scoreboard);
ui_draw_rect(&server_header, vec4(1,1,1,0.25f), CORNER_T, 4.0f);
ui_draw_rect(&server_scoreboard, vec4(0,0,0,0.15f), CORNER_B, 4.0f);
ui_vsplit_l(&server_header, 8.0f, 0x0, &server_header);
ui_do_label(&server_header, "Scoreboard: ", 14.0f, -1);
2008-01-11 16:48:34 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&server_scoreboard, 5.0f, 0x0, &server_scoreboard);
2008-01-11 16:48:34 +00:00
2008-01-12 15:07:57 +00:00
ui_margin(&server_scoreboard, 3.0f, &server_scoreboard);
2008-01-11 16:48:34 +00:00
if (selected_server)
{
for (int i = 0; i < selected_server->num_players; i++)
{
RECT row;
char temp[16];
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&server_scoreboard, 16.0f, &row, &server_scoreboard);
2008-01-11 16:48:34 +00:00
sprintf(temp, "%d", selected_server->player_scores[i]);
2008-01-12 15:07:57 +00:00
ui_do_label(&row, temp, 14.0f, -1);
2008-01-11 16:48:34 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&row, 25.0f, 0x0, &row);
ui_do_label(&row, selected_server->player_names[i], 14.0f, -1);
2008-01-11 16:48:34 +00:00
}
}
2007-11-08 09:11:32 +00:00
2007-11-04 21:36:03 +00:00
RECT button;
2008-01-12 12:08:26 +00:00
RECT types;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&filters, 20.0f, &button, &filters);
ui_do_label(&button, "Quick search: ", 14.0f, -1);
ui_vsplit_l(&button, 95.0f, 0, &button);
2008-01-13 16:30:30 +00:00
ui_do_edit_box(&config.b_filter_string, &button, config.b_filter_string, sizeof(config.b_filter_string), 14.0f);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&filters, 180.0f, &filters, &types);
2008-01-12 12:08:26 +00:00
2007-11-04 21:36:03 +00:00
// render filters
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&filters, 20.0f, &button, &filters);
if (ui_do_button(&config.b_filter_empty, "Has people playing", config.b_filter_empty, &button, ui_draw_checkbox, 0))
2007-11-04 21:36:03 +00:00
config.b_filter_empty ^= 1;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&filters, 20.0f, &button, &filters);
if (ui_do_button(&config.b_filter_full, "Server not full", config.b_filter_full, &button, ui_draw_checkbox, 0))
2007-11-04 21:36:03 +00:00
config.b_filter_full ^= 1;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&filters, 20.0f, &button, &filters);
if (ui_do_button(&config.b_filter_pw, "No password", config.b_filter_pw, &button, ui_draw_checkbox, 0))
2007-11-04 21:36:03 +00:00
config.b_filter_pw ^= 1;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&filters, 2.0f, &button, &filters); // ping
ui_hsplit_t(&filters, 20.0f, &button, &filters);
2008-01-12 12:08:26 +00:00
{
RECT editbox;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&button, 40.0f, &editbox, &button);
ui_vsplit_l(&button, 5.0f, &button, &button);
2008-01-12 12:08:26 +00:00
char buf[8];
sprintf(buf, "%d", config.b_filter_ping);
2008-01-13 16:30:30 +00:00
ui_do_edit_box(&config.b_filter_ping, &editbox, buf, sizeof(buf), 14.0f);
2008-01-12 12:08:26 +00:00
config.b_filter_ping = atoi(buf);
2008-01-12 15:07:57 +00:00
ui_do_label(&button, "Maximum ping", 14.0f, -1);
2008-01-12 12:08:26 +00:00
}
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&types, 20.0f, &button, &types);
if (ui_do_button(&config.b_filter_gametype, "DM", config.b_filter_gametype&(1<<GAMETYPE_DM), &button, ui_draw_checkbox, 0))
2008-01-12 12:08:26 +00:00
config.b_filter_gametype ^= (1<<GAMETYPE_DM);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&types, 20.0f, &button, &types);
if (ui_do_button((char *)&config.b_filter_gametype + 1, "TDM", config.b_filter_gametype&(1<<GAMETYPE_TDM), &button, ui_draw_checkbox, 0))
2008-01-12 12:08:26 +00:00
config.b_filter_gametype ^= (1<<GAMETYPE_TDM);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&types, 20.0f, &button, &types);
if (ui_do_button((char *)&config.b_filter_gametype + 2, "CTF", config.b_filter_gametype&(1<<GAMETYPE_CTF), &button, ui_draw_checkbox, 0))
2008-01-12 12:08:26 +00:00
config.b_filter_gametype ^= (1<<GAMETYPE_CTF);
2007-11-04 21:36:03 +00:00
// render status
2008-01-12 15:07:57 +00:00
ui_draw_rect(&status, vec4(1,1,1,0.25f), CORNER_B, 5.0f);
ui_vmargin(&status, 50.0f, &status);
2007-11-04 21:36:03 +00:00
char buf[128];
sprintf(buf, "%d of %d servers", client_serverbrowse_sorted_num(), client_serverbrowse_num());
2008-01-12 15:07:57 +00:00
ui_do_label(&status, buf, 14.0f, -1);
2007-11-04 21:36:03 +00:00
// render toolbox
{
RECT buttons, button;
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&toolbox, 25.0f, &toolbox, &buttons);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&buttons, 100.0f, &buttons, &button);
ui_vmargin(&button, 2.0f, &button);
2007-11-04 21:36:03 +00:00
static int join_button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&join_button, "Connect", 0, &button, ui_draw_menu_button, 0))
client_connect(config.ui_server_address);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&buttons, 20.0f, &buttons, &button);
ui_vsplit_r(&buttons, 100.0f, &buttons, &button);
ui_vmargin(&button, 2.0f, &button);
2007-11-04 21:36:03 +00:00
static int refresh_button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&refresh_button, "Refresh", 0, &button, ui_draw_menu_button, 0))
{
if(config.ui_page == PAGE_INTERNET)
client_serverbrowse_refresh(0);
else if(config.ui_page == PAGE_LAN)
client_serverbrowse_refresh(1);
}
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
ui_do_label(&button, "Host address:", 14.0f, -1);
ui_vsplit_l(&button, 100.0f, 0, &button);
2008-01-13 16:30:30 +00:00
ui_do_edit_box(&config.ui_server_address, &button, config.ui_server_address, sizeof(config.ui_server_address), 14.0f);
2007-11-04 21:36:03 +00:00
}
}
static void menu2_render_settings_player(RECT main_view)
{
RECT button;
RECT skinselection;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 300.0f, &main_view, &skinselection);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
2007-11-04 21:36:03 +00:00
// render settings
{
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &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);
2008-01-13 16:30:30 +00:00
ui_do_edit_box(config.player_name, &button, config.player_name, sizeof(config.player_name), 14.0f);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.cl_dynamic_camera, "Dynamic camera", config.cl_dynamic_camera, &button, ui_draw_checkbox, 0))
2007-12-11 23:10:07 +00:00
config.cl_dynamic_camera ^= 1;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.cl_autoswitch_weapons, "Switch weapon on pickup", config.cl_autoswitch_weapons, &button, ui_draw_checkbox, 0))
2007-12-11 23:10:07 +00:00
config.cl_autoswitch_weapons ^= 1;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.cl_nameplates, "Show name plates", config.cl_nameplates, &button, ui_draw_checkbox, 0))
2007-12-10 19:13:00 +00:00
config.cl_nameplates ^= 1;
if(config.cl_nameplates)
{
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
ui_vsplit_l(&button, 15.0f, 0, &button);
if (ui_do_button(&config.cl_nameplates_always, "Always show name plates", config.cl_nameplates_always, &button, ui_draw_checkbox, 0))
2007-12-10 19:13:00 +00:00
config.cl_nameplates_always ^= 1;
}
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
2008-01-12 15:07:57 +00:00
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;
if(config.player_use_custom_color)
{
int *colors[2];
colors[0] = &config.player_color_body;
colors[1] = &config.player_color_feet;
const char *parts[] = {"Body", "Feet"};
const char *labels[] = {"Hue", "Sat.", "Lht."};
static int color_slider[2][3] = {{0}};
//static float v[2][3] = {{0, 0.5f, 0.25f}, {0, 0.5f, 0.25f}};
for(int i = 0; i < 2; i++)
{
RECT text;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &text, &main_view);
ui_vsplit_l(&text, 15.0f, 0, &text);
ui_do_label(&text, parts[i], 14.0f, -1);
int prevcolor = *colors[i];
int color = 0;
for(int s = 0; s < 3; s++)
{
RECT text;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 19.0f, &button, &main_view);
ui_vsplit_l(&button, 30.0f, 0, &button);
ui_vsplit_l(&button, 30.0f, &text, &button);
ui_vsplit_r(&button, 5.0f, &button, 0);
ui_hsplit_t(&button, 4.0f, 0, &button);
float k = ((prevcolor>>((2-s)*8))&0xff) / 255.0f;
2008-01-12 15:07:57 +00:00
k = ui_do_scrollbar_h(&color_slider[i][s], &button, k);
color <<= 8;
color += clamp((int)(k*255), 0, 255);
2008-01-12 15:07:57 +00:00
ui_do_label(&text, labels[s], 15.0f, -1);
}
*colors[i] = color;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 5.0f, 0, &main_view);
}
}
}
// draw header
RECT header, footer;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&skinselection, 20, &header, &skinselection);
ui_draw_rect(&header, vec4(1,1,1,0.25f), CORNER_T, 5.0f);
ui_do_label(&header, "Skins", 18.0f, 0);
// draw footers
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&skinselection, 20, &skinselection, &footer);
ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f);
ui_vsplit_l(&footer, 10.0f, 0, &footer);
// modes
2008-01-12 15:07:57 +00:00
ui_draw_rect(&skinselection, vec4(0,0,0,0.15f), 0, 0);
RECT scroll;
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&skinselection, 15, &skinselection, &scroll);
RECT list = skinselection;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&list, 50, &button, &list);
int num = (int)(skinselection.h/button.h);
static float scrollvalue = 0;
static int scrollbar = 0;
2008-01-12 15:07:57 +00:00
ui_hmargin(&scroll, 5.0f, &scroll);
scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue);
int start = (int)((skin_num()-num)*scrollvalue);
if(start < 0)
start = 0;
animstate state;
anim_eval(&data->animations[ANIM_BASE], 0, &state);
anim_eval_add(&state, &data->animations[ANIM_IDLE], 0, 1.0f);
//anim_eval_add(&state, &data->animations[ANIM_WALK], fmod(client_localtime(), 1.0f), 1.0f);
for(int i = start; i < start+num && i < skin_num(); i++)
{
const skin *s = skin_get(i);
char buf[128];
sprintf(buf, "%s", s->name);
int selected = 0;
if(strcmp(s->name, config.player_skin) == 0)
selected = 1;
tee_render_info info;
info.texture = s->org_texture;
info.color_body = vec4(1,1,1,1);
info.color_feet = vec4(1,1,1,1);
if(config.player_use_custom_color)
{
info.color_body = skin_get_color(config.player_color_body);
info.color_feet = skin_get_color(config.player_color_feet);
info.texture = s->color_texture;
}
2008-01-12 15:07:57 +00:00
info.size = ui_scale()*50.0f;
RECT icon;
RECT text;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&button, 50.0f, &icon, &text);
2008-01-12 15:07:57 +00:00
if(ui_do_button(s, "", selected, &button, ui_draw_list_row, 0))
config_set_player_skin(&config, s->name);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&text, 12.0f, 0, &text); // some margin from the top
ui_do_label(&text, buf, 18.0f, 0);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&icon, 5.0f, 0, &icon); // some margin from the top
render_tee(&state, &info, 0, vec2(1, 0), vec2(icon.x+icon.w/2, icon.y+icon.h/2));
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&list, 50, &button, &list);
}
2007-11-04 21:36:03 +00:00
}
typedef void (*assign_func_callback)(CONFIGURATION *config, int value);
static void menu2_render_settings_controls(RECT main_view)
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 300.0f, &main_view, 0);
2007-11-04 21:36:03 +00:00
2007-12-09 14:15:57 +00:00
{
RECT button, label;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
ui_vsplit_l(&button, 110.0f, &label, &button);
ui_do_label(&label, "Mouse sens.", 14.0f, -1);
ui_hmargin(&button, 2.0f, &button);
config.inp_mousesens = (int)(ui_do_scrollbar_h(&config.inp_mousesens, &button, config.inp_mousesens/500.0f)*500.0f);
//*key.key = ui_do_key_reader(key.key, &button, *key.key);
ui_hsplit_t(&main_view, 20.0f, 0, &main_view);
2007-12-09 14:15:57 +00:00
}
2007-11-04 21:36:03 +00:00
typedef struct
{
char name[32];
int *key;
} KEYINFO;
const 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 },
{ "Next Weapon:", &config.key_next_weapon },
{ "Prev. Weapon:", &config.key_prev_weapon },
{ "Emoticon:", &config.key_emoticon },
2007-12-09 09:48:08 +00:00
{ "Chat:", &config.key_chat },
{ "Team Chat:", &config.key_teamchat },
{ "Console:", &config.key_console },
{ "Remote Console:", &config.key_remoteconsole },
2007-11-04 21:36:03 +00:00
{ "Screenshot:", &config.key_screenshot },
};
const int key_count = sizeof(keys) / sizeof(KEYINFO);
for (int i = 0; i < key_count; i++)
{
KEYINFO key = keys[i];
RECT button, label;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
ui_vsplit_l(&button, 110.0f, &label, &button);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_do_label(&label, key.name, 14.0f, -1);
*key.key = ui_do_key_reader(key.key, &button, *key.key);
ui_hsplit_t(&main_view, 5.0f, 0, &main_view);
2007-11-04 21:36:03 +00:00
}
}
static void menu2_render_settings_graphics(RECT main_view)
{
RECT button;
char buf[128];
static const int MAX_RESOLUTIONS = 256;
static VIDEO_MODE modes[MAX_RESOLUTIONS];
static int num_modes = -1;
if(num_modes == -1)
num_modes = gfx_get_video_modes(modes, MAX_RESOLUTIONS);
RECT modelist;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 300.0f, &main_view, &modelist);
2007-11-04 21:36:03 +00:00
// draw allmodes switch
RECT header, footer;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&modelist, 20, &button, &modelist);
if (ui_do_button(&config.gfx_display_all_modes, "Show only supported", config.gfx_display_all_modes^1, &button, ui_draw_checkbox, 0))
2007-11-04 21:36:03 +00:00
{
config.gfx_display_all_modes ^= 1;
num_modes = gfx_get_video_modes(modes, MAX_RESOLUTIONS);
}
// draw header
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&modelist, 20, &header, &modelist);
ui_draw_rect(&header, vec4(1,1,1,0.25f), CORNER_T, 5.0f);
ui_do_label(&header, "Display Modes", 14.0f, 0);
2007-11-04 21:36:03 +00:00
// draw footers
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&modelist, 20, &modelist, &footer);
2007-11-04 21:36:03 +00:00
sprintf(buf, "Current: %dx%d %d bit", config.gfx_screen_width, config.gfx_screen_height, config.gfx_color_depth);
2008-01-12 15:07:57 +00:00
ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f);
ui_vsplit_l(&footer, 10.0f, 0, &footer);
ui_do_label(&footer, buf, 14.0f, -1);
2007-11-04 21:36:03 +00:00
// modes
2008-01-12 15:07:57 +00:00
ui_draw_rect(&modelist, vec4(0,0,0,0.15f), 0, 0);
2007-11-05 23:05:02 +00:00
2007-11-04 21:36:03 +00:00
RECT scroll;
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&modelist, 15, &modelist, &scroll);
2007-11-04 21:36:03 +00:00
RECT list = modelist;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&list, 20, &button, &list);
2007-11-04 21:36:03 +00:00
int num = (int)(modelist.h/button.h);
static float scrollvalue = 0;
static int scrollbar = 0;
2008-01-12 15:07:57 +00:00
ui_hmargin(&scroll, 5.0f, &scroll);
scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue);
2007-11-04 21:36:03 +00:00
int start = (int)((num_modes-num)*scrollvalue);
if(start < 0)
start = 0;
for(int i = start; i < start+num && i < num_modes; i++)
{
int depth = modes[i].red+modes[i].green+modes[i].blue;
if(depth < 16)
depth = 16;
else if(depth > 16)
depth = 24;
int selected = 0;
if(config.gfx_color_depth == depth &&
config.gfx_screen_width == modes[i].width &&
config.gfx_screen_height == modes[i].height)
{
selected = 1;
}
2007-11-05 23:05:02 +00:00
sprintf(buf, " %dx%d %d bit", modes[i].width, modes[i].height, depth);
2008-01-12 15:07:57 +00:00
if(ui_do_button(&modes[i], buf, selected, &button, ui_draw_list_row, 0))
2007-11-04 21:36:03 +00:00
{
config.gfx_color_depth = depth;
config.gfx_screen_width = modes[i].width;
config.gfx_screen_height = modes[i].height;
2007-12-19 20:30:09 +00:00
if(!selected)
need_restart = true;
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&list, 20, &button, &list);
2007-11-04 21:36:03 +00:00
}
// switches
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.gfx_fullscreen, "Fullscreen", config.gfx_fullscreen, &button, ui_draw_checkbox, 0))
2007-12-19 20:30:09 +00:00
{
2007-11-04 21:36:03 +00:00
config.gfx_fullscreen ^= 1;
2007-12-19 20:30:09 +00:00
need_restart = true;
}
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.gfx_vsync, "V-Sync", config.gfx_vsync, &button, ui_draw_checkbox, 0))
2007-11-04 21:36:03 +00:00
config.gfx_vsync ^= 1;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.gfx_fsaa_samples, "FSAA samples", config.gfx_fsaa_samples, &button, ui_draw_checkbox_number, 0))
2007-11-04 21:36:03 +00:00
{
if(config.gfx_fsaa_samples < 2) config.gfx_fsaa_samples = 2;
else if(config.gfx_fsaa_samples < 4) config.gfx_fsaa_samples = 4;
else if(config.gfx_fsaa_samples < 6) config.gfx_fsaa_samples = 6;
else if(config.gfx_fsaa_samples < 8) config.gfx_fsaa_samples = 8;
else if(config.gfx_fsaa_samples < 16) config.gfx_fsaa_samples = 16;
else if(config.gfx_fsaa_samples >= 16) config.gfx_fsaa_samples = 0;
2007-12-19 20:30:09 +00:00
need_restart = true;
2007-11-04 21:36:03 +00:00
}
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 40.0f, &button, &main_view);
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.gfx_texture_quality, "Quality Textures", config.gfx_texture_quality, &button, ui_draw_checkbox, 0))
2007-12-19 20:30:09 +00:00
{
2007-11-04 21:36:03 +00:00
config.gfx_texture_quality ^= 1;
2007-12-19 20:30:09 +00:00
need_restart = true;
}
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.gfx_texture_compression, "Texture Compression", config.gfx_texture_compression, &button, ui_draw_checkbox, 0))
2007-12-19 20:30:09 +00:00
{
2007-11-04 21:36:03 +00:00
config.gfx_texture_compression ^= 1;
2007-12-19 20:30:09 +00:00
need_restart = true;
}
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.gfx_high_detail, "High Detail", config.gfx_high_detail, &button, ui_draw_checkbox, 0))
2007-11-04 21:36:03 +00:00
config.gfx_high_detail ^= 1;
2007-12-13 20:52:20 +00:00
//
RECT text;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, 0, &main_view);
ui_hsplit_t(&main_view, 20.0f, &text, &main_view);
//ui_vsplit_l(&text, 15.0f, 0, &text);
ui_do_label(&text, "UI Color", 14.0f, -1);
2007-12-13 20:52:20 +00:00
const char *labels[] = {"Hue", "Sat.", "Lht.", "Alpha"};
int *color_slider[4] = {&config.ui_color_hue, &config.ui_color_sat, &config.ui_color_lht, &config.ui_color_alpha};
for(int s = 0; s < 4; s++)
{
RECT text;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 19.0f, &button, &main_view);
ui_vmargin(&button, 15.0f, &button);
ui_vsplit_l(&button, 30.0f, &text, &button);
ui_vsplit_r(&button, 5.0f, &button, 0);
ui_hsplit_t(&button, 4.0f, 0, &button);
2007-12-13 20:52:20 +00:00
float k = (*color_slider[s]) / 255.0f;
2008-01-12 15:07:57 +00:00
k = ui_do_scrollbar_h(color_slider[s], &button, k);
2007-12-13 20:52:20 +00:00
*color_slider[s] = (int)(k*255.0f);
2008-01-12 15:07:57 +00:00
ui_do_label(&text, labels[s], 15.0f, -1);
2007-12-13 20:52:20 +00:00
}
2007-11-04 21:36:03 +00:00
}
2007-12-10 19:13:00 +00:00
static void menu2_render_settings_sound(RECT main_view)
{
RECT button;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 300.0f, &main_view, 0);
2007-12-10 19:13:00 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.snd_enable, "Use Sounds", config.snd_enable, &button, ui_draw_checkbox, 0))
2007-12-19 20:30:09 +00:00
{
2007-12-10 19:13:00 +00:00
config.snd_enable ^= 1;
2007-12-19 20:30:09 +00:00
need_restart = true;
}
2007-12-10 19:13:00 +00:00
if(!config.snd_enable)
return;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
if (ui_do_button(&config.snd_nonactive_mute, "Mute when not active", config.snd_nonactive_mute, &button, ui_draw_checkbox, 0))
2008-01-12 12:08:26 +00:00
config.snd_nonactive_mute ^= 1;
2007-12-10 19:13:00 +00:00
// sample rate box
{
char buf[64];
sprintf(buf, "%d", config.snd_rate);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
ui_do_label(&button, "Sample Rate", 14.0f, -1);
ui_vsplit_l(&button, 110.0f, 0, &button);
ui_vsplit_l(&button, 180.0f, &button, 0);
2008-01-13 16:30:30 +00:00
ui_do_edit_box(&config.snd_rate, &button, buf, sizeof(buf), 14.0f);
2007-12-19 20:30:09 +00:00
int before = config.snd_rate;
2007-12-10 19:13:00 +00:00
config.snd_rate = atoi(buf);
2007-12-19 20:30:09 +00:00
if(config.snd_rate != before)
need_restart = true;
2007-12-10 19:13:00 +00:00
if(config.snd_rate < 1)
config.snd_rate = 1;
}
// volume slider
{
RECT button, label;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 5.0f, &button, &main_view);
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
ui_vsplit_l(&button, 110.0f, &label, &button);
ui_hmargin(&button, 2.0f, &button);
ui_do_label(&label, "Sound Volume", 14.0f, -1);
config.snd_volume = (int)(ui_do_scrollbar_h(&config.snd_volume, &button, config.snd_volume/100.0f)*100.0f);
ui_hsplit_t(&main_view, 20.0f, 0, &main_view);
2007-12-10 19:13:00 +00:00
}
}
static void menu2_render_settings_network(RECT main_view)
{
RECT button;
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 300.0f, &main_view, 0);
{
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
ui_do_label(&button, "Rcon Password", 14.0, -1);
ui_vsplit_l(&button, 110.0f, 0, &button);
ui_vsplit_l(&button, 180.0f, &button, 0);
ui_do_edit_box(&config.rcon_password, &button, config.rcon_password, sizeof(config.rcon_password), true);
}
}
2007-11-04 21:36:03 +00:00
static void menu2_render_settings(RECT main_view)
{
static int settings_page = 0;
// render background
RECT temp, tabbar;
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&main_view, 120.0f, &main_view, &tabbar);
ui_draw_rect(&main_view, color_tabbar_active, CORNER_B|CORNER_TL, 10.0f);
ui_hsplit_t(&tabbar, 50.0f, &temp, &tabbar);
ui_draw_rect(&temp, color_tabbar_active, CORNER_R, 10.0f);
2007-11-04 21:36:03 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 10.0f, 0, &main_view);
2007-11-04 21:36:03 +00:00
RECT button;
const char *tabs[] = {"Player", "Controls", "Network", "Graphics", "Sound"};
int num_tabs = (int)(sizeof(tabs)/sizeof(*tabs));
for(int i = 0; i < num_tabs; i++)
{
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&tabbar, 10, &button, &tabbar);
ui_hsplit_t(&tabbar, 26, &button, &tabbar);
if(ui_do_button(tabs[i], tabs[i], settings_page == i, &button, ui_draw_settings_tab_button, 0))
2007-11-04 21:36:03 +00:00
settings_page = i;
}
2008-01-12 15:07:57 +00:00
ui_margin(&main_view, 10.0f, &main_view);
2007-11-04 21:36:03 +00:00
if(settings_page == 0)
menu2_render_settings_player(main_view);
else if(settings_page == 1)
menu2_render_settings_controls(main_view);
else if(settings_page == 2)
menu2_render_settings_network(main_view);
2007-11-04 21:36:03 +00:00
else if(settings_page == 3)
menu2_render_settings_graphics(main_view);
2007-12-10 19:13:00 +00:00
else if(settings_page == 4)
menu2_render_settings_sound(main_view);
2007-12-19 20:30:09 +00:00
if(need_restart)
{
RECT restart_warning;
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&main_view, 40, &main_view, &restart_warning);
ui_do_label(&restart_warning, "You must restart Teewars for all settings to take effect.", 15.0f, -1, 220);
2007-12-19 20:30:09 +00:00
}
2007-11-04 21:36:03 +00:00
}
static void menu2_render_news(RECT main_view)
{
2008-01-12 15:07:57 +00:00
ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
2007-11-04 21:36:03 +00:00
}
2007-11-04 22:30:08 +00:00
static void menu2_render_game(RECT main_view)
{
RECT button;
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 45.0f, &main_view, 0);
ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
2007-11-04 22:30:08 +00:00
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&main_view, 10.0f, 0, &main_view);
ui_hsplit_t(&main_view, 25.0f, &main_view, 0);
ui_vmargin(&main_view, 10.0f, &main_view);
2007-11-04 22:30:08 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_r(&main_view, 120.0f, &main_view, &button);
2007-11-04 22:30:08 +00:00
static int disconnect_button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&disconnect_button, "Disconnect", 0, &button, ui_draw_menu_button, 0))
2007-11-04 22:30:08 +00:00
client_disconnect();
if(local_info && gameobj)
2007-11-18 14:49:56 +00:00
{
if(local_info->team != -1)
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 10.0f, &button, &main_view);
ui_vsplit_l(&main_view, 120.0f, &button, &main_view);
2007-11-18 14:49:56 +00:00
static int spectate_button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&spectate_button, "Spectate", 0, &button, ui_draw_menu_button, 0))
2007-11-18 14:49:56 +00:00
{
2007-12-11 23:10:07 +00:00
config.cl_team = -1;
2007-11-18 14:49:56 +00:00
menu_active = false;
}
}
2007-12-16 21:54:36 +00:00
if(gameobj->gametype == GAMETYPE_DM)
{
if(local_info->team != 0)
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 10.0f, &button, &main_view);
ui_vsplit_l(&main_view, 120.0f, &button, &main_view);
2007-12-16 21:54:36 +00:00
static int spectate_button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&spectate_button, "Join Game", 0, &button, ui_draw_menu_button, 0))
2007-12-16 21:54:36 +00:00
{
config.cl_team = 0;
menu_active = false;
}
}
}
else
2007-11-18 14:49:56 +00:00
{
if(local_info->team != 0)
2007-11-18 14:49:56 +00:00
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 10.0f, &button, &main_view);
ui_vsplit_l(&main_view, 120.0f, &button, &main_view);
static int spectate_button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&spectate_button, "Join Red", 0, &button, ui_draw_menu_button, 0))
{
config.cl_team = 0;
menu_active = false;
}
2007-11-18 14:49:56 +00:00
}
if(local_info->team != 1)
2007-11-18 14:49:56 +00:00
{
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&main_view, 10.0f, &button, &main_view);
ui_vsplit_l(&main_view, 120.0f, &button, &main_view);
static int spectate_button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&spectate_button, "Join Blue", 0, &button, ui_draw_menu_button, 0))
{
config.cl_team = 1;
menu_active = false;
}
2007-11-18 14:49:56 +00:00
}
}
}
2007-11-04 22:30:08 +00:00
}
void menu_do_disconnected()
{
2007-12-03 18:47:29 +00:00
popup = POPUP_NONE;
2007-12-03 20:35:41 +00:00
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;
}
}
void menu_do_connecting()
{
popup = POPUP_CONNECTING;
}
void menu_do_connected()
{
popup = POPUP_NONE;
}
2007-12-16 22:34:43 +00:00
void menu_init()
{
if(config.cl_show_welcome)
popup = POPUP_FIRST_LAUNCH;
config.cl_show_welcome = 0;
}
2007-11-04 21:36:03 +00:00
int menu2_render()
{
2007-11-26 22:26:49 +00:00
if(0)
2007-11-26 22:26:33 +00:00
{
gfx_mapscreen(0,0,10*4/3.0f,10);
gfx_clear(gui_color.r, gui_color.g, gui_color.b);
2007-11-26 22:26:33 +00:00
animstate state;
anim_eval(&data->animations[ANIM_BASE], 0, &state);
anim_eval_add(&state, &data->animations[ANIM_IDLE], 0, 1.0f);
//anim_eval_add(&state, &data->animations[ANIM_WALK], fmod(client_localtime(), 1.0f), 1.0f);
for(int i = 0; i < skin_num(); i++)
{
float x = (i/8)*3;
float y = (i%8);
for(int c = 0; c < 2; c++)
{
//int colors[2] = {54090, 10998628};
//int colors[2] = {65432, 9895832}; // NEW
int colors[2] = {65387, 10223467}; // NEW
tee_render_info info;
info.texture = skin_get(i)->color_texture;
info.color_feet = info.color_body = skin_get_color(colors[c]);
//info.color_feet = info.color_body = vec4(1,1,1,1);
2008-01-12 15:07:57 +00:00
info.size = 1.0f; //ui_scale()*16.0f;
2007-11-26 22:26:33 +00:00
//render_tee(&state, &info, 0, vec2(sinf(client_localtime()*3), cosf(client_localtime()*3)), vec2(1+x+c,1+y));
render_tee(&state, &info, 0, vec2(1,0), vec2(1+x+c,1+y));
}
}
return 0;
}
2008-01-12 15:07:57 +00:00
RECT screen = *ui_screen();
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
2007-12-24 13:09:34 +00:00
if (0)
2007-12-24 13:09:34 +00:00
{
gfx_clear(0.65f,0.78f,0.9f);
2008-01-12 15:07:57 +00:00
2007-12-24 13:09:34 +00:00
for (int i = 0; i < 24; i++)
{
float size = i * 0.5 + 8;
char temp[64];
sprintf(temp, "%f: Ingen tomte i jul", size);
2008-01-12 15:07:57 +00:00
gfx_text(0, 50, 10 + i*int(size), size, temp, -1);
gfx_text(gfx_font_set, 400, 10 + i*int(size), size, temp, -1);
2007-12-24 13:09:34 +00:00
}
return 0;
}
2007-11-04 21:36:03 +00:00
static bool first = true;
if(first)
{
if(config.ui_page == PAGE_INTERNET)
client_serverbrowse_refresh(0);
else if(config.ui_page == PAGE_LAN)
client_serverbrowse_refresh(1);
2007-11-04 21:36:03 +00:00
first = false;
}
2007-11-04 22:30:08 +00:00
if(client_state() == CLIENTSTATE_ONLINE)
{
color_tabbar_inactive = color_tabbar_inactive_ingame;
color_tabbar_active = color_tabbar_active_ingame;
}
else
{
menu2_render_background();
color_tabbar_inactive = color_tabbar_inactive_outgame;
color_tabbar_active = color_tabbar_active_outgame;
}
2007-11-04 21:36:03 +00:00
RECT tab_bar;
RECT main_view;
// some margin around the screen
2008-01-12 15:07:57 +00:00
ui_margin(&screen, 10.0f, &screen);
2007-11-04 21:36:03 +00:00
if(popup == POPUP_NONE)
{
// do tab bar
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&screen, 26.0f, &tab_bar, &main_view);
ui_vmargin(&tab_bar, 20.0f, &tab_bar);
menu2_render_menubar(tab_bar);
// render current page
if(menu_game_active)
menu2_render_game(main_view);
else if(config.ui_page == PAGE_NEWS)
menu2_render_news(main_view);
else if(config.ui_page == PAGE_INTERNET)
menu2_render_serverbrowser(main_view);
else if(config.ui_page == PAGE_LAN)
menu2_render_serverbrowser(main_view);
else if(config.ui_page == PAGE_FAVORITES)
menu2_render_serverbrowser(main_view);
else if(config.ui_page == PAGE_SETTINGS)
menu2_render_settings(main_view);
}
else
{
// make sure that other windows doesn't do anything funnay!
//ui_set_hot_item(0);
//ui_set_active_item(0);
const char *title = "";
const char *extra_text = "";
const char *button_text = "";
2007-11-04 21:36:03 +00:00
if(popup == POPUP_CONNECTING)
{
title = "Connecting to";
extra_text = config.ui_server_address; // TODO: query the client about the address
button_text = "Abort";
}
else if(popup == POPUP_DISCONNECTED)
{
title = "Disconnected";
extra_text = client_error_string();
button_text = "Ok";
}
2007-12-03 20:35:41 +00:00
else if(popup == POPUP_PASSWORD)
{
title = "Password Error";
extra_text = client_error_string();
button_text = "Try Again";
}
2007-12-09 17:25:16 +00:00
else if(popup == POPUP_QUIT)
{
title = "Quit";
extra_text = "Are you sure that you want to quit?";
}
2007-12-16 22:34:43 +00:00
else if(popup == POPUP_FIRST_LAUNCH)
{
title = "Welcome to Teewars";
extra_text =
"As this is the first time you launch Teewars, please enter your nick name below. "
"It's recommended that you check the settings to adjust them to your liking "
"before joining a server.";
button_text = "Ok";
}
RECT box, part;
box = screen;
2008-01-12 15:07:57 +00:00
ui_vmargin(&box, 150.0f, &box);
ui_hmargin(&box, 150.0f, &box);
// render the box
2008-01-12 15:07:57 +00:00
ui_draw_rect(&box, vec4(0,0,0,0.5f), CORNER_ALL, 15.0f);
2008-01-12 15:07:57 +00:00
ui_hsplit_t(&box, 20.f, &part, &box);
ui_hsplit_t(&box, 24.f, &part, &box);
ui_do_label(&part, title, 24.f, 0);
ui_hsplit_t(&box, 20.f, &part, &box);
ui_hsplit_t(&box, 24.f, &part, &box);
ui_vmargin(&part, 20.f, &part);
ui_do_label(&part, extra_text, 20.f, -1, (int)part.w);
2007-12-09 17:25:16 +00:00
if(popup == POPUP_QUIT)
{
2007-12-15 13:19:44 +00:00
RECT yes, no;
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&box, 20.f, &box, &part);
ui_hsplit_b(&box, 24.f, &box, &part);
ui_vmargin(&part, 80.0f, &part);
2007-12-09 17:25:16 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_mid(&part, &no, &yes);
2007-12-15 13:19:44 +00:00
2008-01-12 15:07:57 +00:00
ui_vmargin(&yes, 20.0f, &yes);
ui_vmargin(&no, 20.0f, &no);
2007-12-09 17:25:16 +00:00
static int button_abort = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&button_abort, "No", 0, &no, ui_draw_menu_button, 0) || inp_key_down(KEY_ESC))
2007-12-09 17:25:16 +00:00
popup = POPUP_NONE;
static int button_tryagain = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&button_tryagain, "Yes", 0, &yes, ui_draw_menu_button, 0) || inp_key_down(KEY_ENTER))
2007-12-09 17:25:16 +00:00
client_quit();
}
else if(popup == POPUP_PASSWORD)
2007-12-03 20:35:41 +00:00
{
RECT label, textbox, tryagain, abort;
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&box, 20.f, &box, &part);
ui_hsplit_b(&box, 24.f, &box, &part);
ui_vmargin(&part, 80.0f, &part);
2007-12-16 21:56:59 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_mid(&part, &abort, &tryagain);
2007-12-16 21:56:59 +00:00
2008-01-12 15:07:57 +00:00
ui_vmargin(&tryagain, 20.0f, &tryagain);
ui_vmargin(&abort, 20.0f, &abort);
2007-12-03 20:35:41 +00:00
static int button_abort = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&button_abort, "Abort", 0, &abort, ui_draw_menu_button, 0) || inp_key_down(KEY_ESC))
2007-12-03 20:35:41 +00:00
popup = POPUP_NONE;
2007-12-03 20:35:41 +00:00
static int button_tryagain = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&button_tryagain, "Try again", 0, &tryagain, ui_draw_menu_button, 0) || inp_key_down(KEY_ENTER))
2007-12-03 20:35:41 +00:00
{
client_connect(config.ui_server_address);
}
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&box, 60.f, &box, &part);
ui_hsplit_b(&box, 24.f, &box, &part);
2007-12-03 20:35:41 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&part, 60.0f, 0, &label);
ui_vsplit_l(&label, 100.0f, 0, &textbox);
ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
ui_do_label(&label, "Password:", 20, -1);
ui_do_edit_box(&config.password, &textbox, config.password, sizeof(config.password), true);
2007-12-03 20:35:41 +00:00
}
2007-12-16 22:34:43 +00:00
else if(popup == POPUP_FIRST_LAUNCH)
{
RECT label, textbox;
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&box, 20.f, &box, &part);
ui_hsplit_b(&box, 24.f, &box, &part);
ui_vmargin(&part, 80.0f, &part);
2007-12-16 22:34:43 +00:00
static int enter_button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&enter_button, "Enter", 0, &part, ui_draw_menu_button, 0) || inp_key_down(KEY_ENTER))
2007-12-16 22:34:43 +00:00
popup = POPUP_NONE;
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&box, 60.f, &box, &part);
ui_hsplit_b(&box, 24.f, &box, &part);
2007-12-16 22:34:43 +00:00
2008-01-12 15:07:57 +00:00
ui_vsplit_l(&part, 60.0f, 0, &label);
ui_vsplit_l(&label, 100.0f, 0, &textbox);
ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
ui_do_label(&label, "Nickname:", 20, -1);
2008-01-13 16:30:30 +00:00
ui_do_edit_box(&config.player_name, &textbox, config.player_name, sizeof(config.player_name), 14.0f);
2007-12-16 22:34:43 +00:00
}
2007-12-03 20:35:41 +00:00
else
{
2008-01-12 15:07:57 +00:00
ui_hsplit_b(&box, 20.f, &box, &part);
ui_hsplit_b(&box, 24.f, &box, &part);
ui_vmargin(&part, 120.0f, &part);
2007-12-03 20:35:41 +00:00
static int button = 0;
2008-01-12 15:07:57 +00:00
if(ui_do_button(&button, button_text, 0, &part, ui_draw_menu_button, 0) || inp_key_down(KEY_ESC) || inp_key_down(KEY_ENTER))
2007-12-03 20:35:41 +00:00
{
if(popup == POPUP_CONNECTING)
client_disconnect();
popup = POPUP_NONE;
}
}
}
2007-11-04 21:36:03 +00:00
return 0;
}
2008-01-12 17:09:00 +00:00
void menu_render()
2007-12-02 17:55:45 +00:00
{
static int mouse_x = 0;
static int mouse_y = 0;
2007-12-13 20:52:20 +00:00
// update colors
vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);
color_tabbar_inactive_outgame = vec4(0,0,0,0.25f);
color_tabbar_active_outgame = vec4(0,0,0,0.5f);
color_ingame_scale_i = 0.5f;
color_ingame_scale_a = 0.2f;
color_tabbar_inactive_ingame = vec4(
gui_color.r*color_ingame_scale_i,
gui_color.g*color_ingame_scale_i,
gui_color.b*color_ingame_scale_i,
gui_color.a*0.8f);
color_tabbar_active_ingame = vec4(
gui_color.r*color_ingame_scale_a,
gui_color.g*color_ingame_scale_a,
gui_color.b*color_ingame_scale_a,
gui_color.a);
2007-12-02 17:55:45 +00:00
// handle mouse movement
float mx, my;
{
int rx, ry;
inp_mouse_relative(&rx, &ry);
mouse_x += rx;
mouse_y += ry;
if(mouse_x < 0) mouse_x = 0;
if(mouse_y < 0) mouse_y = 0;
if(mouse_x > gfx_screenwidth()) mouse_x = gfx_screenwidth();
if(mouse_y > gfx_screenheight()) mouse_y = gfx_screenheight();
// update the ui
2008-01-12 15:07:57 +00:00
RECT *screen = ui_screen();
mx = (mouse_x/(float)gfx_screenwidth())*screen->w;
my = (mouse_y/(float)gfx_screenheight())*screen->h;
2007-12-02 17:55:45 +00:00
int buttons = 0;
if(inp_key_pressed(KEY_MOUSE_1)) buttons |= 1;
if(inp_key_pressed(KEY_MOUSE_2)) buttons |= 2;
if(inp_key_pressed(KEY_MOUSE_3)) buttons |= 4;
ui_update(mx,my,mx*3.0f,my*3.0f,buttons);
}
menu2_render();
2007-12-02 17:55:45 +00:00
gfx_texture_set(data->images[IMAGE_CURSOR].id);
gfx_quads_begin();
gfx_setcolor(1,1,1,1);
gfx_quads_drawTL(mx,my,24,24);
gfx_quads_end();
2008-01-12 12:08:26 +00:00
inp_clear_events();
2007-12-02 17:55:45 +00:00
}