1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2025-01-20 02:59:53 +02:00

Saving my work for surface starting items and resources config GUI. Have the starting items working. Need to setup GUI for resources next.

This commit is contained in:
Oarcinae 2024-10-06 15:28:16 -04:00
parent 33b8cb3b32
commit ffc9b450a5
11 changed files with 683 additions and 61 deletions

View File

@ -254,27 +254,24 @@ end)
-- Gui Events
----------------------------------------
script.on_event(defines.events.on_gui_click, function(event)
if not event.element.valid then return end -- Should we ever react to invalid GUI elements?
if not event.element.valid then return end
SeparateSpawnsGuiClick(event)
ClickOarcGuiButton(event)
OarcGuiTabsClick(event)
end)
--- Called when LuaGuiElement checked state is changed (related to checkboxes and radio buttons).
script.on_event(defines.events.on_gui_checked_state_changed, function (event)
if not event.element.valid then return end -- Should we ever react to invalid GUI elements?
if not event.element.valid then return end
SeparateSpawnsGuiCheckedStateChanged(event)
SpawnCtrlGuiOptionsSelect(event)
OarcGuiTabsCheckedStateChanged(event)
end)
script.on_event(defines.events.on_gui_selected_tab_changed, function (event)
if not event.element.valid then return end -- Should we ever react to invalid GUI elements?
if not event.element.valid then return end
OarcGuiSelectedTabChanged(event)
OarcGuiTabsSelectedTabChanged(event)
end)
-- For capturing player escaping custom GUI so we can close it using ESC key.
@ -285,30 +282,36 @@ end)
--- For sliders and other value changing elements.
script.on_event(defines.events.on_gui_value_changed, function(event)
if not event.element.valid then return end -- Should we ever react to invalid GUI elements?
if not event.element.valid then return end
SeparateSpawnsGuiValueChanged(event)
SettingsControlsTabGuiValueChanged(event)
OarcGuiTabsValueChanged(event)
end)
--- For dropdowns and listboxes.
script.on_event(defines.events.on_gui_selection_state_changed, function(event)
if not event.element.valid then return end -- Should we ever react to invalid GUI elements?
if not event.element.valid then return end
SeparateSpawnsGuiSelectionStateChanged(event)
SettingsControlsTabGuiSelectionStateChanged(event)
OarcGuiTabsSelectionStateChanged(event)
end)
script.on_event(defines.events.on_gui_text_changed, function(event)
if not event.element.valid then return end -- Should we ever react to invalid GUI elements?
if not event.element.valid then return end
SettingsControlsTabGuiTextChanged(event)
OarcGuiTabsTextChanged(event)
end)
script.on_event(defines.events.on_gui_confirmed, function(event)
if not event.element.valid then return end -- Should we ever react to invalid GUI elements?
if not event.element.valid then return end
SettingsControlsTabGuiTextconfirmed(event)
OarcGuiTabsConfirmed(event)
end)
script.on_event(defines.events.on_gui_elem_changed, function(event)
if not event.element.valid then return end
OarcGuiTabsElemChanged(event)
end)
----------------------------------------

View File

@ -26,6 +26,9 @@ SPAWN_SHAPE_CHOICE_SQUARE = "square"
RESOURCES_SHAPE_CHOICE_CIRCLE = "circle"
RESOURCES_SHAPE_CHOICE_SQUARE = "square"
MAX_CRASHED_SHIP_RESOURCES_ITEMS = 5
MAX_CRASHED_SHIP_WRECKAGE_ITEMS = 1
---@type OarcConfigStartingItems
NAUVIS_STARTER_ITEMS =
{
@ -364,22 +367,22 @@ OCFG = {
starting_items = NAUVIS_STARTER_ITEMS,
spawn_config = NAUVIS_SPAWN_CONFIG
},
["vulcanus"] = {
starting_items = NAUVIS_STARTER_ITEMS,
spawn_config = NAUVIS_SPAWN_CONFIG
},
["fulgora"] = {
starting_items = NAUVIS_STARTER_ITEMS,
spawn_config = NAUVIS_SPAWN_CONFIG
},
["gleba"] = {
starting_items = NAUVIS_STARTER_ITEMS,
spawn_config = NAUVIS_SPAWN_CONFIG
},
["aquilo"] = {
starting_items = NAUVIS_STARTER_ITEMS,
spawn_config = NAUVIS_SPAWN_CONFIG
}
-- ["vulcanus"] = {
-- starting_items = NAUVIS_STARTER_ITEMS,
-- spawn_config = NAUVIS_SPAWN_CONFIG
-- },
-- ["fulgora"] = {
-- starting_items = NAUVIS_STARTER_ITEMS,
-- spawn_config = NAUVIS_SPAWN_CONFIG
-- },
-- ["gleba"] = {
-- starting_items = NAUVIS_STARTER_ITEMS,
-- spawn_config = NAUVIS_SPAWN_CONFIG
-- },
-- ["aquilo"] = {
-- starting_items = NAUVIS_STARTER_ITEMS,
-- spawn_config = NAUVIS_SPAWN_CONFIG
-- }
},
-- Surfaces blacklist (Ignore these surfaces completely for spawning and regrowth!)

View File

@ -158,7 +158,7 @@ function ValidateAndLoadConfig()
-- Load the template config into the global table.
---@class OarcConfig
global.ocfg = OCFG
global.ocfg = table.deepcopy(OCFG)
-- Check that each entry in OCFG matches the default value of the mod setting. This is just for my own sanity.
-- Helps make sure mod default settings and my internal config are in sync.
@ -221,6 +221,17 @@ function ValidateSettings()
if (global.ocfg.surfaces_config["nauvis"] == nil) then
error("nauvis surface config does not exist! Please check your mod settings or config!")
end
-- Very for each surface config that the item counts are valid.
for surface_name,surface_config in pairs(global.ocfg.surfaces_config) do
if (table_size(surface_config.starting_items.crashed_ship_resources) > MAX_CRASHED_SHIP_RESOURCES_ITEMS) then
error("Too many items in crashed_ship_resources for surface: " .. surface_name)
end
if (table_size(surface_config.starting_items.crashed_ship_wreakage) > MAX_CRASHED_SHIP_WRECKAGE_ITEMS) then
error("Too many items in player_start_items for surface: " .. surface_name)
end
end
end
-- Read in the mod settings and copy them to the OARC_CFG table, overwriting the defaults in config.lua.

View File

