This repository was archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsettingsGUI.lua
91 lines (68 loc) · 3.04 KB
/
settingsGUI.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require "defines"
if not evogui then evogui = {} end
if not evogui.on_click then evogui.on_click = {} end
if not global.evogui then global.evogui = {} end
local function toggle_always_visible(event)
local player = game.get_player(event.player_index)
if event.element.name:sub(1,3) ~= "AV_" then
error(string.format("toggle_always_visible called on the wrong thing: %s", event.element.name))
return
end
local always_visible = global.evogui[player.name].always_visible
local sensor_name = event.element.name:sub(4,-1)
if event.element.state then
always_visible[sensor_name] = true
else
always_visible[sensor_name] = nil
end
end
local function toggle_in_popup(event)
local player = game.get_player(event.player_index)
if event.element.name:sub(1,3) ~= "IP_" then
error(string.format("toggle_in_popup called on the wrong thing: %s", event.element.name))
return
end
local in_popup = global.evogui[player.name].in_popup
local sensor_name = event.element.name:sub(4,-1)
if event.element.state then
in_popup[sensor_name] = true
else
in_popup[sensor_name] = nil
end
end
local function add_sensor_table_row(table, sensor, always_visible, in_popup)
local sensor_always_visible = always_visible[sensor.name] ~= nil
local sensor_in_popup = in_popup[sensor.name] ~= nil
table.add{type="label", caption=sensor.display_name}
table.add{type="checkbox", name="AV_"..sensor.name,
caption={"settings_always_visible"}, state=sensor_always_visible}
table.add{type="checkbox", name="IP_"..sensor.name,
caption={"settings_in_popup"}, state=sensor_in_popup}
evogui.on_click["AV_"..sensor.name] = toggle_always_visible
evogui.on_click["IP_"..sensor.name] = toggle_in_popup
end
function evogui.on_click.evoGUI_settings(event)
local player = game.get_player(event.player_index)
if player.gui.center.evoGUI_settingsGUI then return end
evogui.create_player_globals(player)
local player_data = global.evogui[player.name]
local root = player.gui.center.add{type="frame",
direction="vertical",
name="evoGUI_settingsGUI",
caption={"settings_title"}}
local table = root.add{type="table", colspan=3}
for _, sensor in ipairs(evogui.value_sensors) do
add_sensor_table_row(table, sensor, player_data.always_visible, player_data.in_popup)
end
for _, sensor in ipairs(player_data.personal_sensors) do
add_sensor_table_row(table, sensor, player_data.always_visible, player_data.in_popup)
end
local buttons = root.add{type="flow", 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)
if player.gui.center.evoGUI_settingsGUI ~= nil then
player.gui.center.evoGUI_settingsGUI.destroy()
end
end