diff --git a/value_sensors/day_time.lua b/value_sensors/day_time.lua index aadaba8..d674ea5 100644 --- a/value_sensors/day_time.lua +++ b/value_sensors/day_time.lua @@ -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) diff --git a/value_sensors/player_locations.lua b/value_sensors/player_locations.lua index 1af662e..f9b45c9 100644 --- a/value_sensors/player_locations.lua +++ b/value_sensors/player_locations.lua @@ -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 diff --git a/value_sensors/template.lua b/value_sensors/template.lua index ae8708c..cfc4f8f 100644 --- a/value_sensors/template.lua +++ b/value_sensors/template.lua @@ -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