-
Notifications
You must be signed in to change notification settings - Fork 74
/
AceGUIWidget-DungeonToolsSpellButton.lua
179 lines (155 loc) · 5.86 KB
/
AceGUIWidget-DungeonToolsSpellButton.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
local ButtonType, ButtonVersion = "MDTSpellButton", 1
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
local MDT = DungeonTools
local width,height = 248,32
local tinsert,SetPortraitToTexture,SetPortraitTextureFromCreatureDisplayID,GetItemQualityColor,MouseIsOver = table.insert,SetPortraitToTexture,SetPortraitTextureFromCreatureDisplayID,GetItemQualityColor,MouseIsOver
local buttonMethods = {
["OnAcquire"] = function(self)
self:SetWidth(width);
self:SetHeight(height);
end,
["Initialize"] = function(self)
self.callbacks = {}
function self.callbacks.OnClickNormal(_, mouseButton)
if(IsControlKeyDown())then
elseif(IsShiftKeyDown()) then
if DEFAULT_CHAT_FRAME.editBox and DEFAULT_CHAT_FRAME.editBox:IsVisible() then
local old = DEFAULT_CHAT_FRAME.editBox:GetText()
local link = GetSpellLink(self.spellId) or ""
DEFAULT_CHAT_FRAME.editBox:SetText(old .. link)
end
else
end
end
function self.callbacks.OnEnter()
GameTooltip:SetOwner(self.frame, "ANCHOR_BOTTOMLEFT",0,self.frame:GetHeight())
GameTooltip:SetSpellByID(self.spellId)
if self.interruptible then
local interruptible = CreateTextureMarkup("Interface\\EncounterJournal\\UI-EJ-Icons", 64, 64, 32, 32, 0.75, 0.88, 0, 0.5,0,0).. "Interruptible"
GameTooltip:AddLine(interruptible)
end
GameTooltip:Show()
end
function self.callbacks.OnLeave()
GameTooltip:Hide()
end
function self.callbacks.OnKeyDown(self, key)
if (key == "ESCAPE") then
--
end
end
function self.callbacks.OnDragStart()
--
end
function self.callbacks.OnDragStop()
--
end
self.frame:SetScript("OnClick", self.callbacks.OnClickNormal);
self.frame:SetScript("OnKeyDown", self.callbacks.OnKeyDown);
self.frame:SetScript("OnEnter", self.callbacks.OnEnter);
self.frame:SetScript("OnLeave", self.callbacks.OnLeave);
self.frame:EnableKeyboard(false);
self.frame:SetMovable(true);
self.frame:RegisterForDrag("LeftButton");
self.frame:SetScript("OnDragStart", self.callbacks.OnDragStart);
self.frame:SetScript("OnDragStop", self.callbacks.OnDragStop);
self:Enable();
end,
["SetSpell"] = function(self, spellId,spellData)
self.spellId = spellId
local name,_,icon = GetSpellInfo(spellId)
self.icon:SetTexture(icon)
if IsAddOnLoaded("AddOnSkins") then
if AddOnSkins then
local AS = unpack(AddOnSkins)
AS:SkinTexture(self.icon)
end
end
self.title:SetText(name);
if spellData.interruptible then
self.interruptible = true
self.interruptibleIcon:Show()
else
self.interruptible = false
self.interruptibleIcon:Hide()
end
end,
["Disable"] = function(self)
self.background:Hide();
self.frame:Disable();
end,
["Enable"] = function(self)
self.background:Show();
self.frame:Enable();
end,
["Pick"] = function(self)
self.frame:LockHighlight();
end,
["ClearPick"] = function(self)
self.frame:UnlockHighlight();
end,
["SetIndex"] = function(self, index)
self.index = index
end,
["SetTitle"] = function(self, title)
self.titletext = title;
self.title:SetText(title);
end,
["SetScript"] = function() end
}
--Constructor
local function ButtonConstructor()
local name = "MDTSpellButton"..AceGUI:GetNextWidgetNum(ButtonType);
local button = CreateFrame("BUTTON", name, UIParent, "OptionsListButtonTemplate");
button:SetHeight(height);
button:SetWidth(width);
button.dgroup = nil;
button.data = {};
local background = button:CreateTexture(nil, "BACKGROUND");
button.background = background;
background:SetTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2.blp");
background:SetBlendMode("ADD");
background:SetVertexColor(0.5, 0.5, 0.5, 0.25);
background:SetPoint("TOP", button, "TOP");
background:SetPoint("BOTTOM", button, "BOTTOM");
background:SetPoint("LEFT", button, "LEFT");
background:SetPoint("RIGHT", button, "RIGHT");
local icon = button:CreateTexture(nil, "OVERLAY");
button.icon = icon;
icon:SetWidth(height);
icon:SetHeight(height);
icon:SetPoint("LEFT", button, "LEFT");
local interruptibleIcon = button:CreateTexture(nil, "OVERLAY");
interruptibleIcon:SetWidth(height*0.8);
interruptibleIcon:SetHeight(height*0.8);
interruptibleIcon:SetTexture("Interface\\EncounterJournal\\UI-EJ-Icons")
interruptibleIcon:SetTexCoord(0.75,0,0.75,0.5,0.88,0,0.88,0.5)
interruptibleIcon:SetPoint("BOTTOMLEFT", button.icon, "BOTTOMRIGHT",0,-5);
interruptibleIcon:Hide()
local title = button:CreateFontString(nil, "OVERLAY", "GameFontNormal");
button.title = title;
title:SetHeight(14);
title:SetJustifyH("LEFT");
title:SetPoint("TOP", button, "TOP", 0, -2);
title:SetPoint("LEFT", icon, "RIGHT", 2, 0);
title:SetPoint("RIGHT", button, "RIGHT");
button.description = {};
button:SetScript("OnEnter", function()
end);
button:SetScript("OnLeave", function()
end);
local widget = {
frame = button,
title = title,
icon = icon,
interruptibleIcon = interruptibleIcon,
background = background,
type = ButtonType,
parent = UIParent
}
for method, func in pairs(buttonMethods) do
widget[method] = func
end
return AceGUI:RegisterAsWidget(widget);
end
AceGUI:RegisterWidgetType(ButtonType, ButtonConstructor, ButtonVersion)