NodeLabel = class(Turbine.UI.Label);
function NodeLabel:Constructor(node, object)
Turbine.UI.Label.Constructor(self);
self.node = node;
self.object = object;
self:SetFont(Turbine.UI.Lotro.Font.TrajanPro15);
self:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
self:SetFontStyle(Turbine.UI.FontStyle.Outline);
self:SetOutlineColor(Turbine.UI.Color.Black);
self:SetMultiline(false);
self:SetHeight(20);
self:UpdateText();
self.skipSizeChanged = 1;
end
function NodeLabel:UpdateText()
self:SetForeColor(self.object:GetColor());
self:SetText(self.object:GetName());
end
ShowHideButton = class(Turbine.UI.Lotro.Button);
function ShowHideButton:Constructor(node, object)
Turbine.UI.Lotro.Button.Constructor(self);
self.node = node;
self.object = object;
self:SetWidth(ShowHideButton.buttonWidth);
object.HiddenChanged = function()
self:UpdateText();
end
self:UpdateText();
end
function ShowHideButton:UpdateText()
local hidden = self.object.settings.hidden;
if (hidden) then
self:SetText(ShowHideButton.showText);
else
self:SetText(ShowHideButton.hideText);
end
self:SetVisible(not self.object:IsParentHidden());
end
function ShowHideButton:Click()
self.object:SetHidden(not self.object:IsHidden());
end
BarTreeControl = class(Thurallor.UI.TreeControl);
function BarTreeControl:Constructor(manager)
Thurallor.UI.TreeControl.Constructor(self);
self.manager = manager;
-- Localize; to re-localize, recreate the tree.
ShowHideButton.buttonWidth = L:GetNumber("/PluginManager/OptionsTab/DirectoryTab/ShowHideButtonWidth");
ShowHideButton.showText = L:GetText("/PluginManager/OptionsTab/DirectoryTab/Show");
ShowHideButton.hideText = L:GetText("/PluginManager/OptionsTab/DirectoryTab/Hide");
-- For drag-and-drop operations
self.carrierWindow = Turbine.UI.Window();
self.carrierWindow:SetZOrder(2147483647);
self.carrierWindow:SetOpacity(0.75);
self.carrierWindow:SetMouseVisible(false);
self:ConfigureNodeControl(self, nil, manager);
end
function BarTreeControl:Localize()
end
function BarTreeControl:ConfigureNodeControl(newNode, parentNode, object)
newNode.object = object;
-- Add a text box for the name of the group or bar.
newNode.label = NodeLabel(newNode, object);
newNode:AddColumn(newNode.label, 1);
-- Add the "Show" or "Hide" button.
newNode.showHideButton = ShowHideButton(newNode, object);
newNode:AddColumn(newNode.showHideButton, 0);
if (parentNode) then
parentNode:AddChild(newNode);
end
-- Add subnodes, if any, alphabetized
local childIDs = {};
if (object:CanHaveChildren()) then
childIDs = object:GetChildIDs();
table.sort(childIDs, function (a, b) return object:GetChild(a):GetName() < object:GetChild(b):GetName(); end);
for c = 1, #childIDs, 1 do
local childID = childIDs[c];
local child = object:GetChild(childID);
self:ConfigureNodeControl(Thurallor.UI.TreeControl(), newNode, child);
end
end
newNode:SetExpanded(not object.nodeCollapsed);
-- Add mouse behaviors
newNode.IconClicked = function()
object.nodeCollapsed = not newNode.expanded;
end
newNode.label.MouseClick = function(sender, args)
-- Right-click displays the settings menu.
if (args.Button == Turbine.UI.MouseButton.Right) then
sender.node.object:ShowSettingsMenu(true);
end
end
newNode.label.MouseDoubleClick = function(sender, args)
-- Left-double-click opens the caption editor.
if (args.Button == Turbine.UI.MouseButton.Left) then
sender.node.object:EditCaption(newNode.label);
end
end
newNode.label.MouseDown = function(sender, args)
if ((args.Button == Turbine.UI.MouseButton.Left) and (sender ~= self.label)) then
sender.mouseDown = true;
sender.originalLeft, sender.originalTop = sender.node:GetParent():PointToScreen(sender.node:GetPosition());
sender.originalMouseX, sender.originalMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
end
end
newNode.label.MouseMove = function(sender)
if (sender.mouseDown) then
-- Detach from tree
if (not sender.detached) then
sender.originalParentNode = sender.node:GetParentTreeControl();
sender.originalChildNumber = sender.originalParentNode:RemoveChild(sender.node);
self.carrierWindow:SetVisible(true);
self.carrierWindow:SetSize(sender.node:GetSize());
sender.node:SetParent(self.carrierWindow);
sender.node:SetPosition(0, 0);
self.carrierWindow:SetPosition(sender.originalLeft, sender.originalTop);
sender.node:SetColumnWidth(3, 0);
sender.detached = true;
end
local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
local deltaX, deltaY = newMouseX - sender.originalMouseX, newMouseY - sender.originalMouseY;
local left = sender.originalLeft + deltaX;
local top = sender.originalTop + deltaY;
self.carrierWindow:SetPosition(left, top);
if (sender.previousHighlight) then
sender.previousHighlight:SetBackColor(nil);
sender.previousHighlight = nil;
end
-- Figure out if we're over another textBox
local hoveringOverNode, target = self:IsMouseInside();
if (hoveringOverNode) then
local source = sender.node;
if (
(target.object:CanHaveChildren()) and
(target ~= source) and
(not source.object:Contains(target.object)) and
(source.object.parent ~= target.object)
) then
sender.targetObject = target.object;
--Puts("target object is " .. object.settings.type .. " " .. Serialize(object.settings.caption.text));
target.label:SetBackColor(Turbine.UI.Color(1, 0.25, 0.25, 0.75));
sender.previousHighlight = target.label;
return;
end
end
sender.targetObject = nil;
end
end
newNode.label.MouseUp = function(sender, args)
if (args.Button == Turbine.UI.MouseButton.Left) then
sender.mouseDown = false;
if (sender.detached) then
local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
local deltaX, deltaY = newMouseX - sender.originalMouseX, newMouseY - sender.originalMouseY;
-- Do the object transfer
sender.node:SetParent(nil);
if (sender.targetObject) then
local sourceObject = sender.node.object;
if (sourceObject.settings.type == "bar") then
self.manager:TransferBar(sourceObject.objectID, sourceObject.parent, sender.targetObject);
else
self.manager:TransferGroup(sourceObject.objectID, sourceObject.parent, sender.targetObject);
end
else
-- Reattach to tree
self.carrierWindow:SetVisible(false);
sender.node:SetColumnWidth(3, ShowHideButton.buttonWidth);
sender.originalParentNode:InsertChild(sender.node, sender.originalChildNumber);
sender.detached = false;
end
end
end
end
return newNode;
end