This commit is contained in:
Federico Cecchetto 2022-05-30 23:03:36 +02:00
parent da90d37846
commit 502b7ac3dd
5 changed files with 170 additions and 152 deletions

View File

@ -67,7 +67,7 @@ function addrequest(request)
left = 1, left = 1,
bottom = -1, bottom = -1,
right = -1, right = -1,
material = luiglobals.RegisterMaterial("white"), material = RegisterMaterial("white"),
color = { color = {
r = 0, r = 0,
b = 0, b = 0,
@ -81,7 +81,7 @@ function addrequest(request)
leftAnchor = true, leftAnchor = true,
rightAnchor = true, rightAnchor = true,
bottomAnchor = true, bottomAnchor = true,
material = luiglobals.RegisterMaterial("btn_focused_rect_innerglow"), material = RegisterMaterial("btn_focused_rect_innerglow"),
}) })
border:setup9SliceImage(10, 5, 0.25, 0.12) border:setup9SliceImage(10, 5, 0.25, 0.12)
@ -105,7 +105,7 @@ function addrequest(request)
width = 32, width = 32,
height = 32, height = 32,
left = 1, left = 1,
material = luiglobals.RegisterMaterial(avatarmaterial) material = RegisterMaterial(avatarmaterial)
}) })
local username = LUI.UIText.new({ local username = LUI.UIText.new({
@ -113,7 +113,7 @@ function addrequest(request)
topAnchor = true, topAnchor = true,
height = 12, height = 12,
left = 32 + paddingvalue, left = 32 + paddingvalue,
color = luiglobals.Colors.white, color = Colors.white,
alignment = LUI.Alignment.Left, alignment = LUI.Alignment.Left,
rightAnchor = true, rightAnchor = true,
font = CoD.TextSettings.BodyFontBold.Font font = CoD.TextSettings.BodyFontBold.Font
@ -137,7 +137,7 @@ function addrequest(request)
topAnchor = true, topAnchor = true,
height = 18, height = 18,
width = 85, width = 85,
material = luiglobals.RegisterMaterial("btn_focused_rect_innerglow"), material = RegisterMaterial("btn_focused_rect_innerglow"),
}) })
local center = LUI.UIText.new({ local center = LUI.UIText.new({
@ -214,7 +214,7 @@ function addrequest(request)
bottom = -3, bottom = -3,
left = 3, left = 3,
width = 200 - 6, width = 200 - 6,
material = luiglobals.RegisterMaterial("white"), material = RegisterMaterial("white"),
height = 2, height = 2,
color = { color = {
r = 92 / 255, r = 92 / 255,
@ -236,7 +236,7 @@ function addrequest(request)
avatar:registerEventHandler("update", function() avatar:registerEventHandler("update", function()
local avatarmaterial = discord.getavatarmaterial(request.userid) local avatarmaterial = discord.getavatarmaterial(request.userid)
avatar:setImage(luiglobals.RegisterMaterial(avatarmaterial)) avatar:setImage(RegisterMaterial(avatarmaterial))
end) end)
avatar:addElement(LUI.UITimer.new(100, "update")) avatar:addElement(LUI.UITimer.new(100, "update"))

View File

@ -16,6 +16,7 @@
#include "mods.hpp" #include "mods.hpp"
#include "fastfiles.hpp" #include "fastfiles.hpp"
#include "scripting.hpp" #include "scripting.hpp"
#include "updater.hpp"
#include "game/ui_scripting/execution.hpp" #include "game/ui_scripting/execution.hpp"
#include "game/scripting/execution.hpp" #include "game/scripting/execution.hpp"
@ -40,6 +41,7 @@ namespace ui_scripting
utils::hook::detour hks_load_hook; utils::hook::detour hks_load_hook;
const auto lui_common = utils::nt::load_resource(LUI_COMMON); const auto lui_common = utils::nt::load_resource(LUI_COMMON);
const auto lui_updater = utils::nt::load_resource(LUI_UPDATER);
const auto lua_json = utils::nt::load_resource(LUA_JSON); const auto lua_json = utils::nt::load_resource(LUA_JSON);
struct script struct script
@ -331,6 +333,29 @@ namespace ui_scripting
}, ::scheduler::pipeline::server); }, ::scheduler::pipeline::server);
}; };
} }
auto updater_table = table();
lua["updater"] = updater_table;
updater_table["relaunch"] = updater::relaunch;
updater_table["sethastriedupdate"] = updater::set_has_tried_update;
updater_table["gethastriedupdate"] = updater::get_has_tried_update;
updater_table["autoupdatesenabled"] = updater::auto_updates_enabled;
updater_table["startupdatecheck"] = updater::start_update_check;
updater_table["isupdatecheckdone"] = updater::is_update_check_done;
updater_table["getupdatecheckstatus"] = updater::get_update_check_status;
updater_table["isupdateavailable"] = updater::is_update_available;
updater_table["startupdatedownload"] = updater::start_update_download;
updater_table["isupdatedownloaddone"] = updater::is_update_download_done;
updater_table["getupdatedownloadstatus"] = updater::get_update_download_status;
updater_table["cancelupdate"] = updater::cancel_update;
updater_table["isrestartrequired"] = updater::is_restart_required;
updater_table["getlasterror"] = updater::get_last_error;
updater_table["getcurrentfile"] = updater::get_current_file;
} }
void start() void start()
@ -347,6 +372,7 @@ namespace ui_scripting
lua["luiglobals"] = lua; lua["luiglobals"] = lua;
load_script("lui_common", lui_common); load_script("lui_common", lui_common);
load_script("lui_updater", lui_updater);
load_script("lua_json", lua_json); load_script("lua_json", lua_json);
for (const auto& path : filesystem::get_search_paths()) for (const auto& path : filesystem::get_search_paths())

