Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Add evolution factor precision settings.
Browse files Browse the repository at this point in the history
Closes #21.
  • Loading branch information
narc0tiq committed Sep 9, 2015
1 parent 737a78a commit 2ab75fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions evoGUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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__.
Expand Down
24 changes: 24 additions & 0 deletions value_sensors/evolution_factor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2ab75fe

Please sign in to comment.