handle popup in lua instead
This commit is contained in:
parent
a28f79c003
commit
f2dd9315aa
@ -4,3 +4,4 @@ end
|
|||||||
|
|
||||||
require("lobby")
|
require("lobby")
|
||||||
require("serverlist")
|
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",
|
"MPHUD_LATENCY_MS": " ms",
|
||||||
"LUA_MENU_TELEMETRY": "TELEMETRY",
|
"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": "English",
|
||||||
"MENU_ENGLISH_SAFE": "English (Safe)",
|
"MENU_ENGLISH_SAFE": "English (Safe)",
|
||||||
"MENU_FRENCH": "Français",
|
"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);
|
bool download_files(const game::netadr_s& target, const utils::info_string& info, bool allow_download);
|
||||||
|
|
||||||
void user_download_response(bool response)
|
bool should_user_confirm(const game::netadr_s& target)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
nlohmann::json obj = get_whitelist_json_object();
|
nlohmann::json obj = get_whitelist_json_object();
|
||||||
if (obj != nullptr)
|
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();
|
close_joining_popups();
|
||||||
|
command::execute("lui_open_popup popup_confirmdownload", false);
|
||||||
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);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -419,7 +390,7 @@ namespace party
|
|||||||
|
|
||||||
if (files.size() > 0)
|
if (files.size() > 0)
|
||||||
{
|
{
|
||||||
if (!allow_download && should_user_confirm(target, info))
|
if (!allow_download && should_user_confirm(target))
|
||||||
{
|
{
|
||||||
return true;
|
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)
|
void menu_error(const std::string& error)
|
||||||
{
|
{
|
||||||
console::error("%s\n", error.data());
|
console::error("%s\n", error.data());
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
namespace party
|
namespace party
|
||||||
{
|
{
|
||||||
|
std::string get_www_url();
|
||||||
|
void user_download_response(bool response);
|
||||||
|
|
||||||
void menu_error(const std::string& error);
|
void menu_error(const std::string& error);
|
||||||
|
|
||||||
void reset_connect_state();
|
void reset_connect_state();
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "scripting.hpp"
|
#include "scripting.hpp"
|
||||||
#include "updater.hpp"
|
#include "updater.hpp"
|
||||||
#include "server_list.hpp"
|
#include "server_list.hpp"
|
||||||
|
#include "party.hpp"
|
||||||
|
|
||||||
#include "game/ui_scripting/execution.hpp"
|
#include "game/ui_scripting/execution.hpp"
|
||||||
#include "game/scripting/execution.hpp"
|
#include "game/scripting/execution.hpp"
|
||||||
@ -363,6 +364,9 @@ namespace ui_scripting
|
|||||||
lua["download"] = download_table;
|
lua["download"] = download_table;
|
||||||
|
|
||||||
download_table["abort"] = download::stop_download;
|
download_table["abort"] = download::stop_download;
|
||||||
|
|
||||||
|
download_table["userdownloadresponse"] = party::user_download_response;
|
||||||
|
download_table["getwwwurl"] = party::get_www_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start()
|
void start()
|
||||||
|
Loading…
Reference in New Issue
Block a user