[API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.32 (02/27/19))

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

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

morbideth
Posts: 389
Joined: Sun, 9. Nov 08, 04:07
x3tc

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.11

Post by morbideth » Mon, 7. Jan 19, 04:27

Bug Fix update v0.11 Fixed Right click API breaking some vanilla commands after the first click

Unclejack
Posts: 24
Joined: Wed, 5. Dec 18, 02:50
x4

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.11

Post by Unclejack » Mon, 7. Jan 19, 05:07

Hello morbideth,

I have been working on a small lua patching script to alter the menu_map.lua and was replacing the ui.xml file in the ui/addons/egodetailmonitor.
However, I quickly noticed we can only get this to work using a substitution cat/dat archive, as you mentioned.
I have been unable to patch this ui.xml file with single lines to allow for compatability. As a result, I decided to integrate my script with your G_Work_Around API and it is working well so far.
I actually released this lua-based map enhancement on the nexusmods website (link) and included your G_Work_Around UI API v0.10.

Based on the feedback in this topic and the question of UniTrader, I hope this is alright. I did acknowledge you in the credits and provided a link to this topic for additional reference.
Thanks again for making this API! Finally, although I think you did great work, lets hope Egosoft eventually patches the _G=nil problem to smoothen the support for lua-based modding of the X4 ui.

Unclejack
Posts: 24
Joined: Wed, 5. Dec 18, 02:50
x4

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.11

Post by Unclejack » Tue, 8. Jan 19, 04:48

Hello Again!

I have an important update/message.
Running multiple mods using the G_Work_Around will lead to conflicts if the different mods use the same md template for the work around (with a wait of 1 second).
What happens is that multiple md functions will call G_Work_Around with a param at the exact same time/frame, this will prevent G_work_Around from functioning as it cannot find all params at the same time and thus will not open the targeted lua scripts (it will actually open the same one multiple times as it happens that was the value of param at that time). This can be easily fixed by changing the timing in the md scripts between mods, but this is something to keep in mind!

Currently it is a bit unclear if this happens only when the target lua scripts are targeting the same egosoft.lua script, but it seems to be 100% reproducible with 2 mods targeting the same menu_map.lua script.

Originally reported by Forleyor on discord!

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

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.11

Post by UniTrader » Tue, 8. Jan 19, 05:54

and i have an Improvement for this:
Add this md file to the G_ Workaround mod:
md/G_Work_Around.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<mdscript name="G_Work_Around" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
  <cues>
    <cue name="Root">
      <conditions>
        <check_any>
          <event_game_loaded/>
          <event_game_started/>
        </check_any>
      </conditions>
      <actions>
        <set_value name="$lua_files" exact="[]"/>
      </actions>
      <cues>
        <cue name="Signal" instantiate="true">
          <conditions>
            <event_cue_signalled/>
          </conditions>
          <actions>
            <append_to_list name="$lua_files" exact="event.param"/>
          </actions>
        </cue>
        <cue name="Lua_call" checktime="1s" checkinterval="0.1s">
          <conditions>
            <check_value value="$lua_files.count"/>
          </conditions>
          <actions>
            <open_menu menu="G_Work_Around" param="[0, 0, $lua_files.{1}]"/>
            <remove_value name="$lua_files.{1}"/>
            <reset_cue cue="this"/>
          </actions>
        </cue>
        <cue name="Reset">
          <delay exact="1min"/>
          <actions>
            <reset_cue cue="this.parent"/>
          </actions>
        </cue>
        <cue name="Reset_on_early_Save">
          <conditions>
            <check_any>
              <event_game_loaded/>
              <event_game_started/>
            </check_any>
          </conditions>
          <actions>
            <reset_cue cue="this.parent"/>
            <force_cue cue="this.parent"/>
          </actions>
        </cue>
      </cues>
    </cue>
  </cues>
</mdscript>
and modify the call this way:
<signal_cue_instantly cue="md.G_Work_Around.Signal" param="'.\\extensions\\ut_advanced_renaming\\utrenaming.lua'"/>
All calls will be forwarded to lua with a 0.1s time difference (i think it even ensures a time difference of at least 1 frame because of the behavior of md)
This way its even possible to make multiple calls right one after another in the same cue. its then spread out.
Signals are accepted for 1 minute after Game Start/Load because i dislike having constant polling in the background going on for a value thats extremely unlikely to change. This should be enough to register everything and set up own lua cally if needed. The old call still works as before, my script is just in-between to spread out the simulteneous calls.
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 ;)

morbideth
Posts: 389
Joined: Sun, 9. Nov 08, 04:07
x3tc

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.11

Post by morbideth » Tue, 8. Jan 19, 09:14

