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.
How do GUIs events for custom/no-core entities work?
Re: How do GUIs events for custom/no-core entities work?
Why not have a combinator before it that only lets one signal through? Not fancy enough for you?
I have mods! I guess!
Link
Link
- Deadlock989
- Smart Inserter
- Posts: 2528
- Joined: Fri Nov 06, 2015 7:41 pm
Re: How do GUIs events for custom/no-core entities work?
You can do it with a custom linked control. See viewtopic.php?f=28&t=74530.8mobius8 wrote: ↑Fri Nov 08, 2019 8:24 pmI 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.
Re: How do GUIs events for custom/no-core entities work?
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.
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?Deadlock989 wrote: ↑Sat Nov 09, 2019 12:56 amYou can do it with a custom linked control. See viewtopic.php?f=28&t=74530.8mobius8 wrote: ↑Fri Nov 08, 2019 8:24 pmI 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.
Re: How do GUIs events for custom/no-core entities work?
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).
I have mods! I guess!
Link
Link
Re: How do GUIs events for custom/no-core entities work?
*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.Honktown wrote: ↑Sat Nov 09, 2019 3:19 amI 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).
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)
Thanks Honktown and Deadlock!
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: How do GUIs events for custom/no-core entities work?
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.8mobius8 wrote: ↑Sat Nov 09, 2019 4:33 amCode: Select all
-- [data.lua] local mouse_click={ type = "custom-input", name = "my-mod-mouse-left", key_sequence = "mouse-button-left", consuming = "game-only" }
https://wiki.factorio.com/Prototype/Cus ... me_control
Code: Select all
key_sequence = ""
linked_game_control = "open-gui"
consuming = nil
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.