Skip to content

Commit

Permalink
Merge remote-tracking branch 'narc0tiq/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
The JoCKeR (IL) committed Sep 10, 2015
2 parents df1cd37 + c3f018d commit 05d09db
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 34 deletions.
13 changes: 13 additions & 0 deletions evoGUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ 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

if not player_settings.sensor_settings['play_time'] then
player_settings.sensor_settings['play_time'] = {
['show_days'] = true,
['show_seconds'] = true,
}
end
end


Expand Down
12 changes: 10 additions & 2 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ sensor.day_time.format=It's __1__. Brightness: __2__.
sensor.day_time.day_format=It's __1__ on day __2__. Brightness: __3__
sensor.day_time.settings.title=Time of day settings
sensor.day_time.settings.show_day_number=Show the current planetary day since landing.
sensor.day_time.settings.minute_rounding=Round minutes to the nearest 15.
sensor.day_time.settings.minute_rounding=Round displayed minutes to a quarter hour (xx:15, xx:30, etc).

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__.
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:
sensor.player_locations.err_no_name=You have no multiplayer username, player list disabled.
sensor.player_locations.surface_fragment=on __1__
sensor.player_locations.offline_fragment=[Offline]
sensor.player_locations.settings.title=Player location settings
sensor.player_locations.settings.show_player_index=Show player index
sensor.player_locations.settings.show_position=Show coordinates
Expand All @@ -28,7 +36,7 @@ settings_title=EvoGUI settings

settings.core_settings.title=Core settings (shared)
settings.core_settings.update_freq_left=Update EvoGUI every
settings.core_settings.update_freq_right=ticks (60 ticks = 1 second)
settings.core_settings.update_freq_right=ticks (there are 60 ticks in a second)

settings.sensors_frame.title=Sensor settings

Expand Down
20 changes: 0 additions & 20 deletions value_sensors/day_time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -42,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]
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)
47 changes: 45 additions & 2 deletions value_sensors/play_time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 6 additions & 10 deletions value_sensors/player_locations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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]
Expand Down Expand Up @@ -121,6 +112,11 @@ function sensor:update_ui(owner)

table.insert(desc, p.name)

if p.connected == false then
table.insert(desc, ' ')
table.insert(desc, {"sensor.player_locations.offline_fragment"})
end

if sensor_settings.show_position or sensor_settings.show_surface then
table.insert(desc, ' (')
if sensor_settings.show_position then
Expand Down
14 changes: 14 additions & 0 deletions value_sensors/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -35,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

Expand Down

0 comments on commit 05d09db

Please sign in to comment.