This commit is contained in:
phidias authored and GitHub committed 2026-11-18 14:51:53 +09:00
1 parent ab29815388
commit 75245fa89e
1 file changed
+37 -22
+37 -22
View File
@@ -244,13 +244,16 @@ function Elements.items_table.calculate_display_data(s_index)
local items = Vlayer.get_items(s_index) local items = Vlayer.get_items(s_index)
local allocated = Vlayer.get_allocated_items(s_index) local allocated = Vlayer.get_allocated_items(s_index)
local result = {} local result = {}
local index = 1
for name, qnc in pairs(items) do for name, qnc in pairs(items) do
for quality, count in pairs(qnc) do for quality, count in pairs(qnc) do
local alloc = allocated[name] and allocated[name][quality] or 0 local alloc = allocated[name] and allocated[name][quality] or 0
local value = alloc / max(count, 1) local value = alloc / max(count, 1)
result[name .. quality] = { result[index] = {
name = name,
quality = quality,
value = value, value = value,
caption = format_string( caption = format_string(
"%s / %s, %.1f %%", "%s / %s, %.1f %%",
@@ -259,6 +262,8 @@ function Elements.items_table.calculate_display_data(s_index)
value * 100 value * 100
), ),
} }
index = index + 1
end end
end end
@@ -279,54 +284,64 @@ end
--- @param display_data table<string, ExpGui_Vlayer.elements.stat_bar.display_data> --- @param display_data table<string, ExpGui_Vlayer.elements.stat_bar.display_data>
function Elements.items_table.rows_adjust(items_table, display_data) function Elements.items_table.rows_adjust(items_table, display_data)
local rows = Elements.items_table.data[items_table] local rows = Elements.items_table.data[items_table]
local i_len = #items_table local i_len = #rows
local d_len = #display_data local d_len = #display_data
local min_r = min(i_len, d_len) local min_r = min(i_len, d_len)
--[[ if i_len < d_len then
for name, stat_bar in pairs(Elements.items_table.data[items_table]) do for i=1, min_r do
Elements.stat_bar.refresh(stat_bar, display_data[name]) local disp = display_data[i]
end rows[i][1].caption = format_string(
]] "%s [%s]",
disp.name,
if min_r < d_len then disp.quality
for name, stat_bar in pairs(Elements.items_table.data[items_table]) do )
Elements.stat_bar.refresh(stat_bar, display_data[name]) Elements.stat_bar.refresh(rows[i][2], disp)
end end
for i=min_r, d_len do for i=min_r, d_len do
for _, v in ipairs(rows[i]) do Gui.destroy_if_valid(rows[i][1])
Gui.destroy_if_valid(v) Gui.destroy_if_valid(rows[i][2])
end
end end
else else
for name, vnc in pairs(display_data) do for i=1, min_r do
local disp = display_data[i]
rows[i][1].caption = format_string(
"%s [%s]",
disp.name,
disp.quality
)
Elements.stat_bar.refresh(rows[i][2], disp)
end
for i=min_r, d_len do
local r = {} local r = {}
local disp = display_data[i]
r[1] = Elements.stat_label(items_table, { r[1] = Elements.stat_label(items_table, {
"?", "?",
{ {
"", "",
format_string( format_string(
"[img=entity/%s]", "[img=entity/%s]",
name disp.name
), ),
prototypes.entity[name].localised_name, prototypes.entity[name].localised_name,
format_string( format_string(
" [%s]", " [%s]",
quality disp.quality
) )
}, },
format_string( format_string(
"%s [%s]", "%s [%s]",
name, disp.name,
quality disp.quality
) )
}, },
"" ""
) )
r[2] = Elements.stat_bar(items_table) r[2] = Elements.stat_bar(items_table, disp)
rows[i] = r
rows[#rows + 1] = r
end end
end end
end end