Skip to content

Commit

Permalink
Clearing the textfield (rightclick or backspace when everything is se…
Browse files Browse the repository at this point in the history
…lected) now triggers the mod the same way `Default` does
  • Loading branch information
Quezler committed Dec 19, 2023
1 parent 8eb206b commit 276218d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions mods/se-signal-transmitter-new-channel-name-suggester/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ local Zone = require('__space-exploration-scripts__.zone')
local mod_prefix = "" -- should be `aai-` for versions after v0.4.9
local default_channel = "Default"

script.on_init(function(event)
global.player_keystrokes_since_editing_channel = {}
end)

script.on_configuration_changed(function(event)
global.player_keystrokes_since_editing_channel = global.player_keystrokes_since_editing_channel or {}
end)

script.on_event(defines.events.on_gui_click, function(event)
if event.element and event.element.name == mod_prefix .. "change_channel" then
global.player_keystrokes_since_editing_channel[event.player_index] = 0
if event.element.parent.children[1].caption == default_channel then
local player = game.get_player(event.player_index)
local coin = {name = "coin", count = 1}
Expand All @@ -31,3 +40,19 @@ script.on_event(defines.events.on_player_main_inventory_changed, function(event)
write_channel.select_all()
end
end)

script.on_event(defines.events.on_gui_text_changed, function(event)
if event.element and event.element.name == mod_prefix .. "write-channel" then
global.player_keystrokes_since_editing_channel[event.player_index] = global.player_keystrokes_since_editing_channel[event.player_index] + 1

if event.element.text == "" and global.player_keystrokes_since_editing_channel[event.player_index] == 1 then
local player = game.get_player(event.player_index)

local zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = player.surface.index})
if not zone then return end

event.element.text = Zone._get_rich_text_name(zone)
event.element.select_all()
end
end
end)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "se-signal-transmitter-new-channel-name-suggester",
"title": "Space Exploration - signal transmitter new channel name suggester",
"description": "When you place down a new signal transmitter and rename `Default` to something else, it suggests the current surface's name + primary resource.",
"version": "1.0.3",
"version": "1.0.4",
"author": "Quezler",
"factorio_version": "1.1",
"dependencies": [
Expand Down

0 comments on commit 276218d

Please sign in to comment.