View File

@ -4,6 +4,7 @@
#include "scheduler.hpp" #include "scheduler.hpp"
#include "dvars.hpp" #include "dvars.hpp"
#include "updater.hpp" #include "updater.hpp"
#include "game/ui_scripting/execution.hpp"
#include "version.h" #include "version.h"
@ -63,14 +64,9 @@ namespace updater
utils::concurrency::container<update_data_t> update_data; utils::concurrency::container<update_data_t> update_data;
std::string get_branch()
{
return GIT_BRANCH;
}
std::string select(const std::string& main, const std::string& develop) std::string select(const std::string& main, const std::string& develop)
{ {
if (get_branch() == "develop") if (GIT_BRANCH == "develop"s)
{ {
return develop; return develop;
} }
@ -78,14 +74,12 @@ namespace updater
return main; return main;
} }
std::string get_data_path() void notify(const std::string& name)
{ {
if (get_branch() == "develop") scheduler::once([=]()
{ {
return DATA_PATH_DEV; ui_scripting::notify(name, {});
} }, scheduler::pipeline::lui);
return DATA_PATH;
} }
void set_update_check_status(bool done, bool success, const std::string& error = {}) void set_update_check_status(bool done, bool success, const std::string& error = {})
@ -95,6 +89,8 @@ namespace updater
data_.check.done = done; data_.check.done = done;
data_.check.success = success; data_.check.success = success;
data_.error = error; data_.error = error;
notify("update_check_done");
}); });
} }
@ -105,6 +101,7 @@ namespace updater
data_.download.done = done; data_.download.done = done;
data_.download.success = success; data_.download.success = success;
data_.error = error; data_.error = error;
notify("update_done");
}); });
} }
@ -126,11 +123,8 @@ namespace updater
std::string load_binary_name() std::string load_binary_name()
{ {
// utils::nt::library self; utils::nt::library self;
// return self.get_name(); return self.get_name();
// returns the game's name and not the client's
return BINARY_NAME;
} }
std::string get_binary_name() std::string get_binary_name()
@ -392,6 +386,8 @@ namespace updater
data_.check.success = true; data_.check.success = true;
data_.required_files = required_files; data_.required_files = required_files;
}); });
notify("update_check_done");
}, scheduler::pipeline::async); }, scheduler::pipeline::async);
} }
@ -468,4 +464,4 @@ namespace updater
}; };
} }
//REGISTER_COMPONENT(updater::component) REGISTER_COMPONENT(updater::component)

View File

