UI modding - support thread

The place to discuss scripting and game modifications for X Rebirth.

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

User avatar
YorrickVander
Posts: 2682
Joined: Tue, 29. Oct 13, 22:59
x4

Post by YorrickVander » Sun, 22. Feb 15, 22:28

-withdraawn- failed to read a post properly
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

stefanEgo
EGOSOFT
EGOSOFT
Posts: 522
Joined: Thu, 11. Apr 13, 14:12
x4

Post by stefanEgo » Mon, 23. Feb 15, 10:25

@BigBANGtheory: unfortunately we do have quite limited resources here. So going over a list of UI mods/projects and investigate what is doable and won't be possible. I suggest you just ask directly how to solve a certain use-case, if in doubt, and we'll see how this can be done. Especially, if there are cases where you managed to do something with version 3.20 and don't know how to do it with 3.50, please let us know directly.
Also don't be afraid of creating issues in the bugtracker which might be inappropriate/invalid. If there will be cases like these, we'll just close them (stating the reason/solution for the issue).

@blackmilan/wysiwyg: Here's a quick run-through about how to modify existing menus now:
  1. in ui.xml set ego_detailmonitor as a dependency
  2. in ui.xml specify your own lua-file
  3. in your lua-file add a method-call (for instance init()) and implement that function in that file
  4. in init() iterate over the Menus-table (check entry.name to locate the proper menu)
  5. hook into the corresponding menu-function. For instance to modify how the menu looks, hook into menu.onShowMenu()
There are in principle two ways to hook into the menus. In general we suggest to use the first method, since that is less likely to break new features which could be added in a later version. The second method however is less limited to what you can do:
method 1: in your own lua file add something like this:

Code: Select all

local orgOnShowMenu

local function onShowMenuHook()

orgOnShowMenu() -- this ensures that the original menu behavior is retained - you will only extend the existing menu with your own functionality, retrieve the elements of the menu and hook into their functionality

-- add code to retrieve/update constructed elements

end

local function init()
[...]

orgOnShowMenu = menu.onShowMenu

-- menu being already the retrieved menu-entry from the Menus table for the appropriate menu (for instance the trading offers menu)

[...]
end

init() -- calls init upon loading the addon
method2: in your own lua file add something like this

Code: Select all

local function myOnShowReplacement()

-- copy/paste the content of the original lua-file's onShowMenuHook-function here and adjust it to whatever you feel like
-- most likely when using this method, you'll copy/paste the entire Lua file so you can alter everything

end

local function init()
[...]

menu.onShowMenu = myOnShowReplacement
-- menu being already the retrieved menu-entry from the Menus table for the appropriate menu (for instance the trading offers menu)

-- most likely you will have to replace all the entries in the Menus-table in the end --- depending on what you actually altered/intend to alter in the first place (for instance menu.onUpdate, menu.onRowChanged, etc.)

[...]
end

init() -- calls init() upon loading the addon
I've added a feature request to the bugtracker (http://www.egosoft.com:8282/jira/browse/XRUIMOD-5) to increase the number of use-cases where the first method could be used with. But I can't make any promise whether we will be able to get this in in-time for 3.50.
Stefan Hett

stefanEgo
EGOSOFT
EGOSOFT
Posts: 522
Joined: Thu, 11. Apr 13, 14:12
x4

Post by stefanEgo » Mon, 23. Feb 15, 11:14

For easier navigation/usage of the bugtracker, we've updated the initial post with some shortcuts to useful lists/pages on the bugtracker. Hope this makes it a bit easier to find ur way around there.
Stefan Hett

stefanEgo
EGOSOFT
EGOSOFT
Posts: 522
Joined: Thu, 11. Apr 13, 14:12
x4

Post by stefanEgo » Mon, 23. Feb 15, 11:59

The documentation was updated with a list of all Lua/FFI functions available in 3.50 beta 1. Hope this helps to figure out what's possible with the current UI support and what isn't. Please check out the provided Lua functions to see how these functions are used.
Stefan Hett

User avatar
wysiwyg
Posts: 584
Joined: Thu, 26. Feb 04, 01:08
x4

Post by wysiwyg » Tue, 24. Feb 15, 00:29

stefanEgo wrote:@bm01: There are two possibilities atm:
1. Create two separate addons (one in the fullscreen environment, one in the detailmonitor environment)
2. In the fullscreen environment create your own distinct window after you clicking on your button (see DisplayView() and related functions)

Unfortunately the support for cross-environment use-cases is somehow limited atm (especially with respect to working with a single addon set-up).

Feel free to add a feature request to the bugtracker, if you feel like the current support is too limited.
Request Added to bugtracker - It seems this issue will affect any mod that uses both the detailmonitor and the sidebar menu. Seeing as this worked previously would it not make sense to search in the addons folder of the mod for multiple addons e.g.

extensions/mymod/ui/addons/mymenu/ui.xml --> my_menu_addon.lua
extensions/mymod/ui/addons/mymonitor/ui.xml --> my_monitor_addon.lua

Just a thought!
Cheers
Wysi :)

Phipsz
Posts: 255
Joined: Mon, 23. Apr 12, 23:56
x4

Post by Phipsz » Tue, 24. Feb 15, 00:46

wysiwyg wrote:
stefanEgo wrote:@bm01: There are two possibilities atm:
1. Create two separate addons (one in the fullscreen environment, one in the detailmonitor environment)
2. In the fullscreen environment create your own distinct window after you clicking on your button (see DisplayView() and related functions)

Unfortunately the support for cross-environment use-cases is somehow limited atm (especially with respect to working with a single addon set-up).

Feel free to add a feature request to the bugtracker, if you feel like the current support is too limited.
Request Added to bugtracker - It seems this issue will affect any mod that uses both the detailmonitor and the sidebar menu. Seeing as this worked previously would it not make sense to search in the addons folder of the mod for multiple addons e.g.

extensions/mymod/ui/addons/mymenu/ui.xml --> my_menu_addon.lua
extensions/mymod/ui/addons/mymonitor/ui.xml --> my_monitor_addon.lua

Just a thought!
Cheers
Wysi :)
It does seem to work on my side, the folders have to be prefixed with ego_ though atm. don't add ego_ prefix in the ui.xml as name. so basically following structure should work:

extensions/mymod/ui/addons/ego_mymenu/ui.xml[name="mymenu"] --> my_menu_addon.lua
extensions/mymod/ui/addons/ego_mymonitor/ui.xml[name="mymonitor"] --> my_monitor_addon.lua

(or use my sidebarextender to circumvent two ui-addons :P I have already updated sidebarextender on my side and will push the update in a few hours )

I do agree with you though, I would really like to keep the folder structure for ui the same as before. It really would feel more "right", as we already put everything else in folder structure that has been defined by the existing structure and, as a result, would be more consistent

User avatar
wysiwyg
Posts: 584
Joined: Thu, 26. Feb 04, 01:08
x4

Post by wysiwyg » Tue, 24. Feb 15, 09:14

Hi Phipsz - The problem I have is that now the game only sees a single ui.xml file in the mod's root folder. I can get my menus to show up no problem using the existing method of plugging in to the main menu. However, the sidebar menu operates in the "fullscreen" environment so if one then tries to add something in the "detailmonitor" environment, the game throws a dependency error when trying to resolve the dependency for the detailmonitor:

Code: Select all

<addon name="my_menu" viewtype="fullscreen" ......>
     <file name="mymenu.lua"/>
     <dependency name="fullscreenHelper"/>
</addon>
works fine and the menu shows up no problem. However,

Code: Select all

<addon name="my_menu" viewtype="fullscreen" ......>
     <file name="mymenu.lua"/>
     <file name="mymonitor.lua"/>
     <dependency name="fullscreenHelper"/>
     <dependency name="detailmonitorHelper"/>
</addon>
does not work as it throws an error looking for the dependency for the detailmonitor.

I think your sidebar extender IS the way forward at the moment and I'm certainly going to look at using it for my Station Logistics mod.

Cheers
Wysi :)

stefanEgo
EGOSOFT
EGOSOFT
Posts: 522
Joined: Thu, 11. Apr 13, 14:12
x4

Post by stefanEgo » Tue, 24. Feb 15, 11:26

@wysiwyg: Makes absolute sense. I'll see what we can do for 3.50 here.
@Phipsz: We'll find a solution to support this properly. Please note that ur "workaround" will only work in this beta. It won't be possible in the released 3.50. I've added a bugtracker item here to make clear that this just works for the time being: http://www.egosoft.com:8282/jira/browse/XRUIMOD-7
@wysiwyg: The error you are seeing with ur second example is because
a) the addon name is incorrect (assuming you didn't create a new mod called: "fullscreenHelper" yourself, the correct name would be: "ego_fullscreenHelper" --- same goes for the detailmonitorHelper)
b) atm you can only set dependencies to addons in the same environment, therefore setting a dependency to ego_detailmonitorHelper will still issue an error here
I see whether we can tackle this alongside http://www.egosoft.com:8282/jira/browse/XRUIMOD-6
Stefan Hett

User avatar
wysiwyg
Posts: 584
Joined: Thu, 26. Feb 04, 01:08
x4

Post by wysiwyg » Tue, 24. Feb 15, 13:37

stefanEgo wrote: @wysiwyg: The error you are seeing with ur second example is because
a) the addon name is incorrect (assuming you didn't create a new mod called: "fullscreenHelper" yourself, the correct name would be: "ego_fullscreenHelper" --- same goes for the detailmonitorHelper)
b) atm you can only set dependencies to addons in the same environment, therefore setting a dependency to ego_detailmonitorHelper will still issue an error here
I see whether we can tackle this alongside http://www.egosoft.com:8282/jira/browse/XRUIMOD-6
Thanks Stefan - I wrote the post from memory and forgot to add the ego_ prefixes but can confirm what you said in that using the correct dependencies for two different environments in the same <addon/> tags does throw an error.

On another note I was able to successfully plug in to the MoneyTransfer menu as described in your previous post and this seems to work fine. After a bit of testing and tidying up I'll release this and see how it goes. I'll also post a summary of what I did as an example to add a bit more detail to your instructions.
Cheers
Wysi :)

stefanEgo
EGOSOFT
EGOSOFT
Posts: 522
Joined: Thu, 11. Apr 13, 14:12
x4

Post by stefanEgo » Tue, 24. Feb 15, 14:23

@blackmilan/wysiwyg: With regards to modifying existing menus, we've improved the support now. The changes are being tested now internally and are expected to make it into the next build. No ETA on that version yet, though. - http://www.egosoft.com:8282/jira/browse/XRUIMOD-5

The improvement is mainly that all functions previously local to the Lua-files are now members of the menu structure. That will allow you to hook into any of the functions without having to copy/paste the entire script any-longer.

That should make the method 2 I described earlier obsolete. Please let us know if there are still any remaining constrains which make you having to revert to the alternative method to alter menus, once the new version is out.
Stefan Hett

blackmilan
Posts: 123
Joined: Sat, 22. Jan 11, 22:13
xr

Post by blackmilan » Tue, 24. Feb 15, 19:30

Thanks for your support. I think that should pretty much solve it (at least for what I have currently in mind).
I will try out hooking into the trade menu with the current version (or the next build if it is already available) in the next days and let you know how it went.

User avatar
YorrickVander
Posts: 2682
Joined: Tue, 29. Oct 13, 22:59
x4

Post by YorrickVander » Tue, 24. Feb 15, 20:25

Cyberfuzzie's method seems to work ok still if the ui.xml + lua is put into the mods root directory (tip of the hat to w.evans for telling me about this). I'm yet to get this to work along side the custom dialogs for YAT though :(
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

User avatar
wysiwyg
Posts: 584
Joined: Thu, 26. Feb 04, 01:08
x4

Post by wysiwyg » Tue, 24. Feb 15, 22:02

YorrickVander wrote:I'm yet to get this to work along side the custom dialogs for YAT though :(
That's the crux of the issue at the moment - the sidebar operates in fullscreen mode and the custom dialogs in the detailmonitor mode. As we are only allowed one <addon/> root tag in ui.xml the game has issues finding the helper dependencies. I think Phipsz' sidebar extender is the solution in the short term as the menu runs in one mod and the detailmonitor dialogs in another. There's an issue raised on the bugtracker so hopefully this will change as the betas roll out.

Edit: Cyberfuzzie's method is essentially using a method similar to that described by Stefan in an earlier post. That's the method I used to plug into the MoneyTransfer menu and so far so good!

User avatar
YorrickVander
Posts: 2682
Joined: Tue, 29. Oct 13, 22:59
x4

Post by YorrickVander » Tue, 24. Feb 15, 22:45

Yeah, am waiting now for the next iterations to get YAT back up nicely. At least we can do basic menu > xml calls without overwriting other mods changes more easily soon.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

User avatar
wysiwyg
Posts: 584
Joined: Thu, 26. Feb 04, 01:08
x4

Post by wysiwyg » Tue, 24. Feb 15, 23:12

I thought I would share how I ported my Enhanced Money Transfer mod over to the new system in 3.50 b1 I know most people haven't written mods that patch into the existing UI framework but it should help as a reference as how to do it in general. I won't cover the ui.xml as I think that's already fairly clear - just to reiterate that as things stand the game looks for a single ui.xml file in the mod's root folder. You can also now put your .lua files in the root folder and there's no need anymore to put them in a subst_xx.cat file or use a convoluted path in the xml file to locate them.

So, in the versions previous to 3.50 I was able to simply write a new version of the MoneyTransfer lua file and diff patch the ego_detailmonitor.xml file to replace Ego's version with my own. As of 3.50 b1 I can't do that so I now need to locate the existing (vanilla) menu and "hook" my functions into it. Here's how:

First I make a local empty table to hold a copy of the vanilla MoneyTransfer dialog:

Code: Select all

local emt_menu = {}
I'm also going to make a table to store my collection of functions as this is how I like it (makes debug and cleanup a lot easier)

Code: Select all

local Funcs = {}
Now, here's the important bit (with comments):

Code: Select all

local function init()   -- This function runs at game startup to load menus

	-- iterate over the master "Menus" table to find the menu we want to plug in to
	-- Note that "Menus" is THE master table that holds a live copy of all XR's menus/dialogs

	for _, menu in ipairs(Menus) do     -- note that the underscore is simply a placeholder for an ignored variable 

		-- We're looking for the menu called "MoneyTransferMenu"

		if menu.name == "MoneyTransferMenu" then				

			-- We found our menu so let's first make a local copy of it that we can use, for example if we need to call any Helper functions
			-- or maybe access any passed parameters. In my functions below I can now access passed in parameters as e.g. emt_menu.param1

			emt_menu = menu

			-- Now we hook in our own functions to replace the originals

			menu.onShowMenu = Funcs.EMT_onShowMenu
			menu.onUpdate = Funcs.EMT_onUpdate
			menu.onSelectElement = Funcs.EMT_onSelectElement
			menu.onCloseElement = Funcs.EMT_onCloseElement
			menu.cleanup = Funcs.EMT_cleanup
         break      -- we found our menu so we can break out of the for loop as we don't need to carry on looking anymore
		end
	end
end
Job Done - well almost - we still need to define our own functions below, so (without all the boring details)

Code: Select all

Funcs.EMT_cleanup = function()
	.........
end

Funcs.EMT_onShowMenu = function()
	...........
end

-- Note here that I'm using the onUpdate function so I need to set an update interval - I access this via my local copy of the vanilla menu
emt_menu.updateInterval = 0.5
Funcs.EMT_onUpdate = function()
	..............
end

Funcs.EMT_onSelectElement = function()
	...........
end

Funcs.EMT_onCloseElement= function(dueToClose)
	.........
end
Finally, call the init() function and the mod is patched into the original menu framework

Code: Select all

init()
Remember that if you wish to call any of the functions in the member table (Funcs) locally i.e. inside the mod then use the : operator e.g.

Code: Select all

Funcs.LocalFunction = function()
	local foo = 5
	return foo
end

bar = Funcs:LocalFunction()
-- bar is assigned the value 5
Hope this helps
Wysi :)

Post Reply

Return to “X Rebirth - Scripts and Modding”