Skip to content

Commit

Permalink
portrait: Update element (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
ls- committed Jul 18, 2022
1 parent f3629a7 commit 3b998dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Expand Up @@ -92,6 +92,7 @@ read_globals = {
'UnitCastingInfo',
'UnitChannelInfo',
'UnitClass',
'UnitClassBase',
'UnitExists',
'UnitFactionGroup',
'UnitGUID',
Expand Down
21 changes: 16 additions & 5 deletions elements/portrait.lua
Expand Up @@ -12,6 +12,10 @@ Portrait - A `PlayerModel` or a `Texture` used to represent the unit's portrait.
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
Expand Down Expand Up @@ -50,7 +54,8 @@ local function Update(self, event, unit)
local guid = UnitGUID(unit)
local isAvailable = UnitIsConnected(unit) and UnitIsVisible(unit)
if(event ~= 'OnUpdate' or element.guid ~= guid or element.state ~= isAvailable) then
local hasStateChanged = event ~= 'OnUpdate' or element.guid ~= guid or element.state ~= isAvailable
if(hasStateChanged) then
if(element:IsObjectType('PlayerModel')) then
if(not isAvailable) then
element:SetCamDistanceScale(0.25)
Expand All @@ -66,7 +71,12 @@ local function Update(self, event, unit)
element:SetUnit(unit)
end
else
SetPortraitTexture(element, unit)
local class = element.showClass and UnitClassBase(unit)
if(class) then
element:SetAtlas('classicon-' .. class)
else
SetPortraitTexture(element, unit)
end
end
element.guid = guid
Expand All @@ -76,11 +86,12 @@ local function Update(self, event, unit)
--[[ 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)
* 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)
return element:PostUpdate(unit, hasStateChanged)
end
end
Expand Down

0 comments on commit 3b998dc

Please sign in to comment.