fixed the favorite button in the server info

This commit is contained in:
Magnus Auvinen 2008-11-08 12:58:39 +00:00
parent 388a04d957
commit aee14baf8d
4 changed files with 28 additions and 3 deletions

View file

@ -849,6 +849,7 @@ static void client_process_packet(NETCHUNK *packet)
if(net_addr_comp(&server_address, &packet->address) == 0) if(net_addr_comp(&server_address, &packet->address) == 0)
{ {
mem_copy(&current_server_info, &info, sizeof(current_server_info)); mem_copy(&current_server_info, &info, sizeof(current_server_info));
current_server_info.netaddr = server_address;
current_server_info_requesttime = -1; current_server_info_requesttime = -1;
} }

View file

@ -647,6 +647,18 @@ void client_serverbrowse_update()
} }
int client_serverbrowse_isfavorite(NETADDR addr)
{
/* search for the address */
int i;
for(i = 0; i < num_favorite_servers; i++)
{
if(net_addr_comp(&addr, &favorite_servers[i]) == 0)
return 1;
}
return 0;
}
void client_serverbrowse_addfavorite(NETADDR addr) void client_serverbrowse_addfavorite(NETADDR addr)
{ {
int i; int i;

View file

@ -306,6 +306,18 @@ void client_serverbrowse_update();
*/ */
int client_serverbrowse_lan(); int client_serverbrowse_lan();
/*
Function: client_serverbrowse_isfavorite
Asks the server browser is a netaddr is in the favorite list
Arguments:
addr - Address of the server to ask about.
Returns:
Returns zero if it's not in the list, non-zero if it is.
*/
int client_serverbrowse_isfavorite(NETADDR addr);
/* /*
Function: client_serverbrowse_addfavorite Function: client_serverbrowse_addfavorite
Adds a server to the favorite list Adds a server to the favorite list

View file

@ -209,15 +209,15 @@ void MENUS::render_serverinfo(RECT main_view)
{ {
RECT button; RECT button;
int is_favorite = client_serverbrowse_isfavorite(current_server_info.netaddr);
ui_hsplit_b(&serverinfo, 20.0f, &serverinfo, &button); ui_hsplit_b(&serverinfo, 20.0f, &serverinfo, &button);
static int add_fav_button = 0; static int add_fav_button = 0;
if (ui_do_button(&add_fav_button, "Favorite", current_server_info.favorite, &button, ui_draw_checkbox, 0)) if (ui_do_button(&add_fav_button, "Favorite", is_favorite, &button, ui_draw_checkbox, 0))
{ {
if(current_server_info.favorite) if(is_favorite)
client_serverbrowse_removefavorite(current_server_info.netaddr); client_serverbrowse_removefavorite(current_server_info.netaddr);
else else
client_serverbrowse_addfavorite(current_server_info.netaddr); client_serverbrowse_addfavorite(current_server_info.netaddr);
current_server_info.favorite = !current_server_info.favorite;
} }
} }