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

Commit

Permalink
Configurable update frequency.
Browse files Browse the repository at this point in the history
Closes #20.

Updates locale yet again (mention: #23).
  • Loading branch information
narc0tiq committed Sep 8, 2015
1 parent f960abe commit 11a80d7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
6 changes: 4 additions & 2 deletions evoGUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ require "remote"
if not evogui then evogui = {} end
if not evogui.on_click then evogui.on_click = {} end

evogui.update_delay = 60 -- ticks to wait between each GUI update
local EXPECTED_VERSION = "{{VERSION}}"


function evogui.update_gui()
if (game.tick % evogui.update_delay) == 0 then
if not global.settings then global.settings = {} end
if not global.settings.update_delay then global.settings.update_delay = 60 end

if (game.tick % global.settings.update_delay) == 0 then
for i, player in ipairs(game.players) do
evogui.create_player_globals(player)
evogui.create_sensor_display(player)
Expand Down
6 changes: 6 additions & 0 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ sensor.pollution_around_player.format=Pollution: __1__ PU.

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.sensors_frame.title=Sensor settings

settings_always_visible=Always visible
settings_in_popup=Visible in popup

Expand Down
29 changes: 27 additions & 2 deletions settingsGUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ if not evogui then evogui = {} end
if not evogui.on_click then evogui.on_click = {} end

if not global.evogui then global.evogui = {} end
if not global.settings then global.settings = {} end


local function toggle_always_visible(event)
Expand Down Expand Up @@ -113,7 +114,26 @@ function evogui.on_click.evoGUI_settings(event)
direction="vertical",
name="evoGUI_settingsGUI",
caption={"settings_title"}}
local table = root.add{type="table", colspan=4}

local core_settings = root.add{type="frame",
name="core_settings",
caption={"settings.core_settings.title"},
direction="vertical",
style="naked_frame_style"}

local update_freq_flow = core_settings.add{type="flow", name="update_freq_flow", direction="horizontal"}
update_freq_flow.add{type="label", caption={"settings.core_settings.update_freq_left"}}
local textfield = update_freq_flow.add{type="textfield", name="textfield", style="number_textfield_style"}
textfield.text=tostring(global.settings.update_delay)
update_freq_flow.add{type="label", caption={"settings.core_settings.update_freq_right"}}

local sensors_frame = root.add{type="frame",
name="sensors_frame",
caption={"settings.sensors_frame.title"},
direction="vertical",
style="naked_frame_style"}

local table = sensors_frame.add{type="table", name="table", colspan=4}

for _, sensor in ipairs(evogui.value_sensors) do
add_sensor_table_row(table, sensor, player_data.always_visible, player_data.in_popup)
Expand All @@ -123,14 +143,19 @@ function evogui.on_click.evoGUI_settings(event)
add_sensor_table_row(table, sensor, player_data.always_visible, player_data.in_popup)
end

local buttons = root.add{type="flow", direction="horizontal"}
local buttons = root.add{type="flow", name="buttons", direction="horizontal"}
buttons.add{type="button", name="evoGUI_settings_close", caption={"settings_close"}}
end


function evogui.on_click.evoGUI_settings_close(event)
local player = game.get_player(event.player_index)

local new_update_freq = tonumber(player.gui.center.evoGUI_settingsGUI.core_settings.update_freq_flow.textfield.text)
if new_update_freq ~= nil then
global.settings.update_delay = new_update_freq
end

if player.gui.center.evoGUI_settingsGUI ~= nil then
player.gui.center.evoGUI_settingsGUI.destroy()
end
Expand Down

0 comments on commit 11a80d7

Please sign in to comment.