-
Notifications
You must be signed in to change notification settings - Fork 0
/
LowChampionPointFinder.lua
388 lines (342 loc) · 12.5 KB
/
LowChampionPointFinder.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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
-- Libraries --
local LAM = LibAddonMenu2
-- Local Vars --
LowChampionPointFinder = {}
local ADDON_NAME = "LowChampionPointFinder"
local ADDON_VERSION = "1.02"
local DATABASE_VERSION = "1.02"
local LOADED = false
local EMPTY_GROUP = {lowCp=0, highCp=3600, text="", color={r=0.0, g=0.0, b=0.0, a=0.0}}
local DB
local DEFAULTS = {
useGradients = false,
group1GradientStart = {r=0.4, g=1.0, b=1.0, a=1.0},
group6GradientEnd = {r=1.0, g=0.0, b=0.5, a=0.5},
fontSize = 32,
CpOffset = {x = 0, y = 60},
isPvpOnly = true, -- Controls if CP shows in non pvp zones (IE Duels)
isAttackableOnly = true, -- Controls if you see friendly players CP
ChampionPointGroups = {
[1] = {lowCp=0, highCp=160, text="Low Cp", color={r=0.0, g=1.0, b=1.0, a=1.0}},
[2] = {lowCp=160, highCp=600, text="Low Cp", color={r=0.0, g=1.0, b=0.8, a=1.0}},
[3] = {lowCp=600, highCp=810, text="Low Cp", color={r=0.0, g=1.0, b=0.5, a=1.0}},
[4] = {lowCp=810, highCp=1200, text="", color={r=.8, g=1.0, b=0.0, a=0.8}},
[5] = {lowCp=1200, highCp=1500, text="", color={r=1.0, g=0.2, b=0.0, a=0.5}},
[6] = {lowCp=1500, highCp=3600, text="", color={r=1.0, g=0.0, b=0.0, a=0.5}},
}
}
-- Local Functions --
local function FindChampionPointGroup(Cp,groups)
for i, group in ipairs(groups) do
if Cp >= group.lowCp and Cp <= group.highCp then
local nextGroupColor;
if i == #groups then
nextGroupColor = DB.group6GradientEnd
elseif i == 1 then
nextGroupColor = DB.group1GradientStart
else
nextGroupColor = groups[i-1].color
end
return group, nextGroupColor
end
end
return EMPTY_GROUP,EMPTY_GROUP.color
end
local function GetTargetChampionPoints()
if IsUnitPlayer("reticleover") then
local championPoints = GetUnitChampionPoints("reticleover")
return championPoints
else
return 160
end
end
local function SetColorGradient(color1,color2,view, percentage)
local r = color1.r + (color2.r - color1.r) * percentage
local g = color1.g + (color2.g - color1.g) * percentage
local b = color1.b + (color2.b - color1.b) * percentage
local a = color1.a + (color2.a - color1.a) * percentage
view:SetColor(r, g, b, a)
end
local function SetColor(color,view)
local red = color.r
local green = color.g
local blue = color.b
local alpha = color.a
view:SetColor(red, green, blue, alpha)
end
local function UpdateUi()
if LOADED == true then
local targetName = GetUnitName("reticleover")
local canAttack = IsUnitAttackable("reticleover")
local isPlayer = IsUnitPlayer("reticleover")
local isTargetDead = IsUnitDead("reticleover")
if (IsPlayerInAvAWorld() == false and DB.isPvpOnly== true) or (targetName == "") or (canAttack == false and DB.isAttackableOnly == true) or (isPlayer == false) or (isTargetDead == true) then
LowChampionPointFinderView:SetAlpha(0)
LowChampionPointFinderViewCp:SetText("")
else
LowChampionPointFinderView:SetAlpha(1)
local targetChampionPoints = GetTargetChampionPoints()
local matchingGroup, nextGroupColor = FindChampionPointGroup(targetChampionPoints,DB.ChampionPointGroups)
if nextGroup == nil then
nextGroup = matchingGroup
end
local finalText = string.gsub(matchingGroup.text,"{cp}",targetChampionPoints)
LowChampionPointFinderViewCp:SetText(finalText)
if (DB.useGradients == true) then
SetColorGradient(nextGroupColor,matchingGroup.color,LowChampionPointFinderViewCp,(targetChampionPoints/matchingGroup.highCp))
else
SetColor(matchingGroup.color,LowChampionPointFinderViewCp)
end
end
end
end
local function TargetChanged()
UpdateUi()
end
local function CombatEvent()
UpdateUi()
end
local function CreateAnchors()
LowChampionPointFinderViewCp:ClearAnchors()
LowChampionPointFinderViewCp:SetAnchor(TOP,LowChampionPointFinderView,TOP,DB.CpOffset.x,DB.CpOffset.y)
end
local function UpdateFont() --Same font as squishyfinder <3 --
LowChampionPointFinderViewCp:SetFont("$(BOLD_FONT)|" .. DB.fontSize .. "|soft-shadow-thick")
end
local function createControlsForGroup(i, group, default)
local options = { }
table.insert(options, {
type = "editbox",
name = "Group " .. i .. " CP (lower bound)",
tooltip = "Color group defined by CP above this value",
textType = TEXT_TYPE_NUMERIC_UNSIGNED_INT,
default = default.lowCp,
getFunc = function() return group.lowCp end,
setFunc = function(text)
group.lowCp = tonumber(text)
if (group.lowCp < 0 or group.lowCp > 3600) then
group.lowCp = 0
end
end,
})
table.insert(options, {
type = "editbox",
name = "Group " .. i .. " CP (upper bound)",
tooltip = "Color group defined by CP under this value",
textType = TEXT_TYPE_NUMERIC_UNSIGNED_INT,
default = default.highCp,
getFunc = function() return group.highCp end,
setFunc = function(text)
group.highCp = tonumber(text)
if (group.highCp < 0 or group.highCp > 3600) then
group.highCp = 3600
end
end,
})
table.insert(options, {
type = "editbox",
name = "Group " .. i .. " text",
tooltip = "The text that is displayed when the target's CP is within this value. Leave empty to show nothing. The substring `{cp}` can be used to insert the targets champion points if desired.",
default = default.text,
getFunc = function() return group.text end,
setFunc = function(text)
group.text = text
end,
})
table.insert(options, {
type = "colorpicker",
name = "Group " .. i .. " color",
default = default.color,
getFunc = function()
return group.color.r, group.color.g, group.color.b, group.color.a
end,
setFunc = function(r,g,b,a)
group.color = { r=r, g=g, b=b, a=a }
end,
})
table.insert(options, {
type = "description",
text = "",
})
return options
end
-- Creating LAM2 MENU --
local function CreateSettingsMenu()
local panelName = "LowChampionPointFinderPanel"
local panelData = {
type = "panel",
name = ADDON_NAME,
displayName = "Low Champion Point Finder",
author = "EHansonn",
version = ADDON_VERSION,
registerForRefresh = true,
registerForDefaults = true,
}
local controlPanel = LAM:RegisterAddonPanel(panelName,panelData)
local options = {
{
type = "header",
name = "Visiblity Settings",
},
{
type = "checkbox",
name = "PvP Zone Only",
textType = TEXT_TYPE_NUMERIC_UNSIGNED_INT,
tooltip = "Turn OFF to see CP in non pvp zones",
default = DEFAULTS.isPvpOnly,
getFunc = function() return DB.isPvpOnly end,
setFunc = function(value)
DB.isPvpOnly = value
end,
},
{
type = "checkbox",
name = "Attackable (enemy) targets only",
textType = TEXT_TYPE_NUMERIC_UNSIGNED_INT,
tooltip = "Turn OFF to see non attackable targets (friendly players)",
default = DEFAULTS.isAttackableOnly,
getFunc = function() return DB.isAttackableOnly end,
setFunc = function(value)
DB.isAttackableOnly = value
end,
},
{
type = "checkbox",
name = "Use color gradients",
textType = TEXT_TYPE_NUMERIC_UNSIGNED_INT,
tooltip = "Enable if you want a gradient. If the cp is within group 1, it will have a gradient between the start gradient and group 1s color. For example, if its in group 3s cp, it will go from group 2s color -> group 3s color.",
default = DEFAULTS.useGradients,
getFunc = function() return DB.useGradients end,
setFunc = function(value)
DB.useGradients = value
end,
},
{
type = "colorpicker",
name = "[OPTIONAL] Start gradient for group 1",
tooltop = "Optional. If the target is within group 1s cp range, it gradient will go from this color -> group1s color",
default = DEFAULTS.group1GradientStart,
getFunc = function()
return DB.group1GradientStart.r, DB.group1GradientStart.g, DB.group1GradientStart.b, DB.group1GradientStart.a
end,
setFunc = function(r,g,b,a)
DB.group1GradientStart = { r=r, g=g, b=b, a=a }
end,
},
{
type = "colorpicker",
name = "[OPTIONAL] End gradient for group 6",
tooltop = "Optional. If the target is within group 6s cp range, it gradient will go from this group6's color -> this color",
default = DEFAULTS.group6GradientEnd,
getFunc = function()
return DB.group6GradientEnd.r, DB.group6GradientEnd.g, DB.group6GradientEnd.b, DB.group6GradientEnd.a
end,
setFunc = function(r,g,b,a)
DB.group6GradientEnd = { r=r, g=g, b=b, a=a }
end,
},
{
type = "button",
name = "Reset to defaults",
tooltip = "Resets to default values",
func = function()
DB.isAttackableOnly = DEFAULTS.isAttackableOnly
DB.isPvpOnly = DEFAULTS.isPvpOnly
DB.useGradients = DEFAULTS.useGradients
DB.group1GradientStart = DEFAULTS.group1GradientStart
DB.group6GradientEnd = DEFAULTS.group6GradientEnd
end,
},
{
type = "header",
name = "Alignment Settings",
},
{
type = "editbox",
name = "Font size",
textType = TEXT_TYPE_NUMERIC_UNSIGNED_INT,
tooltip = "Change how big the text is",
default = DEFAULTS.fontSize,
getFunc = function() return DB.fontSize end,
setFunc = function(text)
DB.fontSize = tonumber(text)
UpdateFont()
end,
},
{
type = "editbox",
name = "Alert horizontal offset",
tooltip = "Positive ->, Negative <-",
textType = TEXT_TYPE_NUMERIC_INT,
default = DEFAULTS.CpOffset.x,
getFunc = function() return DB.CpOffset.x end,
setFunc = function(text)
DB.CpOffset.x = tonumber(text)
CreateAnchors()
end,
},
{
type = "editbox",
name = "Alert vertical offset",
tooltip = "Positive down, negative up",
textType = TEXT_TYPE_NUMERIC_INT,
default = DEFAULTS.CpOffset.y,
getFunc = function() return DB.CpOffset.y end,
setFunc = function(text)
DB.CpOffset.y = tonumber(text)
CreateAnchors()
end,
},
{
type = "button",
name = "Reset positions",
tooltip = "Resets positions",
func = function()
DB.CpOffset.x = DEFAULTS.CpOffset.x
DB.CpOffset.y = DEFAULTS.CpOffset.y
DB.fontSize = DEFAULTS.fontSize
CreateAnchors()
UpdateFont()
end,
},
{
type = "header",
name = "Group settings",
},
{
type = "button",
name = "Reset values",
tooltip = "Resets all values back to their defaults",
func = function()
for i, group in ipairs(DB.ChampionPointGroups) do
group.lowCp = DEFAULTS.ChampionPointGroups[i].lowCp
group.highCp = DEFAULTS.ChampionPointGroups[i].highCp
group.color = DEFAULTS.ChampionPointGroups[i].color
group.text = DEFAULTS.ChampionPointGroups[i].text
end
end,
},
}
local optionsIndex = #options +1
for i=1,#DEFAULTS.ChampionPointGroups do
local result = createControlsForGroup(i, DB.ChampionPointGroups[i], DEFAULTS.ChampionPointGroups[i])
for resulti=1,#result do
options[optionsIndex] = result[resulti]
optionsIndex = optionsIndex + 1
end
end
LAM:RegisterOptionControls(panelName,options)
end
local function OnLoad(eventCode,addonName)
if addonName == ADDON_NAME then
EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED)
DB = ZO_SavedVars:NewAccountWide("LowChampionPointFinderVars", DATABASE_VERSION, nil, DEFAULTS)
CreateSettingsMenu()
CreateAnchors()
UpdateFont()
LOADED = true
EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_RETICLE_TARGET_CHANGED, TargetChanged)
EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_COMBAT_EVENT, CombatEvent)
end
end
EVENT_MANAGER:RegisterForEvent(ADDON_NAME,EVENT_ADD_ON_LOADED,OnLoad)