WoWInterface SVN idShamanTotemButtons

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 1 to Rev 2
    Reverse comparison

Rev 1 → Rev 2

trunk/addon.lua New file
0,0 → 1,242
if select(2, UnitClass('player')) ~= 'SHAMAN' then return end
 
local _G = _G
local TL, TC, TR = 'TOPLEFT', 'TOP', 'TOPRIGHT'
local ML, MC, MR = 'LEFT', 'CENTER', 'RIGHT'
local BL, BC, BR = 'BOTTOMLEFT', 'BOTTOM', 'BOTTOMRIGHT'
 
local ADDON_NAME = 'idShamanTotemButtons'
local BUTTON_NAME = ADDON_NAME .. 'Button'
local BUTTON_PADDING = 1
 
local addon = CreateFrame('Frame')
 
local earthtotems = {
8143,--'Tremor Totem',
8075,--'Strength of Earth Totem',
2484,--'Earthbind Totem',
8071,--'Stoneskin Totem',
2062,--'Earth Elemental Totem',
5730,--'Stoneclaw Totem',
}
 
local firetotems = {
1535,--'Fire Nova Totem',
8181,--'Frost Resistance Totem',
8190,--'Magma Totem',
3599,--'Searing Totem',
2894,--'Fire Elemental Totem',
8227,--'Flametongue Totem',
}
if select(5, GetTalentInfo(1, 20)) > 0 then
table.insert(firetotems, 1, 30706)--'Totem of Wrath',--TALENT
end
 
local windtotems = {
3738,--'Wrath of Air Totem',
8512,--'Windfury Totem',
8835,--'Grace of Air Totem',
8177,--'Grounding Totem',
10595,--'Nature Resistance Totem',
6495,--'Sentry Totem',
15107,--'Windwall Totem',
25908,--'Tranquil Air Totem',
}
 
local watertotems = {
5675,--'Mana Spring Totem',
8166,--'Poison Cleansing Totem',
8170,--'Disease Cleansing Totem',
8184,--'Fire Resistance Totem',
5394,--'Healing Stream Totem',
}
if select(5, GetTalentInfo(3, 16)) > 0 then
table.insert(firetotems, 16190)--'Mana Tide Totem',--TALENT
end
 
local totemtypes = {
windtotems,
watertotems,
earthtotems,
firetotems,
}
 
function addon:createButton (name)
local button = CreateFrame('CheckButton', name, UIParent, 'SecureActionButtonTemplate, ActionButtonTemplate')
local icon = _G[name .. 'Icon']
local texture = _G[name .. 'NormalTexture2'] or _G[name .. 'NormalTexture']
local checkedtexture = _G[name]:GetCheckedTexture():SetTexture()
 
button:RegisterForClicks('AnyUp')
 
_G[name..'Name']:Hide()
_G[name..'HotKey']:Hide()
 
icon:SetTexCoord(0.08,0.92,0.08,0.92)
texture:SetTexCoord(0,0,0,0)
 
return button
end
 
function addon:setButtonSpell(button, spellid)
local name = GetSpellInfo(spellid)
 
if not GetSpellTexture(name) then
return
end
 
self.Totems[name] = button
 
button:SetAttribute('type', 'spell')
button:SetAttribute('spell', name)
 
_G[button:GetName()..'Icon']:SetTexture(GetSpellTexture(name))
 
button:SetScript('OnEnter', function ()
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
GameTooltip:SetHyperlink(GetSpellLink(spellid))
GameTooltip:Show()
end)
button:SetScript('OnLeave', function ()
GameTooltip:Hide()
end)
end
 
function addon:createBar (name, first, last, p1, p2, padding)
local bar = CreateFrame('Frame', name, UIParent)
local cols = last - first + 1
local button
 
bar.Buttons = {}
 
for i = first, last do
button = self:createButton(BUTTON_NAME .. i)
table.insert(bar.Buttons, button)
button:SetParent(bar)
button:ClearAllPoints()
 
if i == first then
button:SetPoint(p1, bar, p1, 0, 0)
else
button:SetPoint(p1, _G[BUTTON_NAME .. i - 1], p2, padding, 0)
end
end
 
