Advertisement
Guest User

nibRunes

a guest
Oct 13th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.32 KB | Gaming | 0 0
  1. local Opts = nibRunes_Cfg
  2.  
  3. local nRD = CreateFrame("Frame")
  4. local EventsRegistered
  5.  
  6. -- Rune Data
  7. local RUNETYPE_BLOOD = 1
  8. local RUNETYPE_CHROMATIC = 2
  9. local RUNETYPE_FROST = 3
  10. local RUNETYPE_DEATH = 4
  11.  
  12. local runeType = 4
  13.  
  14. local gcdNextDuration = 1
  15. local gcdEnd = 0
  16.  
  17. local HR, HS = false, false
  18.  
  19. -- Combat Fader
  20. local CombatFader = CreateFrame("Frame")
  21. CombatFader.Status = ""
  22.  
  23. local FadeTime = 0.25
  24.  
  25. local RuneFull = {
  26. [1] = true,
  27. [2] = true,
  28. [3] = true,
  29. [4] = true,
  30. [5] = true,
  31. [6] = true,
  32. }
  33.  
  34. local RunesAreReady = true
  35.  
  36. ---- COMBAT FADER
  37. -- Fade frame
  38. function CombatFader.FadeIt(Frame, NewOpacity)
  39. local CurrentOpacity = Frame:GetAlpha();
  40. if NewOpacity > CurrentOpacity then
  41. UIFrameFadeIn(Frame, FadeTime, CurrentOpacity, NewOpacity);
  42. elseif NewOpacity < CurrentOpacity then
  43. UIFrameFadeOut(Frame, FadeTime, CurrentOpacity, NewOpacity);
  44. end
  45. end
  46.  
  47. -- Determine new opacity values for frames
  48. function CombatFader.FadeFrames()
  49. local NewOpacity
  50.  
  51. -- Retrieve Element's opacity/visibility for current status
  52. NewOpacity = 1
  53. if CombatFader.Status == "INCOMBAT" then
  54. NewOpacity = Opts.combatfader.opacity.incombat
  55. elseif CombatFader.Status == "HARMTARGET" then
  56. NewOpacity = Opts.combatfader.opacity.harmtarget
  57. elseif CombatFader.Status == "HURT" then
  58. NewOpacity = Opts.combatfader.opacity.hurt
  59. elseif CombatFader.Status == "OUTOFCOMBAT" then
  60. NewOpacity = Opts.combatfader.opacity.outofcombat
  61. end
  62.  
  63. CombatFader.FadeIt(nRD.Frames.Parent, NewOpacity)
  64. end
  65.  
  66. -- Update current status
  67. function CombatFader.UpdateStatus()
  68. local OldStatus = CombatFader.Status
  69. if UnitAffectingCombat("player") then
  70. CombatFader.Status = "INCOMBAT"; -- InCombat - Priority 1
  71. elseif UnitExists("target") and UnitCanAttack("player", "target") then
  72. CombatFader.Status = "HARMTARGET"; -- HarmTarget - Priority 2
  73. elseif not RunesAreReady then
  74. CombatFader.Status = "HURT"; -- Not Full - Priority 4
  75. else
  76. CombatFader.Status = "OUTOFCOMBAT"; -- OutOfCombat - Priority 5
  77. end
  78. if CombatFader.Status ~= OldStatus then CombatFader.FadeFrames() end
  79. end
  80.  
  81. function CombatFader.PLAYER_ENTERING_WORLD()
  82. CombatFader.Status = nil
  83. CombatFader.UpdateStatus()
  84. CombatFader.FadeFrames()
  85. end
  86.  
  87. function CombatFader.UpdateRuneStatus()
  88. if Opts.combatfader.enabled then
  89. if ( RuneFull[1] and RuneFull[2] and RuneFull[3] and RuneFull[4] and RuneFull[5] and RuneFull[6] ) then
  90. RunesAreReady = true
  91. else
  92. RunesAreReady = false
  93. end
  94. CombatFader.UpdateStatus()
  95. CombatFader.FadeFrames()
  96. end
  97. end
  98.  
  99. function CombatFader.OptionsRefresh()
  100. CombatFader.Status = nil
  101. CombatFader.UpdateStatus()
  102. end
  103.  
  104. function CombatFader.UpdateEnabled()
  105. if Opts.combatfader.enabled then
  106. CombatFader:RegisterEvent("PLAYER_ENTERING_WORLD")
  107. CombatFader:RegisterEvent("PLAYER_TARGET_CHANGED")
  108. CombatFader:RegisterEvent("PLAYER_REGEN_ENABLED")
  109. CombatFader:RegisterEvent("PLAYER_REGEN_DISABLED")
  110. CombatFader:SetScript("OnEvent", CombatFader.UpdateStatus)
  111.  
  112. CombatFader.Status = nil
  113. CombatFader.UpdateRuneStatus()
  114. else
  115. CombatFader:UnregisterEvent("PLAYER_ENTERING_WORLD")
  116. CombatFader:UnregisterEvent("PLAYER_TARGET_CHANGED")
  117. CombatFader:UnregisterEvent("PLAYER_REGEN_ENABLED")
  118. CombatFader:UnregisterEvent("PLAYER_REGEN_DISABLED")
  119.  
  120. nRD.Frames.Parent:SetAlpha(1)
  121. end
  122. end
  123.  
  124. ---- RUNES
  125. -- Events
  126. function nRD.OnUpdate()
  127. local time = GetTime()
  128.  
  129. if time > nRD.LastTime + 0.04 then -- Update 25 times a second
  130. -- Update Rune Bars
  131. local RuneBar
  132. local start, duration, runeReady
  133. for rune = 1, 6 do
  134. RuneBar = nRD.Frames.RuneBars[rune]
  135. start, duration, runeReady = GetRuneCooldown(rune)
  136. if RuneBar ~= nil then
  137. if runeReady or UnitIsDead("player") or UnitIsGhost("player") then
  138.  
  139. if ( Opts.combatfader.enabled and (not RuneFull[rune]) and (not RunesAreReady) ) then
  140. RuneFull[rune] = runeReady
  141. CombatFader.UpdateRuneStatus()
  142. end
  143.  
  144. local BGSize = Opts.runes.size.height + Opts.appearance.borderwidth * 2
  145. if HR then RuneBar.StatusBarBG:SetWidth(BGSize) else RuneBar.StatusBarBG:SetHeight(BGSize) end
  146. RuneBar.BottomStatusBar:SetValue(1)
  147. RuneBar.TopStatusBar:SetValue(1)
  148. else
  149.  
  150. if ( Opts.combatfader.enabled and (RuneFull[rune] or RunesAreReady) ) then
  151. RuneFull[rune] = runeReady
  152. CombatFader.UpdateRuneStatus()
  153.  
  154. end
  155.  
  156. local BGSize = math.max( ((Opts.runes.size.height) * ((time - start) / duration)) + (Opts.appearance.borderwidth * 2), 0)
  157.  
  158. if HR then RuneBar.StatusBarBG:SetWidth(BGSize) else RuneBar.StatusBarBG:SetHeight(BGSize) end
  159. RuneBar.BottomStatusBar:SetValue((time - start) / duration)
  160. RuneBar.TopStatusBar:SetValue(math.max((time - (start + duration - gcdNextDuration)) / gcdNextDuration, 0.0))
  161.  
  162. end
  163. end
  164. end
  165.  
  166. nRD.LastTime = time
  167. end
  168. end
  169.  
  170. function nRD.RuneTextureUpdate(rune)
  171. RuneBar = nRD.Frames.RuneBars[rune]
  172. if not RuneBar then return end
  173. end
  174.  
  175. function nRD.UpdateRuneTextures()
  176. for rune = 1, 6 do
  177. nRD.RuneTextureUpdate(rune)
  178. end
  179. end
  180.  
  181. local function Rune_TypeUpdate(event, rune)
  182. if not rune or tonumber(rune) ~= rune or rune < 1 or rune > 6 then
  183. return
  184. end
  185.  
  186. -- Update Rune colors
  187. nRD.RuneTextureUpdate(rune, select(3, GetRuneCooldown(rune)))
  188. end
  189.  
  190. local function Rune_PlayerEnteringWorld()
  191. -- Update rune colors
  192. nRD.UpdateRuneTextures()
  193. end
  194.  
  195. local function RuneEvents(self, event, ...)
  196. if event == "PLAYER_ENTERING_WORLD" then
  197. Rune_PlayerEnteringWorld()
  198. --elseif event == "RUNE_TYPE_UPDATE" then
  199. -- Rune_TypeUpdate(event, ...)
  200. end
  201. end
  202.  
  203. function nRD.SetupEvents()
  204. if EventsRegistered then return end
  205.  
  206. --nRD.Frames.Parent:RegisterEvent("RUNE_TYPE_UPDATE")
  207. nRD.Frames.Parent:RegisterEvent("PLAYER_ENTERING_WORLD")
  208. nRD.Frames.Parent:SetScript("OnEvent", RuneEvents)
  209.  
  210. -- Enable OnUpdate handler
  211. nRD.LastTime = 0
  212. nRD.Frames.Main:SetScript("OnUpdate", nRD.OnUpdate)
  213.  
  214. EventsRegistered = true
  215. end
  216.  
  217. -- Settings Update
  218. function nRD.UpdateSettings()
  219. local PF = _G[Opts.position.parent] or UIParent
  220. nRD.Frames.Parent:SetParent(PF)
  221. nRD.Frames.Parent:SetPoint(Opts.position.anchor, PF, Opts.position.anchor, Opts.position.x, Opts.position.y)
  222. nRD.Frames.Parent:SetFrameStrata(Opts.framelevel.strata)
  223. nRD.Frames.Parent:SetFrameLevel(Opts.framelevel.level)
  224.  
  225. if HR and HS then
  226. nRD.Frames.Parent:SetWidth(Opts.runes.size.height * 6 + Opts.runes.size.padding * 7)
  227. nRD.Frames.Parent:SetHeight(Opts.runes.size.width + Opts.runes.size.padding * 2)
  228. elseif HR and not HS then
  229. nRD.Frames.Parent:SetWidth(Opts.runes.size.height + Opts.runes.size.padding * 2)
  230. nRD.Frames.Parent:SetHeight(Opts.runes.size.width * 6 + Opts.runes.size.padding * 7)
  231. else
  232. nRD.Frames.Parent:SetHeight(Opts.runes.size.height + Opts.runes.size.padding * 2)
  233. nRD.Frames.Parent:SetWidth(Opts.runes.size.width * 6 + Opts.runes.size.padding * 7)
  234. end
  235.  
  236. nRD.Frames.Main:SetAllPoints(nRD.Frames.Parent)
  237. nRD.Frames.Main:SetAlpha(Opts.appearance.opacity)
  238.  
  239. local RuneBar
  240. for i = 1, 6 do
  241. local CurRune = Opts.runes.order[i]
  242. local runeType = GetRuneType(CurRune)
  243. RuneBar = nRD.Frames.RuneBars[i]
  244. -- Create Rune Bar
  245. RuneBar.frame:SetFrameStrata(Opts.framelevel.strata)
  246. RuneBar.frame:SetFrameLevel(Opts.framelevel.level + 1)
  247. if HR and HS then
  248. RuneBar.frame:SetWidth(Opts.runes.size.height)
  249. RuneBar.frame:SetHeight(Opts.runes.size.width)
  250. RuneBar.frame:SetPoint("TOPLEFT", nRD.Frames.Main, "TOPLEFT", Opts.runes.size.padding + (CurRune - 1) * (Opts.runes.size.height + Opts.runes.size.padding), -Opts.runes.size.padding)
  251. elseif HR and not HS then
  252. RuneBar.frame:SetWidth(Opts.runes.size.height)
  253. RuneBar.frame:SetHeight(Opts.runes.size.width)
  254. RuneBar.frame:SetPoint("TOPLEFT", nRD.Frames.Main, "TOPLEFT", -Opts.runes.size.padding, Opts.runes.size.padding + (CurRune - 1) * (Opts.runes.size.width + Opts.runes.size.padding))
  255. else
  256. RuneBar.frame:SetHeight(Opts.runes.size.height)
  257. RuneBar.frame:SetWidth(Opts.runes.size.width)
  258. RuneBar.frame:SetPoint("TOPLEFT", nRD.Frames.Main, "TOPLEFT", Opts.runes.size.padding + (CurRune - 1) * (Opts.runes.size.width + Opts.runes.size.padding), -Opts.runes.size.padding)
  259. end
  260.  
  261. -- Status Bar BG (Border)
  262. if HR then
  263. RuneBar.StatusBarBG:SetPoint("LEFT", RuneBar.frame, "LEFT", -Opts.appearance.borderwidth, 0)
  264. else
  265. RuneBar.StatusBarBG:SetPoint("BOTTOM", RuneBar.frame, "BOTTOM", 0, -Opts.appearance.borderwidth)
  266. end
  267. RuneBar.StatusBarBG:SetHeight(RuneBar.frame:GetHeight() + Opts.appearance.borderwidth * 2)
  268. RuneBar.StatusBarBG:SetWidth(RuneBar.frame:GetWidth() + Opts.appearance.borderwidth * 2)
  269. RuneBar.StatusBarBG:SetColorTexture(0, 0, 0, 1)
  270.  
  271. -- Bottom Status Bar
  272. RuneBar.BottomStatusBar:SetFrameStrata(Opts.framelevel.strata)
  273. RuneBar.BottomStatusBar:SetFrameLevel(RuneBar.frame:GetFrameLevel() + 1)
  274. RuneBar.BottomStatusBar.bg:SetColorTexture(Opts.runes.colors.bright[runeType].r * Opts.runes.colors.dimfactor, Opts.runes.colors.bright[runeType].g * Opts.runes.colors.dimfactor, Opts.runes.colors.bright[runeType].b * Opts.runes.colors.dimfactor)
  275.  
  276. -- Top Status Bar
  277. RuneBar.TopStatusBar:SetFrameStrata(Opts.framelevel.strata)
  278. RuneBar.TopStatusBar:SetFrameLevel(RuneBar.BottomStatusBar:GetFrameLevel() + 1)
  279. RuneBar.TopStatusBar.bg:SetColorTexture(Opts.runes.colors.bright[runeType].r, Opts.runes.colors.bright[runeType].g, Opts.runes.colors.bright[runeType].b)
  280. end
  281.  
  282. nRD.UpdateRuneTextures()
  283. end
  284.  
  285. -- Frame Creation
  286. function nRD.CreateFrames()
  287. if nRD.Frames then return end
  288.  
  289. nRD.Frames = {}
  290.  
  291. -- Parent frame
  292. nRD.Frames.Parent = CreateFrame("Frame", "nibRunes_RuneDisplay", UIParent)
  293.  
  294. -- Create main frame
  295. nRD.Frames.Main = CreateFrame("Frame", nil, nRD.Frames.Parent)
  296. nRD.Frames.Main:SetParent(nRD.Frames.Parent)
  297.  
  298. -- Rune Bars
  299. nRD.Frames.RuneBars = {}
  300. local RuneBar
  301. local SBO
  302. if HR then SBO = "HORIZONTAL" else SBO = "VERTICAL" end
  303. for i = 1, 6 do
  304. nRD.Frames.RuneBars[i] = {}
  305. RuneBar = nRD.Frames.RuneBars[i]
  306.  
  307. -- Create Rune Bar
  308. RuneBar.frame = CreateFrame("Frame", nil, nRD.Frames.Main)
  309.  
  310. -- Status Bar BG (Border)
  311. RuneBar.StatusBarBG = RuneBar.frame:CreateTexture()
  312.  
  313. -- Bottom Status Bar
  314. RuneBar.BottomStatusBar = CreateFrame("StatusBar", nil, RuneBar.frame)
  315. RuneBar.BottomStatusBar:SetOrientation(SBO)
  316. RuneBar.BottomStatusBar:SetMinMaxValues(0, 1)
  317. RuneBar.BottomStatusBar:SetValue(1)
  318. RuneBar.BottomStatusBar:SetAllPoints(RuneBar.frame)
  319.  
  320. RuneBar.BottomStatusBar.bg = RuneBar.BottomStatusBar:CreateTexture()
  321. RuneBar.BottomStatusBar.bg:SetAllPoints()
  322. RuneBar.BottomStatusBar.bg:SetColorTexture(Opts.runes.colors.bright[runeType].r * Opts.runes.colors.dimfactor, Opts.runes.colors.bright[runeType].g * Opts.runes.colors.dimfactor, Opts.runes.colors.bright[runeType].b * Opts.runes.colors.dimfactor)
  323. RuneBar.BottomStatusBar:SetStatusBarTexture(RuneBar.BottomStatusBar.bg)
  324.  
  325. -- Top Status Bar
  326. RuneBar.TopStatusBar = CreateFrame("StatusBar", nil, RuneBar.frame)
  327. RuneBar.TopStatusBar:SetOrientation(SBO)
  328. RuneBar.TopStatusBar:SetMinMaxValues(0, 1)
  329. RuneBar.TopStatusBar:SetValue(1)
  330. RuneBar.TopStatusBar:SetAllPoints(RuneBar.frame)
  331.  
  332. RuneBar.TopStatusBar.bg = RuneBar.TopStatusBar:CreateTexture()
  333. RuneBar.TopStatusBar.bg:SetAllPoints()
  334. RuneBar.TopStatusBar.bg:SetColorTexture(Opts.runes.colors.bright[runeType].r, Opts.runes.colors.bright[runeType].g, Opts.runes.colors.bright[runeType].b)
  335. RuneBar.TopStatusBar:SetStatusBarTexture(RuneBar.TopStatusBar.bg)
  336. end
  337.  
  338. end
  339.  
  340. ---- CORE
  341. function nRD.RefreshMod()
  342. nRD.UpdateSettings()
  343. CombatFader.UpdateEnabled()
  344. end
  345.  
  346. ----
  347. function nRD.Enable()
  348. -- Refresh
  349. nRD.RefreshMod()
  350.  
  351. -- Setup Events
  352. nRD.SetupEvents()
  353.  
  354. -- Disable default rune frame
  355. if Opts.hideblizzard then
  356. RuneFrame:UnregisterAllEvents()
  357. RuneFrame:Hide()
  358. RuneFrame.Show = function() end
  359.  
  360. end
  361.  
  362. -- Show RuneDisplay
  363. nRD.Frames.Parent:Show()
  364. end
  365.  
  366. function nRD.PLAYER_LOGIN()
  367. if not (select(2, UnitClass("player")) == "DEATHKNIGHT") then return end
  368.  
  369. if Opts.horizontalrunes then HR = true end
  370. if Opts.horizontalstacked then HS = true end
  371.  
  372. nRD.CreateFrames()
  373. nRD.Enable()
  374. end
  375.  
  376. local function EventHandler(self, event, ...)
  377. if event == "PLAYER_LOGIN" then
  378. nRD.PLAYER_LOGIN()
  379. end
  380. end
  381. nRD:RegisterEvent("PLAYER_LOGIN")
  382. nRD:RegisterEvent("UNIT_HEALTH")
  383. nRD:SetScript("OnEvent", EventHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement