mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Fixed Existing Lua Check Errors
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
@alias player_list
|
||||
]]
|
||||
|
||||
-- luacheck:ignore 211/Colors
|
||||
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local Store = require 'expcore.store' --- @dep expcore.store
|
||||
@@ -24,7 +25,7 @@ local selected_action_store = Store.register(function(player)
|
||||
end)
|
||||
|
||||
-- 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)
|
||||
|
||||
--- Button used to open the action bar
|
||||
-- @element open_action_bar
|
||||
@@ -40,13 +41,13 @@ Gui.element{
|
||||
width = 8,
|
||||
height = 14
|
||||
}
|
||||
:on_click(function(player,element,_)
|
||||
:on_click(function(player, element, _)
|
||||
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
|
||||
Store.clear(selected_player_store,player)
|
||||
Store.clear(selected_player_store, player)
|
||||
else
|
||||
Store.set(selected_player_store,player,selected_player_name)
|
||||
Store.set(selected_player_store, player, selected_player_name)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -59,10 +60,10 @@ Gui.element{
|
||||
tooltip = {'player-list.close-action-bar'},
|
||||
style = 'shortcut_bar_button_red'
|
||||
}
|
||||
:style(Gui.sprite_style(30,-1,{ top_margin = -1, right_margin = -1 }))
|
||||
:on_click(function(player,_)
|
||||
Store.clear(selected_player_store,player)
|
||||
Store.clear(selected_action_store,player)
|
||||
:style(Gui.sprite_style(30, -1, { top_margin = -1, right_margin = -1 }))
|
||||
:on_click(function(player, _)
|
||||
Store.clear(selected_player_store, player)
|
||||
Store.clear(selected_action_store, player)
|
||||
end)
|
||||
|
||||
--- Button used to confirm a reason
|
||||
@@ -74,21 +75,21 @@ Gui.element{
|
||||
tooltip = {'player-list.reason-confirm'},
|
||||
style = 'shortcut_bar_button_green'
|
||||
}
|
||||
:style(Gui.sprite_style(30,-1,{ left_margin = -2, right_margin = -1 }))
|
||||
:on_click(function(player,element)
|
||||
:style(Gui.sprite_style(30, -1, { left_margin = -2, right_margin = -1 }))
|
||||
:on_click(function(player, element)
|
||||
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)
|
||||
local reason_callback = config.buttons[action_name].reason_callback
|
||||
reason_callback(player,reason)
|
||||
Store.clear(selected_player_store,player)
|
||||
Store.clear(selected_action_store,player)
|
||||
reason_callback(player, reason)
|
||||
Store.clear(selected_player_store, player)
|
||||
Store.clear(selected_action_store, player)
|
||||
element.parent.entry.text = ''
|
||||
end)
|
||||
|
||||
--- Set of elements that are used to make up a row of the player table
|
||||
-- @element add_player_base
|
||||
local add_player_base =
|
||||
Gui.element(function(event_trigger,parent,player_data)
|
||||
Gui.element(function(event_trigger, parent, player_data)
|
||||
-- Add the button to open the action bar
|
||||
local toggle_action_bar_flow = parent.add{ type = 'flow', name = player_data.name }
|
||||
open_action_bar(toggle_action_bar_flow)
|
||||
@@ -99,13 +100,13 @@ Gui.element(function(event_trigger,parent,player_data)
|
||||
type = 'label',
|
||||
name = event_trigger,
|
||||
caption = player_data.name,
|
||||
tooltip = {'player-list.open-map',player_data.name,player_data.tag,player_data.role_name}
|
||||
tooltip = {'player-list.open-map', player_data.name, player_data.tag, player_data.role_name}
|
||||
}
|
||||
player_name.style.padding = {0,2,0,0}
|
||||
player_name.style.padding = {0, 2,0, 0}
|
||||
player_name.style.font_color = player_data.chat_color
|
||||
|
||||
-- Add the time played label
|
||||
local alignment = Gui.alignment(parent,'player-time-'..player_data.index)
|
||||
local alignment = Gui.alignment(parent, 'player-time-'..player_data.index)
|
||||
local time_label = alignment.add{
|
||||
name = 'label',
|
||||
type = 'label',
|
||||
@@ -116,34 +117,34 @@ Gui.element(function(event_trigger,parent,player_data)
|
||||
|
||||
return time_label
|
||||
end)
|
||||
:on_click(function(player,element,event)
|
||||
:on_click(function(player, element, event)
|
||||
local selected_player_name = 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)
|
||||
event.player.zoom_to_world(position, 1.75)
|
||||
else
|
||||
-- RMB will toggle the settings
|
||||
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
|
||||
Store.clear(selected_player_store,player)
|
||||
Store.clear(selected_action_store,player)
|
||||
Store.clear(selected_player_store, player)
|
||||
Store.clear(selected_action_store, player)
|
||||
else
|
||||
Store.set(selected_player_store,player,selected_player_name)
|
||||
Store.set(selected_player_store, player, selected_player_name)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Removes the three elements that are added as part of the base
|
||||
local function remove_player_base(parent,player)
|
||||
local function remove_player_base(parent, player)
|
||||
Gui.destroy_if_valid(parent[player.name])
|
||||
Gui.destroy_if_valid(parent['player-name-'..player.index])
|
||||
Gui.destroy_if_valid(parent['player-time-'..player.index])
|
||||
end
|
||||
|
||||
-- Update the time label for a player using there player time data
|
||||
local function update_player_base(parent,player_time)
|
||||
local function update_player_base(parent, player_time)
|
||||
local time_element = parent[player_time.element_name]
|
||||
if time_element and time_element.valid then
|
||||
time_element.label.caption = player_time.caption
|
||||
@@ -154,15 +155,15 @@ end
|
||||
--- 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)
|
||||
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
|
||||
for action_name, button_data in pairs(config.buttons) do
|
||||
-- Added the permission flow
|
||||
local permission_flow = parent.add{ type = 'flow', name = action_name }
|
||||
permission_flow.visible = false
|
||||
-- Add the buttons under that permission
|
||||
for _,button in ipairs(button_data) do
|
||||
for _, button in ipairs(button_data) do
|
||||
button(permission_flow)
|
||||
end
|
||||
end
|
||||
@@ -173,7 +174,7 @@ end)
|
||||
--- Updates the visible state of the action bar buttons
|
||||
local function update_action_bar(element)
|
||||
local player = Gui.get_player_from_element(element)
|
||||
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
|
||||
-- Hide the action bar when no player is selected
|
||||
@@ -184,16 +185,16 @@ local function update_action_bar(element)
|
||||
if not selected_player.connected then
|
||||
-- If the player is offline then reest stores
|
||||
element.visible = false
|
||||
Store.clear(selected_player_store,player)
|
||||
Store.clear(selected_action_store,player)
|
||||
Store.clear(selected_player_store, player)
|
||||
Store.clear(selected_action_store, player)
|
||||
|
||||
else
|
||||
-- Otherwise check what actions the player is allowed to use
|
||||
element.visible = true
|
||||
for action_name,buttons in pairs(config.buttons) do
|
||||
if buttons.auth and not buttons.auth(player,selected_player) then
|
||||
for action_name, buttons in pairs(config.buttons) do
|
||||
if buttons.auth and not buttons.auth(player, selected_player) then
|
||||
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
|
||||
end
|
||||
end
|
||||
@@ -205,36 +206,36 @@ end
|
||||
--- Main player list container for the left flow
|
||||
-- @element player_list_container
|
||||
local player_list_container =
|
||||
Gui.element(function(event_trigger,parent)
|
||||
Gui.element(function(event_trigger, parent)
|
||||
-- Draw the internal container
|
||||
local container = Gui.container(parent,event_trigger,200)
|
||||
local container = Gui.container(parent, event_trigger, 200)
|
||||
|
||||
-- Draw the scroll table for the players
|
||||
local scroll_table = Gui.scroll_table(container,184,3)
|
||||
local scroll_table = Gui.scroll_table(container, 184, 3)
|
||||
|
||||
-- Change the style of the scroll table
|
||||
local scroll_table_style = scroll_table.style
|
||||
scroll_table_style.padding = {1,0,1,2}
|
||||
scroll_table_style.padding = {1, 0,1, 2}
|
||||
|
||||
-- Add the action bar
|
||||
local action_bar = Gui.footer(container,nil,nil,false,'action_bar')
|
||||
local action_bar = Gui.footer(container, nil, nil, false, 'action_bar')
|
||||
|
||||
-- Change the style of the action bar
|
||||
local action_bar_style = action_bar.style
|
||||
action_bar_style.height = 35
|
||||
action_bar_style.padding = {1,3}
|
||||
action_bar_style.padding = {1, 3}
|
||||
action_bar.visible = false
|
||||
|
||||
-- Add the buttons to the action bar
|
||||
add_action_bar_buttons(action_bar)
|
||||
|
||||
-- Add the reason bar
|
||||
local reason_bar = Gui.footer(container,nil,nil,false,'reason_bar')
|
||||
local reason_bar = Gui.footer(container, nil, nil, false, 'reason_bar')
|
||||
|
||||
-- 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.padding = {-1, 3}
|
||||
reason_bar.visible = false
|
||||
|
||||
-- Add the text entry for the reason bar
|
||||
@@ -263,15 +264,15 @@ end)
|
||||
--- Button on the top flow used to toggle the player list container
|
||||
-- @element toggle_left_element
|
||||
Gui.left_toolbar_button('entity/character', {'player-list.main-tooltip'}, player_list_container, function(player)
|
||||
return Roles.player_allowed(player,'gui/player-list')
|
||||
return Roles.player_allowed(player, 'gui/player-list')
|
||||
end)
|
||||
|
||||
-- Get caption and tooltip format for a player
|
||||
local function get_time_formats(online_time,afk_time)
|
||||
local function get_time_formats(online_time, afk_time)
|
||||
local tick = game.tick > 0 and game.tick or 1
|
||||
local percent = math.round(online_time/tick,3)*100
|
||||
local percent = math.round(online_time/tick, 3)*100
|
||||
local caption = format_time(online_time)
|
||||
local tooltip = {'player-list.afk-time', percent, format_time(afk_time,{minutes=true,long=true})}
|
||||
local tooltip = {'player-list.afk-time', percent, format_time(afk_time, {minutes=true, long=true})}
|
||||
return caption, tooltip
|
||||
end
|
||||
|
||||
@@ -297,20 +298,20 @@ end
|
||||
local function get_player_list_order()
|
||||
-- Sort all the online players into roles
|
||||
local players = {}
|
||||
for _,player in pairs(game.connected_players) do
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local highest_role = Roles.get_player_highest_role(player)
|
||||
if not players[highest_role.name] then
|
||||
players[highest_role.name] = {}
|
||||
end
|
||||
table.insert(players[highest_role.name],player)
|
||||
table.insert(players[highest_role.name], player)
|
||||
end
|
||||
|
||||
-- Sort the players from roles into a set order
|
||||
local ctn = 0
|
||||
local player_list_order = {}
|
||||
for _,role_name in pairs(Roles.config.order) do
|
||||
for _, role_name in pairs(Roles.config.order) do
|
||||
if players[role_name] then
|
||||
for _,player in pairs(players[role_name]) do
|
||||
for _, player in pairs(players[role_name]) do
|
||||
ctn = ctn + 1
|
||||
-- Add the player data to the array
|
||||
local caption, tooltip = get_time_formats(player.online_time, player.afk_time)
|
||||
@@ -329,8 +330,8 @@ local function get_player_list_order()
|
||||
|
||||
--[[Adds fake players to the player list
|
||||
for i = 1, 10 do
|
||||
local online_time = math.random(1,tick)
|
||||
local afk_time = math.random(online_time-(tick/10),tick)
|
||||
local online_time = math.random(1, tick)
|
||||
local afk_time = math.random(online_time-(tick/10), tick)
|
||||
local caption, tooltip = get_time_formats(online_time, afk_time)
|
||||
player_list_order[ctn+i] = {
|
||||
name='Player '..i,
|
||||
@@ -347,29 +348,29 @@ local function get_player_list_order()
|
||||
end
|
||||
|
||||
--- Update the play times every 30 sections
|
||||
Event.on_nth_tick(1800,function()
|
||||
Event.on_nth_tick(1800, function()
|
||||
local player_times = get_player_times()
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local frame = Gui.get_left_element(player,player_list_container)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local frame = Gui.get_left_element(player, player_list_container)
|
||||
local scroll_table = frame.container.scroll.table
|
||||
for _,player_time in pairs(player_times) do
|
||||
update_player_base(scroll_table,player_time)
|
||||
for _, player_time in pairs(player_times) do
|
||||
update_player_base(scroll_table, player_time)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- When a player leaves only remove they entry
|
||||
Event.add(defines.events.on_player_left_game,function(event)
|
||||
Event.add(defines.events.on_player_left_game, function(event)
|
||||
local remove_player = Game.get_player_by_index(event.player_index)
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local frame = Gui.get_left_element(player,player_list_container)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local frame = Gui.get_left_element(player, player_list_container)
|
||||
local scroll_table = frame.container.scroll.table
|
||||
remove_player_base(scroll_table,remove_player)
|
||||
remove_player_base(scroll_table, remove_player)
|
||||
|
||||
local selected_player_name = Store.get(selected_player_store,player)
|
||||
local selected_player_name = Store.get(selected_player_store, player)
|
||||
if selected_player_name == remove_player.name then
|
||||
Store.clear(selected_player_store,player)
|
||||
Store.clear(selected_action_store,player)
|
||||
Store.clear(selected_player_store, player)
|
||||
Store.clear(selected_action_store, player)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -377,27 +378,27 @@ 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 frame = Gui.get_left_element(player,player_list_container)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local frame = Gui.get_left_element(player, player_list_container)
|
||||
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)
|
||||
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)
|
||||
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
|
||||
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 frame = Gui.get_left_element(player,player_list_container)
|
||||
local frame = Gui.get_left_element(player, player_list_container)
|
||||
local scroll_table = frame.container.scroll.table
|
||||
update_action_bar(frame.container.action_bar)
|
||||
for _,next_player in pairs(game.connected_players) do
|
||||
for _, next_player in pairs(game.connected_players) do
|
||||
local element = scroll_table[next_player.name][open_action_bar.name]
|
||||
local style = 'frame_button'
|
||||
if next_player.name == value then
|
||||
@@ -412,20 +413,20 @@ Store.watch(selected_player_store,function(value,player_name)
|
||||
end)
|
||||
|
||||
--- 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 frame = Gui.get_left_element(player,player_list_container)
|
||||
local frame = Gui.get_left_element(player, player_list_container)
|
||||
local element = frame.container.reason_bar
|
||||
if value then
|
||||
-- if there is a new value then check the player is still online
|
||||
local selected_player_name = Store.get(selected_player_store,player_name)
|
||||
local selected_player_name = Store.get(selected_player_store, player_name)
|
||||
local selected_player = Game.get_player_from_any(selected_player_name)
|
||||
if selected_player.connected then
|
||||
element.visible = true
|
||||
else
|
||||
-- Clear if the player is offline
|
||||
Store.clear(selected_player_store,player_name)
|
||||
Store.clear(selected_action_store,player_name)
|
||||
Store.clear(selected_player_store, player_name)
|
||||
Store.clear(selected_action_store, player_name)
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
@@ -12,7 +12,7 @@ local Game = require 'utils.game' --- @dep utils.game
|
||||
local format_time = _C.format_time --- @dep expcore.common
|
||||
|
||||
local tabs = {}
|
||||
local function Tab(caption,tooltip,element_define)
|
||||
local function Tab(caption, tooltip, element_define)
|
||||
tabs[#tabs+1] = {caption, tooltip, element_define}
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ local scroll_hieght = 275 -- controls the height of the scrolls
|
||||
--- Sub content area used within the content areas
|
||||
-- @element sub_content
|
||||
local sub_content =
|
||||
Gui.element(function(_,parent)
|
||||
Gui.element(function(_, parent)
|
||||
return parent.add{
|
||||
type = 'frame',
|
||||
direction = 'vertical',
|
||||
@@ -38,7 +38,7 @@ end)
|
||||
--- Table which has a title above it above it
|
||||
-- @element title_table
|
||||
local title_table =
|
||||
Gui.element(function(_,parent,bar_size,caption,column_count)
|
||||
Gui.element(function(_, parent, bar_size, caption, column_count)
|
||||
Gui.title_label(parent, bar_size, caption)
|
||||
|
||||
return parent.add{
|
||||
@@ -65,15 +65,15 @@ Gui.element{
|
||||
style = 'scroll_pane_under_subheader'
|
||||
}
|
||||
:style{
|
||||
padding = {1,3},
|
||||
padding = {1, 3},
|
||||
maximal_height = scroll_hieght,
|
||||
horizontally_stretchable = true,
|
||||
}
|
||||
|
||||
--- Content area for the welcome tab
|
||||
-- @element welcome_content
|
||||
Tab({'readme.welcome-tab'},{'readme.welcome-tooltip'},
|
||||
Gui.element(function(_,parent)
|
||||
Tab({'readme.welcome-tab'}, {'readme.welcome-tooltip'},
|
||||
Gui.element(function(_, parent)
|
||||
local server_details = global.server_details or { name='ExpGaming S0 - Local', description='Failed to load description: disconnected from sync api.', reset_time='Non Set', branch='Unknown'}
|
||||
local container = parent.add{ type='flow', direction='vertical' }
|
||||
local player = Gui.get_player_from_element(parent)
|
||||
@@ -93,15 +93,15 @@ Gui.element(function(_,parent)
|
||||
-- Get the names of the roles the player has
|
||||
local player_roles = Roles.get_player_roles(player)
|
||||
local role_names = {}
|
||||
for i,role in ipairs(player_roles) do
|
||||
for i, role in ipairs(player_roles) do
|
||||
role_names[i] = role.name
|
||||
end
|
||||
|
||||
-- Add the other information to the gui
|
||||
container.add{ type='flow' }.style.height = 4
|
||||
local online_time = format_time(game.tick,{days=true,hours=true,minutes=true,long=true})
|
||||
local online_time = format_time(game.tick, {days=true, hours=true, minutes=true, long=true})
|
||||
Gui.centered_label(sub_content(container), frame_width, {'readme.welcome-general', server_details.reset_time, online_time})
|
||||
Gui.centered_label(sub_content(container), frame_width, {'readme.welcome-roles', table.concat(role_names,', ')})
|
||||
Gui.centered_label(sub_content(container), frame_width, {'readme.welcome-roles', table.concat(role_names, ', ')})
|
||||
Gui.centered_label(sub_content(container), frame_width, {'readme.welcome-chat'})
|
||||
|
||||
return container
|
||||
@@ -109,8 +109,8 @@ end))
|
||||
|
||||
--- Content area for the rules tab
|
||||
-- @element rules_content
|
||||
Tab({'readme.rules-tab'},{'readme.rules-tooltip'},
|
||||
Gui.element(function(_,parent)
|
||||
Tab({'readme.rules-tab'}, {'readme.rules-tooltip'},
|
||||
Gui.element(function(_, parent)
|
||||
local container = parent.add{ type='flow', direction='vertical' }
|
||||
|
||||
-- Add the title and description to the content
|
||||
@@ -125,7 +125,7 @@ Gui.element(function(_,parent)
|
||||
rules.style.cell_padding = 4
|
||||
|
||||
-- Add the rules to the table
|
||||
for i = 1,15 do
|
||||
for i = 1, 15 do
|
||||
Gui.centered_label(rules, 565, {'readme.rules-'..i})
|
||||
end
|
||||
|
||||
@@ -134,8 +134,8 @@ end))
|
||||
|
||||
--- Content area for the commands tab
|
||||
-- @element commands_content
|
||||
Tab({'readme.commands-tab'},{'readme.commands-tooltip'},
|
||||
Gui.element(function(_,parent)
|
||||
Tab({'readme.commands-tab'}, {'readme.commands-tooltip'},
|
||||
Gui.element(function(_, parent)
|
||||
local container = parent.add{ type='flow', direction='vertical' }
|
||||
local player = Gui.get_player_from_element(parent)
|
||||
|
||||
@@ -151,7 +151,7 @@ Gui.element(function(_,parent)
|
||||
commands.style.cell_padding = 0
|
||||
|
||||
-- Add the rules to the table
|
||||
for name,command in pairs(Commands.get(player)) do
|
||||
for name, command in pairs(Commands.get(player)) do
|
||||
Gui.centered_label(commands, 120, name)
|
||||
Gui.centered_label(commands, 450, command.help)
|
||||
end
|
||||
@@ -161,8 +161,8 @@ end))
|
||||
|
||||
--- Content area for the servers tab
|
||||
-- @element servers_content
|
||||
Tab({'readme.servers-tab'},{'readme.servers-tooltip'},
|
||||
Gui.element(function(_,parent)
|
||||
Tab({'readme.servers-tab'}, {'readme.servers-tooltip'},
|
||||
Gui.element(function(_, parent)
|
||||
local container = parent.add{ type='flow', direction='vertical' }
|
||||
|
||||
-- Add the title and description to the content
|
||||
@@ -177,14 +177,14 @@ Gui.element(function(_,parent)
|
||||
|
||||
-- Add the factorio servers
|
||||
local factorio_servers = title_table(scroll_pane, 225, {'readme.servers-factorio'}, 2)
|
||||
for i = 1,8 do
|
||||
for i = 1, 8 do
|
||||
Gui.centered_label(factorio_servers, 110, {'readme.servers-'..i})
|
||||
Gui.centered_label(factorio_servers, 460, {'readme.servers-d'..i})
|
||||
end
|
||||
|
||||
-- Add the external links
|
||||
local external_links = title_table(scroll_pane, 235, {'readme.servers-external'}, 2)
|
||||
for _,key in ipairs{'discord','website','patreon','status','github'} do
|
||||
for _, key in ipairs{'discord', 'website', 'patreon', 'status', 'github'} do
|
||||
Gui.centered_label(external_links, 110, key:gsub("^%l", string.upper))
|
||||
Gui.centered_label(external_links, 460, {'links.'..key}, {'readme.servers-open-in-browser'})
|
||||
end
|
||||
@@ -194,8 +194,8 @@ end))
|
||||
|
||||
--- Content area for the servers tab
|
||||
-- @element backers_content
|
||||
Tab({'readme.backers-tab'},{'readme.backers-tooltip'},
|
||||
Gui.element(function(_,parent)
|
||||
Tab({'readme.backers-tab'}, {'readme.backers-tooltip'},
|
||||
Gui.element(function(_, parent)
|
||||
local container = parent.add{ type='flow', direction='vertical' }
|
||||
|
||||
-- Add the title and description to the content
|
||||
@@ -207,10 +207,10 @@ Gui.element(function(_,parent)
|
||||
-- Find which players will go where
|
||||
local done = {}
|
||||
local groups = {
|
||||
{ _roles={'Senior Administrator','Administrator'}, _title={'readme.backers-management'}, _width=230 },
|
||||
{ _roles={'Board Member','Senior Backer'}, _title={'readme.backers-board'}, _width=145 }, -- change role to board
|
||||
{ _roles={'Sponsor','Supporter'}, _title={'readme.backers-backers'}, _width=196 }, -- change to backer
|
||||
{ _roles={'Moderator','Trainee'}, _title={'readme.backers-staff'}, _width=235 },
|
||||
{ _roles={'Senior Administrator', 'Administrator'}, _title={'readme.backers-management'}, _width=230 },
|
||||
{ _roles={'Board Member', 'Senior Backer'}, _title={'readme.backers-board'}, _width=145 }, -- change role to board
|
||||
{ _roles={'Sponsor', 'Supporter'}, _title={'readme.backers-backers'}, _width=196 }, -- change to backer
|
||||
{ _roles={'Moderator', 'Trainee'}, _title={'readme.backers-staff'}, _width=235 },
|
||||
{ _roles={}, _time=3*3600*60, _title={'readme.backers-active'}, _width=235 },
|
||||
}
|
||||
|
||||
@@ -242,12 +242,12 @@ Gui.element(function(_,parent)
|
||||
local scroll_pane = title_table_scroll(container)
|
||||
for _, players in ipairs(groups) do
|
||||
local table = title_table(scroll_pane, players._width, players._title, 4)
|
||||
for _,player_name in ipairs(players) do
|
||||
for _, player_name in ipairs(players) do
|
||||
Gui.centered_label(table, 140, player_name)
|
||||
end
|
||||
|
||||
if #players < 4 then
|
||||
for i = 1,4-#players do
|
||||
for i = 1, 4-#players do
|
||||
Gui.centered_label(table, 140)
|
||||
end
|
||||
end
|
||||
@@ -260,7 +260,7 @@ end))
|
||||
-- @element readme
|
||||
local readme_toggle
|
||||
local readme =
|
||||
Gui.element(function(event_trigger,parent)
|
||||
Gui.element(function(event_trigger, parent)
|
||||
local container = parent.add{
|
||||
name = event_trigger,
|
||||
type = 'frame',
|
||||
@@ -269,7 +269,7 @@ Gui.element(function(event_trigger,parent)
|
||||
|
||||
-- Add the left hand side of the frame back, removed because of frame_tabbed_pane style
|
||||
local left_alignment = Gui.alignment(container, nil, nil, 'bottom')
|
||||
left_alignment.style.padding = {32,0,0,0}
|
||||
left_alignment.style.padding = {32, 0,0, 0}
|
||||
|
||||
local left_side =
|
||||
left_alignment.add{
|
||||
@@ -288,7 +288,7 @@ Gui.element(function(event_trigger,parent)
|
||||
}
|
||||
|
||||
-- Add the different content areas
|
||||
for _,tab_details in ipairs(tabs) do
|
||||
for _, tab_details in ipairs(tabs) do
|
||||
local tab = tab_pane.add{ type = 'tab', style = 'frame_tab', caption = tab_details[1], tooltip = tab_details[2] }
|
||||
tab_pane.add_tab(tab, tab_details[3](tab_pane))
|
||||
end
|
||||
@@ -299,7 +299,7 @@ end)
|
||||
local toggle_button = Gui.get_top_element(player, readme_toggle)
|
||||
Gui.toolbar_button_style(toggle_button, true)
|
||||
end)
|
||||
:on_close(function(player,element)
|
||||
:on_close(function(player, element)
|
||||
local toggle_button = Gui.get_top_element(player, readme_toggle)
|
||||
Gui.toolbar_button_style(toggle_button, false)
|
||||
Gui.destroy_if_valid(element)
|
||||
@@ -308,10 +308,10 @@ end)
|
||||
--- Toggle button for the readme gui
|
||||
-- @element readme_toggle
|
||||
readme_toggle =
|
||||
Gui.toolbar_button('virtual-signal/signal-info',{'readme.main-tooltip'},function(player)
|
||||
return Roles.player_allowed(player,'gui/readme')
|
||||
Gui.toolbar_button('virtual-signal/signal-info', {'readme.main-tooltip'}, function(player)
|
||||
return Roles.player_allowed(player, 'gui/readme')
|
||||
end)
|
||||
:on_click(function(player,_)
|
||||
:on_click(function(player, _)
|
||||
local center = player.gui.center
|
||||
if center[readme.name] then
|
||||
player.opened = nil
|
||||
@@ -321,7 +321,7 @@ end)
|
||||
end)
|
||||
|
||||
--- When a player joins the game for the first time show this gui
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local element = readme(player.gui.center)
|
||||
element.pane.selected_tab_index = 1
|
||||
@@ -329,7 +329,7 @@ Event.add(defines.events.on_player_created,function(event)
|
||||
end)
|
||||
|
||||
--- When a player joins clear center unless the player has something open
|
||||
Event.add(defines.events.on_player_joined_game,function(event)
|
||||
Event.add(defines.events.on_player_joined_game, function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
if not player.opened then
|
||||
player.gui.center.clear()
|
||||
@@ -337,7 +337,7 @@ Event.add(defines.events.on_player_joined_game,function(event)
|
||||
end)
|
||||
|
||||
--- When a player respawns clear center unless the player has something open
|
||||
Event.add(defines.events.on_player_respawned,function(event)
|
||||
Event.add(defines.events.on_player_respawned, function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
if not player.opened then
|
||||
player.gui.center.clear()
|
||||
|
||||
@@ -20,7 +20,7 @@ local time_formats = {
|
||||
}
|
||||
|
||||
--- Check if a player is allowed to use certain interactions
|
||||
local function check_player_permissions(player,action)
|
||||
local function check_player_permissions(player, action)
|
||||
if not config.progress['allow_'..action] then
|
||||
return false
|
||||
end
|
||||
@@ -30,7 +30,7 @@ local function check_player_permissions(player,action)
|
||||
end
|
||||
|
||||
if config.progress[action..'_role_permission']
|
||||
and not Roles.player_allowed(player,config.progress[action..'_role_permission']) then
|
||||
and not Roles.player_allowed(player, config.progress[action..'_role_permission']) then
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ Gui.element{
|
||||
tooltip = {'rocket-info.toggle-rocket-tooltip'}
|
||||
}
|
||||
:style(Gui.sprite_style(16))
|
||||
:on_click(function(_,element,_)
|
||||
:on_click(function(_, element, _)
|
||||
local rocket_silo_name = element.parent.name:sub(8)
|
||||
local rocket_silo = Rockets.get_silo_entity(rocket_silo_name)
|
||||
if rocket_silo.auto_launch then
|
||||
@@ -68,21 +68,21 @@ Gui.element{
|
||||
sprite = 'utility/center',
|
||||
tooltip = {'rocket-info.launch-tooltip'}
|
||||
}
|
||||
:style(Gui.sprite_style(16,-1))
|
||||
:on_click(function(player,element,_)
|
||||
:style(Gui.sprite_style(16, -1))
|
||||
:on_click(function(player, element, _)
|
||||
local rocket_silo_name = element.parent.name:sub(8)
|
||||
local silo_data = Rockets.get_silo_data_by_name(rocket_silo_name)
|
||||
if silo_data.entity.launch_rocket() then
|
||||
element.enabled = false
|
||||
else
|
||||
player.print({'rocket-info.launch-failed'},Colors.orange_red)
|
||||
player.print({'rocket-info.launch-failed'}, Colors.orange_red)
|
||||
end
|
||||
end)
|
||||
|
||||
--- XY cords that allow zoom to map when pressed
|
||||
-- @element silo_cords
|
||||
local silo_cords =
|
||||
Gui.element(function(event_trigger,parent,silo_data)
|
||||
Gui.element(function(event_trigger, parent, silo_data)
|
||||
local silo_name = silo_data.silo_name
|
||||
local pos = silo_data.position
|
||||
local name = config.progress.allow_zoom_to_map and event_trigger or nil
|
||||
@@ -94,13 +94,13 @@ Gui.element(function(event_trigger,parent,silo_data)
|
||||
name = 'label-x-'..silo_name,
|
||||
caption = silo_name
|
||||
}
|
||||
flow_x.style.padding = {0,2,0,1}
|
||||
flow_x.style.padding = {0, 2,0, 1}
|
||||
|
||||
-- Add the x cord label
|
||||
flow_x.add{
|
||||
type = 'label',
|
||||
name = name,
|
||||
caption = {'rocket-info.progress-x-pos',pos.x},
|
||||
caption = {'rocket-info.progress-x-pos', pos.x},
|
||||
tooltip = tooltip
|
||||
}
|
||||
|
||||
@@ -110,32 +110,32 @@ Gui.element(function(event_trigger,parent,silo_data)
|
||||
name = 'label-y-'..silo_name,
|
||||
caption = silo_name
|
||||
}
|
||||
flow_y.style.padding = {0,2,0,1}
|
||||
flow_y.style.padding = {0, 2,0, 1}
|
||||
|
||||
-- Add the y cord label
|
||||
flow_y.add{
|
||||
type = 'label',
|
||||
name = name,
|
||||
caption = {'rocket-info.progress-y-pos',pos.y},
|
||||
caption = {'rocket-info.progress-y-pos', pos.y},
|
||||
tooltip = tooltip
|
||||
}
|
||||
|
||||
end)
|
||||
:on_click(function(player,element,_)
|
||||
:on_click(function(player, element, _)
|
||||
local rocket_silo_name = element.parent.caption
|
||||
local rocket_silo = Rockets.get_silo_entity(rocket_silo_name)
|
||||
player.zoom_to_world(rocket_silo.position,2)
|
||||
player.zoom_to_world(rocket_silo.position, 2)
|
||||
end)
|
||||
|
||||
--- Base element for each rocket in the progress list
|
||||
-- @element rocket_entry
|
||||
local rocket_entry =
|
||||
Gui.element(function(_,parent,silo_data)
|
||||
Gui.element(function(_, parent, silo_data)
|
||||
local silo_name = silo_data.silo_name
|
||||
local player = Gui.get_player_from_element(parent)
|
||||
|
||||
-- Add the toggle auto launch if the player is allowed it
|
||||
if check_player_permissions(player,'toggle_active') then
|
||||
if check_player_permissions(player, 'toggle_active') then
|
||||
local flow = parent.add{ type = 'flow', name = 'toggle-'..silo_name}
|
||||
local button = toggle_launch(flow)
|
||||
button.tooltip = silo_data.toggle_tooltip
|
||||
@@ -143,17 +143,17 @@ Gui.element(function(_,parent,silo_data)
|
||||
end
|
||||
|
||||
-- Add the remote launch if the player is allowed it
|
||||
if check_player_permissions(player,'remote_launch') then
|
||||
if check_player_permissions(player, 'remote_launch') then
|
||||
local flow = parent.add{ type = 'flow', name = 'launch-'..silo_name}
|
||||
local button = launch_rocket(flow)
|
||||
button.enabled = silo_data.allow_launch
|
||||
end
|
||||
|
||||
-- Draw the silo cords element
|
||||
silo_cords(parent,silo_data)
|
||||
silo_cords(parent, silo_data)
|
||||
|
||||
-- Add a progress label
|
||||
local alignment = Gui.alignment(parent,silo_name)
|
||||
local alignment = Gui.alignment(parent, silo_name)
|
||||
local element =
|
||||
alignment.add{
|
||||
type = 'label',
|
||||
@@ -169,7 +169,7 @@ end)
|
||||
--- Data label which contains a name and a value label pair
|
||||
-- @element data_label
|
||||
local data_label =
|
||||
Gui.element(function(_,parent,label_data)
|
||||
Gui.element(function(_, parent, label_data)
|
||||
local data_name = label_data.name
|
||||
local data_subname = label_data.subname
|
||||
local data_fullname = data_subname and data_name..data_subname or data_name
|
||||
@@ -178,13 +178,13 @@ Gui.element(function(_,parent,label_data)
|
||||
local name_label = parent.add{
|
||||
type = 'label',
|
||||
name = data_fullname..'-label',
|
||||
caption = {'rocket-info.data-caption-'..data_name,data_subname},
|
||||
tooltip = {'rocket-info.data-tooltip-'..data_name,data_subname}
|
||||
caption = {'rocket-info.data-caption-'..data_name, data_subname},
|
||||
tooltip = {'rocket-info.data-tooltip-'..data_name, data_subname}
|
||||
}
|
||||
name_label.style.padding = {0,2}
|
||||
name_label.style.padding = {0, 2}
|
||||
|
||||
--- Right aligned label to store the data
|
||||
local alignment = Gui.alignment(parent,data_fullname)
|
||||
local alignment = Gui.alignment(parent, data_fullname)
|
||||
local element =
|
||||
alignment.add{
|
||||
type = 'label',
|
||||
@@ -192,17 +192,17 @@ Gui.element(function(_,parent,label_data)
|
||||
caption = label_data.value,
|
||||
tooltip = label_data.tooltip
|
||||
}
|
||||
element.style.padding = {0,2}
|
||||
element.style.padding = {0, 2}
|
||||
|
||||
return element
|
||||
end)
|
||||
|
||||
-- Used to update the captions and tooltips on the data labels
|
||||
local function update_data_labels(parent,data_label_data)
|
||||
local function update_data_labels(parent, data_label_data)
|
||||
for _, label_data in ipairs(data_label_data) do
|
||||
local data_name = label_data.subname and label_data.name..label_data.subname or label_data.name
|
||||
if not parent[data_name] then
|
||||
data_label(parent,label_data)
|
||||
data_label(parent, label_data)
|
||||
else
|
||||
local data_label_element = parent[data_name].label
|
||||
data_label_element.tooltip = label_data.tooltip
|
||||
@@ -220,7 +220,7 @@ local function get_progress_data(force_name)
|
||||
if not rocket_silo or not rocket_silo.valid then
|
||||
-- Remove from list if not valid
|
||||
force_silos[silo_data.name] = nil
|
||||
table.insert(progress_data,{
|
||||
table.insert(progress_data, {
|
||||
silo_name = silo_data.name,
|
||||
remove = true
|
||||
})
|
||||
@@ -228,14 +228,14 @@ local function get_progress_data(force_name)
|
||||
else
|
||||
-- Get the progress caption and tooltip
|
||||
local progress_color = Colors.white
|
||||
local progress_caption = {'rocket-info.progress-caption',rocket_silo.rocket_parts}
|
||||
local progress_tooltip = {'rocket-info.progress-tooltip',silo_data.launched or 0}
|
||||
local progress_caption = {'rocket-info.progress-caption', rocket_silo.rocket_parts}
|
||||
local progress_tooltip = {'rocket-info.progress-tooltip', silo_data.launched or 0}
|
||||
local status = rocket_silo.status == defines.entity_status.waiting_to_launch_rocket
|
||||
if status and silo_data.awaiting_reset then
|
||||
progress_caption = {'rocket-info.progress-launched'}
|
||||
progress_color = Colors.green
|
||||
elseif status then
|
||||
progress_caption = {'rocket-info.progress-caption',100}
|
||||
progress_caption = {'rocket-info.progress-caption', 100}
|
||||
progress_color = Colors.cyan
|
||||
else
|
||||
silo_data.awaiting_reset = false
|
||||
@@ -250,7 +250,7 @@ local function get_progress_data(force_name)
|
||||
end
|
||||
|
||||
-- Insert the gui data
|
||||
table.insert(progress_data,{
|
||||
table.insert(progress_data, {
|
||||
silo_name = silo_data.name,
|
||||
position = rocket_silo.position,
|
||||
allow_launch = not silo_data.awaiting_reset and status or false,
|
||||
@@ -267,7 +267,7 @@ local function get_progress_data(force_name)
|
||||
end
|
||||
|
||||
--- Update the build progress section
|
||||
local function update_build_progress(parent,progress_data)
|
||||
local function update_build_progress(parent, progress_data)
|
||||
local show_message = true
|
||||
for _, silo_data in ipairs(progress_data) do
|
||||
parent.parent.no_silos.visible = false
|
||||
@@ -285,7 +285,7 @@ local function update_build_progress(parent,progress_data)
|
||||
elseif not progress_label then
|
||||
-- Add the rocket to the list
|
||||
show_message = false
|
||||
rocket_entry(parent,silo_data)
|
||||
rocket_entry(parent, silo_data)
|
||||
|
||||
else
|
||||
show_message = false
|
||||
@@ -323,7 +323,7 @@ local function get_stats_data(force_name)
|
||||
-- Format the first launch data
|
||||
if config.stats.show_first_rocket then
|
||||
local value = stats.first_launch or 0
|
||||
table.insert(stats_data,{
|
||||
table.insert(stats_data, {
|
||||
name = 'first-launch',
|
||||
value = time_formats.caption_hours(value),
|
||||
tooltip = time_formats.tooltip_hours(value)
|
||||
@@ -333,7 +333,7 @@ local function get_stats_data(force_name)
|
||||
-- Format the last launch data
|
||||
if config.stats.show_last_rocket then
|
||||
local value = stats.last_launch or 0
|
||||
table.insert(stats_data,{
|
||||
table.insert(stats_data, {
|
||||
name = 'last-launch',
|
||||
value = time_formats.caption_hours(value),
|
||||
tooltip = time_formats.tooltip_hours(value)
|
||||
@@ -343,7 +343,7 @@ local function get_stats_data(force_name)
|
||||
-- Format fastest launch data
|
||||
if config.stats.show_fastest_rocket then
|
||||
local value = stats.fastest_launch or 0
|
||||
table.insert(stats_data,{
|
||||
table.insert(stats_data, {
|
||||
name = 'fastest-launch',
|
||||
value = time_formats.caption_hours(value),
|
||||
tooltip = time_formats.tooltip_hours(value)
|
||||
@@ -354,18 +354,18 @@ local function get_stats_data(force_name)
|
||||
if config.stats.show_total_rockets then
|
||||
local total_rockets = Rockets.get_game_rocket_count()
|
||||
total_rockets = total_rockets == 0 and 1 or total_rockets
|
||||
local percentage = math.round(force_rockets/total_rockets,3)*100
|
||||
table.insert(stats_data,{
|
||||
local percentage = math.round(force_rockets/total_rockets, 3)*100
|
||||
table.insert(stats_data, {
|
||||
name = 'total-rockets',
|
||||
value = force_rockets,
|
||||
tooltip = {'rocket-info.value-tooltip-total-rockets',percentage}
|
||||
tooltip = {'rocket-info.value-tooltip-total-rockets', percentage}
|
||||
})
|
||||
end
|
||||
|
||||
-- Format game avg data
|
||||
if config.stats.show_game_avg then
|
||||
local avg = force_rockets > 0 and math.floor(game.tick/force_rockets) or 0
|
||||
table.insert(stats_data,{
|
||||
table.insert(stats_data, {
|
||||
name = 'avg-launch',
|
||||
value = time_formats.caption(avg),
|
||||
tooltip = time_formats.tooltip(avg)
|
||||
@@ -373,9 +373,9 @@ local function get_stats_data(force_name)
|
||||
end
|
||||
|
||||
-- Format rolling avg data
|
||||
for _,avg_over in pairs(config.stats.rolling_avg) do
|
||||
local avg = Rockets.get_rolling_average(force_name,avg_over)
|
||||
table.insert(stats_data,{
|
||||
for _, avg_over in pairs(config.stats.rolling_avg) do
|
||||
local avg = Rockets.get_rolling_average(force_name, avg_over)
|
||||
table.insert(stats_data, {
|
||||
name = 'avg-launch-n',
|
||||
subname = avg_over,
|
||||
value = time_formats.caption(avg),
|
||||
@@ -392,17 +392,17 @@ local function get_milestone_data(force_name)
|
||||
local force_rockets = Rockets.get_rocket_count(force_name)
|
||||
local milestone_data = {}
|
||||
|
||||
for _,milestone in ipairs(config.milestones) do
|
||||
for _, milestone in ipairs(config.milestones) do
|
||||
if milestone <= force_rockets then
|
||||
local time = Rockets.get_rocket_time(force_name,milestone)
|
||||
table.insert(milestone_data,{
|
||||
local time = Rockets.get_rocket_time(force_name, milestone)
|
||||
table.insert(milestone_data, {
|
||||
name = 'milestone-n',
|
||||
subname = milestone,
|
||||
value = time_formats.caption_hours(time),
|
||||
tooltip = time_formats.tooltip_hours(time)
|
||||
})
|
||||
else
|
||||
table.insert(milestone_data,{
|
||||
table.insert(milestone_data, {
|
||||
name = 'milestone-n',
|
||||
subname = milestone,
|
||||
value = {'rocket-info.data-caption-milestone-next'},
|
||||
@@ -425,7 +425,7 @@ Gui.element{
|
||||
tooltip = {'rocket-info.toggle-section-tooltip'}
|
||||
}
|
||||
:style(Gui.sprite_style(20))
|
||||
:on_click(function(_,element,_)
|
||||
:on_click(function(_, element, _)
|
||||
local header_flow = element.parent
|
||||
local flow_name = header_flow.caption
|
||||
local flow = header_flow.parent.parent[flow_name]
|
||||
@@ -443,7 +443,7 @@ end)
|
||||
-- Draw a section header and main scroll
|
||||
-- @element rocket_list_container
|
||||
local section =
|
||||
Gui.element(function(_,parent,section_name,table_size)
|
||||
Gui.element(function(_, parent, section_name, table_size)
|
||||
-- Draw the header for the section
|
||||
local header = Gui.header(
|
||||
parent,
|
||||
@@ -458,7 +458,7 @@ Gui.element(function(_,parent,section_name,table_size)
|
||||
toggle_section(header)
|
||||
|
||||
-- Table used to store the data
|
||||
local scroll_table = Gui.scroll_table(parent,215,table_size,section_name)
|
||||
local scroll_table = Gui.scroll_table(parent, 215, table_size, section_name)
|
||||
scroll_table.parent.visible = false
|
||||
|
||||
-- Return the flow table
|
||||
@@ -468,9 +468,9 @@ end)
|
||||
--- Main gui container for the left flow
|
||||
-- @element rocket_list_container
|
||||
local rocket_list_container =
|
||||
Gui.element(function(event_trigger,parent)
|
||||
Gui.element(function(event_trigger, parent)
|
||||
-- Draw the internal container
|
||||
local container = Gui.container(parent,event_trigger,200)
|
||||
local container = Gui.container(parent, event_trigger, 200)
|
||||
|
||||
-- Set the container style
|
||||
local style = container.style
|
||||
@@ -480,27 +480,27 @@ Gui.element(function(event_trigger,parent)
|
||||
local force_name = player.force.name
|
||||
-- Draw stats section
|
||||
if config.stats.show_stats then
|
||||
update_data_labels(section(container,'stats',2),get_stats_data(force_name))
|
||||
update_data_labels(section(container, 'stats', 2), get_stats_data(force_name))
|
||||
end
|
||||
|
||||
-- Draw milestones section
|
||||
if config.milestones.show_milestones then
|
||||
update_data_labels(section(container,'milestones',2),get_milestone_data(force_name))
|
||||
update_data_labels(section(container, 'milestones', 2), get_milestone_data(force_name))
|
||||
end
|
||||
|
||||
-- Draw build progress list
|
||||
if config.progress.show_progress then
|
||||
local col_count = 3
|
||||
if check_player_permissions(player,'remote_launch') then col_count = col_count+1 end
|
||||
if check_player_permissions(player,'toggle_active') then col_count = col_count+1 end
|
||||
local progress = section(container,'progress',col_count)
|
||||
if check_player_permissions(player, 'remote_launch') then col_count = col_count+1 end
|
||||
if check_player_permissions(player, 'toggle_active') then col_count = col_count+1 end
|
||||
local progress = section(container, 'progress', col_count)
|
||||
-- Label used when there are no active silos
|
||||
local no_silos = progress.parent.add{
|
||||
type = 'label',
|
||||
name = 'no_silos',
|
||||
caption = {'rocket-info.progress-no-silos'}
|
||||
}
|
||||
no_silos.style.padding = {1,2}
|
||||
no_silos.style.padding = {1, 2}
|
||||
update_build_progress(progress, get_progress_data(force_name))
|
||||
end
|
||||
|
||||
@@ -508,13 +508,13 @@ Gui.element(function(event_trigger,parent)
|
||||
return container.parent
|
||||
end)
|
||||
:add_to_left_flow(function(player)
|
||||
return player.force.rockets_launched > 0 and Roles.player_allowed(player,'gui/rocket-info')
|
||||
return player.force.rockets_launched > 0 and Roles.player_allowed(player, 'gui/rocket-info')
|
||||
end)
|
||||
|
||||
--- Button on the top flow used to toggle the container
|
||||
-- @element toggle_left_element
|
||||
Gui.left_toolbar_button('entity/rocket-silo', {'rocket-info.main-tooltip'}, rocket_list_container, function(player)
|
||||
return Roles.player_allowed(player,'gui/rocket-info')
|
||||
return Roles.player_allowed(player, 'gui/rocket-info')
|
||||
end)
|
||||
|
||||
--- Update the gui for all players on a force
|
||||
@@ -522,21 +522,21 @@ local function update_rocket_gui_all(force_name)
|
||||
local stats = get_stats_data(force_name)
|
||||
local milestones = get_milestone_data(force_name)
|
||||
local progress = get_progress_data(force_name)
|
||||
for _,player in pairs(game.forces[force_name].players) do
|
||||
local frame = Gui.get_left_element(player,rocket_list_container)
|
||||
for _, player in pairs(game.forces[force_name].players) do
|
||||
local frame = Gui.get_left_element(player, rocket_list_container)
|
||||
local container = frame.container
|
||||
update_data_labels(container.stats.table,stats)
|
||||
update_data_labels(container.milestones.table,milestones)
|
||||
update_build_progress(container.progress.table,progress)
|
||||
update_data_labels(container.stats.table, stats)
|
||||
update_data_labels(container.milestones.table, milestones)
|
||||
update_build_progress(container.progress.table, progress)
|
||||
end
|
||||
end
|
||||
|
||||
--- Event used to update the stats when a rocket is launched
|
||||
Event.add(defines.events.on_rocket_launched,function(event)
|
||||
Event.add(defines.events.on_rocket_launched, function(event)
|
||||
local force = event.rocket_silo.force
|
||||
update_rocket_gui_all(force.name)
|
||||
if force.rockets_launched == 1 then
|
||||
for _,player in pairs(force.players) do
|
||||
for _, player in pairs(force.players) do
|
||||
Gui.update_top_flow(player)
|
||||
end
|
||||
end
|
||||
@@ -545,23 +545,23 @@ end)
|
||||
--- Update only the progress gui for a force
|
||||
local function update_rocket_gui_progress(force_name)
|
||||
local progress = get_progress_data(force_name)
|
||||
for _,player in pairs(game.forces[force_name].players) do
|
||||
local frame = Gui.get_left_element(player,rocket_list_container)
|
||||
for _, player in pairs(game.forces[force_name].players) do
|
||||
local frame = Gui.get_left_element(player, rocket_list_container)
|
||||
local container = frame.container
|
||||
update_build_progress(container.progress.table,progress)
|
||||
update_build_progress(container.progress.table, progress)
|
||||
end
|
||||
end
|
||||
|
||||
--- Event used to set a rocket silo to be awaiting reset
|
||||
Event.add(defines.events.on_rocket_launch_ordered,function(event)
|
||||
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
||||
local silo = event.rocket_silo
|
||||
local silo_data = Rockets.get_silo_data(silo)
|
||||
silo_data.awaiting_reset = true
|
||||
update_rocket_gui_progress(silo.force.name)
|
||||
end)
|
||||
|
||||
Event.on_nth_tick(150,function()
|
||||
for _,force in pairs(game.forces) do
|
||||
Event.on_nth_tick(150, function()
|
||||
for _, force in pairs(game.forces) do
|
||||
if #Rockets.get_silos(force.name) > 0 then
|
||||
update_rocket_gui_progress(force.name)
|
||||
end
|
||||
@@ -576,20 +576,20 @@ local function on_built(event)
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_built_entity,on_built)
|
||||
Event.add(defines.events.on_robot_built_entity,on_built)
|
||||
Event.add(defines.events.on_built_entity, on_built)
|
||||
Event.add(defines.events.on_robot_built_entity, on_built)
|
||||
|
||||
--- Redraw the progress section on role change
|
||||
local function role_update_event(event)
|
||||
if not config.progress.show_progress then return end
|
||||
local player = game.players[event.player_index]
|
||||
local container = Gui.get_left_element(player,rocket_list_container).container
|
||||
local container = Gui.get_left_element(player, rocket_list_container).container
|
||||
local progress_scroll = container.progress
|
||||
Gui.destroy_if_valid(progress_scroll.table)
|
||||
|
||||
local col_count = 3
|
||||
if check_player_permissions(player,'remote_launch') then col_count = col_count+1 end
|
||||
if check_player_permissions(player,'toggle_active') then col_count = col_count+1 end
|
||||
if check_player_permissions(player, 'remote_launch') then col_count = col_count+1 end
|
||||
if check_player_permissions(player, 'toggle_active') then col_count = col_count+1 end
|
||||
local progress = progress_scroll.add{
|
||||
type = 'table',
|
||||
name = 'table',
|
||||
@@ -599,7 +599,7 @@ local function role_update_event(event)
|
||||
update_build_progress(progress, get_progress_data(player.force.name))
|
||||
end
|
||||
|
||||
Event.add(Roles.events.on_role_assigned,role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned,role_update_event)
|
||||
Event.add(Roles.events.on_role_assigned, role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned, role_update_event)
|
||||
|
||||
return rocket_list_container
|
||||
@@ -11,19 +11,19 @@ local config = require 'config.gui.science' --- @dep config.gui.science
|
||||
local Production = require 'modules.control.production' --- @dep modules.control.production
|
||||
local format_time = _C.format_time --- @dep expcore.common
|
||||
|
||||
local null_time_short = {'science-info.eta-time',format_time(0,{hours=true,minutes=true,seconds=true,time=true,null=true})}
|
||||
local null_time_long = format_time(0,{hours=true,minutes=true,seconds=true,long=true,null=true})
|
||||
local null_time_short = {'science-info.eta-time', format_time(0, {hours=true, minutes=true, seconds=true, time=true, null=true})}
|
||||
local null_time_long = format_time(0, {hours=true, minutes=true, seconds=true, long=true, null=true})
|
||||
|
||||
--- Data label that contains the value and the surfix
|
||||
-- @element production_label
|
||||
local production_label =
|
||||
Gui.element(function(_,parent,production_label_data)
|
||||
Gui.element(function(_, parent, production_label_data)
|
||||
local name = production_label_data.name
|
||||
local tooltip = production_label_data.tooltip
|
||||
local color = production_label_data.color
|
||||
|
||||
-- Add an alignment for the number
|
||||
local alignment = Gui.alignment(parent,name)
|
||||
local alignment = Gui.alignment(parent, name)
|
||||
|
||||
-- Add the main value label
|
||||
local element =
|
||||
@@ -42,7 +42,7 @@ Gui.element(function(_,parent,production_label_data)
|
||||
parent.add{
|
||||
name = 'surfix-'..name,
|
||||
type = 'label',
|
||||
caption = {'science-info.unit',production_label_data.surfix},
|
||||
caption = {'science-info.unit', production_label_data.surfix},
|
||||
tooltip = tooltip
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ Gui.element(function(_,parent,production_label_data)
|
||||
end)
|
||||
|
||||
-- Get the data that is used with the production label
|
||||
local function get_production_label_data(name,tooltip,value,secondary)
|
||||
local function get_production_label_data(name, tooltip, value, secondary)
|
||||
local data_colour = Production.get_color(config.color_clamp, value, secondary)
|
||||
local surfix,caption = Production.format_number(value)
|
||||
local surfix, caption = Production.format_number(value)
|
||||
|
||||
return {
|
||||
name = name,
|
||||
@@ -70,20 +70,20 @@ local function get_production_label_data(name,tooltip,value,secondary)
|
||||
end
|
||||
|
||||
-- Updates a prodution label to match the current data
|
||||
local function update_production_label(parent,production_label_data)
|
||||
local function update_production_label(parent, production_label_data)
|
||||
local name = production_label_data.name
|
||||
local tooltip = production_label_data.tooltip
|
||||
local color = production_label_data.color
|
||||
|
||||
-- Update the production label
|
||||
local production_label_element = parent[name] and parent[name].label or production_label(parent,production_label_data)
|
||||
local production_label_element = parent[name] and parent[name].label or production_label(parent, production_label_data)
|
||||
production_label_element.caption = production_label_data.caption
|
||||
production_label_element.tooltip = production_label_data.tooltip
|
||||
production_label_element.style.font_color = color
|
||||
|
||||
-- Update the surfix label
|
||||
local surfix_element = parent['surfix-'..name]
|
||||
surfix_element.caption = {'science-info.unit',production_label_data.surfix}
|
||||
surfix_element.caption = {'science-info.unit', production_label_data.surfix}
|
||||
surfix_element.tooltip = tooltip
|
||||
surfix_element.style.font_color = color
|
||||
|
||||
@@ -92,7 +92,7 @@ end
|
||||
--- Adds 4 elements that show the data for a science pack
|
||||
-- @element science_pack_base
|
||||
local science_pack_base =
|
||||
Gui.element(function(_,parent,science_pack_data)
|
||||
Gui.element(function(_, parent, science_pack_data)
|
||||
local science_pack = science_pack_data.science_pack
|
||||
|
||||
-- Draw the icon for the science pack
|
||||
@@ -110,7 +110,7 @@ Gui.element(function(_,parent,science_pack_data)
|
||||
local pack_icon_style = pack_icon.style
|
||||
pack_icon_style.height = 55
|
||||
if icon_style == 'quick_bar_slot_button' then
|
||||
pack_icon_style.padding = {0,-2}
|
||||
pack_icon_style.padding = {0, -2}
|
||||
pack_icon_style.width = 36
|
||||
end
|
||||
|
||||
@@ -121,7 +121,7 @@ Gui.element(function(_,parent,science_pack_data)
|
||||
type = 'frame',
|
||||
style = 'bordered_frame'
|
||||
}
|
||||
delta_flow.style.padding = {0,3}
|
||||
delta_flow.style.padding = {0, 3}
|
||||
|
||||
-- Draw the delta flow table
|
||||
local delta_table =
|
||||
@@ -133,15 +133,15 @@ Gui.element(function(_,parent,science_pack_data)
|
||||
delta_table.style.padding = 0
|
||||
|
||||
-- Draw the production labels
|
||||
update_production_label(delta_table,science_pack_data.positive)
|
||||
update_production_label(delta_table,science_pack_data.negative)
|
||||
update_production_label(parent,science_pack_data.net)
|
||||
update_production_label(delta_table, science_pack_data.positive)
|
||||
update_production_label(delta_table, science_pack_data.negative)
|
||||
update_production_label(parent, science_pack_data.net)
|
||||
|
||||
-- Return the pack icon
|
||||
return pack_icon
|
||||
end)
|
||||
|
||||
local function get_science_pack_data(player,science_pack)
|
||||
local function get_science_pack_data(player, science_pack)
|
||||
local force = player.force
|
||||
|
||||
-- Check that some packs have been made
|
||||
@@ -186,28 +186,28 @@ local function get_science_pack_data(player,science_pack)
|
||||
|
||||
end
|
||||
|
||||
local function update_science_pack(pack_table,science_pack_data)
|
||||
local function update_science_pack(pack_table, science_pack_data)
|
||||
if not science_pack_data then return end
|
||||
local science_pack = science_pack_data.science_pack
|
||||
pack_table.parent.non_made.visible = false
|
||||
|
||||
-- Update the icon
|
||||
local pack_icon = pack_table['icon-'..science_pack] or science_pack_base(pack_table,science_pack_data)
|
||||
local pack_icon = pack_table['icon-'..science_pack] or science_pack_base(pack_table, science_pack_data)
|
||||
local icon_style = science_pack_data.icon_style
|
||||
pack_icon.style = icon_style
|
||||
|
||||
local pack_icon_style = pack_icon.style
|
||||
pack_icon_style.height = 55
|
||||
if icon_style == 'quick_bar_slot_button' then
|
||||
pack_icon_style.padding = {0,-2}
|
||||
pack_icon_style.padding = {0, -2}
|
||||
pack_icon_style.width = 36
|
||||
end
|
||||
|
||||
-- Update the production labels
|
||||
local delta_table = pack_table['delta-'..science_pack].table
|
||||
update_production_label(delta_table,science_pack_data.positive)
|
||||
update_production_label(delta_table,science_pack_data.negative)
|
||||
update_production_label(pack_table,science_pack_data.net)
|
||||
update_production_label(delta_table, science_pack_data.positive)
|
||||
update_production_label(delta_table, science_pack_data.negative)
|
||||
update_production_label(pack_table, science_pack_data.net)
|
||||
|
||||
end
|
||||
|
||||
@@ -226,7 +226,7 @@ local function get_eta_label_data(player)
|
||||
local remaining = research.research_unit_count*(1-progress)
|
||||
|
||||
-- Check for the limiting science pack
|
||||
for _,ingredient in pairs(research.research_unit_ingredients) do
|
||||
for _, ingredient in pairs(research.research_unit_ingredients) do
|
||||
local pack_name = ingredient.name
|
||||
local required = ingredient.amount * remaining
|
||||
local time = Production.get_consumsion_eta(force, pack_name, defines.flow_precision_index.one_minute, required)
|
||||
@@ -238,14 +238,14 @@ local function get_eta_label_data(player)
|
||||
-- Return the caption and tooltip
|
||||
return limit and limit > 0 and {
|
||||
research = true,
|
||||
caption = format_time(limit,{hours=true,minutes=true,seconds=true,time=true}),
|
||||
tooltip = format_time(limit,{hours=true,minutes=true,seconds=true,long=true})
|
||||
caption = format_time(limit, {hours=true, minutes=true, seconds=true, time=true}),
|
||||
tooltip = format_time(limit, {hours=true, minutes=true, seconds=true, long=true})
|
||||
} or { research = false }
|
||||
|
||||
end
|
||||
|
||||
-- Updates the eta label
|
||||
local function update_eta_label(element,eta_label_data)
|
||||
local function update_eta_label(element, eta_label_data)
|
||||
-- If no research selected show null
|
||||
if not eta_label_data.research then
|
||||
element.caption = null_time_short
|
||||
@@ -254,24 +254,24 @@ local function update_eta_label(element,eta_label_data)
|
||||
end
|
||||
|
||||
-- Update the element
|
||||
element.caption = {'science-info.eta-time',eta_label_data.caption}
|
||||
element.caption = {'science-info.eta-time', eta_label_data.caption}
|
||||
element.tooltip = eta_label_data.tooltip
|
||||
end
|
||||
|
||||
--- Main task list container for the left flow
|
||||
-- @element task_list_container
|
||||
local science_info_container =
|
||||
Gui.element(function(event_trigger,parent)
|
||||
Gui.element(function(event_trigger, parent)
|
||||
local player = Gui.get_player_from_element(parent)
|
||||
|
||||
-- Draw the internal container
|
||||
local container = Gui.container(parent,event_trigger,200)
|
||||
local container = Gui.container(parent, event_trigger, 200)
|
||||
|
||||
-- Draw the header
|
||||
Gui.header(container, {'science-info.main-caption'}, {'science-info.main-tooltip'})
|
||||
|
||||
-- Draw the scroll table for the tasks
|
||||
local scroll_table = Gui.scroll_table(container,178,4)
|
||||
local scroll_table = Gui.scroll_table(container, 178, 4)
|
||||
|
||||
-- Draw the no packs label
|
||||
local no_packs_label =
|
||||
@@ -283,7 +283,7 @@ Gui.element(function(event_trigger,parent)
|
||||
|
||||
-- Change the style of the no packs label
|
||||
local no_packs_style = no_packs_label.style
|
||||
no_packs_style.padding = {2,4}
|
||||
no_packs_style.padding = {2, 4}
|
||||
no_packs_style.single_line = false
|
||||
no_packs_style.width = 200
|
||||
|
||||
@@ -303,13 +303,13 @@ Gui.element(function(event_trigger,parent)
|
||||
}
|
||||
|
||||
-- Update the eta
|
||||
update_eta_label(eta_label,get_eta_label_data(player))
|
||||
update_eta_label(eta_label, get_eta_label_data(player))
|
||||
|
||||
end
|
||||
|
||||
-- Add packs which have been made
|
||||
for _,science_pack in ipairs(config) do
|
||||
update_science_pack(scroll_table,get_science_pack_data(player,science_pack))
|
||||
for _, science_pack in ipairs(config) do
|
||||
update_science_pack(scroll_table, get_science_pack_data(player, science_pack))
|
||||
end
|
||||
|
||||
-- Return the exteral container
|
||||
@@ -320,16 +320,16 @@ end)
|
||||
--- Button on the top flow used to toggle the task list container
|
||||
-- @element toggle_left_element
|
||||
Gui.left_toolbar_button('entity/lab', {'science-info.main-tooltip'}, science_info_container, function(player)
|
||||
return Roles.player_allowed(player,'gui/science-info')
|
||||
return Roles.player_allowed(player, 'gui/science-info')
|
||||
end)
|
||||
|
||||
--- Updates the gui every 1 second
|
||||
Event.on_nth_tick(60,function()
|
||||
Event.on_nth_tick(60, function()
|
||||
local force_pack_data = {}
|
||||
local force_eta_data = {}
|
||||
for _,player in pairs(game.connected_players) do
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local force_name = player.force.name
|
||||
local frame = Gui.get_left_element(player,science_info_container)
|
||||
local frame = Gui.get_left_element(player, science_info_container)
|
||||
local container = frame.container
|
||||
|
||||
-- Update the science packs
|
||||
@@ -339,16 +339,16 @@ Event.on_nth_tick(60,function()
|
||||
-- No data in chache so it needs to be generated
|
||||
pack_data = {}
|
||||
force_pack_data[force_name] = pack_data
|
||||
for _,science_pack in ipairs(config) do
|
||||
local next_data = get_science_pack_data(player,science_pack)
|
||||
for _, science_pack in ipairs(config) do
|
||||
local next_data = get_science_pack_data(player, science_pack)
|
||||
pack_data[science_pack] = next_data
|
||||
update_science_pack(scroll_table,next_data)
|
||||
update_science_pack(scroll_table, next_data)
|
||||
end
|
||||
|
||||
else
|
||||
-- Data found in chache is no need to generate it
|
||||
for _,next_data in ipairs(pack_data) do
|
||||
update_science_pack(scroll_table,next_data)
|
||||
for _, next_data in ipairs(pack_data) do
|
||||
update_science_pack(scroll_table, next_data)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -361,11 +361,11 @@ Event.on_nth_tick(60,function()
|
||||
-- No data in chache so it needs to be generated
|
||||
eta_data = get_eta_label_data(player)
|
||||
force_eta_data[force_name] = eta_data
|
||||
update_eta_label(eta_label,eta_data)
|
||||
update_eta_label(eta_label, eta_data)
|
||||
|
||||
else
|
||||
-- Data found in chache is no need to generate it
|
||||
update_eta_label(eta_label,eta_data)
|
||||
update_eta_label(eta_label, eta_data)
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ Gui.element{
|
||||
|
||||
--- Toggles if the server ups is visbile
|
||||
-- @command server-ups
|
||||
Commands.new_command('server-ups','Toggle the server ups display')
|
||||
:add_alias('sups','ups')
|
||||
Commands.new_command('server-ups', 'Toggle the server ups display')
|
||||
:add_alias('sups', 'ups')
|
||||
:register(function(player)
|
||||
local label = player.gui.screen[server_ups.name]
|
||||
if not global.ext or not global.ext.server_ups then
|
||||
@@ -42,7 +42,7 @@ local function set_location(event)
|
||||
end
|
||||
|
||||
-- Draw the label when the player joins
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local label = server_ups(player.gui.screen)
|
||||
label.visible = false
|
||||
@@ -50,15 +50,15 @@ Event.add(defines.events.on_player_created,function(event)
|
||||
end)
|
||||
|
||||
-- Update the caption for all online players
|
||||
Event.on_nth_tick(60,function()
|
||||
Event.on_nth_tick(60, function()
|
||||
if global.ext and global.ext.server_ups then
|
||||
local caption = 'SUPS = '..global.ext.server_ups
|
||||
for _,player in pairs(game.connected_players) do
|
||||
for _, player in pairs(game.connected_players) do
|
||||
player.gui.screen[server_ups.name].caption = caption
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Update when res or ui scale changes
|
||||
Event.add(defines.events.on_player_display_resolution_changed,set_location)
|
||||
Event.add(defines.events.on_player_display_scale_changed,set_location)
|
||||
Event.add(defines.events.on_player_display_resolution_changed, set_location)
|
||||
Event.add(defines.events.on_player_display_scale_changed, set_location)
|
||||
@@ -18,7 +18,7 @@ local Styles = {
|
||||
}
|
||||
|
||||
--- If a player is allowed to use the edit buttons
|
||||
local function check_player_permissions(player,task)
|
||||
local function check_player_permissions(player, task)
|
||||
if task then
|
||||
-- When a task is given check if the player can edit it
|
||||
local allow_edit_task = config.allow_edit_task
|
||||
@@ -34,7 +34,7 @@ local function check_player_permissions(player,task)
|
||||
elseif allow_edit_task == 'admin' then
|
||||
return player.admin
|
||||
elseif allow_edit_task == 'expcore.roles' then
|
||||
return Roles.player_allowed(player,config.expcore_roles_allow_edit_task)
|
||||
return Roles.player_allowed(player, config.expcore_roles_allow_edit_task)
|
||||
end
|
||||
|
||||
-- Return false as all other condidtions have not been met
|
||||
@@ -49,7 +49,7 @@ local function check_player_permissions(player,task)
|
||||
elseif allow_add_task == 'admin' then
|
||||
return player.admin
|
||||
elseif allow_add_task == 'expcore.roles' then
|
||||
return Roles.player_allowed(player,config.expcore_roles_allow_add_task)
|
||||
return Roles.player_allowed(player, config.expcore_roles_allow_add_task)
|
||||
end
|
||||
|
||||
-- Return false as all other condidtions have not been met
|
||||
@@ -67,8 +67,8 @@ Gui.element{
|
||||
style = 'tool_button'
|
||||
}
|
||||
:style(Styles.sprite20)
|
||||
:on_click(function(player,_,_)
|
||||
Tasks.add_task(player.force.name,nil,player.name)
|
||||
:on_click(function(player, _,_)
|
||||
Tasks.add_task(player.force.name, nil, player.name)
|
||||
end)
|
||||
|
||||
--- Button displayed next to tasks which the user is can edit, used to start editing a task
|
||||
@@ -81,9 +81,9 @@ Gui.element{
|
||||
style = 'tool_button'
|
||||
}
|
||||
:style(Styles.sprite20)
|
||||
:on_click(function(player,element,_)
|
||||
:on_click(function(player, element, _)
|
||||
local task_id = element.parent.name:sub(6)
|
||||
Tasks.set_editing(task_id,player.name,true)
|
||||
Tasks.set_editing(task_id, player.name, true)
|
||||
end)
|
||||
|
||||
--- Button displayed next to tasks which the user is can edit, used to delete a task from the list
|
||||
@@ -96,7 +96,7 @@ Gui.element{
|
||||
style = 'tool_button'
|
||||
}
|
||||
:style(Styles.sprite20)
|
||||
:on_click(function(_,element,_)
|
||||
:on_click(function(_, element, _)
|
||||
local task_id = element.parent.name:sub(6)
|
||||
Tasks.remove_task(task_id)
|
||||
end)
|
||||
@@ -104,7 +104,7 @@ end)
|
||||
--- Set of three elements which make up each row of the task table
|
||||
-- @element add_task_base
|
||||
local add_task_base =
|
||||
Gui.element(function(_,parent,task_id)
|
||||
Gui.element(function(_, parent, task_id)
|
||||
-- Add the task number label
|
||||
local task_number = parent.add{
|
||||
name = 'count-'..task_id,
|
||||
@@ -118,7 +118,7 @@ Gui.element(function(_,parent,task_id)
|
||||
task_flow.style.padding = 0
|
||||
|
||||
-- Add the two edit buttons outside the task flow
|
||||
local edit_flow = Gui.alignment(parent,'edit-'..task_id)
|
||||
local edit_flow = Gui.alignment(parent, 'edit-'..task_id)
|
||||
edit_task(edit_flow)
|
||||
discard_task(edit_flow)
|
||||
|
||||
@@ -127,7 +127,7 @@ Gui.element(function(_,parent,task_id)
|
||||
end)
|
||||
|
||||
-- Removes the three elements that are added as part of the task base
|
||||
local function remove_task_base(parent,task_id)
|
||||
local function remove_task_base(parent, task_id)
|
||||
Gui.destroy_if_valid(parent['count-'..task_id])
|
||||
Gui.destroy_if_valid(parent['edit-'..task_id])
|
||||
Gui.destroy_if_valid(parent[task_id])
|
||||
@@ -144,11 +144,11 @@ Gui.element{
|
||||
style = 'shortcut_bar_button_green'
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(player,element,_)
|
||||
:on_click(function(player, element, _)
|
||||
local task_id = element.parent.name
|
||||
local new_message = element.parent[task_editing.name].text
|
||||
Tasks.set_editing(task_id,player.name)
|
||||
Tasks.update_task(task_id,new_message,player.name)
|
||||
Tasks.set_editing(task_id, player.name)
|
||||
Tasks.update_task(task_id, new_message, player.name)
|
||||
end)
|
||||
|
||||
--- Button displayed next to tasks which the user is currently editing, used to discard changes
|
||||
@@ -161,15 +161,15 @@ Gui.element{
|
||||
style = 'shortcut_bar_button_red'
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(player,element,_)
|
||||
:on_click(function(player, element, _)
|
||||
local task_id = element.parent.name
|
||||
Tasks.set_editing(task_id,player.name)
|
||||
Tasks.set_editing(task_id, player.name)
|
||||
end)
|
||||
|
||||
--- Editing state for a task, contrins a text field and the two edit buttons
|
||||
-- @element task_editing
|
||||
task_editing =
|
||||
Gui.element(function(event_trigger,parent,task)
|
||||
Gui.element(function(event_trigger, parent, task)
|
||||
local message = task.message
|
||||
|
||||
-- Draw the element
|
||||
@@ -192,17 +192,17 @@ end)
|
||||
maximal_width = 110,
|
||||
height = 20
|
||||
}
|
||||
:on_confirmed(function(player,element,_)
|
||||
:on_confirmed(function(player, element, _)
|
||||
local task_id = element.parent.name
|
||||
local new_message = element.text
|
||||
Tasks.set_editing(task_id,player.name)
|
||||
Tasks.update_task(task_id,new_message,player.name)
|
||||
Tasks.set_editing(task_id, player.name)
|
||||
Tasks.update_task(task_id, new_message, player.name)
|
||||
end)
|
||||
|
||||
--- Default state for a task, contains only a label with the task message
|
||||
-- @element task_label
|
||||
local task_label =
|
||||
Gui.element(function(_,parent,task)
|
||||
Gui.element(function(_, parent, task)
|
||||
local message = task.message
|
||||
local last_edit_name = task.last_edit_name
|
||||
local last_edit_time = task.last_edit_time
|
||||
@@ -220,7 +220,7 @@ end)
|
||||
}
|
||||
|
||||
--- Updates a task for a player
|
||||
local function update_task(player,task_table,task_id)
|
||||
local function update_task(player, task_table, task_id)
|
||||
local task = Tasks.get_task(task_id)
|
||||
local task_ids = Tasks.get_force_task_ids(player.force.name)
|
||||
local task_number = table.get_index(task_ids, task_id)
|
||||
@@ -228,18 +228,18 @@ local function update_task(player,task_table,task_id)
|
||||
-- Task no longer exists so should be removed from the list
|
||||
if not task then
|
||||
task_table.parent.no_tasks.visible = #task_ids == 0
|
||||
remove_task_base(task_table,task_id)
|
||||
remove_task_base(task_table, task_id)
|
||||
return
|
||||
end
|
||||
|
||||
-- Get the task flow for this task
|
||||
local task_flow = task_table[task_id] or add_task_base(task_table,task_id)
|
||||
local task_flow = task_table[task_id] or add_task_base(task_table, task_id)
|
||||
task_table.parent.no_tasks.visible = false
|
||||
task_table['count-'..task_id].caption = task_number..')'
|
||||
|
||||
-- Update the edit flow
|
||||
local edit_flow = task_table['edit-'..task_id]
|
||||
local player_allowed_edit = check_player_permissions(player,task)
|
||||
local player_allowed_edit = check_player_permissions(player, task)
|
||||
local players_editing = table.get_keys(task.curently_editing)
|
||||
local edit_task_element = edit_flow[edit_task.name]
|
||||
local discard_task_element = edit_flow[discard_task.name]
|
||||
@@ -248,14 +248,14 @@ local function update_task(player,task_table,task_id)
|
||||
discard_task_element.visible = player_allowed_edit
|
||||
if #players_editing > 0 then
|
||||
edit_task_element.hovered_sprite = 'utility/warning_icon'
|
||||
edit_task_element.tooltip = {'task-list.edit-tooltip',table.concat(players_editing,', ')}
|
||||
edit_task_element.tooltip = {'task-list.edit-tooltip', table.concat(players_editing, ', ')}
|
||||
else
|
||||
edit_task_element.hovered_sprite = edit_task_element.sprite
|
||||
edit_task_element.tooltip = {'task-list.edit-tooltip-none'}
|
||||
end
|
||||
|
||||
-- Check if the player is was editing and/or currently editing
|
||||
local task_entry = task_flow[task_editing.name] or task_label(task_flow,task)
|
||||
local task_entry = task_flow[task_editing.name] or task_label(task_flow, task)
|
||||
local player_was_editing = task_entry.type == 'textfield'
|
||||
local player_is_editing = task.curently_editing[player.name]
|
||||
|
||||
@@ -272,24 +272,24 @@ local function update_task(player,task_table,task_id)
|
||||
-- Player was editing but is no longer, remove text field and add label
|
||||
edit_task_element.enabled = true
|
||||
task_flow.clear()
|
||||
task_label(task_flow,task)
|
||||
task_label(task_flow, task)
|
||||
|
||||
elseif not player_was_editing and player_is_editing then
|
||||
-- Player was not editing but now is, remove label and add text field
|
||||
edit_task_element.enabled = false
|
||||
task_flow.clear()
|
||||
task_editing(task_flow,task).focus()
|
||||
task_table.parent.scroll_to_element(task_flow,'top-third')
|
||||
task_editing(task_flow, task).focus()
|
||||
task_table.parent.scroll_to_element(task_flow, 'top-third')
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- Update all the tasks for a player
|
||||
local function update_all_tasks(player,scroll_table)
|
||||
local function update_all_tasks(player, scroll_table)
|
||||
local task_ids = Tasks.get_force_task_ids(player.force.name)
|
||||
if #task_ids > 0 then
|
||||
for _,task_id in ipairs(task_ids) do
|
||||
update_task(player,scroll_table,task_id)
|
||||
for _, task_id in ipairs(task_ids) do
|
||||
update_task(player, scroll_table, task_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -297,9 +297,9 @@ end
|
||||
--- Main task list container for the left flow
|
||||
-- @element task_list_container
|
||||
local task_list_container =
|
||||
Gui.element(function(event_trigger,parent)
|
||||
Gui.element(function(event_trigger, parent)
|
||||
-- Draw the internal container
|
||||
local container = Gui.container(parent,event_trigger,200)
|
||||
local container = Gui.container(parent, event_trigger, 200)
|
||||
|
||||
-- Draw the header
|
||||
local header = Gui.header(
|
||||
@@ -315,7 +315,7 @@ Gui.element(function(event_trigger,parent)
|
||||
add_new_task_element.visible = check_player_permissions(player)
|
||||
|
||||
-- Draw the scroll table for the tasks
|
||||
local scroll_table = Gui.scroll_table(container,190,3)
|
||||
local scroll_table = Gui.scroll_table(container, 190, 3)
|
||||
scroll_table.draw_horizontal_lines = true
|
||||
scroll_table.vertical_centering = false
|
||||
|
||||
@@ -334,7 +334,7 @@ Gui.element(function(event_trigger,parent)
|
||||
|
||||
-- Change the style of the no tasks label
|
||||
local no_tasks_style = no_tasks_label.style
|
||||
no_tasks_style.padding = {2,4}
|
||||
no_tasks_style.padding = {2, 4}
|
||||
no_tasks_style.single_line = false
|
||||
no_tasks_style.width = 200
|
||||
|
||||
@@ -342,8 +342,8 @@ Gui.element(function(event_trigger,parent)
|
||||
local task_ids = Tasks.get_force_task_ids(player.force.name)
|
||||
if #task_ids > 0 then
|
||||
no_tasks_label.visible = false
|
||||
for _,task_id in ipairs(task_ids) do
|
||||
update_task(player,scroll_table,task_id)
|
||||
for _, task_id in ipairs(task_ids) do
|
||||
update_task(player, scroll_table, task_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -358,11 +358,11 @@ end)
|
||||
--- Button on the top flow used to toggle the task list container
|
||||
-- @element toggle_left_element
|
||||
Gui.left_toolbar_button('utility/not_enough_repair_packs_icon', {'task-list.main-tooltip'}, task_list_container, function(player)
|
||||
return Roles.player_allowed(player,'gui/task-list')
|
||||
return Roles.player_allowed(player, 'gui/task-list')
|
||||
end)
|
||||
|
||||
--- When a new task is added it will udpate the task list for everyone on that force
|
||||
Tasks.on_update(function(task,task_id,removed_task)
|
||||
Tasks.on_update(function(task, task_id, removed_task)
|
||||
-- Get the force to update, task is nil when removed
|
||||
local force
|
||||
if task then
|
||||
@@ -373,12 +373,12 @@ Tasks.on_update(function(task,task_id,removed_task)
|
||||
|
||||
-- Update the task for all the players on the force
|
||||
local task_ids = Tasks.get_force_task_ids(force.name)
|
||||
for _,player in pairs(force.connected_players) do
|
||||
local frame = Gui.get_left_element(player,task_list_container)
|
||||
for _, player in pairs(force.connected_players) do
|
||||
local frame = Gui.get_left_element(player, task_list_container)
|
||||
local scroll_table = frame.container.scroll.table
|
||||
|
||||
-- Update the task that was changed
|
||||
update_task(player,scroll_table,task_id)
|
||||
update_task(player, scroll_table, task_id)
|
||||
|
||||
-- Update the numbering of the other tasks if the task was removed
|
||||
if not task then
|
||||
@@ -391,26 +391,26 @@ Tasks.on_update(function(task,task_id,removed_task)
|
||||
end)
|
||||
|
||||
--- Update the tasks when the player joins
|
||||
Event.add(defines.events.on_player_joined_game,function(event)
|
||||
Event.add(defines.events.on_player_joined_game, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local frame = Gui.get_left_element(player,task_list_container)
|
||||
local frame = Gui.get_left_element(player, task_list_container)
|
||||
local scroll_table = frame.container.scroll.table
|
||||
update_all_tasks(player,scroll_table)
|
||||
update_all_tasks(player, scroll_table)
|
||||
end)
|
||||
|
||||
--- Makes sure the right buttons are present when roles change
|
||||
local function role_update_event(event)
|
||||
local player = game.players[event.player_index]
|
||||
local container = Gui.get_left_element(player,task_list_container).container
|
||||
local container = Gui.get_left_element(player, task_list_container).container
|
||||
|
||||
-- Update the tasks, incase the user can now edit them
|
||||
local scroll_table = container.scroll.table
|
||||
update_all_tasks(player,scroll_table)
|
||||
update_all_tasks(player, scroll_table)
|
||||
|
||||
-- Update the new task button incase the user can now add them
|
||||
local add_new_task_element = container.header.alignment[add_new_task.name]
|
||||
add_new_task_element.visible = check_player_permissions(player)
|
||||
end
|
||||
|
||||
Event.add(Roles.events.on_role_assigned,role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned,role_update_event)
|
||||
Event.add(Roles.events.on_role_assigned, role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned, role_update_event)
|
||||
@@ -27,7 +27,7 @@ end)
|
||||
|
||||
-- Table that stores a boolean value of weather to keep the warp gui open
|
||||
local keep_gui_open = {}
|
||||
Global.register(keep_gui_open,function(tbl)
|
||||
Global.register(keep_gui_open, function(tbl)
|
||||
keep_gui_open = tbl
|
||||
end)
|
||||
|
||||
@@ -40,7 +40,7 @@ local Styles = {
|
||||
|
||||
--- Returns if a player is allowed to edit the given warp
|
||||
--- If a player is allowed to use the edit buttons
|
||||
local function check_player_permissions(player,action,warp)
|
||||
local function check_player_permissions(player, action, warp)
|
||||
-- Check if the action is allow edit and then check bypass settings
|
||||
if action == 'allow_edit_warp' then
|
||||
-- Check if the warp is the spawn then it cant be edited
|
||||
@@ -62,7 +62,7 @@ local function check_player_permissions(player,action,warp)
|
||||
elseif action_config == 'admin' then
|
||||
return player.admin
|
||||
elseif action_config == 'expcore.roles' then
|
||||
return Roles.player_allowed(player,config['expcore_roles_'..action])
|
||||
return Roles.player_allowed(player, config['expcore_roles_'..action])
|
||||
end
|
||||
|
||||
-- Return false as all other condidtions have not been met
|
||||
@@ -79,12 +79,12 @@ Gui.element{
|
||||
style = 'tool_button'
|
||||
}
|
||||
:style(Styles.sprite20)
|
||||
:on_click(function(player,_)
|
||||
:on_click(function(player, _)
|
||||
-- Add the new warp
|
||||
local force_name = player.force.name
|
||||
local surface = player.surface
|
||||
local position = player.position
|
||||
local warp_id = Warps.add_warp(force_name,surface,position,player.name)
|
||||
local warp_id = Warps.add_warp(force_name, surface, position, player.name)
|
||||
Warps.make_warp_tag(warp_id)
|
||||
Warps.make_warp_area(warp_id)
|
||||
end)
|
||||
@@ -99,7 +99,7 @@ Gui.element{
|
||||
style = 'tool_button'
|
||||
}
|
||||
:style(Styles.sprite20)
|
||||
:on_click(function(_,element)
|
||||
:on_click(function(_, element)
|
||||
local warp_id = element.parent.name:sub(6)
|
||||
Warps.remove_warp(warp_id)
|
||||
end)
|
||||
@@ -114,15 +114,15 @@ Gui.element{
|
||||
style = 'tool_button'
|
||||
}
|
||||
:style(Styles.sprite20)
|
||||
:on_click(function(player,element)
|
||||
:on_click(function(player, element)
|
||||
local warp_id = element.parent.name:sub(6)
|
||||
Warps.set_editing(warp_id,player.name,true)
|
||||
Warps.set_editing(warp_id, player.name, true)
|
||||
end)
|
||||
|
||||
--- Set of three elements which make up each row of the warp table
|
||||
-- @element add_warp_base
|
||||
local add_warp_base =
|
||||
Gui.element(function(_,parent,warp_id)
|
||||
Gui.element(function(_, parent, warp_id)
|
||||
-- Add the icon flow
|
||||
local icon_flow =
|
||||
parent.add{
|
||||
@@ -137,7 +137,7 @@ Gui.element(function(_,parent,warp_id)
|
||||
warp_flow.style.padding = 0
|
||||
|
||||
-- Add the two edit buttons outside the warp flow
|
||||
local edit_flow = Gui.alignment(parent,'edit-'..warp_id)
|
||||
local edit_flow = Gui.alignment(parent, 'edit-'..warp_id)
|
||||
edit_warp(edit_flow)
|
||||
discard_warp(edit_flow)
|
||||
|
||||
@@ -146,7 +146,7 @@ Gui.element(function(_,parent,warp_id)
|
||||
end)
|
||||
|
||||
-- Removes the three elements that are added as part of the warp base
|
||||
local function remove_warp_base(parent,warp_id)
|
||||
local function remove_warp_base(parent, warp_id)
|
||||
Gui.destroy_if_valid(parent['icon-'..warp_id])
|
||||
Gui.destroy_if_valid(parent['edit-'..warp_id])
|
||||
Gui.destroy_if_valid(parent[warp_id])
|
||||
@@ -164,12 +164,12 @@ Gui.element{
|
||||
style = 'shortcut_bar_button_green'
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(player,element)
|
||||
:on_click(function(player, element)
|
||||
local warp_id = element.parent.name
|
||||
local warp_name = element.parent[warp_editing.name].text
|
||||
local warp_icon = element.parent.parent['icon-'..warp_id][warp_icon_button.name].elem_value
|
||||
Warps.set_editing(warp_id,player.name)
|
||||
Warps.update_warp(warp_id,warp_name,warp_icon,player.name)
|
||||
Warps.set_editing(warp_id, player.name)
|
||||
Warps.update_warp(warp_id, warp_name, warp_icon, player.name)
|
||||
end)
|
||||
|
||||
--- Cancels the editing changes of the selected warp name or icon
|
||||
@@ -182,15 +182,15 @@ Gui.element{
|
||||
style = 'shortcut_bar_button_red'
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(player,element)
|
||||
:on_click(function(player, element)
|
||||
local warp_id = element.parent.name
|
||||
Warps.set_editing(warp_id,player.name)
|
||||
Warps.set_editing(warp_id, player.name)
|
||||
end)
|
||||
|
||||
--- Editing state for a warp, contrins a text field and the two edit buttons
|
||||
-- @element warp_editing
|
||||
warp_editing =
|
||||
Gui.element(function(event_trigger,parent,warp)
|
||||
Gui.element(function(event_trigger, parent, warp)
|
||||
local name = warp.name
|
||||
|
||||
-- Draw the element
|
||||
@@ -213,18 +213,18 @@ end)
|
||||
maximal_width = 110,
|
||||
height = 20
|
||||
}
|
||||
:on_confirmed(function(player,element,_)
|
||||
:on_confirmed(function(player, element, _)
|
||||
local warp_id = element.parent.name
|
||||
local warp_name = element.text
|
||||
local warp_icon = element.parent.parent['icon-'..warp_id][warp_icon_button.name].elem_value
|
||||
Warps.set_editing(warp_id,player.name)
|
||||
Warps.update_warp(warp_id,warp_name,warp_icon,player.name)
|
||||
Warps.set_editing(warp_id, player.name)
|
||||
Warps.update_warp(warp_id, warp_name, warp_icon, player.name)
|
||||
end)
|
||||
|
||||
--- Default state for a warp, contains only a label with the warp name
|
||||
-- @element warp_label
|
||||
local warp_label =
|
||||
Gui.element(function(event_trigger,parent,warp)
|
||||
Gui.element(function(event_trigger, parent, warp)
|
||||
local last_edit_name = warp.last_edit_name
|
||||
local last_edit_time = warp.last_edit_time
|
||||
-- Draw the element
|
||||
@@ -232,52 +232,52 @@ Gui.element(function(event_trigger,parent,warp)
|
||||
name = event_trigger,
|
||||
type = 'label',
|
||||
caption = warp.name,
|
||||
tooltip = {'warp-list.last-edit',last_edit_name,format_time(last_edit_time)}
|
||||
tooltip = {'warp-list.last-edit', last_edit_name, format_time(last_edit_time)}
|
||||
}
|
||||
end)
|
||||
:style{
|
||||
single_line = false,
|
||||
maximal_width = 150
|
||||
}
|
||||
:on_click(function(player,element,_)
|
||||
:on_click(function(player, element, _)
|
||||
local warp_id = element.parent.name
|
||||
local warp = Warps.get_warp(warp_id)
|
||||
local position = warp.position
|
||||
player.zoom_to_world(position,1.5)
|
||||
player.zoom_to_world(position, 1.5)
|
||||
end)
|
||||
|
||||
|
||||
--- Default state for the warp icon, when pressed teleports the player
|
||||
-- @element warp_icon_button
|
||||
warp_icon_button =
|
||||
Gui.element(function(event_trigger,parent,warp)
|
||||
Gui.element(function(event_trigger, parent, warp)
|
||||
local warp_position = warp.position
|
||||
-- Draw the element
|
||||
return parent.add{
|
||||
name = event_trigger,
|
||||
type = 'sprite-button',
|
||||
sprite = 'item/'..warp.icon,
|
||||
tooltip = {'warp-list.goto-tooltip',warp_position.x,warp_position.y},
|
||||
tooltip = {'warp-list.goto-tooltip', warp_position.x, warp_position.y},
|
||||
style = 'quick_bar_slot_button'
|
||||
}
|
||||
end)
|
||||
:style(Styles.sprite32)
|
||||
:on_click(function(player,element,_)
|
||||
:on_click(function(player, element, _)
|
||||
if element.type == 'choose-elem-button' then return end
|
||||
local warp_id = element.parent.caption
|
||||
Warps.teleport_player(warp_id,player)
|
||||
Warps.teleport_player(warp_id, player)
|
||||
|
||||
-- Reset the warp cooldown if the player does not have unlimited warps
|
||||
if not check_player_permissions(player,'bypass_warp_cooldown') then
|
||||
Store.set(player_warp_cooldown_store,player,config.cooldown_duraction)
|
||||
Store.trigger(player_in_range_store,player)
|
||||
if not check_player_permissions(player, 'bypass_warp_cooldown') then
|
||||
Store.set(player_warp_cooldown_store, player, config.cooldown_duraction)
|
||||
Store.trigger(player_in_range_store, player)
|
||||
end
|
||||
end)
|
||||
|
||||
--- Editing state for the warp icon, chose elem used to chosse icon
|
||||
-- @element warp_icon_editing
|
||||
local warp_icon_editing =
|
||||
Gui.element(function(_,parent,warp)
|
||||
Gui.element(function(_, parent, warp)
|
||||
return parent.add{
|
||||
name = warp_icon_button.name,
|
||||
type = 'choose-elem-button',
|
||||
@@ -293,7 +293,7 @@ end)
|
||||
local warp_timer =
|
||||
Gui.element{
|
||||
type = 'progressbar',
|
||||
tooltip = {'warp-list.timer-tooltip',config.cooldown_duraction},
|
||||
tooltip = {'warp-list.timer-tooltip', config.cooldown_duraction},
|
||||
minimum_value = 0,
|
||||
maximum_value = config.cooldown_duraction*config.update_smoothing
|
||||
}
|
||||
@@ -303,22 +303,22 @@ Gui.element{
|
||||
}
|
||||
|
||||
--- Updates a warp for a player
|
||||
local function update_warp(player,warp_table,warp_id)
|
||||
local function update_warp(player, warp_table, warp_id)
|
||||
local warp = Warps.get_warp(warp_id)
|
||||
|
||||
-- Warp no longer exists so should be removed from the list
|
||||
if not warp then
|
||||
remove_warp_base(warp_table,warp_id)
|
||||
remove_warp_base(warp_table, warp_id)
|
||||
return
|
||||
end
|
||||
|
||||
-- Get the warp flow for this warp
|
||||
local warp_flow = warp_table[warp_id] or add_warp_base(warp_table,warp_id)
|
||||
local warp_flow = warp_table[warp_id] or add_warp_base(warp_table, warp_id)
|
||||
local icon_flow = warp_table['icon-'..warp_id]
|
||||
|
||||
-- Update the edit flow
|
||||
local edit_flow = warp_table['edit-'..warp_id]
|
||||
local player_allowed_edit = check_player_permissions(player,'allow_edit_warp',warp)
|
||||
local player_allowed_edit = check_player_permissions(player, 'allow_edit_warp', warp)
|
||||
local players_editing = table.get_keys(warp.currently_editing)
|
||||
local edit_warp_element = edit_flow[edit_warp.name]
|
||||
local discard_warp_element = edit_flow[discard_warp.name]
|
||||
@@ -327,15 +327,15 @@ local function update_warp(player,warp_table,warp_id)
|
||||
discard_warp_element.visible = player_allowed_edit
|
||||
if #players_editing > 0 then
|
||||
edit_warp_element.hovered_sprite = 'utility/warning_icon'
|
||||
edit_warp_element.tooltip = {'warp-list.edit-tooltip',table.concat(players_editing,', ')}
|
||||
edit_warp_element.tooltip = {'warp-list.edit-tooltip', table.concat(players_editing, ', ')}
|
||||
else
|
||||
edit_warp_element.hovered_sprite = edit_warp_element.sprite
|
||||
edit_warp_element.tooltip = {'warp-list.edit-tooltip-none'}
|
||||
end
|
||||
|
||||
-- Check if the player is was editing and/or currently editing
|
||||
local warp_label_element = warp_flow[warp_label.name] or warp_label(warp_flow,warp)
|
||||
local icon_entry = icon_flow[warp_icon_button.name] or warp_icon_button(icon_flow,warp)
|
||||
local warp_label_element = warp_flow[warp_label.name] or warp_label(warp_flow, warp)
|
||||
local icon_entry = icon_flow[warp_icon_button.name] or warp_icon_button(icon_flow, warp)
|
||||
local player_was_editing = icon_entry.type == 'choose-elem-button'
|
||||
local player_is_editing = warp.currently_editing[player.name]
|
||||
|
||||
@@ -347,20 +347,20 @@ local function update_warp(player,warp_table,warp_id)
|
||||
local last_edit_name = warp.last_edit_name
|
||||
local last_edit_time = warp.last_edit_time
|
||||
warp_label_element.caption = warp_name
|
||||
warp_label_element.tooltip = {'warp-list.last-edit',last_edit_name,format_time(last_edit_time)}
|
||||
warp_label_element.tooltip = {'warp-list.last-edit', last_edit_name, format_time(last_edit_time)}
|
||||
icon_entry.sprite = 'item/'..warp_icon
|
||||
|
||||
elseif player_was_editing and not player_is_editing then
|
||||
-- Player was editing but is no longer, remove text field and add label
|
||||
edit_warp_element.enabled = true
|
||||
warp_flow.clear()
|
||||
warp_label(warp_flow,warp)
|
||||
warp_label(warp_flow, warp)
|
||||
|
||||
icon_flow.clear()
|
||||
local warp_icon_element = warp_icon_button(icon_flow,warp)
|
||||
local timer = Store.get(player_warp_cooldown_store,player)
|
||||
local in_range = Store.get(player_in_range_store,player)
|
||||
local apply_proximity = not check_player_permissions(player,'bypass_warp_proximity')
|
||||
local warp_icon_element = warp_icon_button(icon_flow, warp)
|
||||
local timer = Store.get(player_warp_cooldown_store, player)
|
||||
local in_range = Store.get(player_in_range_store, player)
|
||||
local apply_proximity = not check_player_permissions(player, 'bypass_warp_proximity')
|
||||
if (timer and timer > 0) or (apply_proximity and not in_range) then
|
||||
warp_icon_element.enabled = false
|
||||
warp_icon_element.tooltip = {'warp-list.goto-disabled'}
|
||||
@@ -370,20 +370,20 @@ local function update_warp(player,warp_table,warp_id)
|
||||
-- Player was not editing but now is, remove label and add text field
|
||||
edit_warp_element.enabled = false
|
||||
warp_flow.clear()
|
||||
warp_editing(warp_flow,warp).focus()
|
||||
warp_table.parent.scroll_to_element(warp_flow,'top-third')
|
||||
warp_editing(warp_flow, warp).focus()
|
||||
warp_table.parent.scroll_to_element(warp_flow, 'top-third')
|
||||
icon_flow.clear()
|
||||
warp_icon_editing(icon_flow,warp)
|
||||
warp_icon_editing(icon_flow, warp)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- Update all the warps for a player
|
||||
local function update_all_warps(player,warp_table)
|
||||
local function update_all_warps(player, warp_table)
|
||||
local warp_ids = Warps.get_force_warp_ids(player.force.name)
|
||||
if #warp_ids > 0 then
|
||||
for _,warp_id in ipairs(warp_ids) do
|
||||
update_warp(player,warp_table,warp_id)
|
||||
for _, warp_id in ipairs(warp_ids) do
|
||||
update_warp(player, warp_table, warp_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -391,9 +391,9 @@ end
|
||||
--- Main warp list container for the left flow
|
||||
-- @element warp_list_container
|
||||
local warp_list_container =
|
||||
Gui.element(function(event_trigger,parent)
|
||||
Gui.element(function(event_trigger, parent)
|
||||
-- Draw the internal container
|
||||
local container = Gui.container(parent,event_trigger,200)
|
||||
local container = Gui.container(parent, event_trigger, 200)
|
||||
|
||||
-- Draw the header
|
||||
local header = Gui.header(
|
||||
@@ -406,10 +406,10 @@ Gui.element(function(event_trigger,parent)
|
||||
-- Draw the new warp button
|
||||
local player = Gui.get_player_from_element(parent)
|
||||
local add_new_warp_element = add_new_warp(header)
|
||||
add_new_warp_element.visible = check_player_permissions(player,'allow_add_warp')
|
||||
add_new_warp_element.visible = check_player_permissions(player, 'allow_add_warp')
|
||||
|
||||
-- Draw the scroll table for the warps
|
||||
local scroll_table = Gui.scroll_table(container,250,3)
|
||||
local scroll_table = Gui.scroll_table(container, 250, 3)
|
||||
|
||||
-- Change the style of the scroll table
|
||||
local scroll_table_style = scroll_table.style
|
||||
@@ -421,14 +421,14 @@ Gui.element(function(event_trigger,parent)
|
||||
|
||||
-- Change the progress of the warp timer
|
||||
local progress = 1
|
||||
local timer = Store.get(player_warp_cooldown_store,player)
|
||||
local timer = Store.get(player_warp_cooldown_store, player)
|
||||
if timer and timer > 0 then
|
||||
progress = 1 - (timer/config.cooldown_duraction)
|
||||
end
|
||||
warp_timer_element.value = progress
|
||||
|
||||
-- Add any existing warps
|
||||
update_all_warps(player,scroll_table)
|
||||
update_all_warps(player, scroll_table)
|
||||
|
||||
-- Return the exteral container
|
||||
return container.parent
|
||||
@@ -437,16 +437,16 @@ end)
|
||||
|
||||
--- Button on the top flow used to toggle the warp list container
|
||||
-- @element warp_list_toggle
|
||||
Gui.left_toolbar_button('item/'..config.default_icon,{'warp-list.main-tooltip',config.standard_proximity_radius},warp_list_container, function(player)
|
||||
return Roles.player_allowed(player,'gui/warp-list')
|
||||
Gui.left_toolbar_button('item/'..config.default_icon, {'warp-list.main-tooltip', config.standard_proximity_radius}, warp_list_container, function(player)
|
||||
return Roles.player_allowed(player, 'gui/warp-list')
|
||||
end)
|
||||
:on_custom_event(Gui.events.on_visibility_changed_by_click, function(player,_,event)
|
||||
:on_custom_event(Gui.events.on_visibility_changed_by_click, function(player, _,event)
|
||||
-- Set gui keep open state for player that clicked the button: true if visible, false if invisible
|
||||
keep_gui_open[player.name] = event.state
|
||||
end)
|
||||
|
||||
--- When the name of a warp is updated this is triggered
|
||||
Warps.on_update(function(warp,_,removed_warp)
|
||||
Warps.on_update(function(warp, _,removed_warp)
|
||||
-- Get the force to update, warp is nil when removed
|
||||
local force
|
||||
if warp then
|
||||
@@ -457,69 +457,69 @@ Warps.on_update(function(warp,_,removed_warp)
|
||||
|
||||
-- Update the gui for selected players
|
||||
local warp_ids = Warps.get_force_warp_ids(force.name)
|
||||
for _,player in pairs(force.connected_players) do
|
||||
local frame = Gui.get_left_element(player,warp_list_container)
|
||||
for _, player in pairs(force.connected_players) do
|
||||
local frame = Gui.get_left_element(player, warp_list_container)
|
||||
local scroll_table = frame.container.scroll.table
|
||||
|
||||
-- Update the gui
|
||||
scroll_table.clear()
|
||||
for _,next_warp_id in ipairs(warp_ids) do
|
||||
update_warp(player,scroll_table,next_warp_id)
|
||||
for _, next_warp_id in ipairs(warp_ids) do
|
||||
update_warp(player, scroll_table, next_warp_id)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Update the warps when the player joins
|
||||
Event.add(defines.events.on_player_joined_game,function(event)
|
||||
Event.add(defines.events.on_player_joined_game, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local frame = Gui.get_left_element(player,warp_list_container)
|
||||
local frame = Gui.get_left_element(player, warp_list_container)
|
||||
local scroll_table = frame.container.scroll.table
|
||||
update_all_warps(player,scroll_table)
|
||||
update_all_warps(player, scroll_table)
|
||||
end)
|
||||
|
||||
--- Makes sure the right buttons are present when roles change
|
||||
local function role_update_event(event)
|
||||
local player = game.players[event.player_index]
|
||||
local container = Gui.get_left_element(player,warp_list_container).container
|
||||
local container = Gui.get_left_element(player, warp_list_container).container
|
||||
|
||||
-- Update the warps, incase the user can now edit them
|
||||
local scroll_table = container.scroll.table
|
||||
update_all_warps(player,scroll_table)
|
||||
update_all_warps(player, scroll_table)
|
||||
|
||||
-- Update the new warp button incase the user can now add them
|
||||
local add_new_warp_element = container.header.alignment[add_new_warp.name]
|
||||
add_new_warp_element.visible = check_player_permissions(player,'allow_add_warp')
|
||||
add_new_warp_element.visible = check_player_permissions(player, 'allow_add_warp')
|
||||
end
|
||||
|
||||
Event.add(Roles.events.on_role_assigned,role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned,role_update_event)
|
||||
Event.add(Roles.events.on_role_assigned, role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned, role_update_event)
|
||||
|
||||
--- When the player leaves or enters range of a warp this is triggered
|
||||
Store.watch(player_in_range_store,function(value,player_name)
|
||||
Store.watch(player_in_range_store, function(value, player_name)
|
||||
local player = game.players[player_name]
|
||||
local force = player.force
|
||||
|
||||
-- Change if the frame is visible based on if the player is in range
|
||||
if not keep_gui_open[player.name] then
|
||||
Gui.toggle_left_element(player,warp_list_container,value)
|
||||
Gui.toggle_left_element(player, warp_list_container, value)
|
||||
end
|
||||
|
||||
-- Check if the player requires proximity
|
||||
if check_player_permissions(player,'bypass_warp_proximity') then
|
||||
if check_player_permissions(player, 'bypass_warp_proximity') then
|
||||
return
|
||||
end
|
||||
|
||||
-- Get the warp table
|
||||
local frame = Gui.get_left_element(player,warp_list_container)
|
||||
local frame = Gui.get_left_element(player, warp_list_container)
|
||||
local scroll_table = frame.container.scroll.table
|
||||
|
||||
-- Check if the buttons should be active
|
||||
local timer = Store.get(player_warp_cooldown_store,player)
|
||||
local timer = Store.get(player_warp_cooldown_store, player)
|
||||
local button_disabled = timer and timer > 0 or not value
|
||||
|
||||
-- Change the enabled state of the warp buttons
|
||||
local warp_ids = Warps.get_force_warp_ids(force.name)
|
||||
for _,warp_id in pairs(warp_ids) do
|
||||
for _, warp_id in pairs(warp_ids) do
|
||||
local element = scroll_table['icon-'..warp_id][warp_icon_button.name]
|
||||
if element and element.valid then
|
||||
element.enabled = not button_disabled
|
||||
@@ -527,23 +527,23 @@ Store.watch(player_in_range_store,function(value,player_name)
|
||||
element.tooltip = {'warp-list.goto-disabled'}
|
||||
else
|
||||
local position = Warps.get_warp(warp_id).position
|
||||
element.tooltip = {'warp-list.goto-tooltip',position.x,position.y}
|
||||
element.tooltip = {'warp-list.goto-tooltip', position.x, position.y}
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Update the warp cooldown progress bars to match the store
|
||||
Store.watch(player_warp_cooldown_store,function(value,player_name,old_value)
|
||||
Store.watch(player_warp_cooldown_store, function(value, player_name, old_value)
|
||||
if value == old_value then return end
|
||||
-- Get the progress bar element
|
||||
local player = game.players[player_name]
|
||||
local frame = Gui.get_left_element(player,warp_list_container)
|
||||
local frame = Gui.get_left_element(player, warp_list_container)
|
||||
local warp_timer_element = frame.container[warp_timer.name]
|
||||
|
||||
-- Set the progress
|
||||
local progress = 1
|
||||
local timer = Store.get(player_warp_cooldown_store,player)
|
||||
local timer = Store.get(player_warp_cooldown_store, player)
|
||||
if timer and timer > 0 then
|
||||
progress = 1 - (timer/config.cooldown_duraction)
|
||||
end
|
||||
@@ -551,7 +551,7 @@ Store.watch(player_warp_cooldown_store,function(value,player_name,old_value)
|
||||
|
||||
-- Trigger update of buttons if cooldown is now 0
|
||||
if value == 0 then
|
||||
Store.trigger(player_in_range_store,player_name)
|
||||
Store.trigger(player_in_range_store, player_name)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -559,8 +559,8 @@ end)
|
||||
local r2 = config.standard_proximity_radius^2
|
||||
local rs2 = config.spawn_proximity_radius^2
|
||||
local mr2 = config.minimum_distance^2
|
||||
Event.on_nth_tick(math.floor(60/config.update_smoothing),function()
|
||||
Store.map(player_warp_cooldown_store,function(value)
|
||||
Event.on_nth_tick(math.floor(60/config.update_smoothing), function()
|
||||
Store.map(player_warp_cooldown_store, function(value)
|
||||
if value > 0 then
|
||||
return value - 1
|
||||
end
|
||||
@@ -568,8 +568,8 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function()
|
||||
|
||||
local force_warps = {}
|
||||
local warps = {}
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local was_in_range = Store.get(player_in_range_store,player)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local was_in_range = Store.get(player_in_range_store, player)
|
||||
|
||||
-- Get the ids of all the warps on the players force
|
||||
local force_name = player.force.name
|
||||
@@ -585,10 +585,10 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function()
|
||||
if #warp_ids > 0 then
|
||||
local surface = player.surface
|
||||
local pos = player.position
|
||||
local px,py = pos.x,pos.y
|
||||
local px, py = pos.x, pos.y
|
||||
|
||||
-- Loop over each warp
|
||||
for _,warp_id in ipairs(warp_ids) do
|
||||
for _, warp_id in ipairs(warp_ids) do
|
||||
-- Check if warp id is chached
|
||||
local warp = warps[warp_id]
|
||||
if not warp then
|
||||
@@ -612,13 +612,13 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function()
|
||||
-- Check the dist to the closest warp
|
||||
local in_range = closest_warp.warp_id == warp_ids.spawn and closest_distance < rs2 or closest_distance < r2
|
||||
if was_in_range and not in_range then
|
||||
Store.set(player_in_range_store,player,false)
|
||||
Store.set(player_in_range_store, player, false)
|
||||
elseif not was_in_range and in_range then
|
||||
Store.set(player_in_range_store,player,true)
|
||||
Store.set(player_in_range_store, player, true)
|
||||
end
|
||||
|
||||
-- Change the enabled state of the add warp button
|
||||
local frame = Gui.get_left_element(player,warp_list_container)
|
||||
local frame = Gui.get_left_element(player, warp_list_container)
|
||||
local add_warp_element = frame.container.header.alignment[add_new_warp.name]
|
||||
local was_able_to_make_warp = add_warp_element.enabled
|
||||
local can_make_warp = closest_distance > mr2
|
||||
@@ -627,7 +627,7 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function()
|
||||
add_warp_element.tooltip = {'warp-list.add-tooltip'}
|
||||
elseif not can_make_warp and was_able_to_make_warp then
|
||||
add_warp_element.enabled = false
|
||||
add_warp_element.tooltip = {'warp-list.too-close',closest_warp.name}
|
||||
add_warp_element.tooltip = {'warp-list.too-close', closest_warp.name}
|
||||
end
|
||||
|
||||
end
|
||||
@@ -637,16 +637,16 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function()
|
||||
end)
|
||||
|
||||
--- When a player is created make sure that there is a spawn warp created
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
-- If the force has no spawn then make a spawn warp
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local force = player.force
|
||||
local spawn_id = Warps.get_spawn_warp_id(force.name)
|
||||
if not spawn_id then
|
||||
local spawn_position = force.get_spawn_position(player.surface)
|
||||
spawn_id = Warps.add_warp(force.name,player.surface,spawn_position,nil,'Spawn')
|
||||
Warps.set_spawn_warp(spawn_id,force)
|
||||
Store.trigger(Warps.store,spawn_id)
|
||||
spawn_id = Warps.add_warp(force.name, player.surface, spawn_position, nil, 'Spawn')
|
||||
Warps.set_spawn_warp(spawn_id, force)
|
||||
Store.trigger(Warps.store, spawn_id)
|
||||
Warps.make_warp_tag(spawn_id)
|
||||
end
|
||||
end)
|
||||
@@ -657,7 +657,7 @@ local function maintain_tag(event)
|
||||
local tag = event.tag
|
||||
local force_name = event.force.name
|
||||
local warp_ids = Warps.get_force_warp_ids(force_name)
|
||||
for _,warp_id in pairs(warp_ids) do
|
||||
for _, warp_id in pairs(warp_ids) do
|
||||
local warp = Warps.get_warp(warp_id)
|
||||
local wtag = warp.tag
|
||||
if not wtag or not wtag.valid or wtag == tag then
|
||||
@@ -669,5 +669,5 @@ local function maintain_tag(event)
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_chart_tag_modified,maintain_tag)
|
||||
Event.add(defines.events.on_chart_tag_removed,maintain_tag)
|
||||
Event.add(defines.events.on_chart_tag_modified, maintain_tag)
|
||||
Event.add(defines.events.on_chart_tag_removed, maintain_tag)
|
||||
Reference in New Issue
Block a user