Lua API for GUI

Everything about development and the OpenMW source code.
ptmikheev
Posts: 69
Joined: 01 Jun 2020, 21:05
Gitlab profile: https://gitlab.com/ptmikheev

Re: Lua API for GUI

Post by ptmikheev »

urm wrote: In this case, we have more or less the same limitations as tes3mp server-driven UI. That means that the parts of my tes3mp PR one could call hacky for OpenMW are not hacky at all :)
And what are the limitations? Currently I don't see any reasonable alternatives to this solution.
The choice between my PR (or something similar) - extending MyGUI and keeping XML layouts - and designing a completely new API is the same choice I've highlighted in the original post.
Just "designing a completely new API" is a too general idea to have a meaningful discussion. We need specific proposals and examples.

About the points from the original post:
1. Should we provide a layout declaration, or construct UI entirely in code?
In my proposal the layout is represented as a tree of Lua tables that is directly editable from code.
If we do have a layout, which features should it have? (e.g. only widget relations and style, like in MyGUI, or maybe registering events and property binds, like in my PR)
I would allow registering events - just by putting a function into layout. See an example in the post above.
Property binding seem less important.
2. Most mods would prefer to edit as little of the UI as possible (e.g. add new info to item popups), how can we offer that option?
3. Multiple mods editing the same UI should be as compatible as possible. An entirely different inventory UI (e. g. Skyrim-like lists with 3d item previews) should not necessarily appear any differently to other scripts interacting with it (e.g. ones that handle right click interactions on items).
4. We should probably provide simple functins similar to the MWScript ones, as many modders would probably still have a use for them.
5. Currently styling MyGUI layouts in vanilla style requires a decent amount of work and boilerplate. No matter which approach we pick, we should provide tools which make it easy.
These are important questions, but I think that they all should be handled on Lua side. I assume we will have a built-in Lua script that deals with raw UI models and provides a more high level interface to other scripts. And of course it will be possible to override such built-in script by a mod.
The C++ part of implementation can be relatively simple and just transfer data from Lua tables to MyGUI.
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Lua API for GUI

Post by urm »

ptmikheev wrote: 04 Apr 2021, 11:29 And what are the limitations? Currently I don't see any reasonable alternatives to this solution.
The similar part that we can't directly map MyGUI functions and be done with it. tes3mp also has network delay, which makes some UI designs impossible to do with code, which we don't have thankfully, as that would promote feature creep in terms of in-layout UI functionality.
ptmikheev wrote: In my proposal the layout is represented as a tree of Lua tables that is directly editable from code.
I'll clarify this for others, since we've also had a discussion in private. This idea is only worth it assuming we use the same table to update the UI afterwards. From the way this was worded, I've assumed they would only be used to generate the UI in the first place, which is not any better than allowing raw MyGUI XML input.
ptmikheev wrote: I would allow registering events - just by putting a function into layout. See an example in the post above.
Property binding seem less important.
Your proposal essentially has property binding already.
ptmikheev wrote: These are important questions, but I think that they all should be handled on Lua side. I assume we will have a built-in Lua script that deals with raw UI models and provides a more high level interface to other scripts. And of course it will be possible to override such built-in script by a mod.
The C++ part of implementation can be relatively simple and just transfer data from Lua tables to MyGUI.
I don't really agree with this. Especially number 5 is very much about how we design the API itself, and not about remaking existing UI into it.

Another thing that your suggestion doesn't cover, is creating new widgets. OpenMW codebase already has a few, although I'd want to largely rewrite them as a part of the new API, since there are many hardcoded things in them, which are specific to Morrowind. Ideally, we should also allow mods to create new widgets dynamically, since some functionality is hard to do without them.

One thing that's not clear to me at all is accessing widget's properties which are calculated during rendering. E. g. some elements might scale to their content, and their actual size in pixels isn't known ahead of time.
User avatar
psi29a
Posts: 5355
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: Lua API for GUI

Post by psi29a »

urm wrote: 06 Apr 2021, 19:41 Another thing that your suggestion doesn't cover, is creating new widgets. OpenMW codebase already has a few, although I'd want to largely rewrite them as a part of the new API, since there are many hardcoded things in them, which are specific to Morrowind. Ideally, we should also allow mods to create new widgets dynamically, since some functionality is hard to do without them.
I like where this is going, it will make things like MorroUI be an actual mod instead of a fork. Or coming up with an entirely different HUD that can be described else where. Even cheesing it up by adding a compass into Morrowind like in Daggerfall and Oblivion. :P
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Lua API for GUI

Post by urm »

psi29a wrote: 07 Apr 2021, 11:09 I like where this is going, it will make things like MorroUI be an actual mod instead of a fork. Or coming up with an entirely different HUD that can be described else where. Even cheesing it up by adding a compass into Morrowind like in Daggerfall and Oblivion. :P
Making things like MorroUI possible as mods is definitely a goal of this.
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Lua API for GUI

Post by urm »

I've started working on this, and have some decent progress: https://gitlab.com/uramer/openmw/-/comm ... 3cc56a1b22

Current features:
1. Render layouts in the form of Lua tables as MyGUI widgets
2. A custom container to store a widget's children, to allow access both by index and name
3. Registering UI event handlers by including them in the layout table
4. Implementation of a few events common to every MyGUI widget, which pass their arguments as a lua table
5. Widget types as an enum to allow for autocomplete

You can find the example scripts here: https://gitlab.com/uramer/openmw/-/tree ... ts/test_ui
clock.lua is a basic example which simply displays the playtime (press 'O', position is hard coded for 1080p). advanced.lua showcases all the features, but has a lot of implementation details (press "K", "M", "," and ".", click on the different rows with your mouse and drag them).

Remaining planned features:
1. Setting widget properties as appropriate Lua objects, instead of all of them being strings, as they are in MyGUI
2. Set position and size of child widgets in proportion to the parent, rather than only in absolute pixels
3. Decide whether there should be a way to read widget properties directly (they could be changed by the widget itself), or if a propertyChanged event is good enough
4. Either support MyGUI skins, or build an alternative system
5. Allow to create custom widget types and skins (maybe those should be the same thing?)
6. Prepare a minimal set of widgets to be exposed to the Lua API, with support for non-string properties and event arguments

Some time before 6 it would make sense to clean up the existing code of custom OpenMW widgets, but that should probably be a separate MR
Last edited by urm on 20 May 2021, 12:14, edited 1 time in total.
Lamoot
Posts: 176
Joined: 22 Apr 2016, 12:03

Re: Lua API for GUI

Post by Lamoot »

I'm not familiar with all specifics of this project, but does this mean all of the GUI will be defined with Lua and there won't be any .xml editing like with default MyGUI? I've spent some time recently editing those and it didn't fill me with joy.
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Lua API for GUI

Post by urm »

Lamoot wrote: 19 May 2021, 20:00 I'm not familiar with all specifics of this project, but does this mean all of the GUI will be defined with Lua and there won't be any .xml editing like with default MyGUI? I've spent some time recently editing those and it didn't fill me with joy.
Yep, no XML involved. I'm also trying to cover up all the buggy or weird functionality of MyGUI, so there should be a bit more joy involved in UI layouts.
Your current work on XML layouts should be relatively easy to transfer to the new system, although a direct transfer might be suboptimal (e. g. I plan to allow relative widget sizes, as opposed to everything being set in pixels).
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Lua API for GUI

Post by urm »

Point 1 done (only for the few widgets and properties which are present in examples).
https://gitlab.com/uramer/openmw/-/comm ... 1c8bdbaf82

Looking for feedback on the layout syntax, particularly the `props` part.
https://gitlab.com/uramer/openmw/-/blob ... /clock.lua
https://gitlab.com/uramer/openmw/-/blob ... vanced.lua
User avatar
wazabear
Posts: 96
Joined: 13 May 2020, 19:31
Gitlab profile: https://gitlab.com/glassmancody.info

Re: Lua API for GUI

Post by wazabear »

urm wrote: 20 May 2021, 08:49 Your current work on XML layouts should be relatively easy to transfer to the new system, although a direct transfer might be suboptimal (e. g. I plan to allow relative widget sizes, as opposed to everything being set in pixels).
What do you mean by this exactly, this is already how skin/layouts work with position/position_real. The layouts which exist already are just not designed the best since they heavily rely on per-pixel positioning (probably a consequence of trying to perfectly match vanilla design), but such behavior is certainly possible and probably how MyGUI is supposed to be used in first place.
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Lua API for GUI

Post by urm »

wazabear wrote: 20 May 2021, 19:15
urm wrote: 20 May 2021, 08:49 Your current work on XML layouts should be relatively easy to transfer to the new system, although a direct transfer might be suboptimal (e. g. I plan to allow relative widget sizes, as opposed to everything being set in pixels).
What do you mean by this exactly, this is already how skin/layouts work with position/position_real. The layouts which exist already are just not designed the best since they heavily rely on per-pixel positioning (probably a consequence of trying to perfectly match vanilla design), but such behavior is certainly possible and probably how MyGUI is supposed to be used in first place.
I don't see any built-in way to make a widget's width 30% of its parent's.
Post Reply