Code: Select all
require("mod-gui")
script.on_event(defines.events.on_player_joined_game,
function (e)
local player = game.get_player(e.player_index)
local buttons = mod_gui.get_button_flow(player)
if not buttons["tab-test-button"] then
buttons.add{
type = "button",
name = "tab-test-button",
caption = "Test tab",
style = mod_gui.button_style
}
end
end
)
script.on_event(defines.events.on_gui_click,
function (e)
if e.element.name == "tab-test-button" then
local player = game.get_player(e.player_index)
local frames = mod_gui.get_frame_flow(player)
if frames["tab-test-frame"] then
return
end
local frame = frames.add{
type = "frame",
name = "tab-test-frame",
caption = "Tab test",
direction = "vertical",
style = mod_gui.frame_style
}
local tabbed_pane = frame.add{type="tabbed-pane"}
local tab1 = tabbed_pane.add{type="tab", caption="Tab 1"}
local tab2 = tabbed_pane.add{type="tab", caption="Tab 2"}
local label1 = tabbed_pane.add{type="label", caption="Label 1"}
local label2 = tabbed_pane.add{type="label", caption="Label 2"}
tabbed_pane.add_tab(tab1, label1)
tabbed_pane.add_tab(tab2, label2)
log(tabbed_pane.selected_tab_index)
end
end
)
1. I created a new game.
2. I clicked on the button, the frame showed up. The first tab was selected by default.
3. However, log(tabbed_pane.selected_tab_index) printed nil.
4. I saved the game and rejoined it. There was no tab selected.
5. I selected one of those tabs.
5. I saved the game and rejoined it. This time the tab was selected.
I believe there shouldn't be that discrepancy between what is visible after creating a tabbed pane (first tab is selected by default) and what is actually stored (tabbed_pane.selected_tab_index is nil).
inb4 the solution is just to set tabbed_pane.selected_tab_index = 1 manually.