Advertisement
Guest User

basecombopoints.lua

a guest
Dec 4th, 2022
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.40 KB | None | 0 0
  1. local Combo = {isComboPoints = true}
  2. ShadowUF.ComboPoints = Combo
  3.  
  4. local function createIcons(config, pointsFrame)
  5. local point, relativePoint, x, y
  6. local pointsConfig = pointsFrame.cpConfig
  7.  
  8. if( config.growth == "LEFT" ) then
  9. point, relativePoint = "BOTTOMRIGHT", "BOTTOMLEFT"
  10. x = config.spacing
  11. elseif( config.growth == "UP" ) then
  12. point, relativePoint = "BOTTOMLEFT", "TOPLEFT"
  13. y = config.spacing
  14. elseif( config.growth == "DOWN" ) then
  15. point, relativePoint = "TOPLEFT", "BOTTOMLEFT"
  16. y = config.spacing
  17. else
  18. point, relativePoint = "BOTTOMLEFT", "BOTTOMRIGHT"
  19. x = config.spacing
  20. end
  21.  
  22. x = x or 0
  23. y = y or 0
  24.  
  25. for id=1, pointsConfig.max do
  26. pointsFrame.icons[id] = pointsFrame.icons[id] or pointsFrame:CreateTexture(nil, "OVERLAY")
  27. local texture = pointsFrame.icons[id]
  28. texture:SetTexture(pointsConfig.icon)
  29. texture:SetSize(config.size or 16, config.size or 16)
  30.  
  31. if( id > 1 ) then
  32. texture:ClearAllPoints()
  33. texture:SetPoint(point, pointsFrame.icons[id - 1], relativePoint, x, y)
  34. else
  35. texture:ClearAllPoints()
  36. texture:SetPoint("CENTER", pointsFrame, "CENTER", 0, 0)
  37. end
  38. end
  39. end
  40.  
  41. local function createBlocks(config, pointsFrame)
  42. local pointsConfig = pointsFrame.cpConfig
  43. if pointsConfig.max == 0 then return end
  44. pointsFrame.visibleBlocks = pointsConfig.max
  45.  
  46. -- Position bars, the 5 accounts for borders
  47. local blockWidth = (pointsFrame:GetWidth() - ((pointsConfig.max / (pointsConfig.grouping or 1)) - 1)) / pointsConfig.max
  48. for id=1, pointsConfig.max do
  49. pointsFrame.blocks[id] = pointsFrame.blocks[id] or pointsFrame:CreateTexture(nil, "OVERLAY")
  50. local texture = pointsFrame.blocks[id]
  51. local color = ShadowUF.db.profile.powerColors[pointsConfig.colorKey or "COMBOPOINTS"]
  52. texture:SetVertexColor(color.r, color.g, color.b, color.a)
  53. texture:SetHorizTile(false)
  54. texture:SetTexture(ShadowUF.Layout.mediaPath.statusbar)
  55. texture:SetHeight(pointsFrame:GetHeight())
  56. texture:SetWidth(blockWidth)
  57. texture:ClearAllPoints()
  58.  
  59. if not texture.background and config.background then
  60. texture.background = pointsFrame:CreateTexture(nil, "BORDER")
  61. texture.background:SetHeight(1)
  62. texture.background:SetWidth(1)
  63. texture.background:SetAllPoints(texture)
  64. texture.background:SetHorizTile(false)
  65. texture.background:SetVertexColor(color.r, color.g, color.b, ShadowUF.db.profile.bars.backgroundAlpha)
  66. texture.background:SetTexture(ShadowUF.Layout.mediaPath.statusbar)
  67. end
  68.  
  69. if texture.background then
  70. texture.background:SetShown(config.background)
  71. end
  72.  
  73. local offset = 1
  74. if pointsConfig.grouping and ((id - 1) % pointsConfig.grouping ~= 0) then
  75. offset = 0
  76. end
  77. if( config.growth == "LEFT" ) then
  78. if( id > 1 ) then
  79. texture:SetPoint("TOPRIGHT", pointsFrame.blocks[id - 1], "TOPLEFT", -offset, 0)
  80. else
  81. texture:SetPoint("TOPRIGHT", pointsFrame, "TOPRIGHT", 0, 0)
  82. end
  83. else
  84. if( id > 1 ) then
  85. texture:SetPoint("TOPLEFT", pointsFrame.blocks[id - 1], "TOPRIGHT", offset, 0)
  86. else
  87. texture:SetPoint("TOPLEFT", pointsFrame, "TOPLEFT", 0, 0)
  88. end
  89. end
  90. end
  91. end
  92.  
  93. function Combo:OnLayoutApplied(frame, config)
  94. local key = self:GetComboPointType()
  95. local pointsFrame = frame[key]
  96. if( not pointsFrame ) then return end
  97.  
  98. pointsFrame:SetFrameLevel(frame.topFrameLevel + 1)
  99.  
  100. local pointsConfig = pointsFrame.cpConfig
  101. config = config[key]
  102.  
  103. -- Not a bar so set the containers frame configuration
  104. if( config and not config.isBar ) then
  105. ShadowUF.Layout:ToggleVisibility(pointsFrame, frame.visibility[key])
  106. end
  107.  
  108. if( not frame.visibility[key] ) then return end
  109.  
  110. -- Hide the active combo points
  111. if( pointsFrame.points ) then
  112. for _, texture in pairs(pointsFrame.points) do
  113. texture:Hide()
  114. end
  115. end
  116.  
  117. -- Setup for bar display!
  118. if( config.isBar ) then
  119. pointsFrame.blocks = pointsFrame.blocks or {}
  120. pointsFrame.points = pointsFrame.blocks
  121.  
  122. createBlocks(config, pointsFrame, pointsConfig.max)
  123.  
  124. -- guess not, will have to do icons :(
  125. else
  126. pointsFrame.icons = pointsFrame.icons or {}
  127. pointsFrame.points = pointsFrame.icons
  128.  
  129. createIcons(config, pointsFrame, pointsConfig.max)
  130.  
  131. -- Position the main frame
  132. pointsFrame:SetSize(0.1, 0.1)
  133.  
  134. ShadowUF.Layout:AnchorFrame(frame, pointsFrame, config)
  135. end
  136. end
  137.  
  138. function Combo:OnDisable(frame)
  139. frame:UnregisterAll(self)
  140. end
  141.  
  142. function Combo:UpdateBarBlocks(frame, event, unit, powerType)
  143. local key = self:GetComboPointType()
  144. local pointsFrame = frame[key]
  145. if( not pointsFrame or not pointsFrame.cpConfig.eventType or not pointsFrame.blocks ) then return end
  146. if( event and powerType ~= pointsFrame.cpConfig.eventType ) then return end
  147.  
  148. local max = self.GetMaxPoints and self:GetMaxPoints() or UnitPowerMax("player", pointsFrame.cpConfig.powerType)
  149. if( max == 0 or pointsFrame.visibleBlocks == max ) then return end
  150.  
  151. pointsFrame.cpConfig.max = max
  152.  
  153. if( not ShadowUF.db.profile.units[frame.unitType][key].isBar ) then
  154. createIcons(ShadowUF.db.profile.units[frame.unitType][key], pointsFrame)
  155. pointsFrame.visibleBlocks = max
  156. return
  157. else
  158. createBlocks(ShadowUF.db.profile.units[frame.unitType][key], pointsFrame)
  159. pointsFrame.visibleBlocks = max
  160. end
  161.  
  162. local blockWidth = (pointsFrame:GetWidth() - (max - 1)) / max
  163. for id=1, max do
  164. pointsFrame.blocks[id]:SetWidth(blockWidth)
  165. pointsFrame.blocks[id]:Show()
  166. end
  167.  
  168. for id=max+1, #pointsFrame.blocks do
  169. pointsFrame.blocks[id]:Hide()
  170. end
  171.  
  172. end
  173.  
  174. function Combo:Update(frame, event, unit, powerType)
  175. local key = self:GetComboPointType()
  176. -- Anything power based will have an eventType to filter on
  177. if( event and frame[key].cpConfig.eventType and frame[key].cpConfig.eventType ~= powerType ) then return end
  178.  
  179. local points = self:GetPoints(unit)
  180.  
  181. -- Bar display, hide it if we don't have any combo points
  182. if( ShadowUF.db.profile.units[frame.unitType][key].isBar ) then
  183. ShadowUF.Layout:SetBarVisibility(frame, key, ShadowUF.db.profile.units[frame.unitType][key].showAlways or (points and points > 0))
  184. end
  185.  
  186. local hasEchoing = IsPlayerSpell(385616)
  187.  
  188. for id, pointTexture in pairs(frame[key].points) do
  189. local color = ShadowUF.db.profile.powerColors["COMBOPOINTS"]
  190. if hasEchoing then
  191. for idx=1,40 do
  192. local name, _, _, _, _, _, _, _, _, spellId = UnitBuff("player", idx)
  193. if spellId ~= nil then
  194. if id == 5 and spellId == 354838 then
  195. color = ShadowUF.db.profile.powerColors["CHI"]
  196. end
  197. if id == 4 and spellId == 323560 then
  198. color = ShadowUF.db.profile.powerColors["CHI"]
  199. end
  200. if id == 3 and spellId == 323559 then
  201. color = ShadowUF.db.profile.powerColors["CHI"]
  202. end
  203. if id == 2 and spellId == 323558 then
  204. color = ShadowUF.db.profile.powerColors["CHI"]
  205. end
  206. end
  207. end
  208. if( id <= points ) then
  209. pointTexture:SetVertexColor(color.r, color.g, color.b, color.a)
  210. pointTexture:Show()
  211. else
  212. pointTexture.background:SetVertexColor(color.r, color.g, color.b, 0.3)
  213. pointTexture:Hide()
  214. end
  215. else
  216. if( id <= points ) then
  217. pointTexture:Show()
  218. else
  219. pointTexture:Hide()
  220. end
  221. end
  222.  
  223. end
  224. end
  225.  
  226. function Combo:OnLayoutWidgets(frame)
  227. local key = self:GetComboPointType()
  228. if( not frame.visibility[key] or not ShadowUF.db.profile.units[frame.unitType][key].isBar or not frame[key].blocks) then return end
  229.  
  230. local height = frame[key]:GetHeight()
  231. for _, block in pairs(frame[key].blocks) do
  232. block:SetHeight(height)
  233. end
  234. end
  235.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement