UI modding - support thread

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

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

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13298
Joined: Sun, 15. Feb 04, 20:12
x4

Post by euclid » Thu, 5. Mar 15, 14:42

stefanEgo wrote: ......In the next build we added a new MD action called "raise_lua_event". That should allow you to send data from MD to Lua scripts as well as being used as a trigger for any kind of functionality.
......
That sounds good! As you know I'd like to access data which are not available via MD/XML script commands, for example "GetProductionModuleData". Looking forward to test this new command.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

Vim Razz
Posts: 1842
Joined: Tue, 2. Nov 10, 02:20
x4

Post by Vim Razz » Fri, 6. Mar 15, 06:27

@stephan -- I was just wondering about the possibility. Thank you for taking the time to add the feature request!


And I'll join the chorus of "wow, sounds great!" at the exploring the possibilities of a raise-lua-event MD function. I currently use a MD-script based system for determining whether certain mods are active or not to make compatibility adjustments in my own project, but have been thinking of switching to a LUA-based extension lookup system instead. The possibility of doing that without having to pop open another fake menu is very appealing.

bm01
Posts: 421
Joined: Wed, 22. Jul 09, 22:31
x4

Post by bm01 » Sat, 7. Mar 15, 13:54

Thank you very much for http://www.egosoft.com:8282/jira/browse/XRUIMOD-6, this is exactly what I asked for in my old post. I was afraid I would have to provide a second mod just for one part of "my" UI.

Also, sorry if it has already be mentioned, but it seems that the ui.xml file isn't uploaded to the Steam Workshop.

cyberfuzzie
Posts: 134
Joined: Tue, 21. Nov 06, 13:58
x4

Post by cyberfuzzie » Sat, 7. Mar 15, 14:47

I put the ui.xml file in my ext_01.cat/dat and it worked fine.

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

Post by Phipsz » Sat, 7. Mar 15, 15:29

bm01 wrote:Also, sorry if it has already be mentioned, but it seems that the ui.xml file isn't uploaded to the Steam Workshop.
Yes, it's quite sad the workshoptool does not automatically pack the ui.xml into the cat with -buildcat (or -buildvcat either) now that I don't even have to add subst_01.cat to mods anymore. while manually packing the files is working fine, it would be more convenient and consistent if the workshoptool would not ignore the ui.xml. workshoptool also has another problem regarding contributor rights I reported a few days ago in the rebirth tools discussion (but sadly got no answer yet.)

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

Post by blackmilan » Sun, 8. Mar 15, 20:49

stefanEgo wrote:@blackmilan: XRUIMOD-16 should be fixed in the next version
Hi Stefan, I just checked out version 3.5 beta 3 and is working perfectly now. :) Thanks!

If anybody is interested in having a look at my code a new version of the Trade Menu Cargo Hold Filter can be found here.

User avatar
wysiwyg
Posts: 585
Joined: Thu, 26. Feb 04, 00:08
x4

Post by wysiwyg » Sun, 8. Mar 15, 23:49

The ui.xml file can be added to the cat/dat files using the XRCatTool. I put all the required commands in a batch file (unfortunately one needs to be well versed in using REGEX to get the full effect!!) Here's my batch file for building Enhanced Money Transfer (Including backports for earlier releases):

Code: Select all

REM Build batch file for X-Rebirth - MT Enhanced Money Transfer Mod
REM Version 1.0
REM Date 2014-12-04
set version=%1

rmdir ..\release\%version%\mt_enhanced_money_transfer\
mkdir ..\release\%version%\mt_enhanced_money_transfer\

REM Add current release to ext_01.cat
XRCatTool -in ..\src\%version% -out ..\release\%version%\mt_enhanced_money_transfer\ext_01.cat -exclude "^content" "^readme" "^ego_forum_text" "xpl$" "old$" "^v251/" "^v320/" -dump

REM Now add the v251 release diff ext_v251.cat file
XRCatTool -in ..\src\%version%\v251 -out ..\release\%version%\mt_enhanced_money_transfer\ext_v251.cat -diff ..\src\%version% -exclude "^v251/"  "^v320/" "^readme" "^ego_forum_text" "^content" "xpl$" "old$" -dump

