yes/no popup before download
This commit is contained in:
parent
163de98ad5
commit
de26138f5b
@ -11,6 +11,7 @@
|
|||||||
#include "fastfiles.hpp"
|
#include "fastfiles.hpp"
|
||||||
|
|
||||||
#include "game/game.hpp"
|
#include "game/game.hpp"
|
||||||
|
#include "game/ui_scripting/execution.hpp"
|
||||||
|
|
||||||
#include "steam/steam.hpp"
|
#include "steam/steam.hpp"
|
||||||
|
|
||||||
@ -48,6 +49,9 @@ namespace party
|
|||||||
{".arena", "usermaparenahash", true},
|
{".arena", "usermaparenahash", true},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
game::netadr_s saved_target;
|
||||||
|
utils::info_string saved_info_string;
|
||||||
|
|
||||||
void perform_game_initialization()
|
void perform_game_initialization()
|
||||||
{
|
{
|
||||||
command::execute("onlinegame 1", true);
|
command::execute("onlinegame 1", true);
|
||||||
@ -288,9 +292,51 @@ namespace party
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void close_joining_popups()
|
||||||
|
{
|
||||||
|
if (game::Menu_IsMenuOpenAndVisible(0, "popup_acceptinginvite"))
|
||||||
|
{
|
||||||
|
command::execute("lui_close popup_acceptinginvite", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game::Menu_IsMenuOpenAndVisible(0, "generic_waiting_popup_"))
|
||||||
|
{
|
||||||
|
command::execute("lui_close generic_waiting_popup_", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool download_files(const game::netadr_s& target, const utils::info_string& info, bool should_download);
|
||||||
|
|
||||||
|
int confirm_user_download_cb(game::hks::lua_State* state)
|
||||||
|
{
|
||||||
|
const auto response = state->m_apistack.base[0].v.boolean;
|
||||||
|
if (!response)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
download_files(saved_target, saved_info_string, true);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void confirm_user_download(const game::netadr_s& target, const utils::info_string& info)
|
||||||
|
{
|
||||||
|
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>();
|
||||||
|
|
||||||
|
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", confirm_user_download_cb);
|
||||||
|
|
||||||
|
close_joining_popups();
|
||||||
|
|
||||||
|
yes_no_popup_func(data_table);
|
||||||
|
}
|
||||||
|
|
||||||
bool needs_vid_restart = false;
|
bool needs_vid_restart = false;
|
||||||
|
|
||||||
bool download_files(const game::netadr_s& target, const utils::info_string& info)
|
bool download_files(const game::netadr_s& target, const utils::info_string& info, bool should_download)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -302,8 +348,16 @@ namespace party
|
|||||||
|
|
||||||
if (files.size() > 0)
|
if (files.size() > 0)
|
||||||
{
|
{
|
||||||
download::stop_download();
|
if (should_download)
|
||||||
download::start_download(target, info, files);
|
{
|
||||||
|
download::stop_download();
|
||||||
|
download::start_download(target, info, files);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
confirm_user_download(target, info);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (needs_restart || needs_vid_restart)
|
else if (needs_restart || needs_vid_restart)
|
||||||
@ -428,15 +482,8 @@ namespace party
|
|||||||
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());
|
||||||
if (game::Menu_IsMenuOpenAndVisible(0, "popup_acceptinginvite"))
|
|
||||||
{
|
|
||||||
command::execute("lui_close popup_acceptinginvite", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game::Menu_IsMenuOpenAndVisible(0, "generic_waiting_popup_"))
|
close_joining_popups();
|
||||||
{
|
|
||||||
command::execute("lui_close generic_waiting_popup_", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
utils::hook::invoke<void>(0x17D770_b, error.data(), "MENU_NOTICE"); // Com_SetLocalizedErrorMessage
|
utils::hook::invoke<void>(0x17D770_b, error.data(), "MENU_NOTICE"); // Com_SetLocalizedErrorMessage
|
||||||
*reinterpret_cast<int*>(0x2ED2F78_b) = 1;
|
*reinterpret_cast<int*>(0x2ED2F78_b) = 1;
|
||||||
@ -918,6 +965,9 @@ namespace party
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saved_target = target;
|
||||||
|
saved_info_string = info;
|
||||||
|
|
||||||
if (info.get("challenge") != connect_state.challenge)
|
if (info.get("challenge") != connect_state.challenge)
|
||||||
{
|
{
|
||||||
menu_error("Connection failed: Invalid challenge.");
|
menu_error("Connection failed: Invalid challenge.");
|
||||||
@ -959,7 +1009,7 @@ namespace party
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (download_files(target, info))
|
if (download_files(target, info, false))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -69,12 +69,6 @@ namespace ui_scripting
|
|||||||
return itr == globals.loaded_scripts.end() ? std::string() : itr->second;
|
return itr == globals.loaded_scripts.end() ? std::string() : itr->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
table get_globals()
|
|
||||||
{
|
|
||||||
const auto state = *game::hks::lua_state;
|
|
||||||
return state->globals.v.table;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_error(const std::string& error)
|
void print_error(const std::string& error)
|
||||||
{
|
{
|
||||||
console::error("************** LUI script execution error **************\n");
|
console::error("************** LUI script execution error **************\n");
|
||||||
@ -523,6 +517,12 @@ namespace ui_scripting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table get_globals()
|
||||||
|
{
|
||||||
|
const auto state = *game::hks::lua_state;
|
||||||
|
return state->globals.v.table;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
game::hks::cclosure* convert_function(F f)
|
game::hks::cclosure* convert_function(F f)
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,8 @@ namespace ui_scripting
|
|||||||
return wrap_function(std::function(f));
|
return wrap_function(std::function(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table get_globals();
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
game::hks::cclosure* convert_function(F f);
|
game::hks::cclosure* convert_function(F f);
|
||||||
|
|
||||||
|
@ -111,8 +111,7 @@ namespace ui_scripting
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto globals = table((*::game::hks::lua_state)->globals.v.table);
|
const auto engine = get_globals().get("Engine").as<table>();
|
||||||
const auto engine = globals.get("Engine").as<table>();
|
|
||||||
const auto root = engine.get("GetLuiRoot")()[0].as<userdata>();
|
const auto root = engine.get("GetLuiRoot")()[0].as<userdata>();
|
||||||
const auto process_event = root.get("processEvent");
|
const auto process_event = root.get("processEvent");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user