forked from rtomson/PetJournal_QuickFilter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PetJournal_QuickFilter.lua
165 lines (140 loc) · 5.14 KB
/
PetJournal_QuickFilter.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
local ASCENDING = 1
local DESCENDING = 2
-- Move the pet list down
PetJournalListScrollFrame:SetPoint("TOPLEFT", PetJournalLeftInset, 3, -55)
-- PetJournalEnhanced draws their own ScrollFrame
if PetJournalEnhancedListScrollFrame then
PetJournalEnhancedListScrollFrame:SetPoint("TOPLEFT", PetJournalLeftInset, 3, -55)
end
local QuickFilter_Function = function(self, button)
local activeCount = 0
for petType, _ in ipairs(PET_TYPE_SUFFIX) do
local btn = _G["PetJournalQuickFilterButton"..petType]
if "LeftButton" == button then
if self == btn and (not btn.isActive) then
btn.isActive = true
else
btn.isActive = false
end
elseif "RightButton" == button and (self == btn) then
btn.isActive = not btn.isActive
end
if btn.isActive then
btn:LockHighlight()
activeCount = activeCount + 1
else
btn:UnlockHighlight()
end
C_PetJournal.SetPetTypeFilter(btn.petType, btn.isActive)
end
if 0 == activeCount then
C_PetJournal.AddAllPetTypesFilter()
end
-- PetJournalEnhanced support
if PetJournalEnhanced then
local PJE = PetJournalEnhanced
if PJE.modules and PJE.modules.Sorting then
PJE.modules.Sorting:UpdatePets()
elseif PJE.UpdatePets then
PJE:UpdatePets()
end
end
end
local Favorites_Function = function(self, button)
if C_PetJournal.IsFlagFiltered(LE_PET_JOURNAL_FLAG_FAVORITES) == false then
C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_FAVORITES, false)
self:UnlockHighlight()
else
C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_FAVORITES, true)
self:LockHighlight()
end
-- PetJournalEnhanced support
if PetJournalEnhanced then
local PJE = PetJournalEnhanced
if PJE.modules and PJE.modules.Sorting then
if ("RightButton" == button) then
if PJE.modules.Sorting.sorting.order == ASCENDING then
PJE.modules.Sorting.sorting.order = DESCENDING
else
PJE.modules.Sorting.sorting.order = ASCENDING
end
end
PJE.modules.Sorting:UpdatePets()
elseif PJE.UpdatePets then
PJE:UpdatePets()
end
end
end
local maxPetType = 0
local totalActiveCount = 0
local totalCount = 0
-- Create the pet type buttons
for petType, suffix in ipairs(PET_TYPE_SUFFIX) do
local btn = CreateFrame("Button", "PetJournalQuickFilterButton"..petType, PetJournalLeftInset)
btn:SetSize(21, 21)
btn:SetPoint("TOPLEFT", PetJournalLeftInset, 6 + 22 * (petType-1), -33)
maxPetType = petType;
local background = btn:CreateTexture(nil, "BACKGROUND")
background:SetTexture("Interface\\PetBattles\\PetBattleHud")
background:SetTexCoord(0.92089844, 0.95410156, 0.34960938, 0.41601563)
background:SetSize(22, 22)
background:SetAllPoints()
btn.Background = background
local icon = btn:CreateTexture(nil, "ARTWORK")
icon:SetTexture("Interface\\PetBattles\\PetIcon-"..suffix)
icon:SetTexCoord(0.79687500, 0.49218750, 0.50390625, 0.65625000)
icon:SetSize(21, 21)
icon:SetPoint("CENTER")
btn.Icon = icon
local highlight = btn:CreateTexture("Highlight", "OVERLAY")
highlight:SetTexture("Interface\\PetBattles\\PetBattleHud")
highlight:SetTexCoord(0.94921875, 0.99414063, 0.67382813, 0.76367188)
highlight:SetSize(27, 27)
highlight:SetPoint("CENTER")
btn:SetHighlightTexture(highlight, "BLEND")
btn.petType = petType
btn:SetScript("OnMouseUp", QuickFilter_Function)
if C_PetJournal.IsPetTypeFiltered(petType) == false then
btn.isActive = true
totalActiveCount = totalActiveCount + 1
btn:LockHighlight()
else
btn.isActive = false
end
totalCount = totalCount + 1
end
-- If they are all active then uncheck all of them
if (totalCount == totalActiveCount) then
for petType, _ in ipairs(PET_TYPE_SUFFIX) do
local btn = _G["PetJournalQuickFilterButton"..petType]
btn.isActive = false
btn:UnlockHighlight()
end
end
local btn = CreateFrame("Button", "PetJournalQuickFilterButtonFavorites", PetJournalLeftInset)
btn:SetSize(21, 21)
btn:SetPoint("TOPLEFT", PetJournalLeftInset, 6 + 22 * (maxPetType), -33)
local background = btn:CreateTexture(nil, "BACKGROUND")
background:SetTexture("Interface\\PetBattles\\PetBattleHud")
background:SetTexCoord(0.92089844, 0.95410156, 0.34960938, 0.41601563)
background:SetSize(22, 22)
background:SetAllPoints()
btn.Background = background
local icon = btn:CreateTexture(nil, "ARTWORK")
icon:SetTexture("Interface\\PetBattles\\PetJournal")
icon:SetTexCoord(0.11328125,0.16210938,0.02246094,0.04687500)
icon:SetSize(21, 21)
icon:SetPoint("CENTER")
btn.Icon = icon
local highlight = btn:CreateTexture("Highlight", "OVERLAY")
highlight:SetTexture("Interface\\PetBattles\\PetBattleHud")
highlight:SetTexCoord(0.94921875, 0.99414063, 0.67382813, 0.76367188)
highlight:SetSize(27, 27)
highlight:SetPoint("CENTER")
btn:SetHighlightTexture(highlight, "BLEND")
btn:SetScript("OnMouseUp", Favorites_Function)
if C_PetJournal.IsFlagFiltered(LE_PET_JOURNAL_FLAG_FAVORITES) == false then
btn:LockHighlight()
else
btn:UnlockHighlight()
end