Advertisement
Galvin

Untitled

Apr 3rd, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 54.61 KB | None | 0 0
  1. --
  2. -- EclipseBar.lua
  3. --
  4. -- Displays the druid moonkin eclipse bar.
  5. --
  6. -- Predicted power:
  7. --
  8. -- Predicted power is calculated by taking any spell thats casting and any spells that are flying and totals them
  9. -- up.  Flying spells on a 5sec timeout, if they take longer than 5secs to reach their target, they'll be removed
  10. -- from the stack.  Spells that generate damage, energize, or miss the target are removed from the stack right away.
  11. --
  12. --
  13. -- Wrath prediction explained:
  14. --
  15. -- When the player first logs in, the wrath sequence will be in sync with the server.  Since the wrath sequence
  16. -- gets reset as well.  This is only true as long as the player has the eclipse bar turned on before casting
  17. -- any spells.
  18. --
  19. -- As long as the player doesn't cast a wrath that will not move the energy bar, it will always be in sync.
  20. -- Euphoria can't be predicted but the wrath sequence will still stay in sync.
  21. --
  22. --
  23. -- Technical explanation of wrath prediction:
  24. --
  25. -- The wrath sequence is calculated by adding a constant value to a floating point number.
  26. -- Wrath without 4pc bonus is 13.333333
  27. -- Wrath with bonus is        16.666667
  28. --
  29. -- The wrath values are calculated by rounding the wrath sequence down.  But if the fractional part
  30. -- is greater than 0.90 then its rounded up. Using positive values in this example.
  31. --
  32. -- Wrath Value   Sequence Value   Rounded       Current Wrath Value
  33. --
  34. -- 13.333333     13.333333        13            13 - 0    = 13
  35. -- 13.333333     26.666666        26            26 - 13   = 13
  36. -- 13.333333     39.999999        40            40 - 26   = 14
  37. -- 13.333333     53.333332        53            53 - 40   = 13
  38. -- Player gaines 4pc bonus
  39. -- 16.666667     69.999999        70            70 - 53   = 17
  40. -- 16.666667     86.666666        86            86 - 70   = 16
  41. -- 16.666667     103.333333       103           103 - 86  = 17
  42. -- 16.666667     120.0            120           120 - 103 = 17
  43. -- Player loses 4pc bonus
  44. -- 13.333333     133.333333       133           133 - 120 = 13
  45. -- 13.333333     146.666666       146           146 - 133 = 13
  46. -- Player gains 4pc bonus
  47. -- 16.666667     163.333333       163           163 - 146 = 17
  48. -- 16.666667     180.0            180           180 - 163 = 17
  49. -------------------------------------------------------------------------------
  50.  
  51. -------------------------------------------------------------------------------
  52. -- GUB   shared data table between all parts of the addon
  53. -------------------------------------------------------------------------------
  54. local MyAddon, GUB = ...
  55.  
  56. GUB.EclipseBar = {}
  57. local Main = GUB.Main
  58.  
  59. -- shared from Main.lua
  60. local LSM = Main.LSM
  61. local PowerTypeToNumber = Main.PowerTypeToNumber
  62. local MouseOverDesc = Main.MouseOverDesc
  63.  
  64. -- localize some globals.
  65. local _
  66. local abs, mod, max, floor, ceil, mrad,     mcos,     msin =
  67.       abs, mod, max, floor, ceil, math.rad, math.cos, math.sin
  68. local strfind, strsub, strupper, strlower, format, strconcat, strmatch, gsub =
  69.       strfind, strsub, strupper, strlower, format, strconcat, strmatch, gsub
  70. local pcall, pairs, ipairs, type, table, select, next, print =
  71.       pcall, pairs, ipairs, type, table, select, next, print
  72. local GetTime, MouseIsOver, IsModifierKeyDown, GameTooltip =
  73.       GetTime, MouseIsOver, IsModifierKeyDown, GameTooltip
  74. local UnitHasVehicleUI, UnitIsDeadOrGhost, UnitAffectingCombat, UnitExists, HasPetUI =
  75.       UnitHasVehicleUI, UnitIsDeadOrGhost, UnitAffectingCombat, UnitExists, HasPetUI
  76. local UnitPowerType, UnitClass, UnitHealth, UnitHealthMax, UnitPower, UnitBuff, UnitPowerMax, UnitGetIncomingHeals =
  77.       UnitPowerType, UnitClass, UnitHealth, UnitHealthMax, UnitPower, UnitBuff, UnitPowerMax, UnitGetIncomingHeals
  78. local GetRuneCooldown, CooldownFrame_SetTimer, GetRuneType =
  79.       GetRuneCooldown, CooldownFrame_SetTimer, GetRuneType
  80. local GetComboPoints, GetShapeshiftFormID, GetPrimaryTalentTree, GetEclipseDirection, GetInventoryItemID =
  81.       GetComboPoints, GetShapeshiftFormID, GetPrimaryTalentTree, GetEclipseDirection, GetInventoryItemID
  82. local CreateFrame, UnitGUID, getmetatable, setmetatable =
  83.       CreateFrame, UnitGUID, getmetatable, setmetatable
  84.  
  85. -------------------------------------------------------------------------------
  86. -- Locals
  87.  
  88. -- UnitBarF = UnitBarsF[]
  89. -- UnitBarF.UnitBar                  Reference to the unitbar data for the eclipse bar.
  90. -- UnitBarF.Border                   Border frame for the eclipse bar. This is a parent of OffsetFrame
  91. -- UnitBarF.OffsetFrame              Used for rotation.
  92. -- UnitBarF.SunMoonBorder            Frame level border for sun and moon. Child of OffsetFrame.
  93. -- UnitBarF.SliderBorder             Frame level border for the slider. Child of SunMoonBorder.
  94. -- UnitBarF.IndicatorBorder          Frame level border for the indicator. Child of SunMoonBorder.
  95. --
  96. -- UnitBarF.EclipseF                 Table containing the frames that make up the eclipse bar.
  97. --
  98. -- Border.Anchor                     Anchor reference for moving.
  99. -- Border.TooltipName                Tooltip text to display for mouse over when bars are unlocked.
  100. -- Border.TooltipDesc                Description under the name for mouse over.
  101. --
  102. -- EclipseF.Moon                     Table containing frame data for moon.
  103. --   Dark                            If true the Moon is not lit.
  104. --   Frame                           Child of SunMoonBorder. Used to hide/show the moon.
  105. --   Border                          Child of SunMoonBorder. Used to show a visible border for moon.
  106. --   StatusBar                       Child of Moon.Frame.  Statusbar containing the visible texture.
  107. --
  108. -- EclipseF.Sun                      Table containing frame data for sun.
  109. --   Dark                            If true then the Sun is not lit.
  110. --   Frame                           Child of SunMoonBorder. Used to hide/show the sun.
  111. --   Border                          Child of SunMoonBorder. Used to show a visible border for sun.
  112. --   StatusBar                       Child of Sun.Frame.  Statusbar containing the visible texture.
  113. --
  114. -- EclipseF.Bar                      Table containing the frame for the bar.
  115. --   Frame                           Child of Border. Used to hide/show the bar.
  116. --   Border                          Child of Border. Used to show a visible border for the bar.
  117. --
  118. -- EclipseF.Lunar                    Table containing the lunar statusbar.
  119. --   Dark                            If true then the StatusBarLunar is not lit.
  120. --   Frame                           Child of Bar.Frame.  This texture fills the lunar side of the bar.
  121. --
  122. -- EclipseF.Solar
  123. --   Dark                            If true then the StatusBarSolar is not lit.
  124. --   Frame                           Child of Bar.Frame.  This texture fills the solar side of the bar.
  125. --
  126. -- EclipseF.Slider                   Table containing the frame data for the slider.
  127. --   Frame                           Child of SliderBorder. Used to hide/show the slider.
  128. --   Border                          Child of Slider.Frame. Used to show a visible border for the slider.
  129. --   StatusBar                       Child of Slider.Frame.  Statusbar containing the visible texture.
  130. --                                   This is set up so that Frame:Hide() will hide the whole Slider.
  131. --
  132. -- EclipseF.Indicator                Table containing the frame data for the indicator.
  133. --   Frame                           Child of IndicatorBorder. Used to hide/show the indicator.
  134. --   Border                          Child of Indicator.Frame. Used to show a visible border for the indicator.
  135. --   StatusBar                       Child of Indicator.Frame. Statusbar containing the visible texture.
  136. --                                   This is set up so that Frame:Hide() will hide the whole Indicator.
  137. --
  138. -- Txt                               Standard text data.
  139. --
  140. -- RotateBar                         Table containing data for the bar rotation.
  141. --
  142. -- EclipseDirection                  Only gets when eclipse power is at max.
  143. --                                   Sometimes the direction can change before the eclipse power hits
  144. --                                   max power.  So to fix this, the direction gets updated when the
  145. --                                   eclipsepower is at maxpower.  If EclipseDirection is nil or none then
  146. --                                   it will be set to the current direction.
  147. --
  148. -- LastEclipseDirection
  149. -- LastEclipse
  150. -- LastEclipsePower
  151. -- LastPredictedSpells               These four values keep track if there is a change in the eclipse bar.
  152. --
  153. -- WrathSequence                     A positive floating point number that keeps track of the wrath sequence.
  154. -- SequenceRounded                   Rounded off value of WrathSequence used to calculate the next wrath value.
  155. -- WrathNormalValue                  Floating point normal wrath to advance the sequence.
  156. -- WrathFourPcValue                  Four pc tier 12 set bonus wrath value to advance the sequence.
  157. -- SavedWrathSequence                Used to save the current value of WrathSequence.
  158. -- SavedSequenceRounded              Used to save the current value of SequenceRounded.
  159. -- LastWrathServerValue              Used to by SyncWrathSequence().  Helps to detect if the sequence is in sync with
  160. --                                   the server. This contains the last wrath value from the server.
  161. -- WrathSync                         If true then in sync otherwise false.
  162. -------------------------------------------------------------------------------
  163.  
  164. -- Powertype constants
  165. local PowerEclipse = PowerTypeToNumber['ECLIPSE']
  166.  
  167. local EclipseDirection = nil
  168. local LastEclipsePower = nil
  169. local LastEclipseDirection = nil
  170. local LastEclipse = nil
  171. local LastPredictedSpells = nil
  172.  
  173. local WrathSequence = 0
  174. local SequenceRounded = 0
  175. local SavedWrathSequence = 0
  176. local SavedSequenceRounded = 0
  177. local LastWrathServerValue = 0
  178. local WrathSync = false
  179. local WrathNormalValue = 13.333333
  180. local WrathFourPcValue = 16.666667
  181.  
  182. local SolarBuff = 48517;
  183. local LunarBuff = 48518;
  184.  
  185. -- Predicted spell ID constants.
  186. local SpellWrath      = 5176
  187. local SpellStarfire   = 2912
  188. local SpellStarsurge  = 78674
  189. local SpellEnergizeWS = 89265 -- Energize for Wrath and Starfire
  190. local SpellEnergizeSS = 86605 -- Energize for Starsurge
  191.  
  192. local PredictedSpellValue = {
  193.   [SpellWrath] = 13,
  194.   [SpellStarfire] = 20,
  195.   [SpellStarsurge] = 15,
  196. }
  197.  
  198. local RotateBar = {
  199.   [90] = {  -- Left to right.
  200.     Frame1 = 'Moon', Point1 = 'TOPLEFT',
  201.     Frame2 = 'Bar',  Point2 = 'LEFT',     RelativePoint2 = 'RIGHT',
  202.     Frame3 = 'Sun',  Point3 = 'LEFT',     RelativePoint3 = 'RIGHT',
  203.     LunarPoint1 = 'TOPLEFT',     LunarRelativePoint1 = 'TOPLEFT',     LunarPadding1X = 1, LunarPadding1Y = 1,
  204.     LunarPoint2 = 'BOTTOMRIGHT', LunarRelativePoint2 = 'BOTTOM',      LunarPadding2X = 0, LunarPadding2Y = 1,
  205.     SolarPoint1 = 'TOPLEFT',     SolarRelativePoint1 = 'TOP',         SolarPadding1X = 0, SolarPadding1Y = 1,
  206.     SolarPoint2 = 'BOTTOMRIGHT', SolarRelativePoint2 = 'BOTTOMRIGHT', SolarPadding2X = 1, SolarPadding2Y = 1
  207.   },
  208.   [180] = { -- Top to bottom.
  209.     Frame1 = 'Moon', Point1 = 'TOPLEFT',
  210.     Frame2 = 'Bar',  Point2 = 'TOP',      RelativePoint2 = 'BOTTOM',
  211.     Frame3 = 'Sun',  Point3 = 'TOP',      RelativePoint3 = 'BOTTOM',
  212.     LunarPoint1 = 'TOPLEFT',     LunarRelativePoint1 = 'TOPLEFT',     LunarPadding1X = 1, LunarPadding1Y = 1,
  213.     LunarPoint2 = 'BOTTOMRIGHT', LunarRelativePoint2 = 'RIGHT',       LunarPadding2X = 1, LunarPadding2Y = 0,
  214.     SolarPoint1 = 'TOPLEFT',     SolarRelativePoint1 = 'LEFT',        SolarPadding1X = 1, SolarPadding1Y = 0,
  215.     SolarPoint2 = 'BOTTOMRIGHT', SolarRelativePoint2 = 'BOTTOMRIGHT', SolarPadding2X = 1, SolarPadding2Y = 1,
  216.   },
  217.   [270] = { -- Right to left.
  218.     Frame1 = 'Sun',  Point1 = 'TOPLEFT',
  219.     Frame2 = 'Bar',  Point2 = 'LEFT',     RelativePoint2 = 'RIGHT',
  220.     Frame3 = 'Moon', Point3 = 'LEFT',     RelativePoint3 = 'RIGHT',
  221.     LunarPoint1 = 'TOPLEFT',     LunarRelativePoint1 = 'TOP',         LunarPadding1X = 0, LunarPadding1Y = 1,
  222.     LunarPoint2 = 'BOTTOMRIGHT', LunarRelativePoint2 = 'BOTTOMRIGHT', LunarPadding2X = 1, LunarPadding2Y = 1,
  223.     SolarPoint1 = 'TOPLEFT',     SolarRelativePoint1 = 'TOPLEFT',     SolarPadding1X = 1, SolarPadding1Y = 1,
  224.     SolarPoint2 = 'BOTTOMRIGHT', SolarRelativePoint2 = 'BOTTOM',      SolarPadding2X = 0, SolarPadding2Y = 1,
  225.   },
  226.   [360] = { -- Bottom to top.
  227.     Frame1 = 'Sun',  Point1 = 'TOPLEFT',
  228.     Frame2 = 'Bar',  Point2 = 'TOP',      RelativePoint2 = 'BOTTOM',
  229.     Frame3 = 'Moon', Point3 = 'TOP',      RelativePoint3 = 'BOTTOM',
  230.     LunarPoint1 = 'TOPLEFT',     LunarRelativePoint1 = 'LEFT',        LunarPadding1X = 1, LunarPadding1Y = 0,
  231.     LunarPoint2 = 'BOTTOMRIGHT', LunarRelativePoint2 = 'BOTTOMRIGHT', LunarPadding2X = 1, LunarPadding2Y = 1,
  232.     SolarPoint1 = 'TOPLEFT',     SolarRelativePoint1 = 'TOPLEFT',     SolarPadding1X = 1, SolarPadding1Y = 1,
  233.     SolarPoint2 = 'BOTTOMRIGHT', SolarRelativePoint2 = 'RIGHT',       SolarPadding2X = 1, SolarPadding2Y = 0,
  234.   },
  235. }
  236.  
  237. --*****************************************************************************
  238. --
  239. -- Eclipsebar predicted power and initialization
  240. --
  241. --*****************************************************************************
  242.  
  243. -------------------------------------------------------------------------------
  244. -- ResetWrathSequence
  245. --
  246. -- Resets the wrath sequence.
  247. --
  248. -- Usage: ResetWrathSequence()
  249. -------------------------------------------------------------------------------
  250. local function ResetWrathSequence()
  251.   SequenceRounded = 0
  252.   WrathSequence = 0
  253. end
  254.  
  255. -------------------------------------------------------------------------------
  256. -- AdvanceWrathSequence
  257. --
  258. -- Advanced the wrath sequence to the next value.
  259. --
  260. -- Usage: WrathValue = AdvanceWrathSequence(Bonus)
  261. --
  262. -- Bonus        If true then the sequence gets advanced based on the set bonus.
  263. --
  264. -- WrathValue   Next value in the sequence.
  265. --
  266. -- NOTES:  The server uses the same math.  As long as the sequence matches the
  267. --         server it will always return the correct value.
  268. -------------------------------------------------------------------------------
  269. local function AdvanceWrathSequence(Bonus)
  270.   local Value = WrathNormalValue
  271.  
  272.   -- Get 4pc bonus value.
  273.   if Bonus then
  274.     Value = WrathFourPcValue
  275.   end
  276.  
  277.   local LastSequenceRounded = SequenceRounded
  278.   WrathSequence = WrathSequence + Value
  279.   SequenceRounded = WrathSequence
  280.  
  281.   -- To return the correct value the WrathSequence has to be rounded.
  282.   if SequenceRounded - floor(SequenceRounded) > 0.90 then
  283.     SequenceRounded = floor(SequenceRounded) + 1
  284.   else
  285.     SequenceRounded = floor(SequenceRounded)
  286.   end
  287.  
  288.   -- Return the wrath value.
  289.   return SequenceRounded - LastSequenceRounded
  290. end
  291.  
  292. -------------------------------------------------------------------------------
  293. -- SyncWrathSequence
  294. --
  295. -- Sync the wrath sequence. Matches the wrath sequence with the server.  Takes 1 to 2 tries.
  296. --
  297. -- usage: SyncWrathSequence(Value)
  298. --
  299. -- Value       Value to sync to.
  300. --
  301. -- NOTES:      Matches the wrath sequence value.  If it doesn't then it
  302. --             forwards the sequence till a match is found.
  303. --             If its an euphoria value.  Then it advances the sequence till the sum
  304. --             of two values equals the euphoria.
  305. -------------------------------------------------------------------------------
  306. local function SyncWrathSequence(Value)
  307.   local LastWrathValue = 0
  308.   local WrathValue = 0
  309.   local WrathCount = 0
  310.   local Found = false
  311.   local Bonus = false
  312.  
  313.   Value = abs(Value)
  314.  
  315.   -- 4pc tier 12 bonus value. set bonus to true.
  316.   if Value == 16 or Value == 17 or Value == 33 or Value == 34 then
  317.     Bonus = true
  318.   end
  319.  
  320.   -- Help sync faster.
  321.   if not WrathSync and (LastWrathServerValue == 13 and Value == 13 or LastWrathServerValue == 17 and Value == 17) then
  322.     Value = LastWrathServerValue + Value
  323.   end
  324.  
  325.   -- Forward the sequence to the next matching value.
  326.   while not Found and WrathCount < 10 do
  327.     WrathCount = WrathCount + 1
  328.     LastWrathValue = WrathValue
  329.     WrathValue = AdvanceWrathSequence(Bonus)
  330.     if Value == WrathValue or Value == LastWrathValue + WrathValue then
  331.       Found = true
  332.     end
  333.   end
  334.  
  335.   -- Check to see if in sync.
  336.   if Found then
  337.     if WrathValue == 14 or WrathValue == 16 or Value == 26 or
  338.        LastWrathServerValue == 13 and Value == 13 or LastWrathServerValue == 17 and Value == 17 then
  339.       WrathSync = true
  340.     end
  341.     LastWrathServerValue = Value
  342.   else
  343.     print('Unable to find ', -Value, ' in the wrath sequence')
  344.   end
  345. end
  346.  
  347. -------------------------------------------------------------------------------
  348. -- SaveRestoreWrathSequence
  349. --
  350. -- Saves/restores the current sequence.
  351. --
  352. -- Usage: SaveRestoreWrathSequence(Action)
  353. --
  354. -- Action     'save' saves the current wrath sequence.
  355. --            'restore' restores the last saved wrath sequence.
  356. --
  357. -- NOTE: Since the prediction code needs to look ahead in the wrath sequence.
  358. --       The sequence needs to be restored so that the prediction code
  359. --       doesn't advance it.
  360. -------------------------------------------------------------------------------
  361. local function SaveRestoreWrathSequence(Action)
  362.   if Action == 'save' then
  363.     SavedWrathSequence = WrathSequence
  364.     SavedSequenceRounded = SequenceRounded
  365.   elseif Action == 'restore' then
  366.     WrathSequence = SavedWrathSequence
  367.     SequenceRounded = SavedSequenceRounded
  368.   end
  369. end
  370.  
  371. -------------------------------------------------------------------------------
  372. -- CheckSpell [User defined function for predicted power] Only called by SetPredictedSpell()
  373. --
  374. -- This function gets called when a damage spell or energize spell hits the target.
  375. --
  376. -- If an energize spell comes in it checks to see what spellID triggered it.
  377. -- then tells SetPredictedSpell() to remove that spellID.  If a damage spell
  378. -- comes in it removes it from the spell stack if it doesn't produce an energize event.
  379. --
  380. -- The wrath sequence only gets updated on damage when a wrath energize event happens.
  381. --
  382. -- NOTE: See SetPredictedSpell() in Main.lua for details on how this function is called.
  383. -------------------------------------------------------------------------------
  384. local function CheckSpell(SpellID, Value)
  385.  
  386.   -- Remove spell from stack that will not generate an energize event.
  387.   if SpellID == SpellWrath or SpellID == SpellStarfire  or SpellID == SpellStarsurge then
  388.     local RemoveSpell = false
  389.     if SpellID == SpellWrath and EclipseDirection == 'sun' then
  390.       RemoveSpell = true
  391.     elseif SpellID == SpellStarfire and EclipseDirection == 'moon' then
  392.       RemoveSpell = true
  393.     else
  394.  
  395.       -- Spell has an energize event, dont remove the spell from the stack.
  396.       RemoveSpell = false
  397.     end
  398.  
  399.     return RemoveSpell
  400.   else
  401.  
  402.     -- Check for energize spell and convert it to spellID damage.
  403.     -- Also a spell damage will happen or happened since energize happened.
  404.     if SpellID == SpellEnergizeWS then
  405.  
  406.       -- Ignore energize if its from moonfire/sunfire.
  407.       if abs(Value) ~= 8 then
  408.         if Value < 0 then
  409.  
  410.           -- Update the sequence based on Value.
  411.           SyncWrathSequence(Value)
  412.  
  413.           -- Spell is wrath from energize.
  414.           SpellID = SpellWrath
  415.         else
  416.  
  417.           -- Spell is starfire from energize.
  418.           SpellID = SpellStarfire
  419.         end
  420.       else
  421.         SpellID = -1
  422.       end
  423.     else
  424.  
  425.       -- Spell is starsurge from energize.
  426.       SpellID = SpellStarsurge
  427.     end
  428.  
  429.     -- pass back the SpellID to be removed.
  430.     return SpellID
  431.   end
  432. end
  433.  
  434. -------------------------------------------------------------------------------
  435. -- Set Wrath, Starfire, Starsurge to need a flight time. Also CheckSpell will be
  436. -- called when either of the spells hit the target.
  437. -- Set Energize to call CheckSpell as well.
  438. -------------------------------------------------------------------------------
  439. Main:SetPredictedSpells(SpellWrath,      true,  CheckSpell)
  440. Main:SetPredictedSpells(SpellStarfire,   true,  CheckSpell)
  441. Main:SetPredictedSpells(SpellStarsurge,  true,  CheckSpell)
  442. Main:SetPredictedSpells(SpellEnergizeWS, false, CheckSpell)
  443. Main:SetPredictedSpells(SpellEnergizeSS, false, CheckSpell)
  444.  
  445. --*****************************************************************************
  446. --
  447. -- Eclipsebar utility
  448. --
  449. --*****************************************************************************
  450.  
  451. -------------------------------------------------------------------------------
  452. -- GetEclipsePowerType
  453. --
  454. -- Returns -1 for lunar or 1 for solar or 0 for nuetral.
  455. --
  456. -- usage: EclipsePowerType = GetEclipsePowerType(EclipsePower)
  457. --
  458. -- EclipsePower          Eclipse Power
  459. --
  460. -- EclipsePowerType      -1 = lunar, 1 = solar, 0 = neutral
  461. -------------------------------------------------------------------------------
  462. local function GetEclipsePowerType(Power)
  463.   if Power < 0 then
  464.     return -1
  465.   elseif Power > 0 then
  466.     return 1
  467.   else
  468.     return 0
  469.   end
  470. end
  471.  
  472. -------------------------------------------------------------------------------
  473. -- GetPredictedEclipsePower
  474. --
  475. -- Calculates different parts of the eclipse bar for prediction.
  476. --
  477. -- usage: PPower, PEclipse, PPowerType, PDirection , PowerChange =
  478. --          GetPredictedEclipsePower(SpellID, Value, Power, MaxPower, Direction, PowerType)
  479. --
  480. -- SpellID         ID of the value being added.  See GetPredictedSpell()
  481. -- Value           Positive value to add to Power.
  482. -- Power           Current eclipse power.
  483. -- MaxPower        Maximum eclipse power (constant)
  484. -- Direction       Current direction the power is going in 'sun', 'moon', or 'none'.
  485. -- PowerType       Type of power -1 lunar, 1 solar
  486. --
  487. -- The returned values are based on the Value passed being added to Power.
  488. --
  489. -- PPower          Value added to Power.
  490. -- PEclipse        -1 = lunar eclipse, 1 = solar eclipse, 0 = none
  491. -- PPowerType      -1 = lunar, 1 = solar, 0 = nuetral
  492. -- PDirection      'moon' = lunar, 'sun' = solar, or 'none'.
  493. -- PowerChange     If true then the SpellID actually caused a power change.
  494. -------------------------------------------------------------------------------
  495. local function GetPredictedEclipsePower(SpellID, Value, Power, MaxPower, Direction, PowerType)
  496.   local PowerChange = false
  497.   local Eclipse = 0
  498.  
  499.   -- Add value based on eclipse direction.
  500.   if Direction == 'moon' then
  501.     if SpellID == SpellWrath or SpellID == SpellStarsurge then
  502.       Power = Power - Value
  503.       PowerChange = true
  504.     end
  505.   elseif Direction == 'sun' then
  506.     if SpellID == SpellStarfire or SpellID == SpellStarsurge then
  507.       Power = Power + Value
  508.       PowerChange = true
  509.     end
  510.   elseif SpellID == SpellWrath then
  511.     Power = Power - Value
  512.     PowerChange = true
  513.   elseif SpellID == SpellStarfire then
  514.     Power = Power + Value
  515.     PowerChange = true
  516.   elseif SpellID == SpellStarsurge then
  517.     if PowerType == 0 then
  518.       Power = Power + Value
  519.     else
  520.       Power = Power + Value * PowerType
  521.     end
  522.     PowerChange = true
  523.   end
  524.  
  525.   -- Clip power if its greater than maxpower.
  526.   if abs(Power) > MaxPower then
  527.     Power = MaxPower * PowerType
  528.   end
  529.  
  530.   -- Calc direction.
  531.   if PowerChange then
  532.     if Power <= -MaxPower then
  533.       Direction = 'sun'
  534.     elseif Power >= MaxPower then
  535.       Direction = 'moon'
  536.     end
  537.   end
  538.  
  539.   -- Calc eclipse.
  540.   if Direction == 'moon' and Power > 0 and Power <= MaxPower or Direction == 'sun' and Power < 0 and Power >= -MaxPower then
  541.     Eclipse = PowerType
  542.   end
  543.  
  544.   return Power, Eclipse, GetEclipsePowerType(Power), Direction, PowerChange
  545. end
  546.  
  547. --*****************************************************************************
  548. --
  549. -- Eclipsebar script functions (script/event)
  550. --
  551. --*****************************************************************************
  552.  
  553. -------------------------------------------------------------------------------
  554. -- EclipseBarStartMoving
  555. --
  556. -- If UnitBars.IsGrouped is true then the unitbar parent frame will be moved.
  557. -- Otherwise just the eclipsebar will be moved.
  558. -------------------------------------------------------------------------------
  559. local function EclipseBarStartMoving(self, Button)
  560.  
  561.   -- Call the base moving function for group or anchor movement.
  562.   if Main.UnitBarStartMoving(self.Anchor, Button) then
  563.     self.UnitBarMoving = true
  564.   end
  565. end
  566.  
  567. -------------------------------------------------------------------------------
  568. -- EclipseBarStopMoving
  569. --
  570. -- Same as above except it stops moving and saves the new coordinates.
  571. -------------------------------------------------------------------------------
  572. local function EclipseBarStopMoving(self, Button)
  573.  
  574.   -- Call the stop moving base function if there was a group move or anchor move.
  575.   if self.UnitBarMoving then
  576.     self.UnitBarMoving = false
  577.     Main.UnitBarStopMoving(self.Anchor, Button)
  578.   end
  579. end
  580.  
  581. --*****************************************************************************
  582. --
  583. -- Eclipsebar display
  584. --
  585. --*****************************************************************************
  586.  
  587. -------------------------------------------------------------------------------
  588. -- EclipseBarHide
  589. --
  590. -- Hides/Shows the sun and moon
  591. --
  592. -- usage: EclipseBarHide(EF, Frame, FadeOutTime, Hide)
  593. --
  594. -- EF          EclipseFrame contains the frame data for the slider.
  595. -- Frame       Frame to hide or show.  Can be 'Sun' or 'Moon'
  596. -- Hide        If true frame is hidden else shown.
  597. -- FadeOutTime if > 0 then fadeout animation will be used.
  598. --             if -1 then all fadeout animation will be canceled.
  599. -------------------------------------------------------------------------------
  600. local function EclipseBarHide(EF, Frame, Hide, FadeOutTime)
  601.  
  602.   --Get frame.
  603.   local SliderF = EF[Frame]
  604.   local Frame = SliderF.Frame
  605.  
  606.   if FadeOutTime == -1 then
  607.     if SliderF.Dark then
  608.       Main:AnimationFadeOut(Frame.FadeOut, 'finish', function() Frame:Hide() end)
  609.     end
  610.  
  611.   elseif not Hide and SliderF.Dark then
  612.     if FadeOutTime > 0 then
  613.  
  614.       -- Finish animation if it's playing.
  615.       Main:AnimationFadeOut(Frame.FadeOut, 'finish')
  616.     end
  617.     Frame:Show()
  618.     SliderF.Dark = false
  619.  
  620.   elseif Hide and not SliderF.Dark then
  621.     if FadeOutTime > 0 then
  622.  
  623.       -- Fade out the soul shard then hide it.
  624.       Main:AnimationFadeOut(Frame.FadeOut, 'start', function() Frame:Hide() end)
  625.     else
  626.       Frame:Hide()
  627.     end
  628.     SliderF.Dark = true
  629.   end
  630. end
  631.  
  632. -------------------------------------------------------------------------------
  633. -- DisplayEclipseSlider
  634. --
  635. -- Subfunction of UpdateEclipseBar()
  636. --
  637. -- Displays a slider on the eclipse bar.
  638. --
  639. -- usage: DisplayEclipseSlider(EF, UB, Slider, Power, MaxPower, Direction, PowerType)
  640. --
  641. -- EF           EclipseFrame contains the frame data for the slider.
  642. -- UB           Unitbar data that is needed to display the slider.
  643. -- Slider       Name of the slider table name.
  644. -- Power        Current eclipse power
  645. -- MaxPower     Maximum eclipse power
  646. -- Eclipse      The current eclipse state.
  647. -- PowerType    -1 = 'lunar', 1 = 'solar', 0 = neutral
  648. -------------------------------------------------------------------------------
  649. local function DisplayEclipseSlider(EF, UB, Slider, Power, MaxPower, Direction, PowerType)
  650.  
  651.   -- Get frame data.
  652.   local Gen = UB.General
  653.   local SliderDirection = Gen.SliderDirection
  654.   local EclipseAngle = Gen.EclipseAngle
  655.   local Background = UB.Background
  656.   local Bar = UB.Bar
  657.   local SliderF = EF[Slider]
  658.  
  659.   -- Clip eclipsepower if out of range.
  660.   if abs(Power) > MaxPower then
  661.     Power = Power * PowerType
  662.   end
  663.  
  664.   local SliderPos = Power / MaxPower
  665.   local BdSize = Background.Bar.BackdropSettings.BdSize / 2
  666.   local BarSize = 0
  667.   local SliderSize = 0
  668.  
  669.   -- Get slider direction.
  670.   if SliderDirection == 'VERTICAL' then
  671.     BarSize = Bar.Bar.BarHeight
  672.     SliderSize = Bar[Slider][format('%sHeight', Slider)]
  673.   else
  674.     BarSize = Bar.Bar.BarWidth
  675.     SliderSize = Bar[Slider][format('%sWidth', Slider)]
  676.   end
  677.  
  678.   -- Calc rotate direction.
  679.   if EclipseAngle == 180 or EclipseAngle == 270 then
  680.     SliderPos = SliderPos * -1
  681.   end
  682.  
  683.   -- Check the SliderInside option.  Need to divide by 2 since we have negative to positive coordinates.
  684.   if Gen.SliderInside then
  685.     SliderPos = SliderPos * ((BarSize - BdSize - SliderSize) / 2)
  686.   else
  687.     SliderPos = SliderPos * (BarSize - BdSize) / 2
  688.   end
  689.  
  690.   if SliderDirection == 'VERTICAL' then
  691.     SliderF.Frame:SetPoint('CENTER', EF.Bar.Frame, 'CENTER', 0, SliderPos)
  692.   else
  693.     SliderF.Frame:SetPoint('CENTER', EF.Bar.Frame, 'CENTER', SliderPos, 0)
  694.   end
  695.  
  696.   -- Set slider color.
  697.   local SliderColor = Bar[Slider].Color
  698.  
  699.   -- Check for sun/moon color option.
  700.   if Bar[Slider].SunMoon then
  701.     if Direction == 'sun' then
  702.       SliderColor = Bar.Sun.Color
  703.     elseif Direction == 'moon' then
  704.       SliderColor = Bar.Moon.Color
  705.     end
  706.   end
  707.   SliderF.StatusBar:SetStatusBarColor(SliderColor.r, SliderColor.g, SliderColor.b, SliderColor.a)
  708. end
  709.  
  710. -------------------------------------------------------------------------------
  711. -- UpdateEclipseBar (Update) [UnitBar assigned function]
  712. --
  713. -- Update the eclipse bar power, sun, and moon.
  714. --
  715. -- usage: UpdateEclipseBar(Event)
  716. --
  717. -- Event     'change' then the bar will only get updated if there is a change.
  718. -------------------------------------------------------------------------------
  719. function GUB.EclipseBar:UpdateEclipseBar(Event)
  720.   local UB = self.UnitBar
  721.   local Gen = UB.General
  722.   local PredictedPower = Gen.PredictedPower
  723.  
  724.   local EclipsePower = UnitPower('player', PowerEclipse)
  725.   local EclipseMaxPower = UnitPowerMax('player', PowerEclipse)
  726.   local SpellID = Main:CheckAura('o', SolarBuff, LunarBuff)
  727.   local Eclipse = SpellID == SolarBuff and 1 or SpellID == LunarBuff and -1 or 0
  728.   local EclipsePowerType = GetEclipsePowerType(EclipsePower)
  729.  
  730.   -- Update EclipseDirection on maxpower or nil or none.
  731.   local ED = GetEclipseDirection()
  732.   if abs(EclipsePower) == EclipseMaxPower or EclipsePower == 0 or EclipseDirection == nil then
  733.     EclipseDirection = ED
  734.   end
  735.  
  736.   local PredictedSpells = PredictedPower and Main:GetPredictedSpell(1) > 0 and 1 or 0
  737.  
  738.   -- Return if there is no change.
  739.   if Event == 'change' and EclipsePower == LastEclipsePower and EclipseDirection == LastEclipseDirection and
  740.      Eclipse == LastEclipse and PredictedSpells == 0 and LastPredictedSpells == 0 then
  741.     return
  742.   end
  743.  
  744.   local EF = self.EclipseF
  745.  
  746.   -- Check for real zero eclipse power.
  747.   if EclipsePower == 0 then
  748.     local EclipsePowerZeroTime = EF.EclipsePowerZeroTime
  749.  
  750.     -- Set the starting time and return.
  751.     if EclipsePowerZeroTime == nil or EclipsePowerZeroTime == 0 then
  752.       EF.EclipsePowerZeroTime = GetTime()
  753.       return
  754.  
  755.     -- Keep returning if not enough time has passed.
  756.     elseif GetTime() - EclipsePowerZeroTime < 0.4 then
  757.       return
  758.     end
  759.   else
  760.     EF.EclipsePowerZeroTime = 0
  761.   end
  762.  
  763.   LastEclipsePower = EclipsePower
  764.   LastEclipseDirection = EclipseDirection
  765.   LastEclipse = Eclipse
  766.   LastPredictedSpells = PredictedSpells
  767.  
  768.   local IndicatorHideShow = Gen.IndicatorHideShow
  769.   local FadeOutTime = Gen.EclipseFadeOutTime
  770.   local BarHalfLit = Gen.BarHalfLit
  771.   local PredictedEclipse = Gen.PredictedEclipse
  772.   local PredictedBarHalfLit = Gen.PredictedBarHalfLit
  773.  
  774.   local Value = 0
  775.   local Bonus = false
  776.   local PC = false
  777.   local PEclipseDirection = nil
  778.   local PEclipsePower = nil
  779.   local PEclipsePowerType = nil
  780.   local PEclipse = nil
  781.  
  782.   -- Check hide slider option.
  783.   if PredictedPower and Gen.PredictedHideSlider then
  784.     EF.Slider.Frame:Hide()
  785.   else
  786.     EF.Slider.Frame:Show()
  787.     DisplayEclipseSlider(EF, UB, 'Slider', EclipsePower, EclipseMaxPower, EclipseDirection, EclipsePowerType)
  788.   end
  789.  
  790.   -- Calculate predicted power.
  791.   if PredictedPower then
  792.     local Index = 1
  793.     local PowerChange = false
  794.     PEclipseDirection = EclipseDirection
  795.     PEclipsePower = EclipsePower
  796.     PEclipsePowerType = EclipsePowerType
  797.     PEclipse = Eclipse
  798.  
  799.     -- Save the wrath sequence so that it can be looked ahead.
  800.     SaveRestoreWrathSequence('save')
  801.     repeat
  802.       SpellID = Main:GetPredictedSpell(Index)
  803.  
  804.       if SpellID ~= 0 then
  805.         Value = PredictedSpellValue[SpellID]
  806.         Bonus = Main:GetSetBonus(12) == 4 and PEclipse == 0
  807.  
  808.         -- Get the next wrath value in the sequence. 4pc bonus is only active if predicted solar eclipse is 1.
  809.         if SpellID == SpellWrath then
  810.           Value = AdvanceWrathSequence(Bonus)
  811.  
  812.         -- Add 5 to starfire if predicted bonus is active.
  813.         elseif SpellID == SpellStarfire and Bonus then
  814.           Value = Value + 5
  815.         end
  816.  
  817.         PEclipsePower, PEclipse, PEclipsePowerType, PEclipseDirection, PowerChange =
  818.           GetPredictedEclipsePower(SpellID, Value, PEclipsePower, EclipseMaxPower, PEclipseDirection, PEclipsePowerType)
  819.  
  820.         -- Set power change flag.
  821.         if PowerChange then
  822.           PC = true
  823.         end
  824.       end
  825.       Index = Index + 1
  826.     until SpellID == 0
  827.  
  828.     -- Restore the wrath sequence.
  829.     SaveRestoreWrathSequence('restore')
  830.  
  831.     -- Display indicator based on predicted power options.
  832.     if PC and IndicatorHideShow ~= 'hidealways' or IndicatorHideShow == 'showalways' then
  833.       EF.Indicator.Frame:Show()
  834.       if PC or IndicatorHideShow == 'showalways' then
  835.         DisplayEclipseSlider(EF, UB, 'Indicator', PEclipsePower, EclipseMaxPower, PEclipseDirection, PEclipsePowerType)
  836.       end
  837.     else
  838.       EF.Indicator.Frame:Hide()
  839.     end
  840.   else
  841.     EF.Indicator.Frame:Hide()
  842.   end
  843.  
  844.   -- Display the eclipse power.
  845.   Value = nil
  846.   if Gen.PredictedPowerText then
  847.     Value = PEclipsePower
  848.   end
  849.   if Gen.PowerText and Value == nil then
  850.     Value = EclipsePower
  851.   end
  852.   if Value then
  853.     EF.Txt:SetText(abs(Value))
  854.   else
  855.     EF.Txt:SetText('')
  856.   end
  857.  
  858.   -- Hide/show sun and moon
  859.   if PredictedEclipse and (EclipseDirection ~= 'moon' and PEclipse == 1 or PEclipse == 1 and Eclipse == 1) or
  860.      (not PredictedEclipse or PEclipse ~= 0) and Eclipse == 1 then
  861.     EclipseBarHide(EF, 'Sun', false, FadeOutTime)
  862.   else
  863.     EclipseBarHide(EF, 'Sun', true, FadeOutTime)
  864.   end
  865.   if PredictedEclipse and (EclipseDirection ~= 'sun' and PEclipse == -1 or PEclipse == -1 and Eclipse == -1) or
  866.      (not PredictedEclipse or PEclipse ~= 0) and Eclipse == -1 then
  867.    EclipseBarHide(EF, 'Moon', false, FadeOutTime)
  868.   else
  869.     EclipseBarHide(EF, 'Moon', true, FadeOutTime)
  870.   end
  871.  
  872.   -- Check the HalfLit option, predicted power can change how this works.
  873.   if PredictedBarHalfLit and PEclipseDirection == 'sun' or
  874.      BarHalfLit and EclipseDirection == 'sun' then
  875.     EclipseBarHide(EF, 'Lunar', true, FadeOutTime)
  876.     EclipseBarHide(EF, 'Solar', false, FadeOutTime)
  877.   elseif PredictedBarHalfLit and PEclipseDirection == 'moon' or
  878.          BarHalfLit and EclipseDirection == 'moon' then
  879.     EclipseBarHide(EF, 'Lunar', false, FadeOutTime)
  880.     EclipseBarHide(EF, 'Solar', true, FadeOutTime)
  881.   else
  882.     EclipseBarHide(EF, 'Lunar', false, FadeOutTime)
  883.     EclipseBarHide(EF, 'Solar', false, FadeOutTime)
  884.   end
  885. end
  886.  
  887. -------------------------------------------------------------------------------
  888. -- CancelAnimationEclipse (CancelAnimation) [UnitBar assigned function]
  889. --
  890. -- Cancels all animation playing in the eclipse bar.
  891. -------------------------------------------------------------------------------
  892. function GUB.EclipseBar:CancelAnimationEclipse()
  893.   local EF = self.EclipseF
  894.   EclipseBarHide(EF, 'Moon', false, -1)
  895.   EclipseBarHide(EF, 'Sun', false, -1)
  896.   EclipseBarHide(EF, 'Lunar', false, -1)
  897.   EclipseBarHide(EF, 'Solar', false, -1)
  898. end
  899.  
  900. --*****************************************************************************
  901. --
  902. -- Eclipsebar creation/setting
  903. --
  904. --*****************************************************************************
  905.  
  906. -------------------------------------------------------------------------------
  907. -- EnableMouseClicksEclipse (EnableMouseClicks) [UnitBar assigned function]
  908. --
  909. -- This will enable or disbable mouse clicks for the eclipse bar.
  910. -------------------------------------------------------------------------------
  911. function GUB.EclipseBar:EnableMouseClicksEclipse(Enable)
  912.   local EF = self.EclipseF
  913.  
  914.   EF.Moon.Border:EnableMouse(Enable)
  915.   EF.Sun.Border:EnableMouse(Enable)
  916.   EF.Bar.Border:EnableMouse(Enable)
  917. end
  918.  
  919. -------------------------------------------------------------------------------
  920. -- FrameSetScriptEclipse (FrameSetScript) [UnitBar assigned function]
  921. --
  922. -- Set up script handlers for the eclipsebar.
  923. -------------------------------------------------------------------------------
  924. function GUB.EclipseBar:FrameSetScriptEclipse(Enable)
  925.   local EF = self.EclipseF
  926.  
  927.   local function FrameSetScript(Frame, Enable)
  928.     if Enable then
  929.       Frame:SetScript('OnMouseDown', EclipseBarStartMoving)
  930.       Frame:SetScript('OnMouseUp', EclipseBarStopMoving)
  931.       Frame:SetScript('OnHide', function(self)
  932.                                    EclipseBarStopMoving(self)
  933.                                 end)
  934.       Frame:SetScript('OnEnter', function(self)
  935.                                     Main.UnitBarTooltip(self, false)
  936.                                  end)
  937.       Frame:SetScript('OnLeave', function(self)
  938.                                     Main.UnitBarTooltip(self, true)
  939.                                  end)
  940.     else
  941.       Frame:SetScript('OnMouseDown', nil)
  942.       Frame:SetScript('OnMouseUp', nil)
  943.       Frame:SetScript('OnHide', nil)
  944.       Frame:SetScript('OnEnter', nil)
  945.       Frame:SetScript('OnLeave', nil)
  946.     end
  947.   end
  948.  
  949.   FrameSetScript(EF.Moon.Border, Enable)
  950.   FrameSetScript(EF.Sun.Border, Enable)
  951.   FrameSetScript(EF.Bar.Border, Enable)
  952. end
  953.  
  954. -------------------------------------------------------------------------------
  955. -- EnableScreenClampEclipse (EnableScreenEclipse) [UnitBar assigned function]
  956. --
  957. -- Enables or disble screen clamp for the eclipse bar.
  958. -------------------------------------------------------------------------------
  959. function GUB.EclipseBar:EnableScreenClampEclipse(Enable)
  960.   self.Border:SetClampedToScreen(Enable)
  961. end
  962.  
  963. -------------------------------------------------------------------------------
  964. -- SetAttrEclipse  (SetAttr) [UnitBar assigned function]
  965. --
  966. -- Sets different parts of the eclipsebar.
  967. --
  968. -- Usage: SetAttrEclipse(Object, Attr, Eclipse)
  969. --
  970. -- Object       Object being changed:
  971. --               'bg'        for background (Border).
  972. --               'bar'       for forground (StatusBar).
  973. --               'text'      for the text.
  974. --               'frame'     for the frame.
  975. -- Attr         Type of attribute being applied to object:
  976. --               'color'     Color being set to the object.
  977. --               'backdrop'  Backdrop settings being set to the object.
  978. --               'scale'     Scale settings being set to the object.
  979. --               'size'      Size being set to the object.
  980. --               'padding'   Amount of padding set to the object.
  981. --               'texture'   One or more textures set to the object.
  982. --               'strata'    Frame strata for the object.
  983. -- Eclipse      Which part of the eclispe bar being changed
  984. --               'moon'      Apply changes to the moon.
  985. --               'sun'       Apply changes to the sun.
  986. --               'bar'       Apply changes to the bar.
  987. --               'slider'    Apply changes to the slider.
  988. --               'Indicator' Apply changes to the predicted slider.
  989. --              if Eclipse is nil then only frame scale, frame strata, or text can be changed.
  990. --
  991. -- NOTE: To apply one attribute to all objects. Object must be nil.
  992. --       To apply all attributes to one object. Attr must be nil.
  993. --       To apply all attributes to all objects both must be nil.
  994. -------------------------------------------------------------------------------
  995. function GUB.EclipseBar:SetAttrEclipse(Object, Attr, Eclipse)
  996.  
  997.   -- Get the unitbar data.
  998.   local UB = self.UnitBar
  999.   local EclipseF = self.EclipseF
  1000.  
  1001.   -- Check scale and strata for 'frame'
  1002.   Main:UnitBarSetAttr(self, Object, Attr)
  1003.  
  1004.   -- Text (StatusBar.Txt).
  1005.   if Object == nil or Object == 'text' then
  1006.     local Txt = EclipseF.Txt
  1007.  
  1008.     local TextColor = UB.Text.Color
  1009.  
  1010.     if Attr == nil or Attr == 'font' then
  1011.       Main:SetFontString(Txt, UB.Text.FontSettings)
  1012.     end
  1013.     if Attr == nil or Attr == 'color' then
  1014.       Txt:SetTextColor(TextColor.r, TextColor.g, TextColor.b, TextColor.a)
  1015.     end
  1016.   end
  1017.  
  1018.   -- if Eclipse is nil then return.
  1019.   if not Eclipse then
  1020.     return
  1021.   end
  1022.  
  1023.   -- Uppercase the first character.
  1024.   Eclipse = gsub(Eclipse, '%a', strupper, 1)
  1025.  
  1026.   -- Get bar data.
  1027.   local Background = UB.Background[Eclipse]
  1028.   local Bar = UB.Bar[Eclipse]
  1029.   local UBF = EclipseF[Eclipse]
  1030.  
  1031.   -- Background (Border).
  1032.   if Object == nil or Object == 'bg' then
  1033.     local Border = UBF.Border
  1034.     local BgColor = Background.Color
  1035.  
  1036.     if Attr == nil or Attr == 'backdrop' then
  1037.       Border:SetBackdrop(Main:ConvertBackdrop(Background.BackdropSettings))
  1038.       Border:SetBackdropColor(BgColor.r, BgColor.g, BgColor.b, BgColor.a)
  1039.     end
  1040.     if Attr == nil or Attr == 'color' then
  1041.       Border:SetBackdropColor(BgColor.r, BgColor.g, BgColor.b, BgColor.a)
  1042.     end
  1043.   end
  1044.  
  1045.   -- Forground (Statusbar).
  1046.   if Object == nil or Object == 'bar' then
  1047.     local StatusBar = UBF.StatusBar
  1048.     local StatusBarLunar = EclipseF.Lunar.Frame
  1049.     local StatusBarSolar = EclipseF.Solar.Frame
  1050.     local Frame = UBF.Frame
  1051.  
  1052.     local Padding = Bar.Padding
  1053.     local BarColor = Bar.Color
  1054.     local BarColorLunar = Bar.ColorLunar
  1055.     local BarColorSolar = Bar.ColorSolar
  1056.  
  1057.     if Attr == nil or Attr == 'texture' then
  1058.       if Eclipse ~= 'Bar' then
  1059.         StatusBar:SetStatusBarTexture(LSM:Fetch('statusbar', Bar.StatusBarTexture))
  1060.         StatusBar:GetStatusBarTexture():SetHorizTile(false)
  1061.         StatusBar:GetStatusBarTexture():SetVertTile(false)
  1062.         StatusBar:SetOrientation(Bar.FillDirection)
  1063.         StatusBar:SetRotatesTexture(Bar.RotateTexture)
  1064.       else
  1065.         StatusBarLunar:SetStatusBarTexture(LSM:Fetch('statusbar', Bar.StatusBarTextureLunar))
  1066.         StatusBarSolar:SetStatusBarTexture(LSM:Fetch('statusbar', Bar.StatusBarTextureSolar))
  1067.         StatusBarLunar:GetStatusBarTexture():SetHorizTile(false)
  1068.         StatusBarLunar:GetStatusBarTexture():SetVertTile(false)
  1069.         StatusBarLunar:SetOrientation(Bar.FillDirection)
  1070.         StatusBarLunar:SetRotatesTexture(Bar.RotateTexture)
  1071.         StatusBarSolar:GetStatusBarTexture():SetHorizTile(false)
  1072.         StatusBarSolar:GetStatusBarTexture():SetVertTile(false)
  1073.         StatusBarSolar:SetOrientation(Bar.FillDirection)
  1074.         StatusBarSolar:SetRotatesTexture(Bar.RotateTexture)
  1075.       end
  1076.     end
  1077.  
  1078.     if Attr == nil or Attr == 'color' then
  1079.       if Eclipse ~= 'Bar' then
  1080.         StatusBar:SetStatusBarColor(BarColor.r, BarColor.g, BarColor.b, BarColor.a)
  1081.       else
  1082.         StatusBarLunar:SetStatusBarColor(BarColorLunar.r, BarColorLunar.g, BarColorLunar.b, BarColorLunar.a)
  1083.         StatusBarSolar:SetStatusBarColor(BarColorSolar.r, BarColorSolar.g, BarColorSolar.b, BarColorSolar.a)
  1084.       end
  1085.     end
  1086.  
  1087.     if Attr == nil or Attr == 'padding' then
  1088.       if Eclipse ~= 'Bar' then
  1089.         StatusBar:ClearAllPoints()
  1090.         StatusBar:SetPoint('TOPLEFT', Padding.Left , Padding.Top)
  1091.         StatusBar:SetPoint('BOTTOMRIGHT', Padding.Right, Padding.Bottom)
  1092.       else
  1093.         local RB = RotateBar[UB.General.EclipseAngle]
  1094.  
  1095.         StatusBarLunar:ClearAllPoints()
  1096.         StatusBarLunar:SetPoint(RB.LunarPoint1, Frame, RB.LunarRelativePoint1,
  1097.                                 Padding.Left * RB.LunarPadding1X, Padding.Top * RB.LunarPadding1Y)
  1098.         StatusBarLunar:SetPoint(RB.LunarPoint2, Frame, RB.LunarRelativePoint2,
  1099.                                 Padding.Right * RB.LunarPadding2X, Padding.Bottom * RB.LunarPadding2Y)
  1100.         StatusBarSolar:ClearAllPoints()
  1101.         StatusBarSolar:SetPoint(RB.SolarPoint1, Frame, RB.SolarRelativePoint1,
  1102.                                 Padding.Left * RB.SolarPadding1X, Padding.Top * RB.SolarPadding1Y)
  1103.         StatusBarSolar:SetPoint(RB.SolarPoint2, Frame, RB.SolarRelativePoint2,
  1104.                                 Padding.Right * RB.SolarPadding2X, Padding.Bottom * RB.SolarPadding2Y)
  1105.       end
  1106.     end
  1107.  
  1108.     if Attr == nil or Attr == 'size' then
  1109.       Frame:SetWidth(Bar[format('%sWidth', Eclipse)])
  1110.       Frame:SetHeight(Bar[format('%sHeight', Eclipse)])
  1111.     end
  1112.   end
  1113. end
  1114.  
  1115. -------------------------------------------------------------------------------
  1116. -- SetLayoutEclipse (SetLayout) [UnitBar assigned function]
  1117. --
  1118. -- Set an eclipsebar to a new layout
  1119. --
  1120. -- Usage: SetLayoutEclipse()
  1121. -------------------------------------------------------------------------------
  1122. function GUB.EclipseBar:SetLayoutEclipse()
  1123.  
  1124.   -- Get the unitbar data.
  1125.   local UB = self.UnitBar
  1126.   local Bar = UB.Bar
  1127.   local Gen = UB.General
  1128.  
  1129.   local EclipseAngle = Gen.EclipseAngle
  1130.   local SunOffsetX = Gen.SunOffsetX
  1131.   local SunOffsetY = Gen.SunOffsetY
  1132.   local MoonOffsetX = Gen.MoonOffsetX
  1133.   local MoonOffsetY = Gen.MoonOffsetY
  1134.   local FadeOutTime = Gen.EclipseFadeOutTime
  1135.   local SunWidth = Bar.Sun.SunWidth
  1136.   local SunHeight = Bar.Sun.SunHeight
  1137.   local MoonWidth = Bar.Moon.MoonWidth
  1138.   local MoonHeight = Bar.Moon.MoonHeight
  1139.   local BarWidth = Bar.Bar.BarWidth
  1140.   local BarHeight = Bar.Bar.BarHeight
  1141.   local SliderWidth = Bar.Slider.SliderWidth
  1142.   local SliderHeight = Bar.Slider.SliderHeight
  1143.   local EF = self.EclipseF
  1144.   local SliderFrame = EF.Slider.Frame
  1145.   local IndicatorFrame = EF.Indicator.Frame
  1146.  
  1147.   local SunX, SunY = 0, 0
  1148.   local MoonX, MoonY = 0, 0
  1149.   local BarX, BarY = 0, 0
  1150.   local SliderX, SliderY = 0, 0
  1151.   local x,y = 0, 0
  1152.   local x1,y1 = 0, 0
  1153.   local OffsetFX = 0
  1154.   local OffsetFY = 0
  1155.   local BorderWidth = 0
  1156.   local BorderHeight = 0
  1157.  
  1158.   -- Set angle to 90 if it's invalid.
  1159.   if RotateBar[EclipseAngle] == nil then
  1160.     EclipseAngle = 90
  1161.     UB.General.EclipseAngle = 90
  1162.   end
  1163.  
  1164.   -- Get rotate data.
  1165.   local RB = RotateBar[EclipseAngle]
  1166.  
  1167.   -- Set sun or moon.
  1168.   local TableName = RB.Frame1
  1169.   local F = EF[TableName]
  1170.   local Frame1 = F.Frame
  1171.   local MoonX = 0
  1172.   local MoonY = 0
  1173.   Frame1:ClearAllPoints()
  1174.   Frame1:SetPoint(RB.Point1, 0, 0)
  1175.   F.Border:SetAllPoints(Frame1)
  1176.  
  1177.   -- Set the bar.
  1178.   F = EF[RB.Frame2]
  1179.   local Frame2 = F.Frame
  1180.  
  1181.   -- Calculate the upper left for the bar.
  1182.   if TableName == 'Moon' then
  1183.     x, y = Main:CalcSetPoint(RB.RelativePoint2, MoonWidth, MoonHeight, MoonOffsetX, MoonOffsetY)
  1184.   else
  1185.     x, y = Main:CalcSetPoint(RB.RelativePoint2, SunWidth, SunHeight, SunOffsetX, SunOffsetY)
  1186.   end
  1187.   x1, y1 = Main:CalcSetPoint(RB.Point2, BarWidth, BarHeight, 0, 0)
  1188.  
  1189.   BarX = x - x1
  1190.   BarY = y - y1
  1191.   Frame2:ClearAllPoints()
  1192.   Frame2:SetPoint('TOPLEFT', BarX, BarY)
  1193.   F.Border:SetAllPoints(Frame2)
  1194.  
  1195.   -- Set the sun or moon.
  1196.   TableName = RB.Frame3
  1197.   F = EF[RB.Frame3]
  1198.   local Frame3 = F.Frame
  1199.  
  1200.   -- Caculate the upper left for sun or moon.
  1201.   Frame3:ClearAllPoints()
  1202.   x, y = Main:CalcSetPoint(RB.RelativePoint3, BarWidth, BarHeight, BarX, BarY)
  1203.   if TableName == 'Moon' then
  1204.     x1, y1 = Main:CalcSetPoint(RB.Point3, MoonWidth, MoonHeight, MoonOffsetX, MoonOffsetY)
  1205.     MoonX = x - x1
  1206.     MoonY = y - y1
  1207.     Frame3:SetPoint('TOPLEFT', MoonX, MoonY)
  1208.   else
  1209.     x1, y1 = Main:CalcSetPoint(RB.Point3, SunWidth, SunHeight, SunOffsetX, SunOffsetY)
  1210.     SunX = x - x1
  1211.     SunY = y - y1
  1212.     Frame3:SetPoint('TOPLEFT', SunX, SunY)
  1213.   end
  1214.   F.Border:SetAllPoints(Frame3)
  1215.  
  1216.   -- Set up the slider.
  1217.   -- Dont clear points, Ecplise:Update() sets the point.
  1218.   EF.Slider.Border:SetAllPoints(SliderFrame)
  1219.  
  1220.   -- Set up the indicator.
  1221.   -- Dont clear points, EclipseBar:Update() sets the point.
  1222.   EF.Indicator.Border:SetAllPoints(IndicatorFrame)
  1223.  
  1224.   -- Calculate upper left of slider for border calculation.
  1225.   SliderX, SliderY = Main:CalcSetPoint('CENTER', BarWidth, BarHeight, -(SliderWidth / 2), SliderHeight / 2)
  1226.   SliderX = BarX + SliderX
  1227.   SliderY = BarY + SliderY
  1228.  
  1229.   -- Set the size of the border.
  1230.   local Border = self.Border
  1231.   Border:ClearAllPoints()
  1232.   Border:SetPoint('TOPLEFT', 0, 0)
  1233.  
  1234.   -- Calculate the offsets for the offsetframe, get the borderwidth and borderheight
  1235.   x, y, BorderWidth, BorderHeight = Main:GetBorder(SunX, SunY, SunWidth, SunHeight,
  1236.                                                                 MoonX, MoonY, MoonWidth, MoonHeight,
  1237.                                                                 BarX, BarY, BarWidth, BarHeight,
  1238.                                                                 SliderX, SliderY, SliderWidth, SliderHeight)
  1239.   OffsetFX = -x
  1240.   OffsetFY = -y
  1241.  
  1242.   Border:SetWidth(BorderWidth)
  1243.   Border:SetHeight(BorderHeight)
  1244.  
  1245.   -- Set the x, y location off the offset frame.
  1246.   local OffsetFrame = self.OffsetFrame
  1247.   OffsetFrame:ClearAllPoints()
  1248.   OffsetFrame:SetPoint('LEFT', OffsetFX, OffsetFY)
  1249.   OffsetFrame:SetWidth(BorderWidth)
  1250.   OffsetFrame:SetHeight(BorderHeight)
  1251.  
  1252.   -- Set the duration of the fade out for sun, moon, lunar and solar.
  1253.   Frame1.FadeOutA:SetDuration(FadeOutTime)
  1254.   Frame3.FadeOutA:SetDuration(FadeOutTime)
  1255.   EF.Lunar.Frame.FadeOutA:SetDuration(FadeOutTime)
  1256.   EF.Solar.Frame.FadeOutA:SetDuration(FadeOutTime)
  1257.  
  1258.   -- Set all attributes.
  1259.   self:SetAttr(nil, nil, 'moon')
  1260.   self:SetAttr(nil, nil, 'bar')
  1261.   self:SetAttr(nil, nil, 'sun')
  1262.   self:SetAttr(nil, nil, 'slider')
  1263.   self:SetAttr(nil, nil, 'indicator')
  1264.  
  1265.   -- Save size data to self (UnitBarF).
  1266.   self.Width = BorderWidth
  1267.   self.Height = BorderHeight
  1268. end
  1269.  
  1270. -------------------------------------------------------------------------------
  1271. -- CreateBar
  1272. --
  1273. -- Usage: GUB.EclipseBar:CreateBar(UnitBarF, UB, Anchor, ScaleFrame)
  1274. --
  1275. -- UnitBarF     The unitbar frame which will contain the eclipse bar.
  1276. -- UB           Unitbar data.
  1277. -- Anchor       The unitbars anchor.
  1278. -- ScaleFrame   ScaleFrame which the unitbar must be a child of for scaling.
  1279. -------------------------------------------------------------------------------
  1280. function GUB.EclipseBar:CreateBar(UnitBarF, UB, Anchor, ScaleFrame)
  1281.   local EclipseFrame = {Moon = {}, Sun = {}, Bar = {}, Lunar = {}, Solar = {}, Slider = {}, Indicator = {}}
  1282.   local Border = CreateFrame('Frame', nil, ScaleFrame)
  1283.  
  1284.   -- Make the border frame top when clicked.
  1285.   Border:SetToplevel(true)
  1286.  
  1287.   -- Create the offset frame.
  1288.   local OffsetFrame = CreateFrame('Frame', nil, Border)
  1289.  
  1290.   -- Create a BorderFrame for Sun and moon for frame level
  1291.   local SunMoonBorderFL = CreateFrame('Frame', nil, OffsetFrame)
  1292.   SunMoonBorderFL:SetAllPoints(OffsetFrame)
  1293.   SunMoonBorderFL:SetFrameLevel(SunMoonBorderFL:GetFrameLevel() + 10)
  1294.  
  1295.   -- Create a borderframe for slider frame level
  1296.   local SliderBorderFL = CreateFrame('Frame', nil, SunMoonBorderFL)
  1297.   SliderBorderFL:SetAllPoints(OffsetFrame)
  1298.   SliderBorderFL:SetFrameLevel(SliderBorderFL:GetFrameLevel() + 30)
  1299.  
  1300.   -- Create a borderframe for indicator frame level
  1301.   local IndicatorBorderFL = CreateFrame('Frame', nil, SunMoonBorderFL)
  1302.   IndicatorBorderFL:SetAllPoints(OffsetFrame)
  1303.   IndicatorBorderFL:SetFrameLevel(IndicatorBorderFL:GetFrameLevel() + 20)
  1304.  
  1305.   -- Create the text frame.
  1306.   local TxtBorder = CreateFrame('Frame', nil, Border)
  1307.   TxtBorder:SetAllPoints(Border)
  1308.   TxtBorder:SetFrameLevel(TxtBorder:GetFrameLevel() + 50)
  1309.   local Txt = TxtBorder:CreateFontString(nil, 'OVERLAY')
  1310.  
  1311.   -- MOON
  1312.  
  1313.   -- Create the moon frame.  This is used for hide/show
  1314.   local MoonFrame = CreateFrame('Frame', nil, SunMoonBorderFL)
  1315.  
  1316.   -- Set the moon to dark.
  1317.   EclipseFrame.Moon.Dark = true
  1318.   MoonFrame:Hide()
  1319.  
  1320.   -- Create the visible border for the moon.
  1321.   local MoonBorder = CreateFrame('Frame', nil, SunMoonBorderFL)
  1322.  
  1323.   -- Create the statusbar for the moon.
  1324.   local Moon = CreateFrame('StatusBar', nil, MoonFrame)
  1325.  
  1326.   -- SUN
  1327.   -- Create the sun frame.  This is used for hide/show
  1328.   local SunFrame = CreateFrame('Frame', nil, SunMoonBorderFL)
  1329.  
  1330.   -- Set the sun to dark
  1331.   EclipseFrame.Sun.Dark = true
  1332.   SunFrame:Hide()
  1333.  
  1334.   -- Create the visible border for the sun.
  1335.   local SunBorder = CreateFrame('Frame', nil, SunMoonBorderFL)
  1336.  
  1337.   -- Create the statusbar for the sun.
  1338.   local Sun = CreateFrame('StatusBar', nil, SunFrame)
  1339.  
  1340.   -- BAR
  1341.   -- Create the eclipse bar for the slider.
  1342.   local BarFrame = CreateFrame('Frame', nil, OffsetFrame)
  1343.  
  1344.   -- Create the visible border for eclipse bar.
  1345.   local BarBorder = CreateFrame('Frame', nil, OffsetFrame)
  1346.  
  1347.   -- Create the left and right statusbars for the bar and set then to lit.
  1348.   local BarLunar = CreateFrame('StatusBar', nil, BarFrame)
  1349.   local BarSolar = CreateFrame('StatusBar', nil, BarFrame)
  1350.   EclipseFrame.Lunar.Dark = false
  1351.   EclipseFrame.Solar.Dark = false
  1352.  
  1353.   -- SLIDER
  1354.   -- Create the slider frame.
  1355.   local SliderFrame = CreateFrame('Frame', nil, SliderBorderFL)
  1356.  
  1357.   -- Create the slider border.
  1358.   local SliderBorder = CreateFrame('Frame', nil, SliderFrame)
  1359.  
  1360.   -- create the statusbar for slider.
  1361.   local Slider = CreateFrame('StatusBar', nil, SliderFrame)
  1362.  
  1363.   -- create the indicator frame.
  1364.   local IndicatorFrame = CreateFrame('Frame', nil, IndicatorBorderFL)
  1365.  
  1366.   -- create the indicator border.
  1367.   local IndicatorBorder = CreateFrame('Frame', nil, IndicatorFrame)
  1368.  
  1369.   -- create the statusbar for the predicted slider border.
  1370.   local Indicator = CreateFrame('StatusBar', nil, IndicatorFrame)
  1371.  
  1372.   -- Create fadeout for Sun, Moon, Lunar, and Solar.
  1373.   local FadeOut, FadeOutA = Main:CreateFadeOut(MoonFrame)
  1374.   MoonFrame.FadeOut = FadeOut
  1375.   MoonFrame.FadeOutA = FadeOutA
  1376.  
  1377.   FadeOut, FadeOutA = Main:CreateFadeOut(SunFrame)
  1378.   SunFrame.FadeOut = FadeOut
  1379.   SunFrame.FadeOutA = FadeOutA
  1380.  
  1381.   FadeOut, FadeOutA = Main:CreateFadeOut(BarLunar)
  1382.   BarLunar.FadeOut = FadeOut
  1383.   BarLunar.FadeOutA = FadeOutA
  1384.  
  1385.   FadeOut, FadeOutA = Main:CreateFadeOut(BarSolar)
  1386.   BarSolar.FadeOut = FadeOut
  1387.   BarSolar.FadeOutA = FadeOutA
  1388.  
  1389.   -- Save the name for tooltips.
  1390.   MoonBorder.TooltipName = UB.Name
  1391.   MoonBorder.TooltipDesc = MouseOverDesc
  1392.   SunBorder.TooltipName = UB.Name
  1393.   SunBorder.TooltipDesc = MouseOverDesc
  1394.   BarBorder.TooltipName = UB.Name
  1395.   BarBorder.TooltipDesc = MouseOverDesc
  1396.  
  1397.   -- Save a reference to the anchor for moving.
  1398.   MoonBorder.Anchor = Anchor
  1399.   SunBorder.Anchor = Anchor
  1400.   BarBorder.Anchor = Anchor
  1401.  
  1402.   EclipseFrame.Moon.Frame = MoonFrame
  1403.   EclipseFrame.Moon.Border = MoonBorder
  1404.   EclipseFrame.Moon.StatusBar = Moon
  1405.   EclipseFrame.Sun.Frame = SunFrame
  1406.   EclipseFrame.Sun.Border = SunBorder
  1407.   EclipseFrame.Sun.StatusBar = Sun
  1408.   EclipseFrame.Bar.Frame = BarFrame
  1409.   EclipseFrame.Bar.Border = BarBorder
  1410.   EclipseFrame.Lunar.Frame = BarLunar
  1411.   EclipseFrame.Solar.Frame = BarSolar
  1412.   EclipseFrame.Slider.Frame = SliderFrame
  1413.   EclipseFrame.Slider.Border = SliderBorder
  1414.   EclipseFrame.Slider.StatusBar = Slider
  1415.   EclipseFrame.Indicator.Frame = IndicatorFrame
  1416.   EclipseFrame.Indicator.Border = IndicatorBorder
  1417.   EclipseFrame.Indicator.StatusBar = Indicator
  1418.  
  1419.   EclipseFrame.Txt = Txt
  1420.  
  1421.   -- Save the borders and Eclipse frames
  1422.   UnitBarF.Border = Border
  1423.   UnitBarF.SunMoonBorder = SunMoonBorderFL
  1424.   UnitBarF.SliderBorder = SliderBorderFL
  1425.   UnitBarF.IndicatorBorder = IndicatorBorderFL
  1426.   UnitBarF.TxtBorder = TxtBorder
  1427.   UnitBarF.OffsetFrame = OffsetFrame
  1428.   UnitBarF.EclipseF = EclipseFrame
  1429. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement