From a1e7e01f47944a80d86906f976f2d0adaf20e553 Mon Sep 17 00:00:00 2001 From: Bilka Date: Tue, 16 Jul 2019 23:21:41 +0200 Subject: [PATCH] Used new functions to restrict text fields to numbers only --- changelog.txt | 5 +++++ gui.lua | 5 ++++- info.json | 4 ++-- map_gen_settings_gui.lua | 23 ++++++++++++++++++----- map_settings_gui.lua | 5 ++++- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/changelog.txt b/changelog.txt index cc6123d..c77c415 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 3.1.4 +Date: 16. 07. 2018 + Minor Features: + - Used new functions to restrict text fields to numbers only. +--------------------------------------------------------------------------------------------------- Version: 3.1.3 Date: 31. 05. 2018 Bugfixes: diff --git a/gui.lua b/gui.lua index 852fd13..c6c4ee6 100644 --- a/gui.lua +++ b/gui.lua @@ -110,7 +110,10 @@ gui.regen = function(player) map_gen_flow1.add{ type = "textfield", name = "change-map-settings-seed-textfield", - text = "0" + text = "0", + numeric = true, + allow_decimal = false, + allow_negative = false } -- rest of map gen settings diff --git a/info.json b/info.json index 62bf427..7463496 100644 --- a/info.json +++ b/info.json @@ -1,10 +1,10 @@ { "name": "ChangeMapSettings", - "version": "3.1.3", + "version": "3.1.4", "factorio_version" : "0.17", "title": "Change Map Settings", "author": "Bilka", "homepage": "", "description": "Allows you to change your map and map generation settings at any time you want.", - "dependencies": [ "base >= 0.17.43" ] + "dependencies": [ "base >= 0.17.58" ] } diff --git a/map_gen_settings_gui.lua b/map_gen_settings_gui.lua index e51414b..872ea3f 100644 --- a/map_gen_settings_gui.lua +++ b/map_gen_settings_gui.lua @@ -279,7 +279,10 @@ map_gen_gui.create_enemies_table = function(parent) table.add{ type = "textfield", name = ENTIRE_PREFIX .. "starting-area-size", - style = "short_number_textfield" + style = "short_number_textfield", + numeric = true, + allow_decimal = true, + allow_negative = true } end @@ -304,18 +307,27 @@ map_gen_gui.make_autoplace_options = function(name, parent, has_richness) parent.add{ type = "textfield", name = ENTIRE_PREFIX .. name .. "-freq", - style = "short_number_textfield" + style = "short_number_textfield", + numeric = true, + allow_decimal = true, + allow_negative = true } parent.add{ type = "textfield", name = ENTIRE_PREFIX .. name .. "-size", - style = "short_number_textfield" + style = "short_number_textfield", + numeric = true, + allow_decimal = true, + allow_negative = true } if has_richness then parent.add{ type = "textfield", name = ENTIRE_PREFIX .. name .. "-richn", - style = "short_number_textfield" + style = "short_number_textfield", + numeric = true, + allow_decimal = true, + allow_negative = true } end end @@ -381,11 +393,12 @@ map_gen_gui.set_to_current = function(parent, map_gen_settings) -- expression selectors local possible_properties = util.get_possible_noise_expression_properties() local relevant_noise_expressions = util.get_relevant_noise_expressions() + local valid_named_noise_expressions = game.named_noise_expressions for _, property in pairs(possible_properties) do local selected_expression = property_expression_names[property] if selected_expression then local noise_expressions_list_item - if game.named_noise_expressions[selected_expression] then -- proper noise expression, not just some number + if valid_named_noise_expressions[selected_expression] then -- proper noise expression, not just some number noise_expressions_list_item = {"noise-expression." .. selected_expression} else noise_expressions_list_item = selected_expression -- number that is really a string. we just use it directly diff --git a/map_settings_gui.lua b/map_settings_gui.lua index c5fa214..6cfeb98 100644 --- a/map_settings_gui.lua +++ b/map_settings_gui.lua @@ -123,7 +123,10 @@ map_settings_gui.make_config_option = function(parent, name, caption, tooltip, d local child = parent.add{ type = "textfield", name = ENTIRE_PREFIX .. name .. "-textfield", - text = default + text = default, + numeric = true, + allow_decimal = true, + allow_negative = false } if max_width then child.style.maximal_width = max_width end return child