lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [Manager.lua] - Blame information for rev 23

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Thurallor-7095
Manager = class(Group);
2 Thurallor-7095
 
3 Thurallor-7095
function Manager:Constructor()
4 Thurallor-7095
    Turbine.UI.Window.Constructor(self);
5 Thurallor-7095
    self.constructing = true;
6 Thurallor-7095
 
7 Thurallor-7095
    self.manager = self;
8 20 Thurallor-7095
    self.watcher = Thurallor.Utils.Watcher;
9 2 Thurallor-7095
    self.groupID = "0";
10 Thurallor-7095
 
11 Thurallor-7095
    self.objects = {};
12 Thurallor-7095
    self.eventGenerators = {};
13 Thurallor-7095
    self.eventCallbacks = {};
14 16 Thurallor-7095
    self.propagatingEvent = {};
15 2 Thurallor-7095
    self.lastSaveTime = 0;
16 12 Thurallor-7095
    self.player = Turbine.Gameplay.LocalPlayer:GetInstance();
17 Thurallor-7095
    self.username = self.player:GetName();
18 6 Thurallor-7095
    self.preferredBagSlot = 1;
19 13 Thurallor-7095
    self.hudVisible = true;
20 16 Thurallor-7095
    self.includees = {};
21 Thurallor-7095
    self.includers = {};
22 2 Thurallor-7095
 
23 Thurallor-7095
    -- Default settings
24 Thurallor-7095
    self.settings = {};
25 Thurallor-7095
    self.settings.type = "group";
26 Thurallor-7095
    self.settings.caption = {};
27 Thurallor-7095
    self.settings.snapToGrid = false;
28 Thurallor-7095
    self.settings.gridSize = 35;
29 Thurallor-7095
    self.settings.language = Turbine.Engine:GetLanguage();
30 Thurallor-7095
    local name = L:GetText("/Default/GlobalName");
31 Thurallor-7095
    self.settings.caption.text = string.gsub(name, "<name>", self.username);
32 Thurallor-7095
    self.settings.caption.width = 80;
33 Thurallor-7095
    self.settings.caption.height = 20;
34 Thurallor-7095
    self.settings.caption.font = Turbine.UI.Lotro.Font.TrajanPro15;
35 Thurallor-7095
    self.settings.color = "FFFFFF";
36 Thurallor-7095
    self.settings.barIDs = {};
37 Thurallor-7095
    self.settings.groupIDs = { "new" };
38 Thurallor-7095
    self.settings.deletedBarIDs = {};
39 Thurallor-7095
    self.settings.deletedGroupIDs = {};
40 Thurallor-7095
    self.settings.eventHandlers = {};
41 Thurallor-7095
    self.settings.eventsEnabled = false;
42 Thurallor-7095
    self.settings.groups = {};
43 Thurallor-7095
    self.settings.bars = {};
44 Thurallor-7095
    self.settings.nextObjectID = 1;
45 16 Thurallor-7095
    self.settings.pluginVersion = plugin:GetVersion();
46 Thurallor-7095
    self.settings.uiScale = 32; -- zoom level will be applied to make quickslots this size
47 Thurallor-7095
    self.settings.uiOpacity = 1.0;
48 2 Thurallor-7095
 
49 Thurallor-7095
    self.globals = self.settings;
50 Thurallor-7095
    self:LoadSettings();
51 Thurallor-7095
end
52 Thurallor-7095
 
53 Thurallor-7095
function Manager:LoadSettings()
54 Thurallor-7095
    Turbine.PluginData.Load(Turbine.DataScope.Character, "SequenceBars", function(loadStr)
55 Thurallor-7095
        if (loadStr) then
56 Thurallor-7095
            -- Workaround for Turbine localization bug -- Thanks, Lynx3d!
57 Thurallor-7095
            local settings = ImportTable(loadStr);
58 Thurallor-7095
            if (not settings) then
59 Thurallor-7095
                Turbine.Shell.WriteLine("Failed to parse SequenceBars.plugindata file!");
60 Thurallor-7095
                return;
61 Thurallor-7095
            end
62 Thurallor-7095
 
63 Thurallor-7095
            -- Previously-saved settings override the defaults
64 Thurallor-7095
            DeepTableCopy(settings, self.settings);
65 Thurallor-7095
        end
66 Thurallor-7095
 
67 Thurallor-7095
        -- Make color object from hex string
68 Thurallor-7095
        self.color = Thurallor.Utils.Color(1, 0, 0, 0);
69 Thurallor-7095
        self.color:SetHex(self.settings.color);
70 13 Thurallor-7095
 
71 2 Thurallor-7095
        -- Select language
72 18 Thurallor-7095
        self:SetLanguage(self.settings.language);
73 2 Thurallor-7095
 
74 Thurallor-7095
        self:LoadBars();
75 Thurallor-7095
        self:LoadGroups();
76 Thurallor-7095
        self:UpdateOptionsPanel();
77 7 Thurallor-7095
        self.settings.pluginVersion = tonumber(Plugins.SequenceBars:GetVersion());
78 2 Thurallor-7095
        self.constructing = nil;
79 7 Thurallor-7095
 
80 13 Thurallor-7095
        self:SetWantsKeyEvents(true);
81 16 Thurallor-7095
        self:SetWantsEvents(self.settings.eventsEnabled);
82 Thurallor-7095
 
83 Thurallor-7095
        self.displaySizeCallback = function(display)
84 Thurallor-7095
            self:Redraw();
85 Thurallor-7095
        end
86 Thurallor-7095
        AddCallback(Turbine.UI.Display, "SizeChanged", self.displaySizeCallback);
87 Thurallor-7095
 
88 7 Thurallor-7095
        self:PropagateEvent("Startup\n");
89 2 Thurallor-7095
    end);
90 Thurallor-7095
end
91 Thurallor-7095
 
92 Thurallor-7095
function Manager:Unload()
93 Thurallor-7095
    self.lastSaveTime = 0;
94 Thurallor-7095
    self.constructing = false;
95 Thurallor-7095
    self.editingCaption = true;
96 Thurallor-7095
    self.lastSaveTime = 0; -- force save
97 Thurallor-7095
    self:SaveSettings(false);
98 Thurallor-7095
    for objectID, object in pairs(self.objects) do
99 Thurallor-7095
--Puts("Destroying object " .. tostring(objectID));
100 Thurallor-7095
        if (object) then
101 Thurallor-7095
            object:Destroy();
102 Thurallor-7095
        end
103 Thurallor-7095
    end
104 Thurallor-7095
end
105 Thurallor-7095
 
106 Thurallor-7095
function Manager:SaveSettings(updateOptionsPanel)
107 Thurallor-7095
    if (updateOptionsPanel) then
108 Thurallor-7095
        self.updateOptionsPanel = true;
109 Thurallor-7095
    end
110 Thurallor-7095
    if (not self.constructing) then
111 Thurallor-7095
        -- Start the idle timer.
112 16 Thurallor-7095
        self.idleTime = Turbine.Engine.GetGameTime() + 0.25;
113 Thurallor-7095
        self.AfterIdle = self.DoSave;
114 2 Thurallor-7095
        self:SetWantsUpdates(true);
115 Thurallor-7095
    end
116 Thurallor-7095
end
117 Thurallor-7095
 
118 Thurallor-7095
function Manager:Update()
119 Thurallor-7095
    -- Save will only occur when idle time reaches 0.25 s.
120 Thurallor-7095
    local currentTime = Turbine.Engine.GetGameTime();
121 16 Thurallor-7095
    if (currentTime < self.idleTime) then
122 2 Thurallor-7095
        return;
123 Thurallor-7095
    end
124 16 Thurallor-7095
    self:AfterIdle();
125 Thurallor-7095
    self:SetWantsUpdates(false);
126 Thurallor-7095
end
127 2 Thurallor-7095
 
128 16 Thurallor-7095
function Manager:DoSave()
129 2 Thurallor-7095
--Puts("Saving...");
130 Thurallor-7095
    -- Workaround for Turbine localization bug -- Thanks, Lynx3d!
131 Thurallor-7095
    local saveData = ExportTable(self.settings);
132 Thurallor-7095
    Turbine.PluginData.Save(Turbine.DataScope.Character, "SequenceBars", saveData, function()
133 Thurallor-7095
--Puts("Save complete.");
134 Thurallor-7095
    end);
135 Thurallor-7095
 
136 Thurallor-7095
    if (self.updateOptionsPanel and (not self.editingCaption)) then
137 Thurallor-7095
        self:UpdateOptionsPanel();
138 Thurallor-7095
        self.updateOptionsPanel = false;
139 Thurallor-7095
    end
140 Thurallor-7095
end
141 Thurallor-7095
 
142 Thurallor-7095
function Manager:UpdateOptionsPanel()
143 Thurallor-7095
    if (not self.optionsPanel) then
144 Thurallor-7095
        self.optionsPanel = OptionsPanel(self);
145 Thurallor-7095
    end
146 12 Thurallor-7095
    self.optionsPanel:RefreshDirectory();
147 2 Thurallor-7095
end
148 Thurallor-7095
 
149 13 Thurallor-7095
function Manager:KeyDown(args)
150 Thurallor-7095
    if (args.Action == Turbine.UI.Lotro.Action.ToggleHUD) then
151 Thurallor-7095
        self.hudVisible = not self.hudVisible;
152 Thurallor-7095
        self:ApplyHiddenness();
153 Thurallor-7095
    end
154 Thurallor-7095
end
155 Thurallor-7095
 
156 Thurallor-7095
function Manager:IsParentHidden()
157 Thurallor-7095
    return (not self.hudVisible);
158 Thurallor-7095
end
159 Thurallor-7095
 
160 7 Thurallor-7095
function Manager:ShellCommand(cmd, args)
161 Thurallor-7095
    if (string.match(args, "^" .. L:GetText("/ShellCommand/Options"))) then
162 13 Thurallor-7095
        self.optionsPanel:ShowGlobalSettings();
163 7 Thurallor-7095
    elseif (string.match(args, "^" .. L:GetText("/ShellCommand/Events"))) then
164 Thurallor-7095
        local eventNames = self:GetEventNames();
165 Thurallor-7095
        if (#eventNames > 0) then
166 Thurallor-7095
            Puts(table.concat(eventNames, "\n"));
167 Thurallor-7095
        end
168 Thurallor-7095
    elseif (string.match(args, "^" .. L:GetText("/ShellCommand/Event"))) then
169 Thurallor-7095
        local eventName = string.sub(args, string.find(args, " ") + 1);
170 Thurallor-7095
        Puts(" -> \"" .. eventName .. "\"");
171 Thurallor-7095
        self:PropagateEvent(eventName);
172 Thurallor-7095
    end
173 Thurallor-7095
end
174 Thurallor-7095
 
175 2 Thurallor-7095
function Manager:FindNewObjectID()
176 Thurallor-7095
    local id = self.settings.nextObjectID;
177 Thurallor-7095
    self.settings.nextObjectID = id + 1;
178 Thurallor-7095
    id = self.username .. "." .. tostring(id);
179 Thurallor-7095
    self.objects[id] = { "reserved" };
180 Thurallor-7095
    return id;
181 Thurallor-7095
end
182 Thurallor-7095
 
183 16 Thurallor-7095
function Manager:GetObject(objectID)
184 Thurallor-7095
    return self.objects[objectID];
185 Thurallor-7095
end
186 Thurallor-7095
 
187 2 Thurallor-7095
function Manager:TransferBar(barID, oldGroup, newGroup)
188 20 Thurallor-7095
    local foundPos = Search(oldGroup.settings.barIDs, barID);
189 2 Thurallor-7095
    if (foundPos) then
190 Thurallor-7095
        table.remove(oldGroup.settings.barIDs, foundPos);
191 Thurallor-7095
        table.insert(newGroup.settings.barIDs, barID);
192 Thurallor-7095
        local bar = self.objects[barID];
193 Thurallor-7095
        bar.parent = newGroup;
194 Thurallor-7095
        self:SaveSettings(true);
195 13 Thurallor-7095
        newGroup:ApplyHiddenness();
196 2 Thurallor-7095
    end
197 Thurallor-7095
end
198 Thurallor-7095
 
199 Thurallor-7095
function Manager:TransferGroup(groupID, oldGroup, newGroup)
200 20 Thurallor-7095
    local foundPos = Search(oldGroup.settings.groupIDs, groupID);
201 2 Thurallor-7095
    if (foundPos) then
202 Thurallor-7095
        table.remove(oldGroup.settings.groupIDs, foundPos);
203 Thurallor-7095
        table.insert(newGroup.settings.groupIDs, groupID);
204 Thurallor-7095
        local group = self.objects[groupID];
205 Thurallor-7095
        group.parent = newGroup;
206 Thurallor-7095
        self:SaveSettings(true);
207 13 Thurallor-7095
        newGroup:ApplyHiddenness();
208 2 Thurallor-7095
    end
209 Thurallor-7095
end
210 Thurallor-7095
 
211 Thurallor-7095
function Manager:EmptyTrash()
212 Thurallor-7095
    self.settings.deletedGroupIDs = {};
213 Thurallor-7095
    for groupID, settings in pairs(self.settings.groups) do
214 Thurallor-7095
        settings.deletedGroupIDs = {};
215 Thurallor-7095
        settings.deletedBarIDs = {};
216 Thurallor-7095
        if (not self.objects[groupID]) then
217 Thurallor-7095
            self.settings.groups[groupID] = nil;
218 Thurallor-7095
        end
219 Thurallor-7095
    end
220 7 Thurallor-7095
    self.settings.deletedBarIDs = {};
221 2 Thurallor-7095
    for barID, bar in pairs(self.settings.bars) do
222 Thurallor-7095
        if (not self.objects[barID]) then
223 Thurallor-7095
            self.settings.bars[barID] = nil;
224 Thurallor-7095
        end
225 Thurallor-7095
    end
226 Thurallor-7095
    self:SaveSettings(false);
227 Thurallor-7095
end
228 Thurallor-7095
 
229 5 Thurallor-7095
function Manager:ShowSettingsMenu(fromOptionsPanel)
230 2 Thurallor-7095
    -- Build the settings menu.
231 18 Thurallor-7095
    self.settingsMenu = Turbine.UI.ContextMenu();
232 5 Thurallor-7095
    Group.AddSettingsMenuItem(self, self.settingsMenu, "Root", fromOptionsPanel);
233 2 Thurallor-7095
    self.amSubMenu = false;
234 Thurallor-7095
    self:AddSettingsMenuItem(self.settingsMenu, "Root");
235 Thurallor-7095
    self.settingsMenu:ShowMenu();
236 Thurallor-7095
end
237 Thurallor-7095
 
238 Thurallor-7095
function Manager:AddSettingsMenuItem(parent, itemName, amSubMenu)
239 Thurallor-7095
    if (amSubMenu ~= nil) then
240 Thurallor-7095
        self.amSubMenu = amSubMenu;
241 Thurallor-7095
    end
242 Thurallor-7095
    local item = Turbine.UI.MenuItem(L:GetText(itemName), true, false);
243 Thurallor-7095
    parent:GetItems():Add(item);
244 18 Thurallor-7095
 
245 2 Thurallor-7095
    if (itemName == "Root") then
246 Thurallor-7095
        local prevContext = L:SetContext("/GlobalMenu");
247 Thurallor-7095
        parent:GetItems():Clear();
248 Thurallor-7095
        self:AddSettingsMenuItem(parent, "HideAll");
249 Thurallor-7095
        if (not self.amSubMenu) then
250 Thurallor-7095
            L:SetContext("/GroupMenu");
251 Thurallor-7095
            Group.AddSettingsMenuItem(self, parent, "CreateNewBar");
252 Thurallor-7095
            Group.AddSettingsMenuItem(self, parent, "CreateNewSubgroup");
253 Thurallor-7095
            Group.AddSettingsMenuItem(self, parent, "Import");
254 Thurallor-7095
        end
255 Thurallor-7095
        if (#self.settings.deletedBarIDs + #self.settings.deletedGroupIDs > 0) then
256 Thurallor-7095
            self:AddSettingsMenuItem(parent, "Undelete");
257 Thurallor-7095
        end
258 Thurallor-7095
        L:SetContext("/GroupMenu");
259 Thurallor-7095
        Group.AddSettingsMenuItem(self, parent, "ArrangeBars");
260 12 Thurallor-7095
        Group.AddSettingsMenuItem(self, parent, "GlobalEventBehaviors");
261 2 Thurallor-7095
        L:SetContext("/GlobalMenu");
262 Thurallor-7095
        self:AddSettingsMenuItem(parent, "GlobalSettings");
263 Thurallor-7095
        if (self:HaveTrash()) then
264 Thurallor-7095
            self:AddSettingsMenuItem(parent, "EmptyTrash");
265 Thurallor-7095
        end
266 Thurallor-7095
        L:SetContext(prevContext);
267 Thurallor-7095
    elseif (itemName == "HideAll") then
268 Thurallor-7095
        item:SetChecked(self.settings.hidden);
269 Thurallor-7095
        item.Click = function(sender, args)
270 Thurallor-7095
            self:SetHidden(not self.settings.hidden);
271 Thurallor-7095
        end
272 Thurallor-7095
    elseif (itemName == "GlobalSettings") then
273 Thurallor-7095
        item.Click = function(sender, args)
274 12 Thurallor-7095
            self.optionsPanel:ShowGlobalSettings();
275 2 Thurallor-7095
        end
276 Thurallor-7095
    elseif (itemName == "EmptyTrash") then
277 Thurallor-7095
        item.Click = function(sender, args)
278 Thurallor-7095
            self:EmptyTrash();
279 Thurallor-7095
        end
280 Thurallor-7095
    else
281 Thurallor-7095
        -- Item is not handled here; send it to Group:AddSettingsMenuItem().
282 Thurallor-7095
        parent:GetItems():RemoveAt(parent:GetItems():GetCount());
283 Thurallor-7095
        Group.AddSettingsMenuItem(self, parent, itemName, true);
284 Thurallor-7095
    end
285 Thurallor-7095
end
286 Thurallor-7095
 
287 Thurallor-7095
function Manager:GetNearestGridPos(left, top)
288 16 Thurallor-7095
    local gridSize = math.floor(0.5 + self.settings.gridSize * (self.settings.uiScale / 32));
289 2 Thurallor-7095
    local displayBottom = Turbine.UI.Display:GetHeight() - 1;
290 Thurallor-7095
    local centerLeft = math.floor(0.5 + Turbine.UI.Display:GetWidth() / 2 + gridSize / 2) + 3;
291 Thurallor-7095
    local offsetLeft, offsetTop = left - centerLeft, displayBottom - top;
292 Thurallor-7095
    local newLeft = centerLeft + math.floor(0.5 + offsetLeft / gridSize) * gridSize;
293 Thurallor-7095
    local newTop = displayBottom - math.floor(0.5 + offsetTop / gridSize) * gridSize;
294 16 Thurallor-7095
    return newLeft, newTop, gridSize;
295 2 Thurallor-7095
end
296 Thurallor-7095
 
297 6 Thurallor-7095
function Manager:SetUnequipDestination(bagSlot)
298 Thurallor-7095
    self.preferredBagSlot = bagSlot;
299 Thurallor-7095
end
300 Thurallor-7095
 
301 20 Thurallor-7095
function Manager:Unequip(itemSlot)
302 Thurallor-7095
    local lp = Turbine.Gameplay.LocalPlayer:GetInstance();
303 Thurallor-7095
    local equippedItems = lp:GetEquipment();
304 Thurallor-7095
    local item = equippedItems:GetItem(itemSlot);
305 Thurallor-7095
    if (item ~= nil) then
306 Thurallor-7095
        _G.Unequip(itemSlot, "*", self.preferredBagSlot);
307 Thurallor-7095
    end
308 Thurallor-7095
end
309 Thurallor-7095
 
310 Thurallor-7095
-- Some trivial wrappers retained for backward compatibility
311 Thurallor-7095
function Manager:GetSkills()
312 Thurallor-7095
    return self.watcher.GetSkillsInfo();
313 Thurallor-7095
end
314 Thurallor-7095
function Manager:SkillReady(iconID)
315 Thurallor-7095
    return self.watcher.SkillReady(iconID);
316 Thurallor-7095
end
317 Thurallor-7095
function Manager:PlayerHasEffectCategory(category)
318 Thurallor-7095
    return self.watcher.PlayerHasEffectCategory(category);
319 Thurallor-7095
end
320 Thurallor-7095
function Manager:TargetHasEffectCategory(category)
321 Thurallor-7095
    return self.watcher.TargetHasEffectCategory(category);
322 Thurallor-7095
end
323 Thurallor-7095
 
324 12 Thurallor-7095
function Manager:SetLanguage(language)
325 Thurallor-7095
    self.settings.language = language;
326 Thurallor-7095
    L:SetLanguage(language);
327 18 Thurallor-7095
    if (language == Turbine.Language.Russian) then
328 Thurallor-7095
        SetCyrillicEnabled(true);
329 Thurallor-7095
        Turbine.UI.ContextMenu = Turbine.UI.ContextMenu2;
330 Thurallor-7095
        Turbine.UI.MenuItem = Turbine.UI.MenuItem2;
331 Thurallor-7095
    else
332 Thurallor-7095
        Turbine.UI.ContextMenu = Turbine.UI.ContextMenu1;
333 Thurallor-7095
        Turbine.UI.MenuItem = Turbine.UI.MenuItem1;
334 Thurallor-7095
        SetCyrillicEnabled(false);
335 Thurallor-7095
    end
336 Thurallor-7095
    if (self.optionsPanel) then
337 Thurallor-7095
        self.optionsPanel:Localize();
338 Thurallor-7095
    end
339 12 Thurallor-7095
    self:SaveSettings(false);
340 Thurallor-7095
end
341 Thurallor-7095
 
342 Thurallor-7095
function Manager:SetSnapToGrid(snapToGrid)
343 Thurallor-7095
    self.settings.snapToGrid = snapToGrid;
344 Thurallor-7095
    if (snapToGrid) then
345 Thurallor-7095
        self:SnapToGrid();
346 Thurallor-7095
    end
347 16 Thurallor-7095
    self:SaveSettings(false);
348 12 Thurallor-7095
end
349 Thurallor-7095
 
350 16 Thurallor-7095
function Manager:ShowGrid(left, top, slotsRight, slotsDown)
351 Thurallor-7095
    if (not self.gridDisplay) then
352 Thurallor-7095
        self.gridDisplay = Turbine.UI.Window();
353 Thurallor-7095
        self.gridDisplay:SetVisible(true);
354 Thurallor-7095
        self.gridDisplay:SetMouseVisible(false);
355 Thurallor-7095
        self.gridDisplay:SetBackground(resources.Icon.Grid);
356 Thurallor-7095
        self.gridDisplay:SetStretchMode(0);
357 Thurallor-7095
        self.gridDisplay:SetSize(slotsRight * self.settings.gridSize, slotsDown * self.settings.gridSize);
358 Thurallor-7095
        self.gridDisplay:SetStretchMode(1);
359 Thurallor-7095
        self.gridDisplay.slotsRight, self.gridDisplay.slotsDown = slotsRight, slotsDown;
360 Thurallor-7095
    end
361 Thurallor-7095
    left, top, scaledGridSize = self:GetNearestGridPos(left, top);
362 Thurallor-7095
    self.gridDisplay.prevLeft, self.gridDisplay.prevTop = left, top;
363 Thurallor-7095
    self.gridDisplay:SetSize(slotsRight * scaledGridSize, slotsDown * scaledGridSize);
364 Thurallor-7095
--    left = left - 2 * scaledGridSize;
365 Thurallor-7095
--    top = top - 2 * scaledGridSize;
366 Thurallor-7095
    self.gridDisplay:SetPosition(left, top);
367 Thurallor-7095
end
368 Thurallor-7095
 
369 Thurallor-7095
function Manager:HideGrid()
370 Thurallor-7095
    if (self.gridDisplay) then
371 Thurallor-7095
        self.gridDisplay:Close();
372 Thurallor-7095
        self.gridDisplay = nil;
373 Thurallor-7095
    end
374 Thurallor-7095
end
375 Thurallor-7095
 
376 Thurallor-7095
function Manager:SetUIOpacity(opacity)
377 Thurallor-7095
    self.settings.uiOpacity = opacity;
378 Thurallor-7095
    self:Redraw(true);
379 Thurallor-7095
    self:SaveSettings(false);
380 Thurallor-7095
end
381 Thurallor-7095
 
382 Thurallor-7095
function Manager:SetUIScale(scale)
383 Thurallor-7095
    self.settings.uiScale = scale;
384 Thurallor-7095
    self:Redraw(true);
385 Thurallor-7095
    if (self.settings.snapToGrid) then
386 Thurallor-7095
        self:SnapToGrid();
387 Thurallor-7095
    end
388 Thurallor-7095
    self:SaveSettings(false);
389 Thurallor-7095
end
390 Thurallor-7095
 
391 Thurallor-7095
function Manager:SetIncludees(includer, includees)
392 Thurallor-7095
--Puts(tostring(includer) .. " is including " .. Serialize(includees));
393 Thurallor-7095
    if (not includees) then
394 Thurallor-7095
        -- Destroying bar.  Notify includers.
395 Thurallor-7095
        self:NotifyIncluders(includer);
396 Thurallor-7095
    end
397 Thurallor-7095
 
398 Thurallor-7095
    -- Delete the previous includes mapping (if any)
399 Thurallor-7095
    local prevIncludes = self.includees[includer];
400 Thurallor-7095
    if (prevIncludes) then
401 Thurallor-7095
        for i = 1, #prevIncludes do
402 Thurallor-7095
            local includee = prevIncludes[i];
403 Thurallor-7095
            self.includers[includee][includer] = nil;
404 Thurallor-7095
--Puts(tostring(includee) .. " will no longer notify " .. tostring(includer));
405 Thurallor-7095
        end
406 Thurallor-7095
    end
407 Thurallor-7095
 
408 Thurallor-7095
    -- Create the new includes mapping (if any)
409 Thurallor-7095
    self.includees[includer] = includees;
410 Thurallor-7095
    if (includees) then
411 Thurallor-7095
        for i = 1, #includees, 1 do
412 Thurallor-7095
            local includee = includees[i];
413 Thurallor-7095
            if (not self.includers[includee]) then
414 Thurallor-7095
                self.includers[includee] = {};
415 Thurallor-7095
            end
416 Thurallor-7095
            self.includers[includee][includer] = true;
417 Thurallor-7095
--Puts(tostring(includee) .. " will notify " .. tostring(includer));
418 Thurallor-7095
        end
419 Thurallor-7095
    end
420 Thurallor-7095
end
421 Thurallor-7095
 
422 Thurallor-7095
-- This function gets called when a sequence changes, so any bars that include that sequence can be notified to update.
423 Thurallor-7095
function Manager:NotifyIncluders(includee)
424 Thurallor-7095
--Puts(tostring(includee) .. " changed");
425 Thurallor-7095
    if (not self.includers[includee]) then
426 Thurallor-7095
        return;
427 Thurallor-7095
    end
428 Thurallor-7095
    self.notifyList = {};
429 Thurallor-7095
    self:FindDependencies(includee);
430 Thurallor-7095
    for barID in keys(self.notifyList) do
431 Thurallor-7095
        if (barID ~= includee) then
432 Thurallor-7095
            local bar = self.objects[barID];
433 Thurallor-7095
            if (bar) then
434 Thurallor-7095
--Puts("Notifying " .. tostring(barID));
435 Thurallor-7095
                bar:ShortcutChanged();
436 Thurallor-7095
            end
437 Thurallor-7095
        end
438 Thurallor-7095
    end
439 Thurallor-7095
    self.notifyList = nil;
440 Thurallor-7095
end
441 Thurallor-7095
 
442 Thurallor-7095
function Manager:FindDependencies(includee)
443 Thurallor-7095
    if (self.includers[includee]) then
444 Thurallor-7095
        for includer in keys(self.includers[includee]) do
445 Thurallor-7095
            if (not self.notifyList[includer]) then
446 Thurallor-7095
                self.notifyList[includer] = true;
447 Thurallor-7095
                self:FindDependencies(includer);
448 Thurallor-7095
            end
449 Thurallor-7095
        end
450 Thurallor-7095
    end
451 Thurallor-7095
end
452 Thurallor-7095
 
453 2 Thurallor-7095
function Manager:AddEventGenerator(object, eventName)
454 Thurallor-7095
    if (not self.eventGenerators[eventName]) then
455 Thurallor-7095
        self.eventGenerators[eventName] = {};
456 Thurallor-7095
    end
457 Thurallor-7095
    table.insert(self.eventGenerators[eventName], object);
458 Thurallor-7095
    local generatorID = #self.eventGenerators[eventName];
459 Thurallor-7095
--Puts("Adding event generator " .. tostring(generatorID) .. " for event " .. Serialize(eventName) .. " from object " .. Serialize(object.settings.caption.text));
460 Thurallor-7095
    return generatorID;
461 Thurallor-7095
end
462 Thurallor-7095
 
463 Thurallor-7095
function Manager:RemoveEventGenerator(generatorID, eventName)
464 8 Thurallor-7095
--Puts("Removing event generator " .. tostring(generatorID) .. " for event " .. Serialize(eventName));
465 13 Thurallor-7095
    local eventGenerators = self.eventGenerators[eventName];
466 Thurallor-7095
    if (eventGenerators) then
467 Thurallor-7095
        local object = eventGenerators[generatorID];
468 Thurallor-7095
--Puts("  (was from object " .. Serialize(object.settings.caption.text) .. ")");
469 Thurallor-7095
        table.remove(eventGenerators, generatorID);
470 Thurallor-7095
        if (#eventGenerators == 0) then
471 Thurallor-7095
            self.eventGenerators[eventName] = nil;
472 Thurallor-7095
        end
473 Thurallor-7095
    else
474 Thurallor-7095
--Puts("Not registered!");
475 2 Thurallor-7095
    end
476 Thurallor-7095
end
477 Thurallor-7095
 
478 Thurallor-7095
-- Returns a list of bars that generates the specified event
479 Thurallor-7095
function Manager:GetEventGenerators(eventName)
480 Thurallor-7095
    return self.eventGenerators[eventName];
481 Thurallor-7095
end
482 Thurallor-7095
 
483 Thurallor-7095
-- Returns the names of all of the events generated by all bars
484 Thurallor-7095
function Manager:GetEventNames()
485 Thurallor-7095
    local eventNames = {};
486 Thurallor-7095
    for k in keys(self.eventGenerators) do
487 Thurallor-7095
        table.insert(eventNames, k);
488 Thurallor-7095
    end
489 Thurallor-7095
    return eventNames;
490 Thurallor-7095
end
491 Thurallor-7095
 
492 Thurallor-7095
function Manager:GetEventCallbacks()
493 Thurallor-7095
    return self.eventCallbacks;
494 Thurallor-7095
end
495 Thurallor-7095
 
496 Thurallor-7095
function Manager:PropagateEvent(eventName)
497 16 Thurallor-7095
    if (self.propagatingEvent[eventName]) then
498 Thurallor-7095
        -- Prevent recursion.  There is no reason to generate the same event twice in the same instant.
499 Thurallor-7095
        return;
500 Thurallor-7095
    end
501 Thurallor-7095
    self.propagatingEvent[eventName] = true;
502 2 Thurallor-7095
    local callbacks = self.eventCallbacks[eventName];
503 Thurallor-7095
    if (type(callbacks) == "table") then
504 Thurallor-7095
--Puts("Propagating event \"" .. tostring(eventName) .. "\" to " .. tostring(#callbacks) .. " callback functions: " .. Serialize(callbacks));
505 Thurallor-7095
        for f = 1, #callbacks do
506 Thurallor-7095
            local func = callbacks[f];
507 Thurallor-7095
            func(eventName);
508 Thurallor-7095
        end
509 Thurallor-7095
    elseif (type(callbacks) == "function") then
510 Thurallor-7095
--Puts("Propagating event \"" .. tostring(eventName) .. "\" to a single callback function: " .. Serialize(callbacks));
511 Thurallor-7095
        callbacks(eventName);
512 Thurallor-7095
    end
513 16 Thurallor-7095
    self.propagatingEvent[eventName] = false;
514 2 Thurallor-7095
end
515 16 Thurallor-7095
 
516 Thurallor-7095
function Manager:Destroy()
517 Thurallor-7095
    self:SetWantsPlayerEvents(false);
518 Thurallor-7095
    Node.Destroy(self);
519 Thurallor-7095
end

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


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