UniTrader wrote:
Tue, 8. Jan 19, 05:54
and i have an Improvement for this:
Add this md file to the G_ Workaround mod:
md/G_Work_Around.xml
v0.20 Updated to include the above, thanks UniTrader. I've also included some debugging tools to help with writing UI mods. You can find more info in the 2nd post of this thread.

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

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by UniTrader » Tue, 8. Jan 19, 10:55

you should also mentoin the dependency node for the content.xml to ensure mod presence and version and load order ;)

Code: Select all

<content id=......>
 <dependency id="G_Work_Around" version="020" optional="false"/>
 <text language=..../>
</content>
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 ;)

alexringess
Posts: 40
Joined: Tue, 25. Sep 18, 23:57
x4

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.11

Post by alexringess » Tue, 8. Jan 19, 12:41

Unclejack wrote:
Tue, 8. Jan 19, 04:48
Hello Again!

I have an important update/message.
Running multiple mods using the G_Work_Around will lead to conflicts if the different mods use the same md template for the work around (with a wait of 1 second).
What happens is that multiple md functions will call G_Work_Around with a param at the exact same time/frame, this will prevent G_work_Around from functioning as it cannot find all params at the same time and thus will not open the targeted lua scripts (it will actually open the same one multiple times as it happens that was the value of param at that time). This can be easily fixed by changing the timing in the md scripts between mods, but this is something to keep in mind!

Currently it is a bit unclear if this happens only when the target lua scripts are targeting the same egosoft.lua script, but it seems to be 100% reproducible with 2 mods targeting the same menu_map.lua script.

Originally reported by Forleyor on discord!
You are making things more complicated than other things.
First, on the nexus page of your mod, it's difficult to know what downloading because you putted exactly the same warning on both version (with G_Workaround and without).
Second, you changed the folder name of your latest version so it's impossible to know if it's an upgrade or a substitution.
And finaly, IMO, I think it's better to simply give the link to the G_Workaround_UI_API on your mod, mentionning clearly that it is a dependancy of your mod, a requierement, and don't providing it on your own mod.
Usualy, when developpers use APIs, they provide the API separately, or publish a link to this API for the end users, and have to upgrade their software/mod/script when the API is upgraded.

morbideth
Posts: 389
Joined: Sun, 9. Nov 08, 04:07
x3tc

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by morbideth » Tue, 8. Jan 19, 12:52

UniTrader wrote:
Tue, 8. Jan 19, 10:55
you should also mentoin the dependency node for the content.xml to ensure mod presence and version and load order ;)

Code: Select all

<content id=......>
 <dependency id="G_Work_Around" version="020" optional="false"/>
 <text language=..../>
</content>
Didn't know there was such a thing, prolly hidden in the X:R documentation. I'll try and squeeze it in, near the text limit. Edit: it fit, I'll put a content.xml file in the templet next update.

Unclejack
Posts: 24
Joined: Wed, 5. Dec 18, 02:50
x4

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by Unclejack » Tue, 8. Jan 19, 17:15

@Alexringess
I don't fully understand what you mean when mentioning both downloads have the same description/name. They never had the same name or description, this was also true for the original upload of the files:

Code: Select all

UJfactionspecific_objectcolours
UJfactionspecific_objectcolours_withG_Work_Around
EHM3_factionObj_and_Sect_Colours
EHM3_factionObj_and_Sect_Colours_withG_Work_Around
Although the descriptive sentences clearly differ in the with and without, I agree this might be improved.
Then, I agree with you that including the API is maybe not the best course of action and I agree that it would be best to refer to an API independently. However, the API is not "officially" released on the Nexusmods (or anywhere else afaik) and I do not really wish to force people to the Egosoft Forums to download this mod in this early stage of X4 modding. First it is not very user-friendly, second, although Morbideth is doing great and I like these forums, some people might not understand completely what is happening when coming to this specific, highly technical, post on an unknown forum for the first time. Although the download link is at the bottom of the post, it is not as clear as the Nexusmod layout, it also does not download the file, it actually is a mirror to a mediafire archive which does not download automatically either (luckily you do not need an forum account to use the download link). Thirdly, this topic is a development topic/guide with a not so (imo) user-friendly title and will change rapidly over time, for instance, the UI api is now updated to v0.2 and although this is great, it could have been uncompatible with my current files on the Nexusmods. So currently, I prefered to package them together as it can guarantee it will at least work when downloading and installing it fresh. Of course I will try to keep updating it as the UI api is updated and keep up with this great workaround, but I also have to work and cannot update the nexusmods page every hour, especially if the UI api itself is rapidly changing and not "officially" released. Once the API is a bit more stable and widely used (or officially user released), or once the modding scene has gone forward, I will remove the UI API packaged with the mod, but for now I wished to include it. If you still feel you do not like my way of releasing the mod or if you have other problems, feel free to provide additional feedback in Discord, with a PM or on the Nexusmod page.

Finally, the reported problem is actually not specific to my personal Nexusmod release or preference for releasing files. The problem reported by Forleyor, as i see it, is a general compatibility problem that would have happened with every lua script out there. Although i am not a professional scripter, I also feel it is my duty to help and suppport this api's development as much as i can as one of its users. I fail to see how this is making things more complicated than necessary in general.

LegionOfOne
Posts: 122
Joined: Sun, 16. Dec 18, 14:16
x4

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by LegionOfOne » Tue, 8. Jan 19, 19:09

Does anyone among you fine folks know how to create our own ffi functions, and where the original ones are located ?

I'm trying to add a new functionnality, specifically to allow us to choose the volume of every buy or sell offer on our stations.
Since that simply doesn't exist yet, I believe I need to create my own ffi functions to handle the logic.

If you can think of another path to the same result, that would also be very helpful.

Thanks in advance !

morbideth
Posts: 389
Joined: Sun, 9. Nov 08, 04:07
x3tc

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by morbideth » Tue, 8. Jan 19, 20:26

LegionOfOne wrote:
Tue, 8. Jan 19, 19:09
Does anyone among you fine folks know how to create our own ffi functions, and where the original ones are located ?

I'm trying to add a new functionnality, specifically to allow us to choose the volume of every buy or sell offer on our stations.
Since that simply doesn't exist yet, I believe I need to create my own ffi functions to handle the logic.

If you can think of another path to the same result, that would also be very helpful.

Thanks in advance !
Um, yeah, you can't write your own ffi function... those are defined by the devs. You would need access to the source code to add them (or I guess you could try decompling the game or modding in assembly :gruebel:)


I think cargo.{$ware}.target might do what you wish. See scriptproperties.html for more info.

SetContainerWareIsBuyable, SetContainerWareIsSellable, SetContainerStockLimitOverride, and SetContainerWarePriceOverride are also options. The UI documentation is here

MD scripts may also be an option.

LegionOfOne
Posts: 122
Joined: Sun, 16. Dec 18, 14:16
x4

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by LegionOfOne » Tue, 8. Jan 19, 20:35

Thanks a lot for your answer, that was very helpful and detailed.
I won't waste any more time on trying to mod my ffi functions thanks to you, and I have a few good hints to follow. It's exactly what I needed.

DeadMor0z
Posts: 26
Joined: Fri, 29. Nov 13, 19:20
x4

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by DeadMor0z » Tue, 8. Jan 19, 22:55

What do you think about using (md) <raise_lua_event name="'EventName'" param="'path_to_lua_file'"/> and (lua) RegisterEvent("EventName", eventCallBack) variant, rather than open_menu?
Events should be queued by default, so there will be no problem with multiple extensions raising event. And it will make workaround code much simplier.

morbideth
Posts: 389
Joined: Sun, 9. Nov 08, 04:07
x3tc

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by morbideth » Wed, 9. Jan 19, 04:18

DeadMor0z wrote:
Tue, 8. Jan 19, 22:55
What do you think about using (md) <raise_lua_event name="'EventName'" param="'path_to_lua_file'"/> and (lua) RegisterEvent("EventName", eventCallBack) variant, rather than open_menu?
Events should be queued by default, so there will be no problem with multiple extensions raising event. And it will make workaround code much simplier.
It's an idea. I haven't looked at those yet. If it works it would get rid of all of the debug spam from opening an empty menu, which would make it worth doing. Going to be a while before I can look into this, unless someone else already has.

DeadMor0z
Posts: 26
Joined: Fri, 29. Nov 13, 19:20
x4

Re: [API/GUIDE] How to mod the UI (_G Workaround and Right Click API) v0.20

Post by DeadMor0z » Wed, 9. Jan 19, 05:39

morbideth wrote:
Wed, 9. Jan 19, 04:18
DeadMor0z wrote:
Tue, 8. Jan 19, 22:55
What do you think about using (md) <raise_lua_event name="'EventName'" param="'path_to_lua_file'"/> and (lua) RegisterEvent("EventName", eventCallBack) variant, rather than open_menu?
Events should be queued by default, so there will be no problem with multiple extensions raising event. And it will make workaround code much simplier.
It's an idea. I haven't looked at those yet. If it works it would get rid of all of the debug spam from opening an empty menu, which would make it worth doing. Going to be a while before I can look into this, unless someone else already has.
I used this technique to pass data back to lua code from md script in my mod - works great.

EDIT: Rewrited latest API to use raise_lua_event and RegisterEvent, checked - all done well. You can get and check it from here:

MUST BE INSTALLED IN YOUR %installdir%\extensions folder! REQUIRES: basic literacy to install.
v0.30 Right Click API, _G Work Around, Modding Templet, and Debugging Tools
Image

Post Reply

Return to “X4: Foundations - Scripts and Modding”