How do GUIs events for custom/no-core entities work?

Place to get help with not working mods / modding interface.
Post Reply
8mobius8
Manual Inserter
Manual Inserter
Posts: 3
Joined: Wed Oct 23, 2019 7:26 pm
Contact:

How do GUIs events for custom/no-core entities work?

Post by 8mobius8 » Fri Nov 08, 2019 8:24 pm

I need some help understanding best way for opening GUIs on player from left clicking on custom or non-core entities in game. I would like to understand breadth here but let me start with a specific example.

Currently writing a mod that allows a entity to record Signals that are on it's logistical network, but I want to be able to configure which signals it records based on what a player selects in a GUI. Much like the constant combinator gui. User left clicks on entity, GUI opens with 'Signal Recorder' title and lots of Signal selectors are available to be selected. After it closes, 'Signal Recorder' entity will write to file every 50 ticks or so.

K, so my problem: I tried to extend the `Radar` entity but it doesn't react to the `on_gui_open` or `on_gui_closed` events.

In general, is there a set prototypes that only trigger these events? Which prototype should I be using if so?

I am dumb, so feel free to send me threads that already answer this question if there are some. :lol: :?

Honktown
Fast Inserter
Fast Inserter
Posts: 185
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: How do GUIs events for custom/no-core entities work?

Post by Honktown » Sat Nov 09, 2019 12:44 am

Why not have a combinator before it that only lets one signal through? Not fancy enough for you?

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 1485
Joined: Fri Nov 06, 2015 7:41 pm

Re: How do GUIs events for custom/no-core entities work?

Post by Deadlock989 » Sat Nov 09, 2019 12:56 am

8mobius8 wrote:
Fri Nov 08, 2019 8:24 pm
I need some help understanding best way for opening GUIs on player from left clicking on custom or non-core entities in game. I would like to understand breadth here but let me start with a specific example.

Currently writing a mod that allows a entity to record Signals that are on it's logistical network, but I want to be able to configure which signals it records based on what a player selects in a GUI. Much like the constant combinator gui. User left clicks on entity, GUI opens with 'Signal Recorder' title and lots of Signal selectors are available to be selected. After it closes, 'Signal Recorder' entity will write to file every 50 ticks or so.

K, so my problem: I tried to extend the `Radar` entity but it doesn't react to the `on_gui_open` or `on_gui_closed` events.

In general, is there a set prototypes that only trigger these events? Which prototype should I be using if so?

I am dumb, so feel free to send me threads that already answer this question if there are some. :lol: :?
You can do it with a custom linked control. See viewtopic.php?f=28&t=74530.

8mobius8
Manual Inserter
Manual Inserter
Posts: 3
Joined: Wed Oct 23, 2019 7:26 pm
Contact:

Re: How do GUIs events for custom/no-core entities work?

Post by 8mobius8 » Sat Nov 09, 2019 2:31 am

Honktown wrote:
Sat Nov 09, 2019 12:44 am
Why not have a combinator before it that only lets one signal through? Not fancy enough for you?
haha yes it's not fancy enough. Need the mod to write data to a file inside the mod folder to be read by something other than Factorio game.
Deadlock989 wrote:
Sat Nov 09, 2019 12:56 am
8mobius8 wrote:
Fri Nov 08, 2019 8:24 pm
I need some help understanding best way for opening GUIs on player from left clicking on custom or non-core entities in game. I would like to understand breadth here but let me start with a specific example.

Currently writing a mod that allows a entity to record Signals that are on it's logistical network, but I want to be able to configure which signals it records based on what a player selects in a GUI. Much like the constant combinator gui. User left clicks on entity, GUI opens with 'Signal Recorder' title and lots of Signal selectors are available to be selected. After it closes, 'Signal Recorder' entity will write to file every 50 ticks or so.

K, so my problem: I tried to extend the `Radar` entity but it doesn't react to the `on_gui_open` or `on_gui_closed` events.

In general, is there a set prototypes that only trigger these events? Which prototype should I be using if so?

I am dumb, so feel free to send me threads that already answer this question if there are some. :lol: :?
You can do it with a custom linked control. See viewtopic.php?f=28&t=74530.
So I found this thread and it makes sense to `CustomInput` prototype from the act of clicking but now I am wondering how I am going to render it on the map. Seems like I would want to extend the `Entity` prototype so I can easily render the entity. Can I use both at the same time? How is this handled normally?

Honktown
Fast Inserter
Fast Inserter
Posts: 185
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: How do GUIs events for custom/no-core entities work?

Post by Honktown » Sat Nov 09, 2019 3:19 am

8mobius8 wrote:
Sat Nov 09, 2019 2:31 am
Honktown wrote:
Sat Nov 09, 2019 12:44 am
Why not have a combinator before it that only lets one signal through? Not fancy enough for you?
haha yes it's not fancy enough. Need the mod to write data to a file inside the mod folder to be read by something other than Factorio game.
I assumed you already had the signal writing finished, but it was grabbing all signals. If it has only one signal, it can only write one signal (I know about writing to the script output directory or whatever, unfortunately I don't know if Factorio can do more than that).

No idea about the other thing. Train stations draw custom map text (the station name).

8mobius8
Manual Inserter
Manual Inserter
Posts: 3
Joined: Wed Oct 23, 2019 7:26 pm
Contact:

Re: How do GUIs events for custom/no-core entities work?

Post by 8mobius8 » Sat Nov 09, 2019 4:33 am

Honktown wrote:
Sat Nov 09, 2019 3:19 am
8mobius8 wrote:
Sat Nov 09, 2019 2:31 am
Honktown wrote:
Sat Nov 09, 2019 12:44 am
Why not have a combinator before it that only lets one signal through? Not fancy enough for you?
haha yes it's not fancy enough. Need the mod to write data to a file inside the mod folder to be read by something other than Factorio game.
I assumed you already had the signal writing finished, but it was grabbing all signals. If it has only one signal, it can only write one signal (I know about writing to the script output directory or whatever, unfortunately I don't know if Factorio can do more than that).

No idea about the other thing. Train stations draw custom map text (the station name).
*forehead smack* After thinking about this much more I realize @Honktown is right wouldn't need to build the GUI for the constant combinator as it will work very well for my purpose for the time being. That is until I understand how to build GUIs hehe. Thanks Honktown.

I was still generally curious on how that linked_control works exactly but after reviewing more of the docs I think I understand. @Deadlock989 or anyone else correct me if I am wrong here we can pull up a GUI on a Left-mouse click on an entity by doing something like:

Code: Select all

-- [data.lua]
local mouse_click={
  type = "custom-input",
  name = "my-mod-mouse-left",
  key_sequence = "mouse-button-left",
  consuming = "game-only"
}
data:extend{mouse_click}

-- Should replace with custom entity instead of copying data.raw
local transmitter = table.deepcopy(data.raw["constant-combinator"]["constant-combinator"])
transmitter.name = "signal-recorder"



-- [control.lua]

function open_recorder_gui(player, signalrecorder)
  -- Do stuff to GUI and Signalrecorder
end

script.on_event("my-mod-mouse-left", function(event)
  local player = game.get_player(event.player)
  local pgui = player.gui
		
  local entity = player.selected
  if entity.name ~= "signal-recorder" then return end
  open_recorder_gui(player, entity)
end)
The Custom Input section on the Tutorial:Script_Interfaces help me put it all together, although the name of that page might need to change to include that content.

Thanks Honktown and Deadlock!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3740
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How do GUIs events for custom/no-core entities work?

Post by eradicator » Mon Nov 11, 2019 12:13 am

8mobius8 wrote:
Sat Nov 09, 2019 4:33 am

Code: Select all

-- [data.lua]
local mouse_click={
  type = "custom-input",
  name = "my-mod-mouse-left",
  key_sequence = "mouse-button-left",
  consuming = "game-only"
}

That is a custom hotkey, not a linked hotkey. The point of linking the control is that if the player changes the button (i.e. swap right/left mouse) your mod will automatically swap too. It also saves you the work of having to translate the menu entry.

https://wiki.factorio.com/Prototype/Cus ... me_control

Code: Select all

key_sequence = ""
linked_game_control = "open-gui"
consuming = nil
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users