Page 1 of 1

Custom "operate" UI for Entities

Posted: Tue Jan 17, 2017 12:55 am
by zx64
Idea is to allow mods to define their own interfaces when a player clicks on modded entities, rather than having to clutter up the player's top level UI.

Off the top of my head, something like this in data.lua:

Code: Select all

data:extend({ .... operate_ui = "my_entity_ui" })
And then define the function in control.lua:

Code: Select all

function my_entity_ui(window, player, entity)
-- window is a LuaGuiElement object like player.gui.top etc.
end
Some sort of LuaEntity.set_operate_ui might be useful for niche stuff but I imagine most uses will be fine sharing the same callback between all instances of an entity.

I went with "operate" in these examples to match the existing property related to whether you can interact with an entity.
I'd rather see if the idea is at all viable before spending too much time thinking of good names. :-)

Re: Custom "operate" UI for Entities

Posted: Sat Jan 21, 2017 1:20 pm
by Sirenfal
+1. I could use this for a lot of stuff, and I've seen a lot of mods that could benefit from this too.

EDIT: Come to think of it, one of Rseding's own mods could benefit from this :P viewtopic.php?f=14&t=6862

Re: Custom "operate" UI for Entities

Posted: Wed Feb 01, 2017 9:58 pm
by aubergine18
+1

Would love this feature. Currently we have to do a bit of crazy stuff, primarily checking every few ticks to see if player has opened an entity or selected one, and even then we can't remove the default UI for our custom entities. An alternate is to define custom-input and when triggered check to see if player has hovered/selected an entity, but it's weird having to use keyboard shortcut just to open custom UI for custom entity.

Instead of naming the prototype property "operate_ui", I'd suggest something like "event_entity_open".

When the property is defined in the prototype, the default UI would not appear when clicking an entity - game would assume the mod will listen for the named event and display its own UI.

In terms of closing the UI, that would need some extra thought - ideally we'd want the UI to be closable in the same ways as vanilla entity UI (eg. walking away from it, clicking another entity and so on). One way this could potentially be achieved is if the game is responsible for creating the outer GUI container and passing a handle to it via the event object - the mod would then create it's GUI elements within that container (I'm not sure how the outer container would scale to the right size though - I assume we could just set a relevant .style?).

I really hope something like this can be implemented for 0.15.

Related: viewtopic.php?f=28&t=35452

Re: Custom "operate" UI for Entities

Posted: Thu Apr 27, 2017 10:32 pm
by Earendel
+1

Re: Custom "operate" UI for Entities

Posted: Fri Apr 28, 2017 7:50 pm
by Mooncat
Has anyone realized that if we can really put our function names in prototypes, it will be a big game changer with many usages? :P

For example, you can define custom ruleset for selection-tools to select objects. You can also define conditional functions for combinators to decide when to transmit signal and the value. Maybe even custom ruleset for AoE to select targets.
And then this can lead to event system overhaul, where you define your on_player_built_entity, on_entity_died, etc to your own entity prototypes. No more broadcast -> better performance -> on_entity_damaged will be possible? 8-)

But I think the function name should include mod ID, so the game can find the exact function from the sea of installed mods.

Re: Custom "operate" UI for Entities

Posted: Fri Apr 28, 2017 8:18 pm
by Rseding91
Mooncat wrote:Has anyone realized that if we can really put our function names in prototypes, it will be a big game changer with many usages? :P

For example, you can define custom ruleset for selection-tools to select objects. You can also define conditional functions for combinators to decide when to transmit signal and the value. Maybe even custom ruleset for AoE to select targets.
And then this can lead to event system overhaul, where you define your on_player_built_entity, on_entity_died, etc to your own entity prototypes. No more broadcast -> better performance -> on_entity_damaged will be possible? 8-)

But I think the function name should include mod ID, so the game can find the exact function from the sea of installed mods.
That's probably never going to happen. That would add a *massive* overhead to every normal game operation having to store, lookup, call, handle errors, and so on for every single operation that something does.

Re: Custom "operate" UI for Entities

Posted: Sat Apr 29, 2017 7:46 am
by Mooncat
Rseding91 wrote:That's probably never going to happen. That would add a *massive* overhead to every normal game operation having to store, lookup, call, handle errors, and so on for every single operation that something does.
Ah... Forgot that LUA is not a compiled language. :(

Re: Custom "operate" UI for Entities

Posted: Tue Jun 09, 2020 2:46 pm
by ravenbs
When you search with Google for "Add custom GUI to Factorio entity" - you find this thread.

... But it is not the solution and implemented in a different way....
So - who can point me to how a custom GUI for a enety is done - instead of this here?

Re: Custom "operate" UI for Entities

Posted: Tue Jun 09, 2020 5:13 pm
by ravenbs
Found a solution - dont know if it is the official one, but I like to share it for all other google users finding this:

Its simple:
Listen to the event "GUI Opened" and open your own one if it is the gui you want:

Code: Select all

script.on_event(
	defines.events.on_gui_opened,
	function(event)		
	if event.entity not nil and string.match(event.entity.name, "yourMachineName") then
	....