mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Added player List
This commit is contained in:
@@ -43,7 +43,7 @@ return {
|
|||||||
--'modules.gui.science-info',
|
--'modules.gui.science-info',
|
||||||
--'modules.gui.warp-list',
|
--'modules.gui.warp-list',
|
||||||
--'modules.gui.task-list',
|
--'modules.gui.task-list',
|
||||||
--'modules.gui.player-list',
|
'modules.gui.player-list',
|
||||||
--'modules.commands.debug',
|
--'modules.commands.debug',
|
||||||
-- Config Files
|
-- Config Files
|
||||||
'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins
|
'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins
|
||||||
|
|||||||
@@ -15,12 +15,16 @@ local Jail = require 'modules.control.jail' --- @dep modules.control.jail
|
|||||||
local Colors = require 'resources.color_presets' --- @dep resources.color_presets
|
local Colors = require 'resources.color_presets' --- @dep resources.color_presets
|
||||||
local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') --- @dep expcore.common
|
local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') --- @dep expcore.common
|
||||||
|
|
||||||
|
Gui.require_concept('button')
|
||||||
|
|
||||||
local action_player_store = 'gui.left.player-list.action-player'
|
local action_player_store = 'gui.left.player-list.action-player'
|
||||||
local action_name_store = 'gui.left.player-list.action-name'
|
local action_name_store = 'gui.left.player-list.action-name'
|
||||||
|
|
||||||
-- common style used by all action buttons
|
-- common style used by all action buttons
|
||||||
local function tool_button_style(style)
|
local function tool_button_style(properties,parent,element)
|
||||||
Gui.set_padding_style(style,-1,-1,-1,-1)
|
element.style = 'tool_button'
|
||||||
|
local style = element.style
|
||||||
|
style.padding = -1
|
||||||
style.height = 28
|
style.height = 28
|
||||||
style.width = 28
|
style.width = 28
|
||||||
end
|
end
|
||||||
@@ -55,11 +59,12 @@ end
|
|||||||
--- Teleports the user to the action player
|
--- Teleports the user to the action player
|
||||||
-- @element goto_player
|
-- @element goto_player
|
||||||
local goto_player =
|
local goto_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/export')
|
:set_sprite('utility/export')
|
||||||
:set_tooltip{'player-list.goto-player'}
|
:set_tooltip{'player-list.goto-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
local action_player_name = get_action_player_name(player)
|
local action_player_name = get_action_player_name(player)
|
||||||
local action_player = Game.get_player_from_any(action_player_name)
|
local action_player = Game.get_player_from_any(action_player_name)
|
||||||
if not player.character or not action_player.character then
|
if not player.character or not action_player.character then
|
||||||
@@ -72,11 +77,12 @@ end)
|
|||||||
--- Teleports the action player to the user
|
--- Teleports the action player to the user
|
||||||
-- @element bring_player
|
-- @element bring_player
|
||||||
local bring_player =
|
local bring_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/import')
|
:set_sprite('utility/import')
|
||||||
:set_tooltip{'player-list.bring-player'}
|
:set_tooltip{'player-list.bring-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
local action_player_name = get_action_player_name(player)
|
local action_player_name = get_action_player_name(player)
|
||||||
local action_player = Game.get_player_from_any(action_player_name)
|
local action_player = Game.get_player_from_any(action_player_name)
|
||||||
if not player.character or not action_player.character then
|
if not player.character or not action_player.character then
|
||||||
@@ -89,11 +95,12 @@ end)
|
|||||||
--- Kills the action player, if there are alive
|
--- Kills the action player, if there are alive
|
||||||
-- @element kill_player
|
-- @element kill_player
|
||||||
local kill_player =
|
local kill_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/too_far')
|
:set_sprite('utility/too_far')
|
||||||
:set_tooltip{'player-list.kill-player'}
|
:set_tooltip{'player-list.kill-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
local action_player_name = get_action_player_name(player)
|
local action_player_name = get_action_player_name(player)
|
||||||
local action_player = Game.get_player_from_any(action_player_name)
|
local action_player = Game.get_player_from_any(action_player_name)
|
||||||
if action_player.character then
|
if action_player.character then
|
||||||
@@ -106,11 +113,12 @@ end)
|
|||||||
--- Reports the action player, requires a reason to be given
|
--- Reports the action player, requires a reason to be given
|
||||||
-- @element report_player
|
-- @element report_player
|
||||||
local report_player =
|
local report_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/spawn_flag')
|
:set_sprite('utility/spawn_flag')
|
||||||
:set_tooltip{'player-list.report-player'}
|
:set_tooltip{'player-list.report-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
local action_player_name = get_action_player_name(player)
|
local action_player_name = get_action_player_name(player)
|
||||||
if Reports.is_reported(action_player_name,player.name) then
|
if Reports.is_reported(action_player_name,player.name) then
|
||||||
player.print({'expcom-report.already-reported'},Colors.orange_red)
|
player.print({'expcom-report.already-reported'},Colors.orange_red)
|
||||||
@@ -130,11 +138,12 @@ end
|
|||||||
--- Gives the action player a warning, requires a reason
|
--- Gives the action player a warning, requires a reason
|
||||||
-- @element warn_player
|
-- @element warn_player
|
||||||
local warn_player =
|
local warn_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/spawn_flag')
|
:set_sprite('utility/spawn_flag')
|
||||||
:set_tooltip{'player-list.warn-player'}
|
:set_tooltip{'player-list.warn-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
Store.set(action_name_store,player.name,'command/give-warning')
|
Store.set(action_name_store,player.name,'command/give-warning')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -148,11 +157,12 @@ end
|
|||||||
--- Jails the action player, requires a reason
|
--- Jails the action player, requires a reason
|
||||||
-- @element jail_player
|
-- @element jail_player
|
||||||
local jail_player =
|
local jail_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/item_editor_icon')
|
:set_sprite('utility/item_editor_icon')
|
||||||
:set_tooltip{'player-list.jail-player'}
|
:set_tooltip{'player-list.jail-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
local action_player_name,action_player_name_color = get_action_player_name(player)
|
local action_player_name,action_player_name_color = get_action_player_name(player)
|
||||||
if Jail.is_jailed(action_player_name) then
|
if Jail.is_jailed(action_player_name) then
|
||||||
player.print({'expcom-jail.already-jailed',action_player_name_color},Colors.orange_red)
|
player.print({'expcom-jail.already-jailed',action_player_name_color},Colors.orange_red)
|
||||||
@@ -171,11 +181,12 @@ end
|
|||||||
--- Temp bans the action player, requires a reason
|
--- Temp bans the action player, requires a reason
|
||||||
-- @element temp_ban_player
|
-- @element temp_ban_player
|
||||||
local temp_ban_player =
|
local temp_ban_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/clock')
|
:set_sprite('utility/clock')
|
||||||
:set_tooltip{'player-list.temp-ban-player'}
|
:set_tooltip{'player-list.temp-ban-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
local action_player_name,action_player_name_color = get_action_player_name(player)
|
local action_player_name,action_player_name_color = get_action_player_name(player)
|
||||||
if Jail.is_jailed(action_player_name) then
|
if Jail.is_jailed(action_player_name) then
|
||||||
player.print({'expcom-jail.already-banned',action_player_name_color},Colors.orange_red)
|
player.print({'expcom-jail.already-banned',action_player_name_color},Colors.orange_red)
|
||||||
@@ -194,11 +205,12 @@ end
|
|||||||
--- Kicks the action player, requires a reason
|
--- Kicks the action player, requires a reason
|
||||||
-- @element kick_player
|
-- @element kick_player
|
||||||
local kick_player =
|
local kick_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/warning_icon')
|
:set_sprite('utility/warning_icon')
|
||||||
:set_tooltip{'player-list.kick-player'}
|
:set_tooltip{'player-list.kick-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
Store.set(action_name_store,player.name,'command/kick')
|
Store.set(action_name_store,player.name,'command/kick')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -210,11 +222,12 @@ end
|
|||||||
--- Bans the action player, requires a reason
|
--- Bans the action player, requires a reason
|
||||||
-- @element ban_player
|
-- @element ban_player
|
||||||
local ban_player =
|
local ban_player =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/danger_icon')
|
:set_sprite('utility/danger_icon')
|
||||||
:set_tooltip{'player-list.ban-player'}
|
:set_tooltip{'player-list.ban-player'}
|
||||||
:set_style('tool_button',tool_button_style)
|
:define_draw(tool_button_style)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
local player = event.player
|
||||||
Store.set(action_name_store,player.name,'command/ban')
|
Store.set(action_name_store,player.name,'command/ban')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -147,9 +147,9 @@ end
|
|||||||
@treturn[2] boolean if the element was found, found
|
@treturn[2] boolean if the element was found, found
|
||||||
@treturn[2] LuaGuiElement the element that was found
|
@treturn[2] LuaGuiElement the element that was found
|
||||||
@usage-- Getting the center gui
|
@usage-- Getting the center gui
|
||||||
local exists, center = Gui.find(player,'gui','center')
|
local exists, center = Gui.exists(player,'gui','center')
|
||||||
]]
|
]]
|
||||||
function Gui.find(element,...)
|
function Gui.exists(element,...)
|
||||||
local path = tostring(element.name)
|
local path = tostring(element.name)
|
||||||
for _,next_element_name in pairs{...} do
|
for _,next_element_name in pairs{...} do
|
||||||
if type(next_element_name) == 'table' then
|
if type(next_element_name) == 'table' then
|
||||||
@@ -165,18 +165,22 @@ function Gui.find(element,...)
|
|||||||
return true, element
|
return true, element
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Checks if a gui element exists or not, returns it if found else the path where it failed
|
--[[-- Checks if a gui element exists or not, if not found will throw an error
|
||||||
@see Gui.find
|
@see Gui.exists
|
||||||
@tparam LuaGuiElement element the root element to start checking from
|
@tparam LuaGuiElement element the root element to start checking from
|
||||||
@tparam ?string|table ... element names or element concepts that point to your element
|
@tparam ?string|table ... element names or element concepts that point to your element
|
||||||
@treturn[1] boolean if the element was found, failed
|
@treturn LuaGuiElement the element that was found
|
||||||
@treturn[1] string the path of the element that the search stoped at
|
|
||||||
@treturn[2] boolean if the element was found, found
|
|
||||||
@treturn[2] LuaGuiElement the element that was found
|
|
||||||
@usage-- Getting the center gui
|
@usage-- Getting the center gui
|
||||||
local exists, center = Gui.exists(player,'gui','center')
|
local exists, center = Gui.find(player,'gui','center')
|
||||||
]]
|
]]
|
||||||
Gui.exists = Gui.find
|
function Gui.find(element,...)
|
||||||
|
local exists, element = Gui.exists(element,...)
|
||||||
|
if not exists then
|
||||||
|
return error('Could not find element: '..element,2)
|
||||||
|
else
|
||||||
|
return element
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--[[-- Toggles the enabled state of an element
|
--[[-- Toggles the enabled state of an element
|
||||||
@tparam LuaGuiElement element the element that you want to toggle the enabled state of
|
@tparam LuaGuiElement element the element that you want to toggle the enabled state of
|
||||||
|
|||||||
@@ -31,19 +31,21 @@ Gui.new_concept('frame')
|
|||||||
-- Update the table style
|
-- Update the table style
|
||||||
Gui.set_padding(element,2,2,4,4)
|
Gui.set_padding(element,2,2,4,4)
|
||||||
element.style = 'subfooter_frame'
|
element.style = 'subfooter_frame'
|
||||||
element.caption = nil
|
element.caption = ''
|
||||||
|
|
||||||
local style = element.style
|
local style = element.style
|
||||||
style.horizontally_stretchable = true
|
style.horizontally_stretchable = true
|
||||||
style.use_header_filler = false
|
style.use_header_filler = false
|
||||||
|
|
||||||
-- Add the caption to the frame
|
-- Add the caption to the frame
|
||||||
element.add{
|
if properties.title then
|
||||||
type = 'label',
|
element.add{
|
||||||
name = 'footer_caption',
|
type = 'label',
|
||||||
caption = properties.title,
|
name = 'footer_caption',
|
||||||
tooltip = properties.tooltip
|
caption = properties.title,
|
||||||
}
|
tooltip = properties.tooltip
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
-- Add the right align area
|
-- Add the right align area
|
||||||
local align = right_align:draw(element,'footer_content')
|
local align = right_align:draw(element,'footer_content')
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ Gui.new_concept('scroll_table')
|
|||||||
|
|
||||||
Gui.new_concept('table')
|
Gui.new_concept('table')
|
||||||
:save_as('scroll_table')
|
:save_as('scroll_table')
|
||||||
:new_property('hight',nil,100)
|
:new_property('height',nil,100)
|
||||||
|
|
||||||
-- Add a scroll before the table is drawn
|
-- Add a scroll before the table is drawn
|
||||||
:define_pre_draw(function(properties,parent,element)
|
:define_pre_draw(function(properties,parent,element)
|
||||||
@@ -36,7 +36,7 @@ Gui.new_concept('table')
|
|||||||
-- Set the scroll style
|
-- Set the scroll style
|
||||||
Gui.set_padding(scroll,1,1,2,2)
|
Gui.set_padding(scroll,1,1,2,2)
|
||||||
scroll.style.horizontally_stretchable = true
|
scroll.style.horizontally_stretchable = true
|
||||||
scroll.style.maximal_height = properties.hight
|
scroll.style.maximal_height = properties.height
|
||||||
|
|
||||||
-- Change the name of the element to table before it is drawn
|
-- Change the name of the element to table before it is drawn
|
||||||
properties.name = 'table'
|
properties.name = 'table'
|
||||||
|
|||||||
@@ -4,11 +4,6 @@
|
|||||||
|
|
||||||
local Gui = require 'expcore.gui' -- @dep expcore.gui
|
local Gui = require 'expcore.gui' -- @dep expcore.gui
|
||||||
|
|
||||||
Gui.require_concept 'label' -- @dep gui.concept.frame
|
|
||||||
|
|
||||||
local right_align =
|
|
||||||
Gui.new_concept('alignment')
|
|
||||||
|
|
||||||
--[[-- A label triplet which has a static label, a data label which can be changed, and a unit label
|
--[[-- A label triplet which has a static label, a data label which can be changed, and a unit label
|
||||||
@see Gui.label
|
@see Gui.label
|
||||||
@see data_label
|
@see data_label
|
||||||
@@ -34,11 +29,8 @@ end)
|
|||||||
local unit_label =
|
local unit_label =
|
||||||
Gui.new_concept('data_label')
|
Gui.new_concept('data_label')
|
||||||
:save_as('unit_label')
|
:save_as('unit_label')
|
||||||
:new_property('data_label_name')
|
|
||||||
:new_property('data_caption')
|
|
||||||
:new_property('data_tooltip')
|
|
||||||
:new_property('data_unit')
|
:new_property('data_unit')
|
||||||
:new_property('data_format',nil,function(concept,element,data,...)
|
:set_data_format(function(concept,element,data,...)
|
||||||
local base_unit = concept.properties.data_unit
|
local base_unit = concept.properties.data_unit
|
||||||
local caption = tostring(data)
|
local caption = tostring(data)
|
||||||
local unit = data == 1 and base_unit or base_unit..'s'
|
local unit = data == 1 and base_unit or base_unit..'s'
|
||||||
@@ -53,6 +45,7 @@ end)
|
|||||||
-- Add the unit label
|
-- Add the unit label
|
||||||
parent.add{
|
parent.add{
|
||||||
name = element.name..'_unit',
|
name = element.name..'_unit',
|
||||||
|
type='label',
|
||||||
caption = unit or '',
|
caption = unit or '',
|
||||||
tooltip = element.tooltip
|
tooltip = element.tooltip
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,9 +232,9 @@ Gui.new_concept('toolbar-button')
|
|||||||
:save_as('toolbar-frame')
|
:save_as('toolbar-frame')
|
||||||
|
|
||||||
-- Properties
|
-- Properties
|
||||||
:new_property('open_by_default',false)
|
:new_property('open_by_default',nil,false)
|
||||||
:new_property('use_container',true)
|
:new_property('use_container',nil,true)
|
||||||
:new_property('direction','horizontal')
|
:new_property('direction',nil,'horizontal')
|
||||||
:new_event('on_update')
|
:new_event('on_update')
|
||||||
|
|
||||||
-- Clone
|
-- Clone
|
||||||
@@ -258,7 +258,6 @@ end)
|
|||||||
|
|
||||||
frame.style.padding = 2
|
frame.style.padding = 2
|
||||||
|
|
||||||
-- Add and return the container if a container is used
|
|
||||||
if properties.use_container then
|
if properties.use_container then
|
||||||
local container =
|
local container =
|
||||||
frame.add{
|
frame.add{
|
||||||
@@ -270,7 +269,6 @@ end)
|
|||||||
Gui.set_padding(container)
|
Gui.set_padding(container)
|
||||||
|
|
||||||
return container
|
return container
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
|
|||||||
@@ -9,16 +9,25 @@ local Roles = require 'expcore.roles' --- @dep expcore.roles
|
|||||||
local Store = require 'expcore.store' --- @dep expcore.store
|
local Store = require 'expcore.store' --- @dep expcore.store
|
||||||
local Game = require 'utils.game' --- @dep utils.game
|
local Game = require 'utils.game' --- @dep utils.game
|
||||||
local Event = require 'utils.event' --- @dep utils.event
|
local Event = require 'utils.event' --- @dep utils.event
|
||||||
local format_time = ext_require('expcore.common','format_time') --- @dep expcore.common
|
|
||||||
local config = require 'config.action_buttons' --- @dep config.action_buttons
|
local config = require 'config.action_buttons' --- @dep config.action_buttons
|
||||||
local Colors = require 'resources.color_presets' --- @dep resources.color_presets
|
local Colors = require 'resources.color_presets' --- @dep resources.color_presets
|
||||||
|
require 'expcore.toolbar' --- @dep expcore.toolbar
|
||||||
|
|
||||||
|
Gui.require_concept('label')
|
||||||
|
Gui.require_concept('button')
|
||||||
|
Gui.require_concept('text_field')
|
||||||
|
Gui.require_concept('frame')
|
||||||
|
Gui.require_style('expstyle')
|
||||||
|
|
||||||
local action_player_store = 'gui.left.player-list.action-player'
|
local action_player_store = 'gui.left.player-list.action-player'
|
||||||
local action_name_store = 'gui.left.player-list.action-name'
|
local action_name_store = 'gui.left.player-list.action-name'
|
||||||
|
|
||||||
--- used on player name label to allow zoom to map
|
--- Name label that alows zoom to map
|
||||||
local zoom_to_map_name = Gui.uid_name()
|
-- @element zoom_to_map
|
||||||
Gui.on_click(zoom_to_map_name,function(event)
|
local zoom_to_map =
|
||||||
|
Gui.new_concept('label')
|
||||||
|
:new_event('on_click',defines.events.on_gui_click)
|
||||||
|
:on_click(function(event)
|
||||||
local action_player_name = event.element.caption
|
local action_player_name = event.element.caption
|
||||||
local action_player = Game.get_player_from_any(action_player_name)
|
local action_player = Game.get_player_from_any(action_player_name)
|
||||||
if event.button == defines.mouse_button_type.left then
|
if event.button == defines.mouse_button_type.left then
|
||||||
@@ -36,136 +45,130 @@ Gui.on_click(zoom_to_map_name,function(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
:define_pre_draw(function(properties,parent,element)
|
||||||
|
-- Place the button into a flow
|
||||||
|
local flow =
|
||||||
|
parent.add{
|
||||||
|
type = 'flow',
|
||||||
|
}
|
||||||
|
|
||||||
|
return element, flow
|
||||||
|
end)
|
||||||
|
:define_draw(function(properties,parent,element,player,role_name)
|
||||||
|
local player_name = player.name
|
||||||
|
element.caption = player_name
|
||||||
|
element.tooltip = {'player-list.open-map',player_name,player.tag,role_name}
|
||||||
|
|
||||||
|
Gui.set_padding(element,0,0,0,2)
|
||||||
|
element.style.font_color = player.chat_color
|
||||||
|
end)
|
||||||
|
|
||||||
|
--- Right align for the time label
|
||||||
|
-- @element right_align
|
||||||
|
local right_align =
|
||||||
|
Gui.new_concept('alignment')
|
||||||
|
|
||||||
|
--- Shows the players online time
|
||||||
|
-- @element time_label
|
||||||
|
local time =
|
||||||
|
Gui.new_concept('time_label')
|
||||||
|
:set_time_format{minutes = true}
|
||||||
|
:set_time(0)
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
Gui.set_padding(element)
|
||||||
|
end)
|
||||||
|
|
||||||
--- Button used to open the action bar
|
--- Button used to open the action bar
|
||||||
-- @element open_action_bar
|
-- @element open_action_bar
|
||||||
local open_action_bar =
|
local open_action_bar =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/expand_dots_white')
|
:set_sprite('utility/expand_dots_white')
|
||||||
:set_tooltip{'player-list.open-action-bar'}
|
:set_tooltip{'player-list.open-action-bar'}
|
||||||
:set_embedded_flow(function(element,action_player_name)
|
:define_pre_draw(function(properties,parent,element,action_player_name)
|
||||||
return action_player_name
|
-- Place the button into a flow
|
||||||
|
local flow =
|
||||||
|
parent.add{
|
||||||
|
type = 'flow',
|
||||||
|
name = action_player_name
|
||||||
|
}
|
||||||
|
|
||||||
|
return element, flow
|
||||||
end)
|
end)
|
||||||
:set_style('frame_button',function(style)
|
:define_draw(function(properties,parent,element)
|
||||||
Gui.set_padding_style(style,-2,-2,-2,-2)
|
-- Update the style of the element
|
||||||
|
element.style = 'frame_button'
|
||||||
|
local style = element.style
|
||||||
|
style.padding = -2
|
||||||
style.width = 8
|
style.width = 8
|
||||||
style.height = 14
|
style.height = 14
|
||||||
end)
|
end)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
|
-- Open the action bar when pressed
|
||||||
|
local element = event.element
|
||||||
|
local player_name = event.player.name
|
||||||
local new_action_player_name = element.parent.name
|
local new_action_player_name = element.parent.name
|
||||||
local action_player_name = Store.get(action_player_store,player.name)
|
local action_player_name = Store.get(action_player_store,player_name)
|
||||||
if action_player_name == new_action_player_name then
|
if action_player_name == new_action_player_name then
|
||||||
Store.clear(action_player_store,player.name) -- will close if already open
|
Store.clear(action_player_store,player_name) -- will close if already open
|
||||||
else
|
else
|
||||||
Store.set(action_player_store,player.name,new_action_player_name)
|
Store.set(action_player_store,player_name,new_action_player_name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Button used to close the action bar
|
--- Button used to close the action bar
|
||||||
-- @element close_action_bar
|
-- @element close_action_bar
|
||||||
local close_action_bar =
|
local close_action_bar =
|
||||||
Gui.new_button()
|
Gui.new_concept('button')
|
||||||
:set_sprites('utility/close_black','utility/close_white')
|
:set_sprite('utility/close_black','utility/close_white')
|
||||||
:set_tooltip{'player-list.close-action-bar'}
|
:set_tooltip{'player-list.close-action-bar'}
|
||||||
:set_style('tool_button',function(style)
|
:define_draw(function(properties,parent,element)
|
||||||
Gui.set_padding_style(style,-1,-1,-1,-1)
|
-- Update the style of the element
|
||||||
|
element.style = 'tool_button'
|
||||||
|
local style = element.style
|
||||||
|
style.padding = -1
|
||||||
style.height = 28
|
style.height = 28
|
||||||
style.width = 28
|
style.width = 28
|
||||||
end)
|
end)
|
||||||
:on_click(function(player,element)
|
:on_click(function(event)
|
||||||
Store.clear(action_player_store,player.name)
|
-- Close the action bar
|
||||||
Store.clear(action_name_store,player.name)
|
local player_name = event.player.name
|
||||||
|
Store.clear(action_player_store,player_name)
|
||||||
|
Store.clear(action_name_store,player_name)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Button used to confirm a reason
|
--- Adds all the player info into the content table
|
||||||
-- @element reason_confirm
|
-- @element player_info
|
||||||
local reason_confirm =
|
local player_info =
|
||||||
Gui.new_button()
|
Gui.new_concept()
|
||||||
:set_sprites('utility/confirm_slot')
|
:define_draw(function(properties,parent,element,player,role_name)
|
||||||
:set_tooltip{'player-list.reason-confirm'}
|
local player_name = player.name
|
||||||
:set_style('tool_button',function(style)
|
open_action_bar:draw(parent,nil,player_name)
|
||||||
Gui.set_padding_style(style,-1,-1,-1,-1)
|
zoom_to_map:draw(parent,nil,player,role_name)
|
||||||
style.height = 28
|
time:update_time(time:draw(right_align:draw(parent,time.name..player_name)),player.online_time)
|
||||||
style.width = 28
|
|
||||||
end)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
local reason = element.parent.entry.text or 'Non Given'
|
|
||||||
local action_name = Store.get(action_name_store,player.name)
|
|
||||||
local reason_callback = config[action_name].reason_callback
|
|
||||||
reason_callback(player,reason)
|
|
||||||
Store.clear(action_player_store,player.name)
|
|
||||||
Store.clear(action_name_store,player.name)
|
|
||||||
element.parent.entry.text = ''
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--[[ Creates the main gui areas for the player list
|
--- Stores all the online players
|
||||||
element
|
-- @element content_table
|
||||||
> container
|
local content_table =
|
||||||
>> scroll
|
Gui.new_concept('scroll_table')
|
||||||
>>> table
|
:set_height(188)
|
||||||
>> action_bar
|
:set_column_count(3)
|
||||||
]]
|
|
||||||
local function generate_container(player,element)
|
|
||||||
Gui.set_padding(element,2,2,2,2)
|
|
||||||
element.style.minimal_width = 200
|
|
||||||
|
|
||||||
-- main container which contains the other elements
|
--- Stores all the action buttons
|
||||||
local container =
|
-- @element action_bar
|
||||||
element.add{
|
local action_bar =
|
||||||
name='container',
|
Gui.new_concept('frame')
|
||||||
type='frame',
|
:define_draw(function(properties,parent,element)
|
||||||
direction='vertical',
|
element.style = 'subfooter_frame'
|
||||||
style='window_content_frame_packed'
|
Gui.set_padding(element,1,1,3,3)
|
||||||
}
|
|
||||||
Gui.set_padding(container)
|
|
||||||
|
|
||||||
-- 3 wide table to contain: action button, player name, and play time
|
local style = element.style
|
||||||
local list_table = Gui.create_scroll_table(container,3,188)
|
style.horizontally_stretchable = true
|
||||||
|
style.height = 35
|
||||||
|
|
||||||
-- action bar which contains the different action buttons
|
close_action_bar:draw(element)
|
||||||
local action_bar =
|
|
||||||
container.add{
|
|
||||||
name='action_bar',
|
|
||||||
type='frame',
|
|
||||||
style='subfooter_frame'
|
|
||||||
}
|
|
||||||
Gui.set_padding(action_bar,1,1,3,3)
|
|
||||||
action_bar.style.horizontally_stretchable = true
|
|
||||||
action_bar.style.height = 35
|
|
||||||
|
|
||||||
-- reason bar which contains the reason text field and confirm button
|
local player = Gui.get_player_from_element(element)
|
||||||
local reason_bar =
|
|
||||||
container.add{
|
|
||||||
name='reason_bar',
|
|
||||||
type='frame',
|
|
||||||
style='subfooter_frame'
|
|
||||||
}
|
|
||||||
Gui.set_padding(reason_bar,-1,-1,3,3)
|
|
||||||
reason_bar.style.horizontally_stretchable = true
|
|
||||||
reason_bar.style.height = 35
|
|
||||||
local action_name = Store.get(action_name_store,player.name)
|
|
||||||
reason_bar.visible = action_name ~= nil
|
|
||||||
|
|
||||||
-- text entry for the reason bar
|
|
||||||
local reason_field =
|
|
||||||
reason_bar.add{
|
|
||||||
name='entry',
|
|
||||||
type='textfield',
|
|
||||||
style='stretchable_textfield',
|
|
||||||
tooltip={'player-list.reason-entry'}
|
|
||||||
}
|
|
||||||
Gui.set_padding(reason_field)
|
|
||||||
reason_field.style.height = 28
|
|
||||||
reason_field.style.minimal_width = 160
|
|
||||||
|
|
||||||
reason_confirm(reason_bar)
|
|
||||||
|
|
||||||
return list_table, action_bar
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Adds buttons and permission flows to the action bar
|
|
||||||
local function generate_action_bar(player,element)
|
|
||||||
close_action_bar(element)
|
|
||||||
local action_player = Store.get(action_player_store,player.name)
|
local action_player = Store.get(action_player_store,player.name)
|
||||||
|
|
||||||
for action_name,buttons in pairs(config) do
|
for action_name,buttons in pairs(config) do
|
||||||
@@ -176,7 +179,7 @@ local function generate_action_bar(player,element)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _,button in ipairs(buttons) do
|
for _,button in ipairs(buttons) do
|
||||||
button(permission_flow)
|
button:draw(permission_flow)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not Roles.player_allowed(player,action_name) then
|
if not Roles.player_allowed(player,action_name) then
|
||||||
@@ -186,18 +189,79 @@ local function generate_action_bar(player,element)
|
|||||||
if buttons.auth and action_player and not buttons.auth(player,action_player) then
|
if buttons.auth and action_player and not buttons.auth(player,action_player) then
|
||||||
permission_flow.visible = false
|
permission_flow.visible = false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not action_player then
|
if not action_player then
|
||||||
element.visible = false
|
element.visible = false
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
|
|
||||||
|
--- Text entry for reason
|
||||||
|
-- @element reason_field
|
||||||
|
local reason_field =
|
||||||
|
Gui.new_concept('text_field')
|
||||||
|
:set_tooltip{'player-list.reason-entry'}
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
element.style = 'stretchable_textfield'
|
||||||
|
local style = element.style
|
||||||
|
style.padding = 0
|
||||||
|
style.minimal_width = 160
|
||||||
|
style.height = 28
|
||||||
|
end)
|
||||||
|
|
||||||
|
--- Button used to confirm a reason
|
||||||
|
-- @element reason_confirm
|
||||||
|
local reason_confirm =
|
||||||
|
Gui.new_concept('button')
|
||||||
|
:set_sprite('utility/confirm_slot')
|
||||||
|
:set_tooltip{'player-list.reason-confirm'}
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
-- Update the style of the element
|
||||||
|
element.style = 'tool_button'
|
||||||
|
local style = element.style
|
||||||
|
style.padding = -1
|
||||||
|
style.height = 28
|
||||||
|
style.width = 28
|
||||||
|
end)
|
||||||
|
:on_click(function(event)
|
||||||
|
-- Confirm the reason given
|
||||||
|
local element = event.element
|
||||||
|
local player_name = event.player.name
|
||||||
|
local reason = element.parent.entry.text or 'Non Given'
|
||||||
|
local action_name = Store.get(action_name_store,player_name)
|
||||||
|
local reason_callback = config[action_name].reason_callback
|
||||||
|
reason_callback(event.player,reason)
|
||||||
|
Store.clear(action_player_store,player_name)
|
||||||
|
Store.clear(action_name_store,player_name)
|
||||||
|
element.parent.entry.text = ''
|
||||||
|
end)
|
||||||
|
|
||||||
|
--- Stores the reason entry and confirmation button
|
||||||
|
-- @element reason_bar
|
||||||
|
local reason_bar =
|
||||||
|
Gui.new_concept('frame')
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
element.style = 'subfooter_frame'
|
||||||
|
Gui.set_padding(element,-1,-1,3,3)
|
||||||
|
|
||||||
|
local style = element.style
|
||||||
|
style.horizontally_stretchable = true
|
||||||
|
style.height = 35
|
||||||
|
|
||||||
|
local player = Gui.get_player_from_element(element)
|
||||||
|
local action_name = Store.get(action_name_store,player.name)
|
||||||
|
element.visible = action_name ~= nil
|
||||||
|
|
||||||
|
reason_field:draw(element)
|
||||||
|
reason_confirm:draw(element)
|
||||||
|
end)
|
||||||
|
|
||||||
--- Updates the action bar
|
--- Updates the action bar
|
||||||
local player_list_name
|
local player_list
|
||||||
local function update_action_bar(player)
|
local function update_action_bar(player)
|
||||||
local frame = Gui.classes.left_frames.get_frame(player_list_name,player)
|
local content = player_list:get_content(player)
|
||||||
local element = frame.container.action_bar
|
local element = Gui.find(content,action_bar)
|
||||||
local action_player_name = Store.get(action_player_store,player.name)
|
local action_player_name = Store.get(action_player_store,player.name)
|
||||||
|
|
||||||
if not action_player_name then
|
if not action_player_name then
|
||||||
@@ -212,6 +276,7 @@ local function update_action_bar(player)
|
|||||||
element.visible = true
|
element.visible = true
|
||||||
for action_name,buttons in pairs(config) do
|
for action_name,buttons in pairs(config) do
|
||||||
if buttons.auth and not buttons.auth(player,action_player) then
|
if buttons.auth and not buttons.auth(player,action_player) then
|
||||||
|
print(action_name)
|
||||||
element[action_name].visible = false
|
element[action_name].visible = false
|
||||||
elseif Roles.player_allowed(player,action_name) then
|
elseif Roles.player_allowed(player,action_name) then
|
||||||
element[action_name].visible = true
|
element[action_name].visible = true
|
||||||
@@ -221,70 +286,37 @@ local function update_action_bar(player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Adds a player to the player list
|
|
||||||
local function add_player(list_table,player,role_name)
|
|
||||||
open_action_bar(list_table,player.name)
|
|
||||||
|
|
||||||
-- flow to contain player_name to allow all to have trigger for zoom to map
|
|
||||||
local player_name_flow =
|
|
||||||
list_table.add{
|
|
||||||
type='flow'
|
|
||||||
}
|
|
||||||
Gui.set_padding(player_name_flow)
|
|
||||||
|
|
||||||
-- player name with the tooltip of their highest role and in they colour
|
|
||||||
local player_name =
|
|
||||||
player_name_flow.add{
|
|
||||||
name=zoom_to_map_name,
|
|
||||||
type='label',
|
|
||||||
caption=player.name,
|
|
||||||
tooltip={'player-list.open-map',player.name,player.tag,role_name}
|
|
||||||
}
|
|
||||||
Gui.set_padding(player_name,0,0,0,2)
|
|
||||||
player_name.style.font_color = player.chat_color
|
|
||||||
|
|
||||||
-- flow which allows right align for the play time
|
|
||||||
local time_flow = Gui.create_alignment(list_table,'player-time-'..player.index)
|
|
||||||
|
|
||||||
-- time given in Xh Ym and is right aligned
|
|
||||||
local tick = game.tick > 0 and game.tick or 1
|
|
||||||
local percent = math.round(player.online_time/tick,3)*100
|
|
||||||
local time =
|
|
||||||
time_flow.add{
|
|
||||||
name='label',
|
|
||||||
type='label',
|
|
||||||
caption=format_time(player.online_time),
|
|
||||||
tooltip={'player-list.afk-time',percent,format_time(player.afk_time,{minutes=true,long=true})}
|
|
||||||
}
|
|
||||||
Gui.set_padding(time)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Adds fake players to the player list
|
--- Adds fake players to the player list
|
||||||
local function add_fake_players(list_table,count)
|
local function add_fake_players(content_area,count)
|
||||||
local role_name = 'Fake Player'
|
local role_name = 'Fake Player'
|
||||||
for i = 1,count do
|
for i = 1,count do
|
||||||
add_player(list_table,{
|
local player = {
|
||||||
name='Player '..i,
|
name='Player '..i,
|
||||||
index=0-i,
|
index=0-i,
|
||||||
tag='',
|
tag='',
|
||||||
online_time=math.random(0,game.tick),
|
online_time=math.random(0,game.tick),
|
||||||
afk_time=math.random(0,game.tick),
|
afk_time=math.random(0,game.tick),
|
||||||
chat_color=table.get_random_dictionary_entry(Colors)
|
chat_color=table.get_random_dictionary_entry(Colors)
|
||||||
},role_name)
|
}
|
||||||
|
|
||||||
|
player_info:draw(content_area,nil,player,role_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Registers the player list
|
--- Registers the player list
|
||||||
-- @element player_list
|
-- @element player_list
|
||||||
local player_list =
|
player_list =
|
||||||
Gui.new_left_frame('gui/player-list')
|
Gui.new_concept('toolbar-frame')
|
||||||
:set_sprites('entity/character')
|
:set_permission_alias('gui/player-list')
|
||||||
|
:set_sprite('entity/character')
|
||||||
:set_tooltip{'player-list.main-tooltip'}
|
:set_tooltip{'player-list.main-tooltip'}
|
||||||
:set_open_by_default()
|
:set_open_by_default(true)
|
||||||
:set_direction('vertical')
|
:set_direction('vertical')
|
||||||
:on_creation(function(player,element)
|
:define_draw(function(properties,parent,element)
|
||||||
local list_table,action_bar = generate_container(player,element)
|
local content_area =
|
||||||
generate_action_bar(player,action_bar)
|
content_table:draw(element)
|
||||||
|
action_bar:draw(element)
|
||||||
|
reason_bar:draw(element)
|
||||||
|
|
||||||
local players = {}
|
local players = {}
|
||||||
for _,next_player in pairs(game.connected_players) do
|
for _,next_player in pairs(game.connected_players) do
|
||||||
@@ -298,55 +330,49 @@ Gui.new_left_frame('gui/player-list')
|
|||||||
for _,role_name in pairs(Roles.config.order) do
|
for _,role_name in pairs(Roles.config.order) do
|
||||||
if players[role_name] then
|
if players[role_name] then
|
||||||
for _,next_player in pairs(players[role_name]) do
|
for _,next_player in pairs(players[role_name]) do
|
||||||
add_player(list_table,next_player,role_name)
|
player_info:draw(content_area,nil,next_player,role_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--add_fake_players(list_table,6)
|
add_fake_players(content_area,4)
|
||||||
--add_fake_players(list_table,20)
|
|
||||||
end)
|
end)
|
||||||
:on_update(function(player,element)
|
:on_update(function(event)
|
||||||
local list = element.container.scroll.table
|
local list = Gui.find(event.element,content_table,'table')
|
||||||
for _,next_player in pairs(game.connected_players) do
|
for _,next_player in pairs(game.connected_players) do
|
||||||
local time_element_name = 'player-time-'..next_player.index
|
local time_element = Gui.find(list,time.name..next_player.name,time)
|
||||||
local time_element = list[time_element_name]
|
|
||||||
if time_element and time_element.valid then
|
if time_element and time_element.valid then
|
||||||
time_element.label.caption = format_time(next_player.online_time)
|
time:update_time(time_element,next_player.online_time)
|
||||||
local tick = game.tick > 0 and game.tick or 1
|
|
||||||
local percent = math.round(next_player.online_time/tick,3)*100
|
|
||||||
time_element.label.tooltip = {'player-list.afk-time',percent,format_time(next_player.afk_time,{minutes=true,long=true})}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
player_list_name = player_list:uid()
|
|
||||||
|
|
||||||
--- When the action player is changed the action bar will update
|
--- When the action player is changed the action bar will update
|
||||||
Store.register(action_player_store,function(value,category)
|
Store.register(action_player_store,function(value,category)
|
||||||
local player = Game.get_player_from_any(category)
|
local player = Game.get_player_from_any(category)
|
||||||
update_action_bar(player)
|
update_action_bar(player)
|
||||||
|
|
||||||
local frame = player_list:get_frame(player)
|
local frame = player_list:get_content(player)
|
||||||
local data_table = frame.container.scroll.table
|
local data_table = Gui.find(frame,content_table,'table')
|
||||||
for _,next_player in pairs(game.connected_players) do
|
for _,next_player in pairs(game.connected_players) do
|
||||||
local element = data_table[next_player.name][open_action_bar.name]
|
local element = Gui.find(data_table,next_player.name,open_action_bar)
|
||||||
local style = 'frame_button'
|
local style = 'frame_button'
|
||||||
if next_player.name == value then
|
if next_player.name == value then
|
||||||
style = 'tool_button'
|
style = 'tool_button'
|
||||||
end
|
end
|
||||||
element.style = style
|
element.style = style
|
||||||
Gui.set_padding(element,-2,-2,-2,-2)
|
style = element.style
|
||||||
element.style.width = 8
|
style.padding = -2
|
||||||
element.style.height = 14
|
style.width = 8
|
||||||
|
style.height = 14
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- When the action name is changed the reason input will update
|
--- When the action name is changed the reason input will update
|
||||||
Store.register(action_name_store,function(value,category)
|
Store.register(action_name_store,function(value,category)
|
||||||
local player = Game.get_player_from_any(category)
|
local player = Game.get_player_from_any(category)
|
||||||
local frame = Gui.classes.left_frames.get_frame(player_list_name,player)
|
local frame = player_list:get_content(player)
|
||||||
local element = frame.container.reason_bar
|
local element = Gui.find(frame,reason_bar)
|
||||||
if value then
|
if value then
|
||||||
local action_player_name = Store.get(action_player_store,category)
|
local action_player_name = Store.get(action_player_store,category)
|
||||||
local action_player = Game.get_player_from_any(action_player_name)
|
local action_player = Game.get_player_from_any(action_player_name)
|
||||||
@@ -362,10 +388,11 @@ Store.register(action_name_store,function(value,category)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- Many events which trigger the gui to be re drawn, it will also update the times every 30 seconds
|
--- Many events which trigger the gui to be re drawn, it will also update the times every 30 seconds
|
||||||
Event.on_nth_tick(1800,player_list 'update_all')
|
local update = function(event) player_list:update_all(event) end
|
||||||
Event.add(defines.events.on_player_joined_game,player_list 'redraw_all')
|
Event.on_nth_tick(1800,update)
|
||||||
Event.add(defines.events.on_player_left_game,player_list 'redraw_all')
|
Event.add(defines.events.on_player_joined_game,update)
|
||||||
Event.add(Roles.events.on_role_assigned,player_list 'redraw_all')
|
Event.add(defines.events.on_player_left_game,update)
|
||||||
Event.add(Roles.events.on_role_unassigned,player_list 'redraw_all')
|
Event.add(Roles.events.on_role_assigned,update)
|
||||||
|
Event.add(Roles.events.on_role_unassigned,update)
|
||||||
|
|
||||||
return player_list
|
return player_list
|
||||||
Reference in New Issue
Block a user