-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI Plugins #5872
UI Plugins #5872
Conversation
Puuuhhh 😃 The example addon you gave looks a bit, hm, crazy? I understand the most but can you explain what this syntax means:
I mean the I will play around with this, but may take some time. |
That's just a string literal, exactly like -- All of the following are equivalent:
[[Hello World]]
[=[Hello World]=]
[==[Hello World]==]
-- And this is not:
[===[Hello World]==] -- this is not the correct closing string delimiter, so everything (including this comment) is still part of the string! --- here's to finally close it: ]===] -- This comment is not part of the string. Another way to handle the situation that does not require writing entire functions as strings would be to put each callback into a separate file and simplify the callbacks as just on_click = [[ include("addons/addon_name.wad/toolbar_callback.lua") ]], |
Thanks :-)
I can't get this to work, nothings happens if i try to make it like so. Here is my auto_mountains.wad (just adapted your addon and exchanged the main function): editor_auto_mountains.zip The contained file auto_height.lua does not work with your suggestion (don't be confused about the function I am also not able to create a window with a textbox and yes-no buttons 🥲 If i try that i get always an error
although i have tried to make it as simple as i can and check all parenthesis and commas i can't get rid of this error. Another question about the value for widelands/src/scripting/lua_ui.cc Lines 382 to 383 in 13f3dd8
Instead of having each tool as a button in the main menu of the editor i think it would be better to have an extra dropdown for add-on tools. Ideally not shown, or disabled, if no add-on tools are installed. If you click several times of an addon entry in the main menu, on each click a new window is created covering the previously opened window. This should be prevented. |
Oh, stupid me :-) That's the reason why i always need some time. How can i determine which button a user has clicked on? Or is this also for a later branch?
Good to know, thanks.
Maybe a misunderstanding: I don't meant to add dropdowns for add-on windows, i meant a dropdown for the editors main menu which contains all add-on ui-plugins. Similar to the Tools menu.
Ah, thanks again. |
Each button has its own
No that's the same case. Adding new entries to an existing dropdown is equally hard. Also, UI plugins have a lot of flexibility since they can edit arbitrary aspects of the GUI; I don't want to restrict the functionality to allow only a handful of dropdown entries and nothing else as plugin entry points. |
Will it be possible to have some sort of templates for ui-plugins? E.g. a yes_no template which contains a textbox and two buttons and one can do something like:
Something along that would make the handling much easier. And i think such templates can cover most of the use cases. |
Hm… we have one such C++ UI element, the WLMessageBox – a simple modal window with a multiline textarea and an OK button and optionally a Cancel button. Would exposing this to Lua be sufficient for most such cases I think? If we really need more complicated templates that will actually be used by many add-ons, that can be done too, but I'd consider this lower priority than getting all the basic UI widget types createable and – very important, and currently only rudimentarily supported – allowing scripts to access them and change their properties later. What sort of templates would you need? |
Think of the fourth empire campaign where the player has to decide to attack Vesta or to deliver some wine. Here a simple yes/no template would be fine. A Yes/No template would be one of the most used, i guess, because simple decisions can be made as a question which only can be answered with yes or no. And in general like described in #2117 , e.g. a mutiline optionbox to make it possible to make some sort of conversation with different possible answers: Protagonist: "Hey, nice to meet you!"
Depending on the players choice, a scenario can act different. Either start a conversation with the protagonist or not. For the editor i think having just a OK-template is enough. More difficult things can be implemented later, or if (ever) needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question and suggestions to improve the example with comments.
From my side this is good to go now :-) |
Instead of of using checkboxes one can also create a window with buttons to achieve a multi-answer approach. I have tried that, but it fails with
Any advice? The scenario: test_UI-Plugin.zip |
Lua function call syntax: |
Always the same stupid mistakes, thanks a lot! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone through lua_ui.cc
once, and it looks OK, but I want to double-check against the docs.
Meanwhile some minor comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I only tested with your attached add-on, otherwise I rely on @frankystone's earlier testing.
The generic get_table_{string,int,boolean}
functions could be moved to lua.{cc,h}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't realise they needed another header.
Thanks for the review :) |
Type of change
New feature
Issue(s) closed
Fixes #4801 (at least partially, but more features can be added by and by)
Closes #2117 since there's no reason why it couldn't be used in scenario scripting as well
How it works
Plugins are a new type of add-on that allow creating arbitrary UI components as children of existing components. These work both in the editor and in-game.
Possible regressions
N/A
Screenshots
Additional context
This is a pretty small-ish baseplate. It supports a handful of basic UI widgets and callback events. That's quite enough to write, for example, the attached sample add-on which exchanges two hardcoded terrain types with each other. editor_swap_terrains.wad.zip
It does not support more advanced window components, such as Dropdowns, ListSelects, Editboxes, and, well, most sorts of components actually. So far we have only Windows, Boxes, Buttons, and single-line Textareas.
Note that there are quite some pitfalls when scripting such a plugin. Both in the windowing system – the frontend is actually quite nice to use compared to C++, except for the callbacks, but layouting a complex window properly is a headache no matter what the frontend looks like. And the callbacks – since the Lua context may be deleted during the lifetime of a toolbar button, we can't reuse custom variables or functions, everything has to be a raw string. Read the attached add-on to see what I mean.
The attached add-on is meant to be enabled only in the editor. Comment out the first line to get it in-game as well, but beware – it will desync in replays/MP the moment you use it.