From e9ab1e55599e1db3b758f3146fe067b43d108937 Mon Sep 17 00:00:00 2001 From: Bilka Date: Tue, 28 May 2019 22:28:04 +0200 Subject: [PATCH] Split map settings GUI into separate file --- README.md | 4 - changelog.txt | 5 + control.lua | 192 +++++++--------------------- gui.lua | 131 +------------------ info.json | 2 +- locale/en/en.cfg | 2 +- map_gen_settings_gui.lua | 55 ++++---- map_settings_gui.lua | 268 +++++++++++++++++++++++++++++++++++++++ utilities.lua | 20 ++- 9 files changed, 361 insertions(+), 318 deletions(-) create mode 100644 map_settings_gui.lua diff --git a/README.md b/README.md index 85df5bf..bf536c1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ # ChangeMapSettings Allows you to change your map and map generation settings at any time you want. Note that map generation changes only apply to new chunks. - -NOTE: -The 0.17 version of this mod is missing configuration options because those are missing from the lua api. Furthermore, frequency of water, trees and cliffs is inverted compared to the base game map generation screen. This is also an issue with the lua api. -The mod will remain in this state until the lua api is changed to properly expose everything. diff --git a/changelog.txt b/changelog.txt index 2c1deee..8c4c4a6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 3.1.2 +Date: 28. 05. 2019 + Changes: + - Split map settings GUI into separate file. +--------------------------------------------------------------------------------------------------- Version: 3.1.1 Date: 24. 05. 2019 Bugfixes: diff --git a/control.lua b/control.lua index 24158ca..f245c6d 100644 --- a/control.lua +++ b/control.lua @@ -2,6 +2,7 @@ local mod_gui = require("mod-gui") local gui = require("gui") local util = require("utilities") local map_gen_gui = require("map_gen_settings_gui") +local map_settings_gui = require("map_settings_gui") local function reset_to_default(player) local frame_flow = mod_gui.get_frame_flow(player) @@ -9,30 +10,11 @@ local function reset_to_default(player) --General local general_table = config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] general_table["change-map-settings-peaceful-checkbox"].state = false + -- MAP SETTINGS -- - --Evolution - local evo_table = config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] - evo_table["change-map-settings-evolution-checkbox"].state = true - evo_table["change-map-settings-evolution-factor-textfield"].text = "0" - evo_table["change-map-settings-evolution-time-textfield"].text = "0.0004" - evo_table["change-map-settings-evolution-destroy-textfield"].text = "0.2" - evo_table["change-map-settings-evolution-pollution-textfield"].text = "0.000090" - --Pollution - local pollution_table = config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] - pollution_table["change-map-settings-pollution-checkbox"].state = true - pollution_table["change-map-settings-pollution-dissipation-textfield"].text = "1" - pollution_table["change-map-settings-enemy-attack-pollution-consumption-textfield"].text = "1" - pollution_table["change-map-settings-pollution-tree-dmg-textfield"].text = "60" - pollution_table["change-map-settings-pollution-tree-absorb-textfield"].text = "10" - pollution_table["change-map-settings-pollution-diffusion-textfield"].text = "2" - --Enemy expansion - local expansion_table = config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] - expansion_table["change-map-settings-enemy-expansion-checkbox"].state = true - expansion_table["change-map-settings-expansion-distance-textfield"].text = "7" - expansion_table["change-map-settings-expansion-min-size-textfield"].text = "5" - expansion_table["change-map-settings-expansion-max-size-textfield"].text = "20" - expansion_table["change-map-settings-expansion-min-cd-textfield"].text = "4" - expansion_table["change-map-settings-expansion-max-cd-textfield"].text = "60" + map_settings_gui.expansion_reset_to_defaults(config_table) + map_settings_gui.evolution_reset_to_defaults(config_table) + map_settings_gui.pollution_reset_to_defaults(config_table) end local function set_to_current_map_gen_settings(player) @@ -45,7 +27,6 @@ local function set_to_current_map_gen_settings(player) --the rest map_gen_gui.set_to_current(map_gen_frame["change-map-settings-map-gen-flow-2"], map_gen_settings) - end local function set_to_current_map_settings(player) @@ -54,31 +35,12 @@ local function set_to_current_map_settings(player) --General local general_table = config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] general_table["change-map-settings-peaceful-checkbox"].state = player.surface.peaceful_mode + -- MAP SETTINGS -- local map_settings = game.map_settings - --Evolution - local evo_table = config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] - evo_table["change-map-settings-evolution-checkbox"].state = map_settings.enemy_evolution.enabled - evo_table["change-map-settings-evolution-factor-textfield"].text = util.number_to_string(game.forces["enemy"].evolution_factor) - evo_table["change-map-settings-evolution-time-textfield"].text = util.number_to_string(map_settings.enemy_evolution.time_factor * 100) - evo_table["change-map-settings-evolution-destroy-textfield"].text = util.number_to_string(map_settings.enemy_evolution.destroy_factor * 100) - evo_table["change-map-settings-evolution-pollution-textfield"].text = util.number_to_string(map_settings.enemy_evolution.pollution_factor * 100) - --Pollution - local pollution_table = config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] - pollution_table["change-map-settings-pollution-checkbox"].state = map_settings.pollution.enabled - pollution_table["change-map-settings-pollution-dissipation-textfield"].text = tostring(map_settings.pollution.ageing) - pollution_table["change-map-settings-enemy-attack-pollution-consumption-textfield"].text = tostring(map_settings.pollution.enemy_attack_pollution_consumption_modifier) - pollution_table["change-map-settings-pollution-tree-dmg-textfield"].text = tostring(map_settings.pollution.min_pollution_to_damage_trees) - pollution_table["change-map-settings-pollution-tree-absorb-textfield"].text = tostring(map_settings.pollution.pollution_restored_per_tree_damage) - pollution_table["change-map-settings-pollution-diffusion-textfield"].text = tostring(map_settings.pollution.diffusion_ratio * 100) - --Enemy expansion - local expansion_table = config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] - expansion_table["change-map-settings-enemy-expansion-checkbox"].state = map_settings.enemy_expansion.enabled - expansion_table["change-map-settings-expansion-distance-textfield"].text = tostring(map_settings.enemy_expansion.max_expansion_distance) - expansion_table["change-map-settings-expansion-min-size-textfield"].text = tostring(map_settings.enemy_expansion.settler_group_min_size) - expansion_table["change-map-settings-expansion-max-size-textfield"].text = tostring(map_settings.enemy_expansion.settler_group_max_size) - expansion_table["change-map-settings-expansion-min-cd-textfield"].text = tostring(map_settings.enemy_expansion.min_expansion_cooldown / 3600) - expansion_table["change-map-settings-expansion-max-cd-textfield"].text = tostring(map_settings.enemy_expansion.max_expansion_cooldown / 3600) + map_settings_gui.expansion_set_to_current(config_table, map_settings) + map_settings_gui.evolution_set_to_current(config_table, map_settings) + map_settings_gui.pollution_set_to_current(config_table, map_settings) end local function set_to_current_all(player) @@ -93,102 +55,47 @@ local function change_map_settings(player) -- Reading everything out local general_table = config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] local peaceful_mode = general_table["change-map-settings-peaceful-checkbox"].state - local map_settings = game.map_settings - -- Evolution - local evo_table = config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] - local evolution_enabled = evo_table["change-map-settings-evolution-checkbox"].state - local evolution_factor = util.check_bounds(util.textfield_to_number(evo_table["change-map-settings-evolution-factor-textfield"]), - 0, 1, - player, {"msg.change-map-settings-invalid-evolution-factor"}) - if not evolution_factor then return end - local evolution_time = util.check_bounds(util.textfield_to_number(evo_table["change-map-settings-evolution-time-textfield"]), - 0, 0.01, - player, {"msg.change-map-settings-invalid-evolution-time"}) - if not evolution_time then return end - local evolution_destroy = util.check_bounds(util.textfield_to_number(evo_table["change-map-settings-evolution-destroy-textfield"]), - 0, 1, - player, {"msg.change-map-settings-invalid-evolution-destroy"}) - if not evolution_destroy then return end - local evolution_pollution = util.check_bounds(util.textfield_to_number(evo_table["change-map-settings-evolution-pollution-textfield"]), - 0, 0.01, - player, {"msg.change-map-settings-invalid-evolution-pollution"}) - if not evolution_pollution then return end - -- Pollution - local pollution_table = config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] - local pollution_enabled = pollution_table["change-map-settings-pollution-checkbox"].state - local pollution_dissipation = util.check_bounds(util.textfield_to_number(pollution_table["change-map-settings-pollution-dissipation-textfield"]), - 0.1, 4, - player, {"msg.change-map-settings-invalid-pollution-absorption"}) - if not pollution_dissipation then return end - local enemy_attack_pollution_consumption = util.check_bounds(util.textfield_to_number(pollution_table["change-map-settings-enemy-attack-pollution-consumption-textfield"]), - 0.1, 4, - player, {"msg.change-map-settings-invalid-enemy-attack-pollution-consumption"}) - if not enemy_attack_pollution_consumption then return end - local pollution_tree_dmg = util.check_bounds(util.textfield_to_uint(pollution_table["change-map-settings-pollution-tree-dmg-textfield"]), - 0, 9999, - player, {"msg.change-map-settings-invalid-pollution-tree-dmg"}) - if not pollution_tree_dmg then return end - local pollution_tree_absorb = util.check_bounds(util.textfield_to_uint(pollution_table["change-map-settings-pollution-tree-absorb-textfield"]), - 0, 9999, - player, {"msg.change-map-settings-invalid-pollution-tree-absorb"}) - if not pollution_tree_absorb then return end - local pollution_diffusion = util.check_bounds(util.textfield_to_uint(pollution_table["change-map-settings-pollution-diffusion-textfield"]), - 0, 25, - player, {"msg.change-map-settings-invalid-pollution-diffusion"}) - if not pollution_diffusion then return end - -- Enemy expansion - local expansion_table = config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] - local expansion_enabled = expansion_table["change-map-settings-enemy-expansion-checkbox"].state - local expansion_distance = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-distance-textfield"]), - 2, 20, - player, {"msg.change-map-settings-invalid-expansion-distance"}) - if not expansion_distance then return end - local expansion_min_size = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-min-size-textfield"]), - 1, 20, - player, {"msg.change-map-settings-invalid-expansion-min-size"}) - if not expansion_min_size then return end - local expansion_max_size = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-max-size-textfield"]), - math.max(expansion_min_size, 1), 50, - player, {"msg.change-map-settings-invalid-expansion-max-size"}) - if not expansion_max_size then return end - local expansion_min_cd = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-min-cd-textfield"]), - 1, 60, - player, {"msg.change-map-settings-invalid-expansion-min-cd"}) - if not expansion_min_cd then return end - local expansion_max_cd = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-max-cd-textfield"]), - math.max(expansion_min_cd, 5), 180, - player, {"msg.change-map-settings-invalid-expansion-max-cd"}) - if not expansion_max_cd then return end + + local status, enemy_expansion = pcall(map_settings_gui.expansion_read, config_table) + if not status then + player.print(enemy_expansion) + player.print({"msg.change-map-settings-apply-failed"}) + return + end + local status2, enemy_evolution = pcall(map_settings_gui.evolution_read, config_table) + if not status2 then + player.print(enemy_evolution) + player.print({"msg.change-map-settings-apply-failed"}) + return + end + local status3, pollution = pcall(map_settings_gui.pollution_read, config_table) + if not status3 then + player.print(pollution) + player.print({"msg.change-map-settings-apply-failed"}) + return + end -- And now to apply it all for _, surface in pairs(game.surfaces) do surface.peaceful_mode = peaceful_mode end - map_settings.enemy_evolution.enabled = evolution_enabled - game.forces["enemy"].evolution_factor = evolution_factor - map_settings.enemy_evolution.time_factor = (evolution_time / 100) - map_settings.enemy_evolution.destroy_factor = (evolution_destroy / 100) - map_settings.enemy_evolution.pollution_factor = (evolution_pollution / 100) - - if (pollution_enabled ~= map_settings.pollution.enabled) and (pollution_enabled == false) then + local map_settings = game.map_settings + if (pollution.enabled ~= map_settings.pollution.enabled) and (pollution.enabled == false) then for _, surface in pairs(game.surfaces) do surface.clear_pollution() end end - map_settings.pollution.enabled = pollution_enabled - map_settings.pollution.ageing = pollution_dissipation - map_settings.pollution.enemy_attack_pollution_consumption_modifier = enemy_attack_pollution_consumption - map_settings.pollution.min_pollution_to_damage_trees = pollution_tree_dmg - map_settings.pollution.pollution_restored_per_tree_damage = pollution_tree_absorb - map_settings.pollution.diffusion_ratio = (pollution_diffusion / 100) - - map_settings.enemy_expansion.enabled = expansion_enabled - map_settings.enemy_expansion.max_expansion_distance = expansion_distance - map_settings.enemy_expansion.settler_group_min_size = expansion_min_size - map_settings.enemy_expansion.settler_group_max_size = expansion_max_size - map_settings.enemy_expansion.min_expansion_cooldown = (expansion_min_cd * 3600) - map_settings.enemy_expansion.max_expansion_cooldown = (expansion_max_cd * 3600) + for k, v in pairs(pollution) do -- fucking structs + map_settings.pollution[k] = v + end + for k, v in pairs(enemy_expansion) do + map_settings.enemy_expansion[k] = v + end + for k, v in pairs(enemy_evolution) do + map_settings.enemy_evolution[k] = v + end + game.forces["enemy"].evolution_factor = enemy_evolution.evolution_factor player.print({"msg.change-map-settings-applied"}) @@ -217,16 +124,12 @@ local function change_map_gen_settings(player) local map_gen_frame = frame_flow["change-map-settings-main-flow"]["change-map-settings-map-gen-frame"] --all the stuff - local status, retval = pcall(function(map_gen_frame) - return map_gen_gui.read(map_gen_frame["change-map-settings-map-gen-flow-2"]) - end, map_gen_frame) - + local status, settings = pcall(map_gen_gui.read, map_gen_frame["change-map-settings-map-gen-flow-2"]) if not status then - player.print(retval) + player.print(settings) player.print({"msg.change-map-settings-apply-failed"}) return end - local settings = retval -- fill out missing fields with the current settings settings.peaceful_mode = player.surface.peaceful_mode @@ -248,15 +151,8 @@ local function change_map_gen_settings(player) end --apply - local status, err = pcall(function(player, settings) - player.surface.map_gen_settings = settings - end, player, settings) - - if not status then - player.print({"msg.change-map-settings-apply-failed"}) - else - player.print({"msg.change-map-settings-applied"}) - end + player.surface.map_gen_settings = settings + player.print({"msg.change-map-settings-applied"}) -- Update the values shown in everyones gui for _, plyr in pairs(game.players) do diff --git a/gui.lua b/gui.lua index eb43ec0..852fd13 100644 --- a/gui.lua +++ b/gui.lua @@ -1,10 +1,11 @@ local mod_gui = require("mod-gui") local util = require("utilities") local map_gen_gui = require("map_gen_settings_gui") +local map_settings_gui = require("map_settings_gui") local gui = {} -- GUI -- -function gui.regen(player) +gui.regen = function(player) gui.kill(player) --toggle button local button_flow = mod_gui.get_button_flow(player) @@ -150,119 +151,12 @@ gui.make_advanced_settings = function(parent, surface) local map_settings = game.map_settings --make different advanced option groups - gui.make_pollution_settings(config_table, map_settings) - gui.make_expansion_settings(config_table, map_settings) - gui.make_evolution_settings(config_table, map_settings) + map_settings_gui.make_pollution_settings(config_table, map_settings) + map_settings_gui.make_expansion_settings(config_table, map_settings) + map_settings_gui.make_evolution_settings(config_table, map_settings) gui.make_general_settings(config_table, surface) end -gui.make_pollution_settings = function(parent, map_settings) - local config_more_option_pollution_flow = parent.add{ - type = "flow", - name = "change-map-settings-config-more-pollution-flow", - direction = "vertical" - } - config_more_option_pollution_flow.add{ - type = "label", - caption = {"gui-map-generator.pollution"}, - style = "caption_label" - } - local config_more_option_pollution_table = config_more_option_pollution_flow.add{ - type = "table", - name = "change-map-settings-config-more-pollution-table", - column_count = 2, - style = "bordered_table" - } - config_more_option_pollution_table.style.column_alignments[2] = "center" - - config_more_option_pollution_table.add{ - type = "label", - caption = {"gui-map-generator.pollution"} - } - config_more_option_pollution_table.add{ - type = "checkbox", - name = "change-map-settings-pollution-checkbox", - state = map_settings.pollution.enabled, - } - config_more_option_pollution_table.children[1].style.horizontally_stretchable = true - gui.make_config_option(config_more_option_pollution_table, "pollution-dissipation", {"gui-map-generator.pollution-absorption-modifier"}, {"gui-map-generator.pollution-absorption-modifier-description"}, tostring(map_settings.pollution.ageing), 50) - gui.make_config_option(config_more_option_pollution_table, "enemy-attack-pollution-consumption", {"gui-map-generator.enemy-attack-pollution-consumption-modifier"}, {"gui-map-generator.enemy-attack-pollution-consumption-modifier-description"}, tostring(map_settings.pollution.enemy_attack_pollution_consumption_modifier), 50) - gui.make_config_option(config_more_option_pollution_table, "pollution-tree-dmg", {"gui-map-generator.minimum-pollution-to-damage-trees"}, {"gui-map-generator.minimum-pollution-to-damage-trees-description"}, tostring(map_settings.pollution.min_pollution_to_damage_trees), 50) - gui.make_config_option(config_more_option_pollution_table, "pollution-tree-absorb", {"gui-map-generator.pollution-absorbed-per-tree-damaged"}, {"gui-map-generator.pollution-absorbed-per-tree-damaged-description"}, tostring(map_settings.pollution.pollution_restored_per_tree_damage), 50) - gui.make_config_option(config_more_option_pollution_table, "pollution-diffusion", {"gui.change-map-settings-in-unit", {"gui-map-generator.pollution-diffusion-ratio"}, {"gui.change-map-settings-percent"}}, {"gui-map-generator.pollution-diffusion-ratio-description"}, tostring(map_settings.pollution.diffusion_ratio * 100), 50) -end - -gui.make_evolution_settings = function(parent, map_settings) - local config_more_option_evo_flow = parent.add{ - type = "flow", - name = "change-map-settings-config-more-evo-flow", - direction = "vertical" - } - config_more_option_evo_flow.add{ - type = "label", - caption = {"gui-map-generator.evolution"}, - style = "caption_label" - } - local config_more_option_evo_table = config_more_option_evo_flow.add{ - type = "table", - name = "change-map-settings-config-more-evo-table", - column_count = 2, - style = "bordered_table" - } - config_more_option_evo_table.style.column_alignments[2] = "center" - - config_more_option_evo_table.add{ - type = "label", - caption = {"gui-map-generator.evolution"} - } - config_more_option_evo_table.add{ - type = "checkbox", - name = "change-map-settings-evolution-checkbox", - state = map_settings.enemy_evolution.enabled, - } - config_more_option_evo_table.children[1].style.horizontally_stretchable = true - gui.make_config_option(config_more_option_evo_table, "evolution-factor", {"gui-map-generator.evolution"}, {"gui.change-map-settings-evolution-factor-tooltip"}, util.number_to_string(game.forces["enemy"].evolution_factor), 80) - gui.make_config_option(config_more_option_evo_table, "evolution-time", {"gui-map-generator.evolution-time-factor"}, {"gui-map-generator.evolution-time-factor-description"}, util.number_to_string(map_settings.enemy_evolution.time_factor * 100), 80) - gui.make_config_option(config_more_option_evo_table, "evolution-destroy", {"gui-map-generator.evolution-destroy-factor"}, {"gui-map-generator.evolution-destroy-factor-description"}, util.number_to_string(map_settings.enemy_evolution.destroy_factor * 100), 80) - gui.make_config_option(config_more_option_evo_table, "evolution-pollution", {"gui-map-generator.evolution-pollution-factor"}, {"gui-map-generator.evolution-pollution-factor-description"}, util.number_to_string(map_settings.enemy_evolution.pollution_factor * 100), 80) -end - -gui.make_expansion_settings = function(parent, map_settings) - local config_more_option_expansion_flow = parent.add{ - type = "flow", - name = "change-map-settings-config-more-expansion-flow", - direction = "vertical" - } - config_more_option_expansion_flow.add{ - type = "label", - caption = {"gui-map-generator.enemy-expansion-group-tile"}, - style = "caption_label" - } - local config_more_option_expansion_table = config_more_option_expansion_flow.add{ - type = "table", - name = "change-map-settings-config-more-expansion-table", - column_count = 2, - style = "bordered_table" - } - config_more_option_expansion_table.style.column_alignments[2] = "center" - - config_more_option_expansion_table.add{ - type = "label", - caption = {"gui-map-generator.enemy-expansion-group-tile"} - } - config_more_option_expansion_table.add{ - type = "checkbox", - name = "change-map-settings-enemy-expansion-checkbox", - state = map_settings.enemy_expansion.enabled, - } - config_more_option_expansion_table.children[1].style.horizontally_stretchable = true - gui.make_config_option(config_more_option_expansion_table, "expansion-distance", {"gui-map-generator.enemy-expansion-maximum-expansion-distance"}, {"gui-map-generator.enemy-expansion-maximum-expansion-distance-description"}, tostring(map_settings.enemy_expansion.max_expansion_distance), 30) - gui.make_config_option(config_more_option_expansion_table, "expansion-min-size", {"gui-map-generator.enemy-expansion-minimum-expansion-group-size"}, {"gui-map-generator.enemy-expansion-minimum-expansion-group-size-description"}, tostring(map_settings.enemy_expansion.settler_group_min_size), 30) - gui.make_config_option(config_more_option_expansion_table, "expansion-max-size", {"gui-map-generator.enemy-expansion-maximum-expansion-group-size"}, {"gui-map-generator.enemy-expansion-maximum-expansion-group-size-description"}, tostring(map_settings.enemy_expansion.settler_group_max_size), 30) - gui.make_config_option(config_more_option_expansion_table, "expansion-min-cd", {"gui.change-map-settings-in-unit", {"gui-map-generator.enemy-expansion-minimum-expansion-cooldown"}, {"gui.change-map-settings-minutes"}}, {"gui-map-generator.enemy-expansion-minimum-expansion-cooldown-description"}, tostring(map_settings.enemy_expansion.min_expansion_cooldown / 3600), 30) - gui.make_config_option(config_more_option_expansion_table, "expansion-max-cd", {"gui.change-map-settings-in-unit", {"gui-map-generator.enemy-expansion-maximum-expansion-cooldown"}, {"gui.change-map-settings-minutes"}}, {"gui-map-generator.enemy-expansion-maximum-expansion-cooldown-description"}, tostring(map_settings.enemy_expansion.max_expansion_cooldown / 3600), 30) -end - gui.make_general_settings = function(parent, surface) local config_more_option_general_flow = parent.add{ type = "flow", @@ -294,21 +188,6 @@ gui.make_general_settings = function(parent, surface) config_more_option_general_table.children[1].style.horizontally_stretchable = true end -gui.make_config_option = function(parent, name, caption, tooltip, default, max_width) - parent.add{ - type = "label", - caption = caption, - tooltip = tooltip - } - local child = parent.add{ - type = "textfield", - name = "change-map-settings-" .. name .. "-textfield", - } - child.text = default - if max_width then child.style.maximal_width = max_width end - return child -end - gui.kill = function(player) local button_flow = mod_gui.get_button_flow(player) local frame_flow = mod_gui.get_frame_flow(player) diff --git a/info.json b/info.json index 1de5e43..5d246bf 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "ChangeMapSettings", - "version": "3.1.1", + "version": "3.1.2", "factorio_version" : "0.17", "title": "Change Map Settings", "author": "Bilka", diff --git a/locale/en/en.cfg b/locale/en/en.cfg index e6969aa..e9d8772 100644 --- a/locale/en/en.cfg +++ b/locale/en/en.cfg @@ -33,4 +33,4 @@ change-map-settings-invalid-expansion-max-size=Invalid expansion maximum group s change-map-settings-invalid-expansion-min-cd=Invalid expansion minimum cooldown. Possible values: 1 to 60 change-map-settings-invalid-expansion-max-cd=Invalid expansion maximum cooldown. Possible values: 5 to 180. Has to be higher than expansion minimum cooldown. change-map-settings-applied=Applied changes. -change-map-settings-apply-failed=Failed to apply map gen settings. +change-map-settings-apply-failed=Failed to apply changes. diff --git a/map_gen_settings_gui.lua b/map_gen_settings_gui.lua index e0ef66f..d605f22 100644 --- a/map_gen_settings_gui.lua +++ b/map_gen_settings_gui.lua @@ -43,14 +43,14 @@ end map_gen_gui.create_expression_selectors_parent = function(parent) local table = parent.add{ type = "table", - name = ENTIRE_PREFIX .. "-expression-selectors-table", + name = ENTIRE_PREFIX .. "expression-selectors-table", column_count = 1, style = "bordered_table" } table.style.horizontally_stretchable = true local flow = table.add{ type = "flow", - name = ENTIRE_PREFIX .. "-expression-selectors-flow", + name = ENTIRE_PREFIX .. "expression-selectors-flow", direction = "vertical" } flow.style.horizontally_stretchable = true @@ -75,7 +75,7 @@ map_gen_gui.make_expression_selector = function(intended_property, expressions, local flow = parent.add{ type = "flow", - name = ENTIRE_PREFIX .. "-" .. intended_property .. "-flow", + name = ENTIRE_PREFIX .. intended_property .. "-flow", direction = "horizontal" } @@ -92,7 +92,7 @@ map_gen_gui.make_expression_selector = function(intended_property, expressions, local dropdown_data = map_gen_gui.get_expression_dropdown_data(expressions) flow.add{ type = "drop-down", - name = ENTIRE_PREFIX .. "-" .. intended_property .. "-drop-down", + name = ENTIRE_PREFIX .. intended_property .. "-drop-down", items = dropdown_data.items, selected_index = dropdown_data.selected_index } @@ -126,19 +126,19 @@ map_gen_gui.create_resource_table = function(parent) table.add{type = "label"} table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.frequency"}), + caption = util.add_info_icon_to_string({"gui-map-generator.frequency"}), style = "caption_label", tooltip = {"gui-map-generator.resource-frequency-description"} } table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.size"}), + caption = util.add_info_icon_to_string({"gui-map-generator.size"}), style = "caption_label", tooltip = {"gui-map-generator.resource-size-description"} } table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.richness"}), + caption = util.add_info_icon_to_string({"gui-map-generator.richness"}), style = "caption_label", tooltip = {"gui-map-generator.resource-richness-description"} } @@ -162,13 +162,13 @@ map_gen_gui.create_controls_with_scale_table = function(parent) table.add{type = "label"} table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.scale"}), + caption = util.add_info_icon_to_string({"gui-map-generator.scale"}), style = "caption_label", tooltip = {"gui-map-generator.terrain-scale-description"} } table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.coverage"}), + caption = util.add_info_icon_to_string({"gui-map-generator.coverage"}), style = "caption_label", tooltip = {"gui-map-generator.terrain-coverage-description"} } @@ -196,13 +196,13 @@ map_gen_gui.create_cliffs_table = function(parent) table.add{type = "label"} table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.cliff-frequency"}), + caption = util.add_info_icon_to_string({"gui-map-generator.cliff-frequency"}), style = "caption_label", tooltip = {"gui-map-generator.cliff-frequency-description"} } table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.cliff-continuity"}), + caption = util.add_info_icon_to_string({"gui-map-generator.cliff-continuity"}), style = "caption_label", tooltip = {"gui-map-generator.cliff-continuity-description"} } @@ -223,13 +223,13 @@ map_gen_gui.create_climate_table = function(parent) table.add{type = "label"} table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.scale"}), + caption = util.add_info_icon_to_string({"gui-map-generator.scale"}), style = "caption_label", tooltip = {"gui-map-generator.terrain-scale-description"} } table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.bias"}), + caption = util.add_info_icon_to_string({"gui-map-generator.bias"}), style = "caption_label", tooltip = {"gui-map-generator.terrain-bias-description"} } @@ -250,13 +250,13 @@ map_gen_gui.create_enemies_table = function(parent) table.add{type = "label"} table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.frequency"}), + caption = util.add_info_icon_to_string({"gui-map-generator.frequency"}), style = "caption_label", tooltip = {"gui-map-generator.enemy-frequency-description"} } table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.size"}), + caption = util.add_info_icon_to_string({"gui-map-generator.size"}), style = "caption_label", tooltip = {"gui-map-generator.enemy-size-description"} } @@ -272,7 +272,7 @@ map_gen_gui.create_enemies_table = function(parent) -- starting area size table.add{ type = "label", - caption = util.add_info_icon_to_localized_string({"gui-map-generator.starting-area-size"}), + caption = util.add_info_icon_to_string({"gui-map-generator.starting-area-size"}), tooltip = {"gui-map-generator.starting-area-size-description"} } table.add{type = "label"} @@ -298,7 +298,7 @@ map_gen_gui.make_autoplace_options = function(name, parent, has_richness) label.caption = {"", {"gui-map-generator." .. name}, "/", {"gui-map-generator.island-size"}} elseif name == "moisture" or name == "aux" then label.tooltip = {"gui-map-generator." .. name .. "-description"} - label.caption = util.add_info_icon_to_localized_string(label.caption) + label.caption = util.add_info_icon_to_string(label.caption) end end parent.add{ @@ -321,7 +321,7 @@ map_gen_gui.make_autoplace_options = function(name, parent, has_richness) end map_gen_gui.reset_to_defaults = function(parent) - local expression_selectors_flow = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "-expression-selectors-table"][ENTIRE_PREFIX .. "-expression-selectors-flow"] + local expression_selectors_flow = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "expression-selectors-table"][ENTIRE_PREFIX .. "expression-selectors-flow"] local resource_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-1"][ENTIRE_PREFIX .. "resource-scroll-pane"][ENTIRE_PREFIX .."resource-table"] local controls_with_scale_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "terrain-scroll-pane"][ENTIRE_PREFIX .."controls-with-scale-table"] local enemies_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-1"][ENTIRE_PREFIX .."enemies-table"] @@ -368,7 +368,7 @@ map_gen_gui.reset_to_defaults = function(parent) end map_gen_gui.set_to_current = function(parent, map_gen_settings) - local expression_selectors_flow = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "-expression-selectors-table"][ENTIRE_PREFIX .. "-expression-selectors-flow"] + local expression_selectors_flow = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "expression-selectors-table"][ENTIRE_PREFIX .. "expression-selectors-flow"] local resource_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-1"][ENTIRE_PREFIX .. "resource-scroll-pane"][ENTIRE_PREFIX .."resource-table"] local controls_with_scale_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "terrain-scroll-pane"][ENTIRE_PREFIX .."controls-with-scale-table"] local enemies_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-1"][ENTIRE_PREFIX .."enemies-table"] @@ -390,11 +390,11 @@ map_gen_gui.set_to_current = function(parent, map_gen_settings) else noise_expressions_list_item = selected_expression -- number that is really a string. we just use it directly end - local property_flow = expression_selectors_flow[ENTIRE_PREFIX .. "-" .. property .. "-flow"] + local property_flow = expression_selectors_flow[ENTIRE_PREFIX .. property .. "-flow"] if not property_flow then property_flow = map_gen_gui.make_expression_selector(property, relevant_noise_expressions[property], expression_selectors_flow, true) end - local dropdown = property_flow[ENTIRE_PREFIX .. "-" .. property .. "-drop-down"] + local dropdown = property_flow[ENTIRE_PREFIX .. property .. "-drop-down"] map_gen_gui.select_in_dropdown_or_add_and_select(noise_expressions_list_item, dropdown) -- select (optionally add) the item end end @@ -440,7 +440,7 @@ end map_gen_gui.select_in_dropdown_or_add_and_select = function(item_to_select, dropdown) local items = dropdown.items for index, item in pairs(items) do - if util.compare_localized_string(item_to_select, item) then + if util.compare_localized_strings(item_to_select, item) then dropdown.selected_index = index return -- found in dropdown end @@ -451,8 +451,9 @@ map_gen_gui.select_in_dropdown_or_add_and_select = function(item_to_select, drop dropdown.selected_index = index end +-- returns map_gen_settings, can throw! map_gen_gui.read = function(parent) - local expression_selectors_flow = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "-expression-selectors-table"][ENTIRE_PREFIX .. "-expression-selectors-flow"] + local expression_selectors_flow = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "expression-selectors-table"][ENTIRE_PREFIX .. "expression-selectors-flow"] local resource_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-1"][ENTIRE_PREFIX .. "resource-scroll-pane"][ENTIRE_PREFIX .."resource-table"] local controls_with_scale_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-2"][ENTIRE_PREFIX .. "terrain-scroll-pane"][ENTIRE_PREFIX .."controls-with-scale-table"] local enemies_table = parent[ENTIRE_PREFIX .. "map-gen-gui-frame-1"][ENTIRE_PREFIX .."enemies-table"] @@ -466,9 +467,9 @@ map_gen_gui.read = function(parent) -- expression selectors local possible_properties = util.get_possible_noise_expression_properties() for _, property in pairs(possible_properties) do - local property_flow = expression_selectors_flow[ENTIRE_PREFIX .. "-" .. property .. "-flow"] + local property_flow = expression_selectors_flow[ENTIRE_PREFIX .. property .. "-flow"] if property_flow then - local dropdown = property_flow[ENTIRE_PREFIX .. "-" .. property .. "-drop-down"] + local dropdown = property_flow[ENTIRE_PREFIX .. property .. "-drop-down"] local selected_noise_expressions_list_item = dropdown.items[dropdown.selected_index] -- above is a localized string in form of {"noise-expression." .. selected_expression} or selected_expression -- parse it to get selected_expression @@ -518,8 +519,8 @@ map_gen_gui.read = function(parent) -- cliffs cliff_settings_mine.name = "cliff" - cliff_settings_mine.cliff_elevation_interval = 40 / util.textfield_to_number_with_error(cliffs_table["change-map-settings-map-gen-cliffs-freq"]) -- inverse with 40 - cliff_settings_mine.richness = util.textfield_to_number_with_error(cliffs_table["change-map-settings-map-gen-cliffs-size"]) + cliff_settings_mine.cliff_elevation_interval = 40 / util.textfield_to_number_with_error(cliffs_table[ENTIRE_PREFIX .. "cliffs-freq"]) -- inverse with 40 + cliff_settings_mine.richness = util.textfield_to_number_with_error(cliffs_table[ENTIRE_PREFIX .. "cliffs-size"]) map_gen_settings.autoplace_controls = autoplace_controls_mine map_gen_settings.property_expression_names = property_expression_names_mine diff --git a/map_settings_gui.lua b/map_settings_gui.lua new file mode 100644 index 0000000..c5fa214 --- /dev/null +++ b/map_settings_gui.lua @@ -0,0 +1,268 @@ +local util = require("utilities") +local MOD_PREFIX = "change-map-settings-" +local GUI_PREFIX = "map-settings-" +local ENTIRE_PREFIX = MOD_PREFIX .. GUI_PREFIX +local map_settings_gui = {} + +map_settings_gui.make_pollution_settings = function(parent, map_settings) + local WIDGET_PREFIX = "pollution-" + local flow = parent.add{ + type = "flow", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow", + direction = "vertical" + } + flow.add{ + type = "label", + caption = {"gui-map-generator.pollution"}, + style = "caption_label" + } + local table = flow.add{ + type = "table", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "table", + column_count = 2, + style = "bordered_table" + } + table.style.column_alignments[2] = "center" + + table.add{ + type = "label", + caption = {"gui-map-generator.pollution"} + } + table.add{ + type = "checkbox", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox", + state = map_settings.pollution.enabled, + } + table.children[1].style.horizontally_stretchable = true + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "dissipation", {"gui-map-generator.pollution-absorption-modifier"}, {"gui-map-generator.pollution-absorption-modifier-description"}, tostring(map_settings.pollution.ageing), 50) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "consumption", {"gui-map-generator.enemy-attack-pollution-consumption-modifier"}, {"gui-map-generator.enemy-attack-pollution-consumption-modifier-description"}, tostring(map_settings.pollution.enemy_attack_pollution_consumption_modifier), 50) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "tree-dmg", {"gui-map-generator.minimum-pollution-to-damage-trees"}, {"gui-map-generator.minimum-pollution-to-damage-trees-description"}, tostring(map_settings.pollution.min_pollution_to_damage_trees), 50) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "tree-absorb", {"gui-map-generator.pollution-absorbed-per-tree-damaged"}, {"gui-map-generator.pollution-absorbed-per-tree-damaged-description"}, tostring(map_settings.pollution.pollution_restored_per_tree_damage), 50) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "diffusion", {"gui." .. MOD_PREFIX .. "in-unit", {"gui-map-generator.pollution-diffusion-ratio"}, {"gui." .. MOD_PREFIX .. "percent"}}, {"gui-map-generator.pollution-diffusion-ratio-description"}, tostring(map_settings.pollution.diffusion_ratio * 100), 50) +end + +map_settings_gui.make_evolution_settings = function(parent, map_settings) + local WIDGET_PREFIX = "evolution-" + local flow = parent.add{ + type = "flow", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow", + direction = "vertical" + } + flow.add{ + type = "label", + caption = {"gui-map-generator.evolution"}, + style = "caption_label" + } + local table = flow.add{ + type = "table", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "table", + column_count = 2, + style = "bordered_table" + } + table.style.column_alignments[2] = "center" + + table.add{ + type = "label", + caption = {"gui-map-generator.evolution"} + } + table.add{ + type = "checkbox", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox", + state = map_settings.enemy_evolution.enabled, + } + table.children[1].style.horizontally_stretchable = true + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "factor", {"gui-map-generator.evolution"}, {"gui." .. MOD_PREFIX .. "evolution-factor-tooltip"}, util.number_to_string(game.forces["enemy"].evolution_factor), 80) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "time", {"gui-map-generator.evolution-time-factor"}, {"gui-map-generator.evolution-time-factor-description"}, util.number_to_string(map_settings.enemy_evolution.time_factor * 100), 80) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "destroy", {"gui-map-generator.evolution-destroy-factor"}, {"gui-map-generator.evolution-destroy-factor-description"}, util.number_to_string(map_settings.enemy_evolution.destroy_factor * 100), 80) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "pollution", {"gui-map-generator.evolution-pollution-factor"}, {"gui-map-generator.evolution-pollution-factor-description"}, util.number_to_string(map_settings.enemy_evolution.pollution_factor * 100), 80) +end + +map_settings_gui.make_expansion_settings = function(parent, map_settings) + local WIDGET_PREFIX = "expansion-" + local flow = parent.add{ + type = "flow", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow", + direction = "vertical" + } + flow.add{ + type = "label", + caption = {"gui-map-generator.enemy-expansion-group-tile"}, + style = "caption_label" + } + local table = flow.add{ + type = "table", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "table", + column_count = 2, + style = "bordered_table" + } + table.style.column_alignments[2] = "center" + + table.add{ + type = "label", + caption = {"gui-map-generator.enemy-expansion-group-tile"} + } + table.add{ + type = "checkbox", + name = ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox", + state = map_settings.enemy_expansion.enabled, + } + table.children[1].style.horizontally_stretchable = true + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "distance", {"gui-map-generator.enemy-expansion-maximum-expansion-distance"}, {"gui-map-generator.enemy-expansion-maximum-expansion-distance-description"}, tostring(map_settings.enemy_expansion.max_expansion_distance), 30) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "min-size", {"gui-map-generator.enemy-expansion-minimum-expansion-group-size"}, {"gui-map-generator.enemy-expansion-minimum-expansion-group-size-description"}, tostring(map_settings.enemy_expansion.settler_group_min_size), 30) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "max-size", {"gui-map-generator.enemy-expansion-maximum-expansion-group-size"}, {"gui-map-generator.enemy-expansion-maximum-expansion-group-size-description"}, tostring(map_settings.enemy_expansion.settler_group_max_size), 30) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "min-cd", {"gui." .. MOD_PREFIX .. "in-unit", {"gui-map-generator.enemy-expansion-minimum-expansion-cooldown"}, {"gui." .. MOD_PREFIX .. "minutes"}}, {"gui-map-generator.enemy-expansion-minimum-expansion-cooldown-description"}, tostring(map_settings.enemy_expansion.min_expansion_cooldown / 3600), 30) + map_settings_gui.make_config_option(table, WIDGET_PREFIX .. "max-cd", {"gui." .. MOD_PREFIX .. "in-unit", {"gui-map-generator.enemy-expansion-maximum-expansion-cooldown"}, {"gui." .. MOD_PREFIX .. "minutes"}}, {"gui-map-generator.enemy-expansion-maximum-expansion-cooldown-description"}, tostring(map_settings.enemy_expansion.max_expansion_cooldown / 3600), 30) +end + +map_settings_gui.make_config_option = function(parent, name, caption, tooltip, default, max_width) + parent.add{ + type = "label", + caption = util.add_info_icon_to_string(caption), + tooltip = tooltip + } + local child = parent.add{ + type = "textfield", + name = ENTIRE_PREFIX .. name .. "-textfield", + text = default + } + if max_width then child.style.maximal_width = max_width end + return child +end + +map_settings_gui.expansion_reset_to_defaults = function(parent) + local WIDGET_PREFIX = "expansion-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state = true + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "distance-textfield"].text = "7" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "min-size-textfield"].text = "5" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "max-size-textfield"].text = "20" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "min-cd-textfield"].text = "4" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "max-cd-textfield"].text = "60" +end + +map_settings_gui.evolution_reset_to_defaults = function(parent) + local WIDGET_PREFIX = "evolution-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state = true + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "factor-textfield"].text = "0" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "time-textfield"].text = "0.0004" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "destroy-textfield"].text = "0.2" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "pollution-textfield"].text = "0.000090" +end + +map_settings_gui.pollution_reset_to_defaults = function(parent) + local WIDGET_PREFIX = "pollution-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state = true + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "dissipation-textfield"].text = "1" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "consumption-textfield"].text = "1" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "tree-dmg-textfield"].text = "60" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "tree-absorb-textfield"].text = "10" + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "diffusion-textfield"].text = "2" +end + +map_settings_gui.expansion_set_to_current = function(parent, map_settings) + local WIDGET_PREFIX = "expansion-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state = map_settings.enemy_expansion.enabled + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "distance-textfield"].text = tostring(map_settings.enemy_expansion.max_expansion_distance) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "min-size-textfield"].text = tostring(map_settings.enemy_expansion.settler_group_min_size) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "max-size-textfield"].text = tostring(map_settings.enemy_expansion.settler_group_max_size) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "min-cd-textfield"].text = tostring(map_settings.enemy_expansion.min_expansion_cooldown / 3600) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "max-cd-textfield"].text = tostring(map_settings.enemy_expansion.max_expansion_cooldown / 3600) +end + +map_settings_gui.evolution_set_to_current = function(parent, map_settings) + local WIDGET_PREFIX = "evolution-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state = map_settings.enemy_evolution.enabled + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "factor-textfield"].text = util.number_to_string(game.forces["enemy"].evolution_factor) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "time-textfield"].text = util.number_to_string(map_settings.enemy_evolution.time_factor * 100) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "destroy-textfield"].text = util.number_to_string(map_settings.enemy_evolution.destroy_factor * 100) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "pollution-textfield"].text = util.number_to_string(map_settings.enemy_evolution.pollution_factor * 100) +end + +map_settings_gui.pollution_set_to_current = function(parent, map_settings) + local WIDGET_PREFIX = "pollution-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state = map_settings.pollution.enabled + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "dissipation-textfield"].text = tostring(map_settings.pollution.ageing) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "consumption-textfield"].text = tostring(map_settings.pollution.enemy_attack_pollution_consumption_modifier) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "tree-dmg-textfield"].text = tostring(map_settings.pollution.min_pollution_to_damage_trees) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "tree-absorb-textfield"].text = tostring(map_settings.pollution.pollution_restored_per_tree_damage) + table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "diffusion-textfield"].text = tostring(map_settings.pollution.diffusion_ratio * 100) +end + +-- can throw! +map_settings_gui.expansion_read = function(parent) + local WIDGET_PREFIX = "expansion-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + local enemy_expansion = {} + + enemy_expansion.enabled = table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state + enemy_expansion.max_expansion_distance = util.check_bounds(util.textfield_to_uint(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "distance-textfield"]), + 2, 20, + {"msg." .. MOD_PREFIX .. "invalid-expansion-distance"}) + enemy_expansion.settler_group_min_size = util.check_bounds(util.textfield_to_uint(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "min-size-textfield"]), + 1, 20, + {"msg." .. MOD_PREFIX .. "invalid-expansion-min-size"}) + enemy_expansion.settler_group_max_size = util.check_bounds(util.textfield_to_uint(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "max-size-textfield"]), + math.max(enemy_expansion.settler_group_min_size, 1), 50, + {"msg." .. MOD_PREFIX .. "invalid-expansion-max-size"}) + enemy_expansion.min_expansion_cooldown = util.check_bounds(util.textfield_to_uint(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "min-cd-textfield"]), + 1, 60, + {"msg." .. MOD_PREFIX .. "invalid-expansion-min-cd"}) * 3600 + enemy_expansion.max_expansion_cooldown = util.check_bounds(util.textfield_to_uint(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "max-cd-textfield"]), + math.max(enemy_expansion.min_expansion_cooldown / 3600, 5), 180, + {"msg." .. MOD_PREFIX .. "invalid-expansion-max-cd"}) * 3600 + return enemy_expansion +end + +-- can throw! +map_settings_gui.evolution_read = function(parent) + local WIDGET_PREFIX = "evolution-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + local enemy_evolution = {} + + enemy_evolution.enabled = table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state + enemy_evolution.evolution_factor = util.check_bounds(util.textfield_to_number(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "factor-textfield"]), + 0, 1, + {"msg." .. MOD_PREFIX .. "invalid-evolution-factor"}) + enemy_evolution.time_factor = util.check_bounds(util.textfield_to_number(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "time-textfield"]), + 0, 0.01, + {"msg." .. MOD_PREFIX .. "invalid-evolution-time"}) / 100 + enemy_evolution.destroy_factor = util.check_bounds(util.textfield_to_number(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "destroy-textfield"]), + 0, 1, + {"msg." .. MOD_PREFIX .. "invalid-evolution-destroy"}) / 100 + enemy_evolution.pollution_factor = util.check_bounds(util.textfield_to_number(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "pollution-textfield"]), + 0, 0.01, + {"msg." .. MOD_PREFIX .. "invalid-evolution-pollution"}) / 100 + return enemy_evolution +end + +-- can throw! +map_settings_gui.pollution_read = function(parent) + local WIDGET_PREFIX = "pollution-" + local table = parent[ENTIRE_PREFIX .. WIDGET_PREFIX .. "flow"][ENTIRE_PREFIX .. WIDGET_PREFIX .. "table"] + local pollution = {} + + pollution.enabled = table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "checkbox"].state + pollution.ageing = util.check_bounds(util.textfield_to_number(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "dissipation-textfield"]), + 0.1, 4, + {"msg." .. MOD_PREFIX .. "invalid-pollution-absorption"}) + pollution.enemy_attack_pollution_consumption_modifier = util.check_bounds(util.textfield_to_number(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "consumption-textfield"]), + 0.1, 4, + {"msg." .. MOD_PREFIX .. "invalid-enemy-attack-pollution-consumption"}) + pollution.min_pollution_to_damage_trees = util.check_bounds(util.textfield_to_uint(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "tree-dmg-textfield"]), + 0, 9999, + {"msg." .. MOD_PREFIX .. "invalid-pollution-tree-dmg"}) + pollution.pollution_restored_per_tree_damage = util.check_bounds(util.textfield_to_uint(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "tree-absorb-textfield"]), + 0, 9999, + {"msg." .. MOD_PREFIX .. "invalid-pollution-tree-absorb"}) + pollution.diffusion_ratio = util.check_bounds(util.textfield_to_uint(table[ENTIRE_PREFIX .. WIDGET_PREFIX .. "diffusion-textfield"]), + 0, 25, + {"msg." .. MOD_PREFIX .. "-invalid-pollution-diffusion"}) / 100 + return pollution +end + +return map_settings_gui \ No newline at end of file diff --git a/utilities.lua b/utilities.lua index 841762d..681fd0e 100644 --- a/utilities.lua +++ b/utilities.lua @@ -2,12 +2,11 @@ local util = {} local tableutil = require("util").table util.textfield_to_uint = function(textfield) - local number = tonumber(textfield.text) - if textfield.text and number and (number >= 0) and (number <= 4294967295) and (math.floor(number) == number) then + local number = util.textfield_to_number(textfield) + if number and (number >= 0) and (number <= 4294967295) and (math.floor(number) == number) then return number - else - return false end + return false end util.textfield_to_number = function(textfield) @@ -18,9 +17,8 @@ util.textfield_to_number = function(textfield) return 1/0 elseif textfield.text and textfield.text == "-inf" then return -(1/0) - else - return false end + return false end util.textfield_to_number_with_error = function(textfield) @@ -43,11 +41,11 @@ util.number_to_string = function(number) -- shows up to 6 decimal places return tostring(math.floor(number * 1000000 + 0.5) / 1000000) -- 0.5 for "rounding" end -util.check_bounds = function(input, min, max, player, error) +util.check_bounds = function(input, min, max, err) if input and (input >= min) and (input <= max) then return input end - player.print(error) + error(err) -- because localized string return false end @@ -64,15 +62,15 @@ util.get_relevant_noise_expressions = function() return expressions end -util.add_info_icon_to_localized_string = function(localized_string) - return {"", localized_string, " [img=info]"} +util.add_info_icon_to_string = function(string) + return {"", string, " [img=info]"} end util.get_possible_noise_expression_properties = function() return { "elevation", "temperature", "moisture", "aux", "starting-lake-noise-amplitude"} end -util.compare_localized_string = function(string1, string2) +util.compare_localized_strings = function(string1, string2) if type(string1) == "string" then string1 = {"", string1} end