REM Now add the v320 release diff ext_320.cat file
XRCatTool -in ..\src\%version%\v320 -out ..\release\%version%\mt_enhanced_money_transfer\ext_v320.cat -diff ..\src\%version% -exclude "^v320/" "^v251/"  "^readme" "^ego_forum_text" "^content" "xpl$" "old$" -dump

REM Copy content.xml to release folder
copy ..\src\%version%\content.xml ..\release\%version%\mt_enhanced_money_transfer\content.xml

REM Copy readme.txt to release folder
copy ..\src\%version%\readme.txt ..\release\%version%\mt_enhanced_money_transfer\readme.txt
echo "Done...."
The file is run from a build directory in the same tree as the source code e.g.

../mt_EMT/build/buildemt.bat
../mt_EMT/src/%version%/*.*
../mt_EMT/release/%version%/*.cat, *.dat, *.txt etc.

The batch file takes a single parameter that is the version to be built e.g.
buildemt.bat v115 will build version 1.15 etc.

Just for completeness I then use the following batch file to publish. It takes three parameters:
Param 1 - publish - publish the mod for the first time
update - updates an already published mod
minor - minor update without version change
Param 2 - version - eg v115
param 3 - "The required update text if using publish or update as Param 1"

Code: Select all

@ECHO OFF
REM Publish X-Rebirth: MT Enhanced Money Transfer Mod
REM Version 1.0
REM 2014/12/04

REM if no parameter then update else first time publish 
IF "%1" EQU "update" GOTO Update_mod
IF "%1" EQU "publish" GOTO Publish_mod
IF "%1" EQU "minor" GOTO Update_minor
GOTO Error_args

:Publish_mod
ECHO "Publishing Mod......"
GOTO End_of_prog

:Update_mod
REM Set the changenote text
set change_note="%~3"
set version=%2
IF "%~3" EQU "" GOTO Error_args
ECHO %change_note%
WorkshopTool update -path "..\release\%version%\mt_enhanced_money_transfer" -changenote %change_note%
GOTO End_of_prog

:Update_minor
set change_note="%~3"
set version=%2
IF "%~3" EQU "" GOTO Error_args
ECHO %change_note%
WorkshopTool update -minor -path "..\release\%version%\mt_enhanced_money_transfer" -changenote %change_note%
GOTO End_of_prog


:Error_args
ECHO "Incorrect command line arguments....."
:End_of_prog
ECHO "Done...."
I should get around to making these files universal one of these days so that the same files will work on any mod. :O

Hopefully you can work out what I did and adapt for your own mods.

Cheers
Wysi :)

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

Post by stefanEgo » Mon, 9. Mar 15, 09:58

@euclid: Please understand that the raise-lua-event MD action is just a one-way handling to transmit data/trigger events from MD back to Lua. It doesn't work the other way around. However, I've created a feature request for this scenario for you. We hope to get this in in-time for 3.50, but no promises ( http://www.egosoft.com:8282/jira/browse/XRUIMOD-22 ).
@bm01/Phipsz/wysiwyg: Thanks for pointing out that the workshop tool doesn't include the ui.xml automatically. As suggested by cyberfuzzie, Phipsz, and wysiwyg, it works if you manually add the ui.xml file though. I'll see if we can improve this behavior. Was also added to the bugtracker: http://www.egosoft.com:8282/jira/browse/XRUIMOD-21
Last edited by stefanEgo on Mon, 9. Mar 15, 10:40, edited 1 time in total.
Stefan Hett

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

Post by stefanEgo » Mon, 9. Mar 15, 10:40

@euclid: Good news. The next build should provide a new function: SignalObject() which can be used to send data from Lua to MD.
Stefan Hett

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13298
Joined: Sun, 15. Feb 04, 20:12
x4

Post by euclid » Mon, 9. Mar 15, 15:04

Thank you (and the team) :-)

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

KlausM
EGOSOFT
EGOSOFT
Posts: 639
Joined: Wed, 6. Nov 02, 20:31
x4

Post by KlausM » Mon, 9. Mar 15, 16:05

stefanEgo wrote:@bm01/Phipsz/wysiwyg: Thanks for pointing out that the workshop tool doesn't include the ui.xml automatically. As suggested by cyberfuzzie, Phipsz, and wysiwyg, it works if you manually add the ui.xml file though. I'll see if we can improve this behavior. Was also added to the bugtracker: http://www.egosoft.com:8282/jira/browse/XRUIMOD-21
The WorkshopTool has just been updated, ui.xml is now included when using -buildcat or -buildvcat. Let us know if there are any problems.

User avatar
YorrickVander
Posts: 2705
Joined: Tue, 29. Oct 13, 21:59
x4

Post by YorrickVander » Mon, 9. Mar 15, 16:17

@stefan + klaus m - ty both, really pleased with the support for this new feature.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

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

Post by stefanEgo » Tue, 10. Mar 15, 08:57

Breaking changes of 3.50 RC1 are noted here: https://wiki.egosoft.com:1337/X%20Rebir ... .50%20RC1/
Most importantly we had to restrict the location of Lua files in extensions to NOT be located in the extension's root-directory.

We suggest to create a ui directory and put the Lua files in there. The references in the ui.xml file then need to be adjusted accordingly (aka: <file name="ui/file1.lua" />).
Stefan Hett

bm01
Posts: 421
Joined: Wed, 22. Jul 09, 22:31
x4

Post by bm01 » Tue, 10. Mar 15, 09:53

By using a dot to represent the current directory ("./file.lua") it's apparently possible to make the lua files accessible while being in the root directory.
I don't know if that's an issue but I thought I should mention it.

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

Post by stefanEgo » Tue, 10. Mar 15, 10:08

@bm01: Yep that's correct. We'll update the documentation accordingly to be more precise about this point.
We are considering it basically best-practice to have Lua-files not in the root-directory. While atm nothing will break, if you do that and use the "." in the path, we won't ensure that this will not break in a future version. Therefore, if you still keep ui-files in the extensions root, don't be surprised if your addon won't work in a later version of X Rebirth.
Stefan Hett

hhr
Posts: 61
Joined: Fri, 6. Oct 06, 15:18
x4

Post by hhr » Tue, 10. Mar 15, 14:29

tell me, what is my mistake?

1) make directory \extensions\test_ui
2) copy original \ui\addons\ego_gameoptions\gameoptions.lua to \extensions\test_ui\ui\gameoptions.lua without changes
3) content.xml:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<content id="test_ui" name="Test UI" description="Test UI description" author="hhrhhr" version="100" date="2015-03-09" save="false">
  <dependency version="350" />
</content>
4) ui.xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<addon name="test_ui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../core/coreaddon.xsd">
  <environment type="fullscreen">
    <file name="ui/gameoptions.lua" />
    <dependency name="ego_gameoptions" />
  </environment>
</addon>
result:

when the game starts immediately see a message in the log

Code: Select all

Error: Invalid call to SetScript(). Given script function must be a function but is 'string'
Error: Invalid call to RemoveScript(). Given script function must be a function but is 'string'
Error: c:\\dev\\x4_hotfix\\X4\\ui\\xanark\\anarkviewbridge.cpp(111): Warning. The current frame for 'fullscreen' was already updated without processing the update event. Check for errors in addon scripts issuing too many update calls.\
(version: 3.50 - Code revision: 192786)
if i load or start a new game, then after pressing the Esc log appended the first two lines and the game freezes.

User avatar
wysiwyg
Posts: 585
Joined: Thu, 26. Feb 04, 00:08
x4

Post by wysiwyg » Tue, 10. Mar 15, 15:08

@hhr - I suspect you are calling two completely separate instances of gameoptions.lua there that are conflicting with each other. Your version of the .lua file will need changing if you want the options menu to behave differently. You'll basically need to 'hook' your modified functions into the existing Menu table as described in the previous pages of this thread. See here for an example of hooking into "Menu"
Hope this helps
Wysi :)

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

Post by stefanEgo » Tue, 10. Mar 15, 15:18

@hhr: wysiwyg was a bit faster than I was. So basically this is just repeating what he already said:
The problem you are running in is that now you end-up with two menus being registered to open alongside the optionsmenu-show-event. The standard one and ur copy of the standard version.
Take a look at the init() function. Since in principle it's now being called twice, it also registers two menus via the call to Helper.registerMenu(menu). In ego_fullscreenHelper/helper.lua you find the registerMenu()-function which basically does two register calls.

Code: Select all

[...]
	RegisterEvent("show"..menu.name, showMenuCallback)
	RegisterEvent("showNonInteractive"..menu.name, showNonInteractiveMenuCallback)
end
This now results in two functions being called when the showOptionsMenu event occurs.

If you really want to replace the entire menu, you'd have to hook into the onShowMenu() function of the existing menu.
Aka:
- update the init() function in your copy
- search the list of existing menus for the OptionsMenu one
- replace that menus callback functions (like the onShowMenu()-function) with your own functions

To provide an easier way for this use-case, I've added a feature request for you ( http://www.egosoft.com:8282/jira/browse/XRUIMOD-23 ) to provide means to completely unregister menus which were registered with the helper. Hopefully this will be ready in-time for 3.50 but can't make any promises here, unfortunately.
There are other means to tackle this case, but I'd say that while the one mentioned above is certainly not the easiest one to work with, it's IMO the safest variation atm.
Stefan Hett

hhr
Posts: 61
Joined: Fri, 6. Oct 06, 15:18
x4

Post by hhr » Tue, 10. Mar 15, 15:49

stefanEgo wrote:If you really want to replace the entire menu...
not exactly.
I had a desire to make a menu for the entire height of the screen and change the width of columns in some settings. it needs to dynamically change the members of table "config" depending on the current (selected) resolutions.

now it looks like this:

Code: Select all

-- old code
-- local config = {...
--	frameHeight = 550,
--	tableHeight = 430,
--...}

-- new code
local config = {}

local function setConfig()
    local res = GetResolutionOption()
    local width = res.width
    local height = rse.height
    ...
    config.frameHeight = height
    config.tableHeight = height - config.tableOffsety * 2
    ....
end
and after every call of SetResolutionOption() I inserted a call to this function (setConfig) to update the values.

affected functions - onUpdate and onSelectElement, to write the "interceptor", then I'll have to copy the entire contents for pasting a single line. is there no other way?

in its current form, it even works and the main menu and in-game. once the game freezes ;)

(original - modded)
[ external image ] - [ external image ]

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

Post by stefanEgo » Wed, 11. Mar 15, 09:11

@hhr: We got the unregisterMenu-function in in-time for 3.50 RC2. So with the latest version, you now have an alternative at hand to replace entire menus (if you ever want that) and call

Code: Select all

-- iterate over the Menus array to get the proper menu, then call:
Helper.unregister(menu)
Note that depending on the actual menu, you might have to do additional things to fully clean-up a menu. In case of the game options menu, this means (at the time of writing this) unregistering the "openOptionsMenuParam" event - see gameoptions.lua: init()-function last line.

For your case I guess the easiest approach would be to hook into the SetResolutionOption function directly:

Code: Select all

[...]
local orgSetResolutionOption
local function mySetResolutionOption(arg1, arg2)
	orgSetResolutionOption(arg1, arg2)
	setConfig()
end
[...]
local function init()
	orgSetResolutionOption = SetResolutionOption
	SetResolutionOption = mySetResolutionOption
end
@all: if you previously checked out the Lua/FFI list in Confluence, you might wanna take another look. We extended the documentation quite much over the past few days. While it's not complete yet, most of the functions are now documented here:
https://www.egosoft.com:8444/confluence ... n+overview
https://www.egosoft.com:8444/confluence ... n+overview
Stefan Hett

Post Reply

Return to “X Rebirth - Scripts and Modding”