1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2025-02-07 13:07:58 +02:00

Return of the coin shop. Plus some cleanup of comments in the config.lua file with regards to the template scenario. Also bumping version number and starting changelog.

This commit is contained in:
Oarcinae 2024-10-12 21:57:46 -04:00
parent c86cf987ff
commit 0d46fcd3fa
15 changed files with 479 additions and 44 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
releases
releases
scenarios

View File

@ -1,15 +1,19 @@
-- To edit this scenario, you must make a copy of it and place it in your own scenarios folder first!
-- Do not edit the scenario provided by the mod install directly!
-- I provide this empty scenario to avoid the freeplay scenario extra baggage.
-- You can use the freeplay scenario too just fine if you want.
-- The main benefit of the scenario is that it lets you modify the any of the config during on_init of the mod.
-- I provide this empty scenario to avoid the freeplay scenario extra baggage and as a template for how to modify the
-- settings on init. You can use the freeplay scenario too just fine if you want.
-- This is where you can modify what resources spawn, how much, where, etc.
-- Once you have a config you like, it's a good idea to save it for later use so you don't lose it if you update the
-- scenario. I will try to avoid making breaking changes to this, but no guarantees.
-- I will try to avoid making breaking changes to this, but no guarantees.
-- To see what settings are available, look at the config_mod.lua file in the mod folder itself.
-- To see the full list of all settings available, look at the config.lua file in the mod folder itself.
-- That has all the settings and their definitions and default values. Plus, if you are using VS Code + FMTK (the
-- Factorio Mod Toolkit), you can use the syntax highlighting and autocomplete to see all the settings available.
-- Alternatively, you can use the in-game "export" button to get a string of all settings that you can then format
-- and edit however you want to use here.
-- ANY CONFIG HERE WILL OVERWRITE MOD SETTINGS! This is the whole point.
-- Check if the OARC mod is loaded. Other than that, it's an empty scenario!
script.on_init(function(event)
@ -33,7 +37,7 @@ local oarc_scenario_interface =
modified_settings.server_info.welcome_msg = "This is a template scenario. You can modify the settings in the control.lua file. If you are seeing this message, you did not modify the scenario correctly."
-- modified_settings.spawn_general.shape = "circle"
-- Some examples of overriding surface config (which is not accessible from the mod settings!)
-- modified_settings.surfaces_config["nauvis"].starting_items.player_start_items = {
-- ["coal"] = 1, -- You're on the naughty list!

View File

@ -1,4 +1,12 @@
---------------------------------------------------------------------------------------------------
Version: 2.0.3
Date: 2024-10-13
Major Features:
- Return of the "coin shop" feature.
- Marking RSO as incompatible because I can't easily make it compatible.
Info:
- Updated comments in config file and scenario template to be more clear.
---------------------------------------------------------------------------------------------------
Version: 2.0.2
Date: 2024-10-08
Major Features:

View File

@ -250,6 +250,17 @@ script.on_event(defines.events.on_unit_group_finished_gathering, function(event)
end
end)
----------------------------------------
-- On enemies killed
-- For coin generation and stuff
----------------------------------------
script.on_event(defines.events.on_post_entity_died, function(event)
if global.ocfg.coin_generation.enabled then
CoinsFromEnemiesOnPostEntityDied(event)
end
end,
{{filter="type", type = "unit"}, {filter="type", type = "unit-spawner"}, {filter="type", type = "turret"}})
----------------------------------------
-- Gui Events
----------------------------------------

View File

@ -25,3 +25,6 @@ data:extend({
},
oarc_linked_chest, oarc_linked_power
})
-- Make coins not hidden
data.raw["item"]["coin"].flags = {}

View File

@ -1,6 +1,6 @@
{
"name": "oarc-mod",
"version": "2.0.2",
"version": "2.0.3",
"factorio_version": "1.1",
"title": "Oarc Multiplayer Spawn",
"author": "Oarcinae",

View File

@ -8,14 +8,13 @@
DO NOT EDIT THIS FILE!
DO NOT EDIT THIS FILE!
If you want to customize settings at init, edit the control.lua file in the scenarios/OARC folder and load that scenario!
If you want to customize settings at init, look at the TEMPLATE_SCENARIO folder!
More settings are available here than are provided in the mod settings menu.
Additionally, many settings are exposed in the game itself and can be changed in game.
]]
-- More settings are available here than are provided in the mod settings menu.
-- Additionally, many settings are exposed in the game itself and can be changed in game.
-- For convenience you, you can edit the control.lua file in the scenarios/OARC folder to override settings as well.
-- That method is useful for headless server hosting where it's hard to configure mod settings.
---@alias SpawnShapeChoice "circle" | "octagon" | "square"
SPAWN_SHAPE_CHOICE_CIRCLE = "circle"
@ -173,6 +172,118 @@ NAUVIS_SURFACE_CONFIG =
spawn_config = NAUVIS_SPAWN_CONFIG
}
---This only matters if you have the coin shop enabled.
---@type OarcStoreList
OARC_SHOP_ITEMS =
{
["Guns"] = {
["pistol"] = {cost = 1, count = 1, play_time_locked=false},
["shotgun"] = {cost = 5, count = 1, play_time_locked=false},
["submachine-gun"] = {cost = 10, count = 1, play_time_locked=false},
["flamethrower"] = {cost = 50, count = 1, play_time_locked=true},
["rocket-launcher"] = {cost = 50, count = 1, play_time_locked=true},
-- ["railgun"] = {cost = 250, count = 1, play_time_locked=true}, -- Was removed awhile ago, but might return with 2.0?
},
["Turrets"] = {
["gun-turret"] = {cost = 25, count = 1, play_time_locked=false},
["flamethrower-turret"] = {cost = 50, count = 1, play_time_locked=false},
["laser-turret"] = {cost = 75, count = 1, play_time_locked=false},
["artillery-turret"] = {cost = 500, count = 1, play_time_locked=true},
},
["Ammo"] = {
["firearm-magazine"] = {cost = 10, count = 10, play_time_locked=false},
["piercing-rounds-magazine"] = {cost = 30, count = 10, play_time_locked=false},
["shotgun-shell"] = {cost = 10, count = 10, play_time_locked=false},
["flamethrower-ammo"] = {cost = 50, count = 10, play_time_locked=true},
["rocket"] = {cost = 100, count = 10, play_time_locked=true},
-- ["railgun-dart"] = {cost = 250, count = 10, play_time_locked=true}, -- Was removed awhile ago, but might return with 2.0?
["atomic-bomb"] = {cost = 1000, count = 1, play_time_locked=true},
["artillery-shell"] = {cost = 50, count = 1, play_time_locked=true},
},
["Special"] = {
["repair-pack"] = {cost = 1, count = 1, play_time_locked=false},
["raw-fish"] = {cost = 1, count = 1, play_time_locked=false},
["grenade"] = {cost = 20, count = 10, play_time_locked=true},
["cliff-explosives"] = {cost = 20, count = 10, play_time_locked=true},
["artillery-targeting-remote"] = {cost = 500, count = 1, play_time_locked=true},
},
["Capsules/Mines"] = {
["land-mine"] = {cost = 20, count = 10, play_time_locked=false},
["defender-capsule"] = {cost = 20, count = 10, play_time_locked=false},
["distractor-capsule"] = {cost = 40, count = 10, play_time_locked=false},
["destroyer-capsule"] = {cost = 60, count = 10, play_time_locked=false},
["poison-capsule"] = {cost = 50, count = 10, play_time_locked=false},
["slowdown-capsule"] = {cost = 25, count = 10, play_time_locked=false},
},
["Armor"] = {
["light-armor"] = {cost = 10, count = 1, play_time_locked=false},
["heavy-armor"] = {cost = 20, count = 1, play_time_locked=false},
["modular-armor"] = {cost = 200, count = 1, play_time_locked=false},
["power-armor"] = {cost = 1000, count = 1, play_time_locked=false},
["power-armor-mk2"] = {cost = 5000, count = 1, play_time_locked=false},
},
["Power Equipment"] = {
["fusion-reactor-equipment"] = {cost = 1000, count = 1, play_time_locked=false},
["battery-equipment"] = {cost = 100, count = 1, play_time_locked=false},
["battery-mk2-equipment"] = {cost = 1000, count = 1, play_time_locked=false},
["solar-panel-equipment"] = {cost = 10, count = 1, play_time_locked=false},
},
["Bot Equipment"] = {
["personal-roboport-equipment"] = {cost = 100, count = 1, play_time_locked=false},
["personal-roboport-mk2-equipment"] = {cost = 500, count = 1, play_time_locked=false},
["construction-robot"] = {cost = 100, count = 10, play_time_locked=false},
["roboport"] = {cost = 1000, count = 1, play_time_locked=false},
["logistic-chest-storage"] = {cost = 100, count = 1, play_time_locked=false},
},
["Misc Equipment"] = {
["belt-immunity-equipment"] = {cost = 10, count = 1, play_time_locked=false},
["exoskeleton-equipment"] = {cost = 100, count = 1, play_time_locked=false},
["night-vision-equipment"] = {cost = 50, count = 1, play_time_locked=false},
["personal-laser-defense-equipment"] = {cost = 100, count = 1, play_time_locked=false},
["energy-shield-equipment"] = {cost = 50, count = 1, play_time_locked=false},
["energy-shield-mk2-equipment"] = {cost = 500, count = 1, play_time_locked=false},
},
["Spidertron"] = {
["spidertron"] = {cost = 5000, count = 1, play_time_locked=false},
["spidertron-remote"] = {cost = 500, count = 1, play_time_locked=false},
},
}
COIN_MULTIPLIER = 2
-- TODO: Add default values for space age new enemies
---@type table<string, number>
COIN_GENERATION_CHANCES = {
["small-biter"] = 0.01,
["medium-biter"] = 0.02,
["big-biter"] = 0.05,
["behemoth-biter"] = 1,
["small-spitter"] = 0.01,
["medium-spitter"] = 0.02,
["big-spitter"] = 0.05,
["behemoth-spitter"] = 1,
["small-worm-turret"] = 5,
["medium-worm-turret"] = 10,
["big-worm-turret"] = 15,
["behemoth-worm-turret"] = 25,
["biter-spawner"] = 20,
["spitter-spawner"] = 20,
}
---@type OarcConfig
OCFG = {
@ -283,6 +394,10 @@ OCFG = {
-- Enables a single shared chest using the native linked-chest entity in factorio.
enable_shared_chest = false,
-- Enable the coin shop GUI for players to buy items with coins.
-- This makes biters drop coins on death.
enable_coin_shop = false,
},
-- This is a separate feature that is part of the mod that helps keep the map size down. Not required but useful.
@ -411,12 +526,22 @@ OCFG = {
"factory-power",
"factory-floor",
},
-- List of items available in the coin shop (if enabled).
---@type OarcStoreList
shop_items = OARC_SHOP_ITEMS,
-- Coin generation settings for when enemies die.
---@type OarcCoinGenerationSettings
coin_generation = {
enabled = false,
coin_multiplier = COIN_MULTIPLIER,
coin_generation_table = COIN_GENERATION_CHANCES,
auto_decon_coins = true,
},
}
--[[
_ _ _ _ _______ _____ ___ _ _ _ _ _ ___ _____ _ _____ ___ ___ _ _ ___
@ -437,6 +562,8 @@ OCFG = {
---@field surfaces_config table<string, OarcConfigSurface> Spawn configuration (starting items and spawn area config) for each surface.
---@field surfaces_blacklist table<string> List of surfaces to ignore automatically.
---@field surfaces_blacklist_match table<string> List of surfaces to ignore automatically if the start of the string matches the surface name.
---@field shop_items OarcStoreList List of items available in the coin shop (if enabled).
---@field coin_generation OarcCoinGenerationSettings Coin generation settings for when enemies die.
---@class OarcConfigServerInfo
---@field welcome_msg_title string Title of welcome GUI window.
@ -470,6 +597,7 @@ OCFG = {
---@field respawn_cooldown_min number Respawn cooldown in minutes.
---@field enable_shared_power boolean Enable shared power between bases. Creates a special power pole for cross surface connections.
---@field enable_shared_chest boolean Enables a single shared chest using the native linked-chest entity in factorio.
---@field enable_coin_shop boolean Enable the coin shop GUI for players to buy items with coins. This makes biters drop coins on death.
---@class OarcConfigRegrowth
---@field enable_regrowth boolean Cleans up unused chunks periodically. Helps keep map size down.
@ -530,4 +658,19 @@ OCFG = {
---@field amount_multiplier number Amount multiplier for the starting resource deposits.
---@alias OarcConfigSolidResource { amount: integer, size: integer, x_offset: integer, y_offset: integer } Amount and placement of solid resource tiles in the spawn area.
---@alias OarcConfigFluidResource { num_patches: integer, amount: integer, x_offset_start: integer, y_offset_start: integer, x_offset_next: integer, y_offset_next: integer } Amount and placement of fluid resource patches in the spawn area.
---@alias OarcConfigFluidResource { num_patches: integer, amount: integer, x_offset_start: integer, y_offset_start: integer, x_offset_next: integer, y_offset_next: integer } Amount and placement of fluid resource patches in the spawn area.
---@class OarcStoreItem
---@field cost integer
---@field count integer
---@field play_time_locked boolean
---@alias OarcStoreCategory table<string, OarcStoreItem>
---@alias OarcStoreList table<string, OarcStoreCategory>
---@class OarcCoinGenerationSettings
---@field enabled boolean Enable coin generation when enemies die.
---@field coin_multiplier number If the drop count is x, then between x and x*coin_multiplier coins will be dropped.
---@field coin_generation_table table<string, number> Table of enemy unity types and their coin drop rates.
---@field auto_decon_coins boolean Automatically deconstruct coins when they are dropped.

View File

@ -46,6 +46,8 @@ OCFG_KEYS =
["gameplay.enable_shared_team_chat"] = {mod_key = "oarc-mod-enable-shared-team-chat" , ocfg_keys = {"gameplay", "enable_shared_team_chat"}, type = "boolean"},
["gameplay.enable_shared_power"] = {mod_key = "oarc-mod-enable-shared-power" , ocfg_keys = {"gameplay", "enable_shared_power"}, type = "boolean"},
["gameplay.enable_shared_chest"] = {mod_key = "oarc-mod-enable-shared-chest" , ocfg_keys = {"gameplay", "enable_shared_chest"}, type = "boolean"},
["gameplay.enable_coin_shop"] = {mod_key = "oarc-mod-enable-coin-shop" , ocfg_keys = {"gameplay", "enable_coin_shop"}, type = "boolean"},
["regrowth_HEADER"] = {mod_key = "" , ocfg_keys = {""}, type = "header", text = {"oarc-settings-section-header-regrowth"}},
["regrowth_SUBHEADER"] = {mod_key = "" , ocfg_keys = {""}, type = "subheader", text = {"oarc-settings-section-subheader-regrowth-warning"}},
@ -116,6 +118,7 @@ OCFG_MOD_KEYS =
["oarc-mod-respawn-cooldown-min"] = "gameplay.respawn_cooldown_min",
["oarc-mod-enable-shared-power"] = "gameplay.enable_shared_power",
["oarc-mod-enable-shared-chest"] = "gameplay.enable_shared_chest",
["oarc-mod-enable-coin-shop"] = "gameplay.enable_coin_shop",
["oarc-mod-enable-regrowth"] = "regrowth.enable_regrowth",
["oarc-mod-enable-world-eater"] = "regrowth.enable_world_eater",
@ -228,6 +231,11 @@ function ValidateSettings()
SendBroadcastMsg("ERROR - Missing surfaces_blacklist_match section in config! Loading defaults instead!")
global.ocfg.surfaces_blacklist_match = table.deepcopy(OCFG.surfaces_blacklist_match)
end
if (global.ocfg["shop_items"] == nil) then
log("ERROR - Missing shop_items section in config! Loading defaults instead!")
SendBroadcastMsg("ERROR - Missing shop_items section in config! Loading defaults instead!")
global.ocfg.shop_items = table.deepcopy(OCFG.shop_items)
end
-- Validate enable_main_team and enable_separate_teams.

141
lib/gui_tabs/item_shop.lua Normal file
View File

@ -0,0 +1,141 @@
-- Adding microtransactions.
---This function creates the player shop tab in the custom GUI.
---@param tab_container LuaGuiElement
---@param player LuaPlayer
---@return nil
function CreateItemShopTab(tab_container, player)
local player_inv = player.get_main_inventory()
if (player_inv == nil) then return end
local wallet = player_inv.get_item_count("coin")
AddLabel(tab_container,
"player_store_wallet_lbl",
"Coins Available: " .. wallet .. " [item=coin]",
{top_margin=5, bottom_margin=5})
AddLabel(tab_container, "coin_info", "Players start with some coins. Earn more coins by killing enemies.", my_note_style)
AddLabel(tab_container, nil, "Locked items become available after playing for awhile...", my_note_style)
if (player.admin) then
AddLabel(tab_container, nil, "Currently, the item list can only be edited via custom scenario or by directly setting the global.ocfg.shop_items table.", my_note_style)
end
local line = tab_container.add{type="line", direction="horizontal"}
line.style.top_margin = 5
line.style.bottom_margin = 5
for category,section in pairs(global.ocfg.shop_items) do
local flow = tab_container.add{name = category, type="flow", direction="horizontal"}
for item_name,item in pairs(section) do
-- Validate if item exists
if (not game.item_prototypes[item_name]) then
log("ERROR: Item not found in global.ocfg.shop_items: " .. item_name)
goto continue
end
local color = "[color=green]"
if (item.cost > wallet) then
color = "[color=red]"
end
local btn = flow.add{
name=item_name,
type="sprite-button",
number=item.count,
sprite="item/"..item_name,
tooltip=item_name .. " Cost: "..color..item.cost.."[/color] [item=coin]",
-- style=mod_gui.button_style,
style="slot_button",
tags = {
action = "store_item",
item = item_name,
cost = item.cost,
category = category
}
}
if (item.play_time_locked and (player.online_time < TICKS_PER_MINUTE*15)) then
btn.enabled = false
end
::continue::
end
local line2 = tab_container.add{type="line", direction="horizontal"}
line2.style.top_margin = 5
line2.style.bottom_margin = 5
end
end
---Handles the player clicking on an item in the store.
---@param event EventData.on_gui_click
---@return nil
function OarcItemShopGuiClick(event)
if not event.element.valid then return end
local button = event.element
local player = game.players[event.player_index]
if (button.tags.action == "store_item") then
local item_name = button.tags.item
local item_cost = button.tags.cost
local category = button.tags.category
local item = global.ocfg.shop_items[category][button.name]
local player_inv = player.get_inventory(defines.inventory.character_main)
if (player_inv == nil) then return end
if (player_inv.get_item_count("coin") >= item.cost) then
player_inv.insert({name = button.name, count = item.count})
player_inv.remove({name = "coin", count = item.cost})
if (button.parent and button.parent.parent and button.parent.parent.player_store_wallet_lbl) then
local wallet = player_inv.get_item_count("coin")
button.parent.parent.player_store_wallet_lbl.caption = "Coins Available: " .. wallet .. " [item=coin]"
end
else
player.print("You're broke! Go kill some enemies or beg for change...")
end
end
end
---Handles the event when an entity dies.
---@param event EventData.on_post_entity_died
---@return nil
function CoinsFromEnemiesOnPostEntityDied(event)
local coin_generation_entry = global.ocfg.coin_generation.coin_generation_table[event.prototype.name]
if (coin_generation_entry) then
DropCoins(event.surface_index, event.position, coin_generation_entry, event.force)
end
end
-- Drop coins, force is optional, decon is applied if force is not nil.
---@param surface_index integer
---@param pos MapPosition
---@param count number
---@param force LuaForce
function DropCoins(surface_index, pos, count, force)
local drop_amount = 0
-- If count is less than 1, it represents a probability to drop a single coin
if (count < 1) then
if (math.random() < count) then
drop_amount = 1
end
-- If count is 1 or more, it represents a probability to drop at least that amount and up to multiplier times
-- that amount.
elseif (count >= 1) then
drop_amount = math.random(count,count * global.ocfg.coin_generation.coin_multiplier)
end
if drop_amount == 0 then return end
if global.ocfg.coin_generation.auto_decon_coins then
game.surfaces[surface_index].spill_item_stack(pos, {name="coin", count=math.floor(drop_amount)}, true, force, false)
else
game.surfaces[surface_index].spill_item_stack(pos, {name="coin", count=math.floor(drop_amount)}, true, nil, false)
end
end

View File

@ -164,6 +164,11 @@ function SettingsControlsTabGuiClick(event)
local entry = OCFG_KEYS[index]
if (entry.type == "boolean") then
settings.global[entry.mod_key] = { value = gui_elem.state }
--Exception for coin shop, update the GUI if the setting is changed
if (entry.mod_key == "oarc-mod-enable-coin-shop") then
AddRemoveOarcGuiTabForAllPlayers(OARC_ITEM_SHOP_TAB_NAME, gui_elem.state, true)
end
end
end

View File

@ -7,6 +7,7 @@ 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")
require("lib/gui_tabs/item_shop")
--------------------------------------------------------------------------------
-- GUI Tab Handler
@ -15,28 +16,44 @@ require("lib/gui_tabs/surface_config")
-- NAME of the top level element (outer frame)
OARC_GUI = "oarc_gui"
-- LIST of all implemented tabs and their content Functions
-- All tabs and their content Functions
OARC_SERVER_INFO_TAB_NAME = "server_info"
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_ITEM_SHOP_TAB_NAME = "item_shop"
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_SURFACE_CONFIG_TAB_NAME] = CreateSurfaceConfigTab,
local OARC_GUI_TAB_CONTENT = {
[OARC_SERVER_INFO_TAB_NAME] = {
create_tab_function = CreateServerInfoTab,
localized_name = {"oarc-server-info-tab-title"}
},
[OARC_SPAWN_CTRL_TAB_NAME] = {
create_tab_function = CreateSpawnControlsTab,
localized_name = {"oarc-spawn-ctrls-tab-title"}
},
[OARC_MOD_INFO_CTRL_TAB_NAME] = {
create_tab_function = CreateModInfoTab,
localized_name = {"oarc-mod-info-tab-title"}
},
[OARC_CONFIG_CTRL_TAB_NAME] = {
create_tab_function = CreateSettingsControlsTab,
localized_name = {"oarc-settings-tab-title"}
},
[OARC_MOD_PLAYER_LIST_TAB_NAME] = {
create_tab_function = CreatePlayerListTab,
localized_name = {"oarc-player-list-tab-title"}
},
[OARC_SURFACE_CONFIG_TAB_NAME] = {
create_tab_function = CreateSurfaceConfigTab,
localized_name = {"oarc-surface-config-tab-title"}
},
[OARC_ITEM_SHOP_TAB_NAME] = {
create_tab_function = CreateItemShopTab,
localized_name = {"oarc-item-shop-tab-title"}
}
}
---@param player LuaPlayer
@ -51,27 +68,33 @@ function InitOarcGuiTabs(player)
CreateOarcGuiButton(player)
-- Add general info tab
AddOarcGuiTab(player, OARC_SERVER_INFO_TAB_NAME, OARC_SERVER_INFO_TAB_LOCALIZED)
AddOarcGuiTab(player, OARC_SERVER_INFO_TAB_NAME)
SetOarcGuiTabEnabled(player, OARC_SERVER_INFO_TAB_NAME, true)
-- Spawn control tab, disabled by default
AddOarcGuiTab(player, OARC_SPAWN_CTRL_TAB_NAME, OARC_SPAWN_CTRL_TAB_LOCALIZED)
AddOarcGuiTab(player, OARC_SPAWN_CTRL_TAB_NAME)
-- Regrowth control tab
AddOarcGuiTab(player, OARC_MOD_INFO_CTRL_TAB_NAME, OARC_MOD_INFO_CTRL_TAB_LOCALIZED)
AddOarcGuiTab(player, OARC_MOD_INFO_CTRL_TAB_NAME)
SetOarcGuiTabEnabled(player, OARC_MOD_INFO_CTRL_TAB_NAME, true)
-- Settings control tab
AddOarcGuiTab(player, OARC_CONFIG_CTRL_TAB_NAME, OARC_CONFIG_CTRL_TAB_LOCALIZED)
AddOarcGuiTab(player, OARC_CONFIG_CTRL_TAB_NAME)
SetOarcGuiTabEnabled(player, OARC_CONFIG_CTRL_TAB_NAME, true)
-- Player list tab
AddOarcGuiTab(player, OARC_MOD_PLAYER_LIST_TAB_NAME, OARC_PLAYER_LIST_TAB_LOCALIZED)
AddOarcGuiTab(player, OARC_MOD_PLAYER_LIST_TAB_NAME)
SetOarcGuiTabEnabled(player, OARC_MOD_PLAYER_LIST_TAB_NAME, true)
-- Item shop tab
if (global.ocfg.gameplay.enable_coin_shop) then
AddOarcGuiTab(player, OARC_ITEM_SHOP_TAB_NAME)
SetOarcGuiTabEnabled(player, OARC_ITEM_SHOP_TAB_NAME, true)
end
-- Surface config tab
if (player.admin) then
AddOarcGuiTab(player, OARC_SURFACE_CONFIG_TAB_NAME, OARC_SURFACE_CONFIG_TAB_LOCALIZED)
AddOarcGuiTab(player, OARC_SURFACE_CONFIG_TAB_NAME)
SetOarcGuiTabEnabled(player, OARC_SURFACE_CONFIG_TAB_NAME, true)
end
@ -177,7 +200,7 @@ function OarcGuiCreateContentOfTab(player)
for _,t in ipairs(otabs.tabs) do
t.content.clear()
if (t.tab.name == tab_name) then
OARC_GUI_TAB_CONTENT_FUNCTIONS[tab_name](t.content, player)
OARC_GUI_TAB_CONTENT[tab_name].create_tab_function(t.content, player)
end
end
end
@ -232,8 +255,7 @@ end
-- It adds whatever it wants to the provided scroll-pane.
---@param player LuaPlayer
---@param tab_name string
---@param localized_name LocalisedString
function AddOarcGuiTab(player, tab_name, localized_name)
function AddOarcGuiTab(player, tab_name)
if (not DoesOarcGuiExist(player)) then
CreateOarcGuiTabsPane(player)
end
@ -247,7 +269,7 @@ function AddOarcGuiTab(player, tab_name, localized_name)
local new_tab = otabs.add{
type="tab",
name=tab_name,
caption=localized_name}
caption=OARC_GUI_TAB_CONTENT[tab_name].localized_name,}
-- Create inside frame for content
local tab_inside_frame = otabs.add{
@ -277,6 +299,54 @@ function AddOarcGuiTab(player, tab_name, localized_name)
end
end
-- https://forums.factorio.com/viewtopic.php?f=7&t=115901
-- ---Removes a tab from the GUI.
-- ---@param player LuaPlayer
-- ---@param tab_name string
-- function RemoveOarcGuiTab(player, tab_name)
-- if (not DoesOarcGuiExist(player)) then return end
-- local otabs = GetOarcGuiTabsPane(player)
-- local selected_tab_name = otabs.tabs[otabs.selected_tab_index].tab.name
-- for _,t in ipairs(otabs.tabs) do
-- if (t.tab.name == tab_name) then
-- local tab = t.tab
-- local content = t.content
-- otabs.remove_tab(t.tab)
-- tab.destroy()
-- content.destroy()
-- --TODO: I haven't figured out how to do this nicely, but removing tabs fucks up the tab view.
-- -- So for now, we just recreate the GUI.
-- OarcGuiCreateContentOfTab(player)
-- return
-- end
-- end
-- end
---Check if tab exists in the GUI.
---@param player LuaPlayer
---@param tab_name string
---@return boolean
function DoesOarcGuiTabExist(player, tab_name)
if (not DoesOarcGuiExist(player)) then return false end
local otabs = GetOarcGuiTabsPane(player)
for _,t in ipairs(otabs.tabs) do
if (t.tab.name == tab_name) then
return true
end
end
return false
end
---This sets the enable state of a tab.
---@param player LuaPlayer
---@param tab_name string
@ -326,6 +396,23 @@ function RecreateOarcGui(player)
InitOarcGuiTabs(player)
end
---Add or remove a tab for all players.
---@param tab_name string
---@param add boolean If true, add the tab. If false, remove the tab.
---@param enable boolean If true, enables the tab. If false, disable the tab. Only used if adding the tab.
---@return nil
function AddRemoveOarcGuiTabForAllPlayers(tab_name, add, enable)
for _,player in pairs(game.players) do
if (add and not DoesOarcGuiTabExist(player, tab_name)) then
AddOarcGuiTab(player, tab_name)
SetOarcGuiTabEnabled(player, tab_name, true)
elseif (not add and DoesOarcGuiTabExist(player, tab_name)) then
-- RemoveOarcGuiTab(player, tab_name) -- SEE https://forums.factorio.com/viewtopic.php?f=7&t=115901
RecreateOarcGui(player) -- Assumes a ocfg setting change, so just recreate the whole thing.
end
end
end
--[[
_____ _____ _ _ _____ _ _ _ _ _ ___ _ ___ ___ ___
| __\ \ / / __| \| |_ _| | || | /_\ | \| | \| | | __| _ \/ __|
@ -362,6 +449,7 @@ function OarcGuiTabsClick(event)
SettingsSurfaceControlsTabGuiClick(event)
PlayerListTabGuiClick(event)
SurfaceConfigTabGuiClick(event)
OarcItemShopGuiClick(event)
end
---All gui tabs on_gui_checked_state_changed event handler

View File

@ -38,6 +38,7 @@ oarc-mod-minimum-online-time=Minimum online time
oarc-mod-respawn-cooldown-min=Reset respawn point cooldown
oarc-mod-enable-shared-power=Shared power
oarc-mod-enable-shared-chest=Shared chest
oarc-mod-enable-coin-shop=Enable coin shop
oarc-mod-enable-regrowth=Regrowth (map cleanup)
oarc-mod-enable-world-eater=World eater (map cleanup - additional)
@ -98,6 +99,7 @@ oarc-mod-minimum-online-time=The minimum time a player must be online before the
oarc-mod-respawn-cooldown-min=The minimum time a player must wait before they can change their spawn point to a new location.
oarc-mod-enable-shared-power=This allows players to share their power network with other players. It will create a special power pole at their spawn point that connects to the shared power network wirelessly.
oarc-mod-enable-shared-chest=This gives players a special chest they can use to share items with other players. It uses the "linked-chest" item that is a hidden feature in factorio.
oarc-mod-enable-coin-shop=This enables a coin shop where players can buy items with coins they earn from killing biters.
oarc-mod-enable-regrowth=Enables regrowth. This slowly removes inactive chunks over time. Any chunk with player structures will not be removed. This helps to keep the map (and file size) smaller over time.
oarc-mod-enable-world-eater=Enables world eater. This requires regrowth. This slowly checks all chunks for a lack of player structures and entities and marks them for removal. This helps to keep the map (and file size) smaller over time. This is more of an experimental feature, use at your own risk.

View File

@ -183,6 +183,7 @@ 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-item-shop-tab-title=[item=coin]Shop
oarc-server-info-tab-welcome-msg-title=Welcome Message
oarc-server-info-tab-discord-invite=Discord Invite:

View File

@ -0,0 +1,13 @@
-- Add new coin shop settings and config.
if global.ocfg.gameplay.enable_coin_shop == nil then
global.ocfg.gameplay.enable_coin_shop = false -- Default to off
end
if global.ocfg.shop_items == nil then
global.ocfg.shop_items = table.deepcopy(OARC_SHOP_ITEMS)
end
if global.ocfg.coin_generation == nil then
global.ocfg.coin_generation = table.deepcopy(OCFG.coin_generation)
end

View File

@ -237,6 +237,13 @@ data:extend({
default_value = false,
order = "f11"
},
{
type = "bool-setting",
name = "oarc-mod-enable-coin-shop",
setting_type = "runtime-global",
default_value = false,
order = "f12"
},
{