1 |
13 |
Thurallor-7095 |
Slot = class(Turbine.UI.Control); |
2 |
|
Thurallor-7095 |
|
3 |
117 |
Thurallor-7095 |
function Slot:Constructor(info, wantsMouseWheelEvents) |
4 |
13 |
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 |
117 |
Thurallor-7095 |
self.wantsMouseWheelEvents = wantsMouseWheelEvents; |
11 |
13 |
Thurallor-7095 |
end |
12 |
|
Thurallor-7095 |
|
13 |
|
Thurallor-7095 |
function Slot:GetInfo() |
14 |
|
Thurallor-7095 |
return self.info; |
15 |
|
Thurallor-7095 |
end |
16 |
|
Thurallor-7095 |
|
17 |
20 |
Thurallor-7095 |
function Slot:GetItem() |
18 |
|
Thurallor-7095 |
if (self.object.GetItem) then |
19 |
|
Thurallor-7095 |
return self.object:GetItem(); |
20 |
|
Thurallor-7095 |
end |
21 |
|
Thurallor-7095 |
end |
22 |
|
Thurallor-7095 |
|
23 |
13 |
Thurallor-7095 |
function Slot:GetNumLabel() |
24 |
|
Thurallor-7095 |
return self.slotNumber; |
25 |
|
Thurallor-7095 |
end |
26 |
|
Thurallor-7095 |
|
27 |
|
Thurallor-7095 |
function Slot:IsQuickslot() |
28 |
|
Thurallor-7095 |
return self.isQuickslot; |
29 |
|
Thurallor-7095 |
end |
30 |
|
Thurallor-7095 |
|
31 |
|
Thurallor-7095 |
function Slot:SetActionEnabled(enabled) |
32 |
|
Thurallor-7095 |
self.actionEnabled = enabled; |
33 |
21 |
Thurallor-7095 |
if (self.object) then |
34 |
|
Thurallor-7095 |
self.object:SetMouseVisible(enabled); |
35 |
|
Thurallor-7095 |
end |
36 |
13 |
Thurallor-7095 |
if (self.numLabel) then |
37 |
|
Thurallor-7095 |
self.numLabel:SetMouseVisible(not enabled); |
38 |
|
Thurallor-7095 |
end |
39 |
|
Thurallor-7095 |
end |
40 |
|
Thurallor-7095 |
|
41 |
|
Thurallor-7095 |
function Slot:SetAllowDrop(allowDrop) |
42 |
|
Thurallor-7095 |
if (self.numLabel) then |
43 |
|
Thurallor-7095 |
self.numLabel:SetAllowDrop(allowDrop); |
44 |
21 |
Thurallor-7095 |
elseif (self.object) then |
45 |
13 |
Thurallor-7095 |
self.object:SetAllowDrop(allowDrop); |
46 |
|
Thurallor-7095 |
end |
47 |
|
Thurallor-7095 |
end |
48 |
|
Thurallor-7095 |
|
49 |
|
Thurallor-7095 |
function Slot:SetDraggable(draggable) |
50 |
|
Thurallor-7095 |
if (draggable) then |
51 |
|
Thurallor-7095 |
self.numLabel.MouseDown = function(sender, args) |
52 |
|
Thurallor-7095 |
self:MouseDown(args); |
53 |
|
Thurallor-7095 |
end |
54 |
|
Thurallor-7095 |
self.numLabel.MouseUp = function(sender, args) |
55 |
|
Thurallor-7095 |
self:MouseUp(args); |
56 |
|
Thurallor-7095 |
end |
57 |
|
Thurallor-7095 |
self.numLabel.MouseMove = function() |
58 |
|
Thurallor-7095 |
self:MouseMove(); |
59 |
|
Thurallor-7095 |
end |
60 |
|
Thurallor-7095 |
elseif (self.numLabel) then |
61 |
|
Thurallor-7095 |
self.numLabel.MouseDown = nil; |
62 |
|
Thurallor-7095 |
self.numLabel.MouseUp = nil; |
63 |
|
Thurallor-7095 |
self.numLabel.MouseMove = nil; |
64 |
|
Thurallor-7095 |
end |
65 |
|
Thurallor-7095 |
end |
66 |
|
Thurallor-7095 |
|
67 |
|
Thurallor-7095 |
function Slot:SetInfo(info) |
68 |
|
Thurallor-7095 |
|
69 |
|
Thurallor-7095 |
-- Discard old object, if it's a different type |
70 |
|
Thurallor-7095 |
if (self.object and (self.info.class ~= info.class)) then |
71 |
|
Thurallor-7095 |
self.object:SetParent(nil); |
72 |
|
Thurallor-7095 |
self.object = nil; |
73 |
|
Thurallor-7095 |
end |
74 |
|
Thurallor-7095 |
|
75 |
|
Thurallor-7095 |
self.info = {}; |
76 |
|
Thurallor-7095 |
DeepTableCopy(info, self.info); |
77 |
|
Thurallor-7095 |
|
78 |
21 |
Thurallor-7095 |
if (not self.parent) then |
79 |
|
Thurallor-7095 |
return; |
80 |
|
Thurallor-7095 |
end |
81 |
|
Thurallor-7095 |
|
82 |
13 |
Thurallor-7095 |
-- Create the quickslot object or command icon |
83 |
|
Thurallor-7095 |
if ((not info.class) or (info.class == "Turbine.UI.Lotro.Quickslot")) then |
84 |
|
Thurallor-7095 |
if (not self.object) then |
85 |
|
Thurallor-7095 |
local object = Turbine.UI.Lotro.Quickslot(); |
86 |
|
Thurallor-7095 |
object:SetParent(self); |
87 |
15 |
Thurallor-7095 |
object:SetZOrder(1); |
88 |
13 |
Thurallor-7095 |
object:SetUseOnRightClick(false); |
89 |
116 |
Thurallor-7095 |
self.object = object; |
90 |
|
Thurallor-7095 |
|
91 |
|
Thurallor-7095 |
-- Forward events to parent object |
92 |
13 |
Thurallor-7095 |
object.MouseClick = function(sender, args) |
93 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseClick", args); |
94 |
13 |
Thurallor-7095 |
end |
95 |
116 |
Thurallor-7095 |
object.MouseWheel = function(sender, args) |
96 |
|
Thurallor-7095 |
DoCallbacks(self, "MouseWheel", args); |
97 |
|
Thurallor-7095 |
end |
98 |
13 |
Thurallor-7095 |
end |
99 |
|
Thurallor-7095 |
self.object:SetShortcut(Turbine.UI.Lotro.Shortcut(info.type, info.Data)); |
100 |
|
Thurallor-7095 |
self.isQuickslot = true; |
101 |
15 |
Thurallor-7095 |
self.object.DragDrop = function(sender) |
102 |
|
Thurallor-7095 |
sender:SetShortcut(Turbine.UI.Lotro.Shortcut(self.info.type, self.info.Data)); |
103 |
|
Thurallor-7095 |
end |
104 |
135 |
Thurallor-7095 |
elseif ((info.class == "Turbine.UI.Control") or (info.class == "Turbine.UI.Lotro.EntityControl")) then |
105 |
13 |
Thurallor-7095 |
if (not self.object) then |
106 |
117 |
Thurallor-7095 |
|
107 |
|
Thurallor-7095 |
local object; |
108 |
136 |
Thurallor-7095 |
if (info.type == "SelectTarget") then |
109 |
135 |
Thurallor-7095 |
object = Turbine.UI.Lotro.EntityControl(); |
110 |
|
Thurallor-7095 |
object:SetSelectionEnabled(true); |
111 |
|
Thurallor-7095 |
object:SetContextMenuEnabled(false); |
112 |
|
Thurallor-7095 |
self.watcher = Thurallor.Utils.Watcher; |
113 |
|
Thurallor-7095 |
self.player = Turbine.Gameplay.LocalPlayer:GetInstance(); |
114 |
|
Thurallor-7095 |
self.getTargetFunc = loadstring(info.getTargetFunc); |
115 |
117 |
Thurallor-7095 |
else |
116 |
135 |
Thurallor-7095 |
-- MouseWheel events aren't implemented for Controls, only ListBoxes. |
117 |
|
Thurallor-7095 |
-- But I think they probably use more resources than Controls, so I'll |
118 |
|
Thurallor-7095 |
-- only use ListBoxes if the mouse wheel option is enabled. |
119 |
|
Thurallor-7095 |
if (self.wantsMouseWheelEvents) then |
120 |
|
Thurallor-7095 |
object = Turbine.UI.ListBox(); |
121 |
|
Thurallor-7095 |
else |
122 |
|
Thurallor-7095 |
object = Turbine.UI.Control(); |
123 |
|
Thurallor-7095 |
end |
124 |
117 |
Thurallor-7095 |
end |
125 |
|
Thurallor-7095 |
|
126 |
13 |
Thurallor-7095 |
object:SetParent(self); |
127 |
|
Thurallor-7095 |
object:SetSize(32, 32); |
128 |
|
Thurallor-7095 |
object:SetPosition(3, 3); |
129 |
15 |
Thurallor-7095 |
object:SetZOrder(1); |
130 |
116 |
Thurallor-7095 |
self.object = object; |
131 |
|
Thurallor-7095 |
|
132 |
|
Thurallor-7095 |
-- Forward events to parent object |
133 |
13 |
Thurallor-7095 |
object.MouseClick = function(sender, args) |
134 |
136 |
Thurallor-7095 |
if (info.type == "SelectTarget") then |
135 |
135 |
Thurallor-7095 |
-- Update the round-robin "cursor" to the next member, regardless |
136 |
|
Thurallor-7095 |
-- of whether the member was successfully selected; clicking on the |
137 |
|
Thurallor-7095 |
-- slot is enough to know the user's intent. |
138 |
|
Thurallor-7095 |
self.watcher.GetNextPartyMember(self.entity); |
139 |
|
Thurallor-7095 |
end |
140 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseClick", args); |
141 |
13 |
Thurallor-7095 |
end |
142 |
121 |
Thurallor-7095 |
object.MouseEnter = function() |
143 |
136 |
Thurallor-7095 |
if (info.type == "SelectTarget") then |
144 |
|
Thurallor-7095 |
self:UpdateEntity(); |
145 |
|
Thurallor-7095 |
self:SetWantsUpdates(true); |
146 |
135 |
Thurallor-7095 |
end |
147 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseEnter"); |
148 |
13 |
Thurallor-7095 |
end |
149 |
121 |
Thurallor-7095 |
object.MouseLeave = function() |
150 |
136 |
Thurallor-7095 |
if (info.type == "SelectTarget") then |
151 |
|
Thurallor-7095 |
self.textOverlay:SetBackground(resources.Icon.SelectTarget); |
152 |
|
Thurallor-7095 |
self.object:SetEntity(nil); |
153 |
|
Thurallor-7095 |
self.entity = nil; |
154 |
|
Thurallor-7095 |
self:SetWantsUpdates(false); |
155 |
|
Thurallor-7095 |
end |
156 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseLeave"); |
157 |
13 |
Thurallor-7095 |
end |
158 |
116 |
Thurallor-7095 |
object.MouseWheel = function(sender, args) |
159 |
|
Thurallor-7095 |
DoCallbacks(self, "MouseWheel", args); |
160 |
|
Thurallor-7095 |
end |
161 |
13 |
Thurallor-7095 |
end |
162 |
|
Thurallor-7095 |
self.isQuickslot = false; |
163 |
|
Thurallor-7095 |
end |
164 |
15 |
Thurallor-7095 |
|
165 |
34 |
Thurallor-7095 |
-- Draw text overlay and icon overlay (if any) |
166 |
|
Thurallor-7095 |
if (not self.textOverlay) then |
167 |
|
Thurallor-7095 |
local textOverlay = Turbine.UI.Label(); |
168 |
|
Thurallor-7095 |
textOverlay:SetParent(self); |
169 |
|
Thurallor-7095 |
textOverlay:SetZOrder(2); |
170 |
|
Thurallor-7095 |
textOverlay:SetSize(32, 32); |
171 |
|
Thurallor-7095 |
textOverlay:SetPosition(3, 3); |
172 |
|
Thurallor-7095 |
textOverlay:SetMouseVisible(false); |
173 |
|
Thurallor-7095 |
textOverlay:SetFont(Turbine.UI.Lotro.Font.Verdana10); |
174 |
|
Thurallor-7095 |
textOverlay:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter); |
175 |
|
Thurallor-7095 |
textOverlay:SetFontStyle(Turbine.UI.FontStyle.Outline); |
176 |
|
Thurallor-7095 |
textOverlay:SetOutlineColor(Turbine.UI.Color(1, 0, 0, 0)); |
177 |
|
Thurallor-7095 |
textOverlay:SetMultiline(true); |
178 |
|
Thurallor-7095 |
textOverlay:SetMarkupEnabled(true); |
179 |
|
Thurallor-7095 |
textOverlay:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend); |
180 |
|
Thurallor-7095 |
self.textOverlay = textOverlay; |
181 |
13 |
Thurallor-7095 |
end |
182 |
34 |
Thurallor-7095 |
self.background = info.background; |
183 |
|
Thurallor-7095 |
if (info.altIcon) then |
184 |
|
Thurallor-7095 |
self.background = info.altIcon; |
185 |
|
Thurallor-7095 |
end |
186 |
|
Thurallor-7095 |
self.textOverlay:SetBackground(self.background); |
187 |
|
Thurallor-7095 |
self.textOverlay:SetText(info.textOverlay); |
188 |
13 |
Thurallor-7095 |
end |
189 |
|
Thurallor-7095 |
|
190 |
136 |
Thurallor-7095 |
-- For "Select Target" slots only: |
191 |
|
Thurallor-7095 |
function Slot:UpdateEntity() |
192 |
|
Thurallor-7095 |
local entity = self.getTargetFunc(self.watcher, self.player, info.raidMemberName); |
193 |
|
Thurallor-7095 |
if (entity ~= self.entity) then |
194 |
|
Thurallor-7095 |
self.object:SetEntity(entity); |
195 |
|
Thurallor-7095 |
self.entity = entity; |
196 |
|
Thurallor-7095 |
end |
197 |
|
Thurallor-7095 |
if (entity) then |
198 |
|
Thurallor-7095 |
self.textOverlay:SetBackground(resources.Icon.SelectTargetKnown); |
199 |
|
Thurallor-7095 |
else |
200 |
|
Thurallor-7095 |
self.textOverlay:SetBackground(resources.Icon.SelectTargetUnknown); |
201 |
|
Thurallor-7095 |
end |
202 |
|
Thurallor-7095 |
end |
203 |
|
Thurallor-7095 |
|
204 |
13 |
Thurallor-7095 |
function Slot:SetNumLabel(slotNumber) |
205 |
|
Thurallor-7095 |
if (not self.numLabel) then |
206 |
|
Thurallor-7095 |
local numLabel = Turbine.UI.Label(); |
207 |
|
Thurallor-7095 |
numLabel:SetParent(self); |
208 |
|
Thurallor-7095 |
numLabel:SetFont(Turbine.UI.Lotro.Font.TrajanPro15); |
209 |
|
Thurallor-7095 |
numLabel:SetFontStyle(Turbine.UI.FontStyle.Outline); |
210 |
|
Thurallor-7095 |
numLabel:SetOutlineColor(Turbine.UI.Color(1, 0, 0, 0)); |
211 |
|
Thurallor-7095 |
numLabel:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter); |
212 |
|
Thurallor-7095 |
numLabel:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend); |
213 |
15 |
Thurallor-7095 |
numLabel:SetSize(38, 38); |
214 |
|
Thurallor-7095 |
numLabel:SetZOrder(3); |
215 |
13 |
Thurallor-7095 |
numLabel.DragDrop = function(sender, args) |
216 |
20 |
Thurallor-7095 |
DoCallbacks(self, "DragDrop", args); |
217 |
13 |
Thurallor-7095 |
end |
218 |
|
Thurallor-7095 |
numLabel.MouseClick = function(sender, args) |
219 |
20 |
Thurallor-7095 |
DoCallbacks(self, "MouseClick", args); |
220 |
13 |
Thurallor-7095 |
end |
221 |
|
Thurallor-7095 |
self.numLabel = numLabel; |
222 |
|
Thurallor-7095 |
end |
223 |
|
Thurallor-7095 |
self.numLabel:SetText(slotNumber); |
224 |
|
Thurallor-7095 |
self.slotNumber = slotNumber; |
225 |
|
Thurallor-7095 |
end |
226 |
|
Thurallor-7095 |
|
227 |
34 |
Thurallor-7095 |
function Slot:StartCooldown(period) |
228 |
|
Thurallor-7095 |
if (period <= 0) then |
229 |
|
Thurallor-7095 |
period = 0.001; |
230 |
|
Thurallor-7095 |
end |
231 |
|
Thurallor-7095 |
self.coolDown = period; |
232 |
|
Thurallor-7095 |
self.resetTime = Turbine.Engine.GetGameTime() + period; |
233 |
43 |
Thurallor-7095 |
if (self.textOverlay) then |
234 |
|
Thurallor-7095 |
self.textOverlay:SetBackground(resources.Icon.Delay); |
235 |
|
Thurallor-7095 |
self.textOverlay:SetText(nil); |
236 |
|
Thurallor-7095 |
end |
237 |
34 |
Thurallor-7095 |
self:ShowTimeRemaining(); |
238 |
|
Thurallor-7095 |
self:SetWantsUpdates(true); |
239 |
|
Thurallor-7095 |
end |
240 |
|
Thurallor-7095 |
|
241 |
|
Thurallor-7095 |
function Slot:Update() |
242 |
136 |
Thurallor-7095 |
if (self.info.type == "SelectTarget") then |
243 |
|
Thurallor-7095 |
self:UpdateEntity(); |
244 |
|
Thurallor-7095 |
else |
245 |
|
Thurallor-7095 |
self:ShowTimeRemaining(); |
246 |
|
Thurallor-7095 |
end |
247 |
34 |
Thurallor-7095 |
end |
248 |
|
Thurallor-7095 |
|
249 |
|
Thurallor-7095 |
-- Reuse the numLabel layer for cooldown overlay. |
250 |
|
Thurallor-7095 |
function Slot:ShowTimeRemaining() |
251 |
|
Thurallor-7095 |
local currentTime = Turbine.Engine.GetGameTime(); |
252 |
|
Thurallor-7095 |
if (currentTime >= self.resetTime) then |
253 |
|
Thurallor-7095 |
self.numLabel:SetParent(nil); |
254 |
|
Thurallor-7095 |
self.numLabel = nil; |
255 |
|
Thurallor-7095 |
self.resetTime = nil; |
256 |
|
Thurallor-7095 |
self:SetWantsUpdates(false); |
257 |
43 |
Thurallor-7095 |
if (self.textOverlay) then |
258 |
|
Thurallor-7095 |
self.textOverlay:SetBackground(self.background); |
259 |
|
Thurallor-7095 |
self.textOverlay:SetText(self.info.textOverlay); |
260 |
|
Thurallor-7095 |
end |
261 |
34 |
Thurallor-7095 |
self.hidden = self.hiddenAfterReset; |
262 |
|
Thurallor-7095 |
DoCallbacks(self, "Reset"); |
263 |
|
Thurallor-7095 |
else |
264 |
|
Thurallor-7095 |
self:SetNumLabel(""); |
265 |
|
Thurallor-7095 |
self.numLabel.MouseClick = nil; |
266 |
|
Thurallor-7095 |
self.numLabel:SetPosition(3, 3); |
267 |
|
Thurallor-7095 |
self.numLabel:SetSize(32, 32); |
268 |
|
Thurallor-7095 |
local steps = resources.Icon.CoolDownEnd - resources.Icon.CoolDownStart + 1; |
269 |
|
Thurallor-7095 |
local progress = 1 - (self.resetTime - currentTime) / self.coolDown; |
270 |
|
Thurallor-7095 |
self.numLabel:SetBackground(resources.Icon.CoolDownStart + math.floor(progress * steps)); |
271 |
|
Thurallor-7095 |
end |
272 |
|
Thurallor-7095 |
end |
273 |
|
Thurallor-7095 |
|
274 |
16 |
Thurallor-7095 |
function Slot:SetSelected(selected, color) |
275 |
13 |
Thurallor-7095 |
if (not selected) then |
276 |
|
Thurallor-7095 |
if (self.marquee) then |
277 |
|
Thurallor-7095 |
self.marquee:SetParent(nil); |
278 |
|
Thurallor-7095 |
self.marquee = nil; |
279 |
|
Thurallor-7095 |
end |
280 |
|
Thurallor-7095 |
return; |
281 |
|
Thurallor-7095 |
end |
282 |
|
Thurallor-7095 |
|
283 |
16 |
Thurallor-7095 |
if (not color) then |
284 |
|
Thurallor-7095 |
color = Turbine.UI.Color.White; |
285 |
|
Thurallor-7095 |
end |
286 |
|
Thurallor-7095 |
|
287 |
13 |
Thurallor-7095 |
if (not self.marquee) then |
288 |
|
Thurallor-7095 |
local marquee = Thurallor.UI.Marquee(); |
289 |
|
Thurallor-7095 |
marquee:SetParent(self); |
290 |
|
Thurallor-7095 |
marquee:SetPosition(2, 2); |
291 |
|
Thurallor-7095 |
marquee:SetSize(34, 34); |
292 |
|
Thurallor-7095 |
marquee:SetMouseVisible(false); |
293 |
|
Thurallor-7095 |
self.marquee = marquee; |
294 |
|
Thurallor-7095 |
end |
295 |
16 |
Thurallor-7095 |
|
296 |
|
Thurallor-7095 |
self.marquee:SetColor(color); |
297 |
13 |
Thurallor-7095 |
end |
298 |
|
Thurallor-7095 |
|
299 |
21 |
Thurallor-7095 |
function Slot:SetParent(parent) |
300 |
|
Thurallor-7095 |
self.parent = parent; |
301 |
|
Thurallor-7095 |
if (parent) then |
302 |
|
Thurallor-7095 |
self:SetInfo(self.info); |
303 |
|
Thurallor-7095 |
elseif (self.object) then |
304 |
26 |
Thurallor-7095 |
self:MouseLeave(); |
305 |
21 |
Thurallor-7095 |
self.object:SetParent(nil); |
306 |
|
Thurallor-7095 |
self.object = nil; |
307 |
34 |
Thurallor-7095 |
self:SetWantsUpdates(false); |
308 |
21 |
Thurallor-7095 |
end |
309 |
|
Thurallor-7095 |
Turbine.UI.Control.SetParent(self, parent); |
310 |
|
Thurallor-7095 |
end |
311 |
|
Thurallor-7095 |
|
312 |
13 |
Thurallor-7095 |
function Slot:DragDrop(args) |
313 |
|
Thurallor-7095 |
local info = {}; |
314 |
|
Thurallor-7095 |
info.class = "Turbine.UI.Lotro.Quickslot"; |
315 |
15 |
Thurallor-7095 |
local newShortcut = args.DragDropInfo:GetShortcut(); |
316 |
|
Thurallor-7095 |
if (newShortcut) then |
317 |
|
Thurallor-7095 |
info.type = newShortcut:GetType(); |
318 |
|
Thurallor-7095 |
info.Data = newShortcut:GetData(); |
319 |
|
Thurallor-7095 |
self:SetInfo(info); |
320 |
132 |
Thurallor-7095 |
DoCallbacks(self, "ShortcutChanged", info.type, info.Data); |
321 |
15 |
Thurallor-7095 |
end |
322 |
13 |
Thurallor-7095 |
|
323 |
|
Thurallor-7095 |
-- Don't remove the item/skill from the location where it was dragged from. |
324 |
|
Thurallor-7095 |
args.DragDropInfo:SetSuccessful(false); |
325 |
|
Thurallor-7095 |
end |
326 |
|
Thurallor-7095 |
|
327 |
|
Thurallor-7095 |
function Slot:MouseEnter() |
328 |
|
Thurallor-7095 |
if ((self.actionEnabled) and (not self.highlight)) then |
329 |
|
Thurallor-7095 |
local highlight = Turbine.UI.Control(); |
330 |
|
Thurallor-7095 |
highlight:SetParent(self); |
331 |
|
Thurallor-7095 |
highlight:SetSize(32, 32); |
332 |
|
Thurallor-7095 |
highlight:SetPosition(3, 3); |
333 |
15 |
Thurallor-7095 |
highlight:SetZOrder(4); |
334 |
13 |
Thurallor-7095 |
highlight:SetBlendMode(Turbine.UI.BlendMode.Overlay); |
335 |
|
Thurallor-7095 |
highlight:SetBackground(resources.Icon.Highlight); |
336 |
|
Thurallor-7095 |
highlight:SetMouseVisible(false); |
337 |
|
Thurallor-7095 |
self.highlight = highlight; |
338 |
|
Thurallor-7095 |
end |
339 |
|
Thurallor-7095 |
end |
340 |
|
Thurallor-7095 |
|
341 |
|
Thurallor-7095 |
function Slot:MouseLeave() |
342 |
|
Thurallor-7095 |
if (self.highlight) then |
343 |
|
Thurallor-7095 |
self.highlight:SetParent(nil); |
344 |
|
Thurallor-7095 |
self.highlight = nil; |
345 |
|
Thurallor-7095 |
end |
346 |
|
Thurallor-7095 |
end |
347 |
|
Thurallor-7095 |
|
348 |
|
Thurallor-7095 |
function Slot:MouseDown(args) |
349 |
|
Thurallor-7095 |
if (args.Button == Turbine.UI.MouseButton.Left) then |
350 |
|
Thurallor-7095 |
-- Drag begin. Save the current position of the slot and mouse. |
351 |
|
Thurallor-7095 |
self.mouseDown = true; |
352 |
|
Thurallor-7095 |
self.mouseMoved = false; |
353 |
|
Thurallor-7095 |
self.originalLeft, self.originalTop = self:PointToScreen(0, 0); |
354 |
|
Thurallor-7095 |
self.originalMouseX, self.originalMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY(); |
355 |
|
Thurallor-7095 |
end |
356 |
|
Thurallor-7095 |
end |
357 |
|
Thurallor-7095 |
|
358 |
|
Thurallor-7095 |
function Slot:MouseMove() |
359 |
|
Thurallor-7095 |
if (not self.mouseDown) then |
360 |
|
Thurallor-7095 |
return; |
361 |
|
Thurallor-7095 |
end |
362 |
|
Thurallor-7095 |
|
363 |
|
Thurallor-7095 |
-- Detach from parent if we haven't already done so. |
364 |
|
Thurallor-7095 |
if (not self.mouseMoved) then |
365 |
|
Thurallor-7095 |
self.numLabel:SetText(nil); |
366 |
|
Thurallor-7095 |
self.parent = self:GetParent(); |
367 |
|
Thurallor-7095 |
self.tempContainer = Turbine.UI.Window(); |
368 |
|
Thurallor-7095 |
self.tempContainer:SetVisible(true); |
369 |
|
Thurallor-7095 |
self.tempContainer:SetSize(self:GetSize()); |
370 |
|
Thurallor-7095 |
self.tempContainer:SetZOrder(2147483647); |
371 |
|
Thurallor-7095 |
self.tempContainer:SetOpacity(0.75); |
372 |
|
Thurallor-7095 |
self:SetParent(self.tempContainer); |
373 |
|
Thurallor-7095 |
self:SetPosition(0, 0); |
374 |
|
Thurallor-7095 |
self.mouseMoved = true; |
375 |
|
Thurallor-7095 |
end |
376 |
|
Thurallor-7095 |
|
377 |
|
Thurallor-7095 |
-- Drag continuing. Find out how much the mouse has moved. |
378 |
|
Thurallor-7095 |
local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY(); |
379 |
|
Thurallor-7095 |
local deltaX, deltaY = newMouseX - self.originalMouseX, newMouseY - self.originalMouseY; |
380 |
|
Thurallor-7095 |
|
381 |
|
Thurallor-7095 |
-- Move the icon and overlay. |
382 |
|
Thurallor-7095 |
local left, top = self.originalLeft + deltaX, self.originalTop + deltaY; |
383 |
|
Thurallor-7095 |
self.tempContainer:SetPosition(left, top); |
384 |
|
Thurallor-7095 |
|
385 |
|
Thurallor-7095 |
-- Show a red "X" if invalid drag location is selected. |
386 |
|
Thurallor-7095 |
local centerX, centerY = left + 16, top + 16; |
387 |
|
Thurallor-7095 |
if (self:DropPositionValid(centerX, centerY)) then |
388 |
|
Thurallor-7095 |
self.numLabel:SetBackground(nil); |
389 |
|
Thurallor-7095 |
else |
390 |
|
Thurallor-7095 |
self.numLabel:SetBackground(resources.Icon.DragFail); |
391 |
|
Thurallor-7095 |
end |
392 |
|
Thurallor-7095 |
end |
393 |
|
Thurallor-7095 |
|
394 |
|
Thurallor-7095 |
function Slot:MouseUp(args) |
395 |
|
Thurallor-7095 |
if (args.Button ~= Turbine.UI.MouseButton.Left) then |
396 |
|
Thurallor-7095 |
return; |
397 |
|
Thurallor-7095 |
end |
398 |
|
Thurallor-7095 |
self.mouseDown = false; |
399 |
|
Thurallor-7095 |
if (not self.mouseMoved) then |
400 |
|
Thurallor-7095 |
return; |
401 |
|
Thurallor-7095 |
end |
402 |
|
Thurallor-7095 |
|
403 |
|
Thurallor-7095 |
-- Reattach to parent. |
404 |
|
Thurallor-7095 |
local left, top = self.tempContainer:GetPosition(); |
405 |
|
Thurallor-7095 |
self:SetParent(self.parent); |
406 |
|
Thurallor-7095 |
self.tempContainer:Close(); |
407 |
|
Thurallor-7095 |
self.tempContainer = nil; |
408 |
|
Thurallor-7095 |
self.numLabel:SetBackground(nil); |
409 |
|
Thurallor-7095 |
self.numLabel:SetText(self.slotNumber); |
410 |
|
Thurallor-7095 |
|
411 |
|
Thurallor-7095 |
local centerX, centerY = left + 16, top + 16; |
412 |
|
Thurallor-7095 |
self:DragDropComplete(centerX, centerY); |
413 |
|
Thurallor-7095 |
end |
414 |
|
Thurallor-7095 |
|
415 |
|
Thurallor-7095 |
-- Event handlers that should be overridden |
416 |
116 |
Thurallor-7095 |
-- |
417 |
|
Thurallor-7095 |
-- function Slot:ShortcutChanged(shortcutType, shortcutData) |
418 |
|
Thurallor-7095 |
-- Puts("ShortcutChanged(" .. Serialize(shortcutType) .. ", " .. Serialize(shortcutData) .. ")"); |
419 |
|
Thurallor-7095 |
-- end |
420 |
|
Thurallor-7095 |
-- |
421 |
|
Thurallor-7095 |
-- function Slot:MouseClick(args) |
422 |
|
Thurallor-7095 |
-- Puts("MouseClick(" .. Serialize(args) .. ")"); |
423 |
|
Thurallor-7095 |
-- end |
424 |
|
Thurallor-7095 |
-- |
425 |
|
Thurallor-7095 |
-- function Slot:MouseWheel(args) |
426 |
|
Thurallor-7095 |
-- Puts("MouseWheel(" .. Serialize(args) .. ")"); |
427 |
|
Thurallor-7095 |
-- end |
428 |
|
Thurallor-7095 |
-- |
429 |
|
Thurallor-7095 |
-- function Slot:DropPositionValid(left, top) |
430 |
|
Thurallor-7095 |
-- Puts("DropPositionValid(" .. tostring(left) .. ", " .. tostring(top) .. ")"); |
431 |
|
Thurallor-7095 |
-- return true; |
432 |
|
Thurallor-7095 |
-- end |
433 |
|
Thurallor-7095 |
-- |
434 |
|
Thurallor-7095 |
-- function Slot:DragDropComplete(left, top) |
435 |
|
Thurallor-7095 |
-- Puts("DragDropComplete(" .. tostring(left) .. ", " .. tostring(top) .. ")"); |
436 |
|
Thurallor-7095 |
-- return true; |
437 |
|
Thurallor-7095 |
-- end |