-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathPlater_Resources_Options.lua
432 lines (369 loc) · 17 KB
/
Plater_Resources_Options.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
local addonId, platerInternal = ...
local Plater = _G.Plater
local GameCooltip = GameCooltip2
local DF = DetailsFramework
local _
local UnitPower = _G.UnitPower
local UnitPowerMax = _G.UnitPowerMax
local abs = _G.abs
local hookbox_label_y = -130
local CONST_GLOBALSETTINGS_X = 240
local CONST_GLOBALSETTINGS_Y = hookbox_label_y
local CONST_SCROLLBOX_WIDTH = 200
local CONST_SCROLLBOX_HEIGHT = 495
local CONST_SCROLLBOX_LINES = 20
local CONST_SCROLLBOX_LINE_HEIGHT = 20
local CONST_SCROLLBOX_LINE_BACKDROP = {bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1}
local CONST_SCROLLBOX_LINE_BACKDROP_COLOR = {0, 0, 0, 0.5}
local CONST_SCROLLBOX_LINE_BACKDROP_COLOR_SELECTED = {.6, .6, .1, 0.7}
local CONST_SCROLLBOX_LINE_BACKDROP_COLOR_HOVER = {.3, .3, .3, 0.5}
local CONST_OPTIONSFRAME_WIDTH = 864
local CONST_ENUMNAME_COMBOPOINT = "ComboPoints"
local CONST_ENUMNAME_HOLYPOWER = "HolyPower"
local CONST_ENUMNAME_RUNES = "Runes"
local CONST_ENUMNAME_ARCANECHARGES = "ArcaneCharges"
local CONST_ENUMNAME_CHI = "Chi"
local CONST_ENUMNAME_SOULCHARGES = "SoulShards"
local CONST_ENUMNAME_ESSENCE = "Essence"
local startX, startY, heightSize = 10, platerInternal.optionsYStart, 755
--templates
local options_text_template = DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")
local options_dropdown_template = DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
local options_switch_template = DF:GetTemplate("switch", "OPTIONS_CHECKBOX_TEMPLATE")
local options_slider_template = DF:GetTemplate("slider", "OPTIONS_SLIDER_TEMPLATE")
local options_button_template = DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE")
--localization
local LOC = DF.Language.GetLanguageTable(addonId)
function Plater.Resources.GetResourceEnumNameForPlayer()
local playerSerial = Plater.PlayerGUID or UnitGUID("player")
local playerClassLoc, playerClass = UnitClass("player")
if (not Plater.db.profile.resources_settings.chr[playerSerial]) then
if (playerClass == "ROGUE" or playerClass == "DRUID") then
Plater.db.profile.resources_settings.chr[playerSerial] = CONST_ENUMNAME_COMBOPOINT
return CONST_ENUMNAME_COMBOPOINT
elseif (playerClass == "WARLOCK") then
Plater.db.profile.resources_settings.chr[playerSerial] = CONST_ENUMNAME_SOULCHARGES
return CONST_ENUMNAME_SOULCHARGES
elseif (playerClass == "MONK") then
Plater.db.profile.resources_settings.chr[playerSerial] = CONST_ENUMNAME_CHI
return CONST_ENUMNAME_CHI
elseif (playerClass == "MAGE") then
Plater.db.profile.resources_settings.chr[playerSerial] = CONST_ENUMNAME_ARCANECHARGES
return CONST_ENUMNAME_ARCANECHARGES
elseif (playerClass == "DEATHKNIGHT") then
Plater.db.profile.resources_settings.chr[playerSerial] = CONST_ENUMNAME_RUNES
return CONST_ENUMNAME_RUNES
elseif (playerClass == "PALADIN") then
Plater.db.profile.resources_settings.chr[playerSerial] = CONST_ENUMNAME_HOLYPOWER
return CONST_ENUMNAME_HOLYPOWER
elseif (playerClass == "EVOKER") then
Plater.db.profile.resources_settings.chr[playerSerial] = CONST_ENUMNAME_ESSENCE
return CONST_ENUMNAME_ESSENCE
end
end
return Plater.db.profile.resources_settings.chr[playerSerial]
end
--return the resource Id for the player, resourceId is used to query how much resources the player has UnitPower and UnitPowerMax
function Plater.Resources.GetResourceIdForPlayer()
local playerClassLoc, playerClass = UnitClass("player")
if (playerClass == "ROGUE" or playerClass == "DRUID") then
return Enum.PowerType[CONST_ENUMNAME_COMBOPOINT]
elseif (playerClass == "WARLOCK") then
return Enum.PowerType[CONST_ENUMNAME_SOULCHARGES]
elseif (playerClass == "MONK") then
return Enum.PowerType[CONST_ENUMNAME_CHI]
elseif (playerClass == "MAGE") then
return Enum.PowerType[CONST_ENUMNAME_ARCANECHARGES]
elseif (playerClass == "DEATHKNIGHT") then
return Enum.PowerType[CONST_ENUMNAME_RUNES]
elseif (playerClass == "PALADIN") then
return Enum.PowerType[CONST_ENUMNAME_HOLYPOWER]
elseif (playerClass == "EVOKER") then
return Enum.PowerType[CONST_ENUMNAME_ESSENCE]
end
--return none if not found, this will trigger an error on new resources in the future
end
function Plater.Resources.BuildResourceOptionsTab(frame)
--if there's no default resource name for this character yet, calling this will set a default
Plater.Resources.GetResourceEnumNameForPlayer()
--left menu
local resourceDisplaysAvailable = { --name should be able to get from the client
{name = "Combo Point", defaultClass = {"DRUID", "ROGUE"}, enumName = CONST_ENUMNAME_COMBOPOINT, iconTexture = false, iconAtlas = "ClassOverlay-ComboPoint"}, --4
{name = "Holy Power", defaultClass = {"PALADIN"}, enumName = CONST_ENUMNAME_HOLYPOWER, iconTexture = [[Interface\PLAYERFRAME\ClassOverlayHolyPower]], iconCoords = {0.530999, 0.6619999, 0.01600000, 0.3479999}}, --9
{name = "Runes", defaultClass = {"DEATHKNIGHT"}, enumName = CONST_ENUMNAME_RUNES, iconTexture = [[Interface\PLAYERFRAME\UI-PlayerFrame-Deathknight-SingleRune]], iconCoords = {0, 1, 0, 1}}, --5
{name = "Arcane Charges", defaultClass = {"MAGE"}, enumName = CONST_ENUMNAME_ARCANECHARGES, iconTexture = [[Interface\PLAYERFRAME\MageArcaneCharges]], iconCoords = {64/256, 91/256, 64/128, 91/128}}, --16
{name = "Chi", defaultClass = {"MONK"}, enumName = CONST_ENUMNAME_CHI, iconTexture = [[Interface\PLAYERFRAME\MonkLightPower]], iconCoords = {0.1, .9, 0.1, .9}}, --12
{name = "Soul Shards", defaultClass = {"WARLOCK"}, enumName = CONST_ENUMNAME_SOULCHARGES, iconTexture = [[Interface\PLAYERFRAME\UI-WARLOCKSHARD]], iconCoords = {0/64, 18/64, 0/128, 18/128}}, --7
{name = "Essence", defaultClass = {"EVOKER"}, enumName = CONST_ENUMNAME_ESSENCE, iconTexture = false, iconAtlas = "UF-Essence-Icon"}, --8
}
local refreshResourceScrollBox = function(self, data, offset, totalLines)
for i = 1, totalLines do
local index = i + offset
local resource = data[index]
if (resource) then
local isSelected = Plater.db.profile.resources_settings.chr[Plater.PlayerGUID] == resource.enumName
local line = self:GetLine(i)
line.resource = resource
line.checkBox:SetValue(isSelected)
line.text:SetText(resource.name)
if (isSelected) then
line:SetBackdropColor(unpack(CONST_SCROLLBOX_LINE_BACKDROP_COLOR_SELECTED))
line.isSelected = true
else
line:SetBackdropColor(unpack(CONST_SCROLLBOX_LINE_BACKDROP_COLOR))
line.isSelected = false
end
if (resource.iconTexture) then
line.icon:SetTexture(resource.iconTexture)
if (resource.iconCoords) then
line.icon:SetTexCoord(unpack(resource.iconCoords))
else
line.icon:SetTexCoord(unpack(0, 1, 0, 1))
end
elseif (resource.iconAtlas) then
line.icon:SetAtlas(resource.iconAtlas)
end
end
end
end
local selectResourceScrollBox = DF:CreateScrollBox(frame, "$parentResourceScrollBox", refreshResourceScrollBox, resourceDisplaysAvailable, CONST_SCROLLBOX_WIDTH, CONST_SCROLLBOX_HEIGHT, CONST_SCROLLBOX_LINES, CONST_SCROLLBOX_LINE_HEIGHT)
DF:ReskinSlider(selectResourceScrollBox)
selectResourceScrollBox:SetPoint("topleft", frame, "topleft", 5, hookbox_label_y)
frame.selectResourceScrollBox = selectResourceScrollBox
local selectResourceLabel = DF:CreateLabel(frame, "Select which resource to use on this character:", 12, "orange")
selectResourceLabel:SetPoint("bottomleft", selectResourceScrollBox, "topleft", 0, 4)
local onEnterResourceLine = function(self)
if (not self.isSelected) then
self:SetBackdropColor(unpack(CONST_SCROLLBOX_LINE_BACKDROP_COLOR_HOVER))
end
end
local onLeaveResourceLine = function(self)
if (not self.isSelected) then
self:SetBackdropColor(unpack(CONST_SCROLLBOX_LINE_BACKDROP_COLOR))
end
end
local onSelectResource = function(self)
end
local toggleResource = function(self)
local line = self:GetParent()
local resource = line.resource
Plater.db.profile.resources_settings.chr[Plater.PlayerGUID] = resource.enumName
selectResourceScrollBox:Refresh()
Plater.Resources.UpdateResourceFrameToUse()
end
local resourceListCreateLine = function(self, index)
--create a new line
local line = CreateFrame("button", "$parentLine" .. index, self, BackdropTemplateMixin and "BackdropTemplate")
--set its parameters
line:SetPoint("topleft", self, "topleft", 0, -((index-1) * (CONST_SCROLLBOX_LINE_HEIGHT+1)))
line:SetSize(CONST_SCROLLBOX_WIDTH, CONST_SCROLLBOX_LINE_HEIGHT)
line:SetScript("OnEnter", onEnterResourceLine)
line:SetScript("OnLeave", onLeaveResourceLine)
line:SetScript("OnMouseUp", onSelectResource)
line:SetBackdrop(CONST_SCROLLBOX_LINE_BACKDROP)
line:SetBackdropColor(unpack(CONST_SCROLLBOX_LINE_BACKDROP_COLOR))
line:SetBackdropBorderColor (0, 0, 0, 0)
local checkBox = DF:CreateSwitch(line, toggleResource, false, 20, 20, _, _, "checkbox", "$parentToggleResourceActivation" .. index, _, _, _, _, DF:GetTemplate("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE"))
checkBox:SetAsCheckBox()
checkBox:SetPoint("left", line, "left", 2, 0)
checkBox.index = index
local resourceIcon = line:CreateTexture("$parentIcon", "artwork")
resourceIcon:SetPoint("left", checkBox.widget, "right", 2, 0)
resourceIcon:SetSize(CONST_SCROLLBOX_LINE_HEIGHT-2, CONST_SCROLLBOX_LINE_HEIGHT-2)
local resourceName = line:CreateFontString("$parentName", "artwork", "GameFontNormal")
resourceName:SetPoint("left", resourceIcon, "right", 2, 0)
line.checkBox = checkBox
line.text = resourceName
line.icon = resourceIcon
return line
end
for i = 1, CONST_SCROLLBOX_LINES do
selectResourceScrollBox:CreateLine(resourceListCreateLine)
end
selectResourceScrollBox:Refresh()
--hide for now and move other settings over ~TODO
selectResourceLabel:Hide()
selectResourceScrollBox:Hide()
--center options
--TODO disabled for now
--local optionsFrame = CreateFrame("frame", "$parentOptionsFrame", frame, "BackdropTemplate")
--optionsFrame:SetWidth(CONST_OPTIONSFRAME_WIDTH)
--optionsFrame:SetPoint("topleft", selectResourceScrollBox, "topright", 26, 0)
--optionsFrame:SetPoint("bottomleft", selectResourceScrollBox, "bottomright", 26, 0)
--DF:ApplyStandardBackdrop(optionsFrame)
--anchor table
local anchor_names = {
LOC["OPTIONS_ANCHOR_TOPLEFT"],
LOC["OPTIONS_ANCHOR_LEFT"],
LOC["OPTIONS_ANCHOR_BOTTOMLEFT"],
LOC["OPTIONS_ANCHOR_BOTTOM"],
LOC["OPTIONS_ANCHOR_BOTTOMRIGHT"],
LOC["OPTIONS_ANCHOR_RIGHT"],
LOC["OPTIONS_ANCHOR_TOPRIGHT"],
LOC["OPTIONS_ANCHOR_TOP"],
LOC["OPTIONS_ANCHOR_CENTER"],
LOC["OPTIONS_ANCHOR_INNERLEFT"],
LOC["OPTIONS_ANCHOR_INNERRIGHT"],
LOC["OPTIONS_ANCHOR_INNERTOP"],
LOC["OPTIONS_ANCHOR_INNERBOTTOM"],
}
local build_anchor_side_table = function(member1, member2)
local t = {}
for i = 1, 13 do
tinsert(t, {
label = anchor_names[i],
value = i,
onclick = function(_, _, value)
Plater.db.profile.resources_settings[member1][member2].side = value
Plater.RefreshDBUpvalues()
Plater.UpdateAllPlates()
Plater.UpdateAllNames()
end
}
)
end
return t
end
--[=[
-show = false, --if the resource bar from plater is enabled
-personal_bar = false, --if the resource bar shows in the personal bar intead of the current target
align = "horizontal", --combo points are horizontal alignment
grow_direction = "center",
-show_depleted = true,
-show_number = false,
-anchor = {side = 8, x = 0, y = 40},
-scale = 0.8,
-padding = 2,
--]=]
local globalResourceOptions = {
{type = "label", get = function() return "Global Settings:" end, text_template = DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")},
--use plater resources
{
type = "toggle",
get = function() return Plater.db.profile.resources_settings.global_settings.show end,
set = function (self, fixedparam, value)
Plater.db.profile.resources_settings.global_settings.show = value
if value then
PlaterDBChr.resources_on_target = false
end
Plater.UpdateAllPlates()
end,
name = "Use Plater Resources",
desc = "Use Plater Resources",
},
--show on personal bar
{
type = "toggle",
get = function() return Plater.db.profile.resources_settings.global_settings.personal_bar end,
set = function (self, fixedparam, value)
Plater.db.profile.resources_settings.global_settings.personal_bar = value
Plater.UpdateAllPlates()
end,
name = "Show On Personal Bar",
desc = "Show On Personal Bar",
},
--show depleted
{
type = "toggle",
get = function() return Plater.db.profile.resources_settings.global_settings.show_depleted end,
set = function (self, fixedparam, value)
Plater.db.profile.resources_settings.global_settings.show_depleted = value
Plater.UpdateAllPlates()
end,
name = "Show Background",
desc = "Show Background",
},
--show resource number
{
type = "toggle",
get = function() return Plater.db.profile.resources_settings.global_settings.show_number end,
set = function (self, fixedparam, value)
Plater.db.profile.resources_settings.global_settings.show_number = value
Plater.UpdateAllPlates()
end,
name = "Show Amount",
desc = "Show Amount",
},
--anchor
{
type = "select",
get = function() return Plater.db.profile.resources_settings.global_settings.anchor.side end,
values = function() return build_anchor_side_table("global_settings", "anchor") end,
name = LOC["OPTIONS_ANCHOR"],
desc = "Which side of the nameplate this widget is attach to.",
},
--anchor x offset
{
type = "range",
get = function() return Plater.db.profile.resources_settings.global_settings.anchor.x end,
set = function (self, fixedparam, value)
Plater.db.profile.resources_settings.global_settings.anchor.x = value
Plater.UpdateAllPlates()
end,
min = -100,
max = 100,
step = 1,
usedecimals = true,
name = LOC["OPTIONS_XOFFSET"],
desc = "Slightly move horizontally.",
},
--anchor y offset
{
type = "range",
get = function() return Plater.db.profile.resources_settings.global_settings.anchor.y end,
set = function (self, fixedparam, value)
Plater.db.profile.resources_settings.global_settings.anchor.y = value
Plater.UpdateAllPlates()
end,
min = -100,
max = 100,
step = 1,
usedecimals = true,
name = LOC["OPTIONS_YOFFSET"],
desc = "Slightly move vertically.",
},
--scale
{
type = "range",
get = function() return Plater.db.profile.resources_settings.global_settings.scale end,
set = function (self, fixedparam, value)
Plater.db.profile.resources_settings.global_settings.scale = value
--call update on the resource bar
Plater.UpdateAllPlates()
end,
min = 0.25,
max = 2,
step = 0.1,
usedecimals = true,
name = "Scale",
desc = "Scale",
},
--padding
{
type = "range",
get = function() return Plater.db.profile.resources_settings.global_settings.padding end,
set = function (self, fixedparam, value)
Plater.db.profile.resources_settings.global_settings.padding = value
--call update on the resource bar
Plater.UpdateAllPlates()
end,
min = -10,
max = 10,
step = 1,
name = "Padding",
desc = "Padding",
},
}
local optionChangedCallback = function()
Plater.Resources.RefreshResourcesDBUpvalues()
end
_G.C_Timer.After(1.4, function()
--TODO to other frame for now
--DF:BuildMenu(optionsFrame, globalResourceOptions, 5, -5, CONST_SCROLLBOX_HEIGHT, true, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template, optionChangedCallback)
globalResourceOptions.always_boxfirst = true
DF:BuildMenu(frame, globalResourceOptions, startX, startY, heightSize, false, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template, optionChangedCallback)
--for widgetId, widget in pairs(frame.widgetids) do
-- print(widget.hasLabel:GetText())
--end
end)
end