mirror of
https://github.com/nzp-team/quakec.git
synced 2024-11-28 14:52:29 +00:00
MENU: Co-Op menus WIP
This commit is contained in:
parent
9d1d4c3bab
commit
6ce5294367
7 changed files with 342 additions and 10 deletions
|
@ -23,6 +23,7 @@ menu_gpad.qc // Gamepad Menu
|
|||
menu_bind.qc // Bindings Menu
|
||||
menu_cred.qc // Credits Menu
|
||||
menu_load.qc // Loading Screen
|
||||
menu_coop.qc // Co-op Menu
|
||||
|
||||
main.qc
|
||||
#endlist
|
||||
#endlist
|
||||
|
|
|
@ -38,6 +38,13 @@ enum {
|
|||
MENU_MAIN,
|
||||
MENU_SOLO,
|
||||
MENU_SOLOUSER,
|
||||
MENU_COOP,
|
||||
MENU_COOPJOIN,
|
||||
MENU_COOPBROWSE,
|
||||
MENU_COOPDIRECT,
|
||||
MENU_COOPCREATE,
|
||||
MENU_COOPSTOCK,
|
||||
MENU_COOPUSER,
|
||||
MENU_OPTIONS,
|
||||
MENU_VIDEO,
|
||||
MENU_AUDIO,
|
||||
|
@ -56,6 +63,11 @@ void(float type) Menu_PlaySound;
|
|||
|
||||
void() Menu_Main;
|
||||
void() Menu_Maps;
|
||||
void() Menu_Coop;
|
||||
void() Menu_Coop_Join;
|
||||
void() Menu_Coop_Browse;
|
||||
void() Menu_Coop_Direct;
|
||||
void() Menu_Coop_Create;
|
||||
void() Menu_Credits;
|
||||
|
||||
#else
|
||||
|
@ -134,4 +146,4 @@ var struct
|
|||
{"nzp_warehouse", 0},
|
||||
{"nzp_warehouse2", 0},
|
||||
{"christmas_special", 0}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -32,6 +32,8 @@ void(string id, vector pos, vector size, float maxlen, __inout string text, __in
|
|||
sui_fill([0, 0], size, basecolor, 0.6, 0);
|
||||
|
||||
sui_text_input(id, [0, 0], size, text, cursor);
|
||||
|
||||
sui_cap_input_length(maxlen, text, cursor);
|
||||
|
||||
sui_set_align([SUI_ALIGN_START, SUI_ALIGN_CENTER]);
|
||||
float focused = sui_is_last_clicked(id);
|
||||
|
@ -550,6 +552,101 @@ void(float order, vector minmaxsteps, string cvar_s, float is_int, float no_text
|
|||
}
|
||||
};
|
||||
|
||||
static void(string id, vector pos, vector size, __inout string text, __inout float cursor) handle_text_input =
|
||||
{
|
||||
sui_action_element(pos, size, id, sui_noop);
|
||||
if (sui_is_clicked(id)) cursor = strlen(text);
|
||||
if (sui_is_hovered(id))
|
||||
{
|
||||
float char = 0;
|
||||
float scan = 0;
|
||||
while(sui_get_input(char, scan)) sui_handle_text_input(char, scan, text, cursor);
|
||||
}
|
||||
};
|
||||
|
||||
static void(vector pos, vector size, string text) draw_text_input =
|
||||
{
|
||||
sui_push_frame(pos, size);
|
||||
sui_fill([0, 0], size, [0.5, 0.1, 0.1], 1.0, 0);
|
||||
sui_set_align([SUI_ALIGN_START, SUI_ALIGN_CENTER]);
|
||||
sui_text([6, 0], MENU_TEXT_SMALL, text, MENU_TEXT_1, 1, 0);
|
||||
sui_pop_frame();
|
||||
};
|
||||
|
||||
//
|
||||
// Menu_TextInput(id, order, text, cursor)
|
||||
// Draws a Text Input box at the given order position
|
||||
//
|
||||
void(string id, float order, __inout string text, __inout float cursor) Menu_TextInput =
|
||||
{
|
||||
vector pos = [320, 50 + (order * 25)];
|
||||
vector size = [240, 16];
|
||||
|
||||
handle_text_input(id, pos, size, text, cursor);
|
||||
|
||||
draw_text_input(pos, size, text);
|
||||
};
|
||||
|
||||
//
|
||||
// Menu_PasswordInput(id, order, text, cursor)
|
||||
// Draws a Text Input box at the given order position (blocked out with asterisks)
|
||||
//
|
||||
void(string id, float order, __inout string text, __inout float cursor) Menu_PasswordInput =
|
||||
{
|
||||
vector pos = [320, 50 + (order * 25)];
|
||||
vector size = [240, 16];
|
||||
string safe = "";
|
||||
|
||||
for (int i = 0; i < strlen(text); i++)
|
||||
safe = sprintf("%s%s", safe, "*");
|
||||
|
||||
handle_text_input(id, pos, size, text, cursor);
|
||||
|
||||
draw_text_input(pos, size, safe);
|
||||
};
|
||||
|
||||
//
|
||||
// Menu_ServerList(id, pos, size, scrollofs, num_servers)
|
||||
// Draw the master server list
|
||||
//
|
||||
void(string id, vector pos, vector size, __inout vector scrollofs, float num_servers) Menu_ServerList =
|
||||
{
|
||||
vector rowsize = [size.x, 16];
|
||||
vector listitem_pos = [0, 0, 0];
|
||||
sui_fill(pos, size, [0, 0, 0], 0.75, 0);
|
||||
sui_list_view_begin(strcat(id, "scrl"), pos, size, rowsize, num_servers, scrollofs, [0, 8]);
|
||||
for (float index = sui_list_item(listitem_pos); index > -1; index = sui_list_item(listitem_pos))
|
||||
{
|
||||
sui_push_frame(listitem_pos, rowsize);
|
||||
sui_set_align([SUI_ALIGN_START, SUI_ALIGN_CENTER]);
|
||||
|
||||
// bg
|
||||
vector bpos = [0, 0];
|
||||
vector bsize = [rowsize.x / 3, rowsize.y];
|
||||
sui_fill(bpos, rowsize, [0.25, 0.25, 0.25], 0.5, 0);
|
||||
|
||||
// name
|
||||
sui_fill(bpos, bsize, [0.25, 0.25, 0.25], 0.5, 0);
|
||||
sui_text(bpos + [8, 0], MENU_TEXT_SMALL, gethostcachestring(gethostcacheindexforkey("name"), index), MENU_TEXT_1, 1, 0);
|
||||
|
||||
// map
|
||||
bpos.x = size.x / 3;
|
||||
sui_text(bpos + [8, 0], MENU_TEXT_SMALL, gethostcachestring(gethostcacheindexforkey("map"), index), MENU_TEXT_1, 1, 0);
|
||||
|
||||
// players
|
||||
bpos.x *= 2;
|
||||
string s = sprintf("%d/%d",
|
||||
stof(gethostcachestring(gethostcacheindexforkey("numhumans"), index)),
|
||||
stof(gethostcachestring(gethostcacheindexforkey("maxplayers"), index))
|
||||
);
|
||||
sui_fill(bpos, bsize, [0.25, 0.25, 0.25], 0.5, 0);
|
||||
sui_text(bpos + [8, 0], MENU_TEXT_SMALL, s, MENU_TEXT_1, 1, 0);
|
||||
|
||||
sui_pop_frame();
|
||||
}
|
||||
sui_list_view_end();
|
||||
};
|
||||
|
||||
struct name_command {
|
||||
string name;
|
||||
string command;
|
||||
|
@ -665,6 +762,13 @@ void(vector size) root_menu =
|
|||
case MENU_MAIN: Menu_Main(); break;
|
||||
case MENU_SOLO: menu_map_mode = MAP_SOLOSTOCK; Menu_Maps(); break;
|
||||
case MENU_SOLOUSER: menu_map_mode = MAP_SOLOUSER; Menu_Maps(); break;
|
||||
case MENU_COOP: Menu_Coop(); break;
|
||||
case MENU_COOPJOIN: Menu_Coop_Join(); break;
|
||||
case MENU_COOPBROWSE: Menu_Coop_Browse(); break;
|
||||
case MENU_COOPDIRECT: Menu_Coop_Direct(); break;
|
||||
case MENU_COOPCREATE: Menu_Coop_Create(); break;
|
||||
case MENU_COOPSTOCK: menu_map_mode = MAP_COOPSTOCK; Menu_Maps(); break;
|
||||
case MENU_COOPUSER: menu_map_mode = MAP_COOPUSER; Menu_Maps(); break;
|
||||
case MENU_CREDITS: Menu_Credits(); break;
|
||||
|
||||
#else
|
||||
|
@ -689,4 +793,4 @@ void(vector size) root_menu =
|
|||
last_menu = current_menu;
|
||||
sui_reset_hover();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
199
source/menu/menu_coop.qc
Normal file
199
source/menu/menu_coop.qc
Normal file
|
@ -0,0 +1,199 @@
|
|||
|
||||
float player_name_cursor;
|
||||
string player_name;
|
||||
|
||||
float server_ip_cursor;
|
||||
string server_ip;
|
||||
|
||||
float server_hostname_cursor;
|
||||
string server_hostname;
|
||||
|
||||
float server_password_cursor;
|
||||
string server_password;
|
||||
|
||||
float server_port_cursor;
|
||||
string server_port;
|
||||
|
||||
int num_cached_servers;
|
||||
|
||||
void() Menu_Coop_Name_Update =
|
||||
{
|
||||
static float initialized;
|
||||
if (!initialized)
|
||||
{
|
||||
player_name = cvar_string("name");
|
||||
player_name_cursor = strlen(player_name);
|
||||
initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cvar_set("name", player_name);
|
||||
}
|
||||
};
|
||||
|
||||
void() Menu_Coop_Hostname_Update =
|
||||
{
|
||||
static float initialized;
|
||||
if (!initialized)
|
||||
{
|
||||
server_hostname = cvar_string("hostname");
|
||||
server_hostname_cursor = strlen(server_hostname);
|
||||
initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cvar_set("hostname", server_hostname);
|
||||
}
|
||||
};
|
||||
|
||||
void() Menu_Coop_Port_Update =
|
||||
{
|
||||
static float initialized;
|
||||
if (!initialized)
|
||||
{
|
||||
server_port = cvar_string("sv_port");
|
||||
server_port_cursor = strlen(server_port);
|
||||
initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cvar_set("sv_port", server_port);
|
||||
}
|
||||
};
|
||||
|
||||
void() Menu_Coop_Password_Update =
|
||||
{
|
||||
static float initialized;
|
||||
if (!initialized)
|
||||
{
|
||||
server_password = cvar_string("password");
|
||||
server_password_cursor = strlen(server_password);
|
||||
initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cvar_set("password", server_password);
|
||||
}
|
||||
};
|
||||
|
||||
void() Menu_Coop_Browse_Refresh =
|
||||
{
|
||||
static float refreshtime;
|
||||
|
||||
if (refreshtime > time)
|
||||
return;
|
||||
|
||||
refreshtime = time + 0.5;
|
||||
|
||||
resethostcachemasks();
|
||||
// TODO: figure out why this returns 0 servers
|
||||
// sethostcachemaskstring(0, gethostcacheindexforkey("gamedir"), cvar_string("game"), SLIST_TEST_EQUAL);
|
||||
sethostcachesort(gethostcacheindexforkey("ping"), false);
|
||||
refreshhostcache(false);
|
||||
resorthostcache();
|
||||
|
||||
num_cached_servers = (int)gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT);
|
||||
};
|
||||
|
||||
void() Menu_Coop_Browse =
|
||||
{
|
||||
|
||||
Menu_Coop_Browse_Refresh();
|
||||
|
||||
Menu_DrawBackground();
|
||||
|
||||
Menu_DrawTitle("BROWSE SERVERS");
|
||||
|
||||
// draw server list
|
||||
sui_set_align([SUI_ALIGN_CENTER, SUI_ALIGN_CENTER]);
|
||||
static vector serverlist_scrollofs;
|
||||
vector vsize = sui_current_frame_size();
|
||||
Menu_ServerList("cbm_serverlist", [0, 0], [vsize.x, vsize.y / 2], serverlist_scrollofs, num_cached_servers);
|
||||
|
||||
Menu_Button(-1, "cbm_back", "BACK", "Return to Join Game Menu.") ? current_menu = MENU_COOPJOIN : 0;
|
||||
|
||||
sui_pop_frame();
|
||||
};
|
||||
|
||||
void() Menu_Coop_Direct =
|
||||
{
|
||||
Menu_Coop_Password_Update();
|
||||
|
||||
Menu_DrawBackground();
|
||||
|
||||
Menu_DrawTitle("DIRECT IP/ID");
|
||||
|
||||
Menu_Button(1, "cdm_serverip", "SERVER IP/ROOM ID", "IP or ID for the Server (typically starts with /).");
|
||||
Menu_TextInput("cdm_serverip", 1, server_ip, server_ip_cursor);
|
||||
|
||||
Menu_Button(2, "cdm_serverpassword", "SERVER PASSWORD", "Password for the Match set by the Host.");
|
||||
Menu_PasswordInput("cdm_serverpassword", 2, server_password, server_password_cursor);
|
||||
|
||||
Menu_DrawDivider(3);
|
||||
Menu_Button(3.25, "cdm_connect", "CONNECT TO SERVER", "Attempt to connect to Game.") ? localcmd("connect ", server_ip, "\n") : 0;
|
||||
|
||||
Menu_Button(-1, "cdm_back", "BACK", "Return to Join Game Menu.") ? current_menu = MENU_COOPJOIN : 0;
|
||||
|
||||
sui_pop_frame();
|
||||
};
|
||||
|
||||
void() Menu_Coop_Join =
|
||||
{
|
||||
Menu_DrawBackground();
|
||||
|
||||
Menu_DrawTitle("JOIN GAME");
|
||||
|
||||
Menu_Button(1, "cjm_browse", "BROWSE SERVERS", "Browse the list of active Servers.") ? current_menu = MENU_COOPBROWSE : 0;
|
||||
Menu_Button(2, "cjm_direct", "DIRECT IP/ID", "Connect directly to an active Server.") ? current_menu = MENU_COOPDIRECT : 0;
|
||||
|
||||
Menu_Button(-1, "cjm_back", "BACK", "Return to Co-Op Menu.") ? current_menu = MENU_COOP : 0;
|
||||
|
||||
sui_pop_frame();
|
||||
};
|
||||
|
||||
void() Menu_Coop_Create =
|
||||
{
|
||||
Menu_Coop_Hostname_Update();
|
||||
Menu_Coop_Port_Update();
|
||||
Menu_Coop_Password_Update();
|
||||
|
||||
Menu_DrawBackground();
|
||||
|
||||
Menu_DrawTitle("CREATE GAME");
|
||||
|
||||
Menu_Button(1, "ccm_servername", "SERVER NAME", "Enter a name that will appear in the Server List.");
|
||||
Menu_TextInput("ccm_servername", 1, server_hostname, server_hostname_cursor);
|
||||
|
||||
Menu_Button(2, "ccm_port", "SERVER PORT", "Edit the port that the Server will use.");
|
||||
Menu_TextInput("ccm_port", 2, server_port, server_port_cursor);
|
||||
|
||||
Menu_Button(3, "ccm_password", "SERVER PASSWORD", "Enter an (optional) password to limit who can join.");
|
||||
Menu_PasswordInput("ccm_password", 3, server_password, server_password_cursor);
|
||||
|
||||
Menu_DrawDivider(4);
|
||||
Menu_Button(4.25, "ccm_choosemap", "CHOOSE MAP", "Select a Map to start the Game.") ? current_menu = MENU_COOPSTOCK : 0;
|
||||
|
||||
Menu_Button(-1, "ccm_back", "BACK", "Return to Co-Op Menu.") ? current_menu = MENU_COOP : 0;
|
||||
|
||||
sui_pop_frame();
|
||||
};
|
||||
|
||||
void() Menu_Coop =
|
||||
{
|
||||
Menu_Coop_Name_Update();
|
||||
|
||||
Menu_DrawBackground();
|
||||
|
||||
Menu_DrawTitle("COOPERATIVE");
|
||||
|
||||
Menu_Button(1, "cm_playername", "PLAYER NAME", "Name that appears in-game and on the Scoreboard.");
|
||||
Menu_TextInput("cm_playername", 1, player_name, player_name_cursor);
|
||||
|
||||
Menu_DrawDivider(2);
|
||||
Menu_Button(2.25, "cm_join", "JOIN GAME", "Join an in-progress Match.") ? current_menu = MENU_COOPJOIN : 0;
|
||||
Menu_Button(3.25, "cm_create", "CREATE GAME", "Create a new Match for others to join.") ? current_menu = MENU_COOPCREATE : 0;
|
||||
|
||||
Menu_Button(-1, "cm_back", "BACK", "Return to Main Menu.") ? current_menu = MENU_MAIN : 0;
|
||||
|
||||
sui_pop_frame();
|
||||
};
|
|
@ -72,7 +72,7 @@ void() Menu_Main =
|
|||
Menu_DrawBuildDate();
|
||||
|
||||
Menu_Button(1, "mm_start", "SOLO", "Play Solo.") ? current_menu = MENU_SOLO : 0;
|
||||
Menu_Button(2, "mm_coop", "COOPERATIVE", "Play with up to Four Players.") ? localcmd("\n") : 0;
|
||||
Menu_Button(2, "mm_coop", "COOPERATIVE", "Play with up to Four Players.") ? current_menu = MENU_COOP : 0;
|
||||
Menu_DrawDivider(3);
|
||||
Menu_Button(3.25, "mm_options", "CONFIGURATION", "Tweak Game related Options.") ? current_menu = MENU_OPTIONS : 0;
|
||||
//Menu_Button(4.25, "mm_achievements", "ACHIEVEMENTS", "View Achievement Progress.") ? localcmd("\n") : 0;
|
||||
|
@ -92,4 +92,4 @@ void() Menu_Main =
|
|||
Menu_SocialBadge(4, "soc_matrix", "discord.nzp.gay", 1); // FIXME: Move to Matrix
|
||||
|
||||
sui_pop_frame();
|
||||
};
|
||||
};
|
||||
|
|
|
@ -105,8 +105,8 @@ void() Menu_Maps =
|
|||
switch(menu_map_mode) {
|
||||
case MAP_SOLOSTOCK: Menu_DrawTitle("SELECT MAP: SOLO"); back_string = "Return to Main Menu."; back_menudest = MENU_MAIN; break;
|
||||
case MAP_SOLOUSER: Menu_DrawTitle("USER MAPS: SOLO"); back_string = "Return to Stock Map selection."; back_menudest = MENU_SOLO; break;
|
||||
case MAP_COOPSTOCK: Menu_DrawTitle("SELECT MAP: COOP"); break;
|
||||
case MAP_COOPUSER: Menu_DrawTitle("USER MAPS: COOP"); break;
|
||||
case MAP_COOPSTOCK: Menu_DrawTitle("SELECT MAP: COOP"); back_string = "Return to Create Game Menu."; back_menudest = MENU_COOPCREATE; break;
|
||||
case MAP_COOPUSER: Menu_DrawTitle("USER MAPS: COOP"); back_string = "Return to Stock Map selection."; back_menudest = MENU_COOPSTOCK; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,12 @@ void() Menu_Maps =
|
|||
Menu_MapButton(i + 1, sprintf("map_%s", stock_maps[i].bsp_name), stock_maps[i].bsp_name, -1) ? Menu_Maps_LoadMap(stock_maps[i].bsp_name) : 0;
|
||||
}
|
||||
Menu_DrawDivider(i + 1.25);
|
||||
Menu_Button(i + 1.5, "map_nzpusermaps", "USER MAPS", "View User-Created Maps.") ? current_menu = MENU_SOLOUSER : 0;
|
||||
|
||||
if (menu_map_mode == MAP_SOLOSTOCK) {
|
||||
Menu_Button(i + 1.5, "map_nzpusermaps", "USER MAPS", "View User-Created Maps.") ? current_menu = MENU_SOLOUSER : 0;
|
||||
} else if (menu_map_mode == MAP_COOPSTOCK) {
|
||||
Menu_Button(i + 1.5, "map_nzpusermaps", "USER MAPS", "View User-Created Maps.") ? current_menu = MENU_COOPUSER : 0;
|
||||
}
|
||||
|
||||
// Usermaps and back button registry
|
||||
menu_maps_buttons[i] = "map_nzpusermaps";
|
||||
|
@ -178,4 +183,4 @@ void() Menu_Maps =
|
|||
Menu_Button(-1, "map_back", "BACK", back_string) ? current_menu = back_menudest : 0;
|
||||
|
||||
sui_pop_frame();
|
||||
};
|
||||
};
|
||||
|
|
|
@ -400,6 +400,17 @@ void() _sui_menukey_downarrow =
|
|||
case MENU_MAIN:
|
||||
_hover_actions[0] = Menu_Main_GetNextButton(current_hovered_option);
|
||||
break;
|
||||
// TODO: do this
|
||||
#if 0
|
||||
case MENU_COOP:
|
||||
case MENU_COOPJOIN:
|
||||
case MENU_COOPBROWSE:
|
||||
case MENU_COOPDIRECT:
|
||||
case MENU_COOPCREATE:
|
||||
case MENU_COOPSTOCK:
|
||||
_hover_actions[0] = Menu_Maps_GetNextButton(current_hovered_option);
|
||||
break;
|
||||
#endif
|
||||
case MENU_SOLO:
|
||||
case MENU_SOLOUSER:
|
||||
_hover_actions[0] = Menu_Maps_GetNextButton(current_hovered_option);
|
||||
|
@ -1070,4 +1081,4 @@ string(string id, vector pos, vector size, string name, string command) sui_bind
|
|||
return keyname;
|
||||
};
|
||||
|
||||
// -------------------- END OF SUI SYSTEM STUFF --------------------
|
||||
// -------------------- END OF SUI SYSTEM STUFF --------------------
|
||||
|
|
Loading…
Reference in a new issue