-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHideAppearance.lua
97 lines (88 loc) · 3.07 KB
/
HideAppearance.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
local ADDON_NAME, namespace = ...
local L = namespace.L
local Wardrobe, showHidden
local f = CreateFrame("Frame")
local GetCategoryAppearances = C_TransmogCollection.GetCategoryAppearances
-- its confusing to check if a (LoadOnDemand) addon is/will be enabled
local function IsAddonEnabled(addon)
local _, title = GetAddOnInfo(addon)
local state = GetAddOnEnableState(nil, addon)
return title and state > 0
end
local function PositionButton(cb, isAtTransmogrifier)
cb:ClearAllPoints()
if isAtTransmogrifier then
cb:SetPoint("BOTTOMLEFT", Wardrobe.ModelR1C1, "TOPLEFT", -7, 10)
elseif IsAddonEnabled("WardrobeSort") or IsAddonEnabled("LegionWardrobe") then
cb:SetPoint("TOPRIGHT", Wardrobe.WeaponDropDown, "BOTTOMLEFT", -64, 5)
else
cb:SetPoint("TOPLEFT", Wardrobe.WeaponDropDown, "BOTTOMLEFT", 14, 5)
end
end
-- probably not the right way to do this and taints everything
function C_TransmogCollection.GetCategoryAppearances(...)
local visualsList = GetCategoryAppearances(...)
if visualsList and HideAppearanceDB then
for i = #visualsList, 1, -1 do
local isHidden = HideAppearanceDB[visualsList[i].visualID]
if (not showHidden and isHidden) or (showHidden and not isHidden) then
tremove(visualsList, i)
end
end
end
return visualsList
end
function f:OnEvent(event, addon)
if addon == "HideAppearance" then
HideAppearanceDB = HideAppearanceDB or {}
Wardrobe = WardrobeCollectionFrame.ItemsCollectionFrame
-- hook all models
for _, model in pairs(Wardrobe.Models) do
model:HookScript("OnMouseDown", self.AddHideButton)
end
-- toggle for showing only hidden Appearances
local cb = CreateFrame("CheckButton", nil, Wardrobe, "UICheckButtonTemplate")
hooksecurefunc("ShowUIPanel", function(panel)
if panel == CollectionsJournal then
PositionButton(cb)
elseif panel == WardrobeFrame then
PositionButton(cb, true)
end
end)
cb.text:SetText(L["ShowHidden"])
cb:SetScript("OnClick", function(btn)
showHidden = btn:GetChecked()
f:UpdateWardrobe()
end)
self:UnregisterEvent(event)
end
end
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", f.OnEvent)
function f.AddHideButton(model, button)
if button == "RightButton" then
if not DropDownList1:IsShown() then -- force show dropdown
WardrobeModelRightClickDropDown.activeFrame = model
ToggleDropDownMenu(1, nil, WardrobeModelRightClickDropDown, model, -6, -3)
end
UIDropDownMenu_AddSeparator()
local isHidden = HideAppearanceDB[model.visualInfo.visualID]
UIDropDownMenu_AddButton({
notCheckable = true,
text = isHidden and SHOW or HIDE,
func = function() f:ToggleTransmog(model, isHidden) end,
})
end
end
function f:ToggleTransmog(model, isHidden)
local visualID = model.visualInfo.visualID
local source = CollectionWardrobeUtil.GetSortedAppearanceSources(visualID)[1]
local name, link = GetItemInfo(source.itemID)
HideAppearanceDB[visualID] = not isHidden and name
self:UpdateWardrobe()
print(format("%s "..link.." from the Appearances Tab", isHidden and "Unhiding" or "Hiding"))
end
function f:UpdateWardrobe()
Wardrobe:RefreshVisualsList()
Wardrobe:UpdateItems()
end