-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoUF_QuestMobIndicator.lua
179 lines (138 loc) · 4.71 KB
/
oUF_QuestMobIndicator.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
--[[
# Element: Quest Indicator
Handles the visibility and updating of an indicator based on the unit's involvement in a quest.
## Widget
QuestMobIndicator - Any UI widget.
## Notes
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
## Examples
-- Position and size
local QuestMobIndicator = self:CreateTexture(nil, 'OVERLAY')
QuestMobIndicator:SetSize(16, 16)
QuestMobIndicator:SetPoint('TOPRIGHT', self)
-- Register it with oUF
self.QuestMobIndicator = QuestMobIndicator
--]]
local _, ns = ...
local oUF = ns.oUF
if (oUF.isClassic) then
return
end
local TooltipScanner = CreateFrame('GameTooltip', 'QuestMobScanningTooltip', nil, 'GameTooltipTemplate') -- Tooltip name cannot be nil
TooltipScanner:SetOwner(WorldFrame, 'ANCHOR_NONE')
local function BreakdownTooltipLine(lineNumber)
local tooltipLine = _G['QuestMobScanningTooltipTextLeft' .. lineNumber]
local tooltipText = tooltipLine:GetText()
local r, g, b = tooltipLine:GetTextColor()
return tooltipText, r, g, b
end
local function GetUnitQuestInfo(unitGUID)
local questName, questUnit, questProgress
local questList = {}
local questTexture = {[628564] = true, [3083385] = true}
local objectiveCount = 0
if not unitGUID then
return
end
TooltipScanner:ClearLines()
TooltipScanner:SetUnit(unitGUID)
-- Get lines with quest information on them
for line = 1, TooltipScanner:NumLines() do
-- Get amount of quest objectives through counting textures
local texture = _G['QuestMobScanningTooltipTexture' .. line]
if texture and questTexture[texture:GetTexture()] then
objectiveCount = objectiveCount + 1
end
if line > 1 then
local tooltipText, r, g, b = BreakdownTooltipLine(line)
local lineIsQuestHeader = (b == 0 and r > 0.99 and g > 0.82) -- Note: Quest Name Heading is colored Yellow. (As well as the player on that quest as of 8.2.5)
if lineIsQuestHeader then
questName = tooltipText
questList[questName] = questList[questName] or {}
elseif questName and objectiveCount > 0 then
table.insert(questList[questName], tooltipText)
objectiveCount = objectiveCount - 1 -- Decrease objective Count
end
end
end
if questList[UnitName('player')] then
return {player = questList[UnitName('player')]} -- Wrap it so the quest widget can parse it properly
elseif not IsInGroup() then
return questList
end
return {}
end
local function Update(self, event, unit)
if (unit ~= self.unit) then
return
end
local element = self.QuestMobIndicator
--[[ Callback: QuestMobIndicator:PreUpdate()
Called before the element has been updated.
* self - the QuestMobIndicator element
--]]
if (element.PreUpdate) then
element:PreUpdate()
end
local isDungeon = IsInInstance()
local questList = GetUnitQuestInfo(unit)
local showIcon = false
for questName, questObjectives in pairs(questList) do
for k,questObjective in ipairs(questObjectives) do
local questProgress, questTotal
if questObjective then
questProgress, questTotal = string.match(questObjective, "([0-9]+)\/([0-9]+)")
questProgress = tonumber(questProgress)
questTotal = tonumber(questTotal)
end
if (not isDungeon and ((questName and not (questProgress and questTotal)) or (questProgress and questTotal and questProgress < questTotal))) then
showIcon = true
end
end
end
if (showIcon) then
element:Show()
else
element:Hide()
end
--[[ Callback: QuestMobIndicator:PostUpdate(isQuestBoss)
Called after the element has been updated.
* self - the QuestMobIndicator element
* isQuestBoss - indicates if the element is shown (boolean)
--]]
if (element.PostUpdate) then
return element:PostUpdate(isQuestBoss)
end
end
local function Path(self, ...)
--[[ Override: QuestMobIndicator.Override(self, event, ...)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* ... - the arguments accompanying the event
--]]
return (self.QuestMobIndicator.Override or Update)(self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self)
local element = self.QuestMobIndicator
if (element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
if (element:IsObjectType('Texture') and not element:GetTexture()) then
element:SetTexture([[Interface\TargetingFrame\PortraitQuestBadge]])
end
return true
end
end
local function Disable(self)
local element = self.QuestMobIndicator
if (element) then
element:Hide()
self:UnregisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
end
end
oUF:AddElement('QuestMobIndicator', Path, Enable, Disable)