Slot = class(Turbine.UI.Control);
function Slot:Constructor(info)
Turbine.UI.Control.Constructor(self);
self:SetMouseVisible(false);
self:SetSize(36, 36);
self:SetInfo(info);
end
function Slot:GetInfo()
return self.info;
end
function Slot:GetNumLabel()
return self.slotNumber;
end
function Slot:IsQuickslot()
return self.isQuickslot;
end
function Slot:SetActionEnabled(enabled)
self.actionEnabled = enabled;
self.object:SetMouseVisible(enabled);
if (self.numLabel) then
self.numLabel:SetMouseVisible(not enabled);
end
end
function Slot:SetAllowDrop(allowDrop)
if (self.numLabel) then
self.numLabel:SetAllowDrop(allowDrop);
else
self.object:SetAllowDrop(allowDrop);
end
end
function Slot:SetDraggable(draggable)
if (draggable) then
self.numLabel.MouseDown = function(sender, args)
self:MouseDown(args);
end
self.numLabel.MouseUp = function(sender, args)
self:MouseUp(args);
end
self.numLabel.MouseMove = function()
self:MouseMove();
end
elseif (self.numLabel) then
self.numLabel.MouseDown = nil;
self.numLabel.MouseUp = nil;
self.numLabel.MouseMove = nil;
end
end
function Slot:SetInfo(info)
-- Discard old object, if it's a different type
if (self.object and (self.info.class ~= info.class)) then
self.object:SetParent(nil);
self.object = nil;
end
self.info = {};
DeepTableCopy(info, self.info);
-- For backward compatibility:
self.eventName = info.eventName;
self.bagSlot = info.bagSlot;
-- Create the quickslot object or command icon
if ((not info.class) or (info.class == "Turbine.UI.Lotro.Quickslot")) then
if (not self.object) then
local object = Turbine.UI.Lotro.Quickslot();
object:SetParent(self);
object:SetZOrder(self:GetZOrder() + 1);
object:SetUseOnRightClick(false);
object.MouseClick = function(sender, args)
self:MouseClick(args);
end
self.object = object;
end
self.object:SetShortcut(Turbine.UI.Lotro.Shortcut(info.type, info.Data));
self.isQuickslot = true;
elseif (info.class == "Turbine.UI.Control") then
if (not self.object) then
local object = Turbine.UI.Control();
object:SetParent(self);
object:SetSize(32, 32);
object:SetPosition(3, 3);
object:SetZOrder(self:GetZOrder() + 1);
object.MouseClick = function(sender, args)
self:MouseClick(args);
end
object.MouseEnter = function(sender)
self:MouseEnter();
end
object.MouseLeave = function(sender)
self:MouseLeave();
end
self.object = object;
end
self.isQuickslot = false;
end
-- Draw text overlay (if any)
if ((info.textOverlay) or (info.background)) then
if (not self.textOverlay) then
local textOverlay = Turbine.UI.Label();
textOverlay:SetParent(self);
textOverlay:SetZOrder(self:GetZOrder() + 2);
textOverlay:SetSize(32, 32);
textOverlay:SetPosition(3, 3);
textOverlay:SetMouseVisible(false);
textOverlay:SetFont(Turbine.UI.Lotro.Font.Verdana10);
textOverlay:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
textOverlay:SetFontStyle(Turbine.UI.FontStyle.Outline);
textOverlay:SetOutlineColor(Turbine.UI.Color(1, 0, 0, 0));
textOverlay:SetMultiline(true);
textOverlay:SetMarkupEnabled(true);
self.textOverlay = textOverlay;
end
self.textOverlay:SetBackground(info.background);
self.textOverlay:SetText(info.textOverlay);
self:SetRoundedCorners(self.roundedCorners);
elseif (self.textOverlay) then
self.textOverlay:SetParent(nil);
self.textOverlay = nil;
end
end
function Slot:SetRoundedCorners(rounded)
self.roundedCorners = rounded;
if (self.textOverlay) then
if (rounded) then
self.textOverlay:SetBlendMode(nil);
else
self.textOverlay:SetBlendMode(Turbine.UI.BlendMode.Overlay);
end
end
end
function Slot:SetNumLabel(slotNumber)
if (not self.numLabel) then
local numLabel = Turbine.UI.Label();
numLabel:SetParent(self);
numLabel:SetFont(Turbine.UI.Lotro.Font.TrajanPro15);
numLabel:SetFontStyle(Turbine.UI.FontStyle.Outline);
numLabel:SetOutlineColor(Turbine.UI.Color(1, 0, 0, 0));
numLabel:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
numLabel:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
numLabel:SetSize(32, 32);
numLabel:SetPosition(3, 3);
numLabel:SetZOrder(self:GetZOrder() + 3);
numLabel.DragDrop = function(sender, args)
self:DragDrop(args);
end
numLabel.MouseClick = function(sender, args)
self:MouseClick(args);
end
self.numLabel = numLabel;
end
self.numLabel:SetText(slotNumber);
self.slotNumber = slotNumber;
end
function Slot:SetSelected(selected)
if (not selected) then
if (self.marquee) then
self.marquee:SetParent(nil);
self.marquee = nil;
end
return;
end
if (not self.marquee) then
local marquee = Thurallor.UI.Marquee();
marquee:SetParent(self);
marquee:SetPosition(2, 2);
marquee:SetSize(34, 34);
marquee:SetMouseVisible(false);
self.marquee = marquee;
end
end
function Slot:DragDrop(args)
local info = {};
info.class = "Turbine.UI.Lotro.Quickslot";
info.type = args.DragDropInfo:GetShortcut():GetType();
info.Data = args.DragDropInfo:GetShortcut():GetData();
self:SetInfo(info);
self:ShortcutChanged(info.type, info.Data);
-- Don't remove the item/skill from the location where it was dragged from.
args.DragDropInfo:SetSuccessful(false);
end
function Slot:MouseEnter()
if ((self.actionEnabled) and (not self.highlight)) then
local highlight = Turbine.UI.Control();
highlight:SetParent(self);
highlight:SetSize(32, 32);
highlight:SetPosition(3, 3);
highlight:SetZOrder(self:GetZOrder() + 4);
highlight:SetBlendMode(Turbine.UI.BlendMode.Overlay);
highlight:SetBackground(resources.Icon.Highlight);
highlight:SetMouseVisible(false);
self.highlight = highlight;
end
end
function Slot:MouseLeave()
if (self.highlight) then
self.highlight:SetParent(nil);
self.highlight = nil;
end
end
function Slot:MouseDown(args)
-- Puts("MouseDown()");
if (args.Button == Turbine.UI.MouseButton.Left) then
-- Drag begin. Save the current position of the slot and mouse.
self.mouseDown = true;
self.mouseMoved = false;
self.originalLeft, self.originalTop = self:PointToScreen(0, 0);
self.originalMouseX, self.originalMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
end
end
function Slot:MouseMove()
if (not self.mouseDown) then
return;
end
-- Detach from parent if we haven't already done so.
if (not self.mouseMoved) then
self.numLabel:SetText(nil);
self.parent = self:GetParent();
self.tempContainer = Turbine.UI.Window();
self.tempContainer:SetVisible(true);
self.tempContainer:SetSize(self:GetSize());
self.tempContainer:SetZOrder(2147483647);
self.tempContainer:SetOpacity(0.75);
self:SetParent(self.tempContainer);
self:SetPosition(0, 0);
self.mouseMoved = true;
end
-- Drag continuing. Find out how much the mouse has moved.
local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
local deltaX, deltaY = newMouseX - self.originalMouseX, newMouseY - self.originalMouseY;
-- Move the icon and overlay.
local left, top = self.originalLeft + deltaX, self.originalTop + deltaY;
self.tempContainer:SetPosition(left, top);
-- Show a red "X" if invalid drag location is selected.
local centerX, centerY = left + 16, top + 16;
if (self:DropPositionValid(centerX, centerY)) then
self.numLabel:SetBackground(nil);
else
self.numLabel:SetBackground(resources.Icon.DragFail);
end
end
function Slot:MouseUp(args)
-- Puts("MouseUp()");
if (args.Button ~= Turbine.UI.MouseButton.Left) then
return;
end
self.mouseDown = false;
if (not self.mouseMoved) then
return;
end
-- Reattach to parent.
local left, top = self.tempContainer:GetPosition();
self:SetParent(self.parent);
self.tempContainer:Close();
self.tempContainer = nil;
self.numLabel:SetBackground(nil);
self.numLabel:SetText(self.slotNumber);
local centerX, centerY = left + 16, top + 16;
self:DragDropComplete(centerX, centerY);
end
-- Event handlers that should be overridden
function Slot:ShortcutChanged(shortcutType, shortcutData)
Puts("ShortcutChanged(" .. Serialize(shortcutType) .. ", " .. Serialize(shortcutData) .. ")");
end
function Slot:MouseClick(args)
Puts("MouseClick(" .. Serialize(args) .. ")");
end
function Slot:DropPositionValid(left, top)
Puts("DropPositionValid(" .. tostring(left) .. ", " .. tostring(top) .. ")");
return true;
end
function Slot:DragDropComplete(left, top)
Puts("DragDropComplete(" .. tostring(left) .. ", " .. tostring(top) .. ")");
return true;
end