Page 1 of 1

on_entity_clicked

Posted: Sun Oct 30, 2016 2:53 pm
by aubergine18
Doing custom GUI for an entity is a PITA.

There are two approaches currently available, both of which suck:

custom-input

This is useful if we need to retain existing gui, but want optional alternative gui. We define custom-input keyboard shortcut, and when its event is triggered, we check game.players[event.player_index].selected to see if it's applicable entity and if so show the GUI.

.opened

We can check player.opened every so often (putting more stuff in on_tick is good for performance, compared to events), and if its not nil check to see if the opened entity is something we are interested in and then show our custom GUI. As far as I know there's no way to hide the vanilla GUI for the entity though.

If we set entity.operable = false for the entity, it will stop vanilla GUI opening but then as far as I know the player.opened will never get set because the player can't "open" the entity.

Proposed solution

When an entity is clicked, trigger an on_entity_clicked event, with the entity as a property of the event table.

This way we could set .operable = false, to prevent default GUI, and use the evnet to trigger our GUI.

While our GUI is open, we can check player proximity to the entity (again, via on_tick, because that's good for performance compared to events) and if they get too far away we can close the GUI (It would be nice to have that event driven also, but not sure if it would be feasible to implement - the game can and does already do it for vanilla entities, but I imagine that an event to allow mods to do the same would impact performance).

As for manual closing of our GUI, we'd likely need to create a custom-input, or put a little X button on the GUI to close it with mouse click. As far as I know the standard ways of closing GUI are not going to be available to mods (they are reserved for vanilla GUI) so we have to provide alternate user interaction for modded GUIs. Different interaction models for vanilla and modded GUI are good UX design.

Re: on_entity_clicked

Posted: Sun Oct 30, 2016 4:28 pm
by Mooncat
hm... it reminds me of this: viewtopic.php?f=28&t=24669
But I know they are different.

I wonder if on_entity_clicked will be useful, because, in your case, the clicked entity is inoperable, the player can click another entity to open its GUI (assuming this 2nd entity is not controlled by your mod), thus your GUI and the vanilla GUI of that entity is overlapped. To solve this problem, you will still need to check player.opened. :?

Re: on_entity_clicked

Posted: Tue Nov 08, 2016 9:11 pm
by apriori
I'm in! Vote for on_entity_clicked event!
Now I'm trying to realize "custom gui" for entities, and the only way to do that (which I use) is by hovering a mouse over an entity for some time. on_entity_clicked would be VERY HELPFUL!