cleaned up the browser code a bit

This commit is contained in:
Magnus Auvinen 2008-09-04 18:42:26 +00:00
parent bcabb31780
commit 7248dd641d
2 changed files with 247 additions and 290 deletions

View file

@ -79,6 +79,10 @@ class MENUS : public COMPONENT
void render_serverinfo(RECT main_view);
// found in menus_browser.cpp
int selected_index;
void render_serverbrowser_serverlist(RECT view);
void render_serverbrowser_serverdetail(RECT view);
void render_serverbrowser_filters(RECT view);
void render_serverbrowser(RECT main_view);
// found in menus_settings.cpp

View file

@ -15,54 +15,13 @@ extern "C" {
#include <game/client/gc_render.hpp>
#include "menus.hpp"
void MENUS::render_serverbrowser(RECT main_view)
void MENUS::render_serverbrowser_serverlist(RECT view)
{
ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
RECT view;
ui_margin(&main_view, 10.0f, &view);
/*
+--headers--------+ +
| |
| | | |
| | | |
| | | |
| | | |
| | | |
+--status---------+
*/
RECT headers;
//RECT filters;
RECT status;
RECT status_toolbar;
RECT toolbox;
RECT button_box;
//RECT server_details;
//RECT server_scoreboard;
//ui_hsplit_t(&view, 20.0f, &status, &view);
//ui_hsplit_b(&view, 110.0f, &view, &filters);
// split off a piece for filters, details and scoreboard
ui_vsplit_r(&view, 200.0f, &view, &toolbox);
ui_hsplit_b(&toolbox, 120.0f, &toolbox, &button_box);
// server list
ui_hsplit_t(&view, 16.0f, &headers, &view);
//ui_hsplit_b(&view, 110.0f, &view, &filters);
//ui_hsplit_b(&view, 5.0f, &view, 0);
ui_hsplit_b(&view, 30.0f, &view, &status_toolbar);
ui_hsplit_b(&view, 20.0f, &view, &status);
//ui_vsplit_r(&filters, 300.0f, &filters, &toolbox);
//ui_vsplit_r(&filters, 150.0f, &filters, 0);
//ui_vsplit_mid(&filters, &filters, &toolbox);
//ui_vsplit_r(&filters, 50.0f, &filters, 0);
// split of the scrollbar
ui_draw_rect(&headers, vec4(1,1,1,0.25f), CORNER_T, 5.0f);
@ -195,9 +154,10 @@ void MENUS::render_serverbrowser(RECT main_view)
view.y -= scrollvalue*scrollnum*cols[0].rect.h;
int new_selected = -1;
int selected_index = -1;
int num_players = 0;
selected_index = -1;
for (int i = 0; i < num_servers; i++)
{
SERVER_INFO *item = client_serverbrowse_sorted_get(i);
@ -346,8 +306,243 @@ void MENUS::render_serverbrowser(RECT main_view)
client_connect(config.ui_server_address);
}
// render status
ui_draw_rect(&status, vec4(1,1,1,0.25f), CORNER_B, 5.0f);
ui_vmargin(&status, 50.0f, &status);
char buf[128];
str_format(buf, sizeof(buf), "%d of %d servers, %d players", client_serverbrowse_sorted_num(), client_serverbrowse_num(), num_players);
ui_do_label(&status, buf, 14.0f, -1);
}
void MENUS::render_serverbrowser_filters(RECT view)
{
// filters
RECT button;
ui_hsplit_t(&view, 5.0f, 0, &view);
ui_vsplit_l(&view, 5.0f, 0, &view);
ui_vsplit_r(&view, 5.0f, &view, 0);
ui_hsplit_b(&view, 5.0f, &view, 0);
// render filters
ui_hsplit_t(&view, 20.0f, &button, &view);
if (ui_do_button(&config.b_filter_empty, "Has people playing", config.b_filter_empty, &button, ui_draw_checkbox, 0))
config.b_filter_empty ^= 1;
ui_hsplit_t(&view, 20.0f, &button, &view);
if (ui_do_button(&config.b_filter_full, "Server not full", config.b_filter_full, &button, ui_draw_checkbox, 0))
config.b_filter_full ^= 1;
ui_hsplit_t(&view, 20.0f, &button, &view);
if (ui_do_button(&config.b_filter_pw, "No password", config.b_filter_pw, &button, ui_draw_checkbox, 0))
config.b_filter_pw ^= 1;
ui_hsplit_t(&view, 20.0f, &button, &view);
if (ui_do_button((char *)&config.b_filter_compatversion, "Compatible Version", config.b_filter_compatversion, &button, ui_draw_checkbox, 0))
config.b_filter_compatversion ^= 1;
ui_hsplit_t(&view, 20.0f, &button, &view);
ui_do_label(&button, "Game types: ", 14.0f, -1);
ui_vsplit_l(&button, 95.0f, 0, &button);
ui_margin(&button, 1.0f, &button);
ui_do_edit_box(&config.b_filter_gametype, &button, config.b_filter_gametype, sizeof(config.b_filter_gametype), 14.0f);
ui_hsplit_t(&view, 20.0f, &button, &view);
ui_do_label(&button, "Quick search: ", 14.0f, -1);
ui_vsplit_l(&button, 95.0f, 0, &button);
ui_margin(&button, 1.0f, &button);
ui_do_edit_box(&config.b_filter_string, &button, config.b_filter_string, sizeof(config.b_filter_string), 14.0f);
{
ui_hsplit_t(&view, 20.0f, &button, &view);
RECT editbox;
ui_vsplit_l(&button, 40.0f, &editbox, &button);
ui_vsplit_l(&button, 5.0f, &button, &button);
char buf[8];
str_format(buf, sizeof(buf), "%d", config.b_filter_ping);
ui_do_edit_box(&config.b_filter_ping, &editbox, buf, sizeof(buf), 14.0f);
config.b_filter_ping = atoi(buf);
ui_do_label(&button, "Maximum ping", 14.0f, -1);
}
//ui_vsplit_r(&buttons, 30.0f, &buttons, &button);
ui_hsplit_b(&view, 25.0f, &view, &button);
static int clear_button = 0;
if(ui_do_button(&clear_button, "Reset Filter", 0, &button, ui_draw_menu_button, 0))
{
config.b_filter_full = 0;
config.b_filter_empty = 0;
config.b_filter_pw = 0;
config.b_filter_ping = 999;
config.b_filter_gametype[0] = 0;
config.b_filter_compatversion = 1;
config.b_filter_string[0] = 0;
}
}
void MENUS::render_serverbrowser_serverdetail(RECT view)
{
RECT server_details = view;
RECT server_scoreboard, server_header;
SERVER_INFO *selected_server = client_serverbrowse_sorted_get(selected_index);
//RECT server_header;
//ui_vsplit_l(&server_details, 10.0f, 0x0, &server_details);
// split off a piece to use for scoreboard
ui_hsplit_t(&server_details, 140.0f, &server_details, &server_scoreboard);
ui_hsplit_b(&server_details, 10.0f, &server_details, 0x0);
// server details
const float font_size = 12.0f;
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: ", font_size+2.0f, -1);
ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details);
ui_margin(&server_details, 3.0f, &server_details);
if (selected_server)
{
RECT row;
static const char *labels[] = { "Version:", "Game Type:", "Progression:", "Ping:" };
RECT left_column;
RECT right_column;
//
{
RECT button;
ui_hsplit_b(&server_details, 20.0f, &server_details, &button);
static int add_fav_button = 0;
if (ui_do_button(&add_fav_button, "Favorite", selected_server->favorite, &button, ui_draw_checkbox, 0))
{
if(selected_server->favorite)
client_serverbrowse_removefavorite(selected_server->netaddr);
else
client_serverbrowse_addfavorite(selected_server->netaddr);
}
}
//ui_do_label(&row, temp, font_size, -1);
ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details);
ui_vsplit_l(&server_details, 80.0f, &left_column, &right_column);
for (int i = 0; i < 4; i++)
{
ui_hsplit_t(&left_column, 15.0f, &row, &left_column);
ui_do_label(&row, labels[i], font_size, -1);
}
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, selected_server->version, font_size, -1);
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, selected_server->gametype, font_size, -1);
char temp[16];
if(selected_server->progression < 0)
str_format(temp, sizeof(temp), "N/A");
else
str_format(temp, sizeof(temp), "%d%%", selected_server->progression);
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, temp, font_size, -1);
str_format(temp, sizeof(temp), "%d", selected_server->latency);
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, temp, font_size, -1);
}
// server scoreboard
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: ", font_size+2.0f, -1);
ui_vsplit_l(&server_scoreboard, 5.0f, 0x0, &server_scoreboard);
ui_margin(&server_scoreboard, 3.0f, &server_scoreboard);
if (selected_server)
{
for (int i = 0; i < selected_server->num_players; i++)
{
RECT row;
char temp[16];
ui_hsplit_t(&server_scoreboard, 16.0f, &row, &server_scoreboard);
str_format(temp, sizeof(temp), "%d", selected_server->players[i].score);
ui_do_label(&row, temp, font_size, -1);
ui_vsplit_l(&row, 25.0f, 0x0, &row);
TEXT_CURSOR cursor;
gfx_text_set_cursor(&cursor, row.x, row.y, 12.0f, TEXTFLAG_RENDER);
const char *name = selected_server->players[i].name;
if(config.b_filter_string[0])
{
// highlight the parts that matches
const char *s = str_find_nocase(name, config.b_filter_string);
if(s)
{
gfx_text_ex(&cursor, name, (int)(s-name));
gfx_text_color(0.4f,0.4f,1,1);
gfx_text_ex(&cursor, s, strlen(config.b_filter_string));
gfx_text_color(1,1,1,1);
gfx_text_ex(&cursor, s+strlen(config.b_filter_string), -1);
}
else
gfx_text_ex(&cursor, name, -1);
}
else
gfx_text_ex(&cursor, name, -1);
}
}
}
void MENUS::render_serverbrowser(RECT main_view)
{
ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
RECT view;
ui_margin(&main_view, 10.0f, &view);
/*
+-----------------+ +------+
| | | |
| | | tool |
| | | box |
| | | |
| | +------+
+-----------------+ button
status toolbar box
*/
//RECT filters;
RECT status_toolbar;
RECT toolbox;
RECT button_box;
// split off a piece for filters, details and scoreboard
ui_vsplit_r(&view, 200.0f, &view, &toolbox);
ui_hsplit_b(&toolbox, 120.0f, &toolbox, &button_box);
ui_hsplit_b(&view, 30.0f, &view, &status_toolbar);
render_serverbrowser_serverlist(view);
static int toolbox_page = 0;
@ -378,207 +573,9 @@ void MENUS::render_serverbrowser(RECT main_view)
ui_hsplit_t(&toolbox, 5.0f, 0, &toolbox);
if(toolbox_page == 0)
{
// filters
RECT button;
ui_hsplit_t(&toolbox, 5.0f, 0, &toolbox);
ui_vsplit_l(&toolbox, 5.0f, 0, &toolbox);
ui_vsplit_r(&toolbox, 5.0f, &toolbox, 0);
ui_hsplit_b(&toolbox, 5.0f, &toolbox, 0);
// render filters
ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
if (ui_do_button(&config.b_filter_empty, "Has people playing", config.b_filter_empty, &button, ui_draw_checkbox, 0))
config.b_filter_empty ^= 1;
ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
if (ui_do_button(&config.b_filter_full, "Server not full", config.b_filter_full, &button, ui_draw_checkbox, 0))
config.b_filter_full ^= 1;
ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
if (ui_do_button(&config.b_filter_pw, "No password", config.b_filter_pw, &button, ui_draw_checkbox, 0))
config.b_filter_pw ^= 1;
ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
if (ui_do_button((char *)&config.b_filter_compatversion, "Compatible Version", config.b_filter_compatversion, &button, ui_draw_checkbox, 0))
config.b_filter_compatversion ^= 1;
ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
ui_do_label(&button, "Game types: ", 14.0f, -1);
ui_vsplit_l(&button, 95.0f, 0, &button);
ui_margin(&button, 1.0f, &button);
ui_do_edit_box(&config.b_filter_gametype, &button, config.b_filter_gametype, sizeof(config.b_filter_gametype), 14.0f);
ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
ui_do_label(&button, "Quick search: ", 14.0f, -1);
ui_vsplit_l(&button, 95.0f, 0, &button);
ui_margin(&button, 1.0f, &button);
ui_do_edit_box(&config.b_filter_string, &button, config.b_filter_string, sizeof(config.b_filter_string), 14.0f);
{
ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
RECT editbox;
ui_vsplit_l(&button, 40.0f, &editbox, &button);
ui_vsplit_l(&button, 5.0f, &button, &button);
char buf[8];
str_format(buf, sizeof(buf), "%d", config.b_filter_ping);
ui_do_edit_box(&config.b_filter_ping, &editbox, buf, sizeof(buf), 14.0f);
config.b_filter_ping = atoi(buf);
ui_do_label(&button, "Maximum ping", 14.0f, -1);
}
//ui_vsplit_r(&buttons, 30.0f, &buttons, &button);
ui_hsplit_b(&toolbox, 25.0f, &toolbox, &button);
static int clear_button = 0;
if(ui_do_button(&clear_button, "Reset Filter", 0, &button, ui_draw_menu_button, 0))
{
config.b_filter_full = 0;
config.b_filter_empty = 0;
config.b_filter_pw = 0;
config.b_filter_ping = 999;
config.b_filter_gametype[0] = 0;
config.b_filter_compatversion = 1;
config.b_filter_string[0] = 0;
}
}
render_serverbrowser_filters(toolbox);
else if(toolbox_page == 1)
{
RECT server_details = toolbox;
RECT server_scoreboard, server_header;
//ui_vsplit_l(&server_details, 10.0f, 0x0, &server_details);
// split off a piece to use for scoreboard
ui_hsplit_t(&server_details, 140.0f, &server_details, &server_scoreboard);
ui_hsplit_b(&server_details, 10.0f, &server_details, 0x0);
// server details
const float font_size = 12.0f;
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: ", font_size+2.0f, -1);
ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details);
ui_margin(&server_details, 3.0f, &server_details);
if (selected_server)
{
RECT row;
static const char *labels[] = { "Version:", "Game Type:", "Progression:", "Ping:" };
RECT left_column;
RECT right_column;
//
{
RECT button;
ui_hsplit_b(&server_details, 20.0f, &server_details, &button);
static int add_fav_button = 0;
if (ui_do_button(&add_fav_button, "Favorite", selected_server->favorite, &button, ui_draw_checkbox, 0))
{
if(selected_server->favorite)
client_serverbrowse_removefavorite(selected_server->netaddr);
else
client_serverbrowse_addfavorite(selected_server->netaddr);
}
}
//ui_do_label(&row, temp, font_size, -1);
ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details);
ui_vsplit_l(&server_details, 80.0f, &left_column, &right_column);
for (int i = 0; i < 4; i++)
{
ui_hsplit_t(&left_column, 15.0f, &row, &left_column);
ui_do_label(&row, labels[i], font_size, -1);
}
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, selected_server->version, font_size, -1);
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, selected_server->gametype, font_size, -1);
char temp[16];
if(selected_server->progression < 0)
str_format(temp, sizeof(temp), "N/A");
else
str_format(temp, sizeof(temp), "%d%%", selected_server->progression);
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, temp, font_size, -1);
str_format(temp, sizeof(temp), "%d", selected_server->latency);
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, temp, font_size, -1);
}
// server scoreboard
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: ", font_size+2.0f, -1);
ui_vsplit_l(&server_scoreboard, 5.0f, 0x0, &server_scoreboard);
ui_margin(&server_scoreboard, 3.0f, &server_scoreboard);
if (selected_server)
{
for (int i = 0; i < selected_server->num_players; i++)
{
RECT row;
char temp[16];
ui_hsplit_t(&server_scoreboard, 16.0f, &row, &server_scoreboard);
str_format(temp, sizeof(temp), "%d", selected_server->players[i].score);
ui_do_label(&row, temp, font_size, -1);
ui_vsplit_l(&row, 25.0f, 0x0, &row);
TEXT_CURSOR cursor;
gfx_text_set_cursor(&cursor, row.x, row.y, 12.0f, TEXTFLAG_RENDER);
const char *name = selected_server->players[i].name;
if(config.b_filter_string[0])
{
// highlight the parts that matches
const char *s = str_find_nocase(name, config.b_filter_string);
if(s)
{
gfx_text_ex(&cursor, name, (int)(s-name));
gfx_text_color(0.4f,0.4f,1,1);
gfx_text_ex(&cursor, s, strlen(config.b_filter_string));
gfx_text_color(1,1,1,1);
gfx_text_ex(&cursor, s+strlen(config.b_filter_string), -1);
}
else
gfx_text_ex(&cursor, name, -1);
}
else
gfx_text_ex(&cursor, name, -1);
}
}
}
// render status
ui_draw_rect(&status, vec4(1,1,1,0.25f), CORNER_B, 5.0f);
ui_vmargin(&status, 50.0f, &status);
char buf[128];
str_format(buf, sizeof(buf), "%d of %d servers, %d players", client_serverbrowse_sorted_num(), client_serverbrowse_num(), num_players);
ui_do_label(&status, buf, 14.0f, -1);
render_serverbrowser_serverdetail(toolbox);
{
ui_hsplit_t(&status_toolbar, 5.0f, 0, &status_toolbar);
@ -599,6 +596,7 @@ void MENUS::render_serverbrowser(RECT main_view)
ui_do_label(&status_toolbar, "new version.. LOLZ!!", 14.0f, -1);
}
// do the button box
{
ui_vsplit_l(&button_box, 5.0f, 0, &button_box);
@ -619,49 +617,4 @@ void MENUS::render_serverbrowser(RECT main_view)
ui_hsplit_b(&button_box, 20.0f, &button_box, &button);
ui_do_label(&button, "Host address:", 14.0f, -1);
}
// render toolbox
if(0)
{
RECT buttons, button;
ui_hsplit_b(&toolbox, 25.0f, &toolbox, &buttons);
ui_vsplit_r(&buttons, 100.0f, &buttons, &button);
ui_vmargin(&button, 2.0f, &button);
static int join_button = 0;
if(ui_do_button(&join_button, "Connect", 0, &button, ui_draw_menu_button, 0))
client_connect(config.ui_server_address);
ui_vsplit_r(&buttons, 20.0f, &buttons, &button);
ui_vsplit_r(&buttons, 100.0f, &buttons, &button);
ui_vmargin(&button, 2.0f, &button);
static int refresh_button = 0;
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);
}
//ui_vsplit_r(&buttons, 30.0f, &buttons, &button);
ui_vsplit_l(&buttons, 120.0f, &button, &buttons);
static int clear_button = 0;
if(ui_do_button(&clear_button, "Reset Filter", 0, &button, ui_draw_menu_button, 0))
{
config.b_filter_full = 0;
config.b_filter_empty = 0;
config.b_filter_pw = 0;
config.b_filter_ping = 999;
config.b_filter_gametype[0] = 0;
config.b_filter_compatversion = 1;
config.b_filter_string[0] = 0;
}
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);
ui_do_edit_box(&config.ui_server_address, &button, config.ui_server_address, sizeof(config.ui_server_address), 14.0f);
}
}