forked from davidmeen/TomeOfTeleportation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTomeQuickMenu.lua
135 lines (109 loc) · 3.23 KB
/
TomeQuickMenu.lua
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
124
125
126
127
128
129
130
131
132
133
134
135
local QuickMenuFrame = nil
local QuickMenuButtons = {}
local QuickMenuTextures = {}
local QuickMenuVisible = false
function TeleHideQuickMenu()
if QuickMenuFrame then
QuickMenuFrame:Hide()
QuickMenuVisible = false
end
end
function TeleQuickMenu_OnHide()
QuickMenuVisible = false
end
function TeleQuickMenuOnClick(frame,button)
if button == "RightButton" then
QuickMenuFrame:Hide()
end
end
function TeleToggleQuickMenu(favourites, size)
if not QuickMenuFrame then
QuickMenuFrame = TeleporterQuickMenuFrame
QuickMenuFrame:SetFrameStrata("HIGH")
tinsert(UISpecialFrames,TeleporterQuickMenuFrame:GetName());
end
if QuickMenuVisible then
TeleHideQuickMenu()
else
local favCount = 0
for spellId, isItem in pairs(favourites) do
favCount = favCount + 1
end
local x, y = GetCursorPosition()
QuickMenuFrame:SetPoint("TOPLEFT", nil, "BOTTOMLEFT", x - size, y)
QuickMenuFrame:SetPoint("BOTTOMRIGHT", nil, "BOTTOMLEFT", x, y - size * favCount)
for i = #QuickMenuButtons + 1, favCount do
QuickMenuButtons[i] = CreateFrame( "Button", "TeleporterQuickMenuFrame"..i, QuickMenuFrame,"SecureActionButtonTemplate")
QuickMenuButtons[i]:SetWidth(size)
QuickMenuButtons[i]:SetHeight(size)
QuickMenuButtons[i]:SetPoint("TOPLEFT",QuickMenuFrame,"TOPLEFT",0,-size*(i-1))
QuickMenuButtons[i]:SetPoint("BOTTOMRIGHT",QuickMenuFrame,"TOPLEFT",size,-size*i)
QuickMenuButtons[i]:SetAttribute("type", "macro")
QuickMenuTextures[i] = QuickMenuButtons[i]:CreateTexture()
QuickMenuTextures[i]:SetAllPoints(QuickMenuButtons[i])
QuickMenuButtons[i]:SetScript(
"OnLeave",
function()
GameTooltip:Hide()
end )
end
local index = 1
for i, spell in pairs(favourites) do
local button = QuickMenuButtons[index]
local isItem = spell.isItem
local spellId = spell.spellId
local texture
local name
if isItem then
name, _, _, _, _, _, _, _, _, texture = GetItemInfo( spellId )
if name then
button:SetScript(
"OnEnter",
function()
TeleporterShowItemTooltip( name, button )
end )
if PlayerHasToy(spellId) then
button:SetAttribute(
"macrotext",
"/teleportercastspell " .. GetItemSpell(spellId) .. "\n" ..
"/cast " .. name .. "\n" )
else
button:SetAttribute(
"macrotext",
"/teleporteruseitem " .. name .. "\n" ..
"/use " .. name .. "\n" )
end
end
else
if C_Spell and C_Spell.GetSpellInfo then
name = C_Spell.GetSpellInfo(spellId).name
texture = C_Spell.GetSpellInfo(spellId).iconID
else
name,_,texture = GetSpellInfo( spellId )
end
button:SetScript(
"OnEnter",
function()
TeleporterShowSpellTooltip( name, button )
end )
button:SetAttribute(
"macrotext",
"/teleportercastspell " .. name .. "\n" ..
"/cast " .. name .. "\n" )
end
button:RegisterForClicks("AnyUp", "AnyDown")
if name then
QuickMenuTextures[index]:SetTexture(texture)
QuickMenuButtons[index]:Show()
QuickMenuButtons[index]:SetScript("OnMouseUp", TeleQuickMenuOnClick)
index = index + 1
end
end
while index <= #QuickMenuButtons do
QuickMenuButtons[index]:Hide()
index = index + 1
end
QuickMenuFrame:Show()
QuickMenuVisible = true
end
end