Code:
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
--
-- Frontend Scripts - PACK CHECKING
-- By: DETrooper
--
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
local dev = require("lua_scripts/dev");
local util = require("lua_scripts/util");
local all_packs_enabled = true;
local all_packs_in_order = true;
REQUIRED_PACKS = {
{key = "caligula_frontend_ui_popups.pack", enabled = true, packPos = nil, order = 1, name = "Frontend UI Pop-Ups"},
{key = "miscellaneous_1.pack", enabled = false, packPos = nil, order = 2, name = "Miscellaneous Pack 1"},
{key = "miscellaneous_2.pack", enabled = false, packPos = nil, order = 3, name = "Miscellaneous Pack 2"}
};
eh:add_listener(
"OnUICreated_Pack_Check",
"UICreated",
true,
function(context) OnUICreated_Pack_Check(context) end,
true
);
eh:add_listener(
"OnFrontendScreenTransition_Pack_Check",
"FrontendScreenTransition",
true,
function(context) OnFrontendScreenTransition_Pack_Check(context) end,
true
);
eh:add_listener(
"OnComponentLClickUp_Pack_Check",
"ComponentLClickUp",
true,
function(context) OnComponentLClickUp_Pack_Check(context) end,
true
);
function OnUICreated_Pack_Check(context)
if not svr:LoadBool("SBOOL_Pack_Check_Already_Shown") then
local modsFile;
if util.fileExists("used_mods.txt") then
modsFile = io.open("used_mods.txt", "r");
end
ShowPackWarning(modsFile);
svr:SaveBool("SBOOL_Pack_Check_Already_Shown", true);
end
end
function OnFrontendScreenTransition_Pack_Check(context)
local pack_warning_uic = UIComponent(m_root:Find("pack_warning"));
if pack_warning_uic and pack_warning_uic:Visible() == true then
pack_warning_uic:SetVisible(false);
end
end;
function OnComponentLClickUp_Pack_Check(context)
if context.string == "pack_warning_accept" or context.string == "button_home" then
local pack_warning_uic = UIComponent(m_root:Find("pack_warning"));
if pack_warning_uic and pack_warning_uic:Visible() == true then
pack_warning_uic:SetVisible(false);
end;
end
end;
function CreatePackWarning(warning_string)
m_root:CreateComponent("pack_warning", "UI/campaign ui/events");
UIComponent(m_root:Find("pack_warning")):CreateComponent("pack_warning_accept", "UI/new/basic_toggle_accept");
local pack_warning_uic = UIComponent(m_root:Find("pack_warning"));
local pack_warning_accept_uic = UIComponent(pack_warning_uic:Find("pack_warning_accept"));
local pack_warning_event_dilemma_uic = UIComponent(pack_warning_uic:Find("event_dilemma"));
local pack_warning_event_standard_uic = UIComponent(pack_warning_uic:Find("event_standard"));
local pack_warning_scroll_frame_uic = UIComponent(pack_warning_event_standard_uic:Find("scroll_frame"));
local pack_warning_tx_title_uic = UIComponent(pack_warning_uic:Find("tx_title"));
local pack_warning_dy_event_picture_uic = UIComponent(pack_warning_event_standard_uic:Find("dy_event_picture"));
local pack_warning_textview_no_sub_uic = UIComponent(pack_warning_event_standard_uic:Find("textview_no_sub"));
local pack_warning_textview_with_sub_uic = UIComponent(pack_warning_event_standard_uic:Find("textview_with_sub"));
local pack_warning_dy_subtitle_uic = UIComponent(pack_warning_event_standard_uic:Find("dy_subtitle"));
local pack_warning_text_uic = UIComponent(pack_warning_textview_with_sub_uic:Find("Text"));
local button_campaign_uic = UIComponent(m_root:Find("button_campaign"));
local curX, curY = pack_warning_uic:Position();
local button_campaign_uicX, button_campaign_uicY = button_campaign_uic:Position();
pack_warning_event_dilemma_uic:SetVisible(false);
pack_warning_event_standard_uic:SetVisible(true);
pack_warning_dy_event_picture_uic:SetVisible(false);
pack_warning_textview_no_sub_uic:SetVisible(false);
tm:callback(
function()
pack_warning_uic:SetMoveable(true);
pack_warning_uic:MoveTo(curX - 40, button_campaign_uicY - 80);
pack_warning_uic:SetMoveable(false);
pack_warning_event_standard_uic:Resize(505, 500);
pack_warning_scroll_frame_uic:Resize(505, 580);
pack_warning_textview_with_sub_uic:Resize(460, 500);
local curX2, curY2 = pack_warning_textview_with_sub_uic:Position();
local curX3, curY3 = pack_warning_dy_subtitle_uic:Position();
pack_warning_textview_with_sub_uic:SetMoveable(true);
pack_warning_textview_with_sub_uic:MoveTo(curX2, curY2 + 110);
pack_warning_textview_with_sub_uic:SetMoveable(false);
pack_warning_dy_subtitle_uic:SetMoveable(true);
pack_warning_dy_subtitle_uic:MoveTo(curX3 - 5, curY3 - 240);
pack_warning_dy_subtitle_uic:SetMoveable(false);
pack_warning_accept_uic:SetMoveable(true);
pack_warning_accept_uic:MoveTo(curX3 + 115, curY3 + 325);
pack_warning_accept_uic:SetMoveable(false);
end,
1
);
pack_warning_tx_title_uic:SetStateText("Frontend UI Pop-Ups");
pack_warning_dy_subtitle_uic:SetStateText("Warning! Potential Errors in Load Order");
pack_warning_text_uic:SetStateText(warning_string);
pack_warning_uic:SetVisible(true);
end
function ShowPackWarning(modsFile)
local packPos = 0;
local warning_string = "";
local extra_packs_enabled = false;
local pack_counter = 0;
if modsFile then
for line in modsFile:lines() do
if line:sub(1, 3) == "mod" then
local pack_name = line:sub(6, #line - 2);
for i = 1, #REQUIRED_PACKS do
if REQUIRED_PACKS[i].key == pack_name then
pack_found = true;
packPos = packPos + 1;
REQUIRED_PACKS[i].enabled = true;
REQUIRED_PACKS[i].packPos = packPos;
if all_packs_in_order == true then
if packPos ~= REQUIRED_PACKS[i].order then
all_packs_in_order = false;
end
end
break;
end
end
end
pack_counter = pack_counter + 1;
end
if pack_counter > 3 then
extra_packs_enabled = true;
else
extra_packs_enabled = false;
end
modsFile:close();
end
warning_string = warning_string.."The following mandatory .pack files are missing:\n\n";
for i = 1, #REQUIRED_PACKS do
local pack = REQUIRED_PACKS[i];
if pack.enabled ~= true then
if all_packs_enabled == true then
all_packs_enabled = false;
end
warning_string = warning_string..pack.name.."\n";
end
end
if all_packs_enabled == false then
warning_string = warning_string.."\nThis will likely cause game-breaking errors.\n\nPlease exit Total War: Attila, and enable these missing files in the mod manager.";
CreatePackWarning(warning_string);
elseif all_packs_in_order == false then
warning_string = "Your .pack files are out of order. The correct order is:\n\n"..
"- Frontend UI Pop-Ups\n"..
"- Miscellaneous Pack 1\n"..
"- Miscellaneous Pack 2\n\n"..
"Out of order .pack files may cause errors, and make multiplayer impossible. Please consider changing what mods you have enabled.";
CreatePackWarning(warning_string);
elseif extra_packs_enabled == true then
warning_string = "You have loaded other mods alongside this mod. This may cause errors and make multiplayer impossible. Please consider changing what mods you have enabled.";
CreatePackWarning(warning_string);
end
end