View Single Post
08-30-09, 10:28 AM   #2
Rhamses
A Theradrim Guardian
Join Date: Jun 2009
Posts: 61
This creaes three buttons at present. The first one searches the spellbook and identifies teh demon spells known by the player. It then collects them and puts them in "children buttons" similar to luna. But, the children are wrapped around the parent.

There are two other parents one contians the four lock channeling - drain and funnel. the other contains the targeted direct damage, shadow bolt, incinerate etc. Not quite done yet. i should do one for curses. I also have to better credit the original author that showed how to do the circles and how to check the spell book

BINDING_HEADER_DEMONOMICON_PETHEADER = 'Demonomicon'

---------------------------------------------------------------------------------------------
-- Warlock Check
---------------------------------------------------------------------------------------------
if select(2, UnitClass('player')) ~= 'WARLOCK' then return; end


----------------------------------------------------------------------------------------------
-- Demon Button #1 Creation
----------------------------------------------------------------------------------------------
local Demonomicon = Servitas:StyleButton(CreateFrame("Button", "Demonomicon", UIParent, "SecureHandlerClickTemplate"))
Servitas.Demonomicon = Demonomicon
SecureHandler_OnLoad(Demonomicon)

Demonomicon:SetPoint("TOPLEFT", PlayerFrame, "BOTTOMLEFT", 52, 12)
Demonomicon:SetHeight(24);
Demonomicon:SetWidth(24)
Demonomicon:SetMovable()
Demonomicon:SetScript("OnDragStart", Demonomicon.StartMoving)
Demonomicon:SetScript("OnDragStop", Demonomicon.StopMovingOrSizing)
Demonomicon:RegisterForDrag("LeftButton")
Demonomicon.Icon:SetTexture[[Interface\Icons\Spell_Shadow_DeathsEmbrace]];
-------------------------------------------------------------------------------------------------------------
-- Toggles the visibility of the children buttons
-------------------------------------------------------------------------------------------------------------

Demonomicon:SetAttribute("_onclick",
[[
if menu:IsShown() then
menu:Hide()
else
menu:SetAttribute("open", button)
menu:Show()
end]])

-------------------------------------------------------------------------------------------------------------
-- Prepare the spells that will be sought from the player's spell book
-------------------------------------------------------------------------------------------------------------

Demonomicon.Buttons = {}
Demonomicon.SummonTab = [[Interface\Icons\Spell_Shadow_Metamorphosis]]
Demonomicon.Textures =
{
Imp = [[Interface\Icons\Spell_Shadow_Haunting]],
Infernal = [[Interface\Icons\Spell_Shadow_SiphonMana]],
Succubus = [[Interface\Icons\Spell_Shadow_LifeDrain]],
Felhunter = [[Interface\Icons\Spell_Shadow_LifeDrain02]],
}

Demonomicon[ Demonomicon.Textures.Imp ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Infernal ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Succubus ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Felhunter ] = 'Summon'

-------------------------------------------------------------------------------------------------------------
-- Creating Frame
-------------------------------------------------------------------------------------------------------------

Demonomicon.Menu = CreateFrame("Frame", Demonomicon:GetName().."Menu", Demonomicon, "SecureHandlerShowHideTemplate")

Demonomicon:SetFrameRef("menu", Demonomicon.Menu)
Demonomicon.Menu:Hide()
Demonomicon.Menu:SetPoint("CENTER", Demonomicon)
Demonomicon.Menu:SetAttribute("_onhide", [[open = nil]])
Demonomicon.Menu:SetAttribute("_onshow", [[
if buttons then
for i, b in ipairs(buttons) do
if self:GetAttribute("open") then
b:SetAttribute('type', 'macro');
end
self:SetBindingClick(true, tostring(b:GetID()), b:GetName(), "LeftButton")
end
end ]])

-------------------------------------------------------------------------------------------------------------
-- Matching desired spells with spells know in spell book
-------------------------------------------------------------------------------------------------------------

Demonomicon:Execute[[menu = self:GetFrameRef("menu")]]

function Demonomicon:SetUpButtons(event, ...)

local Locale, Placement, Buttons = self.Locale, self.Placement, self.Buttons
Locale.Spells = { Summons = {} }
local Spells = Locale.Spells
for tabIndex = 1,MAX_SKILLLINE_TABS do
local tabName, texture, startSpell, numSpells = GetSpellTabInfo(tabIndex)
if not tabName then break end
-- if texture == self.SummonTab then
for spellIndex = startSpell + 1, startSpell + numSpells do
local spellIcon = GetSpellTexture(spellIndex,BOOKTYPE_SPELL)
local spellSought = self[spellIcon]
if spellSought and type(spellSought) == 'string' then
if spellSought == 'Summon' then
Spells.Summons[spellIcon] = GetSpellName(spellIndex, BOOKTYPE_SPELL)
else
Spells[spellSought] = GetSpellName(spellIndex, BOOKTYPE_SPELL)
end
end
-- end
end
end
if next(Spells.Summons) then self:Show() else self:Hide(); return end

-------------------------------------------------------------------------------------------------------------
-- Setting button abilities
-------------------------------------------------------------------------------------------------------------
local numButtons = 0
for _,summonKey in pairs(Placement.order) do
local summon = Spells.Summons[summonKey]
if summon then
numButtons = numButtons + 1
local summonButton = Buttons[numButtons]
if not summonButton then
local newName = self:GetName().."Summon"..numButtons
summonButton = Servitas:StyleButton(CreateFrame('BUTTON', newName, self.Menu, "SecureActionButtonTemplate"))
self.Menu:WrapScript(summonButton, "OnClick", [[if #buttons > 1 then owner:Hide() end]])
Buttons[numButtons] = summonButton
end
summonButton:SetID(numButtons)
summonButton.Icon:SetTexture(summonKey)
summonButton:SetAttribute('macrotext', '/cast '..summon)
end
end
self.Menu:Execute
[[buttons = self:GetChildList(buttons or table.new());
for i, b in ipairs(buttons) do
if b:GetID() == 0 then
table.remove(buttons, i);
end
end]]

-------------------------------------------------------------------------------------------------------------
-- Slice the pie locations
-------------------------------------------------------------------------------------------------------------
if numButtons > 0 then
local angle = Placement.startAngle
local slice = (Placement.endAngle - angle) / numButtons
local radius = 18 / math.sin(slice / 2)
for index=1,numButtons do
Buttons[index]:SetPoint("CENTER", self, "CENTER", radius * math.cos(angle),
radius * math.sin(angle))
angle = angle + slice
end
self.Menu:SetWidth(radius * 2 + 36)
self.Menu:SetHeight(radius * 2 + 36)
end
end
-------------------------------------------------------------------------------------------------------------
-- Load pie slices with Textures
-------------------------------------------------------------------------------------------------------------
Demonomicon:SetScript("OnEvent", function (self, event, ...)
Demonomicon_Locale = {}
Demonomicon_Locale[GetLocale()] = Demonomicon_Locale[GetLocale()] or
({})[GetLocale()] or {}

self.Locale = Demonomicon_Locale[GetLocale()]
Demonomicon_Placement =
{
startAngle = math.pi,
endAngle = 3 * math.pi,
order =
{
self.Textures.Imp,
self.Textures.Infernal,
self.Textures.Voidwalker,
self.Textures.Succubus,
self.Textures.Felhunter,
self.Textures.Felguard
}
}
self.Placement = Demonomicon_Placement
self:SetScript('OnEvent', function (self, event, ...)
self:SetUpButtons(event, ...)end)
end)

--------------------------------------------------------------------------------------------------------------
--
--------------------------------------------------------------------------------------------------------------
Demonomicon:RegisterEvent('PLAYER_ENTERING_WORLD')
Demonomicon:RegisterForClicks("AnyUp")
Demonomicon:RegisterEvent('ADDON_LOADED')


----------------------------------------------------------------------------------------------
-- Demon Button#2 Creation
----------------------------------------------------------------------------------------------
local Demonomicon = Servitas:StyleButton(CreateFrame("Button", "Demonomicon", UIParent, "SecureHandlerClickTemplate"))
Servitas.Demonomicon = Demonomicon
SecureHandler_OnLoad(Demonomicon)

Demonomicon:SetPoint("TOPLEFT", PlayerFrame, "BOTTOMLEFT", 52, 12)
Demonomicon:SetHeight(24);
Demonomicon:SetWidth(24)
Demonomicon:SetMovable()
Demonomicon:SetScript("OnDragStart", Demonomicon.StartMoving)
Demonomicon:SetScript("OnDragStop", Demonomicon.StopMovingOrSizing)
Demonomicon:RegisterForDrag("LeftButton")
Demonomicon.Icon:SetTexture[[Interface\Icons\INV_Misc_Book_06]];

-------------------------------------------------------------------------------------------------------------
-- Toggles the visibility of the children buttons
-------------------------------------------------------------------------------------------------------------

Demonomicon:SetAttribute("_onclick",
[[
if menu:IsShown() then
menu:Hide()
else
menu:SetAttribute("open", button)
menu:Show()
menu:RegisterAutoHide(1.5)
end]])

-------------------------------------------------------------------------------------------------------------
-- Prepare the spells that will be sought from the player's spell book
-------------------------------------------------------------------------------------------------------------

Demonomicon.Buttons = {}
Demonomicon.SummonTab = [[Interface\Icons\Spell_Shadow_Metamorphosis]]
Demonomicon.Textures =
{
Imp = [[Interface\Icons\Spell_Shadow_SummonImp]],
Infernal = [[Interface\Icons\Spell_Shadow_SummonInfernal]],
Voidwalker = [[Interface\Icons\Spell_Shadow_SummonVoidWalker]],
Succubus = [[Interface\Icons\Spell_Shadow_SummonSuccubus]],
Felhunter = [[Interface\Icons\Spell_Shadow_SummonFelHunter]],
Felguard = [[Interface\Icons\Spell_Shadow_SummonFelGuard]]
}

Demonomicon[ Demonomicon.Textures.Imp ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Infernal ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Voidwalker ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Succubus ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Felhunter ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Felguard ] = 'Summon'

Demonomicon[ [[Interface\Icons\Spell_Nature_RemoveCurse]] ] = "FastCast"
-------------------------------------------------------------------------------------------------------------
-- Creating Frame
-------------------------------------------------------------------------------------------------------------

Demonomicon.Menu = CreateFrame("Frame", Demonomicon:GetName().."Menu", Demonomicon, "SecureHandlerShowHideTemplate")

Demonomicon:SetFrameRef("menu", Demonomicon.Menu)
Demonomicon.Menu:Hide()
Demonomicon.Menu:SetPoint("CENTER", Demonomicon)
Demonomicon.Menu:SetAttribute("_onhide", [[open = nil]])
Demonomicon.Menu:SetAttribute("_onshow", [[
if buttons then
for i, b in ipairs(buttons) do
if self:GetAttribute("open") then
b:SetAttribute('type', 'macro');
end
self:SetBindingClick(true, tostring(b:GetID()), b:GetName(), "LeftButton")
end
end ]])

-------------------------------------------------------------------------------------------------------------
-- Matching desired spells with spells know in spell book
-------------------------------------------------------------------------------------------------------------

Demonomicon:Execute[[menu = self:GetFrameRef("menu")]]

function Demonomicon:SetUpButtons(event, ...)

local Locale, Placement, Buttons = self.Locale, self.Placement, self.Buttons
Locale.Spells = { Summons = {} }
local Spells = Locale.Spells
for tabIndex = 1,MAX_SKILLLINE_TABS do
local tabName, texture, startSpell, numSpells = GetSpellTabInfo(tabIndex)
if not tabName then break end
if texture == self.SummonTab then
for spellIndex = startSpell + 1, startSpell + numSpells do
local spellIcon = GetSpellTexture(spellIndex,BOOKTYPE_SPELL)
local spellSought = self[spellIcon]
if spellSought and type(spellSought) == 'string' then
if spellSought == 'Summon' then
Spells.Summons[spellIcon] = GetSpellName(spellIndex, BOOKTYPE_SPELL)
else
Spells[spellSought] = GetSpellName(spellIndex, BOOKTYPE_SPELL)
end
end
end
end
end
if next(Spells.Summons) then self:Show() else self:Hide(); return end

-------------------------------------------------------------------------------------------------------------
-- Setting button abilities
-------------------------------------------------------------------------------------------------------------
local numButtons = 0
for _,summonKey in pairs(Placement.order) do
local summon = Spells.Summons[summonKey]
if summon then
numButtons = numButtons + 1
local summonButton = Buttons[numButtons]
if not summonButton then
local newName = self:GetName().."Summon"..numButtons
summonButton = Servitas:StyleButton(CreateFrame('BUTTON', newName, self.Menu, "SecureActionButtonTemplate"))
self.Menu:WrapScript(summonButton, "OnClick", [[if #buttons > 1 then owner:Hide() end]])
Buttons[numButtons] = summonButton
end
summonButton:SetID(numButtons)
summonButton.Icon:SetTexture(summonKey)
summonButton:SetAttribute('macrotext', '/cast '..(Locale.Spells.FastCast or "").."\n/cast "..summon)
end
end
self.Menu:Execute
[[buttons = self:GetChildList(buttons or table.new());
for i, b in ipairs(buttons) do
if b:GetID() == 0 then
table.remove(buttons, i);
end
end]]

-------------------------------------------------------------------------------------------------------------
-- Slice the pie locations
-------------------------------------------------------------------------------------------------------------
if numButtons > 0 then
local angle = Placement.startAngle
local slice = (Placement.endAngle - angle) / numButtons
local radius = 18 / math.sin(slice / 2)
for index=1,numButtons do
Buttons[index]:SetPoint("CENTER", self, "CENTER", radius * math.cos(angle),
radius * math.sin(angle))
angle = angle + slice
end
self.Menu:SetWidth(radius * 2 + 36)
self.Menu:SetHeight(radius * 2 + 36)
end
end
-------------------------------------------------------------------------------------------------------------
-- Load pie slices with Textures
-------------------------------------------------------------------------------------------------------------
Demonomicon:SetScript("OnEvent", function (self, event, ...)
Demonomicon_Locale = {}
Demonomicon_Locale[GetLocale()] = Demonomicon_Locale[GetLocale()] or
({})[GetLocale()] or {}

self.Locale = Demonomicon_Locale[GetLocale()]
Demonomicon_Placement =
{
startAngle = math.pi,
endAngle = 3 * math.pi,
order =
{
self.Textures.Imp,
self.Textures.Infernal,
self.Textures.Voidwalker,
self.Textures.Succubus,
self.Textures.Felhunter,
self.Textures.Felguard
}
}
self.Placement = Demonomicon_Placement
self:SetScript('OnEvent', function (self, event, ...)
self:SetUpButtons(event, ...)end)
end)

Demonomicon:RegisterEvent('PLAYER_ENTERING_WORLD')
Demonomicon:RegisterForClicks("AnyUp")
Demonomicon:RegisterEvent('ADDON_LOADED')


----------------------------------------------------------------------------------------------
-- Demon Button #3 Creation
----------------------------------------------------------------------------------------------
local Demonomicon = Servitas:StyleButton(CreateFrame("Button", "Demonomicon", UIParent, "SecureHandlerClickTemplate"))
Servitas.Demonomicon = Demonomicon
SecureHandler_OnLoad(Demonomicon)

Demonomicon:SetPoint("TOPLEFT", PlayerFrame, "BOTTOMLEFT", 52, 12)
Demonomicon:SetHeight(24);
Demonomicon:SetWidth(24)
Demonomicon:SetMovable()
Demonomicon:SetScript("OnDragStart", Demonomicon.StartMoving)
Demonomicon:SetScript("OnDragStop", Demonomicon.StopMovingOrSizing)
Demonomicon:RegisterForDrag("LeftButton")
Demonomicon.Icon:SetTexture[[Interface\Icons\Spell_Fire_BlueFire]];
-------------------------------------------------------------------------------------------------------------
-- Toggles the visibility of the children buttons
-------------------------------------------------------------------------------------------------------------

Demonomicon:SetAttribute("_onclick",
[[
if menu:IsShown() then
menu:Hide()
else
menu:SetAttribute("open", button)
menu:Show()
end]])

-------------------------------------------------------------------------------------------------------------
-- Prepare the spells that will be sought from the player's spell book
-------------------------------------------------------------------------------------------------------------

Demonomicon.Buttons = {}
Demonomicon.SummonTab = [[Interface\Icons\Spell_Shadow_Metamorphosis]]
Demonomicon.Textures =
{
Imp = [[Interface\Icons\Icons\Spell_Fire_Immolation]],
Infernal = [[Interface\Icons\Spell_Fire_SoulBurn]],
Succubus = [[Interface\Icons\Spell_Fire_Burnout]],
Felhunter = [[Interface\Icons\Spell_Fire_Fireball02]],
Felguard = [[Interface\Icons\Spell_Shadow_ShadowBolt]],
}
Demonomicon[ Demonomicon.Textures.Imp ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Infernal ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Succubus ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Felhunter ] = 'Summon'
Demonomicon[ Demonomicon.Textures.Felguard ] = 'Summon'

-------------------------------------------------------------------------------------------------------------
-- Creating Frame
-------------------------------------------------------------------------------------------------------------

Demonomicon.Menu = CreateFrame("Frame", Demonomicon:GetName().."Menu", Demonomicon, "SecureHandlerShowHideTemplate")

Demonomicon:SetFrameRef("menu", Demonomicon.Menu)
Demonomicon.Menu:Hide()
Demonomicon.Menu:SetPoint("CENTER", Demonomicon)
Demonomicon.Menu:SetAttribute("_onhide", [[open = nil]])
Demonomicon.Menu:SetAttribute("_onshow", [[
if buttons then
for i, b in ipairs(buttons) do
if self:GetAttribute("open") then
b:SetAttribute('type', 'macro');
end
self:SetBindingClick(true, tostring(b:GetID()), b:GetName(), "LeftButton")
end
end ]])

-------------------------------------------------------------------------------------------------------------
-- Matching desired spells with spells know in spell book
-------------------------------------------------------------------------------------------------------------

Demonomicon:Execute[[menu = self:GetFrameRef("menu")]]

function Demonomicon:SetUpButtons(event, ...)

local Locale, Placement, Buttons = self.Locale, self.Placement, self.Buttons
Locale.Spells = { Summons = {} }
local Spells = Locale.Spells
for tabIndex = 1,MAX_SKILLLINE_TABS do
local tabName, texture, startSpell, numSpells = GetSpellTabInfo(tabIndex)
if not tabName then break end
-- if texture == self.SummonTab then
for spellIndex = startSpell + 1, startSpell + numSpells do
local spellIcon = GetSpellTexture(spellIndex,BOOKTYPE_SPELL)
local spellSought = self[spellIcon]
if spellSought and type(spellSought) == 'string' then
if spellSought == 'Summon' then
Spells.Summons[spellIcon] = GetSpellName(spellIndex, BOOKTYPE_SPELL)
else
Spells[spellSought] = GetSpellName(spellIndex, BOOKTYPE_SPELL)
end
end
-- end
end
end
if next(Spells.Summons) then self:Show() else self:Hide(); return end

-------------------------------------------------------------------------------------------------------------
-- Setting button abilities
-------------------------------------------------------------------------------------------------------------
local numButtons = 0
for _,summonKey in pairs(Placement.order) do
local summon = Spells.Summons[summonKey]
if summon then
numButtons = numButtons + 1
local summonButton = Buttons[numButtons]
if not summonButton then
local newName = self:GetName().."Summon"..numButtons
summonButton = Servitas:StyleButton(CreateFrame('BUTTON', newName, self.Menu, "SecureActionButtonTemplate"))
self.Menu:WrapScript(summonButton, "OnClick", [[if #buttons > 1 then owner:Hide() end]])
Buttons[numButtons] = summonButton
end
summonButton:SetID(numButtons)
summonButton.Icon:SetTexture(summonKey)
summonButton:SetAttribute('macrotext', '/cast '..summon)
end
end
self.Menu:Execute
[[buttons = self:GetChildList(buttons or table.new());
for i, b in ipairs(buttons) do
if b:GetID() == 0 then
table.remove(buttons, i);
end
end]]

-------------------------------------------------------------------------------------------------------------
-- Slice the pie locations
-------------------------------------------------------------------------------------------------------------
if numButtons > 0 then
local angle = Placement.startAngle
local slice = (Placement.endAngle - angle) / numButtons
local radius = 18 / math.sin(slice / 2)
for index=1,numButtons do
Buttons[index]:SetPoint("CENTER", self, "CENTER", radius * math.cos(angle),
radius * math.sin(angle))
angle = angle + slice
end
self.Menu:SetWidth(radius * 2 + 36)
self.Menu:SetHeight(radius * 2 + 36)
end
end
-------------------------------------------------------------------------------------------------------------
-- Load pie slices with Textures
-------------------------------------------------------------------------------------------------------------
Demonomicon:SetScript("OnEvent", function (self, event, ...)
Demonomicon_Locale = {}
Demonomicon_Locale[GetLocale()] = Demonomicon_Locale[GetLocale()] or
({})[GetLocale()] or {}

self.Locale = Demonomicon_Locale[GetLocale()]
Demonomicon_Placement =
{
startAngle = math.pi,
endAngle = 3 * math.pi,
order =
{
self.Textures.Imp,
self.Textures.Infernal,
self.Textures.Succubus,
self.Textures.Felhunter,
self.Textures.Felguard
}
}


self.Placement = Demonomicon_Placement
self:SetScript('OnEvent', function (self, event, ...)
self:SetUpButtons(event, ...)end)
end)

--------------------------------------------------------------------------------------------------------------
--
--------------------------------------------------------------------------------------------------------------

Demonomicon:RegisterEvent('PLAYER_ENTERING_WORLD')
Demonomicon:RegisterForClicks("AnyUp")
Demonomicon:RegisterEvent('ADDON_LOADED')

----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------