-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportrait.lua
More file actions
163 lines (127 loc) · 4.36 KB
/
Copy pathportrait.lua
File metadata and controls
163 lines (127 loc) · 4.36 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
--[[
# Element: Portraits
Handles the updating of the unit's portrait.
## Widget
Portrait - A `PlayerModel` or a `Texture` used to represent the unit's portrait.
## Notes
A question mark model will be used if the widget is a PlayerModel and the client doesn't have the model information for
the unit.
## Options
.showClass - Displays the unit's class in the portrait (boolean)
## Examples
-- 3D Portrait
-- Position and size
local Portrait = CreateFrame('PlayerModel', nil, self)
Portrait:SetSize(32, 32)
Portrait:SetPoint('RIGHT', self, 'LEFT')
-- Register it with oUF
self.Portrait = Portrait
-- 2D Portrait
local Portrait = self:CreateTexture(nil, 'OVERLAY')
Portrait:SetSize(32, 32)
Portrait:SetPoint('RIGHT', self, 'LEFT')
-- Register it with oUF
self.Portrait = Portrait
--]]
local _, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
local unitIsUnit = Private.unitIsUnit
local function Update(self, event, unit)
if(not unit or not unitIsUnit(self.unit, unit)) then return end
local element = self.Portrait
--[[ Callback: Portrait:PreUpdate(unit)
Called before the element has been updated.
* self - the Portrait element
* unit - the unit for which the update has been triggered (string)
--]]
if(element.PreUpdate) then element:PreUpdate(unit) end
local guid = UnitGUID(unit)
local isAvailable = UnitIsConnected(unit) and UnitIsVisible(unit)
local hasStateChanged = event ~= 'OnUpdate'
or (not issecretvalue(guid) and not issecretvalue(element.guid) and element.guid ~= guid)
or element.state ~= isAvailable
if(hasStateChanged) then
if(element:IsObjectType('PlayerModel')) then
if(not isAvailable) then
element:SetCamDistanceScale(0.25)
element:SetPortraitZoom(0)
element:SetPosition(0, 0, 0.25)
element:ClearModel()
element:SetModel([[Interface\Buttons\TalkToMeQuestionMark.m2]])
else
element:SetCamDistanceScale(1)
element:SetPortraitZoom(1)
element:SetPosition(0, 0, 0)
element:ClearModel()
element:SetUnit(unit)
end
else
local class, _
if(element.showClass) then
_, class = UnitClass(unit)
end
if(class) then
element:SetAtlas('classicon-' .. class)
else
SetPortraitTexture(element, unit)
end
end
element.guid = guid
element.state = isAvailable
end
--[[ Callback: Portrait:PostUpdate(unit)
Called after the element has been updated.
* self - the Portrait element
* unit - the unit for which the update has been triggered (string)
* hasStateChanged - indicates whether the state has changed since the last update (boolean)
--]]
if(element.PostUpdate) then
return element:PostUpdate(unit, hasStateChanged)
end
end
local function Path(self, ...)
--[[ Override: Portrait.Override(self, event, unit)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
return (self.Portrait.Override or Update) (self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self, unit)
local element = self.Portrait
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
Private.SmartRegisterUnitEvent(self, 'UNIT_MODEL_CHANGED', self.unit, Path)
Private.SmartRegisterUnitEvent(self, 'UNIT_PORTRAIT_UPDATE', self.unit, Path)
self:RegisterEvent('PORTRAITS_UPDATED', Path, true)
Private.SmartRegisterUnitEvent(self, 'UNIT_CONNECTION', self.unit, Path)
-- The quest log uses PARTY_MEMBER_{ENABLE,DISABLE} to handle updating of
-- party members overlapping quests. This will probably be enough to handle
-- model updating.
if(unit == 'party' or unit == 'target') then
self:RegisterEvent('PARTY_MEMBER_ENABLE', Path)
self:RegisterEvent('PARTY_MEMBER_DISABLE', Path)
end
element:Show()
return true
end
end
local function Disable(self)
local element = self.Portrait
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_MODEL_CHANGED', Path)
self:UnregisterEvent('UNIT_PORTRAIT_UPDATE', Path)
self:UnregisterEvent('PORTRAITS_UPDATED', Path)
self:UnregisterEvent('PARTY_MEMBER_ENABLE', Path)
self:UnregisterEvent('PARTY_MEMBER_DISABLE', Path)
self:UnregisterEvent('UNIT_CONNECTION', Path)
end
end
oUF:AddElement('Portrait', Path, Enable, Disable)