Skip to content

Commit

Permalink
Show servers with players at the top.
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Aug 8, 2024
1 parent 5c4ea12 commit 321b1c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
43 changes: 20 additions & 23 deletions src/application/gui/browse_servers_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,16 @@ void browse_servers_gui_state::show_server_list(

ImGui::NextColumn();

const auto players_text = typesafe_sprintf("%x/%x", d.num_online, d.max_online);

if (d.num_online == 0) {
text_disabled(players_text);
}
else {
do_text(players_text);
}
ImGui::NextColumn();

if (s.is_official_server() ) {
if (d.is_ranked_server()) {
const auto location_id = d.get_location_id();
Expand All @@ -766,17 +776,6 @@ void browse_servers_gui_state::show_server_list(

ImGui::NextColumn();

const auto players_text = typesafe_sprintf("%x/%x", d.num_online, d.max_online);

if (d.num_online == 0) {
text_disabled(players_text);
}
else {
do_text(players_text);
}

ImGui::NextColumn();

{
auto displayed_arena = std::string(d.current_arena);

Expand Down Expand Up @@ -996,10 +995,10 @@ bool browse_servers_gui_state::perform(const browse_servers_input in) {
return sort_by(by_name, by_ping, by_appeared);

case 2:
return sort_by(by_time_to_event, by_ping, by_appeared);
return sort_by(by_players, by_ping, by_appeared);

case 3:
return sort_by(by_players, by_ping, by_appeared);
return sort_by(by_time_to_event, by_ping, by_appeared);

case 4:
return sort_by(by_arena, by_ping, by_appeared);
Expand Down Expand Up @@ -1094,8 +1093,8 @@ bool browse_servers_gui_state::perform(const browse_servers_input in) {
auto do_column_labels = [&](const auto& with_label, const auto& col) {
do_column("Ping");
do_column(with_label, col);
do_column("Event");
do_column("Players");
do_column("Event");
do_column("Arena");
do_column("Game mode");
do_column("Uptime");
Expand Down Expand Up @@ -1272,21 +1271,19 @@ bool browse_servers_gui_state::perform(const browse_servers_input in) {
return false;
}

std::optional<server_list_entry> browse_servers_gui_state::find_best_server() const {
if (server_list.empty()) {
return std::nullopt;
}

return minimum_of(server_list, compare_servers);
}

std::optional<server_list_entry> browse_servers_gui_state::find_best_server(const bool find_ranked) const {
auto filtered = server_list;

erase_if(
filtered,
[&](auto& f) {
const bool good = f.is_official_server() && (find_ranked && f.heartbeat.is_still_joinable_ranked());
if (const bool casual = !find_ranked) {
const bool is_ranked = f.is_official_server() && f.heartbeat.is_ranked_server();

return is_ranked;
}

const bool good = f.is_official_server() && f.heartbeat.is_still_joinable_ranked();

return !good;
}
Expand Down
5 changes: 2 additions & 3 deletions src/application/gui/browse_servers_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class browse_servers_gui_state : public standard_window_mixin<browse_servers_gui
augs::maybe<int> at_least_players = augs::maybe<int>(1, false);
augs::maybe<uint32_t> at_most_ping = augs::maybe<uint32_t>(100, false);

int sort_by_column = 0;
bool ascending = true;
int sort_by_column = 2;
bool ascending = false;
std::string loading_dots;
uint64_t ping_sequence_counter = 0;

Expand Down Expand Up @@ -122,7 +122,6 @@ class browse_servers_gui_state : public standard_window_mixin<browse_servers_gui
void reping_all_servers();

const server_list_entry* find_entry_by_connect_string(const client_connect_string& in) const;
std::optional<server_list_entry> find_best_server() const;
std::optional<server_list_entry> find_best_server(bool is_ranked) const;
void refresh_server_list(browse_servers_input);

Expand Down

0 comments on commit 321b1c0

Please sign in to comment.