Results 1 to 2 of 2

Thread: Frontend UI Pop-Ups

  1. #1
    Commissar Caligula_'s Avatar The Ecstasy of Potatoes
    Join Date
    Dec 2013
    Location
    The alcoves in the Koningin Astridpark
    Posts
    5,876

    Default Frontend UI Pop-Ups


    This is a modding resource and tutorial for fellow modders so that they can create messages that pop up when you launch the game welcoming people to your mod, and warning them that they need to ensure their load order is correct.

    Credit
    All credit goes to the Rome 2 Total Realism team for their scripting tools, and to DETrooper for creating the scripts that enable these frontend messages.
    I simply isolated DETrooper's scripts from the Medieval Kingdoms Total War packs.

    ---------------------------------------------------------------------------------------------------

    This pack contains four different pop-up messages.

    1: The frontend_changelog.lua script creates a message that pops up the first time the player launches a pack after an update for example. This message can say anything you want, such as 'Welcome to update v...', 'we still don't have a campaign', and a short changelog.
    It will then create a log in the player's root Attila folder (NOT data folder) noting that they have read this message, and it won't appear on launch again.

    The frontend_pack_check.lua script checks what mods the player is using every time they launch.
    2: If they don't have all required packs loaded, a message will tell the player which ones they're missing.
    3: If they DO have all required packs enabled, but in the wrong order a message will pop up telling the player the correct order.
    4: If they DO have all required packs enabled, but they also other mods/submods enabled, a message will pop up warning the player that any errors may be due to incompatibility, not because of the main mod.

    Screenshots







    Step-by-Step Tutorial
    Download the Mod
    You will need to download
    • Frontend UI Pop-Ups
    • Miscellaneous 1
    • Miscellaneous 2

    FROM THIS LINK

    db - videos_tables
    The only thing that this table does is disables the intro video on launch. I always include videos_tables in my mods when I am developing them, because I'll be launching the game a LOT of times and it saves quite a lot of time if the video is just disabled.

    lua_scripts - dev.lua
    Don't edit anything in this file.

    lua_scripts - frontend_changelog.lua
    I have pasted the code from this .lua file below. The parts that you will need to change are in blue font.
    Make sure you put " at the start and end of every sentence.
    \n".. is used to create a single line break.
    \n\n".. is used to create a double line break.
    Spoiler Alert, click show to read: 
    Code:
    ---------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------
    --
    -- 	Frontend Scripts - CHANGELOG/UPDATE INFORMATION
    -- 	By: DETrooper
    --
    ---------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------
    
    local dev = require("lua_scripts/dev");
    local util = require ("lua_scripts/util");
    
    local changelogpriority = false; -- If true, always display.
    local changelogstring = 	"Welcome to this tutorial on how to create frontend pop-ups!\n\n"..
    
    			"This pack contains four different pop-up messages.\n\n"..
    							
    			"The frontend_changelog.lua script creates a message that pops up the first time the player launches a pack after an update for example. This message can say anything you want, such as 'Welcome to update v...', 'we still don't have a campaign', and a short changelog.\n"..
    			"It will then create a log in the player's root Attila folder (NOT data folder) noting that they have read this message, and it won't appear on launch again.\n\n"..
    							
    			"The frontend_pack_check.lua script checks what mods the player is using every time they launch.\n"..
    			"- If they don't have all required packs loaded, a message will tell the player which ones they're missing.\n"..
    			"- If they DO have all required packs enabled, but in the wrong order a message will pop up telling the player the correct order.\n"..
    			"- If they DO have all required packs enabled, but they also other mods/submods enabled, a message will pop up warning the player that any errors may be due to incompatibility, not because of the main mod.\n\n";
    
    changelogcreated = false;
    
    eh:add_listener(
    	"OnUICreated_Changelog",
    	"UICreated",
    	true,
    	function(context) OnUICreated_Changelog(context) end,
    	true
    );
    eh:add_listener(
    	"OnFrontendScreenTransition_Changelog",
    	"FrontendScreenTransition",
    	true,
    	function(context) OnFrontendScreenTransition_Changelog(context) end,
    	true
    );
    eh:add_listener(
    	"OnComponentLClickUp_Changelog",
    	"ComponentLClickUp",
    	true,
    	function(context) OnComponentLClickUp_Changelog(context) end,
    	true
    );
    
    function OnUICreated_Changelog(context)
    	if changelogpriority == true then 
    		CreateChangelog();
    	elseif util.fileExists("frontend_UI_changelog.txt") == true then
    		if not dev.settings["changelogNumber"] then
    			dev.writeSettings("frontend_UI_changelog.txt");
    			CreateChangelog();
    			dev.changeSetting("frontend_UI_changelog.txt", "changelogNumber", version_number);
    		else
    			if tonumber(dev.settings["changelogNumber"]) < version_number then
    				CreateChangelog();
    				dev.changeSetting("frontend_UI_changelog.txt", "changelogNumber", version_number);
    			end
    		end
    	else
    		dev.writeSettings("frontend_UI_changelog.txt");
    		CreateChangelog();
    	end
    end;
    
    function OnFrontendScreenTransition_Changelog(context)
    	if UIComponent(m_root:Find("changelog")):Visible() == true then
    		UIComponent(m_root:Find("changelog")):SetVisible(false);
    	end
    
    	if context.string == "main" then
    		UIComponent(m_root:Find("button_message")):SetState("active");
    	else
    		UIComponent(m_root:Find("button_message")):SetState("inactive");
     	end
    end;
    
    function OnComponentLClickUp_Changelog(context)
    	if context.string == "changelog_accept" or context.string == "button_home" then
    		UIComponent(m_root:Find("changelog")):SetVisible(false);
    	elseif context.string == "button_message" then
    		if UIComponent(m_root:Find("changelog")):Visible() == true then
    			UIComponent(m_root:Find("changelog")):SetVisible(false);
    		else
    			CreateChangelog();
    		end
    	end
    end;
    
    function CreateChangelog()
    	UIComponent(m_root:Find("logo")):DestroyChildren();
    	UIComponent(m_root:Find("logo")):CreateComponent("changelog", "UI/campaign ui/events");
    	UIComponent(m_root:Find("changelog")):CreateComponent("changelog_accept", "UI/new/basic_toggle_accept");
    
    	local logo_uic = UIComponent(m_root:Find("logo"));
    	local changelog_uic = UIComponent(logo_uic:Find("changelog"));
    	local changelog_accept_uic = UIComponent(changelog_uic:Find("changelog_accept"));
    	local changelog_event_dilemma_uic = UIComponent(changelog_uic:Find("event_dilemma"));
    	local changelog_event_standard_uic = UIComponent(changelog_uic:Find("event_standard"));
    	local changelog_scroll_frame_uic = UIComponent(changelog_event_standard_uic:Find("scroll_frame"));
    	local changelog_tx_title_uic = UIComponent(changelog_uic:Find("tx_title"));
    	local changelog_dy_event_picture_uic = UIComponent(changelog_event_standard_uic:Find("dy_event_picture"));
    	local changelog_textview_no_sub_uic = UIComponent(changelog_event_standard_uic:Find("textview_no_sub"));
    	local changelog_textview_with_sub_uic = UIComponent(changelog_event_standard_uic:Find("textview_with_sub"));
    	local changelog_dy_subtitle_uic = UIComponent(changelog_event_standard_uic:Find("dy_subtitle"));
    	local changelog_text_uic = UIComponent(changelog_textview_with_sub_uic:Find("Text"));
    	local button_campaign_uic = UIComponent(m_root:Find("button_campaign"));
    	local curX, curY = changelog_uic:Position();
    	local button_campaign_uicX, button_campaign_uicY = button_campaign_uic:Position();
    	changelog_event_dilemma_uic:SetVisible(false);
    	changelog_event_standard_uic:SetVisible(true);
    	changelog_dy_event_picture_uic:SetVisible(false);
    	changelog_textview_no_sub_uic:SetVisible(false);
    
    	tm:callback(
    		function() 
    			changelog_uic:SetMoveable(true);
    			changelog_uic:MoveTo(curX - 40, button_campaign_uicY - 80);
    			changelog_uic:SetMoveable(false);
    			changelog_event_standard_uic:Resize(505, 500);
    			changelog_scroll_frame_uic:Resize(505, 580);
    			changelog_textview_with_sub_uic:Resize(460, 500);
    
    			local curX2, curY2 = changelog_textview_with_sub_uic:Position();
    			local curX3, curY3 = changelog_dy_subtitle_uic:Position();
    			changelog_textview_with_sub_uic:SetMoveable(true);
    			changelog_textview_with_sub_uic:MoveTo(curX2, curY2 + 110);
    			changelog_textview_with_sub_uic:SetMoveable(false);
    			changelog_dy_subtitle_uic:SetMoveable(true);
    			changelog_dy_subtitle_uic:MoveTo(curX3 - 5, curY3 - 240);
    			changelog_dy_subtitle_uic:SetMoveable(false);
    
    			changelog_accept_uic:SetMoveable(true);
    			changelog_accept_uic:MoveTo(curX3 + 115, curY3 + 325);
    			changelog_accept_uic:SetMoveable(false);
    		end, 
    		1
    	);
    
    	changelog_tx_title_uic:SetStateText("Frontend UI Pop-Ups");
    	changelog_dy_subtitle_uic:SetStateText("v1.1.1");
    	changelog_text_uic:SetStateText(changelogstring);
    	changelog_uic:SetVisible(true);
    end

    lua_scripts - frontend_pack_check.lua
    I have pasted the code from this .lua file below. The parts that you will need to change are in blue font.
    You will need to put the entire name of your pack in the key section, eg "caligula_frontend_ui_popups.pack".
    You will then need to number each pack, eg order = 1.

    Note - "if pack_counter > 3 then" is related to the 4th error message. The number relates to how many "core" mods the player MUST have enabled.

    Finally you will need to say what the title of each pack is, eg "Frontend UI Pop-Ups". This will appear if you fail to load core mods. See this picture.
    Deliberately fail to load Miscellaneous 1 or Miscellaneous 2 to see this in action.

    You will then want to edit the error message that shows up if your pack files are loaded out of order, and the correct order that the mods should be in. See this picture.
    Deliberately put Miscellaneous 2 and 1 in the wrong order.

    If you load other mods alongside the core mods, a further message will appear warning of potential incompatibilities. See this picture.
    Deliberately load another mod alongside the core 3 mods.
    Spoiler Alert, click show to read: 
    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

    lua_scripts - frontend_scripted.lua
    The only thing you need to edit here is the version_number that appears in the top right hand corner of your screen.
    If you release a new update, and you want a DIFFERENT "changelog/disclaimer" message to appear, simply change the version_number and your new message will show.
    Spoiler Alert, click show to read: 
    Code:
    ---------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------
    --
    -- 	FRONTEND SCRIPTS
    -- 	By: DETrooper
    --
    ---------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------
    
    system.ClearRequiredFiles();
    
    package.path = ";?.lua;data/ui/templates/?.lua;data/ui/?.lua"
    
    require "data.lua_scripts.all_scripted"
    
    events = get_events();
    
    local m_user_defined_event_callbacks = {}
    
    function AddEventCallBack(event, func, add_to_user_defined_list)
    	assert(events[event] , "Attempting to add event callback to non existant event ("..event..")")
    	assert(func , "Attempting to add a non existant function to event "..event)
    	
    	events[event][#events[event]+1] = func
    	
    	if add_to_user_defined_list ~= false then
    		m_user_defined_event_callbacks[#m_user_defined_event_callbacks+1] = {}
    		m_user_defined_event_callbacks[#m_user_defined_event_callbacks].event = event
    		m_user_defined_event_callbacks[#m_user_defined_event_callbacks].func = func
    	end
    end
    
    require("lua_scripts.fe_script_header");
    
    eh = event_handler:new(AddEventCallBack);
    m_root = nil;
    svr = ScriptedValueRegistry:new();
    tm = timer_manager:new(Timers);
    version_number = 111;
    version_number_string = "v1.1.1";
    
    eh:add_listener(
    	"OnUICreated_Frontend",
    	"UICreated",
    	true,
    	function(context) OnUICreated_Frontend(context) end,
    	true
    );
    eh:add_listener(
    	"OnFrontendScreenTransition_Frontend",
    	"FrontendScreenTransition",
    	true,
    	function(context) ChangeFrontend(context) end,
    	true
    );
    
    require("lua_scripts/frontend_changelog");
    require("lua_scripts/frontend_pack_check");
    require("lua_scripts/frontend_strings");
    
    function OnUICreated_Frontend(context)
    	if context then
    		m_root = UIComponent(context.component);
    
    		ChangeFrontend(context);
    	end
    end
    
    function ChangeFrontend(context)
    	local text_version_number_uic = UIComponent(m_root:Find("version_number"));
    
    	if text_version_number_uic then
    		text_version_number_uic:SetStateText(FRONTEND_STRINGS["text_version_string"]..version_number_string);
    	end
    
    end

    lua_scripts - frontend_strings.lua
    The text_version_string is the actual version title that appears in the top right hand corner of your screen. I believe you need to put a spacebar after the title and before the end quotation.
    Spoiler Alert, click show to read: 
    Code:
    ---------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------
    --
    -- 	FRONTEND STRINGS
    -- 	By: DETrooper
    --
    ---------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------
    
    FRONTEND_STRINGS = {
    	text_version_string = "Frontend UI Pop Ups ",
    };

    lua_scripts - logging_callbacks.lua
    Don't edit anything in this file.

    lua_scripts - util.lua
    Don't edit anything in this file.

    ui - new - basic_toggle_accept
    Don't edit anything in this file.


    Quick Tips
    To make players see a new version of the disclaimer, simply update version_number and version_number_string in frontend_scripted.lua

    The 4th error message, warning of other mods being loaded alongside the core mods, can break at times. I am working to identify the cause of this.
    Last edited by Commissar Caligula_; December 19, 2022 at 03:24 AM.



  2. #2
    Commissar Caligula_'s Avatar The Ecstasy of Potatoes
    Join Date
    Dec 2013
    Location
    The alcoves in the Koningin Astridpark
    Posts
    5,876

    Default Re: Frontend UI Pop-Ups

    I've updated the mod to include a 4th message, which pops up if the player has all required packs enabled, but they also other mods/submods enabled. This message will warn the player that any errors may be due to incompatibility, not because of the main mod.



Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •