Skip to content

Commit

Permalink
Play ranked -> Quick play. Choose casual server with players if no ra…
Browse files Browse the repository at this point in the history
…nked has players.
  • Loading branch information
geneotech committed Aug 8, 2024
1 parent 321b1c0 commit 7a55b89
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/application/gui/main_menu_button_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum class main_menu_button_type {
DOWNLOAD_ON_STEAM,
#endif
DOWNLOAD_MAPS,
PLAY_RANKED,
QUICK_PLAY,
BROWSE_SERVERS,
HOST_SERVER,
#if !WEB_LOWEND
Expand Down
12 changes: 2 additions & 10 deletions src/application/gui/main_menu_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ using viewing_main_menu_context = viewing_menu_context<main_menu_button_type>;

struct main_menu_gui {
bool show = true;
bool has_play_ranked_button = false;

main_menu_context::tree_type tree;
main_menu_context::root_type root;
Expand Down Expand Up @@ -74,7 +73,7 @@ struct main_menu_gui {
}

if (change.was_pressed(augs::event::keys::key::C)) {
button_callback(main_menu_button_type::PLAY_RANKED);
button_callback(main_menu_button_type::QUICK_PLAY);
return true;
}

Expand Down Expand Up @@ -134,10 +133,7 @@ struct main_menu_gui {

root.set_menu_buttons_colors(cyan);
root.buttons[std::size_t(main_menu_button_type::DOWNLOAD_MAPS)].colorize = green;

if (has_play_ranked_button) {
root.buttons[std::size_t(main_menu_button_type::PLAY_RANKED)].color_wave = true;
}
root.buttons[std::size_t(main_menu_button_type::QUICK_PLAY)].color_wave = true;

root.set_menu_buttons_sizes(context.get_necessary_images(), gui_font, { 1000, 1000 });

Expand All @@ -146,10 +142,6 @@ struct main_menu_gui {
root.buttons[i].set_complete_caption(format_enum(e));
}

if (!has_play_ranked_button) {
root.buttons[std::size_t(main_menu_button_type::PLAY_RANKED)].set_complete_caption("Quick play");
}

int bi = 0;

#if !WEB_LOWEND
Expand Down
8 changes: 4 additions & 4 deletions src/application/gui/start_client_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ bool start_client_gui_state::perform(

checkbox("Show", show);
}
else if (current_tab == start_client_tab_type::BEST_RANKED) {
else if (current_tab == start_client_tab_type::BEST_SERVER) {
if (!best_server.has_value()) {
auto cs = scoped_style_color(ImGuiCol_FrameBg, rgba(255,255,255,0));

auto sname = std::string("Finding the best ranked server...");
auto sname = std::string("Finding the best server...");
input_text<max_server_name_length_v>("##BestServer", sname, ImGuiInputTextFlags_ReadOnly);
}
else {
Expand Down Expand Up @@ -570,15 +570,15 @@ bool start_client_gui_state::perform(
;

const bool best_still_unresolved =
current_tab == start_client_tab_type::BEST_RANKED
current_tab == start_client_tab_type::BEST_SERVER
&& best_server == std::nullopt
;

auto scope = maybe_disabled_cols({}, best_still_unresolved || custom_addr_empty || !is_nickname_valid_characters(into_vars.nickname) || !::nickname_len_in_range(into_vars.nickname.length()));

if (ImGui::Button("Connect!")) {
switch (current_tab) {
case start_client_tab_type::BEST_RANKED:
case start_client_tab_type::BEST_SERVER:
if (best_server) {
into_connect_string = std::string(best_server->get_connect_string());
into_displayed_connecting_server_name = best_server->heartbeat.server_name;
Expand Down
2 changes: 1 addition & 1 deletion src/application/gui/start_client_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class start_client_gui_state : public standard_window_mixin<start_client_gui_sta
bool mouse_has_to_move_off_browse = false;
std::optional<augs::frame_num_type> avatar_submitted_when;

start_client_tab_type current_tab = start_client_tab_type::BEST_RANKED;
start_client_tab_type current_tab = start_client_tab_type::BEST_SERVER;
bool request_refresh_best_server = false;
bool request_server_list_open = false;

Expand Down
2 changes: 1 addition & 1 deletion src/application/gui/start_client_tab_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

enum class start_client_tab_type {
// GEN INTROSPECTOR enum class start_client_tab_type
BEST_RANKED,
BEST_SERVER,
CUSTOM_ADDRESS,
REPLAY_DEMO,

Expand Down
2 changes: 1 addition & 1 deletion src/application/setups/main_menu_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ main_menu_setup::main_menu_setup(
initial_step_number = cosm.get_total_steps_passed();

#if 0
gui.root.buttons[main_menu_button_type::PLAY_RANKED].set_appearing_caption("Connect to official server");
gui.root.buttons[main_menu_button_type::QUICK_PLAY].set_appearing_caption("Connect to official server");
gui.root.buttons[main_menu_button_type::BROWSE_SERVERS].set_appearing_caption("Browse servers");
gui.root.buttons[main_menu_button_type::HOST_SERVER].set_appearing_caption("Host server");
gui.root.buttons[main_menu_button_type::CONNECT_TO_SERVER].set_appearing_caption("Connect to server");
Expand Down
31 changes: 23 additions & 8 deletions src/work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,6 @@ work_result work(
WEBSTATIC auto launch_main_menu = [&]() {
if (!has_main_menu()) {
main_menu_gui = {};
main_menu_gui.has_play_ranked_button = ranked_servers_enabled;

setup_launcher([&]() {
emplace_main_menu(*official, config.main_menu);
Expand Down Expand Up @@ -2600,10 +2599,26 @@ work_result work(
};

WEBSTATIC auto perform_start_client_gui = [&](const auto frame_num) {
const auto best_server = browse_servers_gui.find_best_server(ranked_servers_enabled);
auto best_casual = browse_servers_gui.find_best_server(false);
auto best_ranked = browse_servers_gui.find_best_server(ranked_servers_enabled);

if (ranked_servers_enabled) {
const bool has_casual_with_players = best_casual && best_casual->heartbeat.num_online > 0;
const bool no_ranked_with_players = !best_ranked.has_value() || best_ranked->heartbeat.num_online == 0;

if (has_casual_with_players && no_ranked_with_players) {
best_ranked = best_casual;
}
}

#if PLATFORM_WEB
if (!is_signed_in()) {
best_ranked = best_casual;
}
#endif

const bool perform_result = start_client_gui.perform(
best_server,
best_ranked,
browse_servers_gui.refresh_in_progress(),
frame_num,
get_general_renderer(),
Expand All @@ -2627,8 +2642,8 @@ work_result work(

browse_servers_gui.open();

if (best_server.has_value()) {
browse_servers_gui.select_server(*best_server);
if (best_ranked.has_value()) {
browse_servers_gui.select_server(*best_ranked);
}
}
};
Expand Down Expand Up @@ -3340,7 +3355,7 @@ work_result work(

#if BUILD_NETWORKING
if (start_client_gui.show) {
if (start_client_gui.current_tab == start_client_tab_type::BEST_RANKED) {
if (start_client_gui.current_tab == start_client_tab_type::BEST_SERVER) {
if (!browse_servers_gui.refreshed_at_least_once()) {
browse_servers_gui.refresh_server_list(get_browse_servers_input());
}
Expand Down Expand Up @@ -3685,15 +3700,15 @@ work_result work(

break;

case T::PLAY_RANKED:
case T::QUICK_PLAY:
if (common_input_state[augs::event::keys::key::LSHIFT]) {
#if !IS_PRODUCTION_BUILD
client_start_requested = true;
#endif
}
else {
start_client_gui.open();
start_client_gui.current_tab = start_client_tab_type::BEST_RANKED;
start_client_gui.current_tab = start_client_tab_type::BEST_SERVER;
}

break;
Expand Down

0 comments on commit 7a55b89

Please sign in to comment.