@ -108,7 +108,7 @@ end
---Handle the gui click of the player list tab in the Oarc GUI.
---@param event EventData.on_gui_click
---@return nil
function PlayerListGuiClick(event)
function PlayerListTabGuiClick(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags

View File

@ -92,7 +92,7 @@ end
---Server info gui click event handler
---@param event EventData.on_gui_click
---@return nil
function ServerInfoGuiClick(event)
function ServerInfoTabGuiClick(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags

View File

@ -252,7 +252,7 @@ end
---Handle the gui checkboxes & radio buttons of the spawn control tab in the Oarc GUI.
---@param event EventData.on_gui_checked_state_changed
---@return nil
function SpawnCtrlGuiOptionsSelect(event)
function SpawnCtrlGuiOptionsCheckedStateChanged(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags
@ -282,7 +282,7 @@ end
---Handle the gui click of the spawn control tab in the Oarc GUI.
---@param event EventData.on_gui_click
---@return nil
function SpawnCtrlGuiClick(event)
function SpawnCtrlTabGuiClick(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags

View File

@ -0,0 +1,530 @@
--This file will let admins configure the "surfaces_config" table that is NOT available in the mod settings.
---Creates the tab content, used by AddOarcGuiTab
---@param tab_container LuaGuiElement
---@param player LuaPlayer
---@return nil
function CreateSurfaceConfigTab(tab_container, player)
local note = AddLabel(tab_container, nil, "This lets you configure the surface settings, it is only available to admins. These settings are NOT available in the mod settings page. If you want to automatically set these on the start of a new game using a custom file, please check out the included template scenario in the mod folder. I really question my sanity for bothering to make this GUI interface. Send help.", my_note_style) -- TODO: Localize
note.style.maximal_width = 700
-- Drop down to select surface that you want to configure
local selected_surface_name = CreateSurfaceDropdown(tab_container)
-- AddSpacer(tab_container)
local content = tab_container.add {
type = "flow",
direction = "vertical",
name = "surface_config_content_flow"
}
CreateSurfaceConfigContent(content, selected_surface_name)
end
---Create surface config content section below the surface selection dropdown
---@param container LuaGuiElement
---@param surface_name string
---@return nil
function CreateSurfaceConfigContent(container, surface_name)
-- Vertical scroll pane with dividers for each section for the surface config
local scroll_pane = container.add {
type = "scroll-pane",
direction = "vertical",
vertical_scroll_policy = "always",
}
scroll_pane.style.top_margin = 10
-- Add a checkbox to enable/disable the crashed ship.
CreateCrashSiteEnable(scroll_pane, surface_name)
local starting_items_flow = scroll_pane.add {
type = "flow",
direction = "horizontal"
}
-- TODO: Localize
CreateItemsSection(starting_items_flow, surface_name, "Starting Items", "player_start_items")
CreateItemsSection(starting_items_flow, surface_name, "Respawn Items", "player_respawn_items")
CreateItemsSection(starting_items_flow, surface_name, "Crashed Ship (Max 5)", "crashed_ship_resources", MAX_CRASHED_SHIP_RESOURCES_ITEMS)
CreateItemsSection(starting_items_flow, surface_name, "Ship Wreckage (Max 1)", "crashed_ship_wreakage", MAX_CRASHED_SHIP_WRECKAGE_ITEMS)
local spawn_config_flow = scroll_pane.add {
type = "flow",
direction = "horizontal"
}
-- Create an choose-elem-button for the testing
local button = spawn_config_flow.add {
type = "choose-elem-button",
elem_type = "entity",
elem_filters = {{filter = "type", type = "resource"}, {filter = "minable", mode = "and"}},
}
-- Spawn Config (safe area)
-- Spawn Config (water strip) (Note offset from north of spawn.)
-- Spawn Config (shared power pole position) (Note offset from west of spawn.)
-- Spawn Config (shared chest position) (Note offset from west of spawn.)
-- Spawn Config (resources and amounts (and maybe x/y positions)) (Note offset is center and not used if auto place.)
-- Spawn Config (fluid resources) (Note offset from south of spawn.)
end
---Create a checkbox to enable/disable the crashed ship
---@param container LuaGuiElement
---@param surface_name string
---@return nil
function CreateCrashSiteEnable(container, surface_name)
local crashed_ship_enabled = global.ocfg.surfaces_config[surface_name].starting_items.crashed_ship
local crashed_ship_flow = container.add {
type = "flow",
direction = "horizontal"
}
crashed_ship_flow.style.vertical_align = "center"
AddLabel(crashed_ship_flow, nil, "Enable Crashed Ship: ", "caption_label") -- TODO: Localize
local crashed_ship_enabled_checkbox = crashed_ship_flow.add {
type = "checkbox",
state = crashed_ship_enabled,
tags = {
action = "oarc_surface_config_tab",
setting = "crashed_ship_enabled",
surface_name = surface_name
},
tooltip = "Enables the factorio style ship crash with items. If this is disabled, the crashed ship items and wreckage won't do anything." -- TODO: Localize
}
end
---Create surface dropdown selection
---@param container LuaGuiElement
---@return string --The default selected surface name
function CreateSurfaceDropdown(container)
local surface_names = {}
for surface_name,_ in pairs(global.ocfg.surfaces_config) do
table.insert(surface_names, surface_name)
end
table.sort(surface_names)
local selected_surface_name = surface_names[1]
local horizontal_flow = container.add {
type = "flow",
direction = "horizontal"
}
horizontal_flow.style.vertical_align = "center"
AddLabel(horizontal_flow, nil, "Select Surface: ", "caption_label")
local surface_dropdown = horizontal_flow.add {
type = "drop-down",
name = "surface_dropdown",
items = surface_names,
selected_index = 1,
tags = {
action = "oarc_surface_config_tab",
setting = "surface_dropdown"
},
tooltip = "Select the surface you want to configure." -- TODO: Localize
}
local dragger = horizontal_flow.add{ type="empty-widget", style="draggable_space_header" }
dragger.style.horizontally_stretchable = true
-- A button to revert config to default (from OCFG hardcoded.)
local revert_button = horizontal_flow.add {
type = "button",
caption = "Revert", -- TODO: Localize
tooltip = "Revert to default.", -- TODO: Localize
style = "red_button",
tags = {
action = "oarc_surface_config_tab",
setting = "revert_to_default"
}
}
-- Add button to copy nauvis config to current selected surface (if not nauvis)
local copy_button = horizontal_flow.add {
type = "button",
caption = "Copy Nauvis", -- TODO: Localize
tooltip = "Copy Nauvis settings to this surface.", -- TODO: Localize
style = "red_button",
tags = {
action = "oarc_surface_config_tab",
setting = "copy_nauvis"
}
}
return selected_surface_name
end
---Handle the surface dropdown selection
---@param event EventData.on_gui_selection_state_changed
---@return nil
function SurfaceConfigTabGuiSelect(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags
if (tags.action ~= "oarc_surface_config_tab") then
return
end
if (tags.setting == "surface_dropdown") then
local selected_surface_name = event.element.items[event.element.selected_index] --[[@as string]]
local content_flow = event.element.parent.parent["surface_config_content_flow"]
if (content_flow == nil) then
error("Content flow is nil? This shouldn't happen on surface dropdown select! " .. selected_surface_name)
end
-- Recreate the content section
content_flow.clear()
CreateSurfaceConfigContent(content_flow, selected_surface_name)
player.print("Selected surface: " .. selected_surface_name)
end
end
---Create an items selection section
---@param container LuaGuiElement
---@param surface_name string
---@param header string
---@param setting_name string
---@param max_count integer?
---@return nil
function CreateItemsSection(container, surface_name, header, setting_name, max_count)
local items = global.ocfg.surfaces_config[surface_name].starting_items[setting_name]
if (items == nil) then
error("No items found for setting: " .. setting_name .. " for surface: " .. surface_name)
end
if (max_count and (table_size(items) > max_count)) then
-- This would only happen with a bad config.
error("Too many items in starting items list!?")
end
local vertical_flow = container.add {
type = "flow",
direction = "vertical"
}
AddLabel(vertical_flow, nil, header, my_label_header2_style)
local table = vertical_flow.add {
type = "table",
column_count = 3,
style = "bordered_table",
tags = {
surface_name = surface_name,
setting = setting_name,
max_count = max_count or 0
}
}
--Add headers
AddLabel(table, nil, "Item", "caption_label")
AddLabel(table, nil, "Count", "caption_label")
AddLabel(table, nil, "Remove", "caption_label")
for item_name, item_count in pairs(items) do
SurfaceConfigItemListDisplayRow(table, item_name, item_count)
end
-- Add a button to add another row
if (max_count == nil) or (max_count == 0) or (table_size(items) < max_count) then
SurfaceConfigItemListAddRowButton(table)
end
end
---Handle elem changed events
---@param event EventData.on_gui_elem_changed
---@return nil
function SurfaceConfigTabGuiElemChanged(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags
if (tags.action ~= "oarc_surface_config_tab") then
return
end
if (tags.elem_button) then
local new_item_name = event.element.elem_value --[[@as string]]
player.print("Selected item: " .. new_item_name)
if (new_item_name == nil) then
return
end
local old_item_name = tags.item_name --[[@as string]]
-- if the new item name is the same as the old item name, do nothing.
if (new_item_name == tags.item_name) then
return
end
-- otherwise, check if the new item name is already in the list.
local parent = event.element.parent
local surface_name = parent.tags.surface_name --[[@as string]]
local setting_name = parent.tags.setting --[[@as string]]
if (global.ocfg.surfaces_config[surface_name].starting_items[setting_name][new_item_name]) then
player.print("Item already exists in list! " .. new_item_name)
event.element.elem_value = nil
return
end
-- Update the item name in the list, keep the old count.
player.print("Update item: " .. old_item_name .. " to " .. new_item_name .. " for surface " .. surface_name)
global.ocfg.surfaces_config[surface_name].starting_items[setting_name][new_item_name] = global.ocfg.surfaces_config[surface_name].starting_items[setting_name][old_item_name]
global.ocfg.surfaces_config[surface_name].starting_items[setting_name][old_item_name] = nil
-- Update all tags with the new item name.
for _, child in pairs(event.element.parent.children) do
if (child.tags.item_name == old_item_name) then
local tags_copy = child.tags
tags_copy.item_name = new_item_name
child.tags = tags_copy
end
end
end
end
---Handle the surface config tab button clicks
---@param event EventData.on_gui_click
---@return nil
function SurfaceConfigTabGuiClick(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags
if (tags.action ~= "oarc_surface_config_tab") then
return
end
if (tags.remove_row_button) then
player.print("Remove item: " .. tags.item_name)
local parent = event.element.parent
local surface_name = parent.tags.surface_name --[[@as string]]
local setting_name = parent.tags.setting --[[@as string]]
local item_name = tags.item_name --[[@as string]]
local max_count = parent.tags.max_count --[[@as integer]]
-- Nil the entry
player.print("Remove item: " .. item_name .. " for surface " .. surface_name)
global.ocfg.surfaces_config[surface_name].starting_items[setting_name][item_name] = nil
-- Delete the row by removing the child elements from the table.
local parent = event.element.parent --[[@as LuaGuiElement]] -- Ass(u)me that the parent is a table.
for _, child in pairs(parent.children) do
if (child.tags and child.tags.item_name == tags.item_name) then
child.destroy()
end
end
-- Only add the add row if we haven't reached the max count AND the children count is 1 more than % 3.
local table_modulo_3 = #parent.children % 3
if table_modulo_3 == 0 then
SurfaceConfigItemListAddRowButton(parent)
end
elseif (tags.add_row_button) then
local parent = event.element.parent
local surface_name = parent.tags.surface_name --[[@as string]]
local setting_name = parent.tags.setting --[[@as string]]
local max_count = parent.tags.max_count --[[@as integer]]
if (parent == nil) then
error("Parent is nil? This shouldn't happen on add row button click! " .. setting_name)
end
player.print("Add row: " .. setting_name)
-- Delete the button and add a new row and then add the button back.
event.element.destroy()
SurfaceConfigItemListDisplayRow(parent)
-- Only add the add row if we haven't reached the max count.
local item_count = (#parent.children - 3) / 3
if (max_count == nil) or (max_count == 0) or (item_count < max_count) then
SurfaceConfigItemListAddRowButton(parent)
end
elseif (tags.setting == "crashed_ship_enabled") then
local surface_name = tags.surface_name --[[@as string]]
player.print("Crashed Ship Enabled: " .. tostring(event.element.state))
global.ocfg.surfaces_config[surface_name].starting_items.crashed_ship = event.element.state
elseif (tags.setting == "revert_to_default") then
local surface_name = event.element.parent["surface_dropdown"].items[event.element.parent["surface_dropdown"].selected_index] --[[@as string]]
player.print("Revert to default: " .. surface_name)
global.ocfg.surfaces_config[surface_name].starting_items = table.deepcopy(NAUVIS_STARTER_ITEMS)
global.ocfg.surfaces_config[surface_name].spawn_config = table.deepcopy(NAUVIS_SPAWN_CONFIG)
-- Recreate the content section
local content_flow = event.element.parent.parent["surface_config_content_flow"]
if (content_flow == nil) then
error("Content flow is nil? This shouldn't happen on revert to default! " .. surface_name)
end
content_flow.clear()
CreateSurfaceConfigContent(content_flow, surface_name)
elseif (tags.setting == "copy_nauvis") then
local surface_name = event.element.parent["surface_dropdown"].items[event.element.parent["surface_dropdown"].selected_index] --[[@as string]]
if (surface_name == "nauvis") then
player.print("Already on nauvis, select a different surface to copy nauvis settings to!")
return
end
player.print("Copy Nauvis: " .. surface_name)
global.ocfg.surfaces_config[surface_name].starting_items = global.ocfg.surfaces_config["nauvis"].starting_items
global.ocfg.surfaces_config[surface_name].spawn_config = global.ocfg.surfaces_config["nauvis"].spawn_config
-- Recreate the content section
local content_flow = event.element.parent.parent["surface_config_content_flow"]
if (content_flow == nil) then
error("Content flow is nil? This shouldn't happen on copy nauvis! " .. surface_name)
end
content_flow.clear()
CreateSurfaceConfigContent(content_flow, surface_name)
end
end
---Adds a row to a table with an item and count
---@param table LuaGuiElement
---@param item_name string?
---@param item_count integer?
---@return nil
function SurfaceConfigItemListDisplayRow(table, item_name, item_count)
-- Create choose elem button
local button = table.add {
type = "choose-elem-button",
elem_type = "item",
item = item_name,
tags = {
action = "oarc_surface_config_tab",
elem_button = true,
item_name = item_name or ""
},
}
button.style.width = 28
button.style.height = 28
-- Create number textfield
local textfield = table.add {
type = "textfield",
text = tostring(item_count or 0),
numeric = true,
allow_decimal = false,
tooltip = {"oarc-settings-tab-text-field-enter-tooltip" },
tags = {
action = "oarc_surface_config_tab",
item_number_textfield = true,
item_name = item_name or ""
}
}
if (item_name == "") then
textfield.style = "invalid_value_textfield"
end
textfield.style.width = 40
-- Create a button to remove the row
local remove_button = table.add {
type = "sprite-button",
sprite = "utility/deconstruction_mark",
tooltip = "Remove Item", -- TODO: Localize
tags = {
action = "oarc_surface_config_tab",
remove_row_button = true,
item_name = item_name or ""
}
}
remove_button.style.width = 28
remove_button.style.height = 28
end
---Add the add row button to the table
---@param table LuaGuiElement
---@return nil
function SurfaceConfigItemListAddRowButton(table)
-- Add a button to add another row
local add_row_button = table.add {
type = "sprite-button",
sprite = "utility/check_mark_green",
tooltip = "Add Item", -- TODO: Localize
tags = {
action = "oarc_surface_config_tab",
add_row_button = true
}
}
add_row_button.style.width = 28
add_row_button.style.height = 28
end
---Handle on_gui_text_changed events
---@param event EventData.on_gui_text_changed
---@return nil
function SurfaceConfigTabGuiTextChanged(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags
if (tags.action ~= "oarc_surface_config_tab") then
return
end
if (tags.item_number_textfield) then
player.print("Selected item: " .. tags.item_name .. " count: " .. event.element.text)
event.element.style = "invalid_value_textfield"
event.element.style.width = 40
end
end
---Handle on_gui_confirmed events
---@param event EventData.on_gui_confirmed
---@return nil
function SurfaceConfigTabGuiConfirmed(event)
if not event.element.valid then return end
local player = game.players[event.player_index]
local tags = event.element.tags
if (tags.action ~= "oarc_surface_config_tab") then
return
end
if (tags.item_number_textfield) then
player.print("Selected item: " .. tags.item_name .. " count: " .. event.element.text)
local parent = event.element.parent
local surface_name = parent.tags.surface_name --[[@as string]]
local setting_name = parent.tags.setting --[[@as string]]
local item_name = tags.item_name --[[@as string]]
-- Check if an item is selected first.
if (tags.item_name == "") then
player.print("Please select an item first!")
event.element.text = "0"
return
end
-- Update the count
local count = tonumber(event.element.text) or 0
global.ocfg.surfaces_config[surface_name].starting_items[setting_name][item_name] = count
event.element.style = "textbox"
event.element.style.width = 40
end
end

View File

@ -6,6 +6,7 @@ require("lib/gui_tabs/spawn_controls")
require("lib/gui_tabs/settings_controls")
require("lib/gui_tabs/mod_info_faq")
require("lib/gui_tabs/player_list")
require("lib/gui_tabs/surface_config")
--------------------------------------------------------------------------------
-- GUI Tab Handler
@ -20,19 +21,22 @@ OARC_SPAWN_CTRL_TAB_NAME = "spawn_controls"
OARC_CONFIG_CTRL_TAB_NAME = "settings"
OARC_MOD_INFO_CTRL_TAB_NAME = "mod_info"
OARC_MOD_PLAYER_LIST_TAB_NAME = "player_list"
OARC_SURFACE_CONFIG_TAB_NAME = "surface_config"
OARC_SERVER_INFO_TAB_LOCALIZED = {"oarc-server-info-tab-title"}
OARC_SPAWN_CTRL_TAB_LOCALIZED = {"oarc-spawn-ctrls-tab-title"}
OARC_CONFIG_CTRL_TAB_LOCALIZED = {"oarc-settings-tab-title"}
OARC_MOD_INFO_CTRL_TAB_LOCALIZED = {"oarc-mod-info-tab-title"}
OARC_PLAYER_LIST_TAB_LOCALIZED = {"oarc-player-list-tab-title"}
OARC_SURFACE_CONFIG_TAB_LOCALIZED = {"oarc-surface-config-tab-title"}
local OARC_GUI_TAB_CONTENT_FUNCTIONS = {
[OARC_SERVER_INFO_TAB_NAME] = CreateServerInfoTab,
[OARC_SPAWN_CTRL_TAB_NAME] = CreateSpawnControlsTab,
[OARC_MOD_INFO_CTRL_TAB_NAME] = CreateModInfoTab,
[OARC_CONFIG_CTRL_TAB_NAME] = CreateSettingsControlsTab,
[OARC_MOD_PLAYER_LIST_TAB_NAME] = CreatePlayerListTab
[OARC_MOD_PLAYER_LIST_TAB_NAME] = CreatePlayerListTab,
[OARC_SURFACE_CONFIG_TAB_NAME] = CreateSurfaceConfigTab,
}
---@param player LuaPlayer
@ -65,6 +69,12 @@ function InitOarcGuiTabs(player)
AddOarcGuiTab(player, OARC_MOD_PLAYER_LIST_TAB_NAME, OARC_PLAYER_LIST_TAB_LOCALIZED)
SetOarcGuiTabEnabled(player, OARC_MOD_PLAYER_LIST_TAB_NAME, true)
-- Surface config tab
if (player.admin) then
AddOarcGuiTab(player, OARC_SURFACE_CONFIG_TAB_NAME, OARC_SURFACE_CONFIG_TAB_LOCALIZED)
SetOarcGuiTabEnabled(player, OARC_SURFACE_CONFIG_TAB_NAME, true)
end
HideOarcGui(player)
end
@ -150,12 +160,7 @@ function ClickOarcGuiButton(event)
end
end
---@param event EventData.on_gui_selected_tab_changed
---@return nil
function OarcGuiSelectedTabChanged(event)
if (event.element.name ~= "oarc_tabs") then return end
OarcGuiCreateContentOfTab(game.players[event.player_index])
end
---Set tab content to currently selected tab, clears all other tab content and refreshes the selected tab content!
---Safe to call just to refresh the current tab.
@ -306,15 +311,6 @@ function SwitchOarcGuiTab(player, tab_name)
end
end
---Handles the closing of the OARC GUI.
---@param event EventData.on_gui_closed
---@return nil
function OarcGuiClosed(event)
if (event.element and (event.element.name == "oarc_gui")) then
HideOarcGui(game.players[event.player_index])
end
end
---Completely destroys and recreates the OARC GUI for a player.
---@param player LuaPlayer
---@return nil
@ -330,15 +326,92 @@ function RecreateOarcGui(player)
InitOarcGuiTabs(player)
end
--[[
_____ _____ _ _ _____ _ _ _ _ _ ___ _ ___ ___ ___
| __\ \ / / __| \| |_ _| | || | /_\ | \| | \| | | __| _ \/ __|
| _| \ V /| _|| .` | | | | __ |/ _ \| .` | |) | |__| _|| /\__ \
|___| \_/ |___|_|\_| |_| |_||_/_/ \_\_|\_|___/|____|___|_|_\|___/
---Server info gui click event handler
]]
---Handles the closing of the OARC GUI.
---@param event EventData.on_gui_closed
---@return nil
function OarcGuiClosed(event)
if (event.element and (event.element.name == "oarc_gui")) then
HideOarcGui(game.players[event.player_index])
end
end
---@param event EventData.on_gui_selected_tab_changed
---@return nil
function OarcGuiTabsSelectedTabChanged(event)
if (event.element.name ~= "oarc_tabs") then return end
OarcGuiCreateContentOfTab(game.players[event.player_index])
end
---All gui tabs click event handler
---@param event EventData.on_gui_click
---@return nil
function OarcGuiTabsClick(event)
if not event.element.valid then return end
ServerInfoGuiClick(event)
SpawnCtrlGuiClick(event)
ClickOarcGuiButton(event)
ServerInfoTabGuiClick(event)
SpawnCtrlTabGuiClick(event)
SettingsControlsTabGuiClick(event)
SettingsSurfaceControlsTabGuiClick(event)
PlayerListGuiClick(event)
end
PlayerListTabGuiClick(event)
SurfaceConfigTabGuiClick(event)
end
---All gui tabs on_gui_checked_state_changed event handler
---@param event EventData.on_gui_checked_state_changed
---@return nil
function OarcGuiTabsCheckedStateChanged(event)
if not event.element.valid then return end
SpawnCtrlGuiOptionsCheckedStateChanged(event)
end
---Handles the `on_gui_value_changed` event.
---@param event EventData.on_gui_value_changed
---@return nil
function OarcGuiTabsValueChanged(event)
if not event.element.valid then return end
SettingsControlsTabGuiValueChanged(event)
end
---Handles the `on_gui_selection_state_changed` event.
---@param event EventData.on_gui_selection_state_changed
---@return nil
function OarcGuiTabsSelectionStateChanged(event)
if not event.element.valid then return end
SettingsControlsTabGuiSelectionStateChanged(event)
SurfaceConfigTabGuiSelect(event)
end
---Handles the `on_gui_text_changed` event.
---@param event EventData.on_gui_text_changed
---@return nil
function OarcGuiTabsTextChanged(event)
if not event.element.valid then return end
SettingsControlsTabGuiTextChanged(event)
SurfaceConfigTabGuiTextChanged(event)
end
---Handles the `on_gui_confirmed` event.
---@param event EventData.on_gui_confirmed
---@return nil
function OarcGuiTabsConfirmed(event)
if not event.element.valid then return end
SettingsControlsTabGuiTextconfirmed(event)
SurfaceConfigTabGuiConfirmed(event)
end
---Handles the `on_gui_elem_changed` event.
---@param event EventData.on_gui_elem_changed
---@return nil
function OarcGuiTabsElemChanged(event)
if not event.element.valid then return end
SurfaceConfigTabGuiElemChanged(event)
end

View File

@ -58,6 +58,7 @@ my_note_style = {
top_padding = 0,
bottom_padding = 0
}
---@type LuaStyle
---@diagnostic disable-next-line: missing-fields
my_warning_style = {

View File

@ -141,10 +141,10 @@ function SeparateSpawnsInitSurface(surface_name)
global.oarc_surfaces[surface_name] = (surface_name == global.ocfg.gameplay.default_surface)
end
-- Make sure it has a surface configuration entry
if (global.oarc_surfaces[surface_name] and global.ocfg.surfaces_config[surface_name] == nil) then
-- Make sure it has a surface configuration entry!
if (global.ocfg.surfaces_config[surface_name] == nil) then
log("Surface does NOT have a config entry, defaulting to nauvis entry for new surface: " .. surface_name)
global.ocfg.surfaces_config[surface_name] = global.ocfg.surfaces_config["nauvis"]
global.ocfg.surfaces_config[surface_name] = table.deepcopy(global.ocfg.surfaces_config["nauvis"])
end
end

View File

@ -182,6 +182,7 @@ oarc-spawn-ctrls-tab-title=Spawn Controls
oarc-settings-tab-title=Settings
oarc-mod-info-tab-title=Mod Info
oarc-player-list-tab-title=Player List
oarc-surface-config-tab-title=Surface Config
oarc-server-info-tab-welcome-msg-title=Welcome Message
oarc-server-info-tab-discord-invite=Discord Invite: