1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2025-01-05 22:53:48 +02:00

Added Esc key to close top-left GUI and fixed issue where you could be typing into the notepad when it's closed.

This commit is contained in:
Oarcinae 2020-03-03 15:53:01 -05:00
parent c73863de21
commit b447c77517
2 changed files with 26 additions and 1 deletions

View File

@ -425,4 +425,13 @@ end)
script.on_event(defines.events.on_gui_text_changed, function(event)
NotepadOnGuiTextChange(event)
SharedElectricityPlayerGuiValueChange(event)
end)
----------------------------------------
-- On Gui Closed
-- For capturing player escaping custom GUI so we can close it using ESC key.
----------------------------------------
script.on_event(defines.events.on_gui_closed, function(event)
OarcGuiOnGuiClosedEvent(event)
end)

View File

@ -79,10 +79,18 @@ function DoesOarcGuiExist(player)
return (mod_gui.get_frame_flow(player)[OARC_GUI] ~= nil)
end
function IsOarcGuiVisible(player)
local of = mod_gui.get_frame_flow(player)[OARC_GUI]
return (of.visible)
end
function ToggleOarcGuiVisible(player)
local of = mod_gui.get_frame_flow(player)[OARC_GUI]
if (of ~= nil) then
of.visible = not of.visible
if (of.visible) then
player.opened = of -- This allows us to indicate the player has this GUI open and when they press Esc we'll get an event!
end
end
end
@ -111,7 +119,9 @@ function ClickOarcGuiButton(event)
CreateOarcGuiTabsPane(player)
else
ToggleOarcGuiVisible(player)
FakeTabChangeEventOarcGui(player)
if (IsOarcGuiVisible(player)) then
FakeTabChangeEventOarcGui(player)
end
end
end
@ -264,4 +274,10 @@ function SwitchOarcGuiTab(player, tab_name)
return
end
end
end
function OarcGuiOnGuiClosedEvent(event)
if (event.element.name == "oarc_gui") then
ToggleOarcGuiVisible(game.players[event.player_index])
end
end