lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [DirectoryTab.lua] - Rev 171

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

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

DirectoryTab = class(Thurallor.UI.TabCard);

function DirectoryTab:Constructor(manager, optionsPanel)
    Thurallor.UI.TabCard.Constructor(self);
    self.manager = manager;
    self.optionsPanel = optionsPanel;

    self.inside = Turbine.UI.Control();
    self.inside:SetSize(width, height);
    self:SetInteriorControl(self.inside);
    self:SetInteriorAlignment(Turbine.UI.ContentAlignment.TopCenter);
    
    self.instructions = Turbine.UI.Label();
    self.instructions:SetParent(self.inside);
    self.instructions:SetMultiline(true);
    self.instructions.height = 32;
    self.instructions:SetHeight(self.instructions.height);
    self.instructions:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
    self.instructions:SetForeColor(Turbine.UI.Color.PaleGoldenrod);

    -- For drag-and-drop operations
    self.carrierWindow = Turbine.UI.Window();
    self.carrierWindow:SetZOrder(2147483647);
    self.carrierWindow:SetOpacity(0.75);
    self.carrierWindow:SetMouseVisible(false);
end

function DirectoryTab:Refresh()
    self:SetInteriorControl(self.inside);

    if (self.tree) then
        self.tree:SetPosition(10,10);
        self.tree:SetParent(nil);
    end
    
    self.tree = self:AddTreeNode(nil, self.manager);
    self.tree:SetParent(self.inside);
    self.tree:SetTop(self.instructions.height);
    self.tree.SizeChanged = function()
        local totalHeight = self.instructions.height + self.tree:GetHeight();
        DoCallbacks(self, "TreeHeightChanged", totalHeight);
    end
    self.tree.SizeChanged();
end

function DirectoryTab:SetHeight(height)
    Thurallor.UI.TabCard.SetHeight(self, height);
    self.inside:SetHeight(height - 40);
end

function DirectoryTab:SetWidth(width)
    Thurallor.UI.TabCard.SetWidth(self, width);
    self.inside:SetWidth(width - 20);
    if (self.tree) then
        self.instructions:SetWidth(width - 20);
        self.tree:SetWidth(width - 20);
    end
end

function DirectoryTab:Localize()
    if (self.refreshButton) then
    self.refreshButton:SetSize(L:GetNumber("/PluginManager/OptionsTab/ShowHideButtonWidth"), 20);    
        self.refreshButton:SetText(L:GetText("/PluginManager/OptionsTab/Show"));
    end
    self:SetTabText(L:GetText("/PluginManager/OptionsTab/Directory"));
    self.instructions:SetText(L:GetText("/PluginManager/OptionsTab/Instructions"));
    ShowHideButton.buttonWidth = L:GetNumber("/PluginManager/OptionsTab/ShowHideButtonWidth");
    ShowHideButton.showText = L:GetText("/PluginManager/OptionsTab/Show");
    ShowHideButton.hideText = L:GetText("/PluginManager/OptionsTab/Hide");
end

function DirectoryTab:AddTreeNode(parentNode, object)
    local newNode = Thurallor.UI.TreeControl();
    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:AddTreeNode(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.tree.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.tree: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

Go to most recent revision | Compare with Previous | Blame


All times are GMT -5. The time now is 03:54 AM.


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