Guest User

Untitled

a guest
Nov 24th, 2018
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local debugging = true;
  2.  
  3. --main parent frame
  4. local mainFrame = CreateFrame("Frame", "Main", UIParent)
  5. mainFrame:SetPoint("CENTER", 0, 0)
  6. mainFrame:SetWidth(1)
  7. mainFrame:SetHeight(1)
  8. mainFrame:Show()
  9.  
  10. local allFrames = {}
  11. local framesConstructor = {}
  12. function framesConstructor:create(name, width, height, constructor, updater)--method for frame creation - simulates OOP
  13. local tbl = {}
  14. tbl.frame = CreateFrame("Frame", name .. "BackgroundFrame", mainFrame)
  15. tbl.frame:SetPoint("CENTER", mainFrame, "CENTER")
  16. tbl.name = name
  17. tbl.height = height
  18. tbl.width = width
  19. tbl.constructor = constructor
  20. tbl.updater = updater
  21. return tbl
  22. end
  23.  
  24. function getFrameIndexFromTable(name)
  25. for i = 1, #allFrames do
  26. if allFrames[i].name == name then return i
  27. end
  28. end
  29. end
  30.  
  31. local ServerReady = false
  32. mainFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  33. mainFrame:SetScript("OnEvent", function(self, event)
  34. if event == "PLAYER_ENTERING_WORLD" then
  35. mainFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
  36. ServerReady = true
  37. end
  38. end)
  39.  
  40.  
  41.  
  42.  
  43.  
  44. --runic power
  45.  
  46. function setupRpower()
  47. local base = allFrames[getFrameIndexFromTable("runicpower")]
  48.  
  49. rpowerFrame = CreateFrame("Frame", nil, base.frame)
  50. rpowerFrame:SetPoint("TOP", base.frame, "TOP")
  51. rpowerFrame:SetHeight(base.height)
  52. rpowerFrame:SetWidth(base.width)
  53.  
  54. rpowerBackground = rpowerFrame:CreateTexture("ARTWORK")
  55. rpowerBackground:SetAllPoints(rpowerFrame)
  56. rpowerBackground:SetColorTexture(0, 0, 0)
  57. rpowerBackground:SetAlpha(.5)
  58.  
  59. barFrame = CreateFrame("StatusBar", nil, rpowerFrame)
  60. barFrame:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
  61. barFrame:SetMinMaxValues(0, UnitPowerMax("player"))
  62. barFrame:SetHeight(base.height)
  63. barFrame:SetWidth(base.width)
  64. barFrame:SetPoint("CENTER", rpowerFrame, "CENTER")
  65. barFrame:SetStatusBarColor(0, 209, 255)
  66.  
  67. rpowerText = barFrame:CreateFontString("Rpower number", "ARTWORK", "TextStatusBarText")
  68. rpowerText:SetText(0)
  69.  
  70. base.frame:Show()
  71.  
  72. if debugging then
  73. print("runic power setup")
  74. end
  75.  
  76. end
  77.  
  78. function updateRpower()
  79. barFrame:SetMinMaxValues(0, UnitPowerMax("player"))
  80. barFrame:SetValue(UnitPower("player"))
  81. rpowerText:SetText("" .. UnitPower("player") .. " / " .. UnitPowerMax("player") .. "")
  82.  
  83. end
  84.  
  85.  
  86. --runes
  87.  
  88. function setupRunes()
  89. local base = allFrames[getFrameIndexFromTable("runes")]
  90.  
  91. runesFrame = CreateFrame("Frame", nil, base.frame)
  92. runesFrame:SetPoint("TOP", base.frame, "TOP")
  93. runesFrame:SetHeight(base.height)
  94. runesFrame:SetWidth(base.width)
  95.  
  96. runeBars = {}
  97. for i = 1, 6 do
  98. local start, duration, runeReady = GetRuneCooldown(i)
  99. runeBars[i] = CreateFrame("StatusBar", nil, base.frame)
  100. runeBars[i]:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
  101. runeBars[i]:SetHeight(base.height)
  102. runeBars[i]:SetWidth(base.width)
  103. if i<4 then
  104. runeBars[i]:SetPoint("CENTER", runesFrame, -base.width, (i-1)*(-base.height))
  105. else
  106. runeBars[i]:SetPoint("CENTER", runesFrame, base.width, (i-4)*(-base.height))
  107. end
  108.  
  109. --status bar colors - blood is red, frost blue, unholy purple
  110. --if specName == "blood" then
  111. -- runeBars[i]:SetStatusBarColor(255, 0, 0)
  112. --elseif specName == "frost" then
  113. --runeBars[i]:SetStatusBarColor(0, 191, 255)
  114. --elseif specName == "unholy" then
  115. runeBars[i]:SetStatusBarColor(225, 0, 255)
  116. --end
  117.  
  118. end
  119.  
  120. base.frame:Show()
  121.  
  122. if debugging then
  123. print("runes setup")
  124. end
  125. end
  126.  
  127.  
  128.  
  129. function updateRunes()
  130. for i = 1, 6 do
  131. runeStart, runeDuration, runeReady = GetRuneCooldown(i)
  132. if runeReady ~= true then
  133. runeBars[i]:SetMinMaxValues(0, runeDuration-runeStart)
  134. runeBars[i]:SetValue(GetTime() - runeStart)
  135. end
  136. end
  137. end
  138.  
  139.  
  140.  
  141.  
  142. --diseases
  143.  
  144. local currentSpec = GetSpecialization()
  145. local specID = GetInspectSpecialization("player")
  146. local specName
  147. if specID == 250 then
  148. specName = "blood"
  149. elseif specID == 251 then
  150. specName = "frost"
  151. elseif specID == 252 then
  152. specName = "unholy"
  153. end
  154. local diseaseIds = {}
  155. local diseaseTextures = {}
  156. diseaseIds["blood"], diseaseIds["frost"], diseaseIds["unholy"] = { 55078, 55095, 191587 }
  157. diseaseTextures["blood"], diseaseTextures["frost"], diseaseTextures["unholy"] =
  158. {
  159. "Interface\\Icons\\spell_deathknight_bloodplague",
  160. "Interface\\Icons\\spell_deathknight_frostfever",
  161. "Interface\\Icons\\ability_creature_disease_02",
  162. }
  163.  
  164. function setupDis()
  165. local base = allFrames[getFrameIndexFromTable("diseases")]
  166.  
  167. disFrame = CreateFrame("Frame", nil, base.frame)
  168. disFrame:SetPoint("TOP", base.frame, "TOP")
  169. disFrame:SetHeight(base.height)
  170. disFrame:SetWidth(base.width)
  171.  
  172. disTexture = disFrame:CreateTexture("ARTWORK")
  173. disTexture:SetTexture(diseaseTextures[specName])
  174.  
  175. disCd = CreateFrame("Cooldown", nil, disFrame, "CooldownFrameTemplate")
  176. disCd:SetReverse(true)
  177.  
  178.  
  179. base.frame:Show()
  180.  
  181.  
  182. if debugging then
  183. print("diseases setup")
  184. end
  185. end
  186.  
  187. function updateDis()
  188. for i =1, 40 do
  189. local name, _, _, _, duration, expire, _, _, _, id = UnitDebuff("target", i, "PLAYER")
  190. if duration ~= nil and expire ~= nil then
  191. if id == diseaseIds[specName] and id ~= nil then
  192. disCd:SetCooldown(expire-duration, duration)
  193. end
  194. end
  195. end
  196. end
  197.  
  198. --constructs base frames for each component
  199. allFrames[#allFrames + 1] = framesConstructor:create("runicpower", 120, 16, setupRpower, updateRpower)
  200. allFrames[#allFrames + 1] = framesConstructor:create("runes", 120, 12, setupRunes, updateRunes)
  201. allFrames[#allFrames + 1] = framesConstructor:create("diseases", 64, 64, setupDis, updateDis)
  202.  
  203. local function setitallup()
  204. for i = 1, #allFrames do
  205. allFrames[i].frame:SetPoint("TOP", mainFrame, "TOP", 0)
  206. allFrames[i].frame:SetWidth(allFrames[i].width)
  207. allFrames[i].frame:SetHeight(allFrames[i].height)
  208. allFrames[i].frame:SetFrameLevel(15)
  209. end
  210. end
  211.  
  212.  
  213. local hasInitialized = false
  214. mainFrame:SetScript("OnUpdate", function(self, elapsed)
  215. if ServerReady == true then
  216. if hasInitialized == false then
  217. for i =1, #allFrames do
  218. setitallup()
  219. allFrames[i].constructor()
  220. allFrames[i].frame:Show()
  221. end
  222. hasInitialized = true;
  223. end
  224.  
  225.  
  226.  
  227. end
  228.  
  229.  
  230. for i=1, #allFrames do
  231. allFrames[i].updater()
  232. end
  233. end)
RAW Paste Data