From 97b8b3d7b7334730ef352ed52b0949dd42ece071 Mon Sep 17 00:00:00 2001 From: Octav Sandulescu Date: Wed, 9 Sep 2015 07:20:18 +0000 Subject: [PATCH 1/4] Push sensor setting handling up to the template --- value_sensors/day_time.lua | 10 ---------- value_sensors/template.lua | 5 +++++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/value_sensors/day_time.lua b/value_sensors/day_time.lua index d674ea5..a81693b 100644 --- a/value_sensors/day_time.lua +++ b/value_sensors/day_time.lua @@ -4,16 +4,6 @@ if not evogui.on_click then evogui.on_click = {} end local sensor = ValueSensor.new("day_time") -function sensor:update_ui(owner) - local player = game.get_player(owner.player_index) - local sensor_settings = global.evogui[player.name].sensor_settings[self.name] - - self.settings = sensor_settings - - owner[self.name].caption = self:get_line() -end - - function sensor:get_line() -- 0.5 is midnight; let's make days *start* at midnight instead. local day_time = math.fmod(game.daytime + 0.5, 1) diff --git a/value_sensors/template.lua b/value_sensors/template.lua index cfc4f8f..4566d13 100644 --- a/value_sensors/template.lua +++ b/value_sensors/template.lua @@ -22,6 +22,11 @@ function ValueSensor.new(name) end function sensor:update_ui(owner) + local player = game.get_player(owner.player_index) + local sensor_settings = global.evogui[player.name].sensor_settings[self.name] + + self.settings = sensor_settings + owner[self.name].caption = self:get_line() end From 737a78a252c04eaccdc3ba044e393f43da5c8fce Mon Sep 17 00:00:00 2001 From: Octav Sandulescu Date: Wed, 9 Sep 2015 07:31:19 +0000 Subject: [PATCH 2/4] Also move close_settings_gui() up. --- value_sensors/day_time.lua | 10 ---------- value_sensors/player_locations.lua | 11 +---------- value_sensors/template.lua | 9 +++++++++ 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/value_sensors/day_time.lua b/value_sensors/day_time.lua index a81693b..0cb792b 100644 --- a/value_sensors/day_time.lua +++ b/value_sensors/day_time.lua @@ -32,16 +32,6 @@ function sensor:get_line() end -function sensor:close_settings_gui(player_index) - local player = game.get_player(player_index) - local root_name = self:settings_root_name() - - player.gui.center[root_name].destroy() - - if self.settings_gui_closed then self.settings_gui_closed(player_index) end -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] diff --git a/value_sensors/player_locations.lua b/value_sensors/player_locations.lua index 321c707..ef5e37f 100644 --- a/value_sensors/player_locations.lua +++ b/value_sensors/player_locations.lua @@ -3,6 +3,7 @@ require "template" if not evogui.on_click then evogui.on_click = {} end local sensor = ValueSensor.new("player_locations") + function sensor:create_ui(owner) if owner[self.name] == nil then local root = owner.add{type="flow", @@ -16,16 +17,6 @@ function sensor:create_ui(owner) end -function sensor:close_settings_gui(player_index) - local player = game.get_player(player_index) - local root_name = self:settings_root_name() - - player.gui.center[root_name].destroy() - - if self.settings_gui_closed then self.settings_gui_closed(player_index) end -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] diff --git a/value_sensors/template.lua b/value_sensors/template.lua index 4566d13..47ab6d6 100644 --- a/value_sensors/template.lua +++ b/value_sensors/template.lua @@ -40,6 +40,15 @@ function ValueSensor.new(name) return self.name.."_settings" end + function sensor:close_settings_gui(player_index) + local player = game.get_player(player_index) + local root_name = self:settings_root_name() + + player.gui.center[root_name].destroy() + + if self.settings_gui_closed then self.settings_gui_closed(player_index) end + end + function sensor:make_on_click_checkbox_handler(setting_name) local sensor_name = self.name From 2ab75fed667c564c3f121d80a0ed176a5a643e6b Mon Sep 17 00:00:00 2001 From: Octav Sandulescu Date: Wed, 9 Sep 2015 07:31:54 +0000 Subject: [PATCH 3/4] 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) From 453747a18d0ca581c4acd567dbe61fa935d92613 Mon Sep 17 00:00:00 2001 From: Octav Sandulescu Date: Wed, 9 Sep 2015 08:01:10 +0000 Subject: [PATCH 4/4] Add config for the play_time sensor. Closes #22. --- evoGUI.lua | 7 ++++++ locale/en/locale.cfg | 5 ++++ value_sensors/play_time.lua | 47 +++++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/evoGUI.lua b/evoGUI.lua index 9698c2d..53f7301 100644 --- a/evoGUI.lua +++ b/evoGUI.lua @@ -87,6 +87,13 @@ function evogui.create_player_globals(player) ['extra_precision'] = false, } end + + if not player_settings.sensor_settings['play_time'] then + player_settings.sensor_settings['play_time'] = { + ['show_days'] = true, + ['show_seconds'] = true, + } + end end diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg index 9effca1..b885833 100644 --- a/locale/en/locale.cfg +++ b/locale/en/locale.cfg @@ -12,6 +12,11 @@ sensor.evolution_factor.settings.extra_precision=Show four decimals (x.1234%) in sensor.play_time.name=Time played sensor.play_time.format=Play time: __1__. +sensor.play_time.single_day_fragment=1 day, +sensor.play_time.multi_day_fragment=__1__ days, +sensor.play_time.settings.title=Playing time settings +sensor.play_time.settings.show_days=Show days ("2 days, 01:00" instead of "49:00") +sensor.play_time.settings.show_seconds=Show seconds ("hh:mm:ss" instead of "hh:mm"). sensor.player_locations.name=Player locations sensor.player_locations.format=Players: diff --git a/value_sensors/play_time.lua b/value_sensors/play_time.lua index 2077a7c..7955a12 100644 --- a/value_sensors/play_time.lua +++ b/value_sensors/play_time.lua @@ -2,13 +2,56 @@ require "template" local sensor = ValueSensor.new("play_time") + function sensor:get_line() local play_time_seconds = math.floor(game.tick/60) local play_time_minutes = math.floor(play_time_seconds/60) local play_time_hours = math.floor(play_time_minutes/60) + local play_time_days = math.floor(play_time_hours/24) + + local desc = {""} + if play_time_days > 0 and self.settings.show_days then + if play_time_days == 1 then + table.insert(desc, {"sensor.play_time.single_day_fragment"}) + else + table.insert(desc, {"sensor.play_time.multi_day_fragment", tostring(play_time_days)}) + end + table.insert(desc, ' ') + play_time_hours = play_time_hours % 24 + end + + if self.settings.show_seconds then + table.insert(desc, string.format("%d:%02d:%02d", play_time_hours, play_time_minutes % 60, play_time_seconds % 60)) + else + table.insert(desc, string.format("%d:%02d", play_time_hours, play_time_minutes % 60)) + end + + return {self.format_key, desc} +end - return {self.format_key, - string.format("%d:%02d:%02d", play_time_hours, play_time_minutes % 60, play_time_seconds % 60)} + +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.play_time.settings.title"}} + root.add{type="checkbox", name="evogui_show_days", + caption={"sensor.play_time.settings.show_days"}, + state=sensor_settings.show_days} + evogui.on_click.evogui_show_days = self:make_on_click_checkbox_handler("show_days") + + root.add{type="checkbox", name="evogui_show_seconds", + caption={"sensor.play_time.settings.show_seconds"}, + state=sensor_settings.show_seconds} + evogui.on_click.evogui_show_seconds = self:make_on_click_checkbox_handler("show_seconds") + + 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)