GUI Production (#380)

* Update production.lua

* Update production.lua

* Update production.lua

* Update production.lua

* Update production.lua

* Update production.lua

* Update production.lua

* Update production.lua

* Fix table size

* Update gui.cfg

* Update gui.cfg

---------

Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com>
This commit is contained in:
2025-04-06 23:36:42 +09:00
committed by GitHub
parent c367e80641
commit e200533c6c
4 changed files with 52 additions and 65 deletions

View File

@@ -310,7 +310,8 @@ cursor-none=You need to hold the blueprint in cursor
main-tooltip=Production GUI main-tooltip=Production GUI
label-prod=Production label-prod=Production
label-con=Consumption label-con=Consumption
label-bal=Balance (sec) label-bal=Balance
tooltip-per-second=Items per second
[surveillance] [surveillance]
main-tooltip=Surveillance GUI main-tooltip=Surveillance GUI

View File

@@ -310,7 +310,8 @@ cursor-none=您需要將藍圖保持在遊標處
main-tooltip=製造介面 main-tooltip=製造介面
label-prod=製造 label-prod=製造
label-con=消耗 label-con=消耗
label-bal=淨值 (秒) label-bal=淨值
tooltip-per-second=物品每秒
[surveillance] [surveillance]
main-tooltip=監控介面 main-tooltip=監控介面

View File

@@ -310,7 +310,8 @@ cursor-none=您需要將藍圖保持在遊標處
main-tooltip=製造介面 main-tooltip=製造介面
label-prod=製造 label-prod=製造
label-con=消耗 label-con=消耗
label-bal=淨值 (秒) label-bal=淨值
tooltip-per-second=物品每秒
[surveillance] [surveillance]
main-tooltip=監控介面 main-tooltip=監控介面

View File

@@ -16,21 +16,33 @@ local precision = {
} }
local font_color = { local font_color = {
-- positive ["positive"] = { r = 0.3, g = 1, b = 0.3 },
[1] = { r = 0.3, g = 1, b = 0.3 }, ["negative"] = { r = 1, g = 0.3, b = 0.3 },
-- negative
[2] = { r = 1, g = 0.3, b = 0.3 },
} }
local function format_n(n) local function format_n(amount)
local _i, _j, m, i, f = tostring(n):find("([-]?)(%d+)([.]?%d*)") if math.abs(amount) < 0.009 then
i = i:reverse():gsub("(%d%d%d)", "%1,") return "0.00"
if f ~= "" then
return m .. i:reverse():gsub("^,", "") .. f
else
return m .. i:reverse():gsub("^,", "") .. ".0"
end end
local suffix = ""
local suffix_list = {
[" G"] = 1e9,
[" M"] = 1e6,
[" k"] = 1e3
}
local scale = 1
for letter, limit in pairs(suffix_list) do
if math.abs(amount) >= limit then
scale = limit
suffix = letter
break
end
end
local formatted = string.format("%.2f%s", amount / scale, suffix)
-- Split into integer and fractional parts
local integer_part, fractional_part = formatted:match("^(%-?%d+)%.(%d+)(.*)$")
-- Add commas to integer part
return string.format("%s.%s%s", (integer_part or formatted):reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,", ""):gsub("-,", "-"), fractional_part or "00", suffix)
end end
--- Display group --- Display group
@@ -58,35 +70,15 @@ local production_data_group = Gui.element("production_data_group")
item.style.width = 32 item.style.width = 32
end end
local data_1 = parent.add{ for j = 1, 3 do
type = "label", local data = parent.add{
name = "production_" .. i .. "_1", type = "label",
caption = "0.0", name = "production_" .. i .. "_" .. j,
style = "heading_2_label", caption = "0.00",
} style = "heading_2_label",
data_1.style.width = 90 }
data_1.style.horizontal_align = "right" data.style.font_color = font_color["positive"]
data_1.style.font_color = font_color[1] end
local data_2 = parent.add{
type = "label",
name = "production_" .. i .. "_2",
caption = "0.0",
style = "heading_2_label",
}
data_2.style.width = 90
data_2.style.horizontal_align = "right"
data_2.style.font_color = font_color[2]
local data_3 = parent.add{
type = "label",
name = "production_" .. i .. "_3",
caption = "0.0",
style = "heading_2_label",
}
data_3.style.width = 90
data_3.style.horizontal_align = "right"
data_3.style.font_color = font_color[1]
return item return item
end) end)
@@ -96,27 +88,27 @@ local production_data_group = Gui.element("production_data_group")
local production_data_set = Gui.element("production_data_set") local production_data_set = Gui.element("production_data_set")
:draw(function(_, parent, name) :draw(function(_, parent, name)
local production_set = parent.add{ type = "flow", direction = "vertical", name = name } local production_set = parent.add{ type = "flow", direction = "vertical", name = name }
local disp = Gui.elements.scroll_table(production_set, 350, 4, "disp") local disp = Gui.elements.scroll_table(production_set, 320, 4, "disp")
for i = 2, 4 do
disp.style.column_alignments[i] = "right"
end
production_data_group(disp, 0) production_data_group(disp, 0)
disp["production_0_1"].caption = { "production.label-prod" } disp["production_0_1"].caption = { "production.label-prod" }
disp["production_0_1"].tooltip = { "production.tooltip-per-second" }
disp["production_0_2"].caption = { "production.label-con" } disp["production_0_2"].caption = { "production.label-con" }
disp["production_0_2"].tooltip = { "production.tooltip-per-second" }
disp["production_0_3"].caption = { "production.label-bal" } disp["production_0_3"].caption = { "production.label-bal" }
disp["production_0_3"].tooltip = { "production.tooltip-per-second" }
for i = 1, 8 do for i = 1, 8 do
production_data_group(disp, i) production_data_group(disp, i)
end end
return production_set return production_set
end) end)
production_container = Gui.element("production_container") production_container = Gui.element("production_container")
:draw(function(def, parent) :draw(function(def, parent)
local container = Gui.elements.container(parent, 350) local container = Gui.elements.container(parent, 320)
production_data_set(container, "production_st") production_data_set(container, "production_st")
return container.parent return container.parent
end) end)
@@ -138,30 +130,22 @@ Event.on_nth_tick(60, function()
local stat = player.force.get_item_production_statistics(player.surface) -- Allow remote view local stat = player.force.get_item_production_statistics(player.surface) -- Allow remote view
local precision_value = precision[container.frame["production_st"].disp.table["production_0_e"].selected_index] local precision_value = precision[container.frame["production_st"].disp.table["production_0_e"].selected_index]
local table = container.frame["production_st"].disp.table local table = container.frame["production_st"].disp.table
for i = 1, 8 do for i = 1, 8 do
local production_prefix = "production_" .. i local production_prefix = "production_" .. i
local item = table[production_prefix .. "_e"].elem_value --[[ @as string ]] local item = table[production_prefix .. "_e"].elem_value --[[ @as string ]]
if item then if item then
local add = math.floor(stat.get_flow_count{ name = item, category = "input", precision_index = precision_value, count = false } / 6) / 10 local add = math.floor(stat.get_flow_count{ name = item, category = "input", precision_index = precision_value, count = false } / 6) / 10
local minus = math.floor(stat.get_flow_count{ name = item, category = "output", precision_index = precision_value, count = false } / 6) / 10 local minus = math.floor(stat.get_flow_count{ name = item, category = "output", precision_index = precision_value, count = false } / 6) / 10
local sum = add - minus local sum = add - minus
table[production_prefix .. "_1"].caption = format_n(add) table[production_prefix .. "_1"].caption = format_n(add)
table[production_prefix .. "_2"].caption = format_n(minus) table[production_prefix .. "_2"].caption = format_n(minus)
table[production_prefix .. "_3"].caption = format_n(sum) table[production_prefix .. "_3"].caption = format_n(sum)
table[production_prefix .. "_3"].style.font_color = (sum < 0 and font_color["negative"]) or font_color["positive"]
if sum < 0 then
table[production_prefix .. "_3"].style.font_color = font_color[2]
else
table[production_prefix .. "_3"].style.font_color = font_color[1]
end
else else
table[production_prefix .. "_1"].caption = "0.0" table[production_prefix .. "_1"].caption = "0.00"
table[production_prefix .. "_2"].caption = "0.0" table[production_prefix .. "_2"].caption = "0.00"
table[production_prefix .. "_3"].caption = "0.0" table[production_prefix .. "_3"].caption = "0.00"
table[production_prefix .. "_3"].style.font_color = font_color[1] table[production_prefix .. "_3"].style.font_color = font_color["positive"]
end end
end end
end end