Advertisement
architekt909

Untitled

Mar 31st, 2021
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.72 KB | None | 0 0
  1. --[[
  2. # Element: PvPClassificationIndicator
  3.  
  4. Handles the visibility and updating of an indicator based on the unit's PvP classification.
  5.  
  6. ## Widget
  7.  
  8. PvPClassificationIndicator - A `Texture` used to display PvP classification.
  9.  
  10. ## Notes
  11.  
  12. This element updates by changing the texture.
  13.  
  14. ## Options
  15.  
  16. .useAtlasSize - Makes the element use preprogrammed atlas' size instead of its set dimensions (boolean)
  17.  
  18. ## Examples
  19.  
  20.     -- Position and size
  21.     local PvPClassificationIndicator = self:CreateTexture(nil, 'OVERLAY')
  22.     PvPClassificationIndicator:SetSize(24, 24)
  23.     PvPClassificationIndicator:SetPoint('CENTER')
  24.  
  25.     -- Register it with oUF
  26.     self.PvPClassificationIndicator = PvPClassificationIndicator
  27. --]]
  28.  
  29. local _, ns = ...
  30. local oUF = ns.oUF
  31.  
  32. -- sourced from FrameXML/CompactUnitFrame.lua
  33. local ICONS = {
  34.     [Enum.PvPUnitClassification.FlagCarrierHorde or 0] = "nameplates-icon-flag-horde",
  35.     [Enum.PvPUnitClassification.FlagCarrierAlliance or 1] = "nameplates-icon-flag-alliance",
  36.     [Enum.PvPUnitClassification.FlagCarrierNeutral or 2] = "nameplates-icon-flag-neutral",
  37.     [Enum.PvPUnitClassification.CartRunnerHorde or 3] = "nameplates-icon-cart-horde",
  38.     [Enum.PvPUnitClassification.CartRunnerAlliance or 4] = "nameplates-icon-cart-alliance",
  39.     [Enum.PvPUnitClassification.AssassinHorde or 5] = "nameplates-icon-bounty-horde",
  40.     [Enum.PvPUnitClassification.AssassinAlliance or 6] = "nameplates-icon-bounty-alliance",
  41.     [Enum.PvPUnitClassification.OrbCarrierBlue or 7] = "nameplates-icon-orb-blue",
  42.     [Enum.PvPUnitClassification.OrbCarrierGreen or 8] = "nameplates-icon-orb-green",
  43.     [Enum.PvPUnitClassification.OrbCarrierOrange or 9] = "nameplates-icon-orb-orange",
  44.     [Enum.PvPUnitClassification.OrbCarrierPurple or 10] = "nameplates-icon-orb-purple",
  45. }
  46.  
  47. local function Update(self, event, unit)
  48.     if(unit ~= self.unit) then return end
  49.  
  50.     local element = self.PvPClassificationIndicator
  51.  
  52.     --[[ Callback: PvPClassificationIndicator:PreUpdate(unit)
  53.     Called before the element has been updated.
  54.  
  55.     * self - the PvPClassificationIndicator element
  56.     * unit - the unit for which the update has been triggered (string)
  57.     --]]
  58.     if(element.PreUpdate) then
  59.         element:PreUpdate(unit)
  60.     end
  61.  
  62.     local class = UnitPvpClassification(unit)
  63.     local icon = ICONS[class]
  64.     if(icon) then
  65.         element:SetAtlas(icon, element.useAtlasSize)
  66.         element:Show()
  67.     else
  68.         element:Hide()
  69.     end
  70.  
  71.     --[[ Callback: PvPClassificationIndicator:PostUpdate(unit, class)
  72.     Called after the element has been updated.
  73.  
  74.     * self  - the PvPClassificationIndicator element
  75.     * unit  - the unit for which the update has been triggered (string)
  76.     * class - the pvp classification of the unit (number?)
  77.     --]]
  78.     if(element.PostUpdate) then
  79.         return element:PostUpdate(unit, class)
  80.     end
  81. end
  82.  
  83. local function Path(self, ...)
  84.     --[[Override: PvPClassificationIndicator.Override(self, event, ...)
  85.     Used to completely override the internal update function.
  86.  
  87.     * self  - the parent object
  88.     * event - the event triggering the update (string)
  89.     * ...   - the arguments accompanying the event
  90.     --]]
  91.     return (self.PvPClassificationIndicator.Override or Update) (self, ...)
  92. end
  93.  
  94. local function ForceUpdate(element)
  95.     return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  96. end
  97.  
  98. local function Enable(self)
  99.     local element = self.PvPClassificationIndicator
  100.     if(element) then
  101.         element.__owner = self
  102.         element.ForceUpdate = ForceUpdate
  103.  
  104.         self:RegisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
  105.  
  106.         return true
  107.     end
  108. end
  109.  
  110. local function Disable(self)
  111.     local element = self.PvPClassificationIndicator
  112.     if(element) then
  113.         element:Hide()
  114.  
  115.         self:UnregisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
  116.     end
  117. end
  118.  
  119. oUF:AddElement('PvPClassificationIndicator', Path, Enable, Disable)
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement