1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
--[[
SummonAPet
Puts an clickable icon on screen if your pet is not
present and summons it.
TODO/Improvements:
- Either save current slot (easy) or add more buttons/icons
to allow summoning different pets if available. (harder)
- Use proper icon for pet (currently just using a stand-in)
- Checks for valid pet slots in slash command handler
(only needed if using one slot)
- Save icon position
--]]
--[[ Constants ]]--
local ADDON_NAME = "SummonAPet"
local ADDON_SLASH_CMD = "/summonapet"
--[[ Addon variables ]]--
local SummonAPetSlot = 1 -- Slot to use for pet summoning
local AddonReady = false -- Gets set to true once addon fully loaded
--[[ Addon namespace ]]--
local SummonAPet = {}
_G.SummonAPet = SummonAPet
--[[ Base frame for icon button ]]--
SummonAPet.Frame = CreateUIComponent("Frame", "SummonAPetFrame", "UIParent")
_G.SummonAPetFrame = nil -- trash global created by CreateUIComponent
SummonAPet.Frame:SetSize(32,32)
SummonAPet.Frame:ClearAllAnchors()
SummonAPet.Frame:SetAnchor("LEFT", "LEFT", "UIParent", 20, 0)
SummonAPet.Frame:SetAlpha(1.0)
SummonAPet.Frame:SetMouseEnable(true)
SummonAPet.Frame:SetScripts("OnLoad", [=[ SummonAPet.LoadHandler(this) ]=])
SummonAPet.Frame:SetScripts("OnClick", [=[ SummonAPet.ClickHandler(this) ]=])
SummonAPet.Frame:SetScripts("OnUpdate", [=[ SummonAPet.UpdateHandler(this, elapsedTime) ]=])
SummonAPet.Frame:SetScripts("OnMouseDown", [=[ SummonAPet.MouseDownHandler(this, key) ]=])
SummonAPet.Frame:SetScripts("OnMouseUp", [=[ SummonAPet.MouseUpHandler(this, key) ]=])
--[[ Create a texture for the icon/button ]]--
SummonAPet.Texture = CreateUIComponent("Texture", "SummonAPetIcon", "SummonAPetFrame")
_G.SummonAPetIcon = nil
SummonAPet.Texture:SetTexture("interface/icons/boss_skill/skill_boss_skill_76") -- Generic texture
SummonAPet.Texture:SetColor(1.0, 1.0, 1.0);
SummonAPet.Texture:SetSize(32,32);
SummonAPet.Texture:SetAlpha(1.0);
SummonAPet.Texture:SetAlphaMode("BLEND");
SummonAPet.Texture:ClearAllAnchors();
SummonAPet.Texture:SetAnchor("CENTER", "CENTER", SummonAPet.Frame, 0, 0);
SummonAPet.Frame:SetLayers(2,SummonAPet.Texture)
--[[ The Addon functions ]]--
function SummonAPet.LoadHandler(self)
DEFAULT_CHAT_FRAME:AddMessage("['..ADDON_NAME..'] loaded. Use "..ADDON_SLASH_CMD.." for help.",1,1,1)
DEFAULT_CHAT_FRAME:AddMessage("Right-click icon with mouse to position it.",1,1,1)
end
function SummonAPet.ClickHandler(self)
SummonPet(SummonAPetSlot)
end
function SummonAPet.UpdateHandler(self, elapsed)
if IsPetSummoned(SummonAPetSlot) then
-- pet exists, so hide the icon and make button unclickable
SummonAPet.Frame:SetMouseEnable(false)
SummonAPet.Texture:SetAlpha(0)
else
-- no pet, so show the icon and make button clickable
SummonAPet.Frame:SetMouseEnable(true)
SummonAPet.Texture:SetAlpha(1.0)
end
end
function SummonAPet.MouseDownHandler(self, key)
if key == "RBUTTON" then
SummonAPet.Frame:StartMoving("CENTER")
end
end
function SummonAPet.MouseUpHandler(self, key)
SummonAPet.Frame:StopMovingOrSizing()
end
--[[ Define the slash command handler ]]--
_G['SLASH_'..ADDON_NAME..'1'] = ADDON_SLASHCMD
SlashCmdList[ADDON_NAME] = function (ebox, msg)
if not msg or msg == "" then
DEFAULT_CHAT_FRAME:AddMessage("Usage: "..ADDON_SLASH_CMD.." <pet slot number>",1,1,1);
DEFAULT_CHAT_FRAME:AddMessage("where <pet slot number> is the pet's slot number to use for summoning. Default is 1.",1,1,1)
else
local petslot = tonumber((msg or ""))
if petslot < 1 then
petslot = 1
end
SummonAPetSlot = petslot
DEFAULT_CHAT_FRAME:AddMessage("['..ADDON_NAME..'] Pet slot for summoning set to "..petslot,1,1,1)
end
end
|