Apply built-in tooltips to custom GUI elements

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Apply built-in tooltips to custom GUI elements

Post 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.
Helfima
Fast Inserter
Fast Inserter
Posts: 200
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post 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
choose-elem-button-cost.png (33.67 KiB) Viewed 3420 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.
ixu
Fast Inserter
Fast Inserter
Posts: 107
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post by ixu »

choose-elem-button-cost.png
Where can I get this easy-to-use-looking performance information from?
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 249
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post 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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14280
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Helfima
Fast Inserter
Fast Inserter
Posts: 200
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post 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
test-choose-elem-button-cost.zip
(2.26 KiB) Downloaded 128 times

recipes in vanilla:
test_recipe_base.png
test_recipe_base.png (328.42 KiB) Viewed 3280 times

recipe in Pyanodon Mods (it just a test, i never want display all recipes)
test_recipe_py.png
test_recipe_py.png (275.05 KiB) Viewed 3280 times

entity in Pyanodon Mods
test_entity_py.png
test_entity_py.png (386.54 KiB) Viewed 3280 times
saved game with Pyanodon Mods
test_PY.zip
(4.85 MiB) Downloaded 138 times
Rseding91
Factorio Staff
Factorio Staff
Posts: 14280
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post 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.
If you want to get ahold of me I'm almost always on Discord.
PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post 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)
Helfima
Fast Inserter
Fast Inserter
Posts: 200
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post 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 :P
curiosity
Filter Inserter
Filter Inserter
Posts: 470
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Apply built-in tooltips to custom GUI elements

Post by curiosity »

This has been implemented as LuaGuiElement.elem_tooltip
Post Reply

Return to “Implemented mod requests”