WoWInterface SVN Soundwave

Compare Revisions

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

Rev 1 → Rev 2

trunk/Soundwave/Soundwave.toc New file
0,0 → 1,9
## Interface: 40000
## Title: Soundwave
## Notes: Summon a random companion from a pre-configured list
## Author: Ailae
## Version: 40000.wowi:revision
## SavedVariablesPerCharacter: SoundwaveDB
 
Soundwave.lua
GUI.lua
\ No newline at end of file
trunk/Soundwave/GUI.lua New file
0,0 → 1,166
local addon, Soundwave = ...
local BUTTONS, POOL = {}, {}
 
local function findKey(id)
if not SoundwaveDB then return false end
for k,v in pairs(SoundwaveDB) do
if v == id then
return true
end
end
return false
end
 
local function removeKey(id)
for k,v in pairs(SoundwaveDB) do
if v == id then
table.remove(SoundwaveDB, k)
end
end
end
 
local function clearButtons()
if #BUTTONS == 0 then return end
for i=1, #BUTTONS do
local t = table.remove(BUTTONS)
table.insert(POOL, t)
t:ClearAllPoints()
t:Hide()
end
end
 
local row = 7
local size = 36
local function CreateButton(parent)
if #POOL > 0 then return table.remove(POOL, 1) end
 
local cb = CreateFrame("Button", nil, parent)
cb:SetSize(size, size)
cb:RegisterForClicks("anyUp")
cb:EnableMouse(true)
cb:Hide()
 
local pushed = cb:CreateTexture()
pushed:SetTexture("Interface\\Buttons\\UI-Quickslot-Depress")
pushed:SetAllPoints(cb)
cb:SetPushedTexture(pushed)
 
local highlight = cb:CreateTexture()
highlight:SetTexture("Interface\\Buttons\\ButtonHilight-Square")
highlight:SetAllPoints(cb)
cb:SetHighlightTexture(highlight)
 
local icon = cb:CreateTexture()
icon:SetAllPoints(cb)
icon:SetTexCoord(0.03, 0.97, 0.03, 0.97)
cb.icon = icon
 
cb:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT", self:GetWidth()/-2, 5)
GameTooltip:SetSpellByID(self.id)
GameTooltip:AddLine("\nClick to add or remove.", 0, 1, 0)
GameTooltip:AddLine("Shift-click to summon (won't add pet to set).", 0, 1, 0, true)
GameTooltip:Show()
end)
 
cb:SetScript("OnLeave", function(self) GameTooltip:Hide() end)
 
cb:SetScript("OnClick", function(self)
if IsShiftKeyDown() then CallCompanion("CRITTER", self.index) return end
 
if findKey(self.index) then
removeKey(self.index)
self.icon:SetDesaturated(true)
else
table.insert(SoundwaveDB, self.index)
self.icon:SetDesaturated(false)
end
end)
 
cb:SetScript("OnShow", function(self)
self.icon:SetDesaturated(not findKey(self.index))
end)
 
return cb
end
 
local f = CreateFrame("Frame", "SoundwaveGUI", UIParent, "ButtonFrameTemplate")
f:SetPoint("CENTER")
f:Hide()
 
f:SetScript("OnShow", function()
SetPortraitToTexture(f.portrait, "Interface\\AddOns\\Soundwave\\icon")
f.TitleText:SetText("Soundwave Configuration")
f:SetMovable(true)
f:SetClampedToScreen(true)
 
-- ScrollFrame
local scroll = CreateFrame("ScrollFrame", "SoundwaveGUIScroll", f, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", f.Inset, "TOPLEFT", 0, -10)
scroll:SetPoint("BOTTOMRIGHT", f.Inset, "BOTTOMRIGHT", -32, 10)
scroll.scrollBarHideable = true
scroll.ScrollBar:Hide()
 
local container = CreateFrame("Frame", nil, scroll)
container:SetSize(1,1)
scroll:SetScrollChild(container)
container:SetPoint("TOPLEFT", scroll, "TOPLEFT")
 
local function updatePets()
for i=1, GetNumCompanions("CRITTER") do
local spellID, icon = select(3, GetCompanionInfo("CRITTER", i))
local button = CreateButton(container)
button.index = i
button.id = spellID
button.icon:SetTexture(icon)
table.insert(BUTTONS, button)
end
 
for i=1, #BUTTONS do
local b = BUTTONS[i]
if i == 1 then
b:SetPoint("TOPLEFT", container, "TOPLEFT", 10, 0)
else
if mod(i-1, row) == 0 then
b:SetPoint("TOPLEFT", BUTTONS[i-row], "BOTTOMLEFT", 0, -5)
else
b:SetPoint("LEFT", BUTTONS[i-1], "RIGHT", 5, 0)
end
end
b:Show()
end
end
 
local clear = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
clear:SetSize(80, 22)
clear:SetText("Reset")
clear:SetPoint("TOP", f.Inset, "BOTTOM", 0, 0)
 
clear:SetScript("OnClick", function()
if #SoundwaveDB == 0 then return end
wipe(SoundwaveDB)
 
clearButtons()
updatePets()
end)
 
local mover = CreateFrame("Frame", nil, f)
mover:SetAllPoints(f.topBorderBar)
mover:EnableMouse(true)
mover:SetScript("OnMouseDown", function()
f:ClearAllPoints()
f:StartMoving()
end)
 
mover:SetScript("OnMouseUp", function()
f:StopMovingOrSizing()
end)
 
table.insert(UISpecialFrames, "SoundwaveGUI")
 
updatePets()
f:SetScript("OnShow", updatePets)
end)
 
f:SetScript("OnHide", function() clearButtons() Soundwave:COMPANION_UPDATE("CRITTER") end)
Soundwave.GUI = f
\ No newline at end of file
trunk/Soundwave/icon.blp Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes : Added: svn:mime-type + application/octet-stream
trunk/Soundwave/Soundwave.lua New file
0,0 → 1,63
--[[
 
Soundwave
by Ailae of Emeriss-EU
 
]]
 
local addon, Soundwave = ...
local base = "#showtooltip\n/cast <SPELL>"
 
function Soundwave:COMPANION_UPDATE(k)
if k ~= "CRITTER" then return end
if InCombatLockdown() then self:RegisterEvent("PLAYER_REGEN_ENABLED") return end
if GetNumCompanions("CRITTER") == 0 then return end
 
local spell, petindex
if #SoundwaveDB > 1 then
petindex = math.random(1, #SoundwaveDB)
-- don't want the same again, gawd
if self.current and petindex == self.current then
while petindex == self.current do
petindex = math.random(1, #SoundwaveDB)
end
end
spell = select(3, GetCompanionInfo("CRITTER", SoundwaveDB[petindex]))
else
petindex = SoundwaveDB[1] or 1
spell = select(3, GetCompanionInfo("CRITTER", petindex))
end
 
self.current = petindex
 
local spellName = GetSpellInfo(spell)
local macro = string.gsub(base, "<SPELL>", spellName)
EditMacro(GetMacroIndexByName("Soundwave"), "Soundwave", nil, macro)
end
 
function Soundwave:PLAYER_REGEN_ENABLED()
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
self:COMPANION_UPDATE("CRITTER")
end
 
function Soundwave:PLAYER_LOGIN()
if not GetMacroInfo("Soundwave") then
CreateMacro("Soundwave", 1, base, 1)
end
SoundwaveDB = SoundwaveDB or {}
 
self:COMPANION_UPDATE("CRITTER")
 
SLASH_Soundwave1 = "/sw"
SLASH_Soundwave2 = "/soundwave"
SlashCmdList.Soundwave = function() Soundwave.GUI:Show() end
end
 
Soundwave.frame = CreateFrame("Frame", nil, UIParent)
Soundwave.frame:SetScript("OnEvent", function(self, event, ...) return Soundwave[event] and Soundwave[event](Soundwave, ...) end)
 
function Soundwave:RegisterEvent(event) return self.frame:RegisterEvent(event) end
function Soundwave:UnregisterEvent(event) return self.frame:UnregisterEvent(event) end
 
Soundwave:RegisterEvent("PLAYER_LOGIN")
Soundwave:RegisterEvent("COMPANION_UPDATE")
\ No newline at end of file