Page 1 of 1
Apply built-in tooltips to custom GUI elements
Posted: Wed Nov 04, 2020 8:23 am
by PFQNiet
I have a custom GUI element that it would be nice to have an item tooltip on. Or a recipe tooltip. Or whatever vanilla tooltip may be best applicable to the use case.
Unfortunately it seems that the tooltip is limited to LocalisedString. It would be nice if we could have something like a TooltipSpecification, which can either be a LocalisedString or a TooltipPath like "item/iron-plate" to show the tooltip for the Iron Plate item.
The closest I can get to this goal is to use a choose-elem-button and set it to "locked". This gets the tooltip like I want, but it doesn't allow me to use "number" which is needed in my use-case.
Re: Apply built-in tooltips to custom GUI elements
Posted: Wed Nov 04, 2020 9:06 am
by Helfima
+1
when you use choose-elem-button the cost to add the button and lock can be significant. this to get the game tooltip
- choose-elem-button-cost.png (33.67 KiB) Viewed 3363 times
if you can have a button to get tooltip, it will be super
elem-button:
- elem_type :: string: The type of the button - one of the following values.
- item :: string (optional): If type is "item" - the default value for the button.
- tile :: string (optional): If type is "tile" - the default value for the button.
- entity :: string (optional): If type is "entity" - the default value for the button.
- signal :: SignalID (optional): If type is "signal" - the default value for the button.
- fluid :: string (optional): If type is "fluid" - the default value for the button.
- recipe :: string (optional): If type is "recipe" - the default value for the button.
- decorative :: string (optional): If type is "decorative" - the default value for the button.
- item-group :: string (optional): If type is "item-group" - the default value for the button.
- achievement :: string (optional): If type is "achievement" - the default value for the button.
- equipment :: string (optional): If type is "equipment" - the default value for the button.
- technology :: string (optional): If type is "technology" - the default value for the button.
Re: Apply built-in tooltips to custom GUI elements
Posted: Sat Nov 21, 2020 7:54 pm
by ixu
choose-elem-button-cost.png
Where can I get this easy-to-use-looking performance information from?
Re: Apply built-in tooltips to custom GUI elements
Posted: Sat Nov 21, 2020 8:10 pm
by Therenas
ixu wrote: ↑Sat Nov 21, 2020 7:54 pm
choose-elem-button-cost.png
Where can I get this easy-to-use-looking performance information from?
Jarg`s
Factorio Debugger has a profiling mode, it's super useful.
Re: Apply built-in tooltips to custom GUI elements
Posted: Sat Nov 21, 2020 10:50 pm
by Rseding91
I'd be interested in some code that shows the performance impact of creating and or setting locked on choose elem buttons. Because there's nothing inherently expensive about either of those so I suspect something else is going on.
Re: Apply built-in tooltips to custom GUI elements
Posted: Sun Nov 22, 2020 5:58 am
by Helfima
Hello Rseding91,
I did few tests, what surprises me is that the locked setting has a more important value than the creation.
the mod test
Press hotkey [K] in game to open/close test panel
recipes in vanilla:
- test_recipe_base.png (328.42 KiB) Viewed 3223 times
recipe in Pyanodon Mods (it just a test, i never want display all recipes)
- test_recipe_py.png (275.05 KiB) Viewed 3223 times
entity in Pyanodon Mods
- test_entity_py.png (386.54 KiB) Viewed 3223 times
saved game with Pyanodon Mods
Re: Apply built-in tooltips to custom GUI elements
Posted: Sun Nov 22, 2020 4:48 pm
by Rseding91
Ok, I profiled it and it's now fixed for the next release.
The issue was adding and setting the value 1 at a time.
* Every time a new widget is added to any GUI the "widget under mouse" is invalidated and the game flags it as such
* Every time 'locked' was set on one of the elements the game would 'update widget' for the choose elem button and as part of that it would check and remove the tooltip for the widget if the mouse was over it
* The way "widget under mouse" is found is to recursively go through the widgets on screen finding which one the mouse is inside of until the final widget is gotten
That meant the "add, set locked, repeat" would be doing a reclusive scan of the widgets on screen for each added element.
The tooltip logic removal was only meant to happen when changing the selected elem on the widget so I fixed it by only doing the tooltip removal logic when the selected elem changes instead of every time.
Now setting 'locked' takes basically zero CPU time (as it should). In the meantime you can fix it on your end by adding all the elements then iterating them and setting locked. Since setting locked doesn't invalidate the widget-under-mouse; adding/removing widgets does.
Re: Apply built-in tooltips to custom GUI elements
Posted: Sun Nov 22, 2020 8:30 pm
by PFQNiet
Glad this helped uncover a performance issue, but I still have my issue of wanting an item tooltip on my sprite-button (with number, so choose-elem-button is insufficient)
Re: Apply built-in tooltips to custom GUI elements
Posted: Mon Nov 23, 2020 12:54 am
by Helfima
Rseding91 wrote: ↑Sun Nov 22, 2020 4:48 pm
Ok, I profiled it and it's now fixed for the next release...
thx a lot
Re: Apply built-in tooltips to custom GUI elements
Posted: Mon Aug 05, 2024 9:25 pm
by curiosity
This has been implemented as LuaGuiElement.elem_tooltip