mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Bugs Fixed
This commit is contained in:
@@ -38,5 +38,5 @@ return {
|
||||
'config.command_auth_runtime_disable', -- allows commands to be enabled and disabled during runtime
|
||||
'config.permission_groups', -- loads some predefined permission groups
|
||||
'config.roles', -- loads some predefined roles
|
||||
'expcore.store_test'
|
||||
'expcore.gui.test'
|
||||
}
|
||||
@@ -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
|
||||
@@ -10,7 +10,8 @@ local interface_modules = {
|
||||
['output']=Common.player_return,
|
||||
['Group']='expcore.permission_groups',
|
||||
['Roles']='expcore.roles',
|
||||
['Store']='expcore.store'
|
||||
['Store']='expcore.store',
|
||||
['Gui']='expcore.gui'
|
||||
}
|
||||
|
||||
-- loads all the modules given in the above table
|
||||
|
||||
@@ -2,6 +2,7 @@ local Token = require 'utils.token'
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
local Global = require 'utils.global'
|
||||
local mod_gui = require 'mod-gui'
|
||||
|
||||
local Gui = {}
|
||||
|
||||
@@ -179,7 +180,7 @@ Gui.on_player_show_top = custom_handler_factory(on_visible_handlers)
|
||||
Gui.on_pre_player_hide_top = custom_handler_factory(on_pre_hidden_handlers)
|
||||
|
||||
--- Allows the player to show / hide this element.
|
||||
-- The element must be part in gui.top.
|
||||
-- The element must be in Gui.get_top_element_flow(player).
|
||||
-- This function must be called in the control stage, i.e not inside an event.
|
||||
-- @param element_name<string> This name must be globally unique.
|
||||
function Gui.allow_player_to_toggle_top_element_visibility(element_name)
|
||||
@@ -189,6 +190,15 @@ function Gui.allow_player_to_toggle_top_element_visibility(element_name)
|
||||
top_elements[#top_elements + 1] = element_name
|
||||
end
|
||||
|
||||
--- Returns the flow where top elements can be added and will be effected by google visibility
|
||||
-- For the toggle to work it must be registed with Gui.allow_player_to_toggle_top_element_visibility(element_name)
|
||||
-- @tparam player LuaPlayer pointer to the player who has the gui
|
||||
-- @treturn LuaGuiEelement the top element flow
|
||||
function Gui.get_top_element_flow(player)
|
||||
player = Game.get_player_from_any(player)
|
||||
return mod_gui.get_button_flow(player)
|
||||
end
|
||||
|
||||
local toggle_button_name = Gui.uid_name()
|
||||
|
||||
Event.add(
|
||||
@@ -201,15 +211,16 @@ Event.add(
|
||||
end
|
||||
|
||||
local b =
|
||||
player.gui.top.add {
|
||||
Gui.get_top_element_flow(player).add {
|
||||
type = 'button',
|
||||
name = toggle_button_name,
|
||||
caption = '<',
|
||||
style=mod_gui.button_style,
|
||||
tooltip = 'Shows / hides the Redmew Gui buttons.'
|
||||
}
|
||||
local style = b.style
|
||||
style.width = 18
|
||||
style.height = 38
|
||||
style.height = 36
|
||||
style.left_padding = 0
|
||||
style.top_padding = 0
|
||||
style.right_padding = 0
|
||||
@@ -223,21 +234,16 @@ Gui.on_click(
|
||||
function(event)
|
||||
local button = event.element
|
||||
local player = event.player
|
||||
local top = player.gui.top
|
||||
local top = Gui.get_top_element_flow(player)
|
||||
|
||||
if button.caption == '<' then
|
||||
for i = 1, #top_elements do
|
||||
local name = top_elements[i]
|
||||
local ele = top[name]
|
||||
if ele and ele.valid then
|
||||
local style = ele.style
|
||||
|
||||
-- if visible is not set it has the value of nil.
|
||||
-- Hence nil is treated as is visible.
|
||||
local v = style.visible
|
||||
if v or v == nil then
|
||||
if ele.visible then
|
||||
custom_raise(on_pre_hidden_handlers, ele, player)
|
||||
style.visible = false
|
||||
ele.visible = false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -249,17 +255,15 @@ Gui.on_click(
|
||||
local name = top_elements[i]
|
||||
local ele = top[name]
|
||||
if ele and ele.valid then
|
||||
local style = ele.style
|
||||
|
||||
if not style.visible then
|
||||
style.visible = true
|
||||
if not ele.visible then
|
||||
ele.visible = true
|
||||
custom_raise(on_visible_handlers, ele, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
button.caption = '<'
|
||||
button.style.height = 38
|
||||
button.style.height = 36
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user