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
}
local function format_clock(value)
local function format_time_short(value)
return format_time(value*3600, {
hours=true,
minutes=true,
seconds=false,
time=false,
string=true
seconds=false
})
end
@@ -33,49 +31,49 @@ end
local playerStats = PlayerData.Statistics
local computed_stats = {
DamageDeathRatio = {
default = '0.00',
default = format_number_n(0),
calculate = function(player_name)
return format_number_n(playerStats['DamageDealt']:get(player_name, 0) / playerStats['Deaths']:get(player_name, 1))
end
},
KillDeathRatio = {
default = '0.00',
default = format_number_n(0),
calculate = function(player_name)
return format_number_n(playerStats['Kills']:get(player_name, 0) / playerStats['Deaths']:get(player_name, 1))
end
},
SessionTime = {
default = format_clock(0),
default = format_time_short(0),
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
},
BuildRatio = {
default = '0.00',
default = format_number_n(0),
calculate = function(player_name)
return format_number_n(playerStats['MachinesBuilt']:get(player_name, 0) / playerStats['MachinesRemoved']:get(player_name, 1))
end
},
RocketPerHour = {
default = '0.00',
default = format_number_n(0),
calculate = function(player_name)
return format_number_n(playerStats['RocketsLaunched']:get(player_name, 0) * 60 / playerStats['Playtime']:get(player_name, 1))
end
},
TreeKillPerMinute = {
default = '0.00',
default = format_number_n(0),
calculate = function(player_name)
return format_number_n(playerStats['TreesDestroyed']:get(player_name, 0) / playerStats['Playtime']:get(player_name, 1))
end
},
NetPlayTime = {
default = format_clock(0),
default = format_time_short(0),
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
},
AFKTimeRatio = {
default = '0.00',
default = format_number_n(0),
calculate = function(player_name)
return format_number_n(playerStats['AfkTime']:get(player_name, 0) * 100 / playerStats['Playtime']:get(player_name, 1))
end
@@ -137,9 +135,9 @@ local function pd_update(table, player_name)
end
local pd_username_player =
Gui.element(function(name, parent, player_list)
Gui.element(function(definition, parent, player_list)
return parent.add{
name = name,
name = definition.name,
type = 'drop-down',
items = player_list,
selected_index = #player_list > 0 and 1
@@ -152,10 +150,12 @@ end)
local table = element.parent.parent.parent.parent['pd_st_2'].disp.table
pd_update(table, player_name)
end)
:static_name(Gui.unique_static_name)
local pd_username_update =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = 'update'
}:style{
width = 128
@@ -181,8 +181,8 @@ Gui.element(function(_, parent, name, player_list)
end)
pd_container =
Gui.element(function(event_trigger, parent)
local container = Gui.container(parent, event_trigger, label_width['total'])
Gui.element(function(definition, parent)
local container = Gui.container(parent, definition.name, label_width['total'])
local player_list = {}
for _, player in pairs(game.connected_players) do
@@ -194,6 +194,7 @@ Gui.element(function(event_trigger, parent)
return container.parent
end)
:static_name(Gui.unique_static_name)
:add_to_left_flow()
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 Event = require 'utils.event' --- @dep utils.event
local cctv_container
local cctv_player =
Gui.element(function(name, parent, player_list)
Gui.element(function(definition, parent, player_list)
return parent.add{
name = name,
name = definition.name,
type = 'drop-down',
items = player_list,
selected_index = #player_list > 0 and 1
@@ -19,11 +17,11 @@ end)
:style{
horizontally_stretchable = true
}
:static_name(Gui.unique_static_name)
local cctv_type =
local cctv_status =
Gui.element{
type = 'drop-down',
name = 'cctv_status',
items = {'Enable', 'Disable'},
selected_index = 2
}:style{
@@ -36,10 +34,10 @@ Gui.element{
end
end)
local cctv_status =
local cctv_type =
Gui.element{
type = 'drop-down',
name = 'cctv_status',
name = Gui.unique_static_name,
items = {'Player', 'Static'},
selected_index = 1
}:style{
@@ -49,6 +47,7 @@ Gui.element{
local cctv_location =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = 'set'
}:style{
width = 48
@@ -59,6 +58,7 @@ end)
local zoom_in =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = '+'
}:style{
width = 32
@@ -72,6 +72,7 @@ end)
local zoom_out =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = '-'
}:style{
width = 32
@@ -88,8 +89,8 @@ Gui.element(function(_, parent, name, player_list)
local buttons = Gui.scroll_table(camera_set, 480, 6, 'buttons')
cctv_player(buttons, player_list)
cctv_type(buttons)
cctv_status(buttons)
cctv_type(buttons)
cctv_location(buttons)
zoom_out(buttons)
zoom_in(buttons)
@@ -108,9 +109,9 @@ Gui.element(function(_, parent, name, player_list)
return camera_set
end)
cctv_container =
Gui.element(function(event_trigger, parent)
local container = Gui.container(parent, event_trigger, 480)
local cctv_container =
Gui.element(function(definition, parent)
local container = Gui.container(parent, definition.name, 480)
local scroll = container.add{name='scroll', type='scroll-pane', direction='vertical'}
scroll.style.maximal_height = 704
local player_list = {}
@@ -124,6 +125,7 @@ Gui.element(function(event_trigger, parent)
return container.parent
end)
:static_name(Gui.unique_static_name)
:add_to_left_flow()
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
local scroll_table_name = 'cctv_st_' .. i
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
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 =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = 'Add Input Storage'
}:style{
width = 160
@@ -248,6 +249,7 @@ end)
local vlayer_gui_control_storage_output =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = 'Add Output Storage'
}:style{
width = 160
@@ -267,6 +269,7 @@ end)
local vlayer_gui_control_circuit =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = 'Add Circuit'
}:style{
width = 160
@@ -286,6 +289,7 @@ end)
local vlayer_gui_control_power =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = 'Add Power'
}:style{
width = 160
@@ -308,6 +312,7 @@ end)
local vlayer_gui_control_remove =
Gui.element{
type = 'button',
name = Gui.unique_static_name,
caption = 'Remove Special'
}:style{
width = 160