lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [Node.lua] - Blame information for rev 201

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 Thurallor-7095
-- This class contains methods that are in common between Bars and Groups (and the Manager).
2 Thurallor-7095
Node = class(Turbine.UI.Window);
3 Thurallor-7095
 
4 Thurallor-7095
function Node:IsHidden()
5 Thurallor-7095
    return (self.settings.hidden or self:IsParentHidden());
6 Thurallor-7095
end
7 Thurallor-7095
 
8 Thurallor-7095
function Node:IsParentHidden()
9 Thurallor-7095
    return self.parent and self.parent:IsHidden();
10 Thurallor-7095
end
11 Thurallor-7095
 
12 Thurallor-7095
function Node:SetHidden(hide)
13 43 Thurallor-7095
    if (self.settings.hidden ~= hide) then
14 121 Thurallor-7095
        if (self.Log) then
15 Thurallor-7095
            if (hide) then
16 Thurallor-7095
                DoCallbacks(self, "Log", {"hiding", string.upper(self.settings.type)});
17 Thurallor-7095
            else
18 Thurallor-7095
                DoCallbacks(self, "Log", {"showing", string.upper(self.settings.type)});
19 Thurallor-7095
            end
20 Thurallor-7095
        end
21 43 Thurallor-7095
        self.settings.hidden = hide;
22 Thurallor-7095
        self:ApplyHiddenness();
23 143 Thurallor-7095
        self:SaveSettings(true);
24 43 Thurallor-7095
        if (self.HiddenChanged) then
25 Thurallor-7095
            self:HiddenChanged();
26 Thurallor-7095
        end
27 12 Thurallor-7095
    end
28 8 Thurallor-7095
end
29 Thurallor-7095
 
30 177 Thurallor-7095
function Node:SaveSettings(updateBarDirectory, updateEventDirectory)
31 8 Thurallor-7095
    if (not self.constructing) then
32 177 Thurallor-7095
        self.parent:SaveSettings(updateBarDirectory, updateEventDirectory);
33 8 Thurallor-7095
    end
34 Thurallor-7095
end
35 Thurallor-7095
 
36 Thurallor-7095
function Node:EditColor()
37 Thurallor-7095
    if (self.colorPicker == nil) then
38 Thurallor-7095
        self.previousColor = self.color;
39 Thurallor-7095
        self.colorPicker = Thurallor.UI.ColorPicker(self.color, "H");
40 Thurallor-7095
        self.colorPicker:SetZOrder(self:GetZOrder() + 10);
41 Thurallor-7095
        self.colorPicker.ColorChanged = function(picker)
42 Thurallor-7095
            self:SetColor(picker:GetColor());
43 Thurallor-7095
        end
44 Thurallor-7095
        self.colorPicker.Accepted = function()
45 Thurallor-7095
            self.colorPicker = nil;
46 Thurallor-7095
            self:SaveSettings(true);
47 Thurallor-7095
        end
48 Thurallor-7095
        self.colorPicker.Canceled = function()
49 Thurallor-7095
            self:SetColor(self.previousColor);
50 Thurallor-7095
            self.colorPicker = nil;
51 Thurallor-7095
        end
52 Thurallor-7095
    end
53 Thurallor-7095
end
54 Thurallor-7095
 
55 Thurallor-7095
function Node:SetColor(color)
56 Thurallor-7095
    self.color = color;
57 Thurallor-7095
    self.settings.color = color:GetHex();
58 178 Thurallor-7095
    self:SaveSettings(true, true);
59 8 Thurallor-7095
end
60 Thurallor-7095
 
61 Thurallor-7095
function Node:GetID()
62 Thurallor-7095
    return self.objectID;
63 Thurallor-7095
end
64 Thurallor-7095
 
65 Thurallor-7095
function Node:GetName()
66 Thurallor-7095
    return self.settings.caption.text;
67 Thurallor-7095
end
68 Thurallor-7095
 
69 Thurallor-7095
function Node:SetName(newName)
70 Thurallor-7095
    self.settings.caption.text = newName;
71 178 Thurallor-7095
    self:SaveSettings(true, true);
72 8 Thurallor-7095
end
73 Thurallor-7095
 
74 Thurallor-7095
function Node:SetCaptionSize(width, height)
75 Thurallor-7095
    self.settings.caption.width = width;
76 Thurallor-7095
    self.settings.caption.height = height;
77 Thurallor-7095
    self:SaveSettings(false);
78 Thurallor-7095
end
79 Thurallor-7095
 
80 Thurallor-7095
function Node:GetColor()
81 Thurallor-7095
    return self.color;
82 Thurallor-7095
end
83 Thurallor-7095
 
84 Thurallor-7095
function Node:SetWantsEvents(enable)
85 177 Thurallor-7095
    local userEventsWanted = {};
86 Thurallor-7095
    local mgrEventCallbacks = self.manager:GetEventCallbacks();
87 Thurallor-7095
 
88 8 Thurallor-7095
    for h = 1, #self.settings.eventHandlers, 1 do
89 Thurallor-7095
        local handler = self.settings.eventHandlers[h];
90 Thurallor-7095
        local object = loadstring("self = ...; return " .. handler.object)(self);
91 Thurallor-7095
        local trigger = handler.trigger;
92 Thurallor-7095
        if (enable) then
93 Thurallor-7095
            -- Should save this function reference as handler.func, so we can pass the same reference to RemoveCallback().
94 Thurallor-7095
            local funcBody = loadstring(handler.action);
95 Thurallor-7095
            handler.func = function(sender, args)
96 121 Thurallor-7095
                if (self.Log) then
97 199 Thurallor-7095
                    DoCallbacks(self, "Log", {"received: " .. handler.trigger, "EVENT", true});
98 Thurallor-7095
                    DoCallbacks(self, "Log", {"behaviour: " .. handler.description, "EVENT"});
99 121 Thurallor-7095
                end
100 8 Thurallor-7095
                funcBody(self, object, trigger, args);
101 Thurallor-7095
            end;
102 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Compiled handler.action = " .. Serialize(handler.action) .. " into " .. Serialize(handler.func));
103 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Registering event handler " .. Serialize(handler.description) .. " (" .. Serialize(handler.func) .. ")");
104 Thurallor-7095
            AddCallback(object, trigger, handler.func);
105 177 Thurallor-7095
 
106 Thurallor-7095
            -- Make a list of user events we're listening for
107 Thurallor-7095
            if (object == mgrEventCallbacks) then
108 Thurallor-7095
                userEventsWanted[trigger] = true;
109 Thurallor-7095
            end
110 8 Thurallor-7095
        else
111 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Unregistering event handler: " .. Serialize(handler.description) .. " (" .. Serialize(handler.func) .. ")");
112 Thurallor-7095
            RemoveCallback(object, trigger, handler.func);
113 Thurallor-7095
            handler.func = nil;
114 Thurallor-7095
        end
115 Thurallor-7095
    end
116 177 Thurallor-7095
 
117 Thurallor-7095
    -- A central list of all user events being listened for is maintained by Manager
118 Thurallor-7095
    self.manager:SetEventListeners(enable, self, userEventsWanted);
119 8 Thurallor-7095
end
120 Thurallor-7095
 
121 177 Thurallor-7095
function Node:RenameUserEvent(oldName, newName)
122 Thurallor-7095
    self:SetWantsEvents(false);
123 Thurallor-7095
 
124 Thurallor-7095
    -- Update event handlers
125 Thurallor-7095
    for _, handler in pairs(self.settings.eventHandlers) do
126 Thurallor-7095
        if ((handler.trigger == oldName) and (handler.object == "self.manager:GetEventCallbacks()")) then
127 Thurallor-7095
            handler.trigger = newName;
128 Thurallor-7095
            local oldStr = handler.description;
129 Thurallor-7095
            handler.description = oldStr:sub(1, oldStr:len() - oldName:len()) .. newName;
130 Thurallor-7095
        end
131 Thurallor-7095
    end
132 Thurallor-7095
 
133 Thurallor-7095
    self:SetWantsEvents(true);
134 Thurallor-7095
end
135 Thurallor-7095
 
136 128 Thurallor-7095
function Node:AddEventHandler(trigger, action, argValue, argName)
137 8 Thurallor-7095
    self:SetWantsEvents(false);
138 20 Thurallor-7095
    local prevContext = L:SetContext("/EventBehaviorsMenu");
139 128 Thurallor-7095
    local description = { action = L:GetText("Actions/" .. action); trigger = L:GetText("Triggers/" .. trigger) };
140 8 Thurallor-7095
 
141 Thurallor-7095
    -- Initialize action
142 Thurallor-7095
    local handler = {};
143 Thurallor-7095
    if ((action == "ShowGroup") or (action == "ShowBar")) then
144 29 Thurallor-7095
        handler.action = "self:SetHidden(false); ";
145 8 Thurallor-7095
    elseif ((action == "HideGroup") or (action == "HideBar")) then
146 Thurallor-7095
        handler.action = "self:SetHidden(true); ";
147 Thurallor-7095
    elseif ((action == "ResetGroup") or (action == "ResetBar")) then
148 Thurallor-7095
        handler.action = "self:Reset(); ";
149 Thurallor-7095
    elseif (action == "MoveToCursor") then
150 29 Thurallor-7095
        handler.action = "self:MoveToMouseCursor(); ";
151 26 Thurallor-7095
    elseif ((action == "ExpandGroup") or (action == "ExpandBar")) then
152 29 Thurallor-7095
        handler.action = "self:Expand(); ";
153 26 Thurallor-7095
    elseif ((action == "CollapseGroup") or (action == "CollapseBar")) then
154 Thurallor-7095
        handler.action = "self:Collapse(); ";
155 43 Thurallor-7095
    elseif (action == "StopExecuting") then
156 Thurallor-7095
        handler.action = "self:StopExecuting(); ";
157 Thurallor-7095
    elseif (action == "StartExecuting") then
158 Thurallor-7095
        handler.action = "self:StartExecuting(); ";
159 128 Thurallor-7095
    elseif ((action == "SetGroupTransparency") or (action == "SetTransparency")) then
160 Thurallor-7095
        handler.action = "self:SetTransparency(" .. argValue .. "); ";
161 Thurallor-7095
        description.action = description.action .. " " .. argName;
162 8 Thurallor-7095
    else
163 Thurallor-7095
        error("Unknown event handler action: " .. tostring(action), 2);
164 Thurallor-7095
    end
165 Thurallor-7095
 
166 Thurallor-7095
    -- Add object, trigger, action, description
167 Thurallor-7095
    if (trigger == "AtStartup") then
168 Thurallor-7095
        handler.object = "self.manager:GetEventCallbacks()";
169 Thurallor-7095
        handler.trigger = "Startup\n"; -- includes "\n" so it can't be generated by user
170 Thurallor-7095
        handler.action =
171 20 Thurallor-7095
            "self = ...; " ..
172 8 Thurallor-7095
            handler.action;
173 43 Thurallor-7095
    elseif (trigger == "WhenTargetChanges") then
174 Thurallor-7095
        handler.object = "self.manager.watcher";
175 Thurallor-7095
        handler.trigger = "PlayerTargetChanged";
176 Thurallor-7095
        handler.action =
177 Thurallor-7095
            "self = ...; " ..
178 Thurallor-7095
            handler.action;
179 165 Thurallor-7095
    elseif (trigger == "WhenYouAreIncapacitated") then
180 Thurallor-7095
        handler.object = "self.manager.watcher";
181 Thurallor-7095
        handler.trigger = "PlayerIncapacitated";
182 Thurallor-7095
        handler.action =
183 Thurallor-7095
            "self = ...; " ..
184 Thurallor-7095
            handler.action;
185 Thurallor-7095
    elseif (trigger == "WhenYouAreRevived") then
186 Thurallor-7095
        handler.object = "self.manager.watcher";
187 Thurallor-7095
        handler.trigger = "PlayerRevived";
188 Thurallor-7095
        handler.action =
189 Thurallor-7095
            "self = ...; " ..
190 Thurallor-7095
            handler.action;
191 200 Thurallor-7095
    elseif (trigger == "WhenPetChanges") then
192 Thurallor-7095
        handler.object = "self.manager.player";
193 Thurallor-7095
        handler.trigger = "PetChanged";
194 Thurallor-7095
        handler.action =
195 Thurallor-7095
            "self = ...; " ..
196 Thurallor-7095
            handler.action;
197 Thurallor-7095
    elseif (trigger == "WhenMountChanges") then
198 Thurallor-7095
        handler.object = "self.manager.player";
199 Thurallor-7095
        handler.trigger = "MountChanged";
200 Thurallor-7095
        handler.action =
201 Thurallor-7095
            "self = ...; " ..
202 Thurallor-7095
            handler.action;
203 8 Thurallor-7095
    elseif (trigger == "WhenCombatBegins") then
204 43 Thurallor-7095
        handler.object = "self.manager.player";
205 8 Thurallor-7095
        handler.trigger = "InCombatChanged";
206 Thurallor-7095
        handler.action =
207 Thurallor-7095
            "self, object = ...; " ..
208 Thurallor-7095
            "if (object:IsInCombat()) then " ..
209 Thurallor-7095
                handler.action ..
210 Thurallor-7095
            "end";
211 Thurallor-7095
    elseif (trigger == "WhenCombatEnds") then
212 43 Thurallor-7095
        handler.object = "self.manager.player";
213 8 Thurallor-7095
        handler.trigger = "InCombatChanged";
214 Thurallor-7095
        handler.action =
215 Thurallor-7095
            "self, object = ...; " ..
216 Thurallor-7095
            "if (not object:IsInCombat()) then " ..
217 Thurallor-7095
                handler.action ..
218 Thurallor-7095
            "end";
219 20 Thurallor-7095
    elseif (trigger == "WhenMouseArrives") then
220 Thurallor-7095
        handler.object = "self";
221 Thurallor-7095
        handler.trigger = "MouseArrived";
222 Thurallor-7095
        handler.action =
223 Thurallor-7095
            "self = ...; " ..
224 Thurallor-7095
            handler.action;
225 Thurallor-7095
    elseif (trigger == "WhenMouseDeparts") then
226 Thurallor-7095
        handler.object = "self";
227 Thurallor-7095
        handler.trigger = "MouseDeparted";
228 Thurallor-7095
        handler.action =
229 Thurallor-7095
            "self = ...; " ..
230 Thurallor-7095
            handler.action;
231 8 Thurallor-7095
    elseif (string.find(trigger, "WhenEventOccurs:")) then
232 Thurallor-7095
        local eventName = string.sub(trigger, 17);
233 Thurallor-7095
        handler.object = "self.manager:GetEventCallbacks()";
234 Thurallor-7095
        handler.trigger = eventName;
235 Thurallor-7095
        handler.action =
236 20 Thurallor-7095
            "self = ...; " ..
237 8 Thurallor-7095
            handler.action;
238 128 Thurallor-7095
        description.trigger = L:GetText("Triggers/WhenEventOccurs") .. ": " .. eventName;
239 35 Thurallor-7095
    elseif (trigger == "WhenTraitTreeChanges") then
240 Thurallor-7095
        handler.object = "self.manager.watcher";
241 Thurallor-7095
        handler.trigger = "TraitTreeChanged";
242 Thurallor-7095
        handler.action =
243 Thurallor-7095
            "self = ...; " ..
244 Thurallor-7095
            handler.action;
245 111 Thurallor-7095
    elseif (trigger == "WhenStanceChanges") then
246 Thurallor-7095
        handler.object = "self.manager.watcher";
247 Thurallor-7095
        handler.trigger = "PlayerStanceChanged";
248 Thurallor-7095
        handler.action =
249 Thurallor-7095
            "self = ...; " ..
250 Thurallor-7095
            handler.action;
251 8 Thurallor-7095
    else
252 Thurallor-7095
        error("Unknown event handler trigger: " .. tostring(trigger), 2);
253 Thurallor-7095
    end
254 Thurallor-7095
    L:SetContext(prevContext);
255 Thurallor-7095
 
256 Thurallor-7095
    -- Save new event handler and activate it
257 128 Thurallor-7095
    handler.description = description.action .. " " .. description.trigger;
258 8 Thurallor-7095
    table.insert(self.settings.eventHandlers, handler);
259 Thurallor-7095
    self:SetWantsEvents(true);
260 177 Thurallor-7095
    self:SaveSettings(false, true);
261 8 Thurallor-7095
end
262 Thurallor-7095
 
263 Thurallor-7095
function Node:RemoveEventHandler(h)
264 Thurallor-7095
    self:SetWantsEvents(false);
265 Thurallor-7095
    table.remove(self.settings.eventHandlers, h);
266 Thurallor-7095
    self:SetWantsEvents(true);
267 177 Thurallor-7095
    self:SaveSettings(false, true);
268 8 Thurallor-7095
end
269 Thurallor-7095
 
270 177 Thurallor-7095
function Node:SetEventHandlersEnabled(enable)
271 Thurallor-7095
    self.settings.eventsEnabled = enable;
272 Thurallor-7095
    self:SetWantsEvents(enable);
273 Thurallor-7095
    self:SaveSettings(false, true);
274 Thurallor-7095
end
275 Thurallor-7095
 
276 8 Thurallor-7095
function Node:StripSettingsForExport(settings)
277 Thurallor-7095
    settings.deletedBarIDs = nil;
278 Thurallor-7095
    settings.deletedGroupIDs = nil;
279 Thurallor-7095
end
280 Thurallor-7095
 
281 Thurallor-7095
function Node:Export()
282 Thurallor-7095
    if (self.exportWindow) then
283 Thurallor-7095
        self.exportWindow:Close();
284 Thurallor-7095
        self.exportWindow = nil;
285 Thurallor-7095
    end
286 Thurallor-7095
 
287 Thurallor-7095
    -- Compile the data to be exported
288 Thurallor-7095
    Puts(L:GetText("/ExportWindow/Exporting"));
289 Thurallor-7095
    local exportObjects = { [self.objectID] = {} };
290 Thurallor-7095
    self:SetWantsEvents(false); -- we don't want to save eventHandlers[].func values
291 Thurallor-7095
    DeepTableCopy(self.settings, exportObjects[self.objectID]);
292 Thurallor-7095
    self:SetWantsEvents(self.settings.eventsEnabled);
293 Thurallor-7095
    self:StripSettingsForExport(exportObjects[self.objectID]);
294 Thurallor-7095
    if (self:CanHaveChildren()) then
295 Thurallor-7095
        local descendentIDs = self:FindAllDescendentIDs(nil, true, true);
296 Thurallor-7095
        for d = 1, #descendentIDs do
297 Thurallor-7095
            local objectID = descendentIDs[d];
298 Thurallor-7095
            local object = self.manager.objects[objectID];
299 Thurallor-7095
            exportObjects[objectID] = {};
300 Thurallor-7095
            object:SetWantsEvents(false); -- we don't want to save eventHandlers[].func values
301 Thurallor-7095
            DeepTableCopy(object.settings, exportObjects[objectID]);
302 Thurallor-7095
            object:SetWantsEvents(object.settings.eventsEnabled);
303 Thurallor-7095
            self:StripSettingsForExport(exportObjects[objectID]);
304 Thurallor-7095
        end
305 Thurallor-7095
    end
306 Thurallor-7095
 
307 Thurallor-7095
    -- Create the export window
308 Thurallor-7095
    local title = L:GetText("/ExportWindow/Title");
309 Thurallor-7095
    title = string.gsub(title, "<name>", self.settings.caption.text);
310 Thurallor-7095
    self.exportWindow = ExportWindow(title, exportObjects);
311 Thurallor-7095
    self.exportWindow.Closing = function()
312 Thurallor-7095
        self.exportWindow = nil;
313 Thurallor-7095
    end
314 Thurallor-7095
end
315 Thurallor-7095
 
316 200 Thurallor-7095
function Node:ShowSettingsMenu(fromOptionsPanel, mouseX, mouseY, itemsToClick)
317 Thurallor-7095
    mouseX = mouseX or Turbine.UI.Display.GetMouseX();
318 Thurallor-7095
    mouseY = mouseY or Turbine.UI.Display.GetMouseY();
319 Thurallor-7095
 
320 8 Thurallor-7095
    -- Build the settings menu.
321 18 Thurallor-7095
    self.settingsMenu = Turbine.UI.ContextMenu();
322 200 Thurallor-7095
    self.amSubMenuOf = nil;
323 201 Thurallor-7095
    self:AddSettingsMenuItem(self.settingsMenu, "Root", nil, fromOptionsPanel);
324 Thurallor-7095
    self.prevSettingsMenuArgs = { fromOptionsPanel or false, mouseX, mouseY };
325 200 Thurallor-7095
    self.settingsMenu:ShowMenuAt(mouseX, mouseY);
326 Thurallor-7095
 
327 Thurallor-7095
    -- Click the desired items
328 Thurallor-7095
    local menuItem = self.settingsMenu;
329 Thurallor-7095
    while (itemsToClick and next(itemsToClick)) do
330 Thurallor-7095
        local itemName = table.remove(itemsToClick);
331 Thurallor-7095
        local item = menuItem._itemsByName[itemName];
332 Thurallor-7095
        if (item) then
333 Thurallor-7095
            item:GetParent():GetParent().FocusLost = nil;
334 Thurallor-7095
            DoCallbacks(item, "MouseEnter");
335 Thurallor-7095
            DoCallbacks(item, "MouseLeave");
336 Thurallor-7095
            menuItem = item;
337 Thurallor-7095
        end
338 Thurallor-7095
    end
339 8 Thurallor-7095
end
340 Thurallor-7095
 
341 200 Thurallor-7095
function Node:RedisplayMenu(menuItem, otherItem)
342 Thurallor-7095
    local itemsClicked = {};
343 Thurallor-7095
    while (menuItem._name) do
344 Thurallor-7095
        table.insert(itemsClicked, menuItem._name);
345 Thurallor-7095
        menuItem = menuItem._parent;
346 Thurallor-7095
    end
347 Thurallor-7095
    if (otherItem) then
348 Thurallor-7095
        table.insert(itemsClicked, 1, otherItem);
349 Thurallor-7095
    end
350 Thurallor-7095
 
351 Thurallor-7095
    -- Redisplay the settings menu and reselect all of the previously-selected menu items
352 Thurallor-7095
    local node = self.amSubMenuOf or self;
353 Thurallor-7095
    node.settingsMenu:Close();
354 Thurallor-7095
    table.insert(node.prevSettingsMenuArgs, itemsClicked);
355 Thurallor-7095
    DoAtNextFrame(function()
356 Thurallor-7095
        node:ShowSettingsMenu(unpack(node.prevSettingsMenuArgs));
357 Thurallor-7095
    end);
358 Thurallor-7095
end
359 Thurallor-7095
 
360 8 Thurallor-7095
function Node:Destroy()
361 Thurallor-7095
    self:SetWantsEvents(false);
362 34 Thurallor-7095
    self:SetWantsUpdates(false);
363 8 Thurallor-7095
    if (self.settingsMenu) then
364 Thurallor-7095
        self.settingsMenu:Close();
365 Thurallor-7095
    end
366 Thurallor-7095
    if (self.captionEditor) then
367 Thurallor-7095
        self.captionEditor:Close();
368 Thurallor-7095
    end
369 Thurallor-7095
    if (self.exportWindow) then
370 Thurallor-7095
        self.exportWindow:Close();
371 Thurallor-7095
    end
372 Thurallor-7095
    if (self.importWindow) then
373 Thurallor-7095
        self.importWindow:Close();
374 Thurallor-7095
    end
375 Thurallor-7095
    if (self.colorPicker) then
376 Thurallor-7095
        self.colorPicker:Close();
377 Thurallor-7095
    end
378 Thurallor-7095
    self.manager.objects[self.objectID] = nil;
379 121 Thurallor-7095
    if (self.Log) then
380 Thurallor-7095
        DoCallbacks(self, "Log", {"destroyed", string.upper(self.settings.type)});
381 Thurallor-7095
    end
382 8 Thurallor-7095
    self:Close();
383 Thurallor-7095
end

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


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