@ -38,7 +38,9 @@ LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event)
end end
}) })
popup.text = popup:getLastChild():getPreviousSibling():getPreviousSibling() local listchildren = getchildren(popup:getChildById("LUIHorizontalList"))
local children = getchildren(listchildren[2])
popup.text = children[2]
stack = { stack = {
ret = popup ret = popup

View File

@ -1,12 +1,16 @@
updatecancelled = false if (not Engine.InFrontend()) then
taskinterval = 100 return
end
updatecancelled = false
updater.cancelupdate() updater.cancelupdate()
function startupdatecheck(popup, autoclose) function startupdatecheck(popup, autoclose)
updatecancelled = false Engine.GetLuiRoot():registerEventHandler("update_check_done", function(element, event)
if (updatecancelled) then
return
end
local callback = function()
if (not updater.getupdatecheckstatus()) then if (not updater.getupdatecheckstatus()) then
if (autoclose) then if (autoclose) then
LUI.FlowManager.RequestLeaveMenu(popup) LUI.FlowManager.RequestLeaveMenu(popup)
@ -38,23 +42,18 @@ function startupdatecheck(popup, autoclose)
end end
end end
}) })
end end)
updater.startupdatecheck() updater.startupdatecheck()
createtask({
done = updater.isupdatecheckdone,
cancelled = isupdatecancelled,
callback = callback,
interval = taskinterval
})
end end
function startupdatedownload(popup, autoclose) function startupdatedownload(popup, autoclose)
updater.startupdatedownload()
local textupdate = nil local textupdate = nil
local previousfile = nil local previousfile = nil
textupdate = game:oninterval(function() local timer = LUI.UITimer.new(10, "update_file")
popup:addElement(timer)
popup:registerEventHandler("update_file", function()
local file = updater.getcurrentfile() local file = updater.getcurrentfile()
if (file == previousfile) then if (file == previousfile) then
return return
@ -62,10 +61,14 @@ function startupdatedownload(popup, autoclose)
file = previousfile file = previousfile
popup.text:setText("Downloading file " .. updater.getcurrentfile() .. "...") popup.text:setText("Downloading file " .. updater.getcurrentfile() .. "...")
end, 10) end)
local callback = function() Engine.GetLuiRoot():registerEventHandler("update_done", function(element, event)
textupdate:clear() timer:close()
if (updatecancelled) then
return
end
if (not updater.getupdatedownloadstatus()) then if (not updater.getupdatedownloadstatus()) then
if (autoclose) then if (autoclose) then
@ -88,25 +91,16 @@ function startupdatedownload(popup, autoclose)
updater.relaunch() updater.relaunch()
end end
}) })
else
if (LUI.mp_menus) then
Engine.Exec("lui_restart; lui_open mp_main_menu")
else else
Engine.Exec("lui_restart") Engine.Exec("lui_restart")
end end
end
if (autoclose) then if (autoclose) then
LUI.FlowManager.RequestLeaveMenu(popup) LUI.FlowManager.RequestLeaveMenu(popup)
end end
end end)
createtask({ updater.startupdatedownload()
done = updater.isupdatedownloaddone,
cancelled = isupdatecancelled,
callback = callback,
interval = taskinterval
})
end end
function updaterpopup(oncancel) function updaterpopup(oncancel)
@ -133,10 +127,6 @@ function createtask(data)
return interval return interval
end end
function isupdatecancelled()
return updatecancelled
end
function tryupdate(autoclose) function tryupdate(autoclose)
updatecancelled = false updatecancelled = false
local popup = updaterpopup(function() local popup = updaterpopup(function()
@ -153,12 +143,16 @@ function tryautoupdate()
end end
if (not updater.gethastriedupdate()) then if (not updater.gethastriedupdate()) then
game:ontimeout(function() local timer = LUI.UITimer.new(100, "tryupdate")
Engine.GetLuiRoot():addElement(timer)
Engine.GetLuiRoot():registerEventHandler("tryupdate", function()
timer:close()
updater.sethastriedupdate(true) updater.sethastriedupdate(true)
tryupdate(true) tryupdate(true)
end, 100) end)
end end
end end
LUI.onmenuopen("mp_main_menu", tryautoupdate) LUI.tryupdating = tryupdate
LUI.onmenuopen("main_lockout", tryautoupdate) LUI.onmenuopen("main_lockout", tryautoupdate)
LUI.onmenuopen("mp_main_menu", tryautoupdate)