From ed7f9d9dc2c11377b001731b0cb86e0d29b7ec8d Mon Sep 17 00:00:00 2001 From: untodesu Date: Fri, 21 Mar 2025 18:35:24 +0500 Subject: Show a warning tooltip when protocol versions differ - Closes #4 --- data/lang/lang.en_US.json | 3 +++ game/client/play_menu.cc | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/data/lang/lang.en_US.json b/data/lang/lang.en_US.json index 24bd43a..d4ebca2 100644 --- a/data/lang/lang.en_US.json +++ b/data/lang/lang.en_US.json @@ -20,6 +20,9 @@ "play_menu.status.init": "Unknown", "play_menu.status.ping": "Pinging", + "play_menu.outdated_client": "Outdated client", + "play_menu.outdated_server": "Outdated server", + "direct_connection.title": "Direct connection", "direct_connection.connect": "Connect", "direct_connection.cancel": "Cancel", diff --git a/game/client/play_menu.cc b/game/client/play_menu.cc index 1c89252..421751a 100644 --- a/game/client/play_menu.cc +++ b/game/client/play_menu.cc @@ -18,6 +18,7 @@ constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration; constexpr static const char *DEFAULT_SERVER_NAME = "Voxelius Server"; constexpr static const char *SERVERS_TXT = "servers.txt"; +constexpr static const char *WARNING_TOAST = "[!]"; enum class item_status : unsigned int { UNKNOWN = 0x0000U, @@ -59,6 +60,9 @@ static std::string str_status_init; static std::string str_status_ping; static std::string str_status_fail; +static std::string str_outdated_client; +static std::string str_outdated_server; + static std::string input_itemname; static std::string input_hostname; static std::string input_password; @@ -177,6 +181,9 @@ static void on_language_set(const LanguageSetEvent &event) str_status_init = language::resolve("play_menu.status.init"); str_status_ping = language::resolve("play_menu.status.ping"); str_status_fail = language::resolve("play_menu.status.fail"); + + str_outdated_client = language::resolve("play_menu.outdated_client"); + str_outdated_server = language::resolve("play_menu.outdated_server"); } static void on_bother_response(const BotherResponseEvent &event) @@ -235,10 +242,25 @@ static void layout_server_item(ServerStatusItem *item) draw_list->AddText(name_pos, ImGui::GetColorU32(ImGuiCol_Text), item->name.c_str(), item->name.c_str() + item->name.size()); if(item->status == item_status::REACHED) { - const std::string stats = fmt::format("{}/{}", item->num_players, item->max_players); - const float stats_width = ImGui::CalcTextSize(stats.c_str(), stats.c_str() + stats.size()).x; - const ImVec2 stats_pos = ImVec2(cursor.x + item_width - stats_width - padding.x, cursor.y + padding.y); + auto stats = fmt::format("{}/{}", item->num_players, item->max_players); + auto stats_width = ImGui::CalcTextSize(stats.c_str(), stats.c_str() + stats.size()).x; + auto stats_pos = ImVec2(cursor.x + item_width - stats_width - padding.x, cursor.y + padding.y); draw_list->AddText(stats_pos, ImGui::GetColorU32(ImGuiCol_TextDisabled), stats.c_str(), stats.c_str() + stats.size()); + + if(item->protocol_version != protocol::VERSION) { + auto warning_size = ImGui::CalcTextSize(WARNING_TOAST); + auto warning_pos = ImVec2(stats_pos.x - warning_size.x - padding.x - 4.0f * globals::gui_scale, cursor.y + padding.y); + auto warning_end = ImVec2(warning_pos.x + warning_size.x, warning_pos.y + warning_size.y); + draw_list->AddText(warning_pos, ImGui::GetColorU32(ImGuiCol_DragDropTarget), WARNING_TOAST); + + if(ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + if(item->protocol_version < protocol::VERSION) + ImGui::TextUnformatted(str_outdated_server.c_str(), str_outdated_server.c_str() + str_outdated_server.size()); + else ImGui::TextUnformatted(str_outdated_client.c_str(), str_outdated_client.c_str() + str_outdated_client.size()); + ImGui::EndTooltip(); + } + } } ImU32 motd_color = {}; -- cgit