lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [BarTreeControl.Lua] - Blame information for rev 175

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 175 Thurallor-7095
NodeLabel = class(Turbine.UI.Label);
2 Thurallor-7095
 
3 Thurallor-7095
function NodeLabel:Constructor(node, object)
4 Thurallor-7095
    Turbine.UI.Label.Constructor(self);
5 Thurallor-7095
    self.node = node;
6 Thurallor-7095
    self.object = object;
7 Thurallor-7095
    self:SetFont(Turbine.UI.Lotro.Font.TrajanPro15);
8 Thurallor-7095
    self:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
9 Thurallor-7095
    self:SetFontStyle(Turbine.UI.FontStyle.Outline);
10 Thurallor-7095
    self:SetOutlineColor(Turbine.UI.Color.Black);
11 Thurallor-7095
    self:SetMultiline(false);
12 Thurallor-7095
    self:SetHeight(20);
13 Thurallor-7095
    self:UpdateText();
14 Thurallor-7095
    self.skipSizeChanged = 1;
15 Thurallor-7095
end
16 Thurallor-7095
 
17 Thurallor-7095
function NodeLabel:UpdateText()
18 Thurallor-7095
    self:SetForeColor(self.object:GetColor());
19 Thurallor-7095
    self:SetText(self.object:GetName());
20 Thurallor-7095
end
21 Thurallor-7095
 
22 Thurallor-7095
ShowHideButton = class(Turbine.UI.Lotro.Button);
23 Thurallor-7095
 
24 Thurallor-7095
function ShowHideButton:Constructor(node, object)
25 Thurallor-7095
    Turbine.UI.Lotro.Button.Constructor(self);
26 Thurallor-7095
    self.node = node;
27 Thurallor-7095
    self.object = object;
28 Thurallor-7095
    self:SetWidth(ShowHideButton.buttonWidth);
29 Thurallor-7095
    object.HiddenChanged = function()
30 Thurallor-7095
        self:UpdateText();
31 Thurallor-7095
    end
32 Thurallor-7095
    self:UpdateText();
33 Thurallor-7095
end
34 Thurallor-7095
 
35 Thurallor-7095
function ShowHideButton:UpdateText()
36 Thurallor-7095
    local hidden = self.object.settings.hidden;
37 Thurallor-7095
    if (hidden) then
38 Thurallor-7095
        self:SetText(ShowHideButton.showText);
39 Thurallor-7095
    else
40 Thurallor-7095
        self:SetText(ShowHideButton.hideText);
41 Thurallor-7095
    end
42 Thurallor-7095
    self:SetVisible(not self.object:IsParentHidden());
43 Thurallor-7095
end
44 Thurallor-7095
 
45 Thurallor-7095
function ShowHideButton:Click()
46 Thurallor-7095
    self.object:SetHidden(not self.object:IsHidden());
47 Thurallor-7095
end
48 Thurallor-7095
 
49 Thurallor-7095
BarTreeControl = class(Thurallor.UI.TreeControl);
50 Thurallor-7095
 
51 Thurallor-7095
function BarTreeControl:Constructor(manager)
52 Thurallor-7095
    Thurallor.UI.TreeControl.Constructor(self);
53 Thurallor-7095
    self.manager = manager;
54 Thurallor-7095
 
55 Thurallor-7095
    -- Localize; to re-localize, recreate the tree.
56 Thurallor-7095
    ShowHideButton.buttonWidth = L:GetNumber("/PluginManager/OptionsTab/DirectoryTab/ShowHideButtonWidth");
57 Thurallor-7095
    ShowHideButton.showText = L:GetText("/PluginManager/OptionsTab/DirectoryTab/Show");
58 Thurallor-7095
    ShowHideButton.hideText = L:GetText("/PluginManager/OptionsTab/DirectoryTab/Hide");
59 Thurallor-7095
 
60 Thurallor-7095
    -- For drag-and-drop operations
61 Thurallor-7095
    self.carrierWindow = Turbine.UI.Window();
62 Thurallor-7095
    self.carrierWindow:SetZOrder(2147483647);
63 Thurallor-7095
    self.carrierWindow:SetOpacity(0.75);
64 Thurallor-7095
    self.carrierWindow:SetMouseVisible(false);
65 Thurallor-7095
 
66 Thurallor-7095
    self:ConfigureNodeControl(self, nil, manager);
67 Thurallor-7095
end
68 Thurallor-7095
 
69 Thurallor-7095
function BarTreeControl:Localize()
70 Thurallor-7095
end
71 Thurallor-7095
 
72 Thurallor-7095
function BarTreeControl:ConfigureNodeControl(newNode, parentNode, object)
73 Thurallor-7095
    newNode.object = object;
74 Thurallor-7095
 
75 Thurallor-7095
    -- Add a text box for the name of the group or bar.
76 Thurallor-7095
    newNode.label = NodeLabel(newNode, object);
77 Thurallor-7095
    newNode:AddColumn(newNode.label, 1);
78 Thurallor-7095
 
79 Thurallor-7095
    -- Add the "Show" or "Hide" button.
80 Thurallor-7095
    newNode.showHideButton = ShowHideButton(newNode, object);
81 Thurallor-7095
    newNode:AddColumn(newNode.showHideButton, 0);
82 Thurallor-7095
 
83 Thurallor-7095
    if (parentNode) then
84 Thurallor-7095
        parentNode:AddChild(newNode);
85 Thurallor-7095
    end
86 Thurallor-7095
 
87 Thurallor-7095
    -- Add subnodes, if any, alphabetized
88 Thurallor-7095
    local childIDs = {};
89 Thurallor-7095
    if (object:CanHaveChildren()) then
90 Thurallor-7095
        childIDs = object:GetChildIDs();
91 Thurallor-7095
        table.sort(childIDs, function (a, b) return object:GetChild(a):GetName() < object:GetChild(b):GetName(); end);
92 Thurallor-7095
        for c = 1, #childIDs, 1 do
93 Thurallor-7095
            local childID = childIDs[c];
94 Thurallor-7095
            local child = object:GetChild(childID);
95 Thurallor-7095
            self:ConfigureNodeControl(Thurallor.UI.TreeControl(), newNode, child);
96 Thurallor-7095
        end
97 Thurallor-7095
    end
98 Thurallor-7095
    newNode:SetExpanded(not object.nodeCollapsed);
99 Thurallor-7095
 
100 Thurallor-7095
    -- Add mouse behaviors
101 Thurallor-7095
    newNode.IconClicked = function()
102 Thurallor-7095
        object.nodeCollapsed = not newNode.expanded;
103 Thurallor-7095
    end
104 Thurallor-7095
    newNode.label.MouseClick = function(sender, args)
105 Thurallor-7095
        -- Right-click displays the settings menu.
106 Thurallor-7095
        if (args.Button == Turbine.UI.MouseButton.Right) then
107 Thurallor-7095
            sender.node.object:ShowSettingsMenu(true);
108 Thurallor-7095
        end
109 Thurallor-7095
    end
110 Thurallor-7095
    newNode.label.MouseDoubleClick = function(sender, args)
111 Thurallor-7095
        -- Left-double-click opens the caption editor.
112 Thurallor-7095
        if (args.Button == Turbine.UI.MouseButton.Left) then
113 Thurallor-7095
            sender.node.object:EditCaption(newNode.label);
114 Thurallor-7095
        end
115 Thurallor-7095
    end
116 Thurallor-7095
    newNode.label.MouseDown = function(sender, args)
117 Thurallor-7095
        if ((args.Button == Turbine.UI.MouseButton.Left) and (sender ~= self.label)) then
118 Thurallor-7095
            sender.mouseDown = true;
119 Thurallor-7095
            sender.originalLeft, sender.originalTop = sender.node:GetParent():PointToScreen(sender.node:GetPosition());
120 Thurallor-7095
            sender.originalMouseX, sender.originalMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
121 Thurallor-7095
        end
122 Thurallor-7095
    end
123 Thurallor-7095
    newNode.label.MouseMove = function(sender)
124 Thurallor-7095
        if (sender.mouseDown) then
125 Thurallor-7095
 
126 Thurallor-7095
            -- Detach from tree
127 Thurallor-7095
            if (not sender.detached) then
128 Thurallor-7095
                sender.originalParentNode = sender.node:GetParentTreeControl();
129 Thurallor-7095
                sender.originalChildNumber = sender.originalParentNode:RemoveChild(sender.node);
130 Thurallor-7095
                self.carrierWindow:SetVisible(true);
131 Thurallor-7095
                self.carrierWindow:SetSize(sender.node:GetSize());
