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

Commit

Permalink
And now, v0.4
Browse files Browse the repository at this point in the history
Closes #13, closes #17.

Finalizes the interface for sensor settings (both GUI and API, though
the latter will probably be revisited soon) and gives the player
locations sensor the ability to show any/none of: player index,
coordinates, surface, and direction. Defaults to showing only the
direction.
  • Loading branch information
narc0tiq committed Aug 29, 2015
1 parent 8b02fbf commit 26fd340
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.4
0.4.0
13 changes: 13 additions & 0 deletions evoGUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ function evogui.create_player_globals(player)

table.insert(player_settings.personal_sensors, PollutionSensor.new(player))
end

if not player_settings.sensor_settings then
player_settings.sensor_settings = {}
end

if not player_settings.sensor_settings['player_locations'] then
player_settings.sensor_settings['player_locations'] = {
['show_player_index'] = false,
['show_position'] = false,
['show_surface'] = false,
['show_direction'] = true,
}
end
end


Expand Down
6 changes: 6 additions & 0 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ sensor.play_time.format=Play time: __1__.
sensor.player_locations.name=Player locations
sensor.player_locations.format=Players:
sensor.player_locations.surface_fragment=on __1__
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
sensor.player_locations.settings.show_surface=Show surface the player is on
sensor.player_locations.settings.show_direction=Show direction to walk to reach the player
sensor.pollution_around_player.name=Nearby pollution level
sensor.pollution_around_player.format=Pollution: __1__ PU.
Expand Down
99 changes: 94 additions & 5 deletions value_sensors/player_locations.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "template"

if not evogui.on_click then evogui.on_click = {} end
local sensor = ValueSensor.new("player_locations")

function sensor:create_ui(owner)
Expand All @@ -14,12 +15,74 @@ function sensor:create_ui(owner)
end
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)
player.print("Hello, world")
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.player_locations.settings.title"}}
root.add{type="checkbox", name="evogui_show_player_index",
caption={"sensor.player_locations.settings.show_player_index"},
state=sensor_settings.show_player_index}
root.add{type="checkbox", name="evogui_show_position",
caption={"sensor.player_locations.settings.show_position"},
state=sensor_settings.show_position}
root.add{type="checkbox", name="evogui_show_surface",
caption={"sensor.player_locations.settings.show_surface"},
state=sensor_settings.show_surface}
root.add{type="checkbox", name="evogui_show_direction",
caption={"sensor.player_locations.settings.show_direction"},
state=sensor_settings.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)
Expand Down Expand Up @@ -50,6 +113,9 @@ 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]

for _, p in ipairs(game.players) do
if owner[self.name].player_list[p.name] == nil then
owner[self.name].player_list.add{type="label", name=p.name}
Expand All @@ -63,8 +129,31 @@ function sensor:update_ui(owner)
direction = directions(current_player, p)
end

local desc = string.format("(%d) %s @(%d, %d on %s) %s", p.index,
p.name, p.position.x, p.position.y, p.surface.name, direction)
local desc = {''}
if sensor_settings.show_player_index then
table.insert(desc, string.format('(%d) ', p.index))
end

table.insert(desc, p.name)

if sensor_settings.show_position or sensor_settings.show_surface then
table.insert(desc, ' (')
if sensor_settings.show_position then
table.insert(desc, string.format('@%d, %d', p.position.x, p.position.y))
end
if sensor_settings.show_surface then
if sensor_settings.show_position then
table.insert(desc, ' ')
end
table.insert(desc, {"sensor.player_locations.surface_fragment", p.surface.name})
end
table.insert(desc, ')')
end

if sensor_settings.show_direction then
table.insert(desc, ' ' .. direction)
end

owner[self.name].player_list[p.name].caption = desc
end
end
Expand Down
4 changes: 4 additions & 0 deletions value_sensors/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function ValueSensor.new(name)
end
end

function sensor:settings_root_name()
return self.name.."_settings"
end

return sensor
end

Expand Down

0 comments on commit 26fd340

Please sign in to comment.