Commit ae7a12c6 authored by Val Voronov's avatar Val Voronov Committed by GitHub

portrait: Fix updates for *target units (#399)

parent 5220a4e6
......@@ -36,7 +36,7 @@ local _, ns = ...
local oUF = ns.oUF
local function Update(self, event, unit)
if(self.unit ~= unit) then return end
if(not unit or not UnitIsUnit(self.unit, unit)) then return end
local element = self.Portrait
......@@ -48,25 +48,29 @@ local function Update(self, event, unit)
--]]
if(element.PreUpdate) then element:PreUpdate(unit) end
if(element:IsObjectType('PlayerModel')) then
local guid = UnitGUID(unit)
if(not UnitExists(unit) or not UnitIsConnected(unit) or not UnitIsVisible(unit)) then
element:SetCamDistanceScale(0.25)
element:SetPortraitZoom(0)
element:SetPosition(0, 0, 0.5)
element:ClearModel()
element:SetModel([[Interface\Buttons\TalkToMeQuestionMark.m2]])
element.guid = nil
elseif(element.guid ~= guid or event == 'UNIT_MODEL_CHANGED') then
element:SetCamDistanceScale(1)
element:SetPortraitZoom(1)
element:SetPosition(0, 0, 0)
element:ClearModel()
element:SetUnit(unit)
element.guid = guid
local guid = UnitGUID(unit)
local isAvailable = UnitIsConnected(unit) and UnitIsVisible(unit)
if(event ~= 'OnUpdate' or element.guid ~= guid or element.state ~= isAvailable) 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
SetPortraitTexture(element, unit)
end
else
SetPortraitTexture(element, unit)
element.guid = guid
element.state = isAvailable
end
--[[ Callback: Portrait:PostUpdate(unit)
......@@ -101,7 +105,6 @@ local function Enable(self, unit)
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_PORTRAIT_UPDATE', Path)
self:RegisterEvent('UNIT_MODEL_CHANGED', Path)
self:RegisterEvent('UNIT_CONNECTION', Path)
......@@ -126,7 +129,6 @@ local function Disable(self)
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_PORTRAIT_UPDATE', Path)
self:UnregisterEvent('UNIT_MODEL_CHANGED', Path)
self:UnregisterEvent('PARTY_MEMBER_ENABLE', Path)
self:UnregisterEvent('UNIT_CONNECTION', Path)
......
......@@ -66,8 +66,9 @@ registering events.
automatically considered unitless (boolean)
--]]
function frame_metatable.__index:RegisterEvent(event, func, unitless)
-- Block OnUpdate polled frames from registering events.
if(self.__eventless) then return end
-- Block OnUpdate polled frames from registering events except for
-- UNIT_MODEL_CHANGED which is used for portrait updates.
if(self.__eventless and event ~= 'UNIT_MODEL_CHANGED') then return end
argcheck(event, 2, 'string')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment