Guest User

Untitled

a guest
Sep 15th, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.61 KB | None | 0 0
  1. --[[
  2.     Copyright (C) 2006-2007 Nymbia
  3.     Copyright (C) 2010-2017 Hendrik "Nevcairiel" Leppkes < [email protected] >
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License along
  16.     with this program; if not, write to the Free Software Foundation, Inc.,
  17.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. ]]
  19. local Quartz3 = LibStub("AceAddon-3.0"):GetAddon("Quartz3")
  20. local L = LibStub("AceLocale-3.0"):GetLocale("Quartz3")
  21.  
  22. local MODNAME = "Player"
  23. local Player = Quartz3:NewModule(MODNAME, "AceEvent-3.0", "AceHook-3.0")
  24.  
  25. local UnitCastingInfo, UnitChannelInfo = UnitCastingInfo, UnitChannelInfo
  26.  
  27. local WOW_INTERFACE_VER = select(4, GetBuildInfo())
  28. local WoWRetail = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE)
  29. local WoWBC = (WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE) and WOW_INTERFACE_VER >= 20500 and WOW_INTERFACE_VER < 30000
  30. local WoWWrath = (WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE) and WOW_INTERFACE_VER >= 30400 and WOW_INTERFACE_VER < 40000
  31. local WoWCata = (WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE) and WOW_INTERFACE_VER >= 40400 and WOW_INTERFACE_VER < 50000
  32.  
  33. local GetSpellName = C_Spell and C_Spell.GetSpellName or GetSpellInfo
  34.  
  35. --attempt to work around loading bugs in a...hacky way -.-
  36. local FreshCounter = 0
  37. ----------------------------
  38. -- Upvalues
  39. -- GLOBALS: CastingBarFrame
  40. local unpack = unpack
  41.  
  42.  
  43. local db, getOptions, castBar
  44.  
  45. local defaults = {
  46.     profile = Quartz3:Merge(Quartz3.CastBarTemplate.defaults,
  47.     {
  48.         hideblizz = true,
  49.         showticks = true,
  50.         -- no interrupt is pointless for player, disable all options
  51.         noInterruptBorderChange = false,
  52.         noInterruptColorChange = false,
  53.         noInterruptShield = false,
  54.         targetnamestyle = "default"
  55.     })
  56. }
  57.  
  58. do
  59.     local function setOpt(info, value)
  60.         db[info[#info]] = value
  61.         Player:ApplySettings()
  62.     end
  63.  
  64.     local options
  65.     function getOptions()
  66.         if not options then
  67.             options = Player.Bar:CreateOptions()
  68.             options.args.hideblizz = {
  69.                 type = "toggle",
  70.                 name = L["Disable Blizzard Cast Bar"],
  71.                 desc = L["Disable and hide the default UI's casting bar"],
  72.                 set = setOpt,
  73.                 order = 101,
  74.             }
  75.             options.args.showticks = {
  76.                 type = "toggle",
  77.                 name = L["Show channeling ticks"],
  78.                 desc = L["Show damage / mana ticks while channeling spells like Drain Life or Blizzard"],
  79.                 order = 102,
  80.             }
  81.             options.args.nlttargetname = {
  82.                 type = "description",
  83.                 name = "",
  84.                 order = 408.0,
  85.             }
  86.             options.args.targetname = {
  87.                 type = "toggle",
  88.                 name = L["Show Target Name"],
  89.                 desc = L["Display target name of spellcasts after spell name"],
  90.                 disabled = function() return db.hidenametext end,
  91.                 order = 408.1,
  92.             }
  93.             options.args.targetnamestyle = {
  94.                 type = "select",
  95.                 name = L["Target Name Style"],
  96.                 desc = L["How to display target name of spellcasts after spell name"],
  97.                 values = {["default"] = L["Spell -> Target"], ["on"] = L["Spell on Target"]},
  98.                 disabled = function() return not db.targetname or db.hidenametext end,
  99.                 order = 409,
  100.             }
  101.             options.args.noInterruptGroup = nil
  102.         end
  103.         return options
  104.     end
  105. end
  106.  
  107. local function OnUpdate(self)
  108.     if self.casting and self.chargeSpell then
  109.         Player:UpdateStage(self)
  110.     end
  111. end
  112.  
  113. function Player:OnInitialize()
  114.     self.db = Quartz3.db:RegisterNamespace(MODNAME, defaults)
  115.     db = self.db.profile
  116.  
  117.     self:SetEnabledState(Quartz3:GetModuleEnabled(MODNAME))
  118.     Quartz3:RegisterModuleOptions(MODNAME, getOptions, L["Player"])
  119.  
  120.     self.Bar = Quartz3.CastBarTemplate:new(self, "player", MODNAME, L["Player"], db)
  121.     castBar = self.Bar.Bar
  122.  
  123.     self:Hook(self.Bar, "OnUpdate", OnUpdate)
  124.     self.Bar:SetScript("OnUpdate", self.Bar.OnUpdate)
  125. end
  126.  
  127.  
  128. function Player:OnEnable()
  129.     if WoWRetail then
  130.         self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED", "UpdateChannelingTicks")
  131.         self:RegisterEvent("TRAIT_CONFIG_UPDATED", "UpdateChannelingTicks")
  132.     end
  133.  
  134.     self.Bar:RegisterEvents()
  135.     self:ApplySettings()
  136.  
  137.     self:UpdateChannelingTicks()
  138.    
  139.     --attempt to work around loading bugs in a...hacky way -.-
  140.     FreshCounter = 0
  141. end
  142.  
  143. function Player:OnDisable()
  144.     self.Bar:UnregisterEvents()
  145.     self.Bar:Hide()
  146. end
  147.  
  148. function Player:ApplySettings()
  149.     db = self.db.profile
  150.  
  151.     -- obey the hideblizz setting no matter if disabled or not
  152.     if PlayerCastingBarFrame then
  153.         if db.hideblizz then
  154.             PlayerCastingBarFrame.RegisterEvent = function() end
  155.             PlayerCastingBarFrame:UnregisterAllEvents()
  156.             PlayerCastingBarFrame:Hide()
  157.         else
  158.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_INTERRUPTED", "player")
  159.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_DELAYED", "player")
  160.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_START", "player")
  161.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_UPDATE", "player")
  162.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_STOP", "player")
  163.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_EMPOWER_START", "player")
  164.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_EMPOWER_UPDATE", "player")
  165.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_EMPOWER_STOP", "player")
  166.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_INTERRUPTIBLE", "player")
  167.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE", "player")
  168.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_START", "player")
  169.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_STOP", "player")
  170.             PlayerCastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_FAILED", "player")
  171.             PlayerCastingBarFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  172.         end
  173.     else
  174.         if db.hideblizz then
  175.             CastingBarFrame.RegisterEvent = function() end
  176.             CastingBarFrame:UnregisterAllEvents()
  177.             CastingBarFrame:Hide()
  178.         else
  179.             CastingBarFrame.RegisterEvent = nil
  180.             CastingBarFrame:UnregisterAllEvents()
  181.             CastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_START", "player")
  182.             CastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_STOP", "player")
  183.             CastingBarFrame:RegisterUnitEvent("UNIT_SPELLCAST_FAILED", "player")
  184.             CastingBarFrame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
  185.             CastingBarFrame:RegisterEvent("UNIT_SPELLCAST_DELAYED")
  186.             CastingBarFrame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
  187.             CastingBarFrame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
  188.             CastingBarFrame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
  189.             if WoWRetail then
  190.                 CastingBarFrame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE")
  191.                 CastingBarFrame:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE")
  192.             end
  193.             CastingBarFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  194.         end
  195.     end
  196.  
  197.     self.Bar:SetConfig(db)
  198.     if self:IsEnabled() then
  199.         self.Bar:ApplySettings()
  200.     end
  201. end
  202.  
  203. function Player:Unlock()
  204.     self.Bar:Unlock()
  205. end
  206.  
  207. function Player:Lock()
  208.     self.Bar:Lock()
  209. end
  210.  
  211. ----------------------------
  212. -- Cast Bar Hooks
  213.  
  214. function Player:OnHide()
  215.     local Latency = Quartz3:GetModule("Latency", true)
  216.     if Latency then
  217.         if Latency:IsEnabled() and Latency.lagbox then
  218.             Latency.lagbox:Hide()
  219.             Latency.lagtext:Hide()
  220.         end
  221.     end
  222. end
  223.  
  224. local sparkfactory = {
  225.     __index = function(t,k)
  226.         local spark = castBar:CreateTexture(nil, 'OVERLAY')
  227.         t[k] = spark
  228.         spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
  229.         spark:SetVertexColor(unpack(Quartz3.db.profile.sparkcolor))
  230.         spark:SetBlendMode('ADD')
  231.         spark:SetWidth(20)
  232.         spark:SetHeight(db.h*2.2)
  233.         return spark
  234.     end
  235. }
  236. local barticks = setmetatable({}, sparkfactory)
  237.  
  238. local function setBarTicks(ticknum, duration, ticks)
  239.     if( ticknum and ticknum > 0) then
  240.         local width = castBar:GetWidth()
  241.         for k = 1, ticknum do
  242.             local t = barticks[k]
  243.             t:ClearAllPoints()
  244.             local x = ticks[k] / duration
  245.             t:SetPoint("CENTER", castBar, "RIGHT", -width * x, 0 )
  246.             t:Show()
  247.         end
  248.         for k = ticknum+1,#barticks do
  249.             barticks[k]:Hide()
  250.         end
  251.     else
  252.         barticks[1].Hide = nil
  253.         for i=1,#barticks do
  254.             barticks[i]:Hide()
  255.         end
  256.     end
  257. end
  258.  
  259. local channelingTicks = WoWWrath and {
  260.     --- Wrath
  261.     -- druid
  262.     [GetSpellName(740)] = 4, -- tranquility
  263.     [GetSpellName(16914)] = 10, -- hurricane
  264.     -- hunter
  265.     [GetSpellName(1510)] = 6, -- volley
  266.     -- mage
  267.     [GetSpellName(10)] = 8, -- blizzard
  268.     [5143] = 3, -- arcane missiles r1
  269.     [5144] = 4, -- arcane missiles r2
  270.     [GetSpellName(5145)] = 5, -- arcane missiles
  271.     -- priest
  272.     [GetSpellName(15407)] = 3, -- mind flay
  273.     [GetSpellName(48045)] = 5, -- mind sear
  274.     [GetSpellName(47540)] = 2, -- penance
  275.     [GetSpellName(64843)] = 4, -- divine hymn
  276.     [GetSpellName(64901)] = 4, -- hymn of hope
  277.     -- warlock
  278.     [GetSpellName(1949)] = 15, -- hellfire
  279.     [GetSpellName(5740)] = 4, -- rain of fire
  280.     [GetSpellName(5138)] = 5, -- drain mana
  281.     [GetSpellName(689)] = 5, -- drain life
  282.     [GetSpellName(1120)] = 5, -- drain soul
  283.     [GetSpellName(755)] = 10, -- health funnel
  284. } or WoWCata and {
  285.     --- Wrath
  286.     -- druid
  287.     [GetSpellName(740)] = 4, -- tranquility
  288.     [GetSpellName(16914)] = 10, -- hurricane
  289.     -- mage
  290.     [GetSpellName(10)] = 8, -- blizzard
  291.     [GetSpellName(5143)] = 5, -- arcane missiles
  292.     -- priest
  293.     [GetSpellName(15407)] = 3, -- mind flay
  294.     [GetSpellName(48045)] = 5, -- mind sear
  295.     [GetSpellName(47540)] = 2, -- penance
  296.     [GetSpellName(64843)] = 4, -- divine hymn
  297.     [GetSpellName(64901)] = 4, -- hymn of hope
  298.     -- warlock
  299.     [GetSpellName(1949)] = 15, -- hellfire
  300.     [GetSpellName(5740)] = 4, -- rain of fire
  301.     [GetSpellName(689)] = 5, -- drain life
  302.     [GetSpellName(1120)] = 5, -- drain soul
  303.     [GetSpellName(755)] = 10, -- health funnel
  304. } or WoWBC and {
  305.     --- BCC
  306.     -- druid
  307.     [GetSpellName(740)] = 4, -- tranquility
  308.     [GetSpellName(16914)] = 10, -- hurricane
  309.     -- hunter
  310.     [GetSpellName(1510)] = 6, -- volley
  311.     -- mage
  312.     [GetSpellName(10)] = 8, -- blizzard
  313.     [5143] = 3, -- arcane missiles r1
  314.     [5144] = 4, -- arcane missiles r2
  315.     [GetSpellName(5145)] = 5, -- arcane missiles
  316.     -- priest
  317.     [GetSpellName(15407)] = 3, -- mind flay
  318.     [GetSpellName(10797)] = 5, -- star shards
  319.     -- warlock
  320.     [GetSpellName(1949)] = 15, -- hellfire
  321.     [GetSpellName(5740)] = 4, -- rain of fire
  322.     [GetSpellName(5138)] = 5, -- drain mana
  323.     [GetSpellName(689)] = 5, -- drain life
  324.     [GetSpellName(1120)] = 5, -- drain soul
  325.     [GetSpellName(755)] = 10, -- health funnel
  326. } or WoWRetail and {
  327.     --- Retail
  328.     -- warlock
  329.     [GetSpellName(234153)] = 5, -- drain life
  330.     [GetSpellName(198590)] = 5, -- drain soul
  331.     [GetSpellName(217979)] = 5, -- health funnel
  332.     -- druid
  333.     [GetSpellName(740)] = 4, -- tranquility
  334.     -- priest
  335.     [GetSpellName(64843)] = 4, -- divine hymn
  336.     [GetSpellName(15407)] = 6, -- mind flay
  337.     [GetSpellName(391403)] = 4, -- mind flay: insanity
  338.     [GetSpellName(47540)] = 3, -- penance
  339.     [GetSpellName(205065)] = 5, -- void torrent
  340.     [GetSpellName(64901)] = 5, -- symbol of hope
  341.     -- mage
  342.     [GetSpellName(5143)] = 5, -- arcane missiles
  343.     [GetSpellName(205021)] = 5, -- ray of frost
  344.     [GetSpellName(314791)] = 4, -- covenant: shifting power
  345.     -- monk
  346.     [GetSpellName(117952)] = 4, -- crackling jade lightning
  347.     --[GetSpellName(191837)] = 3, -- essence font
  348.     [GetSpellName(115175)] = 8, -- soothing mist
  349.     -- evoker
  350.     [GetSpellName(356995)] = 3, -- disintegrate
  351. } or {}
  352.  
  353.  
  354. local function getChannelingTicks(spell, spellid)
  355.     if not db.showticks then
  356.         return 0
  357.     end
  358.     return channelingTicks[spellid] or channelingTicks[spell] or 0
  359. end
  360.  
  361. local function isTalentKnown(talentID)
  362.     return (select(4, GetTalentInfoByID(19752, GetActiveSpecGroup())))
  363. end
  364.  
  365. function Player:UpdateChannelingTicks()
  366.     local playerClass = select(2, UnitClass("player"))
  367.     if WoWRetail then
  368.         if playerClass == "PRIEST" then
  369.             -- Castigation talent adds a tick to penance
  370.             channelingTicks[GetSpellName(47540)] = IsPlayerSpell(193134) and 4 or 3
  371.         end
  372.     end
  373. end
  374.  
  375. function Player:UNIT_SPELLCAST_START(bar, unit)
  376.    
  377.     --attempt to work around loading bugs in a...hacky way -.-
  378.     if FreshCounter < 2 then
  379.         LibStub("AceAddon-3.0"):GetAddon("Quartz3"):GetModule("Player"):ApplySettings()
  380.         LibStub("AceAddon-3.0"):GetAddon("Quartz3"):GetModule("Target"):ApplySettings()
  381.         LibStub("AceAddon-3.0"):GetAddon("Quartz3"):GetModule("Latency"):ApplySettings()
  382.         FreshCounter = FreshCounter + 1
  383.     end
  384.    
  385.    
  386.     if bar.channeling then
  387.         local spell, _, _, _, _, _, _, spellid = UnitChannelInfo(unit)
  388.         bar.channelingEnd = bar.endTime
  389.         bar.channelingDuration = bar.endTime - bar.startTime
  390.         bar.channelingTicks = getChannelingTicks(spell, spellid)
  391.         bar.channelingTickTime = bar.channelingTicks > 0 and (bar.channelingDuration / bar.channelingTicks) or 0
  392.         bar.ticks = bar.ticks or {}
  393.         for i = 1, bar.channelingTicks do
  394.             bar.ticks[i] = bar.channelingDuration - (i - 1) * bar.channelingTickTime
  395.         end
  396.         setBarTicks(bar.channelingTicks, bar.channelingDuration, bar.ticks)
  397.     else
  398.         setBarTicks(0)
  399.         bar.channelingDuration = nil
  400.     end
  401.  
  402.     if bar.casting and bar.chargeSpell and bar.numStages and bar.numStages > 1 then
  403.         self:AddStages(bar, bar.numStages)
  404.     else
  405.         self:ClearStages(bar)
  406.     end
  407. end
  408.  
  409. function Player:UNIT_SPELLCAST_STOP(bar, unit)
  410.     setBarTicks(0)
  411.     bar.channelingDuration = nil
  412. end
  413.  
  414. function Player:UNIT_SPELLCAST_FAILED(bar, unit)
  415.     setBarTicks(0)
  416.     bar.channelingDuration = nil
  417. end
  418.  
  419. function Player:UNIT_SPELLCAST_INTERRUPTED(bar, unit)
  420.     setBarTicks(0)
  421.     bar.channelingDuration = nil
  422. end
  423.  
  424. function Player:UNIT_SPELLCAST_DELAYED(bar, unit)
  425.     if bar.channeling and bar.endTime > bar.channelingEnd then
  426.         local duration = bar.endTime - bar.startTime
  427.         if bar.channelingDuration and duration > bar.channelingDuration and bar.channelingTicks > 0 then
  428.             local extraTime = (duration - bar.channelingDuration)
  429.             for i = 1, bar.channelingTicks do
  430.                 bar.ticks[i] = bar.ticks[i] + extraTime
  431.             end
  432.             while bar.ticks[bar.channelingTicks] > bar.channelingTickTime do
  433.                 bar.channelingTicks = bar.channelingTicks + 1
  434.                 bar.ticks[bar.channelingTicks] = bar.ticks[bar.channelingTicks-1] - bar.channelingTickTime
  435.             end
  436.             bar.channelingDuration = duration
  437.             bar.channelingEnd = bar.endTime
  438.             setBarTicks(bar.channelingTicks, bar.channelingDuration, bar.ticks)
  439.         end
  440.     end
  441. end
  442.  
  443. function Player:GetStageDuration(bar, stage)
  444.     if stage == bar.NumStages then
  445.         return GetUnitEmpowerHoldAtMaxTime(bar.unit)
  446.     else
  447.         return GetUnitEmpowerStageDuration(bar.unit, stage-1)
  448.     end
  449. end
  450.  
  451. function Player:AddStages(bar, numStages)
  452.     bar.CurrSpellStage = -1
  453.     bar.NumStages = numStages + 1
  454.     bar.StagePoints = {}
  455.     bar.StagePips = {}
  456.     bar.StageTiers = {}
  457.  
  458.     local sumDuration = 0
  459.     local stageMaxValue = (bar.endTime - bar.startTime) * 1000
  460.  
  461.     local castBarLeft = bar.Bar:GetLeft()
  462.     local castBarRight = bar.Bar:GetRight()
  463.     local castBarWidth = castBarRight - castBarLeft
  464.  
  465.     for i = 1, bar.NumStages-1, 1 do
  466.         local duration = self:GetStageDuration(bar, i)
  467.         if duration > -1 then
  468.             sumDuration = sumDuration + duration
  469.             local portion = sumDuration / stageMaxValue
  470.             local offset = castBarWidth * portion
  471.             bar.StagePoints[i] = sumDuration
  472.  
  473.             local stagePipName = "StagePip" .. i
  474.             local stagePip = bar[stagePipName]
  475.             if not stagePip then
  476.                 stagePip = CreateFrame("FRAME", nil, bar.Bar, false and "CastingBarFrameStagePipFXTemplate" or "CastingBarFrameStagePipTemplate")
  477.                 bar[stagePipName] = stagePip
  478.             end
  479.  
  480.             if stagePip then
  481.                 table.insert(bar.StagePips, stagePip)
  482.                 stagePip:ClearAllPoints()
  483.                 stagePip:SetPoint("TOP", bar.Bar, "TOPLEFT", offset, -1)
  484.                 stagePip:SetPoint("BOTTOM", bar.Bar, "BOTTOMLEFT", offset, 1)
  485.                 stagePip:Show()
  486.                 stagePip.BasePip:SetShown(i ~= bar.NumStages)
  487.             end
  488.         end
  489.     end
  490.  
  491.     for i = 1, bar.NumStages-1, 1 do
  492.         local chargeTierName = "ChargeTier" .. i
  493.         local chargeTier = bar[chargeTierName]
  494.         if not chargeTier then
  495.             chargeTier = CreateFrame("FRAME", nil, bar.Bar, "CastingBarFrameStageTierTemplate")
  496.             bar[chargeTierName] = chargeTier
  497.         end
  498.  
  499.         if chargeTier then
  500.             local leftStagePip = bar.StagePips[i]
  501.             local rightStagePip = bar.StagePips[i+1]
  502.  
  503.             if leftStagePip then
  504.                 chargeTier:SetPoint("TOPLEFT", leftStagePip, "TOP", 0, 0)
  505.             end
  506.             if rightStagePip then
  507.                 chargeTier:SetPoint("BOTTOMRIGHT", rightStagePip, "BOTTOM", 0, 0)
  508.             else
  509.                 chargeTier:SetPoint("BOTTOMRIGHT", bar.Bar, "BOTTOMRIGHT", 0, 1)
  510.             end
  511.  
  512.             local chargeTierLeft = chargeTier:GetLeft()
  513.             local chargeTierRight = chargeTier:GetRight()
  514.  
  515.             local left = (chargeTierLeft - castBarLeft) / castBarWidth
  516.             local right = 1.0 - ((castBarRight - chargeTierRight) / castBarWidth)
  517.  
  518.             chargeTier.FlashAnim:Stop()
  519.             chargeTier.FinishAnim:Stop()
  520.  
  521.             chargeTier.Normal:SetAtlas(("ui-castingbar-tier%d-empower"):format(i))
  522.             chargeTier.Disabled:SetAtlas(("ui-castingbar-disabled-tier%d-empower"):format(i))
  523.             chargeTier.Glow:SetAtlas(("ui-castingbar-glow-tier%d-empower"):format(i))
  524.  
  525.             chargeTier.Normal:SetTexCoord(left, right, 0, 1)
  526.             chargeTier.Disabled:SetTexCoord(left, right, 0, 1)
  527.             chargeTier.Glow:SetTexCoord(left, right, 0, 1)
  528.  
  529.             chargeTier.Normal:SetShown(false)
  530.             chargeTier.Disabled:SetShown(true)
  531.             chargeTier.Glow:SetAlpha(0)
  532.  
  533.             chargeTier:Show()
  534.             table.insert(bar.StageTiers, chargeTier)
  535.         end
  536.     end
  537. end
  538.  
  539. function Player:UpdateStage(bar)
  540.     local maxStage = 0;
  541.     local stageValue = bar.Bar:GetValue() * (bar.endTime - bar.startTime) * 1000
  542.     for i = 1, bar.NumStages do
  543.         if bar.StagePoints[i] then
  544.             if stageValue > bar.StagePoints[i] then
  545.                 maxStage = i
  546.             else
  547.                 break
  548.             end
  549.         end
  550.     end
  551.  
  552.     if (maxStage ~= bar.CurrSpellStage and maxStage > -1 and maxStage <= bar.NumStages) then
  553.         bar.CurrSpellStage = maxStage
  554.         if maxStage < bar.NumStages then
  555.             local stagePip = bar.StagePips[maxStage]
  556.             if stagePip and stagePip.StageAnim then
  557.                 stagePip.StageAnim:Play()
  558.             end
  559.         end
  560.  
  561.         local chargeTierName = "ChargeTier" .. bar.CurrSpellStage
  562.         local chargeTier = bar[chargeTierName]
  563.         if chargeTier then
  564.             chargeTier.Normal:SetShown(true)
  565.             chargeTier.Disabled:SetShown(false)
  566.             chargeTier.FlashAnim:Play()
  567.         end
  568.     end
  569. end
  570.  
  571. function Player:ClearStages(bar)
  572.     if bar.ChargeGlow then
  573.         bar.ChargeGlow:SetShown(false)
  574.     end
  575.  
  576.     if bar.StagePips then
  577.         for _, stagePip in pairs(bar.StagePips) do
  578.             local maxStage = bar.NumStages
  579.             for i = 1, maxStage do
  580.                 local stageAnimName = "Stage" .. i
  581.                 local stageAnim = stagePip[stageAnimName]
  582.                 if stageAnim then
  583.                     stageAnim:Stop()
  584.                 end
  585.             end
  586.             stagePip:Hide()
  587.         end
  588.     end
  589.  
  590.     if bar.StageTiers then
  591.         for _, stageTier in pairs(bar.StageTiers) do
  592.             stageTier:Hide()
  593.         end
  594.     end
  595.  
  596.     bar.NumStages = 0
  597. end
  598.  
Add Comment
Please, Sign In to add comment