132 Thurallor-7095
                sender.node:SetParent(self.carrierWindow);
133 Thurallor-7095
                sender.node:SetPosition(0, 0);
134 Thurallor-7095
                self.carrierWindow:SetPosition(sender.originalLeft, sender.originalTop);
135 Thurallor-7095
                sender.node:SetColumnWidth(3, 0);
136 Thurallor-7095
                sender.detached = true;
137 Thurallor-7095
            end
138 Thurallor-7095
 
139 Thurallor-7095
            local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
140 Thurallor-7095
            local deltaX, deltaY = newMouseX - sender.originalMouseX, newMouseY - sender.originalMouseY;
141 Thurallor-7095
            local left = sender.originalLeft + deltaX;
142 Thurallor-7095
            local top = sender.originalTop + deltaY;
143 Thurallor-7095
            self.carrierWindow:SetPosition(left, top);
144 Thurallor-7095
            if (sender.previousHighlight) then
145 Thurallor-7095
                sender.previousHighlight:SetBackColor(nil);
146 Thurallor-7095
                sender.previousHighlight = nil;
147 Thurallor-7095
            end
148 Thurallor-7095
 
149 Thurallor-7095
            -- Figure out if we're over another textBox
150 Thurallor-7095
            local hoveringOverNode, target = self:IsMouseInside();
151 Thurallor-7095
            if (hoveringOverNode) then
152 Thurallor-7095
                local source = sender.node;
153 Thurallor-7095
                if (
154 Thurallor-7095
                    (target.object:CanHaveChildren()) and
155 Thurallor-7095
                    (target ~= source) and
156 Thurallor-7095
                    (not source.object:Contains(target.object)) and
157 Thurallor-7095
                    (source.object.parent ~= target.object)
158 Thurallor-7095
                ) then
159 Thurallor-7095
                    sender.targetObject = target.object;
160 Thurallor-7095
--Puts("target object is " .. object.settings.type .. " " .. Serialize(object.settings.caption.text));
161 Thurallor-7095
                    target.label:SetBackColor(Turbine.UI.Color(1, 0.25, 0.25, 0.75));
162 Thurallor-7095
                    sender.previousHighlight = target.label;
163 Thurallor-7095
                    return;
164 Thurallor-7095
                end
165 Thurallor-7095
            end
166 Thurallor-7095
            sender.targetObject = nil;
167 Thurallor-7095
        end
168 Thurallor-7095
    end
169 Thurallor-7095
    newNode.label.MouseUp = function(sender, args)
170 Thurallor-7095
        if (args.Button == Turbine.UI.MouseButton.Left) then
171 Thurallor-7095
            sender.mouseDown = false;
172 Thurallor-7095
            if (sender.detached) then
173 Thurallor-7095
                local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
174 Thurallor-7095
                local deltaX, deltaY = newMouseX - sender.originalMouseX, newMouseY - sender.originalMouseY;
175 Thurallor-7095
 
176 Thurallor-7095
                -- Do the object transfer
177 Thurallor-7095
                sender.node:SetParent(nil);
178 Thurallor-7095
                if (sender.targetObject) then
179 Thurallor-7095
                    local sourceObject = sender.node.object;
180 Thurallor-7095
                    if (sourceObject.settings.type == "bar") then
181 Thurallor-7095
                        self.manager:TransferBar(sourceObject.objectID, sourceObject.parent, sender.targetObject);
182 Thurallor-7095
                    else
183 Thurallor-7095
                        self.manager:TransferGroup(sourceObject.objectID, sourceObject.parent, sender.targetObject);
184 Thurallor-7095
                    end
185 Thurallor-7095
                else
186 Thurallor-7095
                    -- Reattach to tree
187 Thurallor-7095
                    self.carrierWindow:SetVisible(false);
188 Thurallor-7095
                    sender.node:SetColumnWidth(3, ShowHideButton.buttonWidth);
189 Thurallor-7095
                    sender.originalParentNode:InsertChild(sender.node, sender.originalChildNumber);
190 Thurallor-7095
                    sender.detached = false;
191 Thurallor-7095
                end
192 Thurallor-7095
            end
193 Thurallor-7095
        end
194 Thurallor-7095
    end
195 Thurallor-7095
 
196 Thurallor-7095
    return newNode;
197 Thurallor-7095
end

All times are GMT -5. The time now is 10:48 PM.


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