Custom "operate" UI for Entities

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
zx64
Long Handed Inserter
Long Handed Inserter
Posts: 58
Joined: Fri Dec 16, 2016 3:57 pm
Contact:

Custom "operate" UI for Entities

Post 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. :-)

User avatar
Sirenfal
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 10, 2017 1:42 am
Contact:

Re: Custom "operate" UI for Entities

Post 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

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Custom "operate" UI for Entities

Post 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
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
Earendel
Factorio Staff
Factorio Staff
Posts: 711
Joined: Sun Nov 23, 2014 11:57 am
Contact:

Re: Custom "operate" UI for Entities

Post by Earendel »

+1

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Custom "operate" UI for Entities

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13149
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Custom "operate" UI for Entities

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Custom "operate" UI for Entities

Post 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. :(

ravenbs
Inserter
Inserter
Posts: 49
Joined: Wed Jun 13, 2018 11:07 am
Contact:

Re: Custom "operate" UI for Entities

Post 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?

ravenbs
Inserter
Inserter
Posts: 49
Joined: Wed Jun 13, 2018 11:07 am
Contact:

Re: Custom "operate" UI for Entities

Post 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
	....

Post Reply

Return to “Modding interface requests”