forked from sionar/Botc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableControls.ttslua
248 lines (211 loc) · 8.31 KB
/
TableControls.ttslua
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
--[[
Table Controls
Made by Sionar
--]]
------------------Constants
VERSION = '1.5.3'
BUTTON_W = 500
BUTTON_H = 400
FONT_SIZE = 120
BUTTON_COLOR = {0,0,0}
BUTTON_FONT_COLOR = {1,1,1}
#include GUIDs.ttslua
------------------Variables
objects = {}
tableSize = 10
backgroundDeleted = false
maxSeats = 20
------------------Functions
function onLoad(saveString)
tableSize = Global.getVar('tableSize')
assignObjects()
refreshUI()
self.setDescription('v ' .. VERSION .. '\nMade by Sionar')
if not (saveString == '') then
local save = JSON.decode(saveString)
maxSeats = save['m']
end
end
function onSave()
local save = {}
save['m'] = maxSeats
local saveString = JSON.encode(save)
return saveString
end
function assignObjects()
objects.bgBox = getObjectFromGUID(BG_BOX_GUID)
objects.clockControls = getObjectFromGUID(CLOCK_CONTROLS_GUID)
objects.toolbag = getObjectFromGUID(TOOL_BAG_GUID)
end
function decTableSize(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
tableSize = tableSize - 1
if tableSize < 5 then
tableSize = 5
end
callResize()
refreshUI()
end
function incTableSize(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
tableSize = tableSize + 1
if tableSize > maxSeats then
tableSize = maxSeats
end
callResize()
refreshUI()
end
function setTableSize(clickedObject, playerColor, value, stillEditing)
if not stillEditing then
if playerColor ~= 'Black' then
refreshUI()
return
end
tableSize = tonumber(value)
if tableSize == nil then
tableSize = 10
end
if tableSize < 5 then
tableSize = 5
elseif tableSize > maxSeats then
tableSize = maxSeats
end
callResize()
refreshUI()
end
end
function callResize()
Global.call('setTokenTable')
Global.call('setDecalTable')
Global.setVar('tableSize', tableSize)
Global.call('resizeTable')
Global.call('moveTokens')
Global.call('moveDecals')
end
function callShufflePlayers(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
Global.call('shufflePlayers')
end
function callPruneSeats(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
Global.call('pruneSeats')
end
function callToggleLights(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
Global.call('toggleLights', {switching = true})
end
function deleteBackground(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
backgroundDeleted = true
local allObjects = getAllObjects()
for k,v in pairs(allObjects) do
if v.getName() == 'Background' then
v.destruct()
end
end
if objects.bgBox ~= nil then
objects.bgBox.setScale({0.5,0.5,0.5})
end
local objects = Global.getTable('objects')
objects.bgLight = nil
Global.setTable('objects', objects)
end
function callReset(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
local options = Global.getTable('options')
local safetyExpired = Global.getVar('safetyExpired')
if options.safetyOn then
if safetyExpired then
Player['Black'].broadcast('Click again to reset the game.', {1,0,0})
Global.call('startSafetyCooldown')
else
Global.call('resetGame')
end
else
Global.call('resetGame')
end
end
function callClockStyle1(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
if objects.clockControls ~= nil then
objects.clockControls.call('setClockStyle', {style = 1})
end
end
function callClockStyle2(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
if objects.clockControls ~= nil then
objects.clockControls.call('setClockStyle', {style = 2})
end
end
function modifySeats(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
if objects.toolbag == nil then
return
end
for k,v in pairs(objects.toolbag.getObjects()) do
if v.name == 'Seat Tool' then
objects.toolbag.takeObject({index = v.index})
end
end
end
------------------User Interface
function refreshUI()
self.clearButtons()
self.clearInputs()
local buttonParam, inputParam
buttonParam = {click_function = 'nullFunc', function_owner = self, label = 'Table Size', color = {0,0,0,1}, font_color = stringColorToRGB('White'), color = stringColorToRGB('Black'),
position = {0,0.2,-1.6}, width = 0, height = 0, font_size = FONT_SIZE}
self.createButton(buttonParam)
buttonParam = {click_function = 'decTableSize', function_owner = self, label = '-', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {-1.05,0.2,-1.1}, width = 300, height = 300, font_size = FONT_SIZE, tooltip = 'Remove a seat.'}
self.createButton(buttonParam)
inputParam = {input_function = 'setTableSize', function_owner = self, position = {0, 0.2, -1.1}, width = 600, height = 300, font_size = 260, tooltip = 'Table Size', validation = 2, alignment = 3, value = tableSize, color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR}
self.createInput(inputParam)
buttonParam = {click_function = 'incTableSize', function_owner = self, label = '+', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {1.05,0.2,-1.1}, width = 300, height = 300, font_size = FONT_SIZE, tooltip = 'Add a seat.'}
self.createButton(buttonParam)
buttonParam = {click_function = 'callClockStyle1', function_owner = self, label = 'Clock Style 1', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {-0.8,0.2,-0.4}, width = 750, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Set the clock style to style 1.'}
self.createButton(buttonParam)
buttonParam = {click_function = 'callClockStyle2', function_owner = self, label = 'Clock Style 2', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {0.8,0.2,-0.4}, width = 750, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Set the clock style to style 2.'}
self.createButton(buttonParam)
buttonParam = {click_function = 'callShufflePlayers', function_owner = self, label = 'Shuffle\nSeats', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {-1.2,0.2,0.4}, width = 550, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Shuffle seats (Before the game starts).'}
self.createButton(buttonParam)
buttonParam = {click_function = 'callPruneSeats', function_owner = self, label = 'Prune\nSeats', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {0,0.2,0.4}, width = 550, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Get rid of empty seats and shrink the table (Before the game starts).'}
self.createButton(buttonParam)
buttonParam = {click_function = 'modifySeats', function_owner = self, label = 'Modify\nSeats', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {1.2,0.2,0.4}, width = 550, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Set which seats are in the game.'}
self.createButton(buttonParam)
buttonParam = {click_function = 'callToggleLights', function_owner = self, label = 'Toggle\nLights', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {-1.2,0.2,1.2}, width = 550, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Turn on/off the lights.'}
self.createButton(buttonParam)
buttonParam = {click_function = 'deleteBackground', function_owner = self, label = 'Delete\nBackground', color = BUTTON_COLOR, font_color = BUTTON_FONT_COLOR,
position = {0,0.2,1.2}, width = 550, height = BUTTON_H, font_size = FONT_SIZE - 40, tooltip = 'Delete the background objects (Cannot be restored).'}
self.createButton(buttonParam)
buttonParam = {click_function = 'callReset', function_owner = self, label = 'Reset\nTable', font_color = stringColorToRGB('White'), color = stringColorToRGB('Red'),
position = {1.2,0.2,1.2}, width = 550, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Reset the game.'}
self.createButton(buttonParam)
end