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

Commit

Permalink
More meta handling of per-sensor checkboxes
Browse files Browse the repository at this point in the history
This has the advantage of reducing copypasta, which I'd acquired a fair
bit of.
  • Loading branch information
narc0tiq committed Sep 8, 2015
1 parent b1a68c0 commit f960abe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 49 deletions.
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 f960abe

Please sign in to comment.