mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Player list added
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
|
||||||
|
|||||||
@@ -22,13 +22,6 @@ local function set_store_uids(player,action)
|
|||||||
selected_action_store = action
|
selected_action_store = action
|
||||||
end
|
end
|
||||||
|
|
||||||
-- common style used by all action buttons
|
|
||||||
local function tool_button_style(style)
|
|
||||||
Gui.set_padding_style(style,-1,-1,-1,-1)
|
|
||||||
style.height = 28
|
|
||||||
style.width = 28
|
|
||||||
end
|
|
||||||
|
|
||||||
-- auth that will only allow when on player's of lower roles
|
-- auth that will only allow when on player's of lower roles
|
||||||
local function auth_lower_role(player,selected_player_name)
|
local function auth_lower_role(player,selected_player_name)
|
||||||
local player_highest = Roles.get_player_highest_role(player)
|
local player_highest = Roles.get_player_highest_role(player)
|
||||||
@@ -56,14 +49,23 @@ local function teleport(from_player,to_player)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function new_button(sprite,tooltip)
|
||||||
|
return Gui.element{
|
||||||
|
type = 'sprite-button',
|
||||||
|
style = 'tool_button',
|
||||||
|
sprite = sprite,
|
||||||
|
tooltip = tooltip
|
||||||
|
}:style{
|
||||||
|
padding = -1,
|
||||||
|
height = 28,
|
||||||
|
width = 28
|
||||||
|
}
|
||||||
|
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 = new_button('utility/export',{'player-list.goto-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/export')
|
|
||||||
:set_tooltip{'player-list.goto-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
local selected_player_name = get_action_player_name(player)
|
local selected_player_name = get_action_player_name(player)
|
||||||
local selected_player = Game.get_player_from_any(selected_player_name)
|
local selected_player = Game.get_player_from_any(selected_player_name)
|
||||||
if not player.character or not selected_player.character then
|
if not player.character or not selected_player.character then
|
||||||
@@ -75,12 +77,8 @@ 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 = new_button('utility/import',{'player-list.bring-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/import')
|
|
||||||
:set_tooltip{'player-list.bring-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
local selected_player_name = get_action_player_name(player)
|
local selected_player_name = get_action_player_name(player)
|
||||||
local selected_player = Game.get_player_from_any(selected_player_name)
|
local selected_player = Game.get_player_from_any(selected_player_name)
|
||||||
if not player.character or not selected_player.character then
|
if not player.character or not selected_player.character then
|
||||||
@@ -92,12 +90,8 @@ 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 = new_button('utility/too_far',{'player-list.kill-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/too_far')
|
|
||||||
:set_tooltip{'player-list.kill-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
local selected_player_name = get_action_player_name(player)
|
local selected_player_name = get_action_player_name(player)
|
||||||
local selected_player = Game.get_player_from_any(selected_player_name)
|
local selected_player = Game.get_player_from_any(selected_player_name)
|
||||||
if selected_player.character then
|
if selected_player.character then
|
||||||
@@ -109,12 +103,8 @@ 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 = new_button('utility/spawn_flag',{'player-list.report-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/spawn_flag')
|
|
||||||
:set_tooltip{'player-list.report-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
local selected_player_name = get_action_player_name(player)
|
local selected_player_name = get_action_player_name(player)
|
||||||
if Reports.is_reported(selected_player_name,player.name) then
|
if Reports.is_reported(selected_player_name,player.name) then
|
||||||
player.print({'expcom-report.already-reported'},Colors.orange_red)
|
player.print({'expcom-report.already-reported'},Colors.orange_red)
|
||||||
@@ -133,12 +123,8 @@ 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 = new_button('utility/spawn_flag',{'player-list.warn-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/spawn_flag')
|
|
||||||
:set_tooltip{'player-list.warn-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
Store.set(selected_action_store,player,'command/give-warning')
|
Store.set(selected_action_store,player,'command/give-warning')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -151,12 +137,8 @@ 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 = new_button('utility/item_editor_icon',{'player-list.jail-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/item_editor_icon')
|
|
||||||
:set_tooltip{'player-list.jail-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
local selected_player_name, selected_player_color = get_action_player_name(player)
|
local selected_player_name, selected_player_color = get_action_player_name(player)
|
||||||
if Jail.is_jailed(selected_player_name) then
|
if Jail.is_jailed(selected_player_name) then
|
||||||
player.print({'expcom-jail.already-jailed', selected_player_color},Colors.orange_red)
|
player.print({'expcom-jail.already-jailed', selected_player_color},Colors.orange_red)
|
||||||
@@ -174,12 +156,8 @@ 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 = new_button('utility/clock',{'player-list.temp-ban-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/clock')
|
|
||||||
:set_tooltip{'player-list.temp-ban-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
local selected_player_name, selected_player_color = get_action_player_name(player)
|
local selected_player_name, selected_player_color = get_action_player_name(player)
|
||||||
if Jail.is_jailed(selected_player_name) then
|
if Jail.is_jailed(selected_player_name) then
|
||||||
player.print({'expcom-jail.already-banned', selected_player_color},Colors.orange_red)
|
player.print({'expcom-jail.already-banned', selected_player_color},Colors.orange_red)
|
||||||
@@ -197,12 +175,8 @@ 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 = new_button('utility/warning_icon',{'player-list.kick-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/warning_icon')
|
|
||||||
:set_tooltip{'player-list.kick-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
Store.set(selected_action_store,player,'command/kick')
|
Store.set(selected_action_store,player,'command/kick')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -213,12 +187,8 @@ 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 = new_button('utility/danger_icon',{'player-list.ban-player'})
|
||||||
Gui.new_button()
|
:on_click(function(player)
|
||||||
:set_sprites('utility/danger_icon')
|
|
||||||
:set_tooltip{'player-list.ban-player'}
|
|
||||||
:set_style('tool_button',tool_button_style)
|
|
||||||
:on_click(function(player,element)
|
|
||||||
Store.set(selected_action_store,player,'command/ban')
|
Store.set(selected_action_store,player,'command/ban')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -26,42 +26,21 @@ end)
|
|||||||
-- Set the config to use these stores
|
-- Set the config to use these stores
|
||||||
config.set_store_uids(selected_player_store,selected_action_store)
|
config.set_store_uids(selected_player_store,selected_action_store)
|
||||||
|
|
||||||
--- Used to open the map on a player or toggle the settings
|
|
||||||
local zoom_to_map_name = Gui.uid_name()
|
|
||||||
Gui.on_click(zoom_to_map_name,function(event)
|
|
||||||
local selected_player_name = event.element.caption
|
|
||||||
local selected_player = Game.get_player_from_any(selected_player_name)
|
|
||||||
if event.button == defines.mouse_button_type.left then
|
|
||||||
-- LMB will open the map to the selected player
|
|
||||||
local position = selected_player.position
|
|
||||||
event.player.zoom_to_world(position,1.75)
|
|
||||||
else
|
|
||||||
-- RMB will toggle the settings
|
|
||||||
local player = event.player
|
|
||||||
local old_selected_player_name = Store.get(selected_player_store,player)
|
|
||||||
if selected_player_name == old_selected_player_name then
|
|
||||||
Store.clear(selected_player_store,player)
|
|
||||||
else
|
|
||||||
Store.set(selected_player_store,player,selected_player_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
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.element{
|
||||||
:set_sprites('utility/expand_dots_white')
|
type = 'sprite-button',
|
||||||
:set_tooltip{'player-list.open-action-bar'}
|
sprite = 'utility/expand_dots_white',
|
||||||
:set_embedded_flow(function(element,selected_player_name)
|
tooltip = {'player-list.open-action-bar'},
|
||||||
return selected_player_name
|
style = 'frame_button'
|
||||||
end)
|
}
|
||||||
:set_style('frame_button',function(style)
|
:style{
|
||||||
Gui.set_padding_style(style,-2,-2,-2,-2)
|
padding = -2,
|
||||||
style.width = 8
|
width = 8,
|
||||||
style.height = 14
|
height = 14
|
||||||
end)
|
}
|
||||||
:on_click(function(player,element)
|
:on_click(function(player,element,_)
|
||||||
local selected_player_name = element.parent.name
|
local selected_player_name = element.parent.name
|
||||||
local old_selected_player_name = Store.get(selected_player_store,player)
|
local old_selected_player_name = Store.get(selected_player_store,player)
|
||||||
if selected_player_name == old_selected_player_name then
|
if selected_player_name == old_selected_player_name then
|
||||||
@@ -74,14 +53,18 @@ 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.element{
|
||||||
:set_sprites('utility/close_black','utility/close_white')
|
type = 'sprite-button',
|
||||||
:set_tooltip{'player-list.close-action-bar'}
|
sprite = 'utility/close_black',
|
||||||
:set_style('tool_button',function(style)
|
hovered_sprite = 'utility/close_white',
|
||||||
Gui.set_padding_style(style,-1,-1,-1,-1)
|
tooltip = {'player-list.close-action-bar'},
|
||||||
style.height = 28
|
style = 'tool_button'
|
||||||
style.width = 28
|
}
|
||||||
end)
|
:style{
|
||||||
|
padding = -1,
|
||||||
|
width = 28,
|
||||||
|
height = 28
|
||||||
|
}
|
||||||
:on_click(function(player,element)
|
:on_click(function(player,element)
|
||||||
Store.clear(selected_player_store,player)
|
Store.clear(selected_player_store,player)
|
||||||
Store.clear(selected_action_store,player)
|
Store.clear(selected_action_store,player)
|
||||||
@@ -90,14 +73,17 @@ end)
|
|||||||
--- Button used to confirm a reason
|
--- Button used to confirm a reason
|
||||||
-- @element reason_confirm
|
-- @element reason_confirm
|
||||||
local reason_confirm =
|
local reason_confirm =
|
||||||
Gui.new_button()
|
Gui.element{
|
||||||
:set_sprites('utility/confirm_slot')
|
type = 'sprite-button',
|
||||||
:set_tooltip{'player-list.reason-confirm'}
|
sprite = 'utility/confirm_slot',
|
||||||
:set_style('tool_button',function(style)
|
tooltip = {'player-list.reason-confirm'},
|
||||||
Gui.set_padding_style(style,-1,-1,-1,-1)
|
style = 'tool_button'
|
||||||
style.height = 28
|
}
|
||||||
style.width = 28
|
:style{
|
||||||
end)
|
padding = -1,
|
||||||
|
width = 28,
|
||||||
|
height = 28
|
||||||
|
}
|
||||||
:on_click(function(player,element)
|
:on_click(function(player,element)
|
||||||
local reason = element.parent.entry.text or 'Non Given'
|
local reason = element.parent.entry.text or 'Non Given'
|
||||||
local action_name = Store.get(selected_action_store,player)
|
local action_name = Store.get(selected_action_store,player)
|
||||||
@@ -108,106 +94,98 @@ end)
|
|||||||
element.parent.entry.text = ''
|
element.parent.entry.text = ''
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--[[ Creates the main gui areas for the player list
|
--- Set of elements that are used to make up a row of the player table
|
||||||
element
|
-- @element add_player_base
|
||||||
> container
|
local add_player_base =
|
||||||
>> scroll
|
Gui.element(function(event_trigger,parent,player_data)
|
||||||
>>> table
|
-- Add the button to open the action bar
|
||||||
>> action_bar
|
local toggle_action_bar_flow = parent.add{ type = 'flow', name = player_data.name }
|
||||||
]]
|
open_action_bar(toggle_action_bar_flow)
|
||||||
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
|
-- Add the player name
|
||||||
local container =
|
local player_name_flow = parent.add{ type = 'flow', 'player-name-'..player_data.index }
|
||||||
element.add{
|
local player_name = player_name_flow.add{
|
||||||
name='container',
|
type = 'label',
|
||||||
type='frame',
|
name = event_trigger,
|
||||||
direction='vertical',
|
caption = player_data.name,
|
||||||
style='window_content_frame_packed'
|
tooltip = {'player-list.open-map',player_data.name,player_data.tag,player_data.role_name}
|
||||||
}
|
}
|
||||||
Gui.set_padding(container)
|
player_name.style.padding = {0,2,0,0}
|
||||||
|
player_name.style.font_color = player_data.chat_color
|
||||||
|
|
||||||
-- 3 wide table to contain: action button, player name, and play time
|
-- Add the time played label
|
||||||
local list_table = Gui.create_scroll_table(container,3,188)
|
local alignment = Gui.alignment(parent,nil,nil,'player-time-'..player_data.index)
|
||||||
|
local time_label = alignment.add{
|
||||||
-- action bar which contains the different action buttons
|
name = 'label',
|
||||||
local action_bar =
|
type = 'label',
|
||||||
container.add{
|
caption = player_data.caption,
|
||||||
name='action_bar',
|
tooltip = player_data.tooltip
|
||||||
type='frame',
|
|
||||||
style='subfooter_frame'
|
|
||||||
}
|
}
|
||||||
Gui.set_padding(action_bar,1,1,3,3)
|
time_label.style.padding = 0
|
||||||
action_bar.style.horizontally_stretchable = true
|
|
||||||
action_bar.style.height = 35
|
|
||||||
|
|
||||||
-- reason bar which contains the reason text field and confirm button
|
return time_label
|
||||||
local reason_bar =
|
end)
|
||||||
container.add{
|
:on_click(function(player,element,event)
|
||||||
name='reason_bar',
|
local selected_player_name = element.caption
|
||||||
type='frame',
|
local selected_player = Game.get_player_from_any(selected_player_name)
|
||||||
style='subfooter_frame'
|
if event.button == defines.mouse_button_type.left then
|
||||||
}
|
-- LMB will open the map to the selected player
|
||||||
Gui.set_padding(reason_bar,-1,-1,3,3)
|
local position = selected_player.position
|
||||||
reason_bar.style.horizontally_stretchable = true
|
event.player.zoom_to_world(position,1.75)
|
||||||
reason_bar.style.height = 35
|
else
|
||||||
local action_name = Store.get(selected_action_store,player)
|
-- RMB will toggle the settings
|
||||||
reason_bar.visible = action_name ~= nil
|
local old_selected_player_name = Store.get(selected_player_store,player)
|
||||||
|
if selected_player_name == old_selected_player_name then
|
||||||
|
Store.clear(selected_player_store,player)
|
||||||
|
else
|
||||||
|
Store.set(selected_player_store,player,selected_player_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- text entry for the reason bar
|
-- Removes the three elements that are added as part of the base
|
||||||
local reason_field =
|
local function remove_player_base(parent,player)
|
||||||
reason_bar.add{
|
Gui.destroy_if_valid(parent[player.name])
|
||||||
name='entry',
|
Gui.destroy_if_valid(parent['player-name-'..player.index])
|
||||||
type='textfield',
|
Gui.destroy_if_valid(parent['player-time-'..player.index])
|
||||||
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
|
end
|
||||||
|
|
||||||
--- Adds buttons and permission flows to the action bar
|
-- Update the time label for a player using there player time data
|
||||||
local function generate_action_bar(player,element)
|
local function update_player_base(parent,player_time)
|
||||||
close_action_bar(element)
|
local time_element = parent[player_time.element_name]
|
||||||
local selected_player_name = Store.get(selected_player_store,player)
|
if time_element and time_element.valid then
|
||||||
|
time_element.label.caption = player_time.caption
|
||||||
|
time_element.label.tooltip = player_time.tooltip
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for action_name,buttons in pairs(config.buttons) do
|
--- Adds all the buttons and flows that make up the action bar
|
||||||
|
-- @element add_action_bar
|
||||||
|
local add_action_bar_buttons =
|
||||||
|
Gui.element(function(_,parent)
|
||||||
|
close_action_bar(parent)
|
||||||
|
-- Loop over all the buttons in the config
|
||||||
|
for action_name,button_data in pairs(config.buttons) do
|
||||||
|
-- Added the permission flow
|
||||||
local permission_flow =
|
local permission_flow =
|
||||||
element.add{
|
parent.add{
|
||||||
type='flow',
|
type = 'flow',
|
||||||
name=action_name
|
name = action_name
|
||||||
}
|
}
|
||||||
|
-- Add the buttons under that permission
|
||||||
for _,button in ipairs(buttons) do
|
for _,button in ipairs(button_data) do
|
||||||
button(permission_flow)
|
button(permission_flow)
|
||||||
end
|
end
|
||||||
|
-- Hide the flow by default, will be made visble when a player is selected
|
||||||
if not Roles.player_allowed(player,action_name) then
|
permission_flow.visible = false
|
||||||
permission_flow.visible = false
|
|
||||||
end
|
|
||||||
|
|
||||||
if buttons.auth and selected_player_name and not buttons.auth(player,selected_player_name) then
|
|
||||||
permission_flow.visible = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not selected_player_name then
|
return parent
|
||||||
element.visible = false
|
end)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Updates the action bar
|
--- Updates the visible state of the action bar buttons
|
||||||
local player_list_name
|
local function update_action_bar_buttons(element)
|
||||||
local function update_action_bar(player)
|
local player = Gui.get_player_from_element(element)
|
||||||
local frame = Gui.classes.left_frames.get_frame(player_list_name,player)
|
|
||||||
local element = frame.container.action_bar
|
|
||||||
local selected_player_name = Store.get(selected_player_store,player)
|
local selected_player_name = Store.get(selected_player_store,player)
|
||||||
|
|
||||||
if not selected_player_name then
|
if not selected_player_name then
|
||||||
@@ -236,132 +214,256 @@ local function update_action_bar(player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Adds a player to the player list
|
--- Main player list container for the left flow
|
||||||
local function add_player(list_table,player,role_name)
|
-- @element player_list_container
|
||||||
open_action_bar(list_table,player.name)
|
local player_list_container =
|
||||||
|
Gui.element(function(event_trigger,parent)
|
||||||
-- flow to contain player_name to allow all to have trigger for zoom to map
|
-- Draw the external container
|
||||||
local player_name_flow =
|
local frame =
|
||||||
list_table.add{
|
parent.add{
|
||||||
type='flow'
|
name = event_trigger,
|
||||||
|
type = 'frame'
|
||||||
}
|
}
|
||||||
Gui.set_padding(player_name_flow)
|
|
||||||
|
|
||||||
-- player name with the tooltip of their highest role and in they colour
|
-- Set the frame style
|
||||||
local player_name =
|
local frame_style = frame.style
|
||||||
player_name_flow.add{
|
frame_style.padding = 2
|
||||||
name=zoom_to_map_name,
|
frame_style.minimal_width = 200
|
||||||
type='label',
|
|
||||||
caption=player.name,
|
-- Draw the internal container
|
||||||
tooltip={'player-list.open-map',player.name,player.tag,role_name}
|
local container =
|
||||||
|
frame.add{
|
||||||
|
name = 'container',
|
||||||
|
type = 'frame',
|
||||||
|
direction = 'vertical',
|
||||||
|
style = 'window_content_frame_packed'
|
||||||
}
|
}
|
||||||
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
|
-- Set the container style
|
||||||
local time_flow = Gui.create_alignment(list_table,'player-time-'..player.index)
|
local style = container.style
|
||||||
|
style.vertically_stretchable = false
|
||||||
|
|
||||||
-- time given in Xh Ym and is right aligned
|
-- Draw the scroll table for the players
|
||||||
local tick = game.tick > 0 and game.tick or 1
|
local scroll_table = Gui.scroll_table(container,184,3)
|
||||||
local percent = math.round(player.online_time/tick,3)*100
|
|
||||||
local time =
|
-- Change the style of the scroll table
|
||||||
time_flow.add{
|
local scroll_table_style = scroll_table.style
|
||||||
name='label',
|
scroll_table_style.padding = {1,0,1,2}
|
||||||
type='label',
|
|
||||||
caption=format_time(player.online_time),
|
-- Add the action bar
|
||||||
tooltip={'player-list.afk-time',percent,format_time(player.afk_time,{minutes=true,long=true})}
|
local action_bar =
|
||||||
|
container.add{
|
||||||
|
name = 'action_bar',
|
||||||
|
type = 'frame',
|
||||||
|
style = 'subfooter_frame'
|
||||||
}
|
}
|
||||||
Gui.set_padding(time)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Adds fake players to the player list
|
-- Change the style of the action bar
|
||||||
local function add_fake_players(list_table,count)
|
local action_bar_style = action_bar.style
|
||||||
local role_name = 'Fake Player'
|
action_bar_style.height = 35
|
||||||
for i = 1,count do
|
action_bar_style.padding = {1,3}
|
||||||
add_player(list_table,{
|
action_bar_style.use_header_filler = false
|
||||||
name='Player '..i,
|
action_bar_style.horizontally_stretchable = true
|
||||||
index=0-i,
|
action_bar.visible = false
|
||||||
tag='',
|
|
||||||
online_time=math.random(0,game.tick),
|
-- Add the buttons to the action bar
|
||||||
afk_time=math.random(0,game.tick),
|
add_action_bar_buttons(action_bar)
|
||||||
chat_color=table.get_random_dictionary_entry(Colors)
|
|
||||||
},role_name)
|
-- Add the reason bar
|
||||||
|
local reason_bar =
|
||||||
|
container.add{
|
||||||
|
name = 'reason_bar',
|
||||||
|
type = 'frame',
|
||||||
|
style = 'subfooter_frame'
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Change the style of the reason bar
|
||||||
|
local reason_bar_style = reason_bar.style
|
||||||
|
reason_bar_style.height = 35
|
||||||
|
reason_bar_style.padding = {-1,3}
|
||||||
|
reason_bar_style.use_header_filler = false
|
||||||
|
reason_bar_style.horizontally_stretchable = true
|
||||||
|
reason_bar.visible = false
|
||||||
|
|
||||||
|
-- Add the text entry for the reason bar
|
||||||
|
local reason_field =
|
||||||
|
reason_bar.add{
|
||||||
|
name = 'entry',
|
||||||
|
type = 'textfield',
|
||||||
|
style = 'stretchable_textfield',
|
||||||
|
tooltip = {'player-list.reason-entry'}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Change the style of the text entry
|
||||||
|
local reason_entry_style = reason_field.style
|
||||||
|
reason_entry_style.padding = 0
|
||||||
|
reason_entry_style.height = 28
|
||||||
|
reason_entry_style.minimal_width = 160
|
||||||
|
|
||||||
|
-- Add the confirm reason button
|
||||||
|
reason_confirm(reason_bar)
|
||||||
|
|
||||||
|
-- Return the exteral container
|
||||||
|
return frame
|
||||||
|
end)
|
||||||
|
:add_to_left_flow(true)
|
||||||
|
|
||||||
|
--- Button on the top flow used to toggle the player list container
|
||||||
|
-- @element task_list_toggle
|
||||||
|
Gui.element{
|
||||||
|
type = 'sprite-button',
|
||||||
|
sprite = 'entity/character',
|
||||||
|
tooltip = {'player-list.main-tooltip'},
|
||||||
|
style = Gui.top_flow_button_style
|
||||||
|
}
|
||||||
|
:style{
|
||||||
|
padding = -2
|
||||||
|
}
|
||||||
|
:add_to_top_flow(function(player)
|
||||||
|
return Roles.player_allowed(player,'gui/player-list')
|
||||||
|
end)
|
||||||
|
:on_click(function(player,_,_)
|
||||||
|
Gui.toggle_left_element(player, player_list_container)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Get the player time to be used to update time label
|
||||||
|
local function get_player_times()
|
||||||
|
local ctn = 0
|
||||||
|
local player_times = {}
|
||||||
|
for _, player in pairs(game.connected_players) do
|
||||||
|
ctn = ctn + 1
|
||||||
|
local tick = game.tick > 0 and game.tick or 1
|
||||||
|
local percent = math.round(player.online_time/tick,3)*100
|
||||||
|
player_times[ctn] = {
|
||||||
|
element_name = 'player-time-'..player.index,
|
||||||
|
caption = format_time(player.online_time),
|
||||||
|
tooltip = {'player-list.afk-time',percent,format_time(player.afk_time,{minutes=true,long=true})}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return player_times
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Registers the player list
|
local function get_player_list_order()
|
||||||
-- @element player_list
|
-- Sort all the online players into roles
|
||||||
local player_list =
|
|
||||||
Gui.new_left_frame('gui/player-list')
|
|
||||||
:set_sprites('entity/character')
|
|
||||||
:set_tooltip{'player-list.main-tooltip'}
|
|
||||||
:set_open_by_default()
|
|
||||||
:set_direction('vertical')
|
|
||||||
:on_creation(function(player,element)
|
|
||||||
local list_table,action_bar = generate_container(player,element)
|
|
||||||
generate_action_bar(player,action_bar)
|
|
||||||
|
|
||||||
local players = {}
|
local players = {}
|
||||||
for _,next_player in pairs(game.connected_players) do
|
for _,player in pairs(game.connected_players) do
|
||||||
local highest_role = Roles.get_player_highest_role(next_player)
|
local highest_role = Roles.get_player_highest_role(player)
|
||||||
if not players[highest_role.name] then
|
if not players[highest_role.name] then
|
||||||
players[highest_role.name] = {}
|
players[highest_role.name] = {}
|
||||||
end
|
end
|
||||||
table.insert(players[highest_role.name],next_player)
|
table.insert(players[highest_role.name],player)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Sort the players from roles into a set order
|
||||||
|
local ctn = 0
|
||||||
|
local player_list_order = {}
|
||||||
|
local tick = game.tick > 0 and game.tick or 1
|
||||||
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 _,player in pairs(players[role_name]) do
|
||||||
add_player(list_table,next_player,role_name)
|
ctn = ctn + 1
|
||||||
|
local percent = math.round(player.online_time/tick,3)*100
|
||||||
|
player_list_order[ctn] = {
|
||||||
|
name = player.name,
|
||||||
|
index = player.index,
|
||||||
|
tag = player.tag,
|
||||||
|
role_name = role_name,
|
||||||
|
chat_color = player.chat_color,
|
||||||
|
caption = format_time(player.online_time),
|
||||||
|
tooltip = {'player-list.afk-time',percent,format_time(player.afk_time,{minutes=true,long=true})}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--add_fake_players(list_table,6)
|
--[[Adds fake players to the player list
|
||||||
--add_fake_players(list_table,20)
|
for i = 1, 10 do
|
||||||
end)
|
local online_time = math.random(1,tick)
|
||||||
:on_update(function(player,element)
|
local afk_time = math.random(online_time-(tick/10),tick)
|
||||||
local list = element.container.scroll.table
|
local percent = math.round(online_time/tick,3)*100
|
||||||
for _,next_player in pairs(game.connected_players) do
|
player_list_order[ctn+i] = {
|
||||||
local time_element_name = 'player-time-'..next_player.index
|
name='Player '..i,
|
||||||
local time_element = list[time_element_name]
|
index=0-i,
|
||||||
if time_element and time_element.valid then
|
tag='',
|
||||||
time_element.label.caption = format_time(next_player.online_time)
|
role_name = 'Fake Player',
|
||||||
local tick = game.tick > 0 and game.tick or 1
|
chat_color=table.get_random_dictionary_entry(Colors),
|
||||||
local percent = math.round(next_player.online_time/tick,3)*100
|
caption = format_time(online_time),
|
||||||
time_element.label.tooltip = {'player-list.afk-time',percent,format_time(next_player.afk_time,{minutes=true,long=true})}
|
tooltip = {'player-list.afk-time',percent,format_time(afk_time,{minutes=true,long=true})},
|
||||||
|
}
|
||||||
|
end]]
|
||||||
|
|
||||||
|
return player_list_order
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Update the play times every 30 sections
|
||||||
|
Event.on_nth_tick(1800,function()
|
||||||
|
local player_times = get_player_times()
|
||||||
|
for _,player in pairs(game.connected_players) do
|
||||||
|
local left_flow = Gui.get_left_flow(player)
|
||||||
|
local frame = left_flow[player_list_container.name]
|
||||||
|
local scroll_table = frame.container.scroll.table
|
||||||
|
for _,player_time in pairs(player_times) do
|
||||||
|
update_player_base(scroll_table,player_time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
player_list_name = player_list:uid()
|
--- When a player leaves only remove they entry
|
||||||
|
Event.add(defines.events.on_player_left_game,function(event)
|
||||||
|
local remove_player = event.player
|
||||||
|
for _,player in pairs(game.connected_players) do
|
||||||
|
local left_flow = Gui.get_left_flow(player)
|
||||||
|
local frame = left_flow[player_list_container.name]
|
||||||
|
local scroll_table = frame.container.scroll.table
|
||||||
|
remove_player_base(scroll_table,remove_player)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
--- All other events require a full redraw of the table
|
||||||
|
local function redraw_player_list()
|
||||||
|
local player_list_order = get_player_list_order()
|
||||||
|
for _,player in pairs(game.connected_players) do
|
||||||
|
local left_flow = Gui.get_left_flow(player)
|
||||||
|
local frame = left_flow[player_list_container.name]
|
||||||
|
local scroll_table = frame.container.scroll.table
|
||||||
|
scroll_table.clear()
|
||||||
|
for _,next_player_data in ipairs(player_list_order) do
|
||||||
|
add_player_base(scroll_table,next_player_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Event.add(defines.events.on_player_joined_game,redraw_player_list)
|
||||||
|
Event.add(Roles.events.on_role_assigned,redraw_player_list)
|
||||||
|
Event.add(Roles.events.on_role_unassigned,redraw_player_list)
|
||||||
|
|
||||||
--- When the action player is changed the action bar will update
|
--- When the action player is changed the action bar will update
|
||||||
Store.watch(selected_player_store,function(value,player_name)
|
Store.watch(selected_player_store,function(value,player_name)
|
||||||
local player = Game.get_player_from_any(player_name)
|
local player = Game.get_player_from_any(player_name)
|
||||||
update_action_bar(player)
|
local left_flow = Gui.get_left_flow(player)
|
||||||
|
local frame = left_flow[player_list_container.name]
|
||||||
-- Change the style of the option buttons
|
local scroll_table = frame.container.scroll.table
|
||||||
local frame = player_list:get_frame(player)
|
update_action_bar_buttons(frame.container.action_bar)
|
||||||
local data_table = frame.container.scroll.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 = scroll_table[next_player.name][open_action_bar.name]
|
||||||
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)
|
local element_style = element.style
|
||||||
element.style.width = 8
|
element_style.padding = -2
|
||||||
element.style.height = 14
|
element_style.width = 8
|
||||||
|
element_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.watch(selected_action_store,function(value,player_name)
|
Store.watch(selected_action_store,function(value,player_name)
|
||||||
local player = Game.get_player_from_any(player_name)
|
local player = Game.get_player_from_any(player_name)
|
||||||
local frame = Gui.classes.left_frames.get_frame(player_list_name,player)
|
local left_flow = Gui.get_left_flow(player)
|
||||||
|
local frame = left_flow[player_list_container.name]
|
||||||
local element = frame.container.reason_bar
|
local element = frame.container.reason_bar
|
||||||
if value then
|
if value then
|
||||||
-- if there is a new value then check the player is still online
|
-- if there is a new value then check the player is still online
|
||||||
@@ -379,13 +481,4 @@ Store.watch(selected_action_store,function(value,player_name)
|
|||||||
element.visible = false
|
element.visible = false
|
||||||
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- 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')
|
|
||||||
Event.add(defines.events.on_player_joined_game,player_list 'redraw_all')
|
|
||||||
Event.add(defines.events.on_player_left_game,player_list 'redraw_all')
|
|
||||||
Event.add(Roles.events.on_role_assigned,player_list 'redraw_all')
|
|
||||||
Event.add(Roles.events.on_role_unassigned,player_list 'redraw_all')
|
|
||||||
|
|
||||||
return player_list
|
|
||||||
Reference in New Issue
Block a user