api.gui How to view/examine GUI layout structure / contents?

Willkommen in der Transport Fever Community

Wir begrüßen euch in der Fan-Community zu den Spielen Transport Fever und Train Fever, den Wirtschaftssimulatoren von Urban Games. Die Community steht euch kostenlos zur Verfügung damit ihr euch über das Spiel austauschen und informieren könnt. Wir pflegen hier einen freundlichen und sachlichen Umgang untereinander und unser Team steht euch in allen Fragen gerne beiseite.

 

Die Registrierung und Nutzung ist selbstverständlich kostenlos.

 

Wir wünschen euch viel Spaß und hoffen auf rege Beteiligung.

Das Team der Transport-Fever Community


  • Hi, how can I view the structure and contents of a GUI layout such as a window?


    I can access a window layout using api.gui.util.getById(id), and I can add elements to it using :getContent() :getItem() :getLayout() :getTab() etc, but how to do view the structure and contents already in the layout?


    When I try :getContent() etc, I get a screenful of "generic" results that appear to be a list of the class member functions, but I see no specific info for the actual object entity (or subclass) that I am examining. For example for this Line window, it doesn't show how many items are in the layout, what is in those items, how many tabs, what components, etc. How do I view that structure?


  • CommonAPI2 inspector window has a tab for selecting UI Elements and getting access.

    Note: Special Window elements are not accessible by lua API.


    In the UG console you can use:


    interface = require("commonapi2.uicommon.interface")

    interface.inspect(interface._getRoot(), "filename.txt", true)


    To get a dump filename.txt of the all elements.

    Note: CommonAPI2 provides access to internals of UI Elements you can't reach. So you will get more info then UG offers and beware the file produced is huge...


    interface.inspect( uielement, filename, diffable)

  • Hi, ty for reply. (Sorry I did not have notifications turned on so did not see it earlier 🤦‍♂️)


    I do not have CommonAPI2, only the base game API.


    After days (wasted) of experimenting, I learned that the "structure" that I want to see is not accessible in the API. There is no single "table" that shows the structure and elements of GUI windows. Instead we have to probe it level by level, bit by bit, checking each element. 😵‍💫


    If I had any knowledge about OOP I probably would have known this already, that the game API does not give "free" access to the GUI layout data all at once, and instead we can only probe small pieces of it using the class functions. It was very difficult to learn because I have no OOP knowledge/experience. (Edit: And also because the API ref site is very confusing and often not very informative, especially if someone is not a software developer.)


    So I learned that the "screenful of functions" I mentioned above are actually the only way to examine each GUI element. And those functions give very little clues so we have to guess a lot and have some fore-knowledge about the window layout. It's a very tedious process... 🥴 The functions :getName() and :getNumItems() are probably the two most useful ones.


    Eventually I made progress and finished that mod. Now starting a different one. A hard experience but now I feel at least 12% knowledgeable haha 🫠

  • Well, if you have a text file of the whole tree (including ids and name) it is much easier to development. Or selecting an element in the ui and finding a element with id around it.


    There is a reason why I have build such tools for myself and offer them...

  • Well, if you have a text file of the whole tree (including ids and name) it is much easier to development. Or selecting an element in the ui and finding a element with id around it.


    There is a reason why I have build such tools for myself and offer them...

    I know. This is what I thought the api.gui provided, similar to results pulled from api.res tables. But nope.


    Unfortunately can't require custom APIs when supporting mods across the entire playerbase and all platforms. These features really need to be in the vanilla API. I'm hoping there is improvement in TpF3 (but I'm also not holding my breath).

  • You should use the knowledge and CommonAPI2 as development tool and then write you mod with the official apis...


    Example created with inspect of commonapi2.uicommon.interface

    interface = require("commonapi2.uicommon.interface")

    interface.inspect( element, "filename.txt", true)