Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Portrait = {}
- ShadowUF:RegisterModule(Portrait, "portrait", ShadowUF.L["Portrait"])
- -- If the camera isn't reset OnShow, it'll show the entire character instead of just the head, odd I know
- local function resetCamera(self)
- self:SetCamera(0)
- end
- local function resetGUID(self)
- self.guid = nil
- end
- function Portrait:OnEnable(frame)
- frame:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", self, "UpdateFunc")
- frame:RegisterUnitEvent("UNIT_MODEL_CHANGED", self, "Update")
- frame:RegisterUpdateFunc(self, "UpdateFunc")
- --frame:RegisterUpdateFunc(self, "Update")
- end
- function Portrait:OnDisable(frame)
- frame:UnregisterAll(self)
- end
- function Portrait:OnPreLayoutApply(frame, config)
- if( not frame.visibility.portrait ) then return end
- if( config.portrait.type == "3D" ) then
- if( not frame.portraitModel ) then
- frame.portraitModel = CreateFrame("PlayerModel", nil, frame)
- frame.portraitModel:SetScript("OnShow", resetCamera)
- frame.portraitModel:SetScript("OnHide", resetGUID)
- frame.portraitModel.parent = frame
- end
- frame.portrait = frame.portraitModel
- frame.portrait:Show()
- ShadowUF.Layout:ToggleVisibility(frame.portraitTexture, false)
- else
- frame.portraitTexture = frame.portraitTexture or frame:CreateTexture(nil, "ARTWORK")
- frame.portrait = frame.portraitTexture
- frame.portrait:Show()
- ShadowUF.Layout:ToggleVisibility(frame.portraitModel, false)
- end
- portrait = frame.portrait
- if( not frame.health ) then
- frame.health = frame.portrait:CreateTexture(nil, "OVERLAY")
- frame.health:ClearAllPoints()
- frame.health:SetPoint("TOPRIGHT", frame.portrait, "TOPRIGHT")
- frame.health:SetPoint("BOTTOMRIGHT", frame.portrait, "BOTTOMRIGHT")
- frame.health:SetWidth(1)
- frame.health:SetTexture("Interface\\AddOns\\ShadowedUnitFrames\\Media\\Textures\\Striped")
- frame.health:SetHorizTile(true)
- frame.health:SetVertTile(false)
- frame.health:SetVertexColor(0.75,0.75,0.75)
- frame.health:SetBlendMode("ADD")
- frame.health.child = frame:CreateTexture(nil, "OVERLAY", nil, -8)
- frame.health.child:ClearAllPoints()
- frame.health.child:SetPoint("TOPLEFT", frame.health, "TOPLEFT")
- frame.health.child:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT")
- frame.health.child:SetTexture("Interface\\AddOns\\ShadowedUnitFrames\\Media\\Textures\\Striped")
- frame.health.child:SetHorizTile(true)
- frame.health.child:SetVertTile(false)
- frame.health.child:SetBlendMode("ADD")
- local t = 0
- frame.timer = CreateFrame("Frame")
- frame.timer:RegisterEvent("UNIT_NAME_UPDATE")
- frame.timer:SetScript("OnEvent", function(self, unit)
- Portrait:UpdateHealthBar(frame)
- end)
- frame.timer:SetScript("OnUpdate", function(self, elapsed, ...)
- t = t + elapsed
- if t > 0.1 then
- Portrait:UpdateHealthBar(frame)
- t = 0
- end
- end)
- frame.health:Hide()
- frame.health.child:Hide()
- frame.health.parent = frame.portrait
- end
- end
- function Portrait:UpdateFunc(frame)
- -- Portrait models can't be updated unless the GUID changed or else you have the animation jumping around
- if( ShadowUF.db.profile.units[frame.unitType].portrait.type == "3D" ) then
- local guid = UnitGUID(frame.unitOwner)
- if( frame.portrait.guid ~= guid ) then
- self:Update(frame)
- end
- frame.portrait.guid = guid
- else
- self:Update(frame)
- end
- end
- function Portrait:UpdateHealthBar(frame)
- --Update the Health Overlay
- local isOffline = not UnitIsConnected(frame.unit)
- local isDead = UnitIsDeadOrGhost(frame.unit)
- local currentHealth = UnitHealth(frame.unit)
- local maxHealth = UnitHealthMax(frame.unit)
- local width = frame.portrait:GetWidth()
- frame.health:SetWidth((isOffline or isDead) and width or (width - (width * (currentHealth / maxHealth))))
- if currentHealth/maxHealth == 1 then
- frame.health:Hide()
- frame.health.child:Hide()
- else
- frame.health:Show()
- frame.health.child:Show()
- end
- end
- function Portrait:Update(frame, event)
- local type = ShadowUF.db.profile.units[frame.unitType].portrait.type
- -- Use class thingy
- if( type == "class" ) then
- local classToken = select(2, UnitClass(frame.unitOwner))
- if( classToken ) then
- frame.portrait:SetTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes")
- frame.portrait:SetTexCoord(CLASS_ICON_TCOORDS[classToken][1], CLASS_ICON_TCOORDS[classToken][2], CLASS_ICON_TCOORDS[classToken][3], CLASS_ICON_TCOORDS[classToken][4])
- else
- frame.portrait:SetTexture("")
- end
- -- Use 2D character image
- elseif( type == "2D" ) then
- frame.portrait:SetTexCoord(0.10, 0.90, 0.10, 0.90)
- SetPortraitTexture(frame.portrait, frame.unitOwner)
- -- Using 3D portrait, but the players not in range so swap to question mark
- elseif( not UnitIsVisible(frame.unitOwner) or not UnitIsConnected(frame.unitOwner) ) then
- frame.portrait:SetModelScale(4.25)
- frame.portrait:SetPosition(0, 0, -0.4)
- frame.portrait:SetModel("Interface\\Buttons\\talktomequestionmark.mdx")
- -- Use animated 3D portrait
- else
- frame.portrait:SetUnit(frame.unitOwner)
- frame.portrait:SetCamera(0)
- frame.portrait:Show()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement