lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

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

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

All times are GMT -5. The time now is 08:52 PM.


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