Faster way to /reloadui

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

azaghal
Posts: 438
Joined: Wed, 21. Mar 07, 13:19
xr

Faster way to /reloadui

Post by azaghal »

Since I have started to dabble with the Lua portion of the game's scripting engine, I find myself using the /reloadui command again and again and again... To a point where I have set-up a QMK macro that brings up the console and types in the command in there. This works fine so long as I do not royally mess something up, at which point getting that edit box focused becomes a bit of a problem. Another catch is that it feels a bit slow (ideally I would like to just hit a single shortcut).

So... What are other modders doing in this regard? Am I missing some obvious built-in way to quickly reload the UI?

For what it helps... After getting a bit fed up today with it all after fiddling with the personnel info screen to add another column and testing out if it still looks fine after changing the UI scaling, I noticed the game actually reloads the UI and even shows a small banner about it when you confirm the change. And with that in mind, I managed to get this little hack going.

ui.xml (just the usual - btw, I can highly recommend using something like serpent for dumping Lua tables in readable format - unless I missed something obvious yet again :P)

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<addon name="azaghal_modding_tests" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../ui/core/addon.xsd">
  <environment type="menus">
    <file name="ui/serpent.lua"/>
    <file name="ui/testing.lua"/>
    <file name="ui/reload.lua"/>
    <dependency name="ego_detailmonitor" />
    <dependency name="ego_detailmonitorhelper" />
  </environment>
</addon>
And this is the reload hack:

Code: Select all

local m = {}


function m.init()
    m.menu = Helper.getMenu("HelpMenu")

    m.originalFunctions = {}
    m.originalFunctions.closeMenu = m.menu.closeMenu

    m.menu.closeMenu = m.closeMenu
end


function m.closeMenu(...)
    m.originalFunctions.closeMenu(...)
    Helper.addDelayedOneTimeCallbackOnUpdate(function () ScheduleReloadUI() end, true, getElapsedTime() + 0.1)
    Helper.getMenu("OptionsMenu").displayInit(ReadText(1001, 409))
end


m.init()
I tried to get some kind of dedicated hotkey going with "pure vanilla" (did not want to pull in more deps, like ChemODun's excellent hotkeys mod), but gave up after a couple of quick tries, and just opted to hijack the help menu's close event. So now I can just quickly hit the help menu key binding twice (I have it on Ctrl + Shift + H, and voila - UI files reloaded with even a useful feedback for the modder.

P.S.
I am going to be _super_ annoyed if this was a well-known thing, or somebody already posted a hack like this, but oh well :P
azaghal
Posts: 438
Joined: Wed, 21. Mar 07, 13:19
xr

Re: Faster way to /reloadui

Post by azaghal »

And I have a small update on the Lua script, now with the ability to reload / refresh the MD/AI stuff too (just gotta tweak that local target = "md" thing as necessary) since full thing would be a bit slow for my tastes:

Code: Select all

local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
]]


local m = {}


function m.init()
    m.menu = Helper.getMenu("HelpMenu")

    m.originalFunctions = {}
    m.originalFunctions.closeMenu = m.menu.closeMenu

    m.menu.closeMenu = m.closeMenu
end


function m.closeMenu(...)
    m.originalFunctions.closeMenu(...)

    local function reload(target)
        if target == "ui" or target == "all" then
            ScheduleReloadUI()
        end

        if target == "md" or target == "all" then
            ExecuteDebugCommand("refreshmd", 0)
        end

        if target == "ai" or target == "all" then
            ExecuteDebugCommand("refreshai", 0)
        end

    end

    local target = "md"

    Helper.addDelayedOneTimeCallbackOnUpdate(function() reload(target) end, true, getElapsedTime() + 0.1)
    C.ShowInfoLine(string.format("Reloading %s...", string.upper(target)), 1)
end


m.init()
P.S.
You can pretty reliably segfault the thing if you pass in nil into ExecuteDebugCommand instead of 0 as second argument.
User avatar
ChemODun
Posts: 634
Joined: Mon, 12. Feb 07, 21:58
x4

Re: Faster way to /reloadui

Post by ChemODun »

Good things.
But for the most modders who uses the UIX - there is a "/rui", "/rai", "/rmd" commands available.

And I strongly (excuse me for such word) recommend working with UI changes via UIX.
Multiply entropy by absolute zero

Freedom in space

Return to “X4: Foundations - Scripts and Modding”