lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [Slot.lua] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

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

All times are GMT -5. The time now is 05:32 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui