PHP Code:
-- I am going to create a simple frame that will accept either SPELL ID input, or SPELL NAME input...
-- I will try and distinguish which is being requested by simple string verifications..
-- Spell ID will be simple in adding to the Queue system
-- Spell Name will be slightly more complex.. Possible ideas on how to compare Spell Name against possible Spell choices
---- We can use a predetermined table of Spell ID's to accept as Spell Name inputs
---- We can scan the entire SpellBook before we even begin and see what spells we know (Run check whenever Spec or Level changes)
---- Still thinking about other methods
-- I may include a Scroll Frame which will display the last X number or Queued Casts and if they were successful or not
if not Nova_Queue_Setup then
local function Event_Reader()
local function OnEventFunc(self, event, ...)
if event == "PLAYER_LEVEL_UP" or event == "PLAYER_TALENT_UPDATE" then
Nova_SpellBookCache = { }
local _, _, tabOffset, numEntries = GetSpellTabInfo(2) -- The Spell Tab 1 = General Spells, 2 = Current Spec spells
for i=tabOffset + 1, tabOffset + numEntries do
local spellName, spellSubName = GetSpellBookItemName(i, "spell")
local spell = GetSpellLink(spellName)
if ( not spellSubName or not string.match(spellSubName, "Passive") )
and spell then
local SpellNameFinal = string.lower(gsub(spellName, "[%s%d%p]", ""))
local string1 = gsub(spell, "[%a%|%s%[%]]+", "")
local spellIDfromString = tonumber(string.match(string1, "%p(%d+)"))
table.insert(Nova_SpellBookCache, { name = SpellNameFinal, id = spellIDfromString } )
end
end
elseif #Nova_SpellQueueTable > 0 and event == "COMBAT_LOG_EVENT_UNFILTERED" then
if (select(2, ...) == "SPELL_CAST_SUCCESS"
or select(2, ...) == "SPELL_CAST_START" )
and select(4, ...) == UnitGUID("player") then
for loop = 1, #Nova_SpellQueueTable do
if Nova_SpellQueueTable[loop].id == select(12, ...) then
table.remove(Nova_SpellQueueTable, loop)
print("|cff00F0F0Successfully cast|cffFF0000",select(13, ...),"|cff00F0F0!")
break
end
end
end
end
end
local eventReader = CreateFrame("frame", nil)
eventReader:RegisterEvent("PLAYER_LEVEL_UP")
eventReader:RegisterEvent("PLAYER_TALENT_UPDATE")
eventReader:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
eventReader:SetScript("OnEvent", OnEventFunc)
end
function CheckForValidSpell(string)
-- We need to figure out if we're dealing with a SpellID or a Spell Name
local SpellIDCheck = gsub(string, "[%a%p%s]", "")
local SpellNameCheck = string.lower(gsub(string, "[%s%d%p]", ""))
-- First We'll check the Spell ID as it is a quicker check, and return true if we successfully add
if string.len(SpellIDCheck) > 0 then
local SpellID = tonumber(SpellIDCheck)
for t=1, #Nova_SpellBookCache do
if SpellID == Nova_SpellBookCache[t].id then
if #Nova_SpellQueueTable > 0 then
for j=1, #Nova_SpellQueueTable do
if Nova_SpellBookCache[t].id == Nova_SpellQueueTable[j].id then
print("|cff00F0F0Removing|cffFF0000", GetSpellInfo(Nova_SpellQueueTable[j].id), "|cff00F0F0from the Spell Queue before it was cast!")
table.remove(Nova_SpellQueueTable, j)
return false
end
end
end
table.insert(Nova_SpellQueueTable, { name = Nova_SpellBookCache[t].name, id = Nova_SpellBookCache[t].id })
NovaSpellQueueHistory(Nova_SpellBookCache[t].id)
print("|cff00F0F0Successfully added |cffFF0000"..GetSpellInfo(Nova_SpellBookCache[t].id).."|cff00F0F0 to the Spell Queue")
return
end
end
end
-- If we had a string that appeared to be an ID we'll check that first, if nothign returns true, we
-- will then check the Spell Name and if that is a true Spell
if string.len(SpellNameCheck) > 0 then
for k=1, #Nova_SpellBookCache do
if SpellNameCheck == Nova_SpellBookCache[k].name then
if #Nova_SpellQueueTable > 0 then
for j=1, #Nova_SpellQueueTable do
if Nova_SpellBookCache[k].id == Nova_SpellQueueTable[j].id then
print("|cff00F0F0Removing|cffFF0000", GetSpellInfo(Nova_SpellQueueTable[j].id), "|cff00F0F0from the Spell Queue before it was cast!")
table.remove(Nova_SpellQueueTable, j)
return false
end
end
end
table.insert(Nova_SpellQueueTable, { name = Nova_SpellBookCache[k].name, id = Nova_SpellBookCache[k].id })
NovaSpellQueueHistory(Nova_SpellBookCache[k].id)
print("|cff00F0F0Successfully added |cffFF0000"..GetSpellInfo(Nova_SpellBookCache[k].id).."|cff00F0F0 to the Spell Queue")
return
end
end
else return false
end
print("|cffFF00FFThere wasn't a Spell to go along with what your input")
return false
end
function NovaSpellQueueHistory(spellID)
local buttonID = spellID
local buttonName = GetSpellInfo(buttonID)
local AlreadyInHistory = false
-- We are seeing if it's already in the Spell Queue History or not
-- If not, we will create a new button if 6 don't exists already
-- Or we will overwrite the oldest Spell in the History
for h=1, #Nova_SpellQueueHistory do
if buttonID == Nova_SpellQueueHistory[h].id then
table.sort(Nova_SpellQueueHistory, function(x) return x.id == spellID end)
AlreadyInHistory = true
end
end
if not AlreadyInHistory then
if #Nova_SpellQueueHistory <= 5 then
local spellButton = CreateFrame("button", "SpellQueueSystemButton"..tostring(#Nova_SpellQueueHistory + 1), SpellQueueSystemContent, "UIPanelButtonTemplate")
spellButton:SetSize(110, 20)
spellButton:SetScript("OnClick", function(self)
CheckForValidSpell(self:GetText())
end)
table.insert(Nova_SpellQueueHistory, 1, {name=buttonName, id=buttonID, button=spellButton})
elseif #Nova_SpellQueueHistory == 6 then
Nova_SpellQueueHistory[6].id = buttonID
Nova_SpellQueueHistory[6].name = buttonName
table.sort(Nova_SpellQueueHistory, function(x) return x.id == spellID end)
end
end
local startPointX, startPointY = 10, 5
for i=1, #Nova_SpellQueueHistory do
local ButtonSetting = Nova_SpellQueueHistory[i].button
ButtonSetting:SetText(Nova_SpellQueueHistory[i].name)
ButtonSetting:ClearAllPoints()
if i <= 3 then
ButtonSetting:SetPoint("TOPLEFT", SpellQueueSystemContent, "TOPLEFT", startPointX, - (startPointY + (24 * (i-1))))
else
ButtonSetting:SetPoint("TOPRIGHT", SpellQueueSystemContent, "TOPRIGHT", - startPointX , - (startPointY + (24 * (i-4))))
end
end
end
function Nova_Queue_Setup()
Nova_SpellBookCache = { }
Nova_SpellQueueTable = { }
Nova_SpellQueueHistory = { }
local _, _, tabOffset, numEntries = GetSpellTabInfo(2) -- The Spell Tab 1 = General Spells, 2 = Current Spec spells
for i=tabOffset + 1, tabOffset + numEntries do
local spellName, spellSubName = GetSpellBookItemName(i, "spell")
local spell = GetSpellLink(spellName)
if ( not spellSubName or not string.match(spellSubName, "Passive") )
and spell then
local SpellNameFinal = string.lower(gsub(spellName, "[%s%d%p]", ""))
local string1 = gsub(spell, "[%a%|%s%[%]]+", "")
local spellIDfromString = tonumber(string.match(string1, "%p(%d+)"))
table.insert(Nova_SpellBookCache, { name = SpellNameFinal, id = spellIDfromString } )
end
end
-- Title
local frameTitle = CreateFrame("frame", "SpellQueueSystemTitle", UIParent)
frameTitle:ClearAllPoints()
frameTitle:SetSize(120, 27)
frameTitle:SetMovable(true)
frameTitle:EnableMouse(true)
frameTitle:RegisterForDrag("LeftButton")
frameTitle:SetScript("OnDragStart", frameTitle.StartMoving)
frameTitle:SetScript("OnDragStop", frameTitle.StopMovingOrSizing)
frameTitle:SetScript("OnShow", RefreshFrameBoxes)
local TitleString = frameTitle:CreateFontString("TitleString")
TitleString:SetFontObject("GameTooltipText")
TitleString:SetText("Spell Queue System")
TitleString:SetJustifyH("CENTER")
TitleString:SetJustifyV("CENTER")
TitleString:ClearAllPoints()
TitleString:SetPoint("TOPLEFT", SpellQueueSystemTitle, "TOPLEFT")
TitleString:SetPoint("BOTTOMRIGHT", SpellQueueSystemTitle, "BOTTOMRIGHT")
frameTitle:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }});
frameTitle:SetBackdropColor(0,0,0,1);
frameTitle:SetPoint("CENTER", -300, 100)
frameTitle:Show()
-- Main Frame that we shall link everything to
local frameMain = CreateFrame("frame", "SpellQueueSystem", SpellQueueSystemTitle)
frameMain:ClearAllPoints()
frameMain:SetSize(260, 115)
frameMain:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }});
frameMain:SetBackdropColor(0,0,0,1);
frameMain:SetPoint("TOP", SpellQueueSystemTitle, "BOTTOM", 0, -2)
frameMain:Show()
-- Close/Hide Button
local frameClose = CreateFrame('Button', 'SpellQueueSystemClose', frameMain)
frameClose:ClearAllPoints()
frameClose:SetPoint("BOTTOMRIGHT", frameMain, "TOPRIGHT", 0, 4)
frameClose:RegisterForClicks("LeftButtonDown")
frameClose:SetSize(20, 20)
local closeText = frameClose:CreateFontString("closeText")
closeText:SetFontObject("GameTooltipTextSmall")
closeText:SetText("|cFFFFFAFA X|cffffffff")
closeText:ClearAllPoints()
closeText:SetAllPoints(frameClose)
closeText:SetJustifyH("CENTER")
closeText:SetJustifyV("CENTER")
frameClose:SetScript('OnClick', function() frameTitle:Hide() end )
frameClose:SetBackdrop({
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = false, tileSize = 12, edgeSize = 12,
insets = { left = 6, right = 6, top = 6, bottom = 6 }
})
frameClose:Show()
-- Content Frame
local frameContent = CreateFrame("frame", "SpellQueueSystemContent", frameMain)
frameContent:ClearAllPoints()
frameContent:SetPoint("TOPLEFT", frameMain, "TOPLEFT", 5, -28)
frameContent:SetPoint("BOTTOMRIGHT", frameMain, "BOTTOMRIGHT", -5, 5)
frameContent:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 8, edgeSize = 8,
insets = { left = 4, right = 4, top = 4, bottom = 4 }});
frameContent:SetBackdropColor(0,0,0,1);
-- EditBox
local frameEditbox = CreateFrame("Editbox", "SpellQueueSystemEditbox", frameMain, "InputBoxTemplate")
frameEditbox:SetSize(180, 18)
frameEditbox:ClearAllPoints()
frameEditbox:SetAutoFocus(false)
frameEditbox:ClearFocus()
frameEditbox:SetPoint("BOTTOMLEFT", frameContent, "TOPLEFT", 8, 4)
frameEditbox:SetScript("OnEnterPressed", function(self)
CheckForValidSpell(self:GetText())
self:SetText("")
self:ClearFocus()
end)
frameEditbox:SetScript("OnEscapePressed", function(self) self:SetText(""); self:ClearFocus() end)
-- Accept Button
local frameAccept = CreateFrame("Button", "SpellQueueSystemAccept", frameEditbox, "UIPanelButtonTemplate")
frameAccept:SetBackdrop({edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 8, edgeSize = 8,
insets = { left = 4, right = 4, top = 4, bottom = 4 }});
frameAccept:SetBackdropBorderColor(1,1,1,1);
frameAccept:SetNormalFontObject("GameTooltipText")
frameAccept:SetText("Accept")
frameAccept:SetSize(60, 18)
frameAccept:SetPoint("BOTTOMRIGHT", frameContent, "TOPRIGHT", 0, 4)
frameAccept:SetScript("OnClick", function()
CheckForValidSpell(frameEditbox:GetText())
frameEditbox:SetText("")
frameEditbox:ClearFocus()
end)
Event_Reader()
end
end
SLASH_NOVASPELLQUEUE1 = "/novaspell"
function SlashCmdList.NOVASPELLQUEUE(spellText, editbox)
CheckForValidSpell(spellText)
end
if not Setup then
Nova_Queue_Setup()
RunMacroText("/novaspell") -- The first time run, it always returns insecure, so getting that first run out of the way
Setup = true
end