Migrate new Guis

This commit is contained in:
Cooldude2606
2023-12-30 17:34:13 +00:00
parent f7eb9c0c37
commit 3f0df9b9b0
3 changed files with 39 additions and 31 deletions

View File

@@ -16,13 +16,11 @@ local label_width = {
['total'] = 480 ['total'] = 480
} }
local function format_clock(value) local function format_time_short(value)
return format_time(value*3600, { return format_time(value*3600, {
hours=true, hours=true,
minutes=true, minutes=true,
seconds=false, seconds=false
time=false,
string=true
}) })
end end
@@ -33,49 +31,49 @@ end
local playerStats = PlayerData.Statistics local playerStats = PlayerData.Statistics
local computed_stats = { local computed_stats = {
DamageDeathRatio = { DamageDeathRatio = {
default = '0.00', default = format_number_n(0),
calculate = function(player_name) calculate = function(player_name)
return format_number_n(playerStats['DamageDealt']:get(player_name, 0) / playerStats['Deaths']:get(player_name, 1)) return format_number_n(playerStats['DamageDealt']:get(player_name, 0) / playerStats['Deaths']:get(player_name, 1))
end end
}, },
KillDeathRatio = { KillDeathRatio = {
default = '0.00', default = format_number_n(0),
calculate = function(player_name) calculate = function(player_name)
return format_number_n(playerStats['Kills']:get(player_name, 0) / playerStats['Deaths']:get(player_name, 1)) return format_number_n(playerStats['Kills']:get(player_name, 0) / playerStats['Deaths']:get(player_name, 1))
end end
}, },
SessionTime = { SessionTime = {
default = format_clock(0), default = format_time_short(0),
calculate = function(player_name) calculate = function(player_name)
return format_clock((playerStats['Playtime']:get(player_name, 0) - playerStats['AfkTime']:get(player_name, 0)) / playerStats['JoinCount']:get(player_name, 1)) return format_time_short((playerStats['Playtime']:get(player_name, 0) - playerStats['AfkTime']:get(player_name, 0)) / playerStats['JoinCount']:get(player_name, 1))
end end
}, },
BuildRatio = { BuildRatio = {
default = '0.00', default = format_number_n(0),
calculate = function(player_name) calculate = function(player_name)
return format_number_n(playerStats['MachinesBuilt']:get(player_name, 0) / playerStats['MachinesRemoved']:get(player_name, 1)) return format_number_n(playerStats['MachinesBuilt']:get(player_name, 0) / playerStats['MachinesRemoved']:get(player_name, 1))
end end
}, },
RocketPerHour = { RocketPerHour = {
default = '0.00', default = format_number_n(0),
calculate = function(player_name) calculate = function(player_name)
return format_number_n(playerStats['RocketsLaunched']:get(player_name, 0) * 60 / playerStats['Playtime']:get(player_name, 1)) return format_number_n(playerStats['RocketsLaunched']:get(player_name, 0) * 60 / playerStats['Playtime']:get(player_name, 1))
end end
}, },
TreeKillPerMinute = { TreeKillPerMinute = {
default = '0.00', default = format_number_n(0),
calculate = function(player_name) calculate = function(player_name)
return format_number_n(playerStats['TreesDestroyed']:get(player_name, 0) / playerStats['Playtime']:get(player_name, 1)) return format_number_n(playerStats['TreesDestroyed']:get(player_name, 0) / playerStats['Playtime']:get(player_name, 1))
end end
}, },
NetPlayTime = { NetPlayTime = {
default = format_clock(0), default = format_time_short(0),
calculate = function(player_name) calculate = function(player_name)
return format_clock((playerStats['Playtime']:get(player_name, 0) - playerStats['AfkTime']:get(player_name, 0))) return format_time_short((playerStats['Playtime']:get(player_name, 0) - playerStats['AfkTime']:get(player_name, 0)))
end end
}, },
AFKTimeRatio = { AFKTimeRatio = {
default = '0.00', default = format_number_n(0),
calculate = function(player_name) calculate = function(player_name)
return format_number_n(playerStats['AfkTime']:get(player_name, 0) * 100 / playerStats['Playtime']:get(player_name, 1)) return format_number_n(playerStats['AfkTime']:get(player_name, 0) * 100 / playerStats['Playtime']:get(player_name, 1))
end end
@@ -137,9 +135,9 @@ local function pd_update(table, player_name)
end end
local pd_username_player = local pd_username_player =
Gui.element(function(name, parent, player_list) Gui.element(function(definition, parent, player_list)
return parent.add{ return parent.add{
name = name, name = definition.name,
type = 'drop-down', type = 'drop-down',
items = player_list, items = player_list,
selected_index = #player_list > 0 and 1 selected_index = #player_list > 0 and 1
@@ -152,10 +150,12 @@ end)
local table = element.parent.parent.parent.parent['pd_st_2'].disp.table local table = element.parent.parent.parent.parent['pd_st_2'].disp.table
pd_update(table, player_name) pd_update(table, player_name)
end) end)
:static_name(Gui.unique_static_name)
local pd_username_update = local pd_username_update =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = 'update' caption = 'update'
}:style{ }:style{
width = 128 width = 128
@@ -181,8 +181,8 @@ Gui.element(function(_, parent, name, player_list)
end) end)
pd_container = pd_container =
Gui.element(function(event_trigger, parent) Gui.element(function(definition, parent)
local container = Gui.container(parent, event_trigger, label_width['total']) local container = Gui.container(parent, definition.name, label_width['total'])
local player_list = {} local player_list = {}
for _, player in pairs(game.connected_players) do for _, player in pairs(game.connected_players) do
@@ -194,6 +194,7 @@ Gui.element(function(event_trigger, parent)
return container.parent return container.parent
end) end)
:static_name(Gui.unique_static_name)
:add_to_left_flow() :add_to_left_flow()
Gui.left_toolbar_button('item/power-armor-mk2', 'Player Data GUI', pd_container, function(player) Gui.left_toolbar_button('item/power-armor-mk2', 'Player Data GUI', pd_container, function(player)

View File

@@ -5,12 +5,10 @@ local Gui = require 'expcore.gui' --- @dep expcore.gui
local Roles = require 'expcore.roles' --- @dep expcore.roles local Roles = require 'expcore.roles' --- @dep expcore.roles
local Event = require 'utils.event' --- @dep utils.event local Event = require 'utils.event' --- @dep utils.event
local cctv_container
local cctv_player = local cctv_player =
Gui.element(function(name, parent, player_list) Gui.element(function(definition, parent, player_list)
return parent.add{ return parent.add{
name = name, name = definition.name,
type = 'drop-down', type = 'drop-down',
items = player_list, items = player_list,
selected_index = #player_list > 0 and 1 selected_index = #player_list > 0 and 1
@@ -19,11 +17,11 @@ end)
:style{ :style{
horizontally_stretchable = true horizontally_stretchable = true
} }
:static_name(Gui.unique_static_name)
local cctv_type = local cctv_status =
Gui.element{ Gui.element{
type = 'drop-down', type = 'drop-down',
name = 'cctv_status',
items = {'Enable', 'Disable'}, items = {'Enable', 'Disable'},
selected_index = 2 selected_index = 2
}:style{ }:style{
@@ -36,10 +34,10 @@ Gui.element{
end end
end) end)
local cctv_status = local cctv_type =
Gui.element{ Gui.element{
type = 'drop-down', type = 'drop-down',
name = 'cctv_status', name = Gui.unique_static_name,
items = {'Player', 'Static'}, items = {'Player', 'Static'},
selected_index = 1 selected_index = 1
}:style{ }:style{
@@ -49,6 +47,7 @@ Gui.element{
local cctv_location = local cctv_location =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = 'set' caption = 'set'
}:style{ }:style{
width = 48 width = 48
@@ -59,6 +58,7 @@ end)
local zoom_in = local zoom_in =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = '+' caption = '+'
}:style{ }:style{
width = 32 width = 32
@@ -72,6 +72,7 @@ end)
local zoom_out = local zoom_out =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = '-' caption = '-'
}:style{ }:style{
width = 32 width = 32
@@ -88,8 +89,8 @@ Gui.element(function(_, parent, name, player_list)
local buttons = Gui.scroll_table(camera_set, 480, 6, 'buttons') local buttons = Gui.scroll_table(camera_set, 480, 6, 'buttons')
cctv_player(buttons, player_list) cctv_player(buttons, player_list)
cctv_type(buttons)
cctv_status(buttons) cctv_status(buttons)
cctv_type(buttons)
cctv_location(buttons) cctv_location(buttons)
zoom_out(buttons) zoom_out(buttons)
zoom_in(buttons) zoom_in(buttons)
@@ -108,9 +109,9 @@ Gui.element(function(_, parent, name, player_list)
return camera_set return camera_set
end) end)
cctv_container = local cctv_container =
Gui.element(function(event_trigger, parent) Gui.element(function(definition, parent)
local container = Gui.container(parent, event_trigger, 480) local container = Gui.container(parent, definition.name, 480)
local scroll = container.add{name='scroll', type='scroll-pane', direction='vertical'} local scroll = container.add{name='scroll', type='scroll-pane', direction='vertical'}
scroll.style.maximal_height = 704 scroll.style.maximal_height = 704
local player_list = {} local player_list = {}
@@ -124,6 +125,7 @@ Gui.element(function(event_trigger, parent)
return container.parent return container.parent
end) end)
:static_name(Gui.unique_static_name)
:add_to_left_flow() :add_to_left_flow()
Gui.left_toolbar_button('entity/radar', 'Surveillance GUI', cctv_container, function(player) Gui.left_toolbar_button('entity/radar', 'Surveillance GUI', cctv_container, function(player)
@@ -154,7 +156,7 @@ Event.add(defines.events.on_tick, function(_)
for i=1, 2 do for i=1, 2 do
local scroll_table_name = 'cctv_st_' .. i local scroll_table_name = 'cctv_st_' .. i
local current_camera_set = frame.container.scroll[scroll_table_name] local current_camera_set = frame.container.scroll[scroll_table_name]
local switch_index = current_camera_set.buttons.table[cctv_status.name].selected_index local switch_index = current_camera_set.buttons.table[cctv_type.name].selected_index
if switch_index == 1 then if switch_index == 1 then
local selected_index = current_camera_set.buttons.table[cctv_player.name].selected_index local selected_index = current_camera_set.buttons.table[cctv_player.name].selected_index

View File

@@ -229,6 +229,7 @@ end
local vlayer_gui_control_storage_input = local vlayer_gui_control_storage_input =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = 'Add Input Storage' caption = 'Add Input Storage'
}:style{ }:style{
width = 160 width = 160
@@ -248,6 +249,7 @@ end)
local vlayer_gui_control_storage_output = local vlayer_gui_control_storage_output =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = 'Add Output Storage' caption = 'Add Output Storage'
}:style{ }:style{
width = 160 width = 160
@@ -267,6 +269,7 @@ end)
local vlayer_gui_control_circuit = local vlayer_gui_control_circuit =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = 'Add Circuit' caption = 'Add Circuit'
}:style{ }:style{
width = 160 width = 160
@@ -286,6 +289,7 @@ end)
local vlayer_gui_control_power = local vlayer_gui_control_power =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = 'Add Power' caption = 'Add Power'
}:style{ }:style{
width = 160 width = 160
@@ -308,6 +312,7 @@ end)
local vlayer_gui_control_remove = local vlayer_gui_control_remove =
Gui.element{ Gui.element{
type = 'button', type = 'button',
name = Gui.unique_static_name,
caption = 'Remove Special' caption = 'Remove Special'
}:style{ }:style{
width = 160 width = 160