mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 13:01:39 +09:00
Bugs Fixed
This commit is contained in:
@@ -5,7 +5,7 @@ local Gui = require './core'
|
||||
local Button = {
|
||||
config={},
|
||||
clean_names={},
|
||||
_prototype = Gui._set_up_prototype{}
|
||||
_prototype = Gui._extend_prototype{}
|
||||
}
|
||||
|
||||
function Button.new_button(name)
|
||||
@@ -31,15 +31,25 @@ function Button.draw_button(name,element)
|
||||
button = Button.config[button]
|
||||
end
|
||||
end
|
||||
button:draw_to(element)
|
||||
return button:draw_to(element)
|
||||
end
|
||||
|
||||
function Button._prototype:draw_to(element)
|
||||
if element.children[self.name] then return end
|
||||
local self_element = element.add(self)
|
||||
local draw = table.deep_copy(self)
|
||||
draw.authenticator = nil
|
||||
draw.clean_name = nil
|
||||
draw.raw_mouse_button_filter = nil
|
||||
draw.key_button_filter = nil
|
||||
draw._on_click = nil
|
||||
draw._on_left_click = nil
|
||||
draw._on_right_click = nil
|
||||
draw.has_handler = nil
|
||||
local self_element = element.add(draw)
|
||||
if self.authenticator then
|
||||
self_element.enabled = not not self.authenticator(element.player,self.clean_name or self.name)
|
||||
end
|
||||
return self_element
|
||||
end
|
||||
|
||||
function Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite)
|
||||
@@ -90,7 +100,7 @@ function Button._prototype:on_click(callback)
|
||||
if type(callback) ~= 'function' then
|
||||
return error('Event callback must be a function')
|
||||
end
|
||||
self.on_click = callback
|
||||
self._on_click = callback
|
||||
self:_add_handler()
|
||||
return self
|
||||
end
|
||||
@@ -99,7 +109,7 @@ function Button._prototype:on_left_click(callback)
|
||||
if type(callback) ~= 'function' then
|
||||
return error('Event callback must be a function')
|
||||
end
|
||||
self.on_left_click = callback
|
||||
self._on_left_click = callback
|
||||
self:_add_handler()
|
||||
return self
|
||||
end
|
||||
@@ -108,7 +118,7 @@ function Button._prototype:on_right_click(callback)
|
||||
if type(callback) ~= 'function' then
|
||||
return error('Event callback must be a function')
|
||||
end
|
||||
self.on_right_click = callback
|
||||
self._on_right_click = callback
|
||||
self:_add_handler()
|
||||
return self
|
||||
end
|
||||
@@ -125,9 +135,9 @@ function Button._prototype:_add_handler()
|
||||
if not self.authenticator(event.player,self.clean_name or self.name) then return end
|
||||
end
|
||||
|
||||
if mosue_button == defines.mouse_button_type.left and self.on_left_click then
|
||||
if mosue_button == defines.mouse_button_type.left and self._on_left_click then
|
||||
self.on_left_click(event.player,event.element,event)
|
||||
elseif mosue_button == defines.mouse_button_type.right and self.on_right_click then
|
||||
elseif mosue_button == defines.mouse_button_type.right and self._on_right_click then
|
||||
self.on_right_click(event.player,event.element,event)
|
||||
end
|
||||
|
||||
@@ -138,7 +148,7 @@ function Button._prototype:_add_handler()
|
||||
end
|
||||
end
|
||||
|
||||
self.on_click(event.player,event.element,event)
|
||||
self._on_click(event.player,event.element,event)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -9,16 +9,19 @@ function Gui._extend_prototype(tbl)
|
||||
for k,v in pairs(Gui._prototype) do
|
||||
if not tbl[k] then tbl[k] = v end
|
||||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
--- Sets the caption for the element config
|
||||
function Gui._prototype:set_caption(caption)
|
||||
self.caption = caption
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the tooltip for the element config
|
||||
function Gui._prototype:set_tooltip(tooltip)
|
||||
self.tooltip = tooltip
|
||||
return self
|
||||
end
|
||||
|
||||
function Gui.toggle_enable(element)
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
local Gui = require 'expcore.gui'
|
||||
|
||||
Gui.new_toolbar_button('click-1')
|
||||
:set_authenticator(function(player,button_name)
|
||||
return global.click_one
|
||||
end)
|
||||
:on_click(function(player,element,event)
|
||||
player.print('CLICK 1')
|
||||
end)
|
||||
|
||||
Gui.new_toolbar_button('click-2')
|
||||
:set_caption('Click Two')
|
||||
:set_authenticator(function(player,button_name)
|
||||
return global.click_two
|
||||
end)
|
||||
:on_click(function(player,element,event)
|
||||
player.print('CLICK 2')
|
||||
end)
|
||||
|
||||
Gui.new_toolbar_button('click-3')
|
||||
:set_sprites('utility/questionmark')
|
||||
:set_authenticator(function(player,button_name)
|
||||
return global.click_three
|
||||
end)
|
||||
:on_click(function(player,element,event)
|
||||
player.print('CLICK 3')
|
||||
end)
|
||||
@@ -1,6 +1,6 @@
|
||||
local Buttons = require './buttons'
|
||||
local Gui = require './core'
|
||||
local Roles = require 'expre.roles'
|
||||
local Roles = require 'expcore.roles'
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
@@ -12,6 +12,7 @@ function Toolbar.new_button(name)
|
||||
name = name or #Toolbar.buttons+1
|
||||
local button = Buttons.new_button('toolbar/'..name)
|
||||
button:set_authenticator(Roles.player_allowed)
|
||||
Toolbar.add_button(button)
|
||||
return button
|
||||
end
|
||||
|
||||
@@ -28,30 +29,36 @@ function Toolbar.add_button(button)
|
||||
end
|
||||
end
|
||||
|
||||
function Toolbar.draw(player)
|
||||
function Toolbar.update(player)
|
||||
local top = Gui.get_top_element_flow(player)
|
||||
if not top then return end
|
||||
for _,button in pairs(Toolbar.buttons) do
|
||||
local self_button = button:draw_to(player.gui.top)
|
||||
local element
|
||||
if top[button.name] then element = top[button.name]
|
||||
else element = button:draw_to(top) end
|
||||
if button.authenticator(player,button.clean_name or button.name) then
|
||||
self_button.visible = true
|
||||
element.visible = true
|
||||
element.enabled = true
|
||||
else
|
||||
self_button.visible = false
|
||||
element.visible = false
|
||||
element.enabled = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
Toolbar.draw(player)
|
||||
Toolbar.update(player)
|
||||
end)
|
||||
|
||||
Event.add(Roles.player_role_assigned,function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
Toolbar.draw(player)
|
||||
Toolbar.update(player)
|
||||
end)
|
||||
|
||||
Event.add(Roles.player_role_unassigned,function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
Toolbar.draw(player)
|
||||
Toolbar.update(player)
|
||||
end)
|
||||
|
||||
return Toolbar
|
||||
Reference in New Issue
Block a user