1 |
13 |
Thurallor-7095 |
Slot = class(Turbine.UI.Control); |
2 |
|
Thurallor-7095 |
|
3 |
|
Thurallor-7095 |
function Slot:Constructor(info) |
4 |
|
Thurallor-7095 |
Turbine.UI.Control.Constructor(self); |
5 |
|
Thurallor-7095 |
self:SetMouseVisible(false); |
6 |
|
Thurallor-7095 |
self:SetSize(36, 36); |
7 |
|
Thurallor-7095 |
self:SetInfo(info); |
8 |
15 |
Thurallor-7095 |
self:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend); |
9 |
|
Thurallor-7095 |
Turbine.UI.Control.SetAllowDrop(self, false); |
10 |
13 |
Thurallor-7095 |
end |
11 |
|
Thurallor-7095 |
|
12 |
|
Thurallor-7095 |
function Slot:GetInfo() |
13 |
|
Thurallor-7095 |
return self.info; |
14 |
|
Thurallor-7095 |
end |
15 |
|
Thurallor-7095 |
|
16 |
20 |
Thurallor-7095 |
function Slot:GetItem() |
17 |
|
Thurallor-7095 |
if (self.object.GetItem) then |
18 |
|
Thurallor-7095 |
return self.object:GetItem(); |
19 |
|
Thurallor-7095 |
end |
20 |
|
Thurallor-7095 |
end |
21 |
|
Thurallor-7095 |
|
22 |
13 |
Thurallor-7095 |
function Slot:GetNumLabel() |
23 |
|
Thurallor-7095 |
return self.slotNumber; |
24 |
|
Thurallor-7095 |
end |
25 |
|
Thurallor-7095 |
|
26 |
|
Thurallor-7095 |
function Slot:IsQuickslot() |
27 |
|
Thurallor-7095 |
return self.isQuickslot; |
28 |
|
Thurallor-7095 |
end |
29 |
|
Thurallor-7095 |
|
30 |
|
Thurallor-7095 |
function Slot:SetActionEnabled(enabled) |
31 |
|
Thurallor-7095 |
self.actionEnabled = enabled; |
32 |
21 |
Thurallor-7095 |
if (self.object) then |
33 |
|
Thurallor-7095 |
self.object:SetMouseVisible(enabled); |
34 |
|
Thurallor-7095 |
end |
35 |
13 |
Thurallor-7095 |
if (self.numLabel) then |
36 |
|
Thurallor-7095 |
self.numLabel:SetMouseVisible(not enabled); |
37 |
|
Thurallor-7095 |
end |
38 |
|
Thurallor-7095 |
end |
39 |
|
Thurallor-7095 |
|
40 |
|
Thurallor-7095 |
function Slot:SetAllowDrop(allowDrop) |
41 |
|
Thurallor-7095 |
if (self.numLabel) then |
42 |
|
Thurallor-7095 |
self.numLabel:SetAllowDrop(allowDrop); |
43 |
21 |
Thurallor-7095 |
elseif (self.object) then |
44 |
13 |
Thurallor-7095 |
self.object:SetAllowDrop(allowDrop); |
45 |
|
Thurallor-7095 |
end |
46 |
|
Thurallor-7095 |
end |
47 |
|
Thurallor-7095 |
|
48 |
|
Thurallor-7095 |
function Slot:SetDraggable(draggable) |
49 |
|
Thurallor-7095 |
if (draggable) then |
50 |
|
Thurallor-7095 |
self.numLabel.MouseDown = function(sender, args) |
51 |
|
Thurallor-7095 |
self:MouseDown(args); |
52 |
|
Thurallor-7095 |
end |
53 |
|
Thurallor-7095 |
self.numLabel.MouseUp = function(sender, args) |
54 |
|
Thurallor-7095 |
self:MouseUp(args); |
55 |
|
Thurallor-7095 |
end |
56 |
|
Thurallor-7095 |
self.numLabel.MouseMove = function() |
57 |
|
Thurallor-7095 |
self:MouseMove(); |
58 |
|
Thurallor-7095 |
end |
59 |
|
Thurallor-7095 |
elseif (self.numLabel) then |
60 |
|
Thurallor-7095 |
self.numLabel.MouseDown = nil; |
61 |
|
Thurallor-7095 |
self.numLabel.MouseUp = nil; |
62 |
|
Thurallor-7095 |
self.numLabel.MouseMove = nil; |
63 |
|
Thurallor-7095 |
end |
64 |
|
Thurallor-7095 |
end |
65 |
|
Thurallor-7095 |
|
66 |
|
Thurallor-7095 |
function Slot:SetInfo(info) |
67 |
|
Thurallor-7095 |
|
68 |
|
Thurallor-7095 |
-- Discard old object, if it's a different type |
69 |
|
Thurallor-7095 |
if (self.object and (self.info.class ~= info.class)) then |
70 |
|
Thurallor-7095 |
self.object:SetParent(nil); |
71 |
|
Thurallor-7095 |
self.object = nil; |
72 |
|
Thurallor-7095 |
end |
73 |
|
Thurallor-7095 |
|
74 |
|
Thurallor-7095 |
self.info = {}; |
75 |
|
Thurallor-7095 |
DeepTableCopy(info, self.info); |
76 |
|
Thurallor-7095 |
|
77 |
21 |
Thurallor-7095 |
if (not self.parent) then |
78 |
|
Thurallor-7095 |
return; |
79 |
|
Thurallor-7095 |
end |
80 |
|
Thurallor-7095 |
|
81 |
13 |
Thurallor-7095 |
-- Create the quickslot object or command icon |
82 |
|
Thurallor-7095 |
if ((not info.class) or (info.class == "Turbine.UI.Lotro.Quickslot")) then |
83 |
|
Thurallor-7095 |
if (not self.object) then |
84 |
|
Thurallor-7095 |
local object = Turbine.UI.Lotro.Quickslot(); |
85 |
|
Thurallor-7095 |
object:SetParent(self); |
86 |
15 |
Thurallor-7095 |
object:SetZOrder(1); |
87 |
13 |
Thurallor-7095 |
object:SetUseOnRightClick(false); |
88 |
|
Thurallor-7095 |
object.MouseClick = function(sender, args) |
89 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseClick", args); |
90 |
13 |
Thurallor-7095 |
end |
91 |
|
Thurallor-7095 |
self.object = object; |
92 |
|
Thurallor-7095 |
end |
93 |
|
Thurallor-7095 |
self.object:SetShortcut(Turbine.UI.Lotro.Shortcut(info.type, info.Data)); |
94 |
|
Thurallor-7095 |
self.isQuickslot = true; |
95 |
15 |
Thurallor-7095 |
self.object.DragDrop = function(sender) |
96 |
|
Thurallor-7095 |
sender:SetShortcut(Turbine.UI.Lotro.Shortcut(self.info.type, self.info.Data)); |
97 |
|
Thurallor-7095 |
end |
98 |
13 |
Thurallor-7095 |
elseif (info.class == "Turbine.UI.Control") then |
99 |
|
Thurallor-7095 |
if (not self.object) then |
100 |
|
Thurallor-7095 |
local object = Turbine.UI.Control(); |
101 |
|
Thurallor-7095 |
object:SetParent(self); |
102 |
|
Thurallor-7095 |
object:SetSize(32, 32); |
103 |
|
Thurallor-7095 |
object:SetPosition(3, 3); |
104 |
15 |
Thurallor-7095 |
object:SetZOrder(1); |
105 |
13 |
Thurallor-7095 |
object.MouseClick = function(sender, args) |
106 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseClick", args); |
107 |
13 |
Thurallor-7095 |
end |
108 |
|
Thurallor-7095 |
object.MouseEnter = function(sender) |
109 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseEnter"); |
110 |
13 |
Thurallor-7095 |
end |
111 |
|
Thurallor-7095 |
object.MouseLeave = function(sender) |
112 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseLeave"); |
113 |
13 |
Thurallor-7095 |
end |
114 |
|
Thurallor-7095 |
self.object = object; |
115 |
|
Thurallor-7095 |
end |
116 |
|
Thurallor-7095 |
self.isQuickslot = false; |
117 |
|
Thurallor-7095 |
end |
118 |
15 |
Thurallor-7095 |
|
119 |
13 |
Thurallor-7095 |
-- Draw text overlay (if any) |
120 |
|
Thurallor-7095 |
if ((info.textOverlay) or (info.background)) then |
121 |
|
Thurallor-7095 |
if (not self.textOverlay) then |
122 |
|
Thurallor-7095 |
local textOverlay = Turbine.UI.Label(); |
123 |
|
Thurallor-7095 |
textOverlay:SetParent(self); |
124 |
15 |
Thurallor-7095 |
textOverlay:SetZOrder(2); |
125 |
13 |
Thurallor-7095 |
textOverlay:SetSize(32, 32); |
126 |
|
Thurallor-7095 |
textOverlay:SetPosition(3, 3); |
127 |
|
Thurallor-7095 |
textOverlay:SetMouseVisible(false); |
128 |
|
Thurallor-7095 |
textOverlay:SetFont(Turbine.UI.Lotro.Font.Verdana10); |
129 |
|
Thurallor-7095 |
textOverlay:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter); |
130 |
|
Thurallor-7095 |
textOverlay:SetFontStyle(Turbine.UI.FontStyle.Outline); |
131 |
|
Thurallor-7095 |
textOverlay:SetOutlineColor(Turbine.UI.Color(1, 0, 0, 0)); |
132 |
|
Thurallor-7095 |
textOverlay:SetMultiline(true); |
133 |
|
Thurallor-7095 |
textOverlay:SetMarkupEnabled(true); |
134 |
|
Thurallor-7095 |
self.textOverlay = textOverlay; |
135 |
|
Thurallor-7095 |
end |
136 |
|
Thurallor-7095 |
self.textOverlay:SetBackground(info.background); |
137 |
|
Thurallor-7095 |
self.textOverlay:SetText(info.textOverlay); |
138 |
15 |
Thurallor-7095 |
self.textOverlay:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend); |
139 |
13 |
Thurallor-7095 |
elseif (self.textOverlay) then |
140 |
|
Thurallor-7095 |
self.textOverlay:SetParent(nil); |
141 |
|
Thurallor-7095 |
self.textOverlay = nil; |
142 |
|
Thurallor-7095 |
end |
143 |
|
Thurallor-7095 |
end |
144 |
|
Thurallor-7095 |
|
145 |
|
Thurallor-7095 |
function Slot:SetNumLabel(slotNumber) |
146 |
|
Thurallor-7095 |
if (not self.numLabel) then |
147 |
|
Thurallor-7095 |
local numLabel = Turbine.UI.Label(); |
148 |
|
Thurallor-7095 |
numLabel:SetParent(self); |
149 |
|
Thurallor-7095 |
numLabel:SetFont(Turbine.UI.Lotro.Font.TrajanPro15); |
150 |
|
Thurallor-7095 |
numLabel:SetFontStyle(Turbine.UI.FontStyle.Outline); |
151 |
|
Thurallor-7095 |
numLabel:SetOutlineColor(Turbine.UI.Color(1, 0, 0, 0)); |
152 |
|
Thurallor-7095 |
numLabel:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter); |
153 |
|
Thurallor-7095 |
numLabel:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend); |
154 |
15 |
Thurallor-7095 |
numLabel:SetSize(38, 38); |
155 |
|
Thurallor-7095 |
numLabel:SetZOrder(3); |
156 |
13 |
Thurallor-7095 |
numLabel.DragDrop = function(sender, args) |
157 |
20 |
Thurallor-7095 |
DoCallbacks(self, "DragDrop", args); |
158 |
13 |
Thurallor-7095 |
end |
159 |
|
Thurallor-7095 |
numLabel.MouseClick = function(sender, args) |
160 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseClick", args); |
161 |
13 |
Thurallor-7095 |
end |
162 |
|
Thurallor-7095 |
self.numLabel = numLabel; |
163 |
|
Thurallor-7095 |
end |
164 |
|
Thurallor-7095 |
self.numLabel:SetText(slotNumber); |
165 |
|
Thurallor-7095 |
self.slotNumber = slotNumber; |
166 |
|
Thurallor-7095 |
end |
167 |
|
Thurallor-7095 |
|
168 |
16 |
Thurallor-7095 |
function Slot:SetSelected(selected, color) |
169 |
13 |
Thurallor-7095 |
if (not selected) then |
170 |
|
Thurallor-7095 |
if (self.marquee) then |
171 |
|
Thurallor-7095 |
self.marquee:SetParent(nil); |
172 |
|
Thurallor-7095 |
self.marquee = nil; |
173 |
|
Thurallor-7095 |
end |
174 |
|
Thurallor-7095 |
return; |
175 |
|
Thurallor-7095 |
end |
176 |
|
Thurallor-7095 |
|
177 |
16 |
Thurallor-7095 |
if (not color) then |
178 |
|
Thurallor-7095 |
color = Turbine.UI.Color.White; |
179 |
|
Thurallor-7095 |
end |
180 |
|
Thurallor-7095 |
|
181 |
13 |
Thurallor-7095 |
if (not self.marquee) then |
182 |
|
Thurallor-7095 |
local marquee = Thurallor.UI.Marquee(); |
183 |
|
Thurallor-7095 |
marquee:SetParent(self); |
184 |
|
Thurallor-7095 |
marquee:SetPosition(2, 2); |
185 |
|
Thurallor-7095 |
marquee:SetSize(34, 34); |
186 |
|
Thurallor-7095 |
marquee:SetMouseVisible(false); |
187 |
|
Thurallor-7095 |
self.marquee = marquee; |
188 |
|
Thurallor-7095 |
end |
189 |
16 |
Thurallor-7095 |
|
190 |
|
Thurallor-7095 |
self.marquee:SetColor(color); |
191 |
13 |
Thurallor-7095 |
end |
192 |
|
Thurallor-7095 |
|
193 |
21 |
Thurallor-7095 |
function Slot:SetParent(parent) |
194 |
|
Thurallor-7095 |
self.parent = parent; |
195 |
|
Thurallor-7095 |
if (parent) then |
196 |
|
Thurallor-7095 |
self:SetInfo(self.info); |
197 |
|
Thurallor-7095 |
elseif (self.object) then |
198 |
26 |
Thurallor-7095 |
self:MouseLeave(); |
199 |
21 |
Thurallor-7095 |
self.object:SetParent(nil); |
200 |
|
Thurallor-7095 |
self.object = nil; |
201 |
|
Thurallor-7095 |
end |
202 |
|
Thurallor-7095 |
Turbine.UI.Control.SetParent(self, parent); |
203 |
|
Thurallor-7095 |
end |
204 |
|
Thurallor-7095 |
|
205 |
13 |
Thurallor-7095 |
function Slot:DragDrop(args) |
206 |
|
Thurallor-7095 |
local info = {}; |
207 |
|
Thurallor-7095 |
info.class = "Turbine.UI.Lotro.Quickslot"; |
208 |
15 |
Thurallor-7095 |
local newShortcut = args.DragDropInfo:GetShortcut(); |
209 |
|
Thurallor-7095 |
if (newShortcut) then |
210 |
|
Thurallor-7095 |
info.type = newShortcut:GetType(); |
211 |
|
Thurallor-7095 |
info.Data = newShortcut:GetData(); |
212 |
|
Thurallor-7095 |
self:SetInfo(info); |
213 |
|
Thurallor-7095 |
self:ShortcutChanged(info.type, info.Data); |
214 |
|
Thurallor-7095 |
end |
215 |
13 |
Thurallor-7095 |
|
216 |
|
Thurallor-7095 |
-- Don't remove the item/skill from the location where it was dragged from. |
217 |
|
Thurallor-7095 |
args.DragDropInfo:SetSuccessful(false); |
218 |
|
Thurallor-7095 |
end |
219 |
|
Thurallor-7095 |
|
220 |
|
Thurallor-7095 |
function Slot:MouseEnter() |
221 |
|
Thurallor-7095 |
if ((self.actionEnabled) and (not self.highlight)) then |
222 |
|
Thurallor-7095 |
local highlight = Turbine.UI.Control(); |
223 |
|
Thurallor-7095 |
highlight:SetParent(self); |
224 |
|
Thurallor-7095 |
highlight:SetSize(32, 32); |
225 |
|
Thurallor-7095 |
highlight:SetPosition(3, 3); |
226 |
15 |
Thurallor-7095 |
highlight:SetZOrder(4); |
227 |
13 |
Thurallor-7095 |
highlight:SetBlendMode(Turbine.UI.BlendMode.Overlay); |
228 |
|
Thurallor-7095 |
highlight:SetBackground(resources.Icon.Highlight); |
229 |
|
Thurallor-7095 |
highlight:SetMouseVisible(false); |
230 |
|
Thurallor-7095 |
self.highlight = highlight; |
231 |
|
Thurallor-7095 |
end |
232 |
|
Thurallor-7095 |
end |
233 |
|
Thurallor-7095 |
|
234 |
|
Thurallor-7095 |
function Slot:MouseLeave() |
235 |
|
Thurallor-7095 |
if (self.highlight) then |
236 |
|
Thurallor-7095 |
self.highlight:SetParent(nil); |
237 |
|
Thurallor-7095 |
self.highlight = nil; |
238 |
|
Thurallor-7095 |
end |
239 |
|
Thurallor-7095 |
end |
240 |
|
Thurallor-7095 |
|
241 |
|
Thurallor-7095 |
function Slot:MouseDown(args) |
242 |
|
Thurallor-7095 |
if (args.Button == Turbine.UI.MouseButton.Left) then |
243 |
|
Thurallor-7095 |
-- Drag begin. Save the current position of the slot and mouse. |
244 |
|
Thurallor-7095 |
self.mouseDown = true; |
245 |
|
Thurallor-7095 |
self.mouseMoved = false; |
246 |
|
Thurallor-7095 |
self.originalLeft, self.originalTop = self:PointToScreen(0, 0); |
247 |
|
Thurallor-7095 |
self.originalMouseX, self.originalMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY(); |
248 |
|
Thurallor-7095 |
end |
249 |
|
Thurallor-7095 |
end |
250 |
|
Thurallor-7095 |
|
251 |
|
Thurallor-7095 |
function Slot:MouseMove() |
252 |
|
Thurallor-7095 |
if (not self.mouseDown) then |
253 |
|
Thurallor-7095 |
return; |
254 |
|
Thurallor-7095 |
end |
255 |
|
Thurallor-7095 |
|
256 |
|
Thurallor-7095 |
-- Detach from parent if we haven't already done so. |
257 |
|
Thurallor-7095 |
if (not self.mouseMoved) then |
258 |
|
Thurallor-7095 |
self.numLabel:SetText(nil); |
259 |
|
Thurallor-7095 |
self.parent = self:GetParent(); |
260 |
|
Thurallor-7095 |
self.tempContainer = Turbine.UI.Window(); |
261 |
|
Thurallor-7095 |
self.tempContainer:SetVisible(true); |
262 |
|
Thurallor-7095 |
self.tempContainer:SetSize(self:GetSize()); |
263 |
|
Thurallor-7095 |
self.tempContainer:SetZOrder(2147483647); |
264 |
|
Thurallor-7095 |
self.tempContainer:SetOpacity(0.75); |
265 |
|
Thurallor-7095 |
self:SetParent(self.tempContainer); |
266 |
|
Thurallor-7095 |
self:SetPosition(0, 0); |
267 |
|
Thurallor-7095 |
self.mouseMoved = true; |
268 |
|
Thurallor-7095 |
end |
269 |
|
Thurallor-7095 |
|
270 |
|
Thurallor-7095 |
-- Drag continuing. Find out how much the mouse has moved. |
271 |
|
Thurallor-7095 |
local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY(); |
272 |
|
Thurallor-7095 |
local deltaX, deltaY = newMouseX - self.originalMouseX, newMouseY - self.originalMouseY; |
273 |
|
Thurallor-7095 |
|
274 |
|
Thurallor-7095 |
-- Move the icon and overlay. |
275 |
|
Thurallor-7095 |
local left, top = self.originalLeft + deltaX, self.originalTop + deltaY; |
276 |
|
Thurallor-7095 |
self.tempContainer:SetPosition(left, top); |
277 |
|
Thurallor-7095 |
|
278 |
|
Thurallor-7095 |
-- Show a red "X" if invalid drag location is selected. |
279 |
|
Thurallor-7095 |
local centerX, centerY = left + 16, top + 16; |
280 |
|
Thurallor-7095 |
if (self:DropPositionValid(centerX, centerY)) then |
281 |
|
Thurallor-7095 |
self.numLabel:SetBackground(nil); |
282 |
|
Thurallor-7095 |
else |
283 |
|
Thurallor-7095 |
self.numLabel:SetBackground(resources.Icon.DragFail); |
284 |
|
Thurallor-7095 |
end |
285 |
|
Thurallor-7095 |
end |
286 |
|
Thurallor-7095 |
|
287 |
|
Thurallor-7095 |
function Slot:MouseUp(args) |
288 |
|
Thurallor-7095 |
if (args.Button ~= Turbine.UI.MouseButton.Left) then |
289 |
|
Thurallor-7095 |
return; |
290 |
|
Thurallor-7095 |
end |
291 |
|
Thurallor-7095 |
self.mouseDown = false; |
292 |
|
Thurallor-7095 |
if (not self.mouseMoved) then |
293 |
|
Thurallor-7095 |
return; |
294 |
|
Thurallor-7095 |
end |
295 |
|
Thurallor-7095 |
|
296 |
|
Thurallor-7095 |
-- Reattach to parent. |
297 |
|
Thurallor-7095 |
local left, top = self.tempContainer:GetPosition(); |
298 |
|
Thurallor-7095 |
self:SetParent(self.parent); |
299 |
|
Thurallor-7095 |
self.tempContainer:Close(); |
300 |
|
Thurallor-7095 |
self.tempContainer = nil; |
301 |
|
Thurallor-7095 |
self.numLabel:SetBackground(nil); |
302 |
|
Thurallor-7095 |
self.numLabel:SetText(self.slotNumber); |
303 |
|
Thurallor-7095 |
|
304 |
|
Thurallor-7095 |
local centerX, centerY = left + 16, top + 16; |
305 |
|
Thurallor-7095 |
self:DragDropComplete(centerX, centerY); |
306 |
|
Thurallor-7095 |
end |
307 |
|
Thurallor-7095 |
|
308 |
|
Thurallor-7095 |
-- Event handlers that should be overridden |
309 |
|
Thurallor-7095 |
function Slot:ShortcutChanged(shortcutType, shortcutData) |
310 |
16 |
Thurallor-7095 |
-- Puts("ShortcutChanged(" .. Serialize(shortcutType) .. ", " .. Serialize(shortcutData) .. ")"); |
311 |
13 |
Thurallor-7095 |
end |
312 |
|
Thurallor-7095 |
|
313 |
|
Thurallor-7095 |
function Slot:MouseClick(args) |
314 |
16 |
Thurallor-7095 |
-- Puts("MouseClick(" .. Serialize(args) .. ")"); |
315 |
13 |
Thurallor-7095 |
end |
316 |
|
Thurallor-7095 |
|
317 |
|
Thurallor-7095 |
function Slot:DropPositionValid(left, top) |
318 |
16 |
Thurallor-7095 |
-- Puts("DropPositionValid(" .. tostring(left) .. ", " .. tostring(top) .. ")"); |
319 |
13 |
Thurallor-7095 |
return true; |
320 |
|
Thurallor-7095 |
end |
321 |
|
Thurallor-7095 |
|
322 |
|
Thurallor-7095 |
function Slot:DragDropComplete(left, top) |
323 |
16 |
Thurallor-7095 |
-- Puts("DragDropComplete(" .. tostring(left) .. ", " .. tostring(top) .. ")"); |
324 |
13 |
Thurallor-7095 |
return true; |
325 |
|
Thurallor-7095 |
end |