-
Notifications
You must be signed in to change notification settings - Fork 27
/
Spell.lua
187 lines (148 loc) · 4.29 KB
/
Spell.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
180
181
182
183
184
185
186
187
--- @type StdUi
local StdUi = LibStub and LibStub('StdUi', true);
if not StdUi then
return
end
local module, version = 'Spell', 3;
if not StdUi:UpgradeNeeded(module, version) then
return
end
----------------------------------------------------
--- SpellBox
----------------------------------------------------
local SpellBoxEvents = {
OnEnter = function(self)
if self.editBox.value then
GameTooltip:SetOwner(self.editBox);
GameTooltip:SetSpellByID(self.editBox.value);
GameTooltip:Show();
end
end,
OnLeave = function(self)
if self.editBox.value then
GameTooltip:Hide();
end
end
};
function StdUi:SpellBox(parent, width, height, iconSize, spellValidator)
iconSize = iconSize or 16;
local editBox = self:EditBox(parent, width, height, '', spellValidator or self.Util.spellValidator);
editBox:SetTextInsets(iconSize + 7, 3, 3, 3);
local iconFrame = self:Panel(editBox, iconSize, iconSize);
self:GlueLeft(iconFrame, editBox, 2, 0, true);
local icon = self:Texture(iconFrame, iconSize, iconSize, 134400);
icon:SetAllPoints();
editBox.icon = icon;
iconFrame.editBox = editBox;
for k, v in pairs(SpellBoxEvents) do
iconFrame:SetScript(k, v);
end
return editBox;
end
----------------------------------------------------
--- SpellInfo
----------------------------------------------------
local SpellInfoMethods = {
SetSpell = function(self, nameOrId)
local name, _, i, _, _, _, spellId
if C_Spell then
name = C_Spell.GetSpellInfo(nameOrId).name;
i = C_Spell.GetSpellInfo(nameOrId).iconID;
spellId = C_Spell.GetSpellInfo(nameOrId).spellID;
else
name, _, i, _, _, _, spellId = GetSpellInfo(nameOrId)
end
self.spellId = spellId;
self.spellName = name;
self.icon:SetTexture(i);
self.text:SetText(name);
end
};
local SpellInfoEvents = {
OnEnter = function(self)
GameTooltip:SetOwner(self.widget);
GameTooltip:SetSpellByID(self.widget.spellId);
GameTooltip:Show();
end,
OnLeave = function()
GameTooltip:Hide();
end
};
function StdUi:SpellInfo(parent, width, height, iconSize)
iconSize = iconSize or 16;
local frame = self:Panel(parent, width, height);
local iconFrame = self:Panel(frame, iconSize, iconSize);
self:GlueLeft(iconFrame, frame, 2, 0, true);
local icon = self:Texture(iconFrame, iconSize, iconSize);
icon:SetAllPoints();
local btn = self:SquareButton(frame, iconSize, iconSize, 'DELETE');
StdUi:GlueRight(btn, frame, -3, 0, true);
local text = self:Label(frame);
text:SetPoint('LEFT', icon, 'RIGHT', 3, 0);
text:SetPoint('RIGHT', btn, 'RIGHT', -3, 0);
frame.removeBtn = btn;
frame.icon = icon;
frame.text = text;
btn.parent = frame;
iconFrame.widget = frame;
for k, v in pairs(SpellInfoMethods) do
frame[k] = v;
end
for k, v in pairs(SpellInfoEvents) do
iconFrame:SetScript(k, v);
end
return frame;
end;
----------------------------------------------------
--- SpellCheckbox
----------------------------------------------------
local SpellCheckboxMethods = {
SetSpell = function(self, nameOrId)
local name, _, i, _, _, _, spellId
if C_Spell then
name = C_Spell.GetSpellInfo(nameOrId).name;
i = C_Spell.GetSpellInfo(nameOrId).iconID;
spellId = C_Spell.GetSpellInfo(nameOrId).spellID;
else
name, _, i, _, _, _, spellId = GetSpellInfo(nameOrId)
end
self.spellId = spellId;
self.spellName = name;
self.icon:SetTexture(i);
self.text:SetText(name);
end
};
local SpellCheckboxEvents = {
OnEnter = function(self)
if self.spellId then
GameTooltip:SetOwner(self);
GameTooltip:SetSpellByID(self.spellId);
GameTooltip:Show();
end
end,
OnLeave = function(self)
if self.spellId then
GameTooltip:Hide();
end
end
};
function StdUi:SpellCheckbox(parent, width, height, iconSize)
iconSize = iconSize or 16;
local checkbox = self:Checkbox(parent, '', width, height);
checkbox.spellId = nil;
checkbox.spellName = '';
local iconFrame = self:Panel(checkbox, iconSize, iconSize);
iconFrame:SetPoint('LEFT', checkbox.target, 'RIGHT', 5, 0);
local icon = self:Texture(iconFrame, iconSize, iconSize);
icon:SetAllPoints();
checkbox.icon = icon;
checkbox.text:SetPoint('LEFT', iconFrame, 'RIGHT', 5, 0);
for k, v in pairs(SpellCheckboxMethods) do
checkbox[k] = v;
end
for k, v in pairs(SpellCheckboxEvents) do
checkbox:SetScript(k, v);
end
return checkbox;
end;
StdUi:RegisterModule(module, version);