mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
@@ -52,7 +52,7 @@ end)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
function Gui.left_toolbar_button(sprite,tooltip,element_define,authenticator)
|
function Gui.left_toolbar_button(sprite,tooltip,element_define,authenticator)
|
||||||
return Gui.element{
|
local button = Gui.element{
|
||||||
type = 'sprite-button',
|
type = 'sprite-button',
|
||||||
sprite = sprite,
|
sprite = sprite,
|
||||||
tooltip = tooltip,
|
tooltip = tooltip,
|
||||||
@@ -62,9 +62,26 @@ function Gui.left_toolbar_button(sprite,tooltip,element_define,authenticator)
|
|||||||
padding = -2
|
padding = -2
|
||||||
}
|
}
|
||||||
:add_to_top_flow(authenticator)
|
:add_to_top_flow(authenticator)
|
||||||
:on_click(function(player,_,_)
|
|
||||||
Gui.toggle_left_element(player, element_define)
|
-- Add on_click handler to handle click events comming from the player
|
||||||
|
button:on_click(function(player,_,_)
|
||||||
|
local top_flow = Gui.get_top_flow(player)
|
||||||
|
local element = top_flow[button.name]
|
||||||
|
local visibility_state = Gui.toggle_left_element(player, element_define)
|
||||||
|
|
||||||
|
-- Raise custom event that tells listening elements if the element has changed visibility by a player clicking
|
||||||
|
-- Used in warp gui to handle the keep open logic
|
||||||
|
button:raise_custom_event{
|
||||||
|
name = Gui.events.on_visibility_changed_by_click,
|
||||||
|
element = element,
|
||||||
|
state = visibility_state
|
||||||
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Add property to the left flow element with the name of the button
|
||||||
|
-- This is for the ability to reverse lookup the button from the left flow element
|
||||||
|
element_define.toolbar_button = button.name
|
||||||
|
return button
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Draw all the left elements onto the left flow, internal use only
|
--[[-- Draw all the left elements onto the left flow, internal use only
|
||||||
@@ -137,6 +154,26 @@ function Gui.hide_left_flow(player)
|
|||||||
hide_button.visible = false
|
hide_button.visible = false
|
||||||
for name,_ in pairs(Gui.left_elements) do
|
for name,_ in pairs(Gui.left_elements) do
|
||||||
left_flow[name].visible = false
|
left_flow[name].visible = false
|
||||||
|
|
||||||
|
-- Get the assosiated element define
|
||||||
|
local element_define = Gui.defines[name]
|
||||||
|
local top_flow = Gui.get_top_flow(player)
|
||||||
|
|
||||||
|
-- Check if the the element has a button attached
|
||||||
|
if element_define.toolbar_button then
|
||||||
|
-- Check if the topflow contains the button
|
||||||
|
local button = top_flow[element_define.toolbar_button]
|
||||||
|
if button then
|
||||||
|
-- Get the button define from the reverse lookup on the element
|
||||||
|
local button_define = Gui.defines[element_define.toolbar_button]
|
||||||
|
-- Raise the custom event if all of the top checks have passed
|
||||||
|
button_define:raise_custom_event{
|
||||||
|
name = Gui.events.on_visibility_changed_by_click,
|
||||||
|
element = button,
|
||||||
|
state = false
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -246,6 +246,7 @@ end
|
|||||||
|
|
||||||
--[[-- Raise the handler which is attached to any event; external use should be limited to custom events
|
--[[-- Raise the handler which is attached to any event; external use should be limited to custom events
|
||||||
@tparam table event the event table bassed to the handler, must include fields: name, element
|
@tparam table event the event table bassed to the handler, must include fields: name, element
|
||||||
|
@treturn table the element define so more events can be raised
|
||||||
|
|
||||||
@usage Raising a custom event
|
@usage Raising a custom event
|
||||||
element_define:raise_custom_event{
|
element_define:raise_custom_event{
|
||||||
@@ -258,20 +259,20 @@ function Gui._prototype_element:raise_custom_event(event)
|
|||||||
-- Check the element is valid
|
-- Check the element is valid
|
||||||
local element = event.element
|
local element = event.element
|
||||||
if not element or not element.valid then
|
if not element or not element.valid then
|
||||||
return
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the event handler for this element
|
-- Get the event handler for this element
|
||||||
local handler = self[event.name]
|
local handler = self[event.name]
|
||||||
if not handler then
|
if not handler then
|
||||||
return
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the player for this event
|
-- Get the player for this event
|
||||||
local player_index = event.player_index or element.player_index
|
local player_index = event.player_index or element.player_index
|
||||||
local player = game.players[player_index]
|
local player = game.players[player_index]
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return self
|
||||||
end
|
end
|
||||||
event.player = player
|
event.player = player
|
||||||
|
|
||||||
@@ -279,6 +280,7 @@ function Gui._prototype_element:raise_custom_event(event)
|
|||||||
if not success then
|
if not success then
|
||||||
error('There as been an error with an event handler for a gui element:\n\t'..err)
|
error('There as been an error with an event handler for a gui element:\n\t'..err)
|
||||||
end
|
end
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This function is used to register a link between element define events and the events in the factorio api
|
-- This function is used to register a link between element define events and the events in the factorio api
|
||||||
@@ -348,5 +350,11 @@ Gui._prototype_element.on_text_changed = event_handler_factory(defines.events.on
|
|||||||
-- @tparam function handler the event handler which will be called
|
-- @tparam function handler the event handler which will be called
|
||||||
Gui._prototype_element.on_value_changed = event_handler_factory(defines.events.on_gui_value_changed)
|
Gui._prototype_element.on_value_changed = event_handler_factory(defines.events.on_gui_value_changed)
|
||||||
|
|
||||||
|
--- Custom element events.
|
||||||
|
-- @section customEvents
|
||||||
|
|
||||||
|
-- Triggered when a user changed the visibility of a left flow element by clicking a button
|
||||||
|
Gui.events.on_visibility_changed_by_click = 'on_visibility_changed_by_click'
|
||||||
|
|
||||||
-- Module return
|
-- Module return
|
||||||
return Gui
|
return Gui
|
||||||
@@ -439,9 +439,9 @@ end)
|
|||||||
Gui.left_toolbar_button('item/'..config.default_icon,{'warp-list.main-tooltip',config.standard_proximity_radius},warp_list_container, function(player)
|
Gui.left_toolbar_button('item/'..config.default_icon,{'warp-list.main-tooltip',config.standard_proximity_radius},warp_list_container, function(player)
|
||||||
return Roles.player_allowed(player,'gui/warp-list')
|
return Roles.player_allowed(player,'gui/warp-list')
|
||||||
end)
|
end)
|
||||||
:on_click(function(player,_,_)
|
:on_custom_event(Gui.events.on_visibility_changed_by_click, function(player,_,event)
|
||||||
local visible_state = Gui.toggle_left_element(player, warp_list_container)
|
-- Set gui keep open state for player that clicked the button: true if visible, false if invisible
|
||||||
keep_gui_open[player.name] = visible_state
|
keep_gui_open[player.name] = event.state
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- When the name of a warp is updated this is triggered
|
--- When the name of a warp is updated this is triggered
|
||||||
|
|||||||
Reference in New Issue
Block a user