UI modding - support thread

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

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

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sat, 12. Sep 15, 11:31

ok, solved it - i was stupid.

i thought my copied map worked because it was called but in fact i used the vanilla map (changed the related lines in the MD-Script but didnt save the changes) - and also misunderstood the UI Modding Doc, thought the ui.xml goes into the ui folder inside the Extension - that was all. My exact problem is already solved, will now look into how to add Space selection instead of Zone/Sector/Cluster only

thanks everyone for help and sorry if i wasted some of your time.. :oops:
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Wed, 7. Oct 15, 21:24

During September/October, Egosoft staff have continued to update many of their guides for modders on their wiki. They have also published a couple of new guides there too (!). Finally, there is a new wiki page for us to try and keep a track of forum-based guides as they can sink out of sight over time.

All those things above are now grouped under a single wiki page called Mods and modding support. A one-stop shop for making and breaking code :)

The front page of wiki explains a bit about the wiki and how we can add content to help it expand and update it over time.
Mods and modding support wrote:Finding mods (AKA "extensions") (something simple to help users find mods)
Mission Director Guide (new)
UI Modding support
- Getting started guide
- FFI function overview
- Lua function overview
- Further UI modding resources
- Breaking changes (most recently for 3.20 -> 3.50 Beta 1)
- Changelog (currently may be unreadable due to a technical difficulty - Egosoft aware)
- Widgetsystem function overview (new)
How to replace a menu
Modding FAQ - links to forum-based help from Egosoft and players (new)
Porting pre 3.50 UI mods

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

Post by stefanEgo » Fri, 6. Nov 15, 15:16

@BigBANGtheory: In 4.00 Beta 2 we've now added means to draw geomeotrical elements in UI menus (part of the widget system - see http://www.egosoft.com:8282/jira/browse/XRUIMOD-11).
Stefan Hett

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Thu, 19. Nov 15, 18:48

Do you have any documentation on what checkObjectSelectConditions does and the parameters that it checks ?

its from line 272 of menu_property.lua

Code: Select all

elseif menu.mode == "selectobject" then
		if Helper.checkObjectSelectConditions(rowdata, menu.modeparam) then
			active = true
		end

I am attempting to answer my own question from

http://forum.egosoft.com/viewtopic.php?t=384092

Regards

jth

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Thu, 19. Nov 15, 18:54

look into ui/addons/ego_detailmonitorHelper/helper.lua line 2599 ;) dont think it would help you..
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Fri, 20. Nov 15, 13:18

UniTrader wrote:look into ui/addons/ego_detailmonitorHelper/helper.lua line 2599 ;) dont think it would help you..
Thanks for the answer to this question.

Its a very useful piece of insight into how the lua scripts are bolted together that had totally failed to register with me

I had no idea that that Helper.checkObjectSelectConditions was a function in another lua script or where the Helper functions for ego_detailmonitor were. I was guessing that it was some sort of API call in the exe.

I have located the checkObjectSelectConditions function in ui/addons/ego_detailmonitorHelper/helper.lua and am attempting to understand it.

Hopefully should I manage it I will be able to answer my own question in the other post

Here comes a shed load of DebugError statements and a lot of trial and error :)

jth

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Modifying the second title row

Post by jth » Sat, 5. Dec 15, 19:26

Hi

The following comes from ego_detailmonitor\menu_buildcost.lua starting at line 126

Code: Select all

	local setup = Helper.createTableSetup(menu)
	local name, typestring, typeicon, typename, ownericon = GetComponentData(menu.architect, "name", "typestring", "typeicon", "typename", "ownericon")
	setup:addTitleRow({
		Helper.createIcon(typeicon, false, 255, 255, 255, 100, 0, 0, Helper.headerCharacterIconSize, Helper.headerCharacterIconSize),
		Helper.createFontString(typename .. " " .. name, false, "left", 255, 255, 255, 100, Helper.headerRow1Font, Helper.headerRow1FontSize),
		Helper.createIcon(ownericon, false, 255, 255, 255, 100, 0, 0, Helper.headerCharacterIconSize, Helper.headerCharacterIconSize)	-- text depends on selection
	}, nil, {2, 4, 1})
	setup:addTitleRow({ 
		Helper.createFontString(title, false, "left", 129, 160, 182, 100, Helper.headerRow2Font, Helper.headerRow2FontSize, false, Helper.headerRow2Offsetx, Helper.headerRow2Offsety, Helper.headerRow2Height, Helper.headerRow1Width)	-- text depends on selection
	}, nil , {7})
I think that its responsible for creating the title rows for the build cost

I am working on a modified copy of menu_buildcost for recycling cost instead, its coming along fairly well but ....

What I want to do is overwrite the second title line with something that says "Insufficient resources - ...." if I find that the station has insufficient resources to recycle the selected ship.

How do I do this ?

EDIT
Is it just a mattter of moving the

Code: Select all

setup:addTitleRow({ 
		Helper.createFontString(title, false, "left", 129, 160, 182, 100, Helper.headerRow2Font, Helper.headerRow2FontSize, false, Helper.headerRow2Offsetx, Helper.headerRow2Offsety, Helper.headerRow2Height, Helper.headerRow1Width)	-- text depends on selection
	}, nil , {7})
down a bit and adding an if .. else to change title to recyclingIssues before it gets to Helper.displayTableView near the bottom

or is there some way to overwrite the second title formatted string and have it switch to it

Thanks

jth

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

Post by wysiwyg » Sun, 6. Dec 15, 14:15

I find it easier for code readability and maintenance to keep the logic and output separate:

The string variable title is the only "actual" variable in the long winded output statement. So something like:

Code: Select all

if <condition 1> then
     title = "Condition 1 text"
else
     title = "Condition 2 text" 
end
then write the row output as a single statement:

Code: Select all

setup:addTitleRow({ 
      Helper.createFontString(title, false, "left", 129, 160, 182, 100, Helper.headerRow2Font, Helper.headerRow2FontSize, false, Helper.headerRow2Offsetx, Helper.headerRow2Offsety, Helper.headerRow2Height, Helper.headerRow1Width)   -- text depends on selection 
   }, nil , {7})
If you want to be more advanced and change the formatting as well you could write a function of your own that takes arguments that determnine the output and then call the function conditionally e.g.

Code: Select all

function WriteMyFormattedRow( TEXT, RED, GREEN, BLUE, ALPHA)
Helper.createFontString(TEXT, false, "left", RED, GREEN, BLUE, ALPHA, Helper.headerRow2Font, Helper.headerRow2FontSize, false, Helper.headerRow2Offsetx, Helper.headerRow2Offsety, Helper.headerRow2Height, Helper.headerRow1Width)   -- text depends on selection 
   }, nil , {7})
end
Then call something like:

Code: Select all

if <condition 1> then
     WriteMyFormattedRow( "Resources Available", 255, 255, 255, 100)
else
     WriteMyFormattedRow( "Insufficient Resources....", 255, 0, 0, 100)
end
Hope this helps
Wysi :)

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Sun, 6. Dec 15, 15:03

Thanks Wysi

I will try out your suggestion

jth

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Sun, 6. Dec 15, 18:37

OK Wysi

I have given it a try and run into a few stumbling block in my implementation. I thought that I might share them as I found it very educational :)

I managed to create a rather large positioning problem with my first attempt. The second title row came out completely in the wrong place :(

The pseudo code started as something like

Code: Select all

local setup = Helper.createTableSetup(menu)

Add Title line 1
Add Title line 2

setup:addHeaderRow ...

get resources

for _, entry in ipairs(resources) do
   check needed wares against storage and if there is insufficient energy or food then create an error message
   display resource entry
end
I am not able to work out whether there is enough resources until it compares the station cargo with the build resources and that happens as part of going through the resources at the bottom of the code

cargo["energycells"] gets the energycells in storage nicely but resources is unfortunately a table of tables rather than a single table like cargo and I don't know how to extract it in a one liner. So its difficult to add it as a condition around "Add Title line 2"

So I changed things and moved "Add Title line 2" down a bit

Code: Select all

local setup = Helper.createTableSetup(menu)

Add Title line 1

setup:addHeaderRow ...

get resources

for _, entry in ipairs(resources) do
   check needed wares against storage and if there is insufficient energy or food then create an error message
   display resource entry
end

if there is an error message then display it as Title line 2
if not display the original Title line 2
The result of that is that the second Title line vanishes from the top and re-appears after the HeaderRow and list of resources which I was not expecting. Oops :(

I guess that my assumption that setup:addTitleRow created a special Title line was not correct and it looks like it only means add a table row with Title formatting which is educational :)

So to get this working I need to move the "Add Title line 2" and get resources upwards and add an extra iteration through resources immediately after writing Title line 1 and move the checks in there. Not very elegant but should do the trick.

Code: Select all

local setup = Helper.createTableSetup(menu)

Add Title line 1

get resources

for _, entry in ipairs(resources) do
   check needed wares against storage and if there is insufficient energy or food then create an error message
end

if there is an error message then display it as Title line 2
if not display the original Title line 2

setup:addHeaderRow ...

for _, entry in ipairs(resources) do
   display resource entry
end
Or come up with something similar to menu_property.lua which uses what I thought was a different style of menu with updateable information in the second title row.

The magic bit in menu_property.lua seems to be the displayThreeTableView and Helper.updateCellText which allows you to update some Cell Text

Code: Select all

-- create tableview
menu.infotable, menu.selecttable, menu.buttontable = Helper.displayThreeTableView(menu, infodesc, selectdesc, buttondesc, false, "", "", 0, 0, 0, 0, "both", firsttime)

...

local infotext = IsSameComponent(rowdata, menu.playership) and "%s = %d %%, %s = %d %%, %s = %s / %s / %s" or "%s = %d %%, %s = %d %%, %s = %s / %s / %s\n%s%s %s"
Helper.updateCellText(menu.infotable, 2, 1, string.format(infotext, ReadText(1001, 2), shieldpercent, ReadText(1001, 1), hullpercent, ReadText(1001, 2943), cluster, sector, zone, ReadText(1001, 78), ReadText(1001, 120), aicommand))
and with a fantastic bit of luck :) menu_buildcost.lua is also using the Helper.displayThreeTableView (I didn't think that it was when I made the original post) which supports the variable information in the second title line but it doesn't use infotext at all ....

So if I do

Code: Select all

local setup = Helper.createTableSetup(menu)

Add Title line 1
Add Title line 2

setup:addHeaderRow ...

get resources

for _, entry in ipairs(resources) do
   check needed wares against storage and if there is insufficient energy or food then create an error message
   display resource entry
end

if lengthrecyclingIssues ~= #recyclingIssues then -- there are some issues
	local infotext = "%s"
	Helper.updateCellText(menu.infotable, 2, 1, string.format(infotext, " \27R" .. recyclingIssues .. "\27X"))
end
then it sticks a red error message in the second title line and it seems to overwrite the original "Title line 2" with no problem which is exactly what I wanted :)

I hope that this is allowable and not a fortunate coincidence

and thanks for providing what should have been the simplest answer to implement

jth

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Example wanted for raise_lua_event

Post by jth » Sat, 19. Dec 15, 15:28

Has anyone got a small snippet of code (both md and corresponding lua) that shows how to use raise_lua_event

EDIT

and/or a pointer (URL or just the mod name) to some code that uses a dummy call to some UI code that doesn't actually display anything but returns with some data or does something

Background

I want to use the "Deploy to station" option out of the architect menu without having to get the player to go through starting a conversation and then selecting "Deploy to station" then picking the station.

I could just pinch the code but its fairly long and bad software engineering to do that.

I would simply like to generate an event_conversation_next_section with the architect with a section="cArch_deployatstation" and param of [0,0,$targetstation]

I can do most of this with start_conversation, then listen for event_conversation_started and

Code: Select all

 add_player_choice position="top_left" section="cArch_deployatstation" text="{1002,4009}" choiceparam="[0, 0, $playerstation]" comment="Deploy to Station"/>
but I still need the player to select it and I would like to avoid that

Thanks

jth

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

Post by YorrickVander » Sat, 19. Dec 15, 17:41

I haven't seen *anything* about this since stefan posted on the subject on page... 4?
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sat, 19. Dec 15, 18:01

Sounds to me like you want direct control of the conversation flow without player input? (quasi a add player choice without the player selecting anything) - I have created something like this, search the MD files of my Manager script for "'return'" to find the MD lines and look into the ui folder for the lua side
Will provide links later if needed, currently on the phone
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Sat, 19. Dec 15, 19:29

YorrickVander wrote:I haven't seen *anything* about this since stefan posted on the subject on page... 4?
It looks like its in common.xsd dated 14/12/2015 so I think its just been released in 4.00 beta 4 HF2 or 3

I will have a look at UniTrader's suggestion too

jth

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Sun, 20. Dec 15, 17:26

Ok I have looked at UniTraders code and its exactly what I was looking for and works about as I expected. Thanks UniTrader that saved me a load of time :)

That gets me a fallback position so I thought that I would try and get raise_lua_event to play ball too.

I found the JIRA entry for raise_lua_event which is http://www.egosoft.com:8282/jira/browse/XRUIMOD-19 with a view to getting some insight into the parameters

The magic words say The idea is to add an MD action which calls RaiseLuaEvent() which would then be accessible by UI addons via the RegisterEvent()-callbacks

I decided to experiment on UniTraders ut_conversationcontrol.lua file as that covers both approaches and plugged it into my mod in the usual way

in the md script

Code: Select all

<raise_lua_event name="'HELLO_WORLD'" param="'cArch_deployatstation'"/>
and in the lua code

Code: Select all

local function init()
        ....
	RegisterEvent("HELLO_WORLD", menu.helloworld)
end

function menu.helloworld()
	DebugError("Hello World")
end
and to my surpise in the debug.log I got

[=ERROR=] Hello World

It works or rather I managed to drive it :)

Its a bit too simple an example to be useful without parameters so ...

Changed the lua code to

Code: Select all

local function init()
        ....
	RegisterEvent("HELLO_WORLD", menu.helloworld)
	menu.param, menu.param2 = GetMenuParameters()
end

function menu.helloworld()
	DebugError("Hello World" .. menu.param)
end
but its producing an error

[=ERROR=] Error while executing onEvent script for event: HELLO_WORLD.
Errormessage: [string "extensions/station_structural_rebuild/ui/ut_c..."]:67: attempt to concatenate field 'param' (a nil value)

so I guess that is not how you get at the parameter from raise_lua_event :(

EDIT

Experimented a lot and realised that RegisterEvent only has two parameters and finally guessed that the raise_lua_event parameter must come out as the parameter to the function that is called by the event. So came up with some modified lua code

Code: Select all

local function init()
        ....
	RegisterEvent("HELLO_WORLD", menu.helloworld)
end

function menu.helloworld(eventname, eventparam)
	DebugError("Hello World " .. eventname .. " " .. eventparam )
end
which produces

[=ERROR=] Hello World HELLO_WORLD cArch_deployatstation

Its getting there :)

jth

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Sun, 20. Dec 15, 18:58

At this point I thought that I would try and pass multiple paremeters through but that is not allowed has to be a string, number or component which puts a bit of a spanner in the works as I have two parameters to pass

This is how to pass a component $SR_Station across

Code: Select all

<raise_lua_event name="'HELLO_WORLD'" param="$SR_Station"/>
and

Code: Select all

function menu.helloworld(eventname, eventparam)
	DebugError("Hello World " .. eventname .. " " .. GetComponentData(eventparam, "name") )
end
that produces

[=ERROR=] Hello World HELLO_WORLD Foodstuffs Supply I

The killer here is that there is only one parameter allowed and I have two

So if I have lots of different functions, one for each callback label then it could work although its not ideal

Code: Select all

<raise_lua_event name="'cArch_deployatstation'" param="$SR_Station"/>
and

Code: Select all

local function init()
        ....
	RegisterEvent("cArch_deployatstation", menu.cArch_deployatstation)
end

function menu.cArch_deployatstation(eventname, eventparam)
	DebugError("Hello World " .. eventname .. " " .. GetComponentData(eventparam, "name") )
end
that produces

[=ERROR=] Hello World cArch_deployatstation Foodstuffs Supply I :)

or I guess that I could pass a string that contains the two parameters with a seperator and slice and dice it in the lua script

anyway that will do for today

jth
Last edited by jth on Mon, 21. Dec 15, 12:55, edited 1 time in total.

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

Post by YorrickVander » Mon, 21. Dec 15, 10:13

For passing multiple data types you could try creating a cue actor and accessing blackboard variables setup in xml. I assume that will be ok as a component to pass across.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

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

Post by YorrickVander » Mon, 21. Dec 15, 20:00

I'm a little lost why, on returning to a custom ui element from say a button to link to encyclopedia, the menu stack closes rather than going back as needed. As far as I can see I am not missing anything to facilitate this in my lua file.

The file in question for dissection (still wip but working in game) : https://www.dropbox.com/s/e6bgshn60gvc6 ... t.lua?dl=0
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Mon, 21. Dec 15, 20:24

can you also post the related MD Callback for Conversation Section gYorrick_FlyToLoot ?
does the related MD Callback create new Dialogue Choices or open a further Menu? if not the Conversation automatically ends (thats why i created the conversation flow control - to keep the Menus open if further input is expected by simulating a Player choice)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

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

Post by YorrickVander » Mon, 21. Dec 15, 20:54

There is none from fly to loot. But I think I see what you're getting at. Will tinker and find out.

To be clear in case of misunderstanding : its not the back button on my ui element that fails. That works as intended and returns to the sidebar. It's when I go from the new ui > encyclopedia entry > back that the menu closes instead of returning to the new element.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

Post Reply

Return to “X Rebirth - Scripts and Modding”