From 2ab75fed667c564c3f121d80a0ed176a5a643e6b Mon Sep 17 00:00:00 2001 From: Octav Sandulescu Date: Wed, 9 Sep 2015 07:31:54 +0000 Subject: [PATCH] Add evolution factor precision settings. Closes #21. --- evoGUI.lua | 6 ++++++ locale/en/locale.cfg | 2 ++ value_sensors/evolution_factor.lua | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/evoGUI.lua b/evoGUI.lua index 4dbd5dc..9698c2d 100644 --- a/evoGUI.lua +++ b/evoGUI.lua @@ -81,6 +81,12 @@ function evogui.create_player_globals(player) ['minute_rounding'] = true, } end + + if not player_settings.sensor_settings['evolution_factor'] then + player_settings.sensor_settings['evolution_factor'] = { + ['extra_precision'] = false, + } + end end diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg index 1108f62..9effca1 100644 --- a/locale/en/locale.cfg +++ b/locale/en/locale.cfg @@ -7,6 +7,8 @@ sensor.day_time.settings.minute_rounding=Round displayed minutes to a quarter ho sensor.evolution_factor.name=Evolution factor sensor.evolution_factor.format=Biter evolution: __1__. +sensor.evolution_factor.settings.title=Evolution factor display settings +sensor.evolution_factor.settings.extra_precision=Show four decimals (x.1234%) instead of one (x.1%). sensor.play_time.name=Time played sensor.play_time.format=Play time: __1__. diff --git a/value_sensors/evolution_factor.lua b/value_sensors/evolution_factor.lua index 09bae83..4258417 100644 --- a/value_sensors/evolution_factor.lua +++ b/value_sensors/evolution_factor.lua @@ -2,8 +2,32 @@ require "template" local sensor = ValueSensor.new("evolution_factor") + function sensor:get_line() + if self.settings.extra_precision then + return {self.format_key, string.format("%0.4f%%", game.evolution_factor * 100)} + end + return {self.format_key, string.format("%0.1f%%", game.evolution_factor * 100)} end + +function sensor:settings_gui(player_index) + local player = game.get_player(player_index) + local sensor_settings = global.evogui[player.name].sensor_settings[self.name] + local root_name = self:settings_root_name() + + local root = player.gui.center.add{type="frame", + name=root_name, + direction="vertical", + caption={"sensor.evolution_factor.settings.title"}} + root.add{type="checkbox", name="evogui_extra_precision", + caption={"sensor.evolution_factor.settings.extra_precision"}, + state=sensor_settings.extra_precision} + evogui.on_click.evogui_extra_precision = self:make_on_click_checkbox_handler("extra_precision") + + local btn_close = root.add{type="button", name="evogui_custom_sensor_close", caption={"settings_close"}} + evogui.on_click[btn_close.name] = function(event) self:close_settings_gui(player_index) end +end + ValueSensor.register(sensor)