Page 1 of 1
Custom entity tooltips?
Posted: Tue Jan 09, 2018 2:54 am
by Reika
Or "right hand/info panel" or whatever you want to call it. Basically I have a simple entity which contains no data in and of itself, but has data corresponding to it in the global table, and want the tooltip to display that info.
Is this possible?
Basically I want to show the liquid level (as well as emission per cycle) in the right panel for this entity:

Re: Custom entity tooltips?
Posted: Tue Jan 09, 2018 11:27 am
by 321freddy
Since you cannot edit the basegames GUIs you have to rely on a workaround.
The only one I know of which would come very close to what you want only works for entities which support custom backer names:
Basically you add a newline to the backer name of the entitiy and add your text there:
Code: Select all
player.selected.backer_name = player.selected.backer_name .. "\r\n<your data goes here>"
Results in something like this:
If your entitiy does not support backer names the you'd have to create your own gui inside the on_selected_entity_changed and put your data in there.
Or display a flying text entity.
Using your own gui gives you way more flexibility but is a bit detached from the base game gui. I did it like this in my attach notes mod:

I can provide code examples for this if you want.
Re: Custom entity tooltips?
Posted: Tue Jan 09, 2018 9:20 pm
by Reika
321freddy wrote:Since you cannot edit the basegames GUIs you have to rely on a workaround.
The only one I know of which would come very close to what you want only works for entities which support custom backer names:
Basically you add a newline to the backer name of the entitiy and add your text there:
Code: Select all
player.selected.backer_name = player.selected.backer_name .. "\r\n<your data goes here>"
Results in something like this:
If your entitiy does not support backer names the you'd have to create your own gui inside the on_selected_entity_changed and put your data in there.
Or display a flying text entity.
Using your own gui gives you way more flexibility but is a bit detached from the base game gui. I did it like this in my attach notes mod:
I can provide code examples for this if you want.
Since spilled fluid is a simple entity and does not support backer names, can you show me a sample of the custom GUI code? I have never done anything like that before.
Re: Custom entity tooltips?
Posted: Tue Jan 09, 2018 9:59 pm
by darkfrei
Reika wrote:can you show me a sample of the custom GUI code? I have never done anything like that before.
viewtopic.php?f=25&t=56317
Re: Custom entity tooltips?
Posted: Wed Jan 10, 2018 12:37 am
by Reika
It seems that the only way to remove gui elements is to iterate the parent's entire contents, since the "children" array is index, not name based.
Since this is only called on selected entity change, is there a way to update this in realtime, performantly (ie without iterating across all players' entire gui contents each tick)?
Also, even that has issues, as if there are multiple spills, only one of which is being selected, the GUI elements to be updated cannot have identifiers so that the tick-based code can know which object the GUI element corresponds to.
Re: Custom entity tooltips?
Posted: Wed Jan 10, 2018 2:11 am
by eradicator
Simple.
Create a gui element player.left (or top) and store the reference
Code: Select all
global[playerindex].mytooltip = player.gui.left.add{stuff/frame}.add{stuff/label}
in on_selected_entity_changed watch for your entities name, if your spill is selected start a dynamic tick handler.
In the tick handler just:
Code: Select all
mytooltip.mylabel.text = fetch_my_data(generate_identifier(player.selected))
When the player unselected the spill stop the tick handler.
Not sure if simple-entity has a unit_number property, so you might have to generate a UID based on the position coordinates. Also be aware that you get no control over where on the screen that tooltip is placed. It all depends on what other mods that add gui elements are loaded before yours.
(Dynamically starting/stopping the tick handler is obviously done for performance reasons only, to not waste cpu when unnessecary)
Re: Custom entity tooltips?
Posted: Wed Jan 10, 2018 2:29 am
by Reika
eradicator wrote:Simple.
Create a gui element player.left (or top) and store the reference
Code: Select all
global[playerindex].mytooltip = player.gui.left.add{stuff/frame}.add{stuff/label}
in on_selected_entity_changed watch for your entities name, if your spill is selected start a dynamic tick handler.
In the tick handler just:
Code: Select all
mytooltip.mylabel.text = fetch_my_data(generate_identifier(player.selected))
When the player unselected the spill stop the tick handler.
Not sure if simple-entity has a unit_number property, so you might have to generate a UID based on the position coordinates. Also be aware that you get no control over where on the screen that tooltip is placed. It all depends on what other mods that add gui elements are loaded before yours.
(Dynamically starting/stopping the tick handler is obviously done for performance reasons only, to not waste cpu when unnessecary)
These entities already have a tickhandler, so I can plug it into that. I also already have UIDs based on coordinates, for exactly this ability.