· 7 years ago · Sep 10, 2018, 09:02 PM
1TidyPlatesUtility = {}
2
3-------------------------------------------------------------------------------------
4-- General Helpers
5-------------------------------------------------------------------------------------
6local _
7
8local copytable -- Allows self-reference
9copytable = function(original)
10 local duplicate = {}
11 for key, value in pairs(original) do
12 if type(value) == "table" then duplicate[key] = copytable(value)
13 else duplicate[key] = value end
14 end
15 return duplicate
16end
17
18
19TidyPlatesUtility.IsFriend = function(...) end
20--TidyPlatesUtility.IsHealer =
21TidyPlatesUtility.IsGuildmate = function(...) end
22
23local function RaidMemberCount()
24 if UnitInRaid("player") then
25 return GetNumGroupMembers()
26 end
27end
28
29local function PartyMemberCount()
30 if UnitInParty("player") then
31 return GetNumGroupMembers()
32 end
33end
34
35local function GetSpec()
36 return GetActiveSpecGroup()
37end
38
39TidyPlatesUtility.GetNumRaidMembers = RaidMemberCount
40TidyPlatesUtility.GetNumPartyMembers = PartyMemberCount
41TidyPlatesUtility.GetSpec = GetSpec
42
43local function GetGroupInfo()
44 local groupType, groupCount
45
46 if UnitInRaid("player") then groupType = "raid"
47 groupCount = GetNumGroupMembers()
48 -- Unitids for raid groups go from raid1..to..raid40. No errors.
49 elseif UnitInParty("player") then groupType = "party"
50 groupCount = GetNumGroupMembers() - 1
51 -- WHY? Because the range for unitids are party1..to..party4. GetNumGroupMembers() includes the Player, causing errors.
52 else return end
53
54 return groupType, groupCount
55end
56
57TidyPlatesUtility.GetGroupInfo = GetGroupInfo
58
59
60local function mergetable(master, mate)
61 local merged = {}
62 local matedata
63 for key, value in pairs(master) do
64 if type(value) == "table" then
65 matedata = mate[key]
66 if type(matedata) == "table" then merged[key] = mergetable(value, matedata)
67 else merged[key] = copytable(value) end
68 else
69 matedata = mate[key]
70 if matedata == nil then merged[key] = master[key]
71 else merged[key] = matedata end
72 end
73 end
74 return merged
75end
76
77local function updatetable(original, added)
78 -- Check for exist
79 if not (original or added) then return original end
80 if not (type(original) == 'table' and type(added) == 'table' ) then return original end
81 local originalval
82
83 for index, var in pairs(original) do
84 if type(var) == "table" then original[index] = updatetable(var, added[index]) or var
85 else
86 --original[index] = added[index] or original[index]
87 if added[index] ~= nil then
88 original[index] = added[index]
89 else original[index] = original[index] end
90
91 end
92 end
93 return original
94end
95
96local function valueToString(value)
97 if value ~= nil then
98 if value >= 1000000 then return format('%.1fm', value / 1000000)
99 elseif value >= 1000 then return format('%.1fk', value / 1000)
100 else return value end
101 end
102end
103
104TidyPlatesUtility.abbrevNumber = valueToString
105TidyPlatesUtility.copyTable = copytable
106TidyPlatesUtility.mergeTable = mergetable
107TidyPlatesUtility.updateTable = updatetable
108
109------------------------------------------
110-- GameTooltipScanner
111------------------------------------------
112local ScannerName = "TidyPlatesScanningTooltip"
113local TooltipScanner = CreateFrame( "GameTooltip", ScannerName , nil, "GameTooltipTemplate" ); -- Tooltip name cannot be nil
114TooltipScanner:SetOwner( WorldFrame, "ANCHOR_NONE" );
115
116------------------------------------------
117-- Unit Subtitles/NPC Roles
118------------------------------------------
119local UnitSubtitles = {}
120local function GetUnitSubtitle(unit)
121 local unitid = unit.unitid
122
123 -- Bypass caching while in an instance
124 --if inInstance or (not UnitExists(unitid)) then return end
125 if ( UnitIsPlayer(unitid) or UnitPlayerControlled(unitid) or (not UnitExists(unitid))) then return end
126
127 --local guid = UnitGUID(unitid)
128 local name = unit.name
129 local subTitle = UnitSubtitles[name]
130
131 if not subTitle then
132 TooltipScanner:ClearLines()
133 TooltipScanner:SetUnit(unitid)
134
135 local TooltipTextLeft1 = _G[ScannerName.."TextLeft1"]
136 local TooltipTextLeft2 = _G[ScannerName.."TextLeft2"]
137 local TooltipTextLeft3 = _G[ScannerName.."TextLeft3"]
138 local TooltipTextLeft4 = _G[ScannerName.."TextLeft4"]
139
140 name = TooltipTextLeft1:GetText()
141
142 if name then name = gsub( gsub( (name), "|c........", "" ), "|r", "" ) else return end -- Strip color escape sequences: "|c"
143 if name ~= UnitName(unitid) then return end -- Avoid caching information for the wrong unit
144
145
146 -- Tooltip Format Priority: Faction, Description, Level
147 local toolTipText = TooltipTextLeft2:GetText() or "UNKNOWN"
148
149 if string.match(toolTipText, UNIT_LEVEL_TEMPLATE) then
150 subTitle = ""
151 else
152 subTitle = toolTipText
153 end
154
155 UnitSubtitles[name] = subTitle
156 end
157
158 -- Maintaining a cache allows us to avoid the hit
159 if subTitle == "" then return nil
160 else return subTitle end
161
162end
163
164TidyPlatesUtility.GetUnitSubtitle = GetUnitSubtitle
165
166------------------------------------------
167-- Quest Info
168------------------------------------------
169local function GetTooltipLineText(lineNumber)
170 local tooltipLine = _G[ScannerName .. "TextLeft" .. lineNumber]
171 local tooltipText = tooltipLine:GetText()
172 local r, g, b = tooltipLine:GetTextColor()
173
174 return tooltipText, r, g, b
175end
176
177local function GetUnitQuestInfo(unit)
178 local unitid = unit.unitid
179 local questName
180 local questProgress
181
182 if not unitid then return end
183
184 -- Tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
185 TooltipScanner:ClearLines()
186 TooltipScanner:SetUnit(unitid)
187
188 for line = 3, TooltipScanner:NumLines() do
189 local tooltipText, r, g, b = GetTooltipLineText( line )
190
191 -- If the Quest Name exists, the following tooltip lines list quest progress
192 if questName then
193 -- Strip out the name of the player that is on the quest.
194 local playerName, questNote = string.match(tooltipText, "(%g*) ?%- (.*)")
195
196 if (playerName == "") or (playerName == UnitName("player")) then
197 questProgress = questNote
198 break
199 end
200
201 elseif b == 0 and r > 0.99 and g > 0.82 then
202 -- Note: Quest Name Heading is colored Yellow
203 questName = tooltipText
204 end
205 end
206
207 return questName, questProgress
208end
209
210
211TidyPlatesUtility.GetUnitQuestInfo = GetUnitQuestInfo
212
213------------------------
214-- Threat Function
215------------------------
216
217-- /run print(UnitThreatSituation("party1"), UnitAffectingCombat("party1"))
218--local function GetThreatCondition(name)
219local function GetFriendlyThreat(unitid)
220
221 if unitid then
222 local isUnitInParty = UnitPlayerOrPetInParty(unit)
223 local isUnitInRaid = UnitInRaid(unit)
224 local isUnitPet = (unit == "pet")
225
226 --if isUnitInParty then
227 local unitaggro = UnitThreatSituation(unitid)
228 if unitaggro and unitaggro > 1 then return true end
229 --end
230 end
231end
232
233TidyPlatesUtility.GetFriendlyThreat = GetFriendlyThreat
234
235------------------------
236-- Threat Function
237------------------------
238
239do
240
241 local function GetRelativeThreat(enemyUnitid) -- 'enemyUnitid' is a target/enemy
242 if not UnitExists(enemyUnitid) then return end
243
244 local allyUnitid, allyThreat = nil, 0
245 local playerIsTanking, playerSituation, playerThreat = UnitDetailedThreatSituation("player", enemyUnitid)
246 if not playerThreat then return end
247
248 -- Get Group Type
249 local evalUnitid, evalIndex, evalThreat
250 local groupType, size, startAt = nil, nil, 1
251 if UnitInRaid("player") then
252 groupType = "raid"
253 groupSize = TidyPlatesUtility:GetNumRaidMembers()
254 startAt = 2
255 elseif UnitInParty("player") then
256 groupType = "party"
257 groupSize = TidyPlatesUtility:GetNumPartyMembers()
258 else groupType = nil end
259
260 -- Cycle through Group, picking highest threat holder
261 if groupType then
262 for allyIndex = startAt, groupSize do
263 evalUnitid = groupType..allyIndex
264 evalThreat = select(3, UnitDetailedThreatSituation(evalUnitid, enemyUnitid))
265 if evalThreat and evalThreat > allyThreat then
266 allyThreat = evalThreat
267 allyUnitid = evalUnitid
268 end
269 end
270 end
271
272 -- Request Pet Threat (if possible)
273 if HasPetUI() and UnitExists("pet") then
274 evalThreat = select(3, UnitDetailedThreatSituation("pet", enemyUnitid)) or 0
275 if evalThreat > allyThreat then
276 allyThreat = evalThreat
277 allyUnitid = "pet"
278 end
279 end
280
281 --[[
282 if playerIsTanking and allyThreat then
283 return 100 - tonumber(allyThreat or 0), true
284 elseif allyThreat and allyUnitid then
285 return 100 - playerThreat, false
286 end
287 --]]
288 -- [[
289 -- Return the appropriate value
290 if playerThreat and allyThreat and allyUnitid then
291 if playerThreat >= 100 then -- The enemy is attacking you. You are tanking. Returns: 1. Your threat, plus your lead over the next highest person, 2. Your Unitid (since you're tanking)
292 return tonumber(playerThreat + (100-allyThreat)), "player"
293 else -- The enemy is not attacking you. Returns: 1. Your scaled threat percent, 2. Who is On Top
294 return tonumber(playerThreat), allyUnitid
295 end
296 end
297 --]]
298 end
299
300 TidyPlatesUtility.GetRelativeThreat = GetRelativeThreat
301end
302------------------------------------------------------------------
303-- Panel Helpers (Used to create interface panels)
304------------------------------------------------------------------
305
306local function CreatePanelFrame(self, reference, listname, title)
307 local panelframe = CreateFrame( "Frame", reference, UIParent);
308 panelframe.name = listname
309 panelframe.Label = panelframe:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLarge')
310 panelframe.Label:SetPoint("TOPLEFT", panelframe, "TOPLEFT", 16, -16)
311 panelframe.Label:SetHeight(15)
312 panelframe.Label:SetWidth(350)
313 panelframe.Label:SetJustifyH("LEFT")
314 panelframe.Label:SetJustifyV("TOP")
315 panelframe.Label:SetText(title or listname)
316 return panelframe
317end
318-- [[
319local function CreateDescriptionFrame(self, reference, parent, title, text)
320 local descframe = CreateFrame( "Frame", reference, parent);
321 descframe:SetHeight(15)
322 descframe:SetWidth(200)
323
324 descframe.Label = descframe:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
325 descframe.Label:SetAllPoints()
326 descframe.Label:SetJustifyH("LEFT")
327 descframe.Label:SetText(title)
328
329 descframe.Description = descframe:CreateFontString(nil, 'ARTWORK', 'GameFontWhiteSmall')
330 descframe.Description:SetPoint("TOPLEFT")
331 descframe.Description:SetPoint("BOTTOMRIGHT")
332 descframe.Description:SetJustifyH("LEFT")
333 descframe.Description:SetJustifyV("TOP")
334 descframe.Description:SetText(text)
335 --
336 return descframe
337end
338--]]
339local function CreateCheckButton(self, reference, parent, label)
340 local checkbutton = CreateFrame( "CheckButton", reference, parent, "InterfaceOptionsCheckButtonTemplate" )
341 checkbutton.Label = _G[reference.."Text"]
342 checkbutton.Label:SetText(label)
343 checkbutton.GetValue = function() if checkbutton:GetChecked() then return true else return false end end
344 checkbutton.SetValue = checkbutton.SetChecked
345
346 return checkbutton
347end
348
349local function CreateRadioButtons(self, reference, parent, numberOfButtons, defaultButton, spacing, list, label)
350 local index
351 local radioButtonSet = {}
352
353 for index = 1, numberOfButtons do
354 radioButtonSet[index] = CreateFrame( "CheckButton", reference..index, parent, "UIRadioButtonTemplate" )
355 radioButtonSet[index].Label = _G[reference..index.."Text"]
356 radioButtonSet[index].Label:SetText(list[index] or " ")
357 radioButtonSet[index].Label:SetWidth(250)
358 radioButtonSet[index].Label:SetJustifyH("LEFT")
359
360 if index > 1 then
361 radioButtonSet[index]:SetPoint("TOP", radioButtonSet[index-1], "BOTTOM", 0, -(spacing or 10))
362 end
363
364 radioButtonSet[index]:SetScript("OnClick", function (self)
365 local button
366 for button = 1, numberOfButtons do radioButtonSet[button]:SetChecked(false) end
367 self:SetChecked(true)
368 end)
369 end
370
371 radioButtonSet.GetChecked = function()
372 local index
373 for index = 1, numberOfButtons do
374 if radioButtonSet[index]:GetChecked() then return index end
375 end
376 end
377
378 radioButtonSet.SetChecked = function(self, number)
379 local index
380 for index = 1, numberOfButtons do radioButtonSet[index]:SetChecked(false) end
381 radioButtonSet[number]:SetChecked(true)
382 end
383
384 --if label then
385 -- dropdown.Label = dropdown:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
386 -- dropdown.Label:SetPoint("TOPLEFT", 18, 18)
387 -- dropdown.Label:SetText(label)
388 --end
389
390 radioButtonSet[defaultButton]:SetChecked(true)
391 radioButtonSet.GetValue = radioButtonSet.GetChecked
392 radioButtonSet.SetValue = radioButtonSet.SetChecked
393
394 return radioButtonSet
395end
396
397local function CreateSliderFrame(self, reference, parent, label, val, minval, maxval, step, mode)
398 local slider = CreateFrame("Slider", reference, parent, 'OptionsSliderTemplate')
399 slider:SetWidth(100)
400 slider:SetHeight(15)
401 --
402 slider:SetMinMaxValues(minval or 0, maxval or 1)
403 slider:SetValueStep(step or .1)
404 slider:SetValue(val or .5)
405 slider:SetOrientation("HORIZONTAL")
406 slider:Enable()
407 -- Labels
408 slider.Label = slider:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
409 slider.Label:SetPoint("TOPLEFT", -5, 18)
410 slider.Low = _G[reference.."Low"]
411 slider.High = _G[reference.."High"]
412 slider.Label:SetText(label or "")
413
414 -- Value
415 slider.Value = slider:CreateFontString(nil, 'ARTWORK', 'GameFontWhite')
416 slider.Value:SetPoint("BOTTOM", 0, -10)
417 slider.Value:SetWidth(50)
418 --slider.Value
419 if mode and mode == "ACTUAL" then
420 slider.Value:SetText(tostring(ceil(val)))
421 slider:SetScript("OnValueChanged", function()
422 local v = tostring(ceil(slider:GetValue()))
423 slider.Value:SetText(v)
424 end)
425 slider.Low:SetText(ceil(minval or 0))
426 slider.High:SetText(ceil(maxval or 1))
427 else
428 slider.Value:SetText(tostring(ceil(100*(val or .5))))
429 slider:SetScript("OnValueChanged", function()
430 slider.Value:SetText(tostring(ceil(100*slider:GetValue())).."%")
431 end)
432 slider.Low:SetText(ceil((minval or 0)*100).."%")
433 slider.High:SetText(ceil((maxval or 1)*100).."%")
434 end
435
436 --slider.tooltipText = "Slider"
437 return slider
438end
439
440------------------------------------------------
441-- Alternative Dropdown Menu
442------------------------------------------------
443
444local DropDownMenuFrame = CreateFrame("Frame")
445local MaxDropdownItems = 25
446
447DropDownMenuFrame:SetSize(100, 100)
448DropDownMenuFrame:SetFrameStrata("TOOLTIP");
449DropDownMenuFrame:Hide()
450
451local Border = CreateFrame("Frame", nil, DropDownMenuFrame)
452Border:SetBackdrop(
453 { bgFile = "Interface/DialogFrame/UI-DialogBox-Background-Dark",
454 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
455 tile = true, tileSize = 16, edgeSize = 16,
456 insets = { left = 4, right = 4, top = 4, bottom = 4 }});
457Border:SetBackdropColor(0,0,0,1);
458Border:SetPoint("TOPLEFT", DropDownMenuFrame, "TOPLEFT")
459
460-- Create the Menu Item Buttons
461for i = 1, MaxDropdownItems do
462 local button = CreateFrame("Button", "TidyPlateDropdownMenuButton"..i, DropDownMenuFrame)
463 DropDownMenuFrame["Button"..i] = button
464
465 button:SetHeight(15)
466 button:SetPoint("RIGHT", DropDownMenuFrame, "RIGHT")
467 button:SetText("Button")
468
469 button.buttonIndex = i
470
471 if i > 1 then
472 button:SetPoint("TOPLEFT", DropDownMenuFrame["Button"..i-1], "BOTTOMLEFT")
473 else
474 -- Initial Corner Point
475 button:SetPoint("TOPLEFT", DropDownMenuFrame, "TOPLEFT", 10, -8)
476 end
477
478 local region = select(1, button:GetRegions())
479 region:SetJustifyH("LEFT")
480 region:SetPoint("LEFT", button, "LEFT")
481 region:SetPoint("RIGHT", button, "RIGHT")
482
483 --button:SetFrameStrata("DIALOG")
484 button:SetHighlightTexture("Interface/QuestFrame/UI-QuestTitleHighlight")
485 button:SetNormalFontObject("GameFontHighlightSmallLeft")
486 button:SetHighlightFontObject("GameFontNormalSmallLeft")
487 button:Show()
488end
489
490--[[
491local CloseDropdownButton = CreateFrame("Button", nil, DropDownMenuFrame, "UIPanelCloseButton")
492CloseDropdownButton:SetPoint("TOPLEFT", DropDownMenuFrame, "TOPRIGHT", -4, 0)
493CloseDropdownButton:SetFrameStrata("TOOLTIP");
494CloseDropdownButton:Raise()
495CloseDropdownButton:Show()
496--]]
497
498
499local function HideDropdownMenu()
500 DropDownMenuFrame:Hide()
501end
502
503local function ShowDropdownMenu(sourceFrame, menu, clickScript)
504 if DropDownMenuFrame:IsShown() and DropDownMenuFrame.SourceFrame == sourceFrame then
505 HideDropdownMenu()
506 return
507 end
508
509 local currentSelection
510
511 DropDownMenuFrame.SourceFrame = sourceFrame
512 if sourceFrame.GetValue then currentSelection = sourceFrame:GetValue() end
513
514 local numOfItems = 0
515 local maxWidth = 0
516 for i = 1, MaxDropdownItems do
517 local item = menu[i]
518
519 local button = DropDownMenuFrame["Button"..i]
520
521 if item then
522 local itemText = item.text
523
524 local region1, region2 = button:GetRegions()
525 --print(region1:GetObjectType(), region2:GetObjectType() )
526
527 if currentSelection == i or itemText == currentSelection then
528 region1:SetTextColor(1, .8, 0)
529 region1:SetFont(1, .8, 0)
530 else
531 region1:SetTextColor(1, 1, 1)
532 end
533
534 button:SetText(itemText)
535 button.Value = item.value
536
537 --button:SetText
538 maxWidth = max(maxWidth, button:GetTextWidth())
539 numOfItems = numOfItems + 1
540 button:SetScript("OnClick", clickScript)
541
542
543 button:Show()
544 else
545 button:Hide()
546 end
547
548 end
549
550 DropDownMenuFrame:SetWidth(maxWidth + 20)
551 Border:SetPoint("BOTTOMRIGHT", DropDownMenuFrame["Button"..numOfItems], "BOTTOMRIGHT", 10, -12)
552 DropDownMenuFrame:SetPoint("TOPLEFT", sourceFrame, "BOTTOM")
553 DropDownMenuFrame:Show()
554 DropDownMenuFrame:Raise()
555
556 -- Make sure the menu stays visible when displayed
557 local LowerBound = Border:GetBottom() or 0
558 if 0 > LowerBound then DropDownMenuFrame:SetPoint("TOPLEFT", sourceFrame, "BOTTOM", 0, LowerBound * -1) end
559end
560
561
562------------------------------------------------
563-- Creates the Dropdown Drawer object
564------------------------------------------------
565
566
567local function CreateDropdownFrame(helpertable, reference, parent, menu, default, label, valueMethod)
568 local drawer = CreateFrame("Frame", reference, parent, "TidyPlatesDropdownDrawerTemplate" )
569
570 drawer.Text = _G[reference.."Text"]
571 drawer.Button = _G[reference.."Button"]
572 drawer:SetWidth(120)
573
574 if label then
575 drawer.Label = drawer:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
576 drawer.Label:SetPoint("TOPLEFT", 18, 18)
577 drawer.Label:SetText(label)
578 end
579
580 drawer.valueMethod = valueMethod
581
582
583 drawer.Text:SetWidth(100)
584 drawer.Value = default
585
586 -- SetValue is used in the Hub and Panel functions; Very important
587 ------------------------------------
588 drawer.SetValue = function (self, value)
589 --if not value then return end
590
591 local itemText
592
593 -- Search for Numerical Index
594 if menu[value] then
595 itemText = menu[value].text
596 else
597 -- Search for Token
598 for i,v in pairs(menu) do
599 if v.value == value then
600 itemText = v.text
601 break
602 end
603 end
604 end
605
606 if value then
607 drawer.Text:SetText(itemText)
608 drawer.Value = value
609 end
610 end
611
612 -- GetValue is used in the Hub and Panel functions; Very important
613 ------------------------------------
614 drawer.GetValue = function (self)
615 return self.Value
616 end
617
618 -- New Dropdown Method
619 ------------------------------------------------
620
621 local function OnClickItem(self)
622
623 drawer:SetValue(menu[self.buttonIndex].value or self.buttonIndex)
624 --print(self.Value, menu[self.buttonIndex].value, drawer:GetValue())
625
626 if drawer.OnValueChanged then drawer.OnValueChanged(drawer) end
627 PlaySound("igMainMenuOptionCheckBoxOn");
628 HideDropdownMenu()
629 end
630
631 local function OnClickDropdown()
632 PlaySound("igMainMenuOptionCheckBoxOn");
633 ShowDropdownMenu(drawer, menu, OnClickItem)
634 end
635
636 local function OnHideDropdown()
637 HideDropdownMenu()
638 end
639
640 -- Override the default menu display scripts...
641 local button = _G[reference.."Button"]
642 button:SetScript("OnClick", OnClickDropdown)
643 button:SetScript("OnHide", OnHideDropdown)
644
645 -- Set the default value on itself
646 drawer:SetValue(default)
647
648 return drawer
649end
650
651-- [[ COLOR
652local CreateColorBox
653do
654
655 local workingFrame
656 local function ChangeColor(cancel)
657 local a, r, g, b
658 if cancel then
659 --r,g,b,a = unpack(ColorPickerFrame.startingval )
660 workingFrame:SetBackdropColor(unpack(ColorPickerFrame.startingval ))
661 else
662 a, r, g, b = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();
663 workingFrame:SetBackdropColor(r,g,b,1-a)
664 if workingFrame.OnValueChanged then workingFrame:OnValueChanged() end
665 end
666 end
667
668 local function ShowColorPicker(frame)
669 local r,g,b,a = frame:GetBackdropColor()
670 workingFrame = frame
671 ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = ChangeColor, ChangeColor, ChangeColor;
672 ColorPickerFrame.startingval = {r,g,b,a}
673 ColorPickerFrame:SetColorRGB(r,g,b);
674 ColorPickerFrame.hasOpacity = true
675 ColorPickerFrame.opacity = 1 - a
676 ColorPickerFrame:SetFrameStrata(frame:GetFrameStrata())
677 ColorPickerFrame:SetFrameLevel(frame:GetFrameLevel()+1)
678 ColorPickerFrame:Hide(); ColorPickerFrame:Show(); -- Need to activate the OnShow handler.
679 end
680
681 function CreateColorBox(self, reference, parent, label, r, g, b, a)
682 local colorbox = CreateFrame("Button", reference, parent)
683 colorbox:SetWidth(24)
684 colorbox:SetHeight(24)
685 colorbox:SetBackdrop({bgFile = "Interface\\ChatFrame\\ChatFrameColorSwatch",
686 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
687 tile = false, tileSize = 16, edgeSize = 8,
688 insets = { left = 1, right = 1, top = 1, bottom = 1 }});
689 colorbox:SetBackdropColor(r, g, b, a);
690 colorbox:SetScript("OnClick",function() ShowColorPicker(colorbox) end)
691 --
692 colorbox.Label = colorbox:CreateFontString(nil, 'ARTWORK', 'GameFontWhiteSmall')
693 colorbox.Label:SetPoint("TOPLEFT", colorbox, "TOPRIGHT", 4, -7)
694 colorbox.Label:SetText(label)
695
696 colorbox.GetValue = function() local color = {}; color.r, color.g, color.b, color.a = colorbox:GetBackdropColor(); return color end
697 colorbox.SetValue = function(self, color) colorbox:SetBackdropColor(color.r, color.g, color.b, color.a); end
698 --colorbox.tooltipText = "Colorbox"
699 return colorbox
700 end
701end
702
703PanelHelpers = {}
704
705PanelHelpers.CreatePanelFrame = CreatePanelFrame
706PanelHelpers.CreateDescriptionFrame = CreateDescriptionFrame
707PanelHelpers.CreateCheckButton = CreateCheckButton
708PanelHelpers.CreateRadioButtons = CreateRadioButtons
709PanelHelpers.CreateSliderFrame = CreateSliderFrame
710PanelHelpers.CreateDropdownFrame = CreateDropdownFrame
711PanelHelpers.CreateColorBox = CreateColorBox
712PanelHelpers.ShowDropdownMenu = ShowDropdownMenu
713PanelHelpers.HideDropdownMenu = HideDropdownMenu
714
715TidyPlatesUtility.PanelHelpers = PanelHelpers
716
717
718
719local function StartMovement(frame)
720 -- Store Original Point to frame.OriginalAnchor
721 frame:StartMoving()
722 local OriginalAnchor = frame.OriginalAnchor
723
724 if not OriginalAnchor.point then
725 OriginalAnchor.point, OriginalAnchor.relativeTo, OriginalAnchor.relativePoint,
726 OriginalAnchor.xOfs, OriginalAnchor.yOfs = frame:GetPoint(1)
727 print("Starting Movement from, ", OriginalAnchor.xOfs, OriginalAnchor.yOfs)
728 end
729
730
731 -- Store Current Screen-RelativePosition to frame.NewAnchor
732end
733
734local function FinishMovement(frame)
735 -- Store New Screen-RelativePosition to frame.NewAnchor
736 local NewAnchor = frame.NewAnchor
737 local OriginalAnchor = frame.OriginalAnchor
738 NewAnchor.point, NewAnchor.relativeTo, NewAnchor.relativePoint,
739 NewAnchor.xOfs, NewAnchor.yOfs = frame:GetPoint(1)
740 print(frame:GetName(), " has been moved, " , NewAnchor.xOfs - OriginalAnchor.xOfs, " , ", NewAnchor.yOfs - OriginalAnchor.yOfs)
741 frame:StopMovingOrSizing()
742 -- Process the
743end
744
745local function EnableFreePositioning(frame)
746 -- http://www.wowwiki.com/API_Frame_StartMoving
747 -- point, relativeTo, relativePoint, xOfs, yOfs = MyRegion:GetPoint(n)
748 frame:SetMovable(true)
749 frame:EnableMouse(true)
750 frame:SetScript("OnMouseDown", StartMovement)
751 frame:SetScript("OnMouseUp", FinishMovement)
752 frame.OriginalAnchor = {}
753 frame.NewAnchor = {}
754end
755
756PanelHelpers.EnableFreePositioning = EnableFreePositioning
757
758
759
760
761----------------------
762-- Call In() - Registers a callback, which hides the specified frame in X seconds
763----------------------
764do
765 local CallList = {} -- Key = Frame, Value = Expiration Time
766 local Watcherframe = CreateFrame("Frame")
767 local WatcherframeActive = false
768 local select = select
769 local timeToUpdate = 0
770
771 local function CheckWatchList(self)
772 local curTime = GetTime()
773 if curTime < timeToUpdate then return end
774 local count = 0
775 timeToUpdate = curTime + 1
776 -- Cycle through the watchlist
777 for func, expiration in pairs(CallList) do
778 if expiration < curTime then
779 CallList[func] = nil
780 func()
781 else count = count + 1 end
782 end
783 -- If no more frames to watch, unregister the OnUpdate script
784 if count == 0 then Watcherframe:SetScript("OnUpdate", nil) end
785 end
786
787 local function CallIn(func, expiration)
788 -- Register Frame
789 CallList[ func] = expiration + GetTime()
790 -- Init Watchframe
791 if not WatcherframeActive then
792 Watcherframe:SetScript("OnUpdate", CheckWatchList)
793 WatcherframeActive = true
794 end
795 end
796
797 TidyPlatesUtility.CallIn = CallIn
798
799end
800
801
802
803--------------------------------------------------------------------------------------------------
804-- InterfaceOptionsFrame_OpenToCategory
805-- Quick and dirty fix
806--------------------------------------------------------------------------------------------------
807
808do
809 local fixed = false
810
811 local function OpenInterfacePanel(panel)
812 if not fixed then
813
814 local panelName = panel.name
815 if not panelName then return end
816
817 local t = {}
818
819 for i, p in pairs(INTERFACEOPTIONS_ADDONCATEGORIES) do
820 if p.name == panelName then
821 t.element = p
822 InterfaceOptionsListButton_ToggleSubCategories(t)
823 end
824 end
825 fixed = true
826 end
827
828 InterfaceOptionsFrame_OpenToCategory(panel)
829 end
830
831 TidyPlatesUtility.OpenInterfacePanel = OpenInterfacePanel
832end
833
834-- /run for i,v in pairs(INTERFACEOPTIONS_ADDONCATEGORIES) do print(i, v, v.name) end