Code:
-- Morpher
-- Eradicator (2009)
--
--This addon is free software. It comes without any warranty, to
-- the extent permitted by applicable law. You can redistribute it
-- and/or modify it under the terms of the Do What The **** You Want
-- To Public License, Version 2, as published by Sam Hocevar. See
-- included LICENSE.txt for more details.
local morph=false
local morphid=0
local morphtext=".modify displayid "
morphFrame = CreateFrame("FRAME", nil, UIParent)
morphFrame:SetMovable(true)
morphFrame:EnableMouse(true)
morphFrame:SetWidth(200)
morphFrame:SetHeight(30)
morphFrame:SetPoint("CENTER", UIParent, "CENTER")
morphFrame: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 }})
morphFrame:SetBackdropColor(0,0,0,1)
morphFrame:Hide()
function morph_StopMoving()
if morphFrame.isMoving then
morphFrame:StopMovingOrSizing()
morphFrame.isMoving = false
end
end
function morph_StartMoving()
if arg1 == "RightButton" then
morphFrame:StartMoving()
morphFrame.isMoving = true
end
end
morphFrame.titletxt = morphFrame:CreateFontString(nil, "OVERLAY", "GameTooltipText")
morphFrame.titletxt:SetText("Morpher")
morphFrame.titletxt:SetPoint("CENTER", morphFrame, "LEFT", 35, 0)
morphFrame.closebtn = CreateFrame("BUTTON", nil, morphFrame, "UIPanelCloseButton")
morphFrame.closebtn:SetPoint("CENTER", morphFrame, "RIGHT", -14, 0)
morphFrame.closebtn:Show()
morphFrame.nextbtn = CreateFrame("BUTTON", nil, morphFrame, "UIPanelButtonTemplate ")
morphFrame.nextbtn:SetWidth(15)
morphFrame.nextbtn:SetHeight(19)
morphFrame.nextbtn:SetText(">")
morphFrame.nextbtn:SetPoint("CENTER", morphFrame.closebtn, "LEFT", -3, 0)
morphFrame.nextbtn:SetAlpha(1)
morphFrame.nextbtn:Show()
morphFrame.stopbtn = CreateFrame("BUTTON", nil, morphFrame, "UIPanelButtonTemplate ")
morphFrame.stopbtn:SetWidth(34)
morphFrame.stopbtn:SetHeight(19)
morphFrame.stopbtn:SetText("Stop")
morphFrame.stopbtn:SetPoint("CENTER", morphFrame.nextbtn, "LEFT", -18, 0)
morphFrame.stopbtn:SetAlpha(1)
morphFrame.stopbtn:Show()
morphFrame.startbtn = CreateFrame("BUTTON", nil, morphFrame, "UIPanelButtonTemplate ")
morphFrame.startbtn:SetWidth(34)
morphFrame.startbtn:SetHeight(19)
morphFrame.startbtn:SetText("Start")
morphFrame.startbtn:SetPoint("CENTER", morphFrame.stopbtn, "LEFT", -18, 0)
morphFrame.startbtn:SetAlpha(1)
morphFrame.startbtn:Show()
morphFrame.prevbtn = CreateFrame("BUTTON", nil, morphFrame, "UIPanelButtonTemplate ")
morphFrame.prevbtn:SetWidth(15)
morphFrame.prevbtn:SetHeight(19)
morphFrame.prevbtn:SetText("<")
morphFrame.prevbtn:SetPoint("CENTER", morphFrame.startbtn, "LEFT", -9, 0)
morphFrame.prevbtn:SetAlpha(1)
morphFrame.prevbtn:Show()
function NextMorph()
morphid=morphid+1
SendChatMessage(morphtext .. tostring(morphid), "SAY", nil)
morphFrame.titletxt:SetText("Morpher - " .. tostring(morphid))
morphFrame:SetWidth(148 + morphFrame.titletxt:GetWidth())
morphFrame.titletxt:ClearAllPoints()
morphFrame.titletxt:SetPoint("CENTER",morphFrame,"LEFT", morphFrame.titletxt:GetWidth()/2+10, 0)
end
function PrevMorph()
morphid=morphid-1
if morphid < 1 then
DEFAULT_CHAT_FRAME:AddMessage("MorphID cannot be lower than one.",1,0,0,1)
return
end
SendChatMessage(morphtext .. tostring(morphid), "SAY", nil)
morphFrame.titletxt:SetText("Morpher - " .. tostring(morphid))
morphFrame:SetWidth(148 + morphFrame.titletxt:GetWidth())
morphFrame.titletxt:ClearAllPoints()
morphFrame.titletxt:SetPoint("CENTER",morphFrame,"LEFT", morphFrame.titletxt:GetWidth()/2+10, 0)
end
function SetMorph(i)
if i < 1 then
DEFAULT_CHAT_FRAME:AddMessage("MorphID cannot be lower than one.",1,0,0,1)
return
end
morphid=i
morphFrame.titletxt:SetText("Morpher - " .. tostring(morphid))
morphFrame:SetWidth(148 + morphFrame.titletxt:GetWidth())
morphFrame.titletxt:ClearAllPoints()
morphFrame.titletxt:SetPoint("CENTER",morphFrame,"LEFT", morphFrame.titletxt:GetWidth()/2+10, 0)
end
morphFrame:SetScript("OnMouseDown", morph_StartMoving)
morphFrame:SetScript("OnMouseUp", morph_StopMoving)
morphFrame:SetScript("OnHide", morph_StopMoving)
morphFrame.closebtn:SetScript("OnClick", function()
morph=false
morphFrame:Hide() end)
morphFrame.startbtn:SetScript("OnClick", function() morph=true end)
morphFrame.stopbtn:SetScript("OnClick", function() morph=false end)
morphFrame.nextbtn:SetScript("OnClick", NextMorph)
morphFrame.prevbtn:SetScript("OnClick", PrevMorph)
morphFrame:SetScript("OnUpdate", function(self, elapsed)
self.elapsed = self.elapsed + elapsed
if self.elapsed >= 1 then
self.elapsed = 0
if morph==true then
NextMorph()
end
end
end)
morphFrame.elapsed = 0
local morpher_scm_hook = SendChatMessage
function SendChatMessage(msg,type,lang,chan)
if string.sub(msg,1,1)=="#" and string.sub(msg,2,2)~="#" then
if msg == "#morph toggle" then
if morphFrame:IsVisible() then
DEFAULT_CHAT_FRAME:AddMessage("Morpher frame has been hidden.",0,1,0,1)
morph=false
morphFrame:Hide()
else
DEFAULT_CHAT_FRAME:AddMessage("Morpher frame has been shown.",0,1,0,1)
morphFrame:Show()
end
elseif msg == "#morph show" then
if not morphFrame:IsVisible() then
DEFAULT_CHAT_FRAME:AddMessage("Morpher frame has been shown.",0,1,0,1)
morphFrame:Show()
end
elseif msg == "#morph hide" then
if morphFrame:IsVisible() then
DEFAULT_CHAT_FRAME:AddMessage("Morpher frame has been hidden.",0,1,0,1)
morph=false
morphFrame:Hide()
end
elseif string.sub(msg,1,6)=="#morph" then
if string.len(msg)==6 then
DEFAULT_CHAT_FRAME:AddMessage("You must enter a number.",1,0,0,1)
return
end
local id = tonumber(string.sub(msg,7))
if id ~= nil then
SetMorph(id)
else
DEFAULT_CHAT_FRAME:AddMessage("You must enter a number.",1,0,0,1)
end
else
morpher_scm_hook(msg,type,lang,chan)
end
else
morpher_scm_hook(msg,type,lang,chan)
end
end