handle popup in lua instead
This commit is contained in:
parent
a268b492f6
commit
df47c906c4
@ -4,3 +4,4 @@ end
|
||||
|
||||
require("lobby")
|
||||
require("serverlist")
|
||||
require("confirm")
|
||||
|
12
data/cdata/ui_scripts/server_list/confirm.lua
Normal file
12
data/cdata/ui_scripts/server_list/confirm.lua
Normal file
@ -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
|
@ -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",
|
||||
|
@ -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<ui_scripting::table>();
|
||||
const auto yes_no_popup_func = LUI.get("yesnopopup").as<ui_scripting::function>();
|
||||
|
||||
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());
|
||||
|
@ -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();
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user