bar:SetWidth(button:GetWidth() * cols + (cols - 1) * BUTTON_PADDING)
bar:SetHeight(button:GetHeight())
 
return bar
end
 
function addon:PLAYER_LOGIN ()
-- EARTH!
-- FIRE!
-- WIND!
-- WATER!
-- HEART!
-- Go Planet!
--
-- By your powers combined, I am Captain Planet!
--
-- Captain Planet, He's our hero
-- Gonna take pollution down to zero
--
-- He's our powers magnified
-- And he's fighting on the planet's side
--
-- Captain Planet, He's out hero
-- Gonna take pollution down to zero
--
-- Gonna help him put asunder
-- Bad guys who like to loot and plunder
--
-- "You'll pay for this, Captain Planet!"
--
-- We're the Planeteers
-- You can be one too
-- 'Cause saving our planet is the thing to do!
--
-- Looting and Polluting is not the way
-- Hear what Captain planet has to say!
--
-- The power is yours!
 
 
local earth = self:createBar(ADDON_NAME .. 'BarEarth', 1, 6, ML, MR, BUTTON_PADDING)
local fire = self:createBar(ADDON_NAME .. 'BarFire', 7, 13, ML, MR, BUTTON_PADDING)
local wind = self:createBar(ADDON_NAME .. 'BarWind', 14, 21, ML, MR, BUTTON_PADDING)
local water = self:createBar(ADDON_NAME .. 'BarWater', 22, 27, ML, MR, BUTTON_PADDING)
 
self.Totems = {}
self.Bars = {}
self.Bars.Earth = earth
self.Bars.Fire = fire
self.Bars.Wind = wind
self.Bars.Water = water
 
for i=1,#earthtotems do
self:setButtonSpell(earth.Buttons[i], earthtotems[i])
end
for i=1,#firetotems do
self:setButtonSpell(fire.Buttons[i], firetotems[i])
end
for i=1,#windtotems do
self:setButtonSpell(wind.Buttons[i], windtotems[i])
end
for i=1,#watertotems do
self:setButtonSpell(water.Buttons[i], watertotems[i])
end
 
earth:SetPoint(MC, UIParent, MC, 400, 0)
fire:SetPoint(TL, earth, BL, 0, -BUTTON_PADDING)
wind:SetPoint(TL, fire, BL, 0, -BUTTON_PADDING)
water:SetPoint(TL, wind, BL, 0, -BUTTON_PADDING)
end
 
function addon:PLAYER_TOTEM_UPDATE (totemtype)
local name
local texture
 
for i, spellid in ipairs(totemtypes[totemtype]) do
name = GetSpellInfo(spellid)
texture = GetSpellTexture(name)
if texture then
self.Totems[name]:SetButtonState('NORMAL')
end
end
end
 
function addon:SPELL_UPDATE_COOLDOWN ()
local name
local texture
local start, duration, enable
 
for i, totemtype in ipairs(totemtypes) do
for j, spellid in ipairs(totemtype) do
name = GetSpellInfo(spellid)
texture = GetSpellTexture(name)
if texture then
start, duration, enable = GetSpellCooldown(name)
CooldownFrame_SetTimer(_G[self.Totems[name]:GetName() .. 'Cooldown'], start, duration, enable)
end
end
end
end
 
function addon.OnEvent (frame, event, ...)
if event == 'PLAYER_LOGIN' then
addon:PLAYER_LOGIN()
elseif event == 'PLAYER_TOTEM_UPDATE' then
addon:PLAYER_TOTEM_UPDATE(...)
elseif event == 'SPELL_UPDATE_COOLDOWN' then
addon:SPELL_UPDATE_COOLDOWN(...)
end
end
 
addon:SetScript('OnEvent', addon.OnEvent)
addon:RegisterEvent('PLAYER_LOGIN')
addon:RegisterEvent('PLAYER_TOTEM_UPDATE')
addon:RegisterEvent('SPELL_UPDATE_COOLDOWN')
 
_G.idShamanTotemButtons = addon
 
trunk/idShamanTotemButtons.toc New file
0,0 → 1,2
## Interface: 20400
addon.lua