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 8, 2015
2 parents 94b86c0 + 11a80d7 commit df1cd37
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 53 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
20 changes: 3 additions & 17 deletions value_sensors/day_time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,16 @@ function sensor:settings_gui(player_index)
root.add{type="checkbox", name="evogui_show_day_number",
caption={"sensor.day_time.settings.show_day_number"},
state=sensor_settings.show_day_number}
evogui.on_click.evogui_show_day_number = self:make_on_click_checkbox_handler("show_day_number")

root.add{type="checkbox", name="evogui_minute_rounding",
caption={"sensor.day_time.settings.minute_rounding"},
state=sensor_settings.minute_rounding}
evogui.on_click.evogui_minute_rounding = self:make_on_click_checkbox_handler("minute_rounding")

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


function evogui.on_click.evogui_show_day_number(event)
local player = game.get_player(event.player_index)
local sensor_settings = global.evogui[player.name].sensor_settings["day_time"]

sensor_settings.show_day_number = event.element.state
end


function evogui.on_click.evogui_minute_rounding(event)
local player = game.get_player(event.player_index)
local sensor_settings = global.evogui[player.name].sensor_settings["day_time"]

sensor_settings.minute_rounding = event.element.state
end



ValueSensor.register(sensor)
39 changes: 7 additions & 32 deletions value_sensors/player_locations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,28 @@ function sensor:settings_gui(player_index)
root.add{type="checkbox", name="evogui_show_player_index",
caption={"sensor.player_locations.settings.show_player_index"},
state=sensor_settings.show_player_index}
evogui.on_click.evogui_show_player_index = self:make_on_click_checkbox_handler("show_player_index")

root.add{type="checkbox", name="evogui_show_position",
caption={"sensor.player_locations.settings.show_position"},
state=sensor_settings.show_position}
evogui.on_click.evogui_show_position = self:make_on_click_checkbox_handler("show_position")

root.add{type="checkbox", name="evogui_show_surface",
caption={"sensor.player_locations.settings.show_surface"},
state=sensor_settings.show_surface}
evogui.on_click.evogui_show_surface = self:make_on_click_checkbox_handler("show_surface")

root.add{type="checkbox", name="evogui_show_direction",
caption={"sensor.player_locations.settings.show_direction"},
state=sensor_settings.show_direction}
evogui.on_click.evogui_show_direction = self:make_on_click_checkbox_handler("show_direction")

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


function evogui.on_click.evogui_show_player_index(event)
local player = game.get_player(event.player_index)
local sensor_settings = global.evogui[player.name].sensor_settings["player_locations"]

sensor_settings.show_player_index = event.element.state
end


function evogui.on_click.evogui_show_position(event)
local player = game.get_player(event.player_index)
local sensor_settings = global.evogui[player.name].sensor_settings["player_locations"]

sensor_settings.show_position = event.element.state
end


function evogui.on_click.evogui_show_surface(event)
local player = game.get_player(event.player_index)
local sensor_settings = global.evogui[player.name].sensor_settings["player_locations"]

sensor_settings.show_surface = event.element.state
end


function evogui.on_click.evogui_show_direction(event)
local player = game.get_player(event.player_index)
local sensor_settings = global.evogui[player.name].sensor_settings["player_locations"]

sensor_settings.show_direction = event.element.state
end


local function directions(source, destination)
-- Directions to or from positionless things? Hrm.
if not source.position or not destination.position then return '?' end
Expand Down
11 changes: 11 additions & 0 deletions value_sensors/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ function ValueSensor.new(name)
return self.name.."_settings"
end

function sensor:make_on_click_checkbox_handler(setting_name)
local sensor_name = self.name

return function(event)
local player = game.get_player(event.player_index)
local sensor_settings = global.evogui[player.name].sensor_settings[sensor_name]

sensor_settings[setting_name] = event.element.state
end
end

return sensor
end

Expand Down

0 comments on commit df1cd37

Please sign in to comment.