mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Added left frames
This commit is contained in:
146
expcore/Gui/left.lua
Normal file
146
expcore/Gui/left.lua
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
local Gui = require './core'
|
||||||
|
local Toolbar = require './toolbar'
|
||||||
|
local Buttons = require './buttons'
|
||||||
|
local mod_gui = require 'mod-gui'
|
||||||
|
local Game = require 'utils.game'
|
||||||
|
local Events = require 'utils.events'
|
||||||
|
|
||||||
|
local LeftFrames = {
|
||||||
|
buttons={},
|
||||||
|
draw_functions={},
|
||||||
|
open_by_default={}
|
||||||
|
}
|
||||||
|
|
||||||
|
function LeftFrames.get_flow(player)
|
||||||
|
return mod_gui.get_frame_flow(player)
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.get_open(player)
|
||||||
|
local open = {}
|
||||||
|
local flow = LeftFrames.get_flow(player)
|
||||||
|
|
||||||
|
for _,child in pairs(flow.children) do
|
||||||
|
if LeftFrames.buttons[child.name] then
|
||||||
|
if child.valid and child.visible then
|
||||||
|
table.insert(open,child)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #open == 0 then
|
||||||
|
flow[LeftFrames.toogle_button.name].visible = false
|
||||||
|
end
|
||||||
|
|
||||||
|
return open
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.get_frame(player,name)
|
||||||
|
local flow = LeftFrames.get_flow(player)
|
||||||
|
if flow[name] and flow[name].valid then
|
||||||
|
return flow[name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.toogle_frame(player,name,state)
|
||||||
|
local frame = LeftFrames.get_frame(player,name)
|
||||||
|
if state ~= nil then
|
||||||
|
frame.visible = state
|
||||||
|
else
|
||||||
|
Gui.toggle_visible(frame)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.new_frame(name)
|
||||||
|
local frame_name = Gui.uid_name()
|
||||||
|
LeftFrames.add_frame(frame_name,name)
|
||||||
|
return frame_name
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.add_frame(define_name,permision_name)
|
||||||
|
LeftFrames.buttons[define_name] =
|
||||||
|
Toolbar.new_button(permision_name)
|
||||||
|
:on_click(function(player,_element)
|
||||||
|
LeftFrames.toogle_frame(player,define_name)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.set_open_by_default(define_name,state)
|
||||||
|
if not LeftFrames.buttons[define_name] then
|
||||||
|
return error('Left frame is not registered',2)
|
||||||
|
end
|
||||||
|
|
||||||
|
LeftFrames.draw_functions[define_name] = state
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.on_update(define_name,callback)
|
||||||
|
if not LeftFrames.buttons[define_name] then
|
||||||
|
return error('Left frame is not registered',2)
|
||||||
|
end
|
||||||
|
|
||||||
|
LeftFrames.open_by_default[define_name] = callback
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.update(define_name,player)
|
||||||
|
player = Game.get_player_from_any(player)
|
||||||
|
local frame = LeftFrames.get_frame(player,define_name)
|
||||||
|
frame.clear()
|
||||||
|
if LeftFrames.draw_functions[define_name] then
|
||||||
|
LeftFrames.draw_functions[define_name](frame,player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.update_all_frames(player)
|
||||||
|
player = Game.get_player_from_any(player)
|
||||||
|
for define_name,draw_function in pairs(LeftFrames.draw_functions) do
|
||||||
|
local frame = LeftFrames.get_frame(player,define_name)
|
||||||
|
frame.clear()
|
||||||
|
draw_function(frame,player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.update_all_players(define_name,update_offline)
|
||||||
|
local players = update_offline and game.players or game.connected_players
|
||||||
|
for _,player in pairs(players) do
|
||||||
|
LeftFrames.update(define_name,player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LeftFrames.update_all(update_offline)
|
||||||
|
local players = update_offline and game.players or game.connected_players
|
||||||
|
for _,player in pairs(players) do
|
||||||
|
LeftFrames.update_all_frames(player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
LeftFrames.toogle_button =
|
||||||
|
Buttons.new_button()
|
||||||
|
:set_caption('<')
|
||||||
|
:on_click(function(player,_element)
|
||||||
|
local flow = LeftFrames.get_flow(player)
|
||||||
|
|
||||||
|
for _,child in pairs(flow.children) do
|
||||||
|
if LeftFrames.buttons[child.name] then
|
||||||
|
if child.valid and child.visible then
|
||||||
|
child.visible = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
Events.add(defines.events.on_player_created,function(event)
|
||||||
|
local player = Game.get_plyaer_by_index(event.player_index)
|
||||||
|
local flow = LeftFrames.get_flow(player)
|
||||||
|
|
||||||
|
LeftFrames.toogle_button(flow)
|
||||||
|
|
||||||
|
for define_name,_ in pairs(LeftFrames.buttons) do
|
||||||
|
local frame = flow.add{
|
||||||
|
type='frame',
|
||||||
|
name=define_name
|
||||||
|
}
|
||||||
|
|
||||||
|
if LeftFrames.draw_functions[define_name] then
|
||||||
|
LeftFrames.draw_functions[define_name](frame,player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
@@ -12,17 +12,27 @@ local Event = require 'utils.event'
|
|||||||
local Game = require 'utils.game'
|
local Game = require 'utils.game'
|
||||||
|
|
||||||
local Toolbar = {
|
local Toolbar = {
|
||||||
|
permisison_names = {},
|
||||||
buttons = {}
|
buttons = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function toolbar_allow(player,define_name)
|
||||||
|
local permisison_name = Toolbar.permisison_names[define_name] or define_name
|
||||||
|
return Roles.player_allowed(player,permisison_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Toolbar.permission_alias(define_name,permisison_name)
|
||||||
|
Toolbar.permisison_names[define_name] = permisison_name
|
||||||
|
end
|
||||||
|
|
||||||
--- Adds a new button to the toolbar
|
--- Adds a new button to the toolbar
|
||||||
-- @tparam[opt] name string the name of the button to be added
|
-- @tparam[opt] name string the name of the button to be added
|
||||||
-- @treturn table the button define
|
-- @treturn table the button define
|
||||||
function Toolbar.new_button(name)
|
function Toolbar.new_button(name)
|
||||||
name = name or #Toolbar.buttons+1
|
local button = Buttons.new_button()
|
||||||
local button = Buttons.new_button('toolbar/'..name)
|
button:set_post_authenticator(toolbar_allow)
|
||||||
button:set_post_authenticator(Roles.player_allowed)
|
|
||||||
Toolbar.add_button(button)
|
Toolbar.add_button(button)
|
||||||
|
Toolbar.permission_alias(button.name,name)
|
||||||
return button
|
return button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -58,17 +58,6 @@ Gui.classes.button = Button
|
|||||||
Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button
|
Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local Toolbar = require('./gui/toolbar')
|
|
||||||
Gui.new_toolbar_button = Toolbar.new_button
|
|
||||||
Gui.add_button_to_toolbar = Toolbar.add_button
|
|
||||||
Gui.update_toolbar = Toolbar.update
|
|
||||||
Gui.classes.toolbar = Toolbar
|
|
||||||
--[[
|
|
||||||
Toolbar.new_button(name) --- Adds a new button to the toolbar
|
|
||||||
Toolbar.add_button(button) --- Adds an existing buttton to the toolbar
|
|
||||||
Toolbar.update(player) --- Updates the player's toolbar with an new buttons or expected change in auth return
|
|
||||||
]]
|
|
||||||
|
|
||||||
local Checkbox = require('./gui/checkboxs')
|
local Checkbox = require('./gui/checkboxs')
|
||||||
Gui.new_checkbox = Checkbox.new_checkbox
|
Gui.new_checkbox = Checkbox.new_checkbox
|
||||||
Gui.new_radiobutton = Checkbox.new_radiobutton
|
Gui.new_radiobutton = Checkbox.new_radiobutton
|
||||||
@@ -154,4 +143,23 @@ Gui.classes.elem_button = ElemButton
|
|||||||
ElemButton._prototype:set_default(value) --- Sets the default value for the elem button, this may be a function or a string
|
ElemButton._prototype:set_default(value) --- Sets the default value for the elem button, this may be a function or a string
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local Toolbar = require('./gui/toolbar')
|
||||||
|
Gui.new_toolbar_button = Toolbar.new_button
|
||||||
|
Gui.add_button_to_toolbar = Toolbar.add_button
|
||||||
|
Gui.update_toolbar = Toolbar.update
|
||||||
|
Gui.classes.toolbar = Toolbar
|
||||||
|
--[[
|
||||||
|
Toolbar.new_button(name) --- Adds a new button to the toolbar
|
||||||
|
Toolbar.add_button(button) --- Adds an existing buttton to the toolbar
|
||||||
|
Toolbar.update(player) --- Updates the player's toolbar with an new buttons or expected change in auth return
|
||||||
|
]]
|
||||||
|
|
||||||
|
local LeftFrames = require('./gui/left')
|
||||||
|
Gui.new_left_frame = LeftFrames.new_frame
|
||||||
|
Gui.add_frame_to_left_frames = LeftFrames.add_frame
|
||||||
|
Gui.set_left_open_by_default = LeftFrames.set_open_by_default
|
||||||
|
Gui.on_left_frame_update = LeftFrames.on_update
|
||||||
|
Gui.update_left_frames = LeftFrames.update_all_frames
|
||||||
|
Gui.update_left_frame = LeftFrames.update
|
||||||
|
|
||||||
return Gui
|
return Gui
|
||||||
Reference in New Issue
Block a user