-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTidyPlatesUtility.lua
More file actions
411 lines (333 loc) · 13.8 KB
/
TidyPlatesUtility.lua
File metadata and controls
411 lines (333 loc) · 13.8 KB
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
TidyPlatesUtility = {}
-------------------------------------------------------------------------------------
-- General
-------------------------------------------------------------------------------------
local function copytable(original)
local duplicate = {}
for key, value in pairs(original) do
if type(value) == "table" then duplicate[key] = copytable(value)
else duplicate[key] = value end
end
return duplicate
end
local function mergetable(master, mate)
local merged = {}
local matedata
for key, value in pairs(master) do
if type(value) == "table" then
matedata = mate[key]
if type(matedata) == "table" then merged[key] = mergetable(value, matedata)
else merged[key] = copytable(value) end
else
matedata = mate[key]
if matedata == nil then merged[key] = master[key]
else merged[key] = matedata end
end
end
return merged
end
local function updatetable(original, added)
-- Check for exist
if not (original or added) then return original end
if not (type(original) == 'table' and type(added) == 'table' ) then return original end
local matedata
for index, var in pairs(original) do
if type(var) == "table" then original[index] = updatetable(var, added[index]) or var
else
--original[index] = added[index] or original[index]
if added[index] ~= nil then
original[index] = added[index]
else original[index] = original[index] end
end
end
return original
end
local function valueToString(value)
if value ~= nil then
if value >= 1000000 then return format('%.1fm', value / 1000000)
elseif value >= 1000 then return format('%.1fk', value / 1000)
else return value end
end
end
TidyPlatesUtility.abbrevNumber = valueToString
TidyPlatesUtility.copyTable = copytable
TidyPlatesUtility.mergeTable = mergetable
TidyPlatesUtility.updateTable = updatetable
-- Threat
local function GetRelativeThreat(unit)
if not UnitExists(unit) then return end
local _, group, size, index, unitid
local playerthreat, leaderthreat, tempthreat, petthreat, leadername = 0,0,0,0, nil
-- Request Player Threat
_, _, playerthreat, _, _ = UnitDetailedThreatSituation("player", unit)
-- Request Pet Threat
if HasPetUI() then
_, _, petthreat, _, _ = UnitDetailedThreatSituation("pet", unit)
leaderthreat = petthreat or 0
leadername = "pet"
end
-- Get Group Type
if UnitInRaid("player") then group = "raid"; size = GetNumRaidMembers() - 1
elseif UnitInParty("player") then group = "party"; size = GetNumPartyMembers()
else group = nil end
-- Cycle through Group, picking highest threat holder
if group then
for index = 1, size do
unitid = group..index
_, _, tempthreat , _, _ = UnitDetailedThreatSituation(unitid, unit)
if tempthreat and tempthreat > leaderthreat then
leaderthreat = tempthreat
leadername = unitid
end
end
end
if playerthreat and leaderthreat then
--if playerthreat == 100 then return playerthreat + (100-leaderthreat), leadername
if playerthreat == 100 then return playerthreat + (100-leaderthreat), nil
else return playerthreat, leadername end
else return end
end
TidyPlatesUtility.GetRelativeThreat = GetRelativeThreat
------------------------------------------------------------------
-- Panel Helpers (Used to create interface panels)
------------------------------------------------------------------
PanelHelpers = {}
function PanelHelpers:CreatePanelFrame(reference, title)
local panelframe = CreateFrame( "Frame", reference, UIParent);
panelframe.name = title
panelframe.Label = panelframe:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLarge')
panelframe.Label:SetPoint("TOPLEFT", panelframe, "TOPLEFT", 16, -16)
panelframe.Label:SetHeight(15)
panelframe.Label:SetWidth(350)
panelframe.Label:SetJustifyH("LEFT")
panelframe.Label:SetJustifyV("TOP")
panelframe.Label:SetText(title)
return panelframe
end
-- [[
function PanelHelpers:CreateDescriptionFrame(reference, parent, title, text)
local descframe = CreateFrame( "Frame", reference, parent);
descframe:SetHeight(100)
descframe:SetWidth(150)
--
descframe.Label = descframe:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
descframe.Label:SetPoint("BOTTOMLEFT", descframe, "TOPLEFT", 0, 3)
descframe.Label:SetPoint("BOTTOMRIGHT")
descframe.Label:SetJustifyH("LEFT")
descframe.Label:SetText(title)
--
descframe.Description = descframe:CreateFontString(nil, 'ARTWORK', 'GameFontWhiteSmall')
descframe.Description:SetPoint("TOPLEFT")
descframe.Description:SetPoint("BOTTOMRIGHT")
descframe.Description:SetJustifyH("LEFT")
descframe.Description:SetJustifyV("TOP")
descframe.Description:SetText(text)
--
return descframe
end
--]]
function PanelHelpers:CreateCheckButton(reference, parent, label)
local checkbutton = CreateFrame( "CheckButton", reference, parent, "InterfaceOptionsCheckButtonTemplate" )
_G[reference.."Text"]:SetText(label)
checkbutton.GetValue = function() if checkbutton:GetChecked() then return true else return false end end
checkbutton.SetValue = checkbutton.SetChecked
--checkbutton.tooltipText = "Checkbutton"
return checkbutton
end
function PanelHelpers:CreateRadioButtons(reference, parent, numberOfButtons, defaultButton, spacing, list, label)
local index
local radioButtonSet = {}
for index = 1, numberOfButtons do
radioButtonSet[index] = CreateFrame( "CheckButton", reference..index, parent, "UIRadioButtonTemplate" )
radioButtonSet[index].Label = _G[reference..index.."Text"]
radioButtonSet[index].Label:SetText(list[index] or " ")
radioButtonSet[index].Label:SetWidth(250)
radioButtonSet[index].Label:SetJustifyH("LEFT")
--radioButtonSet[index].tooltipText = "Radiobutton"
if index > 1 then
radioButtonSet[index]:SetPoint("TOP", radioButtonSet[index-1], "BOTTOM", 0, -(spacing or 10))
end
radioButtonSet[index]:SetScript("OnClick", function (self)
local button
for button = 1, numberOfButtons do radioButtonSet[button]:SetChecked(false) end
self:SetChecked(true)
end)
end
radioButtonSet.GetChecked = function()
local index
for index = 1, numberOfButtons do
if radioButtonSet[index]:GetChecked() then return index end
end
end
radioButtonSet.SetChecked = function(self, number)
local index
for index = 1, numberOfButtons do radioButtonSet[index]:SetChecked(false) end
radioButtonSet[number]:SetChecked(true)
end
--if label then
-- dropdown.Label = dropdown:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
-- dropdown.Label:SetPoint("TOPLEFT", 18, 18)
-- dropdown.Label:SetText(label)
--end
radioButtonSet[defaultButton]:SetChecked(true)
radioButtonSet.GetValue = radioButtonSet.GetChecked
radioButtonSet.SetValue = radioButtonSet.SetChecked
return radioButtonSet
end
function PanelHelpers:CreateSliderFrame(reference, parent, label, val, minval, maxval, step)
local slider = CreateFrame("Slider", reference, parent, 'OptionsSliderTemplate')
slider:SetWidth(100)
slider:SetHeight(15)
--
slider:SetMinMaxValues(minval or 0, maxval or 1)
slider:SetValueStep(step or .1)
slider:SetValue(val or .5)
slider:SetOrientation("HORIZONTAL")
slider:Enable()
-- Labels
slider.Label = slider:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
slider.Label:SetPoint("TOPLEFT", -5, 18)
slider.Low = _G[reference.."Low"]
slider.High = _G[reference.."High"]
slider.Label:SetText(label or "")
slider.Low:SetText(ceil((minval or 0)*100).."%")
slider.High:SetText(ceil((maxval or 1)*100).."%")
-- Value
slider.Value = slider:CreateFontString(nil, 'ARTWORK', 'GameFontWhite')
slider.Value:SetPoint("BOTTOM", 0, -10)
slider.Value:SetWidth(50)
--slider.Value
slider.Value:SetText(tostring(ceil(100*(val or .5))))
slider:SetScript("OnValueChanged", function()
slider.Value:SetText(tostring(ceil(100*slider:GetValue())).."%")
end)
--slider.tooltipText = "Slider"
return slider
end
function PanelHelpers:CreateDropdownFrame(reference, parent, menu, default, label)
local dropdown = CreateFrame("Frame", reference, parent, "UIDropDownMenuTemplate" )
local index, item
dropdown.Text = _G[reference.."Text"]
dropdown.Text:SetText(menu[default].text)
--
if label then
dropdown.Label = dropdown:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
dropdown.Label:SetPoint("TOPLEFT", 18, 18)
dropdown.Label:SetText(label)
end
--
dropdown.Value = default
dropdown.initialize = function(self, level)
if not level == 1 then return end
for index, item in pairs(menu) do
item.func = function(self) dropdown.Text:SetText(item.text); dropdown.Value = index end
UIDropDownMenu_AddButton(item, level)
end end
dropdown.SetValue = function (self, value) dropdown.Text:SetText(menu[value].text); dropdown.Value = value end
dropdown.GetValue = function () return dropdown.Value end
--dropdown.tooltipText = "Dropdown"
return dropdown
end
-- [[ COLOR
do
local ShowColorPicker
do
local swatchframe
local function ChangeColor(cancel)
local a, r, g, b
if cancel then
r,g,b,a = unpack(ColorPickerFrame.previousValues )
swatchframe:SetBackdropColor(r,g,b,a)
else
a, r, g, b = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();
swatchframe:SetBackdropColor(r,g,b,1-a)
end
end
function ShowColorPicker(targetframe)
swatchframe = targetframe
local r,g,b,a = swatchframe:GetBackdropColor()
ColorPickerFrame.previousValues = {r,g,b,a}
ColorPickerFrame:SetColorRGB(r,g,b);
ColorPickerFrame.hasOpacity = true
ColorPickerFrame.opacity = 1 - a
ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = ChangeColor, ChangeColor, ChangeColor;
ColorPickerFrame:Hide(); -- Need to run the OnShow handler.
ColorPickerFrame:Show();
end
end
function PanelHelpers:CreateColorBox(reference, parent, label, r, g, b, a)
local colorbox = CreateFrame("Button", reference, parent)
colorbox:SetWidth(24)
colorbox:SetHeight(24)
colorbox:SetBackdrop({bgFile = "Interface\\ChatFrame\\ChatFrameColorSwatch",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = false, tileSize = 16, edgeSize = 8,
insets = { left = 1, right = 1, top = 1, bottom = 1 }});
colorbox:SetBackdropColor(r, g, b, a);
colorbox:SetScript("OnClick",function() ShowColorPicker(colorbox) end)
--
colorbox.Label = colorbox:CreateFontString(nil, 'ARTWORK', 'GameFontWhiteSmall')
colorbox.Label:SetPoint("TOPLEFT", colorbox, "TOPRIGHT", 4, -7)
colorbox.Label:SetText(label)
colorbox.GetValue = function() local color = {}; color.r, color.g, color.b, color.a = colorbox:GetBackdropColor(); return color end
colorbox.SetValue = function(self, color) colorbox:SetBackdropColor(color.r, color.g, color.b, color.a); end
--colorbox.tooltipText = "Colorbox"
return colorbox
end
end
TidyPlatesUtility.PanelHelpers = PanelHelpers
--[[
do
local function OnClickSelect(self)
end
local function AddListItem(self, itemname, itemdata)
local item = CreateFrame("Frame", nil, self.Content)
item.Label = = item:CreateFontString(nil, "OVERLAY")
-- Create or REUSE frame
-- create a frame
-- create highlight region
-- create text region
-- Scale Frame
-- Set Anchors
-- Scale Contents Frame
-- Store parent list information
-- Add OnClick Handler (OnSelect)
end
local function DeleteItem(self, itemname)
end
local function UpdateList(self)
self:SetScrollChild(self.Content)
end
local function GetSelectedItem(self) end
function PanelHelpers:CreateScrollList(reference, parent, label, targetTable)
local self = CreateFrame("ScrollFrame",reference, parent)
local self.Content = CreateFrame("Frame", reference.."_Contents", scrollListWindow)
-- Setup Visible Item List
self.Content.Items = {}
self.Content.ItemCount = 0
self.Content.SelectedIndex = 0
-- Setup Default Options
-- Register Functions
end
end
--]]
--[[
UIPanelScrollFrameTemplate
or
UIPanelScrollFrameTemplate2
--]]
--[[
<OnEnter>
if ( self.tooltipText ) then
GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT");
GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1);
end
if ( self.tooltipRequirement ) then
GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0);
GameTooltip:Show();
end
</OnEnter>
<OnLeave>
GameTooltip:Hide();
</OnLeave>
--]]