add rescan functionality for allow-list, and add the allow-list data to show on the cybersyn combinator UI for transparency

This commit is contained in:
Zoryn
2024-10-22 19:01:44 -04:00
parent 5d256f8c87
commit 62fc8bd583
4 changed files with 74 additions and 0 deletions

View File

@@ -100,6 +100,8 @@ local function handle_drop_down(e)
end
combinator_update(storage, comb)
update_allow_list_section(e.player_index, comb.unit_number)
end
---@param e EventData.on_gui_switch_state_changed
local function handle_pr_switch(e)
@@ -150,6 +152,48 @@ local function handle_setting_flip(e)
set_comb_setting(comb, element.tags.bit--[[@as int]], not element.state)
combinator_update(storage, comb)
update_allow_list_section(e.player_index, comb.unit_number)
end
local function generate_stop_layout(combId)
local targetStop = storage.to_stop[combId]
local stopLayout = ""
if targetStop ~= nil then
local station = storage.stations[targetStop.unit_number]
local refueler = storage.refuelers[targetStop.unit_number]
if station ~= nil then
stopLayout = station.layout_pattern
elseif refueler ~= nil then
stopLayout = refueler.layout_pattern
end
end
--TODO: improve readability
return serpent.line(stopLayout)
end
function get_allow_list_section(player_index)
local player = game.get_player(player_index)
if player.opened.name == "cybersyn-combinator" then
--this WILL crash if the order of elements in the UI is modified
--TODO: make this dynamic based on property names? or store a ref to the layout preview section?
return player.opened.children[2].children[1].children[8]
end
end
function update_allow_list_section(player_index, comb_unit_number)
local layoutSection = get_allow_list_section(player_index)
if layoutSection ~= nil then
local selected_index, signal, switch_state, bits = get_comb_gui_settings(storage.to_comb[comb_unit_number])
--only for Station (1) and Refueler (3)
if ((selected_index == 1 or selected_index == 3) and setting_flip(bits, SETTING_DISABLE_ALLOW_LIST)) then
layoutSection.visible = true
layoutSection.children[2].caption = generate_stop_layout(comb_unit_number)
else
layoutSection.visible = false
end
end
end
local function on_gui_opened(event)
@@ -196,6 +240,14 @@ function gui_opened(comb, player)
local rootgui = player.gui.screen
local selected_index, signal, switch_state, bits = get_comb_gui_settings(comb)
local showLayout = false
local layoutText = ""
--only for Station (1) and Refueler (3)
if ((selected_index == 1 or selected_index == 3) and setting_flip(bits, SETTING_DISABLE_ALLOW_LIST)) then
showLayout = true
layoutText = generate_stop_layout(comb.unit_number)
end
local _, main_window = flib_gui.add(rootgui, {
{type="frame", direction="vertical", name=COMBINATOR_NAME, children={
--title bar
@@ -242,6 +294,12 @@ function gui_opened(comb, player)
{type="checkbox", name="is_stack", state=setting(bits, SETTING_IS_STACK), handler=handle_setting, tags={id=comb.unit_number, bit=SETTING_IS_STACK}, tooltip={"cybersyn-gui.is-stack-tooltip"}, caption={"cybersyn-gui.is-stack-description"}},
}},
{type="checkbox", name="enable_inactive", state=setting(bits, SETTING_ENABLE_INACTIVE), handler=handle_setting, tags={id=comb.unit_number, bit=SETTING_ENABLE_INACTIVE}, tooltip={"cybersyn-gui.enable-inactive-tooltip"}, caption={"cybersyn-gui.enable-inactive-description"}},
}},
--preview allow list
{type="flow", name="bottom-allowlist", direction="vertical", style_mods={vertical_align="top"}, visible=showLayout, children={
{type="label", name="allow_list_label_title", style="heading_2_label", caption={"cybersyn-gui.allow-list-preview"}, tooltip={"cybersyn-gui.allow-list-preview-tooltip"}, style_mods={top_padding=8}},
{type="label", name="allow_list_label", caption=layoutText, style_mods={top_padding=8}},
{type="button", name="allow_list_refresh", tags={id=comb.unit_number}, tooltip={"cybersyn-gui.allow-list-refresh-tooltip"}, caption={"cybersyn-gui.allow-list-refresh-description"}},
}}
}}
}}
@@ -255,3 +313,4 @@ function gui_opened(comb, player)
set_visibility(main_window, selected_index)
player.opened = main_window
end