Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 20th, 2012  |  syntax: Lua  |  size: 4.80 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. if select(2, UnitClass('player')) ~= "PALADIN" then return end
  2.  
  3. local f = CreateFrame("Frame", nil, UIParent)
  4. local max_holy_power = 3
  5. local scale = 1
  6. local leftanchor = "CENTER"
  7. local hpframes = {}
  8.  
  9.  
  10. f:SetScript("OnEvent", function(self, event, ...)
  11.     self[event](self, ...)
  12. end)
  13.  
  14. local function updateHP()
  15.         local power = UnitPower("player", 9)
  16.         local i = 1
  17.  
  18.         while i <= power do
  19.                 hpframes[i]:SetBackdropColor(1, 1, 0, 1)
  20.                 i = 1 + i
  21.         end
  22.  
  23.         while i <= max_holy_power do
  24.                 hpframes[i]:SetBackdropColor(0, 0, 0, .3)
  25.                 i = 1 + i
  26.         end
  27.  
  28.  
  29. end
  30.  
  31.  
  32. local function updateFrames()
  33.         for i = 1,max_holy_power do
  34.                 hpframes[i]:SetSize(22, 22)
  35.  
  36.                 hpframes[i]:SetBackdropColor(0, 0, 1, .5)
  37.                 hpframes[i]:SetBackdropBorderColor(0, 0, 0, 1)
  38.          
  39.                 if i == 1 then
  40.                         hpframes[i]:SetPoint("CENTER")
  41.                         hpframes[i]:SetScale(scale)
  42.  
  43.                 end
  44.         end)
  45.         updateHP()
  46.  
  47. local function initFrames()
  48.         for i = 1,max_holy_power do
  49.                 hpframes[i] = CreateFrame("Frame", "SHPFrame"..i, i == 1 and UIParent or hpframes[i-1])
  50.                 hpframes[i]:SetBackdrop({bgFile=[[Interface\ChatFrame\ChatFrameBackground]],edgeFile=[[Interface/Tooltips/UI-Tooltip-Border]],tile=true,tileSize=4,edgeSize=1,insets={left= 1, right = 1, top = 1, bottom = 1}})
  51.  
  52.         end
  53.         updateFrames()
  54. end
  55.  
  56. local function destroyFrames()
  57.         for i = 1,max_holy_power do
  58.                 hpframes[i]:Hide()
  59.                 hpframes[i] = nil
  60.         end
  61.         hpframes = {}
  62. end
  63.  
  64. function ColorPickCallback(restore)
  65.         if restore then
  66.                 r, g, b = unpack(restore)
  67.         else
  68.                 r, g, b = ColorPickerFrame:GetColorRGB();
  69.         end
  70.        
  71.         SimpleHolyPowerDB.r = r
  72.         SimpleHolyPowerDB.g = g
  73.         SimpleHolyPowerDB.b = b
  74.  
  75.         updateFrames()
  76. end
  77.  
  78. function f:PLAYER_ENTERING_WORLD()
  79.         updateHP()
  80. end
  81.  
  82. function f:UNIT_POWER(unit, type)
  83.         if type == "HOLY_POWER" and unit == "player" then
  84.                 updateHP()
  85.         end
  86. end
  87.  
  88. function f:UNIT_ENTERED_VEHICLE(unit)
  89.         if unit == "player" then
  90.                 for i = 1,max_holy_power do
  91.                         hpframes[i]:Hide()
  92.                 end
  93.         end
  94. end
  95.  
  96. function f:UNIT_EXITED_VEHICLE(unit)
  97.         if unit == "player" then
  98.                 for i = 1,max_holy_power do
  99.                         hpframes[i]:Show()
  100.                 end
  101.         end
  102. end
  103.  
  104.  
  105. function f:ADDON_LOADED(addon)
  106.         if addon ~= "SimpleHolyPower" then return end
  107.         if select(2, UnitClass('player')) ~= "PALADIN" then
  108.                 return
  109.         end
  110.  
  111.         local defaults = {
  112.                 xpos = 0,
  113.                 ypos = 0,
  114.                 r = 0.9686274509803922,
  115.                 g = 0.6745098039215687,
  116.                 b = 0.1450980392156863,
  117.                 scale = 1,
  118.                 leftanchor = "CENTER"
  119.         }
  120.                
  121.         SimpleHolyPowerDB = SimpleHolyPowerDB or {}
  122.                
  123.         for k,v in pairs(defaults) do
  124.                 if SimpleHolyPowerDB[k] == nil then
  125.                         SimpleHolyPowerDB[k] = v
  126.                 end
  127.         end
  128.  
  129.  
  130.         SLASH_SHP1, SLASH_SHP2 = "/shp", "/simpleholypower"
  131.         SlashCmdList.SHP = function(txt)
  132.                 local cmd, msg = txt:match("^(%S*)%s*(.-)$");
  133.                 cmd = string.lower(cmd)
  134.                 msg = string.lower(msg)
  135.  
  136.                 if cmd == "reset" then
  137.                         xpos = 0
  138.                         ypos = 0
  139.                         r = 0.9686274509803922
  140.                         g = 0.674509803921568
  141.                         b = 0.1450980392156863
  142.                         scale = 1
  143.                         leftanchor = "CENTER"
  144.                         SimpleHolyPowerDB.xpos = 0
  145.                         SimpleHolyPowerDB.ypos = 0
  146.                         SimpleHolyPowerDB.r = 0.9686274509803922
  147.                         SimpleHolyPowerDB.g = 0.674509803921568
  148.                         SimpleHolyPowerDB.b = 0.1450980392156863
  149.                         SimpleHolyPowerDB.scale = 1
  150.                         SimpleHolyPowerDB.leftanchor = "CENTER"
  151.                        
  152.                         destroyFrames()
  153.                         initFrames()
  154.  
  155.                         print("Frame reset to the center, you can now move it to the desired position.")
  156.  
  157.                 elseif cmd == "scale" then
  158.                         local num = tonumber(msg)
  159.                         if num then
  160.                                 scale = num
  161.                                 SimpleHolyPowerDB.scale = num
  162.  
  163.                                 updateFrames()
  164.                         else
  165.                                 print("Not a valid scale! Scale has to be a number, recommended to be between 0.5 and 3")
  166.                         end
  167.                 elseif cmd == "color" or cmd == "colour" then
  168.                         ColorPickerFrame:SetColorRGB(r,g,b)
  169.                         ColorPickerFrame.previousValues = {r,g,b}
  170.                         ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = ColorPickCallback, ColorPickCallback, ColorPickCallback
  171.                         ColorPickerFrame:Hide() -- apparently needed...
  172.                         ColorPickerFrame:Show()
  173.                 else
  174.                         print("|cff3399FF/shp|r usage:")
  175.                         print("|cff3399FF/shp reset|r Resets the addon back to default settings. Use if you can't see the frame and/or dragged it out of the screen.")
  176.                         print("|cff3399FF/shp color|r Open the color picker window.")
  177.                         print("|cff3399FF/shp scale|r Change the scale of the addon (default: 1, don't use values larger than 3)")
  178.                         print("|cff33FF99To move the boxes:|r Alt+Left mouse button on the leftmost box to drag it.")
  179.                 end
  180.  
  181.         end
  182.  
  183.         xpos = SimpleHolyPowerDB.xpos
  184.         ypos = SimpleHolyPowerDB.ypos
  185.         r = SimpleHolyPowerDB.r
  186.         g = SimpleHolyPowerDB.g
  187.         b = SimpleHolyPowerDB.b
  188.         scale = SimpleHolyPowerDB.scale
  189.         leftanchor = SimpleHolyPowerDB.leftanchor
  190.  
  191.         initFrames()
  192.         f:RegisterEvent("UNIT_POWER")
  193.         f:RegisterEvent("PLAYER_ENTERING_WORLD")
  194.         f:RegisterEvent("UNIT_ENTERED_VEHICLE")
  195.         f:RegisterEvent("UNIT_EXITED_VEHICLE")
  196.  
  197.  
  198.  
  199. end
  200.  
  201. f:RegisterEvent("ADDON_LOADED")