lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

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

Go to most recent revision | 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 Thurallor-7095
                    DoCallbacks(self, "Log", {"received: " .. handler.trigger, "EVENT"});
98 Thurallor-7095
                end
99 8 Thurallor-7095
                funcBody(self, object, trigger, args);
100 Thurallor-7095
            end;
101 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Compiled handler.action = " .. Serialize(handler.action) .. " into " .. Serialize(handler.func));
102 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Registering event handler " .. Serialize(handler.description) .. " (" .. Serialize(handler.func) .. ")");
103 Thurallor-7095
            AddCallback(object, trigger, handler.func);
104 177 Thurallor-7095
 
105 Thurallor-7095
            -- Make a list of user events we're listening for
106 Thurallor-7095
            if (object == mgrEventCallbacks) then
107 Thurallor-7095
                userEventsWanted[trigger] = true;
108 Thurallor-7095
            end
109 8 Thurallor-7095
        else
110 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Unregistering event handler: " .. Serialize(handler.description) .. " (" .. Serialize(handler.func) .. ")");
111 Thurallor-7095
            RemoveCallback(object, trigger, handler.func);
112 Thurallor-7095
            handler.func = nil;
113 Thurallor-7095
        end
114 Thurallor-7095
    end
115 177 Thurallor-7095
 
116 Thurallor-7095
    -- A central list of all user events being listened for is maintained by Manager
117 Thurallor-7095
    self.manager:SetEventListeners(enable, self, userEventsWanted);
118 8 Thurallor-7095
end
119 Thurallor-7095
 
120 177 Thurallor-7095
function Node:RenameUserEvent(oldName, newName)
121 Thurallor-7095
    self:SetWantsEvents(false);
122 Thurallor-7095
 
123 Thurallor-7095
    -- Update event handlers
124 Thurallor-7095
    for _, handler in pairs(self.settings.eventHandlers) do
125 Thurallor-7095
        if ((handler.trigger == oldName) and (handler.object == "self.manager:GetEventCallbacks()")) then
126 Thurallor-7095
            handler.trigger = newName;
127 Thurallor-7095
            local oldStr = handler.description;
128 Thurallor-7095
            handler.description = oldStr:sub(1, oldStr:len() - oldName:len()) .. newName;
129 Thurallor-7095
        end
130 Thurallor-7095
    end
131 Thurallor-7095
 
132 Thurallor-7095
    self:SetWantsEvents(true);
133 Thurallor-7095
end
134 Thurallor-7095
 
135 128 Thurallor-7095
function Node:AddEventHandler(trigger, action, argValue, argName)
136 8 Thurallor-7095
    self:SetWantsEvents(false);
137 20 Thurallor-7095
    local prevContext = L:SetContext("/EventBehaviorsMenu");
138 128 Thurallor-7095
    local description = { action = L:GetText("Actions/" .. action); trigger = L:GetText("Triggers/" .. trigger) };
139 8 Thurallor-7095
 
140 Thurallor-7095
    -- Initialize action
141 Thurallor-7095
    local handler = {};
142 Thurallor-7095
    if ((action == "ShowGroup") or (action == "ShowBar")) then
143 29 Thurallor-7095
        handler.action = "self:SetHidden(false); ";
144 8 Thurallor-7095
    elseif ((action == "HideGroup") or (action == "HideBar")) then
145 Thurallor-7095
        handler.action = "self:SetHidden(true); ";
146 Thurallor-7095
    elseif ((action == "ResetGroup") or (action == "ResetBar")) then
147 Thurallor-7095
        handler.action = "self:Reset(); ";
148 Thurallor-7095
    elseif (action == "MoveToCursor") then
149 29 Thurallor-7095
        handler.action = "self:MoveToMouseCursor(); ";
150 26 Thurallor-7095
    elseif ((action == "ExpandGroup") or (action == "ExpandBar")) then
151 29 Thurallor-7095
        handler.action = "self:Expand(); ";
152 26 Thurallor-7095
    elseif ((action == "CollapseGroup") or (action == "CollapseBar")) then
153 Thurallor-7095
        handler.action = "self:Collapse(); ";
154 43 Thurallor-7095
    elseif (action == "StopExecuting") then
155 Thurallor-7095
        handler.action = "self:StopExecuting(); ";
156 Thurallor-7095
    elseif (action == "StartExecuting") then
157 Thurallor-7095
        handler.action = "self:StartExecuting(); ";
158 128 Thurallor-7095
    elseif ((action == "SetGroupTransparency") or (action == "SetTransparency")) then
159 Thurallor-7095
        handler.action = "self:SetTransparency(" .. argValue .. "); ";
160 Thurallor-7095
        description.action = description.action .. " " .. argName;
161 8 Thurallor-7095
    else
162 Thurallor-7095
        error("Unknown event handler action: " .. tostring(action), 2);
163 Thurallor-7095
    end
164 Thurallor-7095
 
165 Thurallor-7095
    -- Add object, trigger, action, description
166 Thurallor-7095
    if (trigger == "AtStartup") then
167 Thurallor-7095
        handler.object = "self.manager:GetEventCallbacks()";
168 Thurallor-7095
        handler.trigger = "Startup\n"; -- includes "\n" so it can't be generated by user
169 Thurallor-7095
        handler.action =
170 20 Thurallor-7095
            "self = ...; " ..
171 8 Thurallor-7095
            handler.action;
172 43 Thurallor-7095
    elseif (trigger == "WhenTargetChanges") then
173 Thurallor-7095
        handler.object = "self.manager.watcher";
174 Thurallor-7095
        handler.trigger = "PlayerTargetChanged";
175 Thurallor-7095
        handler.action =
176 Thurallor-7095
            "self = ...; " ..
177 Thurallor-7095
            handler.action;
178 165 Thurallor-7095
    elseif (trigger == "WhenYouAreIncapacitated") then
179 Thurallor-7095
        handler.object = "self.manager.watcher";
180 Thurallor-7095
        handler.trigger = "PlayerIncapacitated";
181 Thurallor-7095
        handler.action =
182 Thurallor-7095
            "self = ...; " ..
183 Thurallor-7095
            handler.action;
184 Thurallor-7095
    elseif (trigger == "WhenYouAreRevived") then
185 Thurallor-7095
        handler.object = "self.manager.watcher";
186 Thurallor-7095
        handler.trigger = "PlayerRevived";
187 Thurallor-7095
        handler.action =
188 Thurallor-7095
            "self = ...; " ..
189 Thurallor-7095
            handler.action;
190 8 Thurallor-7095
    elseif (trigger == "WhenCombatBegins") then
191 43 Thurallor-7095
        handler.object = "self.manager.player";
192 8 Thurallor-7095
        handler.trigger = "InCombatChanged";
193 Thurallor-7095
        handler.action =
194 Thurallor-7095
            "self, object = ...; " ..
195 Thurallor-7095
            "if (object:IsInCombat()) then " ..
196 Thurallor-7095
                handler.action ..
197 Thurallor-7095
            "end";
198 Thurallor-7095
    elseif (trigger == "WhenCombatEnds") then
199 43 Thurallor-7095
        handler.object = "self.manager.player";
200 8 Thurallor-7095
        handler.trigger = "InCombatChanged";
201 Thurallor-7095
        handler.action =
202 Thurallor-7095
            "self, object = ...; " ..
203 Thurallor-7095
            "if (not object:IsInCombat()) then " ..
204 Thurallor-7095
                handler.action ..
205 Thurallor-7095
            "end";
206 20 Thurallor-7095
    elseif (trigger == "WhenMouseArrives") then
207 Thurallor-7095
        handler.object = "self";
208 Thurallor-7095
        handler.trigger = "MouseArrived";
209 Thurallor-7095
        handler.action =
210 Thurallor-7095
            "self = ...; " ..
211 Thurallor-7095
            handler.action;
212 Thurallor-7095
    elseif (trigger == "WhenMouseDeparts") then
213 Thurallor-7095
        handler.object = "self";
214 Thurallor-7095
        handler.trigger = "MouseDeparted";
215 Thurallor-7095
        handler.action =
216 Thurallor-7095
            "self = ...; " ..
217 Thurallor-7095
            handler.action;
218 8 Thurallor-7095
    elseif (string.find(trigger, "WhenEventOccurs:")) then
219 Thurallor-7095
        local eventName = string.sub(trigger, 17);
220 Thurallor-7095
        handler.object = "self.manager:GetEventCallbacks()";
221 Thurallor-7095
        handler.trigger = eventName;
222 Thurallor-7095
        handler.action =
223 20 Thurallor-7095
            "self = ...; " ..
224 8 Thurallor-7095
            handler.action;
225 128 Thurallor-7095
        description.trigger = L:GetText("Triggers/WhenEventOccurs") .. ": " .. eventName;
226 35 Thurallor-7095
    elseif (trigger == "WhenTraitTreeChanges") then
227 Thurallor-7095
        handler.object = "self.manager.watcher";
228 Thurallor-7095
        handler.trigger = "TraitTreeChanged";
229 Thurallor-7095
        handler.action =
230 Thurallor-7095
            "self = ...; " ..
231 Thurallor-7095
            handler.action;
232 111 Thurallor-7095
    elseif (trigger == "WhenStanceChanges") then
233 Thurallor-7095
        handler.object = "self.manager.watcher";
234 Thurallor-7095
        handler.trigger = "PlayerStanceChanged";
235 Thurallor-7095
        handler.action =
236 Thurallor-7095
            "self = ...; " ..
237 Thurallor-7095
            handler.action;
238 8 Thurallor-7095
    else
239 Thurallor-7095
        error("Unknown event handler trigger: " .. tostring(trigger), 2);
240 Thurallor-7095
    end
241 Thurallor-7095
    L:SetContext(prevContext);
242 Thurallor-7095
 
243 Thurallor-7095
    -- Save new event handler and activate it
244 128 Thurallor-7095
    handler.description = description.action .. " " .. description.trigger;
245 8 Thurallor-7095
    table.insert(self.settings.eventHandlers, handler);
246 Thurallor-7095
    self:SetWantsEvents(true);
247 177 Thurallor-7095
    self:SaveSettings(false, true);
248 8 Thurallor-7095
end
249 Thurallor-7095
 
250 Thurallor-7095
function Node:RemoveEventHandler(h)
251 Thurallor-7095
    self:SetWantsEvents(false);
252 Thurallor-7095
    table.remove(self.settings.eventHandlers, h);
253 Thurallor-7095
    self:SetWantsEvents(true);
254 177 Thurallor-7095
    self:SaveSettings(false, true);
255 8 Thurallor-7095
end
256 Thurallor-7095
 
257 177 Thurallor-7095
function Node:SetEventHandlersEnabled(enable)
258 Thurallor-7095
    self.settings.eventsEnabled = enable;
259 Thurallor-7095
    self:SetWantsEvents(enable);
260 Thurallor-7095
    self:SaveSettings(false, true);
261 Thurallor-7095
end
262 Thurallor-7095
 
263 8 Thurallor-7095
function Node:StripSettingsForExport(settings)
264 Thurallor-7095
    settings.deletedBarIDs = nil;
265 Thurallor-7095
    settings.deletedGroupIDs = nil;
266 Thurallor-7095
end
267 Thurallor-7095
 
268 Thurallor-7095
function Node:Export()
269 Thurallor-7095
    if (self.exportWindow) then
270 Thurallor-7095
        self.exportWindow:Close();
271 Thurallor-7095
        self.exportWindow = nil;
272 Thurallor-7095
    end
273 Thurallor-7095
 
274 Thurallor-7095
    -- Compile the data to be exported
275 Thurallor-7095
    Puts(L:GetText("/ExportWindow/Exporting"));
276 Thurallor-7095
    local exportObjects = { [self.objectID] = {} };
277 Thurallor-7095
    self:SetWantsEvents(false); -- we don't want to save eventHandlers[].func values
278 Thurallor-7095
    DeepTableCopy(self.settings, exportObjects[self.objectID]);
279 Thurallor-7095
    self:SetWantsEvents(self.settings.eventsEnabled);
280 Thurallor-7095
    self:StripSettingsForExport(exportObjects[self.objectID]);
281 Thurallor-7095
    if (self:CanHaveChildren()) then
282 Thurallor-7095
        local descendentIDs = self:FindAllDescendentIDs(nil, true, true);
283 Thurallor-7095
        for d = 1, #descendentIDs do
284 Thurallor-7095
            local objectID = descendentIDs[d];
285 Thurallor-7095
            local object = self.manager.objects[objectID];
286 Thurallor-7095
            exportObjects[objectID] = {};
287 Thurallor-7095
            object:SetWantsEvents(false); -- we don't want to save eventHandlers[].func values
288 Thurallor-7095
            DeepTableCopy(object.settings, exportObjects[objectID]);
289 Thurallor-7095
            object:SetWantsEvents(object.settings.eventsEnabled);
290 Thurallor-7095
            self:StripSettingsForExport(exportObjects[objectID]);
291 Thurallor-7095
        end
292 Thurallor-7095
    end
293 Thurallor-7095
 
294 Thurallor-7095
    -- Create the export window
295 Thurallor-7095
    local title = L:GetText("/ExportWindow/Title");
296 Thurallor-7095
    title = string.gsub(title, "<name>", self.settings.caption.text);
297 Thurallor-7095
    self.exportWindow = ExportWindow(title, exportObjects);
298 Thurallor-7095
    self.exportWindow.Closing = function()
299 Thurallor-7095
        self.exportWindow = nil;
300 Thurallor-7095
    end
301 Thurallor-7095
end
302 Thurallor-7095
 
303 Thurallor-7095
function Node:ShowSettingsMenu(fromOptionsPanel)
304 Thurallor-7095
    -- Build the settings menu.
305 18 Thurallor-7095
    self.settingsMenu = Turbine.UI.ContextMenu();
306 8 Thurallor-7095
    self.amSubMenu = false;
307 Thurallor-7095
    self:AddSettingsMenuItem(self.settingsMenu, "Root", fromOptionsPanel);
308 Thurallor-7095
    self.settingsMenu:ShowMenu();
309 Thurallor-7095
end
310 Thurallor-7095
 
311 Thurallor-7095
function Node:Destroy()
312 Thurallor-7095
    self:SetWantsEvents(false);
313 34 Thurallor-7095
    self:SetWantsUpdates(false);
314 8 Thurallor-7095
    if (self.settingsMenu) then
315 Thurallor-7095
        self.settingsMenu:Close();
316 Thurallor-7095
    end
317 Thurallor-7095
    if (self.captionEditor) then
318 Thurallor-7095
        self.captionEditor:Close();
319 Thurallor-7095
    end
320 Thurallor-7095
    if (self.exportWindow) then
321 Thurallor-7095
        self.exportWindow:Close();
322 Thurallor-7095
    end
323 Thurallor-7095
    if (self.importWindow) then
324 Thurallor-7095
        self.importWindow:Close();
325 Thurallor-7095
    end
326 Thurallor-7095
    if (self.colorPicker) then
327 Thurallor-7095
        self.colorPicker:Close();
328 Thurallor-7095
    end
329 Thurallor-7095
    self.manager.objects[self.objectID] = nil;
330 121 Thurallor-7095
    if (self.Log) then
331 Thurallor-7095
        DoCallbacks(self, "Log", {"destroyed", string.upper(self.settings.type)});
332 Thurallor-7095
    end
333 8 Thurallor-7095
    self:Close();
334 Thurallor-7095
end

All times are GMT -5. The time now is 06:11 PM.


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