diff --git a/data/cdata/ui_scripts/server_list/__init__.lua b/data/cdata/ui_scripts/server_list/__init__.lua index 94df0df8..b17a57f4 100644 --- a/data/cdata/ui_scripts/server_list/__init__.lua +++ b/data/cdata/ui_scripts/server_list/__init__.lua @@ -4,3 +4,4 @@ end require("lobby") require("serverlist") +require("confirm") diff --git a/data/cdata/ui_scripts/server_list/confirm.lua b/data/cdata/ui_scripts/server_list/confirm.lua new file mode 100644 index 00000000..da79dadc --- /dev/null +++ b/data/cdata/ui_scripts/server_list/confirm.lua @@ -0,0 +1,12 @@ +LUI.MenuBuilder.m_types_build["popup_confirmdownload"] = function() + return LUI.MenuBuilder.BuildRegisteredType("generic_yesno_popup", { + popup_title = Engine.Localize("@MENU_NOTICE"), + message_text = Engine.Localize("@LUA_MENU_3RD_PARTY_CONTENT_DESC", download.getwwwurl()), + yes_action = function() + download.userdownloadresponse(true) + end, + no_action = function() + download.userdownloadresponse(false) + end + }) +end diff --git a/data/zonetool/h1_mod_common/localizedstrings/english.json b/data/zonetool/h1_mod_common/localizedstrings/english.json index c07118fd..caebe8bb 100644 --- a/data/zonetool/h1_mod_common/localizedstrings/english.json +++ b/data/zonetool/h1_mod_common/localizedstrings/english.json @@ -62,6 +62,8 @@ "MPHUD_LATENCY_MS": " ms", "LUA_MENU_TELEMETRY": "TELEMETRY", + "LUA_MENU_3RD_PARTY_CONTENT_DESC": "Would you like to install required 3rd-party content for this server? (from &&1)", + "MENU_ENGLISH": "English", "MENU_ENGLISH_SAFE": "English (Safe)", "MENU_FRENCH": "Français", diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 235e8186..6962600f 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -355,27 +355,7 @@ namespace party bool download_files(const game::netadr_s& target, const utils::info_string& info, bool allow_download); - void user_download_response(bool response) - { - if (!response) - { - return; - } - - nlohmann::json obj = get_whitelist_json_object(); - if (obj == nullptr) - { - obj = {}; - } - - obj.push_back(target_ip_to_string(saved_info_response.host)); - - utils::io::write_file(get_whitelist_json_path(), obj.dump(4)); - - download_files(saved_info_response.host, saved_info_response.info_string, true); - } - - bool should_user_confirm(const game::netadr_s& target, const utils::info_string& info) + bool should_user_confirm(const game::netadr_s& target) { nlohmann::json obj = get_whitelist_json_object(); if (obj != nullptr) @@ -390,17 +370,8 @@ namespace party } } - const auto LUI = ui_scripting::get_globals().get("LUI").as(); - const auto yes_no_popup_func = LUI.get("yesnopopup").as(); - close_joining_popups(); - - const ui_scripting::table data_table{}; - data_table.set("title", game::UI_SafeTranslateString("MENU_NOTICE")); - data_table.set("text", std::format("Would you like to install required 3rd-party content for this server? (from {})", info.get("sv_wwwBaseUrl"))); - data_table.set("callback", user_download_response); - - yes_no_popup_func(data_table); + command::execute("lui_open_popup popup_confirmdownload", false); return true; } @@ -419,7 +390,7 @@ namespace party if (files.size() > 0) { - if (!allow_download && should_user_confirm(target, info)) + if (!allow_download && should_user_confirm(target)) { return true; } @@ -550,6 +521,31 @@ namespace party } } + std::string get_www_url() + { + return saved_info_response.info_string.get("sv_wwwBaseUrl"); + } + + void user_download_response(bool response) + { + if (!response) + { + return; + } + + nlohmann::json obj = get_whitelist_json_object(); + if (obj == nullptr) + { + obj = {}; + } + + obj.push_back(target_ip_to_string(saved_info_response.host)); + + utils::io::write_file(get_whitelist_json_path(), obj.dump(4)); + + download_files(saved_info_response.host, saved_info_response.info_string, true); + } + void menu_error(const std::string& error) { console::error("%s\n", error.data()); diff --git a/src/client/component/party.hpp b/src/client/component/party.hpp index 69590895..ca4852b2 100644 --- a/src/client/component/party.hpp +++ b/src/client/component/party.hpp @@ -3,6 +3,9 @@ namespace party { + std::string get_www_url(); + void user_download_response(bool response); + void menu_error(const std::string& error); void reset_connect_state(); diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 7db9c820..7e2e0d5e 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -19,6 +19,7 @@ #include "scripting.hpp" #include "updater.hpp" #include "server_list.hpp" +#include "party.hpp" #include "game/ui_scripting/execution.hpp" #include "game/scripting/execution.hpp" @@ -363,6 +364,9 @@ namespace ui_scripting lua["download"] = download_table; download_table["abort"] = download::stop_download; + + download_table["userdownloadresponse"] = party::user_download_response; + download_table["getwwwurl"] = party::get_www_url; } void start()