lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

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

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 Thurallor-7095
        self.settings.hidden = hide;
15 Thurallor-7095
        self:ApplyHiddenness();
16 Thurallor-7095
        if (self.HiddenChanged) then
17 Thurallor-7095
            self:HiddenChanged();
18 Thurallor-7095
        end
19 12 Thurallor-7095
    end
20 8 Thurallor-7095
end
21 Thurallor-7095
 
22 Thurallor-7095
function Node:SaveSettings(updateOptionsPanel)
23 Thurallor-7095
    if (not self.constructing) then
24 Thurallor-7095
        self.parent:SaveSettings(updateOptionsPanel);
25 Thurallor-7095
    end
26 Thurallor-7095
end
27 Thurallor-7095
 
28 Thurallor-7095
function Node:EditColor()
29 Thurallor-7095
    if (self.colorPicker == nil) then
30 Thurallor-7095
        self.previousColor = self.color;
31 Thurallor-7095
        self.colorPicker = Thurallor.UI.ColorPicker(self.color, "H");
32 Thurallor-7095
        self.colorPicker:SetZOrder(self:GetZOrder() + 10);
33 Thurallor-7095
        self.colorPicker.ColorChanged = function(picker)
34 Thurallor-7095
            self:SetColor(picker:GetColor());
35 Thurallor-7095
        end
36 Thurallor-7095
        self.colorPicker.Accepted = function()
37 Thurallor-7095
            self.colorPicker = nil;
38 Thurallor-7095
            self:SaveSettings(true);
39 Thurallor-7095
        end
40 Thurallor-7095
        self.colorPicker.Canceled = function()
41 Thurallor-7095
            self:SetColor(self.previousColor);
42 Thurallor-7095
            self.colorPicker = nil;
43 Thurallor-7095
        end
44 Thurallor-7095
    end
45 Thurallor-7095
end
46 Thurallor-7095
 
47 Thurallor-7095
function Node:SetColor(color)
48 Thurallor-7095
    self.color = color;
49 Thurallor-7095
    self.settings.color = color:GetHex();
50 Thurallor-7095
    self:SaveSettings(true);
51 Thurallor-7095
end
52 Thurallor-7095
 
53 Thurallor-7095
function Node:GetID()
54 Thurallor-7095
    return self.objectID;
55 Thurallor-7095
end
56 Thurallor-7095
 
57 Thurallor-7095
function Node:GetName()
58 Thurallor-7095
    return self.settings.caption.text;
59 Thurallor-7095
end
60 Thurallor-7095
 
61 Thurallor-7095
function Node:SetName(newName)
62 Thurallor-7095
    self.settings.caption.text = newName;
63 Thurallor-7095
    self:SaveSettings(true);
64 Thurallor-7095
end
65 Thurallor-7095
 
66 Thurallor-7095
function Node:SetCaptionSize(width, height)
67 Thurallor-7095
    self.settings.caption.width = width;
68 Thurallor-7095
    self.settings.caption.height = height;
69 Thurallor-7095
    self:SaveSettings(false);
70 Thurallor-7095
end
71 Thurallor-7095
 
72 Thurallor-7095
function Node:GetColor()
73 Thurallor-7095
    return self.color;
74 Thurallor-7095
end
75 Thurallor-7095
 
76 Thurallor-7095
function Node:SetWantsEvents(enable)
77 Thurallor-7095
    for h = 1, #self.settings.eventHandlers, 1 do
78 Thurallor-7095
        local handler = self.settings.eventHandlers[h];
79 Thurallor-7095
        local object = loadstring("self = ...; return " .. handler.object)(self);
80 Thurallor-7095
        local trigger = handler.trigger;
81 Thurallor-7095
        if (enable) then
82 Thurallor-7095
            -- Should save this function reference as handler.func, so we can pass the same reference to RemoveCallback().
83 Thurallor-7095
            local funcBody = loadstring(handler.action);
84 Thurallor-7095
            handler.func = function(sender, args)
85 Thurallor-7095
                funcBody(self, object, trigger, args);
86 Thurallor-7095
            end;
87 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Compiled handler.action = " .. Serialize(handler.action) .. " into " .. Serialize(handler.func));
88 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Registering event handler " .. Serialize(handler.description) .. " (" .. Serialize(handler.func) .. ")");
89 Thurallor-7095
            AddCallback(object, trigger, handler.func);
90 Thurallor-7095
        else
91 Thurallor-7095
--Puts("Node " .. Serialize(self.settings.caption.text) .. ": Unregistering event handler: " .. Serialize(handler.description) .. " (" .. Serialize(handler.func) .. ")");
92 Thurallor-7095
            RemoveCallback(object, trigger, handler.func);
93 Thurallor-7095
            handler.func = nil;
94 Thurallor-7095
        end
95 Thurallor-7095
    end
96 Thurallor-7095
end
97 Thurallor-7095
 
98 Thurallor-7095
function Node:AddEventHandler(trigger, action)
99 Thurallor-7095
    self:SetWantsEvents(false);
100 20 Thurallor-7095
    local prevContext = L:SetContext("/EventBehaviorsMenu");
101 8 Thurallor-7095
 
102 Thurallor-7095
    -- Initialize action
103 Thurallor-7095
    local handler = {};
104 Thurallor-7095
    handler.action = "";
105 Thurallor-7095
    if ((action == "ShowGroup") or (action == "ShowBar")) then
106 29 Thurallor-7095
        handler.action = "self:SetHidden(false); ";
107 8 Thurallor-7095
    elseif ((action == "HideGroup") or (action == "HideBar")) then
108 Thurallor-7095
        handler.action = "self:SetHidden(true); ";
109 Thurallor-7095
    elseif ((action == "ResetGroup") or (action == "ResetBar")) then
110 Thurallor-7095
        handler.action = "self:Reset(); ";
111 Thurallor-7095
    elseif (action == "MoveToCursor") then
112 29 Thurallor-7095
        handler.action = "self:MoveToMouseCursor(); ";
113 26 Thurallor-7095
    elseif ((action == "ExpandGroup") or (action == "ExpandBar")) then
114 29 Thurallor-7095
        handler.action = "self:Expand(); ";
115 26 Thurallor-7095
    elseif ((action == "CollapseGroup") or (action == "CollapseBar")) then
116 Thurallor-7095
        handler.action = "self:Collapse(); ";
117 43 Thurallor-7095
    elseif (action == "StopExecuting") then
118 Thurallor-7095
        handler.action = "self:StopExecuting(); ";
119 Thurallor-7095
    elseif (action == "StartExecuting") then
120 Thurallor-7095
        handler.action = "self:StartExecuting(); ";
121 8 Thurallor-7095
    else
122 Thurallor-7095
        error("Unknown event handler action: " .. tostring(action), 2);
123 Thurallor-7095
    end
124 20 Thurallor-7095
    handler.description = L:GetText("Actions/" .. action) .. " " .. L:GetText("Triggers/" .. trigger);
125 8 Thurallor-7095
 
126 Thurallor-7095
    -- Add object, trigger, action, description
127 Thurallor-7095
    if (trigger == "AtStartup") then
128 Thurallor-7095
        handler.object = "self.manager:GetEventCallbacks()";
129 Thurallor-7095
        handler.trigger = "Startup\n"; -- includes "\n" so it can't be generated by user
130 Thurallor-7095
        handler.action =
131 20 Thurallor-7095
            "self = ...; " ..
132 8 Thurallor-7095
            handler.action;
133 43 Thurallor-7095
    elseif (trigger == "WhenTargetChanges") then
134 Thurallor-7095
        handler.object = "self.manager.watcher";
135 Thurallor-7095
        handler.trigger = "PlayerTargetChanged";
136 Thurallor-7095
        handler.action =
137 Thurallor-7095
            "self = ...; " ..
138 Thurallor-7095
            handler.action;
139 8 Thurallor-7095
    elseif (trigger == "WhenCombatBegins") then
140 43 Thurallor-7095
        handler.object = "self.manager.player";
141 8 Thurallor-7095
        handler.trigger = "InCombatChanged";
142 Thurallor-7095
        handler.action =
143 Thurallor-7095
            "self, object = ...; " ..
144 Thurallor-7095
            "if (object:IsInCombat()) then " ..
145 Thurallor-7095
                handler.action ..
146 Thurallor-7095
            "end";
147 Thurallor-7095
    elseif (trigger == "WhenCombatEnds") then
148 43 Thurallor-7095
        handler.object = "self.manager.player";
149 8 Thurallor-7095
        handler.trigger = "InCombatChanged";
150 Thurallor-7095
        handler.action =
151 Thurallor-7095
            "self, object = ...; " ..
152 Thurallor-7095
            "if (not object:IsInCombat()) then " ..
153 Thurallor-7095
                handler.action ..
154 Thurallor-7095
            "end";
155 20 Thurallor-7095
    elseif (trigger == "WhenMouseArrives") then
156 Thurallor-7095
        handler.object = "self";
157 Thurallor-7095
        handler.trigger = "MouseArrived";
158 Thurallor-7095
        handler.action =
159 Thurallor-7095
            "self = ...; " ..
160 Thurallor-7095
            handler.action;
161 Thurallor-7095
    elseif (trigger == "WhenMouseDeparts") then
162 Thurallor-7095
        handler.object = "self";
163 Thurallor-7095
        handler.trigger = "MouseDeparted";
164 Thurallor-7095
        handler.action =
165 Thurallor-7095
            "self = ...; " ..
166 Thurallor-7095
            handler.action;
167 8 Thurallor-7095
    elseif (string.find(trigger, "WhenEventOccurs:")) then
168 Thurallor-7095
        local eventName = string.sub(trigger, 17);
169 Thurallor-7095
        handler.object = "self.manager:GetEventCallbacks()";
170 Thurallor-7095
        handler.trigger = eventName;
171 Thurallor-7095
        handler.action =
172 20 Thurallor-7095
            "self = ...; " ..
173 8 Thurallor-7095
            handler.action;
174 20 Thurallor-7095
        handler.description = L:GetText("Actions/" .. action) .. " " .. L:GetText("Triggers/WhenEventOccurs") .. ": " .. eventName;
175 35 Thurallor-7095
    elseif (trigger == "WhenTraitTreeChanges") then
176 Thurallor-7095
        handler.object = "self.manager.watcher";
177 Thurallor-7095
        handler.trigger = "TraitTreeChanged";
178 Thurallor-7095
        handler.action =
179 Thurallor-7095
            "self = ...; " ..
180 Thurallor-7095
            handler.action;
181 111 Thurallor-7095
    elseif (trigger == "WhenStanceChanges") then
182 Thurallor-7095
        handler.object = "self.manager.watcher";
183 Thurallor-7095
        handler.trigger = "PlayerStanceChanged";
184 Thurallor-7095
        handler.action =
185 Thurallor-7095
            "self = ...; " ..
186 Thurallor-7095
            handler.action;
187 8 Thurallor-7095
    else
188 Thurallor-7095
        error("Unknown event handler trigger: " .. tostring(trigger), 2);
189 Thurallor-7095
    end
190 Thurallor-7095
    L:SetContext(prevContext);
191 Thurallor-7095
 
192 Thurallor-7095
    -- Save new event handler and activate it
193 Thurallor-7095
    table.insert(self.settings.eventHandlers, handler);
194 Thurallor-7095
    self:SaveSettings(false);
195 Thurallor-7095
    self:SetWantsEvents(true);
196 Thurallor-7095
end
197 Thurallor-7095
 
198 Thurallor-7095
function Node:RemoveEventHandler(h)
199 Thurallor-7095
    self:SetWantsEvents(false);
200 Thurallor-7095
    table.remove(self.settings.eventHandlers, h);
201 Thurallor-7095
    self:SaveSettings(false);
202 Thurallor-7095
    self:SetWantsEvents(true);
203 Thurallor-7095
end
204 Thurallor-7095
 
205 Thurallor-7095
function Node:StripSettingsForExport(settings)
206 Thurallor-7095
    settings.deletedBarIDs = nil;
207 Thurallor-7095
    settings.deletedGroupIDs = nil;
208 Thurallor-7095
end
209 Thurallor-7095
 
210 Thurallor-7095
function Node:Export()
211 Thurallor-7095
    if (self.exportWindow) then
212 Thurallor-7095
        self.exportWindow:Close();
213 Thurallor-7095
        self.exportWindow = nil;
214 Thurallor-7095
    end
215 Thurallor-7095
 
216 Thurallor-7095
    -- Compile the data to be exported
217 Thurallor-7095
    Puts(L:GetText("/ExportWindow/Exporting"));
218 Thurallor-7095
    local exportObjects = { [self.objectID] = {} };
219 Thurallor-7095
    self:SetWantsEvents(false); -- we don't want to save eventHandlers[].func values
220 Thurallor-7095
    DeepTableCopy(self.settings, exportObjects[self.objectID]);
221 Thurallor-7095
    self:SetWantsEvents(self.settings.eventsEnabled);
222 Thurallor-7095
    self:StripSettingsForExport(exportObjects[self.objectID]);
223 Thurallor-7095
    if (self:CanHaveChildren()) then
224 Thurallor-7095
        local descendentIDs = self:FindAllDescendentIDs(nil, true, true);
225 Thurallor-7095
        for d = 1, #descendentIDs do
226 Thurallor-7095
            local objectID = descendentIDs[d];
227 Thurallor-7095
            local object = self.manager.objects[objectID];
228 Thurallor-7095
            exportObjects[objectID] = {};
229 Thurallor-7095
            object:SetWantsEvents(false); -- we don't want to save eventHandlers[].func values
230 Thurallor-7095
            DeepTableCopy(object.settings, exportObjects[objectID]);
231 Thurallor-7095
            object:SetWantsEvents(object.settings.eventsEnabled);
232 Thurallor-7095
            self:StripSettingsForExport(exportObjects[objectID]);
233 Thurallor-7095
        end
234 Thurallor-7095
    end
235 Thurallor-7095
 
236 Thurallor-7095
    -- Create the export window
237 Thurallor-7095
    local title = L:GetText("/ExportWindow/Title");
238 Thurallor-7095
    title = string.gsub(title, "<name>", self.settings.caption.text);
239 Thurallor-7095
    self.exportWindow = ExportWindow(title, exportObjects);
240 Thurallor-7095
    self.exportWindow.Closing = function()
241 Thurallor-7095
        self.exportWindow = nil;
242 Thurallor-7095
    end
243 Thurallor-7095
end
244 Thurallor-7095
 
245 Thurallor-7095
function Node:ShowSettingsMenu(fromOptionsPanel)
246 Thurallor-7095
    -- Build the settings menu.
247 18 Thurallor-7095
    self.settingsMenu = Turbine.UI.ContextMenu();
248 8 Thurallor-7095
    self.amSubMenu = false;
249 Thurallor-7095
    self:AddSettingsMenuItem(self.settingsMenu, "Root", fromOptionsPanel);
250 Thurallor-7095
    self.settingsMenu:ShowMenu();
251 Thurallor-7095
end
252 Thurallor-7095
 
253 Thurallor-7095
function Node:Destroy()
254 Thurallor-7095
    self:SetWantsEvents(false);
255 34 Thurallor-7095
    self:SetWantsUpdates(false);
256 8 Thurallor-7095
    if (self.settingsMenu) then
257 Thurallor-7095
        self.settingsMenu:Close();
258 Thurallor-7095
    end
259 Thurallor-7095
    if (self.captionEditor) then
260 Thurallor-7095
        self.captionEditor:Close();
261 Thurallor-7095
    end
262 Thurallor-7095
    if (self.exportWindow) then
263 Thurallor-7095
        self.exportWindow:Close();
264 Thurallor-7095
    end
265 Thurallor-7095
    if (self.importWindow) then
266 Thurallor-7095
        self.importWindow:Close();
267 Thurallor-7095
    end
268 Thurallor-7095
    if (self.colorPicker) then
269 Thurallor-7095
        self.colorPicker:Close();
270 Thurallor-7095
    end
271 Thurallor-7095
    self.manager.objects[self.objectID] = nil;
272 Thurallor-7095
    self:Close();
273 Thurallor-7095
end

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


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