-
Notifications
You must be signed in to change notification settings - Fork 4
/
VotePanel.ttslua
195 lines (177 loc) · 6.95 KB
/
VotePanel.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
#include Localization.ttslua
#include GUIDs.ttslua
--[[
Vote Panel
Made by Sionar
--]]
------------------Constants
VERSION = '2.0.0'
DISTANCE = 3
RADIUS = 40
COLORS_ALL = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink', 'Magenta', 'Lavender', 'Navy', 'Cyan', 'Mint', 'Lime', 'Peach', 'Coral', 'Maroon', 'Silver'}
------------------Functions
function onLoad()
LANGUAGE = Global.getVar('LANGUAGE')
if not LABELS[LANGUAGE] then
LANGUAGE = 'EN-US'
end
end
function createButtons()
self.clearButtons()
local params = {}
local colors = Global.getTable('colors')
local angle = Global.getTable('angle')
local lifeTokens = Global.getTable('lifeTokens')
local canNominate = Global.getTable('canNominate')
local canBeNominated = Global.getTable('canBeNominated')
local hasVote = Global.getTable('hasVote')
local voted = Global.getTable('voted')
local currentNominator = Global.getVar('currentNominator')
local currentNominated = Global.getVar('currentNominated')
local scale
for k,color in pairs(colors) do
if lifeTokens[color].object == nil then
scale = {0,0,0}
else
scale = {1,1,1}
end
params = {click_function = 'nominated' .. color, function_owner = self, label = LABELS[LANGUAGE].VOTING_BUTTONS.nominate .. color, position = radiusNominated(RADIUS, -1 * angle[color], 1), rotation = {0, angle[color], 0}, color = {53/255,52/255,60/255}, font_color = {218/255, 25/255, 24/255}, width = 1000, height = 500, font_size = 200, scale = scale, tooltip = 'Right click to enable/disable being nominated'}
if not canBeNominated[color] then
params.color = {0,0,0}
params.font_color = {0,0,0}
end
if currentNominated == color then
params.color = {218/255, 25/255, 24/255}
params.font_color = {1,1,1}
end
self.createButton(params)
params = {click_function = 'vote' .. color, function_owner = self, label = LABELS[LANGUAGE].VOTING_BUTTONS.vote, position = radius(RADIUS, -1 * angle[color], 1), color = {53/255,52/255,60/255}, rotation = {0, angle[color], 0}, font_color = {1,1,1}, width = 1000, height = 500, font_size = 400, scale = scale}
if not hasVote[color] then
params.color = {0,0,0}
params.font_color = {0,0,0}
end
if voted[color] then
params.color = {53/255,52/255,60/255}
params.font_color = {1,1,1}
end
self.createButton(params)
params = {click_function = 'nominate' .. color, function_owner = self, label = LABELS[LANGUAGE].VOTING_BUTTONS.become_nom, position = radiusNominate(RADIUS, -1 * angle[color], 1), rotation = {0, angle[color], 0}, color = {53/255,52/255,60/255}, font_color = {58/255, 150/255, 255/255}, width = 1000, height = 500, font_size = 200, scale = scale, tooltip = 'Right click to enable/disable allowing nomination'}
if not canNominate[color] then
params.color = {0,0,0}
params.font_color = {0,0,0}
end
if currentNominator == color then
params.color = {58/255, 150/255, 255/255}
params.font_color = {1,1,1}
end
self.createButton(params)
end
end
function radius(rad, angle, height)
return {rad*math.sin(angle*math.pi/180), height, rad*math.cos(angle*math.pi/180)}
end
function radiusNominate(rad, angle, height)
return {rad*math.sin(angle*math.pi/180) - DISTANCE * math.cos(angle*math.pi/180), height, rad*math.cos(angle*math.pi/180) + DISTANCE * math.sin(angle*math.pi/180)}
end
function radiusNominated(rad, angle, height)
return {rad*math.sin(angle*math.pi/180) + DISTANCE * math.cos(angle*math.pi/180), height, rad*math.cos(angle*math.pi/180) - DISTANCE * math.sin(angle*math.pi/180)}
end
function vote(clickedObject, playerColor, color)
local callParams = {}
if playerColor == color or playerColor == 'Black' then
callParams.voter = color
Global.call('vote', callParams)
end
end
for k,color in pairs(COLORS_ALL) do
_G['vote' .. color] = function(clickedObject, playerColor)
vote(clickedObject, playerColor, color)
end
end
function nominate(clickedButton, playerColor, rightClick, color)
if not rightClick then
local callParams = {}
if playerColor == color or playerColor == 'Black' then
callParams.nominator = color
Global.call('nominate', callParams)
end
else
if playerColor == 'Black' then
toggleDisableNominate(color)
end
end
end
for k,color in pairs(COLORS_ALL) do
_G['nominate' .. color] = function(clickedObject, playerColor, rightClick)
nominate(clickedObject, playerColor, rightClick, color)
end
end
function nominated(clickedButton, playerColor, rightClick, color)
if not rightClick then
local callParams = {}
callParams.player = playerColor
callParams.target = color
Global.call('nominated', callParams)
else
if playerColor == 'Black' then
toggleDisableNominated(color)
end
end
end
for k,color in pairs(COLORS_ALL) do
_G['nominated' .. color] = function(clickedObject, playerColor, rightClick)
nominated(clickedObject, playerColor, rightClick, color)
end
end
function toggleDisableNominate(color)
local canNominate = Global.getTable('canNominate')
local colors = Global.getTable('colors')
local index
for k,v in pairs(colors) do
if v == color then
index = k
break
end
end
local buttonParams = {}
if canNominate[color] == true then
canNominate[color] = false
buttonParams.index = (index - 1) * 3 + 2
buttonParams.color = {0,0,0}
buttonParams.font_color = {0,0,0}
else
canNominate[color] = true
buttonParams.index = (index - 1) * 3 + 2
buttonParams.color = {53/255,52/255,60/255}
buttonParams.font_color = {58/255, 150/255, 255/255}
end
self.editButton(buttonParams)
Global.setTable('canNominate', canNominate)
Global.call('resetCurrentNominations')
end
function toggleDisableNominated(color)
local canBeNominated = Global.getTable('canBeNominated')
local colors = Global.getTable('colors')
local index
for k,v in pairs(colors) do
if v == color then
index = k
break
end
end
local buttonParams = {}
if canBeNominated[color] == true then
canBeNominated[color] = false
buttonParams.index = (index - 1) * 3 + 0
buttonParams.color = {0,0,0}
buttonParams.font_color = {0,0,0}
else
canBeNominated[color] = true
buttonParams.index = (index - 1) * 3 + 0
buttonParams.color = {53/255,52/255,60/255}
buttonParams.font_color = {218/255, 25/255, 24/255}
end
self.editButton(buttonParams)
Global.setTable('canBeNominated', canBeNominated)
Global.call('resetCurrentNominations')
end