lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 Thurallor-7095
Bar = class(Node);
2 2 Thurallor-7095
 
3 Thurallor-7095
function Bar:Constructor(group, barID, settings)
4 Thurallor-7095
    Turbine.UI.Window.Constructor(self);
5 Thurallor-7095
    self.constructing = true;
6 13 Thurallor-7095
    self:SetZOrder(0);
7 Thurallor-7095
    self:SetMouseVisible(false);
8 20 Thurallor-7095
    self:SetAllowDrop(true);
9 Thurallor-7095
 
10 13 Thurallor-7095
    self.slotContainer = Turbine.UI.Control();
11 Thurallor-7095
    self.slotContainer:SetParent(self);
12 Thurallor-7095
    self.slotContainer:SetMouseVisible(false);
13 2 Thurallor-7095
 
14 Thurallor-7095
    self.parent = group;
15 Thurallor-7095
    self.manager = group.manager;
16 Thurallor-7095
    self.objectID = barID;
17 Thurallor-7095
    self.onLoad = onLoad;
18 16 Thurallor-7095
    self.slots = {};
19 Thurallor-7095
    self.visibleSlots = {};
20 Thurallor-7095
    self.cursorPos = 3;
21 Thurallor-7095
    self.cursorSlot = 1;
22 2 Thurallor-7095
    self.globals = self.manager.settings;
23 16 Thurallor-7095
    self.player = Turbine.Gameplay.LocalPlayer:GetInstance();
24 17 Thurallor-7095
    self.automaticClicks = 0;
25 116 Thurallor-7095
    self.wheelPosition = 0;
26 147 Thurallor-7095
    self.advancement = {};
27 180 Thurallor-7095
    self.reevaluatingConditionals = {};
28 17 Thurallor-7095
 
29 2 Thurallor-7095
    -- Default settings
30 Thurallor-7095
    local defaults = {};
31 Thurallor-7095
    defaults.type = "bar";
32 Thurallor-7095
    defaults.locked = false;
33 Thurallor-7095
    defaults.hidden = false;
34 7 Thurallor-7095
    defaults.color = Thurallor.Utils.Color();
35 Thurallor-7095
    defaults.color:SetHSV(math.random(), 1, 1);
36 Thurallor-7095
    defaults.color = defaults.color:GetHex();
37 2 Thurallor-7095
    defaults.cursorStyle = "SmallSquareGlow";
38 Thurallor-7095
    defaults.caption = { };
39 112 Thurallor-7095
    defaults.caption.visible = "Always";
40 Thurallor-7095
    defaults.caption.clickThru = nil;
41 2 Thurallor-7095
    defaults.caption.text = L:GetText("/Default/BarName");
42 Thurallor-7095
    defaults.caption.position = "beginning";
43 Thurallor-7095
    defaults.caption.width = 80;
44 5 Thurallor-7095
    defaults.caption.height = 35;
45 2 Thurallor-7095
    defaults.caption.font = Turbine.UI.Lotro.Font.TrajanPro15;
46 Thurallor-7095
    defaults.slotSize = 35; -- must be an even number
47 Thurallor-7095
    defaults.slotSpacing = 0;
48 Thurallor-7095
    defaults.orientation = "Right";
49 Thurallor-7095
    defaults.visibleSlots = 5;
50 Thurallor-7095
    defaults.cursorHomePosition = 2;
51 Thurallor-7095
    defaults.animation = { duration = 0.1 };
52 Thurallor-7095
    defaults.sequenceItemInfo = { {}, {}, {}, {}, {} };
53 Thurallor-7095
    defaults.position = { left = math.floor(Turbine.UI.Display:GetWidth() / 2); top = math.floor(Turbine.UI.Display:GetHeight() / 2 )};
54 26 Thurallor-7095
    defaults.anchor = "TopLeft";
55 8 Thurallor-7095
    defaults.eventHandlers = {};
56 Thurallor-7095
    defaults.eventsEnabled = false;
57 16 Thurallor-7095
    defaults.hideAutomatics = true;
58 Thurallor-7095
    defaults.hideInactiveBranches = true;
59 116 Thurallor-7095
    defaults.wheelSpeed = 0;
60 2 Thurallor-7095
 
61 Thurallor-7095
    -- Previously-saved settings override the defaults
62 Thurallor-7095
    DeepTableCopy(settings, defaults);
63 Thurallor-7095
    DeepTableCopy(defaults, settings);
64 Thurallor-7095
    self.settings = settings;
65 Thurallor-7095
 
66 Thurallor-7095
    self:ReapplySettings();
67 Thurallor-7095
    self.constructing = nil;
68 8 Thurallor-7095
    self:SetWantsEvents(self.settings.eventsEnabled);
69 2 Thurallor-7095
end
70 Thurallor-7095
 
71 Thurallor-7095
function Bar:ReapplySettings()
72 Thurallor-7095
 
73 Thurallor-7095
    -- Make color object from hex string
74 Thurallor-7095
    self.color = Thurallor.Utils.Color(1, 0, 0, 0);
75 Thurallor-7095
    self.color:SetHex(self.settings.color);
76 Thurallor-7095
 
77 8 Thurallor-7095
    -- For backward compatibility
78 Thurallor-7095
    self.settings.cursorStyle = string.gsub(self.settings.cursorStyle, "SilverFrame(%d)", "MetalFrame%1");
79 44 Thurallor-7095
    for s = 1, #self.settings.sequenceItemInfo, 1 do
80 135 Thurallor-7095
        info = self.settings.sequenceItemInfo[s] or {};
81 29 Thurallor-7095
        if (info.action) then
82 Thurallor-7095
            info.action = string.gsub(info.action, "item.eventName", "item.info.eventName");
83 Thurallor-7095
            info.action = string.gsub(info.action, "item.bagSlot", "item.info.bagSlot");
84 13 Thurallor-7095
        end
85 34 Thurallor-7095
        if ((info.class == "Turbine.UI.Lotro.Quickslot") and (info.background)) then
86 Thurallor-7095
            info.altIcon = info.background;
87 Thurallor-7095
            info.background = nil;
88 Thurallor-7095
        end
89 119 Thurallor-7095
        if (info.condName == "StanceSelected") then
90 Thurallor-7095
            if (string.match(info.condExpr, "GetClassAttributes")) then
91 Thurallor-7095
                info.condExpr = "return (Thurallor.Utils.Watcher.GetStance() == <stance>);";
92 Thurallor-7095
            end
93 Thurallor-7095
        end
94 41 Thurallor-7095
        if (info.condName and (string.find("SkillTrained|SkillNotTrained|SkillReady|SkillNotReady", info.condName))) then
95 Thurallor-7095
            if ((type(info.condArgs.skill) == "number") and (info.condArgs.skill == 0)) then
96 43 Thurallor-7095
                local skills = Thurallor.Utils.Watcher.GetTrainedSkillsInfo();
97 Thurallor-7095
                local name = skills.names[1];
98 Thurallor-7095
                local skill = skills.byName[name];
99 Thurallor-7095
                local skillInfo = skill:GetSkillInfo();
100 Thurallor-7095
                info.condArgs.skill = skillInfo:GetIconImageID();
101 41 Thurallor-7095
            end
102 Thurallor-7095
            if ((info.condName == "SkillNotReady") and string.find(info.condExpr, "SkillTrained")) then
103 43 Thurallor-7095
                info.condExpr = "return (not Thurallor.Utils.Watcher.SkillReady(<skillName>));";
104 41 Thurallor-7095
            end
105 Thurallor-7095
            if ((info.condName == "SkillTrained") and string.find(info.condExpr, "SkillReady")) then
106 Thurallor-7095
                info.condExpr = "return (Thurallor.Utils.Watcher.SkillTrained(<skillName>));";
107 Thurallor-7095
            end
108 43 Thurallor-7095
            info.condExpr = string.gsub(info.condExpr, "<skill>", "<skillName>");
109 44 Thurallor-7095
            if (info.condArgs.skill and (not info.condArgs.skillName)) then
110 41 Thurallor-7095
                local skills = Thurallor.Utils.Watcher.GetSkillsInfo();
111 Thurallor-7095
                local skill = skills.byIcon[info.condArgs.skill];
112 44 Thurallor-7095
                local name;
113 Thurallor-7095
                if (skill == nil) then
114 Thurallor-7095
                    local barName = self.settings.caption.text;
115 Thurallor-7095
                    local group = self.parent;
116 Thurallor-7095
                    while (group ~= self.manager) do
117 Thurallor-7095
                        barName = group.settings.caption.text .. ":" .. barName;
118 Thurallor-7095
                        group = group.parent;
119 Thurallor-7095
                    end
120 Thurallor-7095
                    _G.manualUpdatesNeeded = _G.manualUpdatesNeeded .. "• In bar \"" .. barName .. "\", in slot " .. s .. ", please reselect the skill from the menu.\n\n";
121 Thurallor-7095
                    name = skills.names[1];
122 Thurallor-7095
                else
123 Thurallor-7095
                    local skillInfo = skill:GetSkillInfo();
124 Thurallor-7095
                    name = skillInfo:GetName();
125 Thurallor-7095
                end
126 41 Thurallor-7095
                info.condArgs.skillName = "\"" .. name .. "\"";
127 Thurallor-7095
                info.condArgs.skill = nil;
128 Thurallor-7095
            end
129 Thurallor-7095
        end
130 114 Thurallor-7095
        if ((info.type == "SetUnequipDestination") and (type(info.bagSlot) == "number")) then
131 Thurallor-7095
            local maxSlot = self.player:GetBackpack():GetSize();
132 Thurallor-7095
            local str = tostring(info.bagSlot);
133 Thurallor-7095
            if (info.bagSlot < maxSlot) then
134 Thurallor-7095
                str = str .. ";" .. tostring(info.bagSlot + 1) .. "..." .. tostring(maxSlot);
135 Thurallor-7095
            end
136 Thurallor-7095
            if (info.bagSlot > 1) then
137 Thurallor-7095
                str = str .. ";1..." .. tostring(info.bagSlot - 1);
138 Thurallor-7095
            end
139 Thurallor-7095
            info.bagSlot = str;
140 Thurallor-7095
        end
141 13 Thurallor-7095
    end
142 29 Thurallor-7095
    for _, handler in pairs(self.settings.eventHandlers) do
143 Thurallor-7095
        if (handler.action) then
144 31 Thurallor-7095
            handler.action = string.gsub(handler.action, "self:SetHidden%(false%); self:BringToFront%(%); ", "self:SetHidden(false); ");
145 30 Thurallor-7095
            handler.action = string.gsub(handler.action, "self:SetHidden%(false%); self:Activate%(%); ", "self:SetHidden(false); ");
146 Thurallor-7095
            handler.action = string.gsub(handler.action, "self:Expand%(%); self:Activate%(%); ", "self:Expand(); ");
147 31 Thurallor-7095
            handler.action = string.gsub(handler.action, "self:Expand%(%); self:BringToFront%(%); ", "self:Expand(); ");
148 30 Thurallor-7095
            handler.action = string.gsub(handler.action, "self:MoveToMouseCursor%(%); self:Activate%(%); ", "self:MoveToMouseCursor%(%); ");
149 29 Thurallor-7095
        end
150 Thurallor-7095
    end
151 112 Thurallor-7095
        if (self.settings.caption.hidden) then
152 Thurallor-7095
                self.settings.caption.hidden = nil;
153 Thurallor-7095
                self.settings.caption.visible = "WhenMouseIsPresent";
154 Thurallor-7095
        end
155 Thurallor-7095
 
156 2 Thurallor-7095
    self:SetCursorStyle(self.settings.cursorStyle);
157 179 Thurallor-7095
    self:Rebuild();
158 Thurallor-7095
end
159 Thurallor-7095
 
160 Thurallor-7095
function Bar:Rebuild()
161 2 Thurallor-7095
    self:GetQuickSlots();
162 16 Thurallor-7095
    self:FindHiddenSlots();
163 2 Thurallor-7095
    self:Redraw();
164 Thurallor-7095
end
165 Thurallor-7095
 
166 30 Thurallor-7095
function Bar:Activate()
167 Thurallor-7095
    -- This used to be called in event handlers after Expand(), MoveToMouseCursor(), and SetHidden(false).
168 Thurallor-7095
    -- Don't want to use Turbine.UI.Window.Activate() because that would steal focus from the chat window.
169 Thurallor-7095
end
170 Thurallor-7095
 
171 29 Thurallor-7095
-- Bring this bar in front of all other bars.
172 Thurallor-7095
function Bar:BringToFront()
173 Thurallor-7095
    -- Don't want to use Turbine.UI.Window.Activate() because that would steal focus from the chat window.
174 Thurallor-7095
    self:SetZOrder(1);
175 Thurallor-7095
    self:SetZOrder(0);
176 Thurallor-7095
end
177 Thurallor-7095
 
178 2 Thurallor-7095
function Bar:CanHaveChildren()
179 Thurallor-7095
    return false;
180 Thurallor-7095
end
181 Thurallor-7095
 
182 Thurallor-7095
function Bar:Contains(object)
183 Thurallor-7095
    return false;
184 Thurallor-7095
end
185 Thurallor-7095
 
186 Thurallor-7095
function Bar:SetColor(color)
187 8 Thurallor-7095
    Node.SetColor(self, color);
188 34 Thurallor-7095
    self:Redraw(true);
189 2 Thurallor-7095
    self:SetCursorStyle();
190 Thurallor-7095
    if (self.sequenceEditor) then
191 Thurallor-7095
        self.sequenceEditor:Redraw();
192 Thurallor-7095
    end
193 Thurallor-7095
end
194 Thurallor-7095
 
195 Thurallor-7095
function Bar:SetName(caption)
196 8 Thurallor-7095
    Node.SetName(self, caption);
197 34 Thurallor-7095
    self:Redraw(true);
198 2 Thurallor-7095
    if (self.sequenceEditor) then
199 Thurallor-7095
        self.sequenceEditor:SetText(caption);
200 Thurallor-7095
    end
201 Thurallor-7095
    if (self.exportWindow) then
202 Thurallor-7095
        self.exportWindow:SetText(caption);
203 Thurallor-7095
    end
204 Thurallor-7095
end
205 Thurallor-7095
 
206 Thurallor-7095
function Bar:SetCaptionSize(width, height)
207 9 Thurallor-7095
    Node.SetCaptionSize(self, width, height);
208 34 Thurallor-7095
    self:Redraw(true);
209 13 Thurallor-7095
    self:OffsetPosition(0, 0);
210 2 Thurallor-7095
end
211 Thurallor-7095
 
212 Thurallor-7095
function Bar:SetCaptionFont(font)
213 Thurallor-7095
    self.settings.caption.font = font;
214 Thurallor-7095
    self:SaveSettings(false);
215 34 Thurallor-7095
    self:Redraw(true);
216 2 Thurallor-7095
end
217 Thurallor-7095
 
218 112 Thurallor-7095
function Bar:SetCaptionVisible(visible)
219 Thurallor-7095
    self.settings.caption.visible = visible;
220 2 Thurallor-7095
    self:SaveSettings(false);
221 34 Thurallor-7095
    self:Redraw(true);
222 2 Thurallor-7095
end
223 Thurallor-7095
 
224 112 Thurallor-7095
function Bar:SetCaptionClickThru(clickThru)
225 Thurallor-7095
        if (clickThru == false) then
226 Thurallor-7095
                clickThru = nil;
227 Thurallor-7095
        end
228 Thurallor-7095
        self.settings.caption.clickThru = clickThru;
229 Thurallor-7095
    self:SaveSettings(false);
230 Thurallor-7095
    self:Redraw(true);
231 Thurallor-7095
end
232 Thurallor-7095
 
233 2 Thurallor-7095
function Bar:ApplyHiddenness()
234 Thurallor-7095
    local hidden = self:IsHidden();
235 21 Thurallor-7095
    if ((not hidden) and (not self:IsVisible())) then
236 Thurallor-7095
        self.visibleSlots = {};
237 Thurallor-7095
    end
238 Thurallor-7095
    self:SetCursorSlot(self.cursorSlot);
239 2 Thurallor-7095
    self:SetVisible(not hidden);
240 Thurallor-7095
end
241 Thurallor-7095
 
242 26 Thurallor-7095
function Bar:Collapse()
243 Thurallor-7095
    if (self.settings.collapsed) then
244 Thurallor-7095
        return;
245 Thurallor-7095
    end
246 121 Thurallor-7095
    if (self.Log) then
247 Thurallor-7095
        DoCallbacks(self, "Log", {"collapsing", "BAR"});
248 Thurallor-7095
    end
249 26 Thurallor-7095
    self.settings.collapsed = self.cursorPos;
250 Thurallor-7095
    self:Redraw(true);
251 27 Thurallor-7095
    local x1, y1 = self:GetSlotCoords(1);
252 Thurallor-7095
    if ((self.settings.orientation == "Up") or (self.settings.orientation == "Left")) then
253 Thurallor-7095
        x1, y1 = self:GetSlotCoords(self.settings.visibleSlots);
254 Thurallor-7095
    end
255 Thurallor-7095
    local x2, y2 = self:GetSlotCoords(self.settings.cursorHomePosition);
256 Thurallor-7095
    self:OffsetPosition(x2 - x1, y2 - y1);
257 26 Thurallor-7095
    self:SetCursorPos(1);
258 Thurallor-7095
    self:SetCursorSlot(self.cursorSlot);
259 Thurallor-7095
    self:SaveSettings(false);
260 Thurallor-7095
end
261 Thurallor-7095
 
262 Thurallor-7095
function Bar:IsCollapsed()
263 Thurallor-7095
    return ((self.settings.visibleSlots == 1) or (self.settings.collapsed ~= nil));
264 Thurallor-7095
end
265 Thurallor-7095
 
266 Thurallor-7095
function Bar:Expand()
267 Thurallor-7095
    if (not self.settings.collapsed) then
268 Thurallor-7095
        return;
269 Thurallor-7095
    end
270 121 Thurallor-7095
    if (self.Log) then
271 Thurallor-7095
        DoCallbacks(self, "Log", {"expanding", "BAR"});
272 Thurallor-7095
    end
273 26 Thurallor-7095
    local cursorPos = math.min(self.settings.collapsed, self.settings.visibleSlots);
274 Thurallor-7095
    self.settings.collapsed = nil;
275 Thurallor-7095
    self:Redraw(true);
276 27 Thurallor-7095
    local x1, y1 = self:GetSlotCoords(1);
277 Thurallor-7095
    if ((self.settings.orientation == "Up") or (self.settings.orientation == "Left")) then
278 Thurallor-7095
        x1, y1 = self:GetSlotCoords(self.settings.visibleSlots);
279 Thurallor-7095
    end
280 Thurallor-7095
    local x2, y2 = self:GetSlotCoords(self.settings.cursorHomePosition);
281 Thurallor-7095
    self:OffsetPosition(x1 - x2, y1 - y2);
282 26 Thurallor-7095
    self:SetCursorPos(cursorPos);
283 Thurallor-7095
    self:SetCursorSlot(self.cursorSlot);
284 Thurallor-7095
    self:SaveSettings(false);
285 Thurallor-7095
end
286 Thurallor-7095
 
287 Thurallor-7095
function Bar:IsExpanded()
288 Thurallor-7095
    return ((self.settings.visibleSlots == 1) or (self.settings.collapsed == nil));
289 Thurallor-7095
end
290 Thurallor-7095
 
291 2 Thurallor-7095
-- Updates the sequence item when a user drags a shortcut onto the sequence editor
292 121 Thurallor-7095
function Bar:ShortcutChanged()
293 Thurallor-7095
    if (self.Log) then
294 Thurallor-7095
        DoCallbacks(self, "Log", {"modified with sequence editor", "BAR"});
295 Thurallor-7095
    end
296 2 Thurallor-7095
    self:SaveSettings(false);
297 179 Thurallor-7095
    self:Rebuild();
298 2 Thurallor-7095
end
299 Thurallor-7095
 
300 16 Thurallor-7095
-- Initialize "hidden" and "folded" flags
301 Thurallor-7095
function Bar:FindHiddenSlots()
302 Thurallor-7095
    for i = 1, #self.slots, 1 do
303 Thurallor-7095
        local slot = self.slots[i];
304 Thurallor-7095
        slot.folded = false;
305 Thurallor-7095
        if (self.settings.hideAutomatics and slot.info.automatic) then
306 Thurallor-7095
            slot.hidden = true;
307 Thurallor-7095
        else
308 Thurallor-7095
            slot.hidden = false;
309 Thurallor-7095
        end
310 Thurallor-7095
    end
311 Thurallor-7095
end
312 Thurallor-7095
 
313 Thurallor-7095
function Bar:GetSequence()
314 Thurallor-7095
    return self.sequence;
315 Thurallor-7095
end
316 Thurallor-7095
 
317 167 Thurallor-7095
function Bar:SetUseOnRightClick(useOnRightClick)
318 Thurallor-7095
    for _, slot in pairs(self.slots) do
319 Thurallor-7095
        slot:SetUseOnRightClick(useOnRightClick);
320 Thurallor-7095
    end
321 Thurallor-7095
end
322 Thurallor-7095
 
323 2 Thurallor-7095
-- Creates (or recreates) the array of objects (e.g. Quickslot) according to self.settings.sequenceItemInfo
324 Thurallor-7095
function Bar:GetQuickSlots()
325 16 Thurallor-7095
    -- Hide and destroy existing clickable objects, if any
326 Thurallor-7095
    for s = 1, #self.slots, 1 do
327 Thurallor-7095
        self.slots[s]:SetParent(nil);
328 Thurallor-7095
    end
329 Thurallor-7095
 
330 Thurallor-7095
    -- Unregister as event(s) generator.  We will re-register for each generated event as we loop through the sequence below.
331 177 Thurallor-7095
    self.manager:SetEventGenerators(false, self);
332 2 Thurallor-7095
 
333 117 Thurallor-7095
    local wantsMouseWheelEvents = self.settings.wheelSpeed and (self.settings.wheelSpeed > 0);
334 Thurallor-7095
    self.sequence = Sequence(self, self.settings.sequenceItemInfo, wantsMouseWheelEvents);
335 16 Thurallor-7095
    self.manager:SetIncludees(self.objectID, self.sequence:GetIncludes());
336 Thurallor-7095
 
337 Thurallor-7095
    -- Register as generator of event(s)
338 177 Thurallor-7095
    self.manager:SetEventGenerators(true, self, self.sequence:GetEvents());
339 16 Thurallor-7095
 
340 Thurallor-7095
    -- Iterate through the sequence configuring the clickable objects.
341 Thurallor-7095
    self.slots = self.sequence:GetSlots(); -- returns array of Slot instances
342 Thurallor-7095
    for s = 1, #self.slots, 1 do
343 Thurallor-7095
        local slot = self.slots[s];
344 Thurallor-7095
        local info = slot.info;
345 36 Thurallor-7095
        self:ConfigureSlot(slot, s);
346 20 Thurallor-7095
        AddCallback(slot, "MouseClick", function(sender, args)
347 167 Thurallor-7095
            if (self.globals.useOnRightClick or args.Button == Turbine.UI.MouseButton.Left) then
348 121 Thurallor-7095
                if (self.Log) then
349 Thurallor-7095
                    DoCallbacks(self, "Log", {"clicked slot " .. tostring(sender.s), "MOUSE"});
350 Thurallor-7095
                end
351 20 Thurallor-7095
                self:SlotClick(sender.s, false);
352 13 Thurallor-7095
            end
353 20 Thurallor-7095
        end);
354 2 Thurallor-7095
    end
355 36 Thurallor-7095
 
356 Thurallor-7095
    -- Create a "reset" slot to be displayed when all other slots are folded
357 43 Thurallor-7095
    if (not self.resetSlot) then
358 Thurallor-7095
        local info = { type = "Reset"; class = "Turbine.UI.Control"; background = resources.Icon.Reset };
359 Thurallor-7095
        self.resetSlot = Slot(info);
360 Thurallor-7095
    end
361 36 Thurallor-7095
    self:ConfigureSlot(self.resetSlot, #self.slots);
362 Thurallor-7095
    AddCallback(self.resetSlot, "MouseClick", function(sender, args)
363 Thurallor-7095
        if (args.Button == Turbine.UI.MouseButton.Left) then
364 121 Thurallor-7095
            if (self.Log) then
365 Thurallor-7095
                DoCallbacks(self, "Log", {"clicked reset button", "MOUSE"});
366 Thurallor-7095
            end
367 36 Thurallor-7095
            self:Reset();
368 Thurallor-7095
        end
369 Thurallor-7095
    end);
370 43 Thurallor-7095
 
371 Thurallor-7095
    -- Create a "gears" slot to be displayed when running continuously
372 Thurallor-7095
    if (not self.gearsSlot) then
373 Thurallor-7095
        self.gearsSlot = Gears(false);
374 Thurallor-7095
    end
375 Thurallor-7095
    self:ConfigureSlot(self.gearsSlot, #self.slots);
376 2 Thurallor-7095
end
377 Thurallor-7095
 
378 36 Thurallor-7095
function Bar:ConfigureSlot(slot, s)
379 43 Thurallor-7095
    slot:SetZOrder(2);
380 Thurallor-7095
    slot:SetActionEnabled(true);
381 Thurallor-7095
    slot:SetAllowDrop(false);
382 Thurallor-7095
    slot:SetDraggable(false);
383 167 Thurallor-7095
    slot:SetUseOnRightClick(self.globals.useOnRightClick);
384 43 Thurallor-7095
    slot.bar = self;
385 Thurallor-7095
    slot.s = s;
386 36 Thurallor-7095
    slot.MouseClick = nil; -- avoid multiple callbacks when the slot is reconfigured
387 Thurallor-7095
    slot.MouseEnter = nil;
388 116 Thurallor-7095
    slot.MouseWheel = nil;
389 43 Thurallor-7095
    AddCallback(slot, "MouseClick", function(sender, args)
390 Thurallor-7095
        -- Right-click displays the settings menu.
391 167 Thurallor-7095
        if (not self.globals.useOnRightClick and (args.Button == Turbine.UI.MouseButton.Right)) then
392 43 Thurallor-7095
            self:ShowSettingsMenu();
393 Thurallor-7095
        end
394 Thurallor-7095
    end);
395 121 Thurallor-7095
    AddCallback(slot, "MouseEnter", function()
396 43 Thurallor-7095
        self:MouseArrive();
397 Thurallor-7095
    end);
398 116 Thurallor-7095
    AddCallback(slot, "MouseWheel", function(sender, args)
399 117 Thurallor-7095
        args.s = s;
400 116 Thurallor-7095
        self:MouseWheel(args);
401 Thurallor-7095
    end);
402 43 Thurallor-7095
end
403 36 Thurallor-7095
 
404 16 Thurallor-7095
function Bar:Redraw(noReset)
405 26 Thurallor-7095
    if (self.settings.collapsed) then
406 Thurallor-7095
        self.displaySlots = 1;
407 Thurallor-7095
    else
408 Thurallor-7095
        self.displaySlots = self.settings.visibleSlots;
409 Thurallor-7095
    end
410 Thurallor-7095
    local slotsLongDimension = (2 * self.cursorMargin) + (self.displaySlots + 1) * self.settings.slotSize + self.displaySlots * self.settings.slotSpacing;
411 13 Thurallor-7095
    local slotsShortDimension = (2 * self.cursorMargin) + self.settings.slotSize;
412 2 Thurallor-7095
 
413 13 Thurallor-7095
    local captionMargin = 4;
414 Thurallor-7095
    local captionWidth, captionHeight = self.settings.caption.width, self.settings.caption.height;
415 16 Thurallor-7095
    local barWidth, barHeight, slotsWidth, slotsHeight, captionLeft, captionTop;
416 2 Thurallor-7095
    if ((self.settings.orientation == "Up") or (self.settings.orientation == "Down")) then
417 13 Thurallor-7095
        slotsWidth, slotsHeight = slotsShortDimension, slotsLongDimension;
418 Thurallor-7095
 
419 Thurallor-7095
        -- Position slots and caption horizontally; set bar width
420 Thurallor-7095
        if (slotsWidth < captionWidth) then
421 Thurallor-7095
            barWidth = captionWidth;
422 16 Thurallor-7095
            self.slotsLeft = math.floor((barWidth - slotsWidth) / 2);
423 13 Thurallor-7095
            captionLeft = 0;
424 Thurallor-7095
        elseif (slotsWidth > captionWidth) then
425 Thurallor-7095
            barWidth = slotsWidth;
426 16 Thurallor-7095
            self.slotsLeft = 0;
427 13 Thurallor-7095
            captionLeft = math.floor((barWidth - captionWidth) / 2);
428 Thurallor-7095
        else -- (slotsWidth == captionWidth)
429 16 Thurallor-7095
            barWidth, self.slotsLeft, captionLeft = slotsWidth, 0, 0;
430 13 Thurallor-7095
        end
431 Thurallor-7095
 
432 Thurallor-7095
        -- Position slots and caption vertically; set bar height
433 Thurallor-7095
        if (self.settings.orientation == "Up") then
434 Thurallor-7095
            if (self.settings.caption.position == "beginning") then
435 16 Thurallor-7095
                self.slotsTop = 0;
436 13 Thurallor-7095
                captionTop = slotsHeight - self.cursorMargin + captionMargin;
437 Thurallor-7095
                barHeight = math.max(slotsHeight, captionTop + captionHeight);
438 Thurallor-7095
            else -- (self.settings.caption.position == "end")
439 Thurallor-7095
                captionTop = math.max(0, self.cursorMargin + self.settings.slotSize - (captionHeight + captionMargin));
440 16 Thurallor-7095
                self.slotsTop = math.max((captionHeight + captionMargin) - (self.cursorMargin + self.settings.slotSize), 0);
441 Thurallor-7095
                barHeight = self.slotsTop + slotsHeight;
442 13 Thurallor-7095
            end
443 Thurallor-7095
        else -- (self.settings.orientation == "Down")
444 Thurallor-7095
            if (self.settings.caption.position == "beginning") then
445 Thurallor-7095
                captionTop = math.max(0, self.cursorMargin - (captionHeight + captionMargin));
446 16 Thurallor-7095
                self.slotsTop = math.max((captionHeight + captionMargin) - self.cursorMargin, 0);
447 Thurallor-7095
                barHeight = self.slotsTop + slotsHeight;
448 13 Thurallor-7095
            else -- (self.settings.caption.position == "end")
449 16 Thurallor-7095
                self.slotsTop = 0;
450 13 Thurallor-7095
                captionTop = slotsHeight - self.cursorMargin - self.settings.slotSize + captionMargin;
451 Thurallor-7095
                barHeight = math.max(slotsHeight, captionTop + captionHeight);
452 Thurallor-7095
            end
453 Thurallor-7095
        end
454 Thurallor-7095
    else -- ((self.settings.orientation == "Left") or (self.settings.orientation == "Right")) then
455 Thurallor-7095
        slotsWidth, slotsHeight = slotsLongDimension, slotsShortDimension;
456 Thurallor-7095
 
457 Thurallor-7095
        -- Position slots and caption vertically; set bar height
458 Thurallor-7095
        if (slotsHeight < captionHeight) then
459 Thurallor-7095
            barHeight = captionHeight;
460 16 Thurallor-7095
            self.slotsTop = math.floor((barHeight - slotsHeight) / 2);
461 13 Thurallor-7095
            captionTop = 0;
462 Thurallor-7095
        elseif (slotsHeight > captionHeight) then
463 Thurallor-7095
            barHeight = slotsHeight;
464 16 Thurallor-7095
            self.slotsTop = 0;
465 13 Thurallor-7095
            captionTop = math.floor((barHeight - captionHeight) / 2);
466 Thurallor-7095
        else -- (slotsHeight == captionHeight)
467 16 Thurallor-7095
            barHeight, self.slotsTop, captionTop = slotsHeight, 0, 0;
468 13 Thurallor-7095
        end
469 Thurallor-7095
 
470 Thurallor-7095
        -- Position slots and caption horizontally; set bar width
471 Thurallor-7095
        if (self.settings.orientation == "Left") then
472 Thurallor-7095
            if (self.settings.caption.position == "beginning") then
473 16 Thurallor-7095
                self.slotsLeft = 0;
474 13 Thurallor-7095
                captionLeft = slotsWidth - self.cursorMargin + captionMargin;
475 Thurallor-7095
                barWidth = math.max(slotsWidth, captionLeft + captionWidth);
476 Thurallor-7095
            else -- (self.settings.caption.position == "end")
477 Thurallor-7095
                captionLeft = math.max(0, self.cursorMargin + self.settings.slotSize - (captionWidth + captionMargin));
478 16 Thurallor-7095
                self.slotsLeft = math.max((captionLeft + captionWidth + captionMargin) - (self.cursorMargin + self.settings.slotSize), 0);
479 Thurallor-7095
                barWidth = self.slotsLeft + slotsWidth;
480 13 Thurallor-7095
            end
481 Thurallor-7095
        else -- (self.settings.orientation == "Right")
482 Thurallor-7095
            if (self.settings.caption.position == "beginning") then
483 Thurallor-7095
                captionLeft = math.max(0, self.cursorMargin - (captionWidth + captionMargin));
484 16 Thurallor-7095
                self.slotsLeft = math.max((captionWidth + captionMargin) - self.cursorMargin, 0);
485 Thurallor-7095
                barWidth = self.slotsLeft + slotsWidth;
486 13 Thurallor-7095
            else -- (self.settings.caption.position == "end")
487 16 Thurallor-7095
                self.slotsLeft = 0;
488 13 Thurallor-7095
                captionLeft = slotsWidth - self.cursorMargin - self.settings.slotSize + captionMargin;
489 Thurallor-7095
                barWidth = math.max(slotsWidth, captionLeft + captionWidth);
490 Thurallor-7095
            end
491 Thurallor-7095
        end
492 2 Thurallor-7095
    end
493 16 Thurallor-7095
 
494 13 Thurallor-7095
    self.slotContainer:SetSize(slotsWidth, slotsHeight);
495 16 Thurallor-7095
    self.slotContainer:SetPosition(self.slotsLeft, self.slotsTop);
496 13 Thurallor-7095
    self:DrawCaption();
497 Thurallor-7095
    self.caption:SetSize(captionWidth, captionHeight);
498 Thurallor-7095
    self.caption:SetPosition(captionLeft, captionTop);
499 16 Thurallor-7095
 
500 Thurallor-7095
    self:SetStretchMode(0);
501 Thurallor-7095
    self:SetSize(barWidth, barHeight);
502 Thurallor-7095
    self:SetStretchMode(1);
503 158 Thurallor-7095
    self:SetSize(barWidth * self:GetScale() / 32, barHeight * self:GetScale() / 32);
504 16 Thurallor-7095
 
505 26 Thurallor-7095
    self:SetPosition();
506 158 Thurallor-7095
    self:SetOpacity(self:GetTransparency());
507 2 Thurallor-7095
 
508 16 Thurallor-7095
    -- Draw cursor icon and slots.
509 Thurallor-7095
    if (not noReset) then
510 Thurallor-7095
        self:Reset();
511 Thurallor-7095
    end
512 2 Thurallor-7095
 
513 Thurallor-7095
    self:ApplyHiddenness();
514 Thurallor-7095
end
515 Thurallor-7095
 
516 Thurallor-7095
function Bar:Reset()
517 121 Thurallor-7095
    if (self.Log) then
518 Thurallor-7095
        DoCallbacks(self, "Log", {"reset", "BAR"})
519 Thurallor-7095
    end
520 16 Thurallor-7095
    self.sequence:UnfoldAllSlots();
521 180 Thurallor-7095
    self.reevaluatingConditionals = {};
522 2 Thurallor-7095
    self.animationStopped = false;
523 26 Thurallor-7095
    local cursorPos = self.settings.cursorHomePosition;
524 Thurallor-7095
    if (self.settings.collapsed) then
525 Thurallor-7095
        self.settings.collapsed = self.settings.cursorHomePosition;
526 Thurallor-7095
        cursorPos = 1;
527 Thurallor-7095
    end
528 Thurallor-7095
    self:SetCursorPos(cursorPos);
529 Thurallor-7095
    self.clickedPos = cursorPos;
530 38 Thurallor-7095
    self.clickedSlot = 1;
531 16 Thurallor-7095
    self:SetCursorSlot(1);
532 43 Thurallor-7095
    self.gearsSlot:SetDelaying(false);
533 143 Thurallor-7095
    self:UnregisterAdvanceCallback(); -- In case we were waiting for advancement when the bar was reset
534 16 Thurallor-7095
    if (self.slots[1] and self.slots[1].info.automatic) then
535 20 Thurallor-7095
        self:SlotClick(1, true);
536 16 Thurallor-7095
    end
537 2 Thurallor-7095
end
538 Thurallor-7095
 
539 Thurallor-7095
-- Moves the cursor to the specified position on the bar
540 16 Thurallor-7095
function Bar:SetCursorPos(pos)
541 2 Thurallor-7095
    local resource = resources.Cursor[self.settings.cursorStyle];
542 Thurallor-7095
    local left, top = self:GetSlotCoords(pos);
543 Thurallor-7095
    left = left - self.cursorMargin + resource.xOffset;
544 Thurallor-7095
    top = top - self.cursorMargin + resource.yOffset;
545 13 Thurallor-7095
    self.cursor.left, self.cursor.top = left, top;
546 2 Thurallor-7095
    self.cursor:SetPosition(left, top);
547 16 Thurallor-7095
    self.cursorPos = pos;
548 2 Thurallor-7095
end
549 Thurallor-7095
 
550 Thurallor-7095
function Bar:DrawCaption()
551 Thurallor-7095
    if (not self.caption) then
552 13 Thurallor-7095
        self.caption = Turbine.UI.Control();
553 Thurallor-7095
        self.caption:SetParent(self);
554 Thurallor-7095
        self.caption:SetZOrder(10);
555 20 Thurallor-7095
        self.caption:SetMouseVisible(true);
556 Thurallor-7095
 
557 Thurallor-7095
        -- While mouse is over caption, highlight the label to indicate that it can be clicked.
558 Thurallor-7095
        function self.caption.MouseEnter(caption)
559 Thurallor-7095
            caption.label:SetFontStyle(Turbine.UI.FontStyle.None);
560 112 Thurallor-7095
                        caption.label:SetOutlineColor(self.color); -- boldface effect
561 Thurallor-7095
                        caption.label:SetFontStyle(Turbine.UI.FontStyle.Outline);
562 20 Thurallor-7095
            caption.label:SetVisible(true);
563 Thurallor-7095
        end
564 Thurallor-7095
        function self.caption.MouseLeave(caption)
565 Thurallor-7095
            caption.label:SetFontStyle(Turbine.UI.FontStyle.None);
566 Thurallor-7095
            caption.label:SetOutlineColor(Turbine.UI.Color(0.75, 0, 0, 0));
567 Thurallor-7095
            caption.label:SetFontStyle(Turbine.UI.FontStyle.Outline);
568 112 Thurallor-7095
            caption.label:SetVisible(self.settings.caption.visible == "Always");
569 20 Thurallor-7095
        end
570 Thurallor-7095
 
571 Thurallor-7095
        function self.caption.MouseClick(caption, args)
572 Thurallor-7095
            if (self.mouseMoved) then
573 Thurallor-7095
                self.mouseMoved = false;
574 Thurallor-7095
                return;
575 Thurallor-7095
            end
576 Thurallor-7095
 
577 Thurallor-7095
            -- Left-click resets the sequence back to the beginning.
578 Thurallor-7095
            if (args.Button == Turbine.UI.MouseButton.Left) then
579 Thurallor-7095
                self:Reset();
580 Thurallor-7095
            end
581 Thurallor-7095
 
582 Thurallor-7095
            -- Right-click displays the settings menu.
583 Thurallor-7095
            if (args.Button == Turbine.UI.MouseButton.Right) then
584 Thurallor-7095
                self:ShowSettingsMenu();
585 Thurallor-7095
            end
586 Thurallor-7095
        end
587 Thurallor-7095
        function self.caption.MouseDoubleClick(caption, args)
588 Thurallor-7095
            -- Left-double-click opens the caption editor.
589 Thurallor-7095
            if (args.Button == Turbine.UI.MouseButton.Left) then
590 Thurallor-7095
                self:EditCaption();
591 Thurallor-7095
            end
592 Thurallor-7095
 
593 Thurallor-7095
            -- Right-double-click would open the sequence editor, but
594 Thurallor-7095
            -- since right-click opens the settings menu, right-double
595 Thurallor-7095
            -- -click isn't possible.
596 Thurallor-7095
        end
597 Thurallor-7095
 
598 Thurallor-7095
        -- MouseDown, MouseUp, and MouseMove are used to move the window (if not locked)
599 Thurallor-7095
        function self.caption.MouseDown(caption, args)
600 Thurallor-7095
            if (args.Button == Turbine.UI.MouseButton.Left) then
601 Thurallor-7095
                self.mouseDown = true;
602 143 Thurallor-7095
                self.mouseMoved = false;
603 20 Thurallor-7095
                self.originalMouseX, self.originalMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
604 Thurallor-7095
            end
605 Thurallor-7095
        end
606 Thurallor-7095
        function self.caption.MouseUp(caption, args)
607 Thurallor-7095
            if (args.Button == Turbine.UI.MouseButton.Left) then
608 Thurallor-7095
                self.mouseDown = false;
609 143 Thurallor-7095
                if (self.mouseMoved and not self.settings.locked) then
610 201 Thurallor-7095
                    if (self.manager.settings.snapToGrid) then
611 Thurallor-7095
                        local togetherGroup = self:GetTopTogetherGroup();
612 Thurallor-7095
                        if (togetherGroup) then
613 Thurallor-7095
                            togetherGroup:SnapToGrid();
614 Thurallor-7095
                        else
615 Thurallor-7095
                            self:SnapToGrid();
616 Thurallor-7095
                        end
617 20 Thurallor-7095
                    end
618 Thurallor-7095
                    self:SaveSettings(false);
619 127 Thurallor-7095
                    self.manager:UnhighlightGrid();
620 Thurallor-7095
                    self.manager:ShowAnchorIcon(nil);
621 20 Thurallor-7095
                end
622 Thurallor-7095
            end
623 Thurallor-7095
        end
624 Thurallor-7095
        function self.caption.MouseMove(caption, args)
625 Thurallor-7095
            if (self.mouseDown and not self.settings.locked) then
626 Thurallor-7095
                self.mouseMoved = true;
627 Thurallor-7095
                local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
628 Thurallor-7095
                local deltaX, deltaY = newMouseX - self.originalMouseX, newMouseY - self.originalMouseY;
629 Thurallor-7095
                self.originalMouseX, self.originalMouseY = newMouseX, newMouseY;
630 Thurallor-7095
 
631 Thurallor-7095
                -- See if we need to move other bars along with this one.
632 201 Thurallor-7095
                local togetherGroup = self:GetTopTogetherGroup();
633 Thurallor-7095
                if (togetherGroup) then
634 Thurallor-7095
                    togetherGroup:OffsetPosition(deltaX, deltaY);
635 20 Thurallor-7095
                else
636 Thurallor-7095
                    self:OffsetPosition(deltaX, deltaY);
637 Thurallor-7095
                end
638 Thurallor-7095
 
639 127 Thurallor-7095
                -- Highlight grid if "Snap to grid" is enabled.
640 20 Thurallor-7095
                if (self.globals.snapToGrid) then
641 Thurallor-7095
                    local left, top, width, height = self:GetPosition();
642 Thurallor-7095
                    if ((self.settings.orientation == "Right") or (self.settings.orientation == "Left")) then
643 26 Thurallor-7095
                        width = self.displaySlots;
644 20 Thurallor-7095
                        height = 1;
645 Thurallor-7095
                    else
646 Thurallor-7095
                        width = 1;
647 26 Thurallor-7095
                        height = self.displaySlots;
648 20 Thurallor-7095
                    end
649 158 Thurallor-7095
                    self.manager:HighlightGrid(left, top, width, height, self:GetScale());
650 20 Thurallor-7095
                end
651 127 Thurallor-7095
 
652 Thurallor-7095
                -- Display anchor icon to indicate position reference
653 Thurallor-7095
                local left, top = self:GetSlotsScreenCoords();
654 Thurallor-7095
                self.manager:ShowAnchorIcon(self.settings.anchor, left, top);
655 20 Thurallor-7095
            end
656 Thurallor-7095
        end
657 Thurallor-7095
        function self.caption.DragDrop(caption)
658 Thurallor-7095
            self:EditSequence();
659 Thurallor-7095
        end
660 2 Thurallor-7095
    end
661 Thurallor-7095
    local caption = self.caption;
662 13 Thurallor-7095
    if (not caption.label) then
663 Thurallor-7095
        caption.label = Turbine.UI.Label();
664 Thurallor-7095
        caption.label:SetParent(caption);
665 Thurallor-7095
        caption.label:SetMouseVisible(false);
666 Thurallor-7095
    end
667 Thurallor-7095
    local label = caption.label;
668 112 Thurallor-7095
        caption:SetMouseVisible((not self.settings.caption.clickThru) and (self.settings.caption.visible ~= "Never"));
669 13 Thurallor-7095
 
670 Thurallor-7095
    local alignment;
671 Thurallor-7095
    local where = self.settings.orientation;
672 2 Thurallor-7095
    if (self.settings.caption.position == "end") then
673 Thurallor-7095
        local swap = {Up = "Down"; Down = "Up"; Left = "Right"; Right = "Left"};
674 Thurallor-7095
        where = swap[where];
675 Thurallor-7095
    end
676 Thurallor-7095
    if (where == "Up") then
677 Thurallor-7095
        alignment = Turbine.UI.ContentAlignment.TopCenter;
678 Thurallor-7095
    elseif (where == "Down") then
679 Thurallor-7095
        alignment = Turbine.UI.ContentAlignment.BottomCenter;
680 Thurallor-7095
    elseif (where == "Right") then
681 Thurallor-7095
        alignment = Turbine.UI.ContentAlignment.MiddleRight;
682 Thurallor-7095
    else -- "Left"
683 Thurallor-7095
        alignment = Turbine.UI.ContentAlignment.MiddleLeft;
684 Thurallor-7095
    end
685 Thurallor-7095
 
686 Thurallor-7095
    label:SetText(self.settings.caption.text);
687 112 Thurallor-7095
    label:SetVisible((self.settings.caption.visible == "Always") or ((self.settings.caption.visible == "WhenMouseIsPresent") and self.mouseInside));
688 2 Thurallor-7095
    self:FormatCaptionLabel(label, alignment);
689 Thurallor-7095
    if (self.captionEditor and self.captionEditor:WantsCaptionUpdates()) then
690 Thurallor-7095
        local textBox = self.captionEditor:GetTextBox();
691 Thurallor-7095
        self:FormatCaptionLabel(textBox, alignment);
692 Thurallor-7095
        self.captionEditor:Redraw();
693 Thurallor-7095
    end
694 20 Thurallor-7095
end
695 2 Thurallor-7095
 
696 20 Thurallor-7095
function Bar:MouseArrive()
697 Thurallor-7095
    if (self.mouseInside) then
698 Thurallor-7095
        -- Already inside; do nothing.
699 Thurallor-7095
        return;
700 2 Thurallor-7095
    end
701 20 Thurallor-7095
    self.mouseInside = true;
702 42 Thurallor-7095
    self.parent:MouseArrive(self.objectID);
703 112 Thurallor-7095
        self:BringToFront();
704 Thurallor-7095
        if (self.settings.caption.visible == "WhenMouseIsPresent") then
705 Thurallor-7095
                self.caption.label:SetVisible(true);
706 Thurallor-7095
        end
707 121 Thurallor-7095
    if (self.Log) then
708 Thurallor-7095
        DoCallbacks(self, "Log", {"arrived", "MOUSE"});
709 Thurallor-7095
    end
710 20 Thurallor-7095
    DoCallbacks(self, "MouseArrived");
711 Thurallor-7095
    self:SetWantsUpdates(true);
712 2 Thurallor-7095
end
713 Thurallor-7095
 
714 42 Thurallor-7095
function Bar:MouseInside(mouseLeft, mouseTop)
715 Thurallor-7095
    if (self:IsHidden()) then
716 Thurallor-7095
        return false;
717 Thurallor-7095
    end
718 Thurallor-7095
    local left, top, width, height = self:GetSlotsScreenCoords();
719 Thurallor-7095
    local spacing = 1;
720 Thurallor-7095
    left = left - spacing;
721 Thurallor-7095
    top = top - spacing;
722 Thurallor-7095
    local right = left + width + 2 * spacing;
723 Thurallor-7095
    local bottom = top + height + 2 * spacing;
724 Thurallor-7095
    return ((mouseLeft >= left) and (mouseLeft < right) and (mouseTop >= top) and (mouseTop < bottom));
725 Thurallor-7095
end
726 Thurallor-7095
 
727 20 Thurallor-7095
function Bar:MouseDepart()
728 Thurallor-7095
    self.mouseInside = false;
729 42 Thurallor-7095
    self.parent:MouseDepart(self.objectID);
730 112 Thurallor-7095
        if (self.settings.caption.visible == "WhenMouseIsPresent") then
731 Thurallor-7095
                self.caption.label:SetVisible(false);
732 Thurallor-7095
        end
733 121 Thurallor-7095
    if (self.Log) then
734 Thurallor-7095
        DoCallbacks(self, "Log", {"departed", "MOUSE"});
735 Thurallor-7095
    end
736 20 Thurallor-7095
    DoCallbacks(self, "MouseDeparted");
737 Thurallor-7095
end
738 Thurallor-7095
 
739 116 Thurallor-7095
function Bar:MouseWheel(args)
740 Thurallor-7095
    local dir = args.Direction;
741 117 Thurallor-7095
    local prevSlot = args.s;
742 Thurallor-7095
    local mousePos = prevSlot and (prevSlot > 0) and self.slots[prevSlot].pos;
743 116 Thurallor-7095
 
744 Thurallor-7095
    -- Increment wheel position according to chosen wheel speed
745 Thurallor-7095
    self.wheelPosition = self.wheelPosition + (dir * self.settings.wheelSpeed);
746 Thurallor-7095
    if (math.abs(self.wheelPosition) < 1) then
747 Thurallor-7095
        -- More wheel motion is needed
748 Thurallor-7095
        return;
749 Thurallor-7095
    end
750 Thurallor-7095
    dir = self.wheelPosition;
751 Thurallor-7095
    self.wheelPosition = 0;
752 121 Thurallor-7095
    if (self.Log) then
753 Thurallor-7095
        if (dir > 0) then
754 Thurallor-7095
            DoCallbacks(self, "Log", {"wheel moved forward", "MOUSE"});
755 Thurallor-7095
        else
756 Thurallor-7095
            DoCallbacks(self, "Log", {"wheel moved backward", "MOUSE"});
757 Thurallor-7095
        end
758 Thurallor-7095
    end
759 116 Thurallor-7095
 
760 Thurallor-7095
    -- Find next or previous visible slot
761 117 Thurallor-7095
    local s = self.cursorSlot;
762 116 Thurallor-7095
    repeat
763 Thurallor-7095
        s = s + dir;
764 Thurallor-7095
        if (s > #self.slots) then
765 Thurallor-7095
            s = 1;
766 Thurallor-7095
        elseif (s < 1) then
767 Thurallor-7095
            s = #self.slots;
768 Thurallor-7095
        end
769 Thurallor-7095
        slot = self.slots[s];
770 Thurallor-7095
        if ((s == self.cursorSlot) or (not slot)) then
771 Thurallor-7095
            -- No other visible slots; do nothing.
772 Thurallor-7095
            return;
773 Thurallor-7095
        end
774 Thurallor-7095
    until (not (slot.hidden or slot.isFolded));
775 Thurallor-7095
 
776 Thurallor-7095
    -- Notify slot under cursor that the mouse has exited, to turn off the highlight
777 117 Thurallor-7095
    if (prevSlot) then
778 116 Thurallor-7095
        DoCallbacks(self.slots[prevSlot], "MouseLeave");
779 Thurallor-7095
    end
780 Thurallor-7095
    self:SetCursorSlot(s);
781 117 Thurallor-7095
 
782 Thurallor-7095
    -- Make sure the item under the cursor is always clickable.  This hack is
783 Thurallor-7095
    -- necessary because as the slot moves, no MouseEnter event occurs and
784 Thurallor-7095
    -- hence no MouseClick events can be received.
785 Thurallor-7095
    for object, pos in pairs(self.visibleSlots) do
786 Thurallor-7095
        if (pos == mousePos) then
787 Thurallor-7095
            object:SetVisible(false);
788 Thurallor-7095
            object:SetVisible(true);
789 Thurallor-7095
            break;
790 Thurallor-7095
        end
791 Thurallor-7095
    end
792 116 Thurallor-7095
end
793 Thurallor-7095
 
794 2 Thurallor-7095
function Bar:EditCaption()
795 Thurallor-7095
    if (self.captionEditor == nil) then
796 Thurallor-7095
        self.captionEditor = CaptionEditor("BarCaption", self, self.caption.label:GetWidth(), self.caption.label:GetHeight(), self.settings.caption.text);
797 121 Thurallor-7095
        self.captionEditor.Closed = function()
798 2 Thurallor-7095
            self.captionEditor = nil;
799 Thurallor-7095
        end
800 Thurallor-7095
    end
801 Thurallor-7095
end
802 Thurallor-7095
 
803 Thurallor-7095
function Bar:EditSequence()
804 Thurallor-7095
    if (self.sequenceEditor == nil) then
805 Thurallor-7095
        self.sequenceEditor = SequenceEditor(self, self.settings);
806 121 Thurallor-7095
        self.sequenceEditor.Closed = function()
807 2 Thurallor-7095
            self.sequenceEditor = nil;
808 Thurallor-7095
        end
809 Thurallor-7095
    end
810 Thurallor-7095
end
811 Thurallor-7095
 
812 121 Thurallor-7095
function Bar:OpenDebugWindow()
813 Thurallor-7095
    local title = L:GetText("/BarMenu/Debug") .. ": " .. self.settings.caption.text;
814 Thurallor-7095
    local debugWindow = Thurallor.UI.LogWindow(title, { self });
815 Thurallor-7095
    debugWindow:SetBackColor(self.color);
816 Thurallor-7095
    debugWindow:SetTrace("MOUSE", "Mouse actions", true);
817 Thurallor-7095
    debugWindow:SetTrace("BAR", "Bar status changes", true);
818 146 Thurallor-7095
    debugWindow:SetTrace("ADVANCE", "Bar advancement", true);
819 121 Thurallor-7095
    debugWindow:SetTrace("SPECIAL-SLOT", "Special slot actions", true);
820 Thurallor-7095
    debugWindow:SetTrace("EVENT", "Event behaviours", true);
821 Thurallor-7095
    debugWindow:SetVisible(true);
822 Thurallor-7095
    debugWindow:AppendText("Debugging started");
823 Thurallor-7095
 
824 Thurallor-7095
    -- Forward log information fron the Gears object to the DebugWindow.
825 Thurallor-7095
    self.gearsSlot.Log = function(_, args)
826 Thurallor-7095
        if (self.Log == nil) then
827 Thurallor-7095
            -- All debug windows closed.
828 Thurallor-7095
            self.gearsSlot.Log = nil;
829 Thurallor-7095
        else
830 Thurallor-7095
            DoCallbacks(self, "Log", args);
831 Thurallor-7095
        end
832 Thurallor-7095
    end
833 Thurallor-7095
end
834 Thurallor-7095
 
835 2 Thurallor-7095
function Bar:FormatCaptionLabel(control, alignment)
836 Thurallor-7095
    control:SetFont(self.settings.caption.font);
837 Thurallor-7095
    control:SetForeColor(self.color);
838 Thurallor-7095
    control:SetFontStyle(Turbine.UI.FontStyle.Outline);
839 Thurallor-7095
    control:SetOutlineColor(Turbine.UI.Color(0.75, 0, 0, 0));
840 Thurallor-7095
    control:SetTextAlignment(alignment);
841 Thurallor-7095
    control:SetWidth(self.settings.caption.width);
842 Thurallor-7095
    control:SetHeight(self.settings.caption.height);
843 169 Thurallor-7095
    control:SetText(control:GetText());
844 2 Thurallor-7095
end
845 Thurallor-7095
 
846 8 Thurallor-7095
function Bar:MoveToMouseCursor()
847 125 Thurallor-7095
    -- If animating, go head and complete the animation instantaneously.
848 Thurallor-7095
    -- User is going to want to click the slot immediately; and we need
849 Thurallor-7095
    -- to know where the slot is going to end up in order to reposition the
850 Thurallor-7095
    -- bar properly.
851 Thurallor-7095
    if (self.animationStartTime) then
852 Thurallor-7095
        self:Animate(self.settings.animation.duration);
853 Thurallor-7095
    end
854 Thurallor-7095
 
855 111 Thurallor-7095
    -- PointToScreen doesn't work with scaled windows, so we have to do the calculations ourselves.
856 Thurallor-7095
    local winLeft, winTop = Turbine.UI.Window.GetPosition(self);
857 Thurallor-7095
    local containerX, containerY = self.slotContainer:GetPosition();
858 158 Thurallor-7095
    local scale = self:GetScale() / 32;
859 111 Thurallor-7095
    containerX = containerX * scale;
860 Thurallor-7095
    containerY = containerY * scale;
861 Thurallor-7095
    local cursorX, cursorY = self.cursor:GetPosition();
862 Thurallor-7095
    cursorX = cursorX * scale + containerX + winLeft;
863 Thurallor-7095
    cursorY = cursorY * scale + containerY + winTop;
864 Thurallor-7095
    local cursorWidth = self.cursor:GetWidth() * scale;
865 Thurallor-7095
    local cursorHeight = self.cursor:GetSize() * scale;
866 Thurallor-7095
    local cursorCenter = (cursorX + math.floor(cursorWidth / 2));
867 Thurallor-7095
    local cursorMiddle = (cursorY + math.floor(cursorHeight / 2));
868 Thurallor-7095
    local mouseX, mouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
869 8 Thurallor-7095
    self:OffsetPosition(mouseX - cursorCenter, mouseY - cursorMiddle);
870 31 Thurallor-7095
    Turbine.UI.Window.Activate(self);
871 125 Thurallor-7095
 
872 Thurallor-7095
    -- Make sure the item under the cursor is always clickable.  This hack is
873 Thurallor-7095
    -- necessary because as the slot moves, no MouseEnter event occurs and
874 Thurallor-7095
    -- hence no MouseClick events can be received.
875 Thurallor-7095
    self.slots[self.cursorSlot]:SetVisible(false);
876 Thurallor-7095
    self.slots[self.cursorSlot]:SetVisible(true);
877 8 Thurallor-7095
end
878 Thurallor-7095
 
879 13 Thurallor-7095
-- Bar is positioned with respect to the topmost/leftmost quickslot.
880 Thurallor-7095
function Bar:GetSlotsScreenCoords()
881 Thurallor-7095
    local winLeft, winTop = Turbine.UI.Window.GetPosition(self);
882 Thurallor-7095
    local firstLeft, firstTop = self:GetSlotCoords(1);
883 26 Thurallor-7095
    local lastLeft, lastTop = self:GetSlotCoords(self.displaySlots);
884 13 Thurallor-7095
    local slotLeft, slotTop = math.min(firstLeft, lastLeft), math.min(firstTop, lastTop);
885 Thurallor-7095
    local slotRight = math.max(firstLeft, lastLeft) + self.settings.slotSize;
886 Thurallor-7095
    local slotBottom = math.max(firstTop, lastTop) + self.settings.slotSize;
887 158 Thurallor-7095
    local scale = self:GetScale() / 32;
888 16 Thurallor-7095
    -- If animating, use destination position (self.slotsLeft, self.slotsTop) rather than actual current position (self.slotContainer:GetPosition).
889 Thurallor-7095
    local left = winLeft + scale * (self.slotsLeft + slotLeft);
890 Thurallor-7095
    local top = winTop + scale * (self.slotsTop + slotTop);
891 Thurallor-7095
    local width = scale * (slotRight - slotLeft);
892 Thurallor-7095
    local height = scale * (slotBottom - slotTop);
893 13 Thurallor-7095
    return left, top, width, height;
894 Thurallor-7095
end
895 Thurallor-7095
 
896 Thurallor-7095
function Bar:SetPosition(left, top)
897 26 Thurallor-7095
    local anchorLeft, anchorTop = self.manager:GetAnchorPosition(self.settings.anchor);
898 27 Thurallor-7095
    local changed = true;
899 26 Thurallor-7095
    if (left == nil) then
900 Thurallor-7095
        left = self.settings.position.left + anchorLeft;
901 Thurallor-7095
        top = self.settings.position.top + anchorTop;
902 27 Thurallor-7095
        changed = false;
903 26 Thurallor-7095
    end
904 13 Thurallor-7095
    local winLeft, winTop = Turbine.UI.Window.GetPosition(self);
905 Thurallor-7095
    local slotLeft, slotTop = self:GetSlotsScreenCoords();
906 Thurallor-7095
    local leftOffset, topOffset = slotLeft - winLeft, slotTop - winTop;
907 Thurallor-7095
    Turbine.UI.Window.SetPosition(self, left - leftOffset, top - topOffset);
908 27 Thurallor-7095
    if (changed) then
909 Thurallor-7095
        self.settings.position = { left = left - anchorLeft; top = top - anchorTop };
910 Thurallor-7095
        self:SaveSettings(false);
911 Thurallor-7095
    end
912 13 Thurallor-7095
end
913 Thurallor-7095
 
914 26 Thurallor-7095
function Bar:SetAnchorPoint(anchor)
915 Thurallor-7095
    local left, top = self:GetPosition();
916 Thurallor-7095
    self.settings.anchor = anchor;
917 Thurallor-7095
    self:SetPosition(left, top);
918 13 Thurallor-7095
end
919 Thurallor-7095
 
920 26 Thurallor-7095
-- Returns the position with respect to the top, left corner of the screen, regardless of anchor point.
921 13 Thurallor-7095
function Bar:GetPosition()
922 26 Thurallor-7095
    local anchorLeft, anchorTop = self.manager:GetAnchorPosition(self.settings.anchor);
923 Thurallor-7095
    return anchorLeft + self.settings.position.left, anchorTop + self.settings.position.top;
924 13 Thurallor-7095
end
925 Thurallor-7095
 
926 2 Thurallor-7095
function Bar:OffsetPosition(deltaX, deltaY)
927 16 Thurallor-7095
    local left, top = self:GetPosition();
928 Thurallor-7095
    self:SetPosition(left + deltaX, top + deltaY);
929 2 Thurallor-7095
end
930 Thurallor-7095
 
931 201 Thurallor-7095
-- Finds the topmost group containing this bar which has the "bars move together" option enabled.
932 Thurallor-7095
function Bar:GetTopTogetherGroup()
933 Thurallor-7095
    return self.parent:GetTopTogetherGroup();
934 Thurallor-7095
end
935 Thurallor-7095
 
936 2 Thurallor-7095
function Bar:SnapToGrid()
937 13 Thurallor-7095
    local left, top = self:GetSlotsScreenCoords();
938 158 Thurallor-7095
    local newLeft, newTop = self.parent.manager:GetNearestGridPos(left, top, self:GetScale());
939 16 Thurallor-7095
    self:SetPosition(newLeft, newTop);
940 2 Thurallor-7095
    self:SaveSettings(false);
941 Thurallor-7095
end
942 Thurallor-7095
 
943 201 Thurallor-7095
function Bar:AddSettingsMenuItem(parent, itemName, _, fromOptionsPanel)
944 2 Thurallor-7095
    local item = Turbine.UI.MenuItem(L:GetText(itemName), true, false);
945 200 Thurallor-7095
    item._name = itemName;
946 Thurallor-7095
    item._parent = parent;
947 Thurallor-7095
    parent._itemsByName = parent._itemsByName or {};
948 Thurallor-7095
    parent._itemsByName[itemName] = item;
949 2 Thurallor-7095
    parent:GetItems():Add(item);
950 Thurallor-7095
 
951 Thurallor-7095
    if (itemName == "Root") then
952 Thurallor-7095
        local prevContext = L:SetContext("/BarMenu");
953 Thurallor-7095
        parent:GetItems():Clear();
954 13 Thurallor-7095
        if (fromOptionsPanel and (not self:IsHidden())) then
955 2 Thurallor-7095
            self:AddSettingsMenuItem(parent, "Find");
956 Thurallor-7095
        end
957 Thurallor-7095
        self:AddSettingsMenuItem(parent, "Hide");
958 26 Thurallor-7095
        if (self.settings.visibleSlots > 1) then
959 Thurallor-7095
            if (self:IsCollapsed()) then
960 Thurallor-7095
                self:AddSettingsMenuItem(parent, "Expand");
961 Thurallor-7095
            else
962 Thurallor-7095
                self:AddSettingsMenuItem(parent, "Collapse");
963 Thurallor-7095
            end
964 Thurallor-7095
        end
965 2 Thurallor-7095
        self:AddSettingsMenuItem(parent, "Clone");
966 Thurallor-7095
        self:AddSettingsMenuItem(parent, "Delete");
967 Thurallor-7095
        self:AddSettingsMenuItem(parent, "Export");
968 Thurallor-7095
        self:AddSettingsMenuItem(parent, "EditSequence");
969 8 Thurallor-7095
        self:AddSettingsMenuItem(parent, "EventBehaviors");
970 2 Thurallor-7095
        self:AddSettingsMenuItem(parent, "Settings");
971 121 Thurallor-7095
        self:AddSettingsMenuItem(parent, "Debug");
972 13 Thurallor-7095
        if (not fromOptionsPanel) then
973 28 Thurallor-7095
            if (self.parent ~= self.manager) then
974 201 Thurallor-7095
                local groupItem = self:AddSettingsMenuItem(parent, "Group");
975 Thurallor-7095
                local groupName = self.parent:GetName();
976 Thurallor-7095
                local text = groupItem:GetText();
977 Thurallor-7095
                text = text:gsub("<name>", groupName);
978 Thurallor-7095
                groupItem:SetText(text);
979 28 Thurallor-7095
            end
980 200 Thurallor-7095
            self:AddSettingsMenuItem(parent, "Global");
981 5 Thurallor-7095
            self:AddSettingsMenuItem(parent, "Directory");
982 2 Thurallor-7095
        end
983 Thurallor-7095
        L:SetContext(prevContext);
984 121 Thurallor-7095
    elseif (itemName == "Debug") then
985 Thurallor-7095
        item:SetText(item:GetText() .. "...");
986 Thurallor-7095
        item.Click = function()
987 Thurallor-7095
            self:OpenDebugWindow();
988 Thurallor-7095
        end
989 26 Thurallor-7095
    elseif (itemName == "Expand") then
990 121 Thurallor-7095
        item.Click = function()
991 26 Thurallor-7095
            self:Expand();
992 Thurallor-7095
        end
993 Thurallor-7095
    elseif (itemName == "Collapse") then
994 121 Thurallor-7095
        item.Click = function()
995 26 Thurallor-7095
            self:Collapse();
996 Thurallor-7095
        end
997 5 Thurallor-7095
    elseif (itemName == "Directory") then
998 121 Thurallor-7095
        item.Click = function()
999 177 Thurallor-7095
            self.manager:ShowDirectory("bars");
1000 5 Thurallor-7095
        end
1001 2 Thurallor-7095
    elseif (itemName == "Export") then
1002 121 Thurallor-7095
        item.Click = function()
1003 2 Thurallor-7095
            self:Export();
1004 Thurallor-7095
        end
1005 Thurallor-7095
    elseif (itemName == "Find") then
1006 199 Thurallor-7095
        item.Click = function(ctl)
1007 Thurallor-7095
            self:Find(ctl);
1008 2 Thurallor-7095
        end
1009 Thurallor-7095
    elseif (itemName == "Hide") then
1010 Thurallor-7095
        item:SetChecked(self.settings.hidden);
1011 121 Thurallor-7095
        item.Click = function()
1012 2 Thurallor-7095
            self:SetHidden(not self.settings.hidden);
1013 Thurallor-7095
        end
1014 26 Thurallor-7095
    elseif (itemName == "Position") then
1015 Thurallor-7095
        local prevContext = L:SetContext("PositionMenu");
1016 Thurallor-7095
        self:AddSettingsMenuItem(item, "RelativeTo");
1017 201 Thurallor-7095
        self:AddSettingsMenuItem(item, "Draggable");
1018 26 Thurallor-7095
        L:SetContext(prevContext);
1019 201 Thurallor-7095
    elseif (itemName == "Draggable") then
1020 Thurallor-7095
        item:SetChecked(not self.settings.locked);
1021 121 Thurallor-7095
        item.Click = function()
1022 201 Thurallor-7095
            local locked = not self.settings.locked;
1023 Thurallor-7095
            self:SetLocked(locked);
1024 2 Thurallor-7095
        end
1025 26 Thurallor-7095
    elseif (itemName == "RelativeTo") then
1026 Thurallor-7095
        local prevContext = L:SetContext("RelativeToMenu");
1027 Thurallor-7095
        for text in values(L:GetSortedTexts()) do
1028 Thurallor-7095
            local anchor = L:GetItem(text);
1029 Thurallor-7095
            local newItem = self:AddSettingsMenuItem(item, anchor);
1030 Thurallor-7095
            newItem:SetChecked(anchor == self.settings.anchor);
1031 31 Thurallor-7095
            newItem:SetEnabled(anchor ~= self.settings.anchor);
1032 121 Thurallor-7095
            newItem.Click = function()
1033 26 Thurallor-7095
                self:SetAnchorPoint(anchor);
1034 Thurallor-7095
            end
1035 Thurallor-7095
        end
1036 Thurallor-7095
        L:SetContext(prevContext);
1037 2 Thurallor-7095
    elseif (itemName == "EditSequence") then
1038 Thurallor-7095
        item:SetEnabled(not self.sequenceEditor);
1039 121 Thurallor-7095
        item.Click = function()
1040 2 Thurallor-7095
            self:EditSequence();
1041 Thurallor-7095
        end
1042 8 Thurallor-7095
    elseif (itemName == "EventBehaviors") then
1043 Thurallor-7095
        local prevContext = L:SetContext("/EventBehaviorsMenu");
1044 Thurallor-7095
        if (self.settings.eventsEnabled) then
1045 200 Thurallor-7095
            self:AddSettingsMenuItem(item, "AddBehavior");
1046 8 Thurallor-7095
            if (#self.settings.eventHandlers > 0) then
1047 Thurallor-7095
                self:AddSettingsMenuItem(item, "CurrentBehaviors");
1048 Thurallor-7095
            end
1049 Thurallor-7095
            self:AddSettingsMenuItem(item, "DisableEvents");
1050 Thurallor-7095
        else
1051 Thurallor-7095
            self:AddSettingsMenuItem(item, "EnableEvents");
1052 Thurallor-7095
        end
1053 Thurallor-7095
        L:SetContext(prevContext);
1054 Thurallor-7095
    elseif (itemName == "EnableEvents") then
1055 200 Thurallor-7095
        item.Click = function(ctl)
1056 177 Thurallor-7095
            self:SetEventHandlersEnabled(true);
1057 200 Thurallor-7095
            self:RedisplayMenu(ctl._parent);
1058 8 Thurallor-7095
        end
1059 Thurallor-7095
    elseif (itemName == "DisableEvents") then
1060 200 Thurallor-7095
        item.Click = function(ctl)
1061 177 Thurallor-7095
            self:SetEventHandlersEnabled(false);
1062 200 Thurallor-7095
            self:RedisplayMenu(ctl._parent);
1063 8 Thurallor-7095
        end
1064 Thurallor-7095
    elseif (itemName == "CurrentBehaviors") then
1065 Thurallor-7095
        if (self.settings.eventHandlers) then
1066 Thurallor-7095
            for h = 1, #self.settings.eventHandlers do
1067 Thurallor-7095
                local handler = self.settings.eventHandlers[h];
1068 Thurallor-7095
                local handlerItem = Turbine.UI.MenuItem(handler.description, true, false);
1069 Thurallor-7095
                item:GetItems():Add(handlerItem);
1070 200 Thurallor-7095
                handlerItem._parent = item;
1071 8 Thurallor-7095
                local removeItem = Turbine.UI.MenuItem(L:GetText("Remove"), true, false);
1072 Thurallor-7095
                handlerItem:GetItems():Add(removeItem);
1073 200 Thurallor-7095
                removeItem._parent = handlerItem;
1074 Thurallor-7095
                removeItem.Click = function(ctl)
1075 8 Thurallor-7095
                    self:RemoveEventHandler(h);
1076 200 Thurallor-7095
                    self:RedisplayMenu(ctl._parent._parent);
1077 8 Thurallor-7095
                end
1078 Thurallor-7095
            end
1079 Thurallor-7095
        end
1080 Thurallor-7095
    elseif (itemName == "AddBehavior") then
1081 20 Thurallor-7095
        local prevContext = L:SetContext("/EventBehaviorsMenu/Actions");
1082 8 Thurallor-7095
        self:AddSettingsMenuItem(item, "ShowBar");
1083 Thurallor-7095
        self:AddSettingsMenuItem(item, "HideBar");
1084 Thurallor-7095
        self:AddSettingsMenuItem(item, "ResetBar");
1085 16 Thurallor-7095
        self.availableEvents = self.manager:GetEventNames();
1086 8 Thurallor-7095
        self:AddSettingsMenuItem(item, "MoveToCursor");
1087 26 Thurallor-7095
        self:AddSettingsMenuItem(item, "ExpandBar");
1088 Thurallor-7095
        self:AddSettingsMenuItem(item, "CollapseBar");
1089 128 Thurallor-7095
        self:AddSettingsMenuItem(item, "SetTransparency");
1090 43 Thurallor-7095
        self:AddSettingsMenuItem(item, "StartExecuting");
1091 Thurallor-7095
        self:AddSettingsMenuItem(item, "StopExecuting");
1092 20 Thurallor-7095
        L:SetContext(prevContext);
1093 128 Thurallor-7095
    elseif (itemName == "SetTransparency") then
1094 Thurallor-7095
        local prevContext = L:SetContext("/BarMenu/SettingsMenu/TransparencyMenu");
1095 Thurallor-7095
        local subItem = self:AddSettingsMenuItem(item, "SetTransparency:");
1096 200 Thurallor-7095
        subItem._name = "SetTransparency";
1097 128 Thurallor-7095
        subItem:SetText(L:GetText("UseGlobalSetting"));
1098 Thurallor-7095
        subItem.argName = L:GetText("default");
1099 Thurallor-7095
        subItem.argValue = "nil";
1100 Thurallor-7095
        for i = 0, 10 do
1101 Thurallor-7095
            subItem = self:AddSettingsMenuItem(item, "SetTransparency:");
1102 200 Thurallor-7095
            subItem._name = "SetTransparency";
1103 128 Thurallor-7095
            subItem.argName = L:GetText("PartiallyTransparent"):gsub("<pct>", i * 10);
1104 Thurallor-7095
            if (i == 0) then
1105 Thurallor-7095
                subItem:SetText(L:GetText("FullyTransparent"));
1106 Thurallor-7095
                subItem.argValue = "0";
1107 Thurallor-7095
            elseif (i == 10) then
1108 Thurallor-7095
                subItem:SetText(L:GetText("FullyOpaque"));
1109 Thurallor-7095
                subItem.argValue = "1";
1110 Thurallor-7095
            else
1111 Thurallor-7095
                subItem:SetText(subItem.argName);
1112 Thurallor-7095
                subItem.argValue = "0." .. i;
1113 Thurallor-7095
            end
1114 Thurallor-7095
        end
1115 Thurallor-7095
        L:SetContext(prevContext);
1116 Thurallor-7095
    elseif (string.find("|SetTransparency:|ShowBar|HideBar|ResetBar|MoveToCursor|ExpandBar|CollapseBar|StartExecuting|StopExecuting|", "|" .. itemName .. "|")) then
1117 20 Thurallor-7095
        local prevContext = L:SetContext("/EventBehaviorsMenu/Triggers");
1118 Thurallor-7095
        self.availableEvents = self.manager:GetEventNames();
1119 Thurallor-7095
 
1120 Thurallor-7095
        -- Show only the options that make sense
1121 31 Thurallor-7095
        if (itemName ~= "MoveToCursor") then
1122 43 Thurallor-7095
            if ((itemName ~= "ResetBar") and (itemName ~= "StopExecuting")) then
1123 34 Thurallor-7095
                self:AddSettingsMenuItem(item, "AtStartup");
1124 Thurallor-7095
            end
1125 31 Thurallor-7095
            self:AddSettingsMenuItem(item, "WhenCombatBegins");
1126 Thurallor-7095
            self:AddSettingsMenuItem(item, "WhenCombatEnds");
1127 Thurallor-7095
        end
1128 43 Thurallor-7095
        self:AddSettingsMenuItem(item, "WhenTargetChanges");
1129 128 Thurallor-7095
        if (string.find("|SetTransparency:|ResetBar|ExpandBar|StartExecuting|", "|" .. itemName .. "|")) then
1130 20 Thurallor-7095
            self:AddSettingsMenuItem(item, "WhenMouseArrives");
1131 26 Thurallor-7095
        end
1132 128 Thurallor-7095
        if (string.find("|SetTransparency:|HideBar|ResetBar|CollapseBar|StopExecuting|", "|" .. itemName .. "|")) then
1133 20 Thurallor-7095
            self:AddSettingsMenuItem(item, "WhenMouseDeparts");
1134 Thurallor-7095
        end
1135 128 Thurallor-7095
        if (string.find("|SetTransparency:|ShowBar|ResetBar|MoveToCursor|StartExecuting|StopExecuting|", "|" .. itemName .. "|")) then
1136 35 Thurallor-7095
            self:AddSettingsMenuItem(item, "WhenTraitTreeChanges");
1137 111 Thurallor-7095
            self:AddSettingsMenuItem(item, "WhenStanceChanges");
1138 35 Thurallor-7095
        end
1139 200 Thurallor-7095
        self:AddSettingsMenuItem(item, "WhenPetChanges");
1140 Thurallor-7095
        self:AddSettingsMenuItem(item, "WhenMountChanges");
1141 165 Thurallor-7095
        self:AddSettingsMenuItem(item, "WhenYouAreIncapacitated");
1142 Thurallor-7095
        self:AddSettingsMenuItem(item, "WhenYouAreRevived");
1143 33 Thurallor-7095
        self:AddSettingsMenuItem(item, "WhenEventOccurs");
1144 20 Thurallor-7095
        L:SetContext(prevContext);
1145 8 Thurallor-7095
    elseif (itemName == "WhenEventOccurs") then
1146 33 Thurallor-7095
        if (#self.availableEvents > 0) then
1147 Thurallor-7095
            for e = 1, #self.availableEvents do
1148 Thurallor-7095
                local eventName = self.availableEvents[e];
1149 Thurallor-7095
                local eventNameItem = Turbine.UI.MenuItem(eventName, true, false);
1150 200 Thurallor-7095
                eventNameItem._parent = item;
1151 33 Thurallor-7095
                item:GetItems():Add(eventNameItem);
1152 200 Thurallor-7095
                eventNameItem.Click = function(ctl)
1153 Thurallor-7095
                    self:AddEventHandler("WhenEventOccurs:" .. eventName, parent._name, parent.argValue, parent.argName);
1154 Thurallor-7095
                    self:RedisplayMenu(ctl._parent._parent._parent._parent, "CurrentBehaviors");
1155 33 Thurallor-7095
                end
1156 8 Thurallor-7095
            end
1157 33 Thurallor-7095
        else
1158 Thurallor-7095
            local noEventsItem = Turbine.UI.MenuItem(L:GetText("/EventBehaviorsMenu/NoEventsDefined"), false, false);
1159 Thurallor-7095
            item:GetItems():Add(noEventsItem);
1160 8 Thurallor-7095
        end
1161 177 Thurallor-7095
        local eventDirectoryItem = Turbine.UI.MenuItem("( . . . )", true, false);
1162 Thurallor-7095
        eventDirectoryItem.Click = function()
1163 Thurallor-7095
            self.manager:ShowDirectory("events");
1164 Thurallor-7095
        end
1165 Thurallor-7095
        item:GetItems():Add(eventDirectoryItem);
1166 200 Thurallor-7095
    elseif (string.find("|AtStartup|WhenTargetChanges|WhenCombatBegins|WhenCombatEnds|WhenMouseArrives|WhenMouseDeparts|WhenTraitTreeChanges|WhenStanceChanges|WhenPetChanges|WhenMountChanges|WhenYouAreIncapacitated|WhenYouAreRevived|", "|" .. itemName .. "|")) then
1167 Thurallor-7095
        item.Click = function(ctl)
1168 Thurallor-7095
            self:AddEventHandler(itemName, parent._name, parent.argValue, parent.argName);
1169 Thurallor-7095
            self:RedisplayMenu(ctl._parent._parent._parent, "CurrentBehaviors");
1170 8 Thurallor-7095
        end
1171 2 Thurallor-7095
    elseif (itemName == "Settings") then
1172 Thurallor-7095
        local prevContext = L:SetContext("SettingsMenu");
1173 201 Thurallor-7095
        self:AddSettingsMenuItem(item, "Position");
1174 2 Thurallor-7095
        self:AddSettingsMenuItem(item, "Orientation");
1175 Thurallor-7095
        if ((self.settings.orientation == "Up") or (self.settings.orientation == "Down")) then
1176 Thurallor-7095
            self:AddSettingsMenuItem(item, "Height");
1177 Thurallor-7095
        else
1178 Thurallor-7095
            self:AddSettingsMenuItem(item, "Width");
1179 Thurallor-7095
        end
1180 Thurallor-7095
        self:AddSettingsMenuItem(item, "Cursor");
1181 116 Thurallor-7095
        self:AddSettingsMenuItem(item, "MouseWheel");
1182 2 Thurallor-7095
        self:AddSettingsMenuItem(item, "Caption");
1183 Thurallor-7095
        self:AddSettingsMenuItem(item, "Color");
1184 128 Thurallor-7095
        self:AddSettingsMenuItem(item, "Transparency");
1185 158 Thurallor-7095
        self:AddSettingsMenuItem(item, "Scale");
1186 2 Thurallor-7095
        self:AddSettingsMenuItem(item, "Animation");
1187 16 Thurallor-7095
        self:AddSettingsMenuItem(item, "HideAutomatics");
1188 Thurallor-7095
        self:AddSettingsMenuItem(item, "HideInactiveBranches");
1189 43 Thurallor-7095
        self:AddSettingsMenuItem(item, "ContinuousExecution");
1190 2 Thurallor-7095
        L:SetContext(prevContext);
1191 43 Thurallor-7095
    elseif (itemName == "ContinuousExecution") then
1192 Thurallor-7095
        item:SetChecked(self.settings.continuous);
1193 121 Thurallor-7095
        item.Click = function()
1194 43 Thurallor-7095
            self.settings.continuous = not self.settings.continuous;
1195 Thurallor-7095
            if (self.settings.continuous) then
1196 Thurallor-7095
                -- Enforce hiding of automatics and inactive branches
1197 Thurallor-7095
                self.settings.hideAutomatics = true;
1198 Thurallor-7095
                self.settings.hideInactiveBranches = true;
1199 Thurallor-7095
            else
1200 Thurallor-7095
                self.gearsSlot:SetRunning(false);
1201 Thurallor-7095
            end
1202 Thurallor-7095
            self:SaveSettings(false);
1203 Thurallor-7095
            self:ReapplySettings();
1204 Thurallor-7095
        end
1205 16 Thurallor-7095
    elseif (itemName == "HideAutomatics") then
1206 Thurallor-7095
        item:SetChecked(self.settings.hideAutomatics);
1207 121 Thurallor-7095
        item.Click = function()
1208 16 Thurallor-7095
            self.settings.hideAutomatics = not self.settings.hideAutomatics;
1209 43 Thurallor-7095
            if (not self.settings.hideAutomatics) then
1210 Thurallor-7095
                -- Continuous mode not allowed if showing automatics
1211 Thurallor-7095
                if (self.settings.continuous) then
1212 Thurallor-7095
                    self.gearsSlot:SetRunning(false);
1213 Thurallor-7095
                    self.settings.continuous = false;
1214 Thurallor-7095
                end
1215 Thurallor-7095
            end
1216 16 Thurallor-7095
            self:SaveSettings(false);
1217 Thurallor-7095
            self:ReapplySettings();
1218 Thurallor-7095
        end
1219 Thurallor-7095
    elseif (itemName == "HideInactiveBranches") then
1220 Thurallor-7095
        item:SetChecked(self.settings.hideInactiveBranches);
1221 121 Thurallor-7095
        item.Click = function()
1222 16 Thurallor-7095
            self.settings.hideInactiveBranches = not self.settings.hideInactiveBranches;
1223 43 Thurallor-7095
            if (not self.settings.hideInactiveBranches) then
1224 Thurallor-7095
                -- Continuous mode not allowed if showing inactive branches
1225 Thurallor-7095
                if (self.settings.continuous) then
1226 Thurallor-7095
                    self.gearsSlot:SetRunning(false);
1227 Thurallor-7095
                    self.settings.continuous = false;
1228 Thurallor-7095
                end
1229 Thurallor-7095
            end
1230 16 Thurallor-7095
            self:SaveSettings(false);
1231 Thurallor-7095
            self:ReapplySettings();
1232 Thurallor-7095
        end
1233 2 Thurallor-7095
    elseif (itemName == "Color") then
1234 Thurallor-7095
        item:SetEnabled(not self.colorPicker);
1235 121 Thurallor-7095
        item.Click = function()
1236 2 Thurallor-7095
            self:EditColor();
1237 Thurallor-7095
        end
1238 128 Thurallor-7095
    elseif (itemName == "Transparency") then
1239 Thurallor-7095
        local prevContext = L:SetContext("/BarMenu/SettingsMenu/TransparencyMenu");
1240 Thurallor-7095
        local checked = (self.settings.opacity == nil);
1241 158 Thurallor-7095
        local globalItem = Turbine.UI.MenuItem(L:GetText("UseGlobalSetting"), true, checked);
1242 Thurallor-7095
        globalItem.Click = function(obj)
1243 Thurallor-7095
            obj:SetChecked(true);
1244 128 Thurallor-7095
            self:SetTransparency(nil);
1245 Thurallor-7095
        end
1246 158 Thurallor-7095
        item:GetItems():Add(globalItem);
1247 Thurallor-7095
 
1248 Thurallor-7095
        checked = not checked;
1249 Thurallor-7095
        local labelItem = Turbine.UI.MenuItem("", true, checked);
1250 Thurallor-7095
        globalItem.labelItem = labelItem;
1251 Thurallor-7095
        labelItem.globalItem = globalItem;
1252 Thurallor-7095
        labelItem.UpdateLabel = function(obj)
1253 Thurallor-7095
            local prevContext = L:SetContext("/BarMenu/SettingsMenu/TransparencyMenu");
1254 Thurallor-7095
            local transparency = self:GetTransparency();
1255 Thurallor-7095
            local text;
1256 Thurallor-7095
            if (transparency == 0) then
1257 Thurallor-7095
                text = L:GetText("FullyTransparent");
1258 Thurallor-7095
            elseif (transparency == 1) then
1259 Thurallor-7095
                text = L:GetText("FullyOpaque");
1260 128 Thurallor-7095
            else
1261 158 Thurallor-7095
                text = L:GetText("PartiallyTransparent"):gsub("<pct>", math.floor(0.5 + transparency * 100));
1262 128 Thurallor-7095
            end
1263 158 Thurallor-7095
            obj.Label:SetText(text);
1264 Thurallor-7095
            L:SetContext(prevContext);
1265 128 Thurallor-7095
        end
1266 158 Thurallor-7095
        labelItem:UpdateLabel();
1267 Thurallor-7095
        labelItem.Click = function(obj)
1268 Thurallor-7095
            obj.KeepOpen = true;
1269 Thurallor-7095
            obj:SetChecked(true);
1270 Thurallor-7095
            self:SetTransparency(self:GetTransparency());
1271 Thurallor-7095
            obj.globalItem:SetChecked(false);
1272 Thurallor-7095
        end
1273 Thurallor-7095
        item:GetItems():Add(labelItem);
1274 Thurallor-7095
 
1275 160 Thurallor-7095
        local sliderItem = Turbine.UI.MenuItem("                                        ", false, false);
1276 158 Thurallor-7095
        local slider = Turbine.UI.Lotro.ScrollBar();
1277 Thurallor-7095
        slider.labelItem = labelItem;
1278 Thurallor-7095
        slider.globalItem = globalItem;
1279 Thurallor-7095
        globalItem.slider = slider;
1280 Thurallor-7095
        slider:SetSize(200, 10);
1281 Thurallor-7095
        slider:SetBackground("Thurallor/SequenceBars/Images/scrollbar_background_horiz.tga");
1282 Thurallor-7095
        slider:SetBlendMode(Turbine.UI.BlendMode.Overlay);
1283 Thurallor-7095
        slider:SetParent(sliderItem.Label);
1284 Thurallor-7095
        slider:SetMinimum(0);
1285 Thurallor-7095
        slider:SetMaximum(100);
1286 Thurallor-7095
        slider:SetSmallChange(1);
1287 Thurallor-7095
        slider:SetLargeChange(10);
1288 Thurallor-7095
        slider:SetValue(math.floor(0.5 + self:GetTransparency() * 100));
1289 Thurallor-7095
        slider.ValueChanged = function(obj)
1290 Thurallor-7095
            self:SetTransparency(obj:GetValue() / 100);
1291 Thurallor-7095
            obj.labelItem:UpdateLabel();
1292 Thurallor-7095
            obj.labelItem:SetChecked(true);
1293 Thurallor-7095
            obj.globalItem:SetChecked(false);
1294 Thurallor-7095
        end
1295 Thurallor-7095
        item:GetItems():Add(sliderItem);
1296 128 Thurallor-7095
        L:SetContext(prevContext);
1297 158 Thurallor-7095
    elseif (itemName == "Scale") then
1298 Thurallor-7095
        local prevContext = L:SetContext("/BarMenu/SettingsMenu/ScaleMenu");
1299 Thurallor-7095
        local checked = (self.settings.scale == nil);
1300 Thurallor-7095
        local globalItem = Turbine.UI.MenuItem(L:GetText("UseGlobalSetting"), true, checked);
1301 Thurallor-7095
        globalItem.Click = function(obj)
1302 Thurallor-7095
            obj:SetChecked(true);
1303 Thurallor-7095
            self:SetScale(nil);
1304 Thurallor-7095
        end
1305 Thurallor-7095
        item:GetItems():Add(globalItem);
1306 Thurallor-7095
 
1307 Thurallor-7095
        checked = not checked;
1308 Thurallor-7095
        local labelItem = Turbine.UI.MenuItem("", true, checked);
1309 Thurallor-7095
        globalItem.labelItem = labelItem;
1310 Thurallor-7095
        labelItem.globalItem = globalItem;
1311 Thurallor-7095
        labelItem.UpdateLabel = function(obj)
1312 Thurallor-7095
            local scale = self:GetScale();
1313 Thurallor-7095
            obj.Label:SetText(L:GetText("/PluginManager/OptionsTab/GlobalSettingsTab/UiScale") .. ": " .. string.format("%d", scale * 100 / 32) .. "%");
1314 Thurallor-7095
        end
1315 Thurallor-7095
        labelItem:UpdateLabel();
1316 Thurallor-7095
        labelItem.Click = function(obj)
1317 Thurallor-7095
            obj.KeepOpen = true;
1318 Thurallor-7095
            obj:SetChecked(true);
1319 Thurallor-7095
            self:SetScale(self:GetScale());
1320 Thurallor-7095
            obj.globalItem:SetChecked(false);
1321 Thurallor-7095
        end
1322 Thurallor-7095
        item:GetItems():Add(labelItem);
1323 Thurallor-7095
 
1324 160 Thurallor-7095
        local sliderItem = Turbine.UI.MenuItem("                                        ", false, false);
1325 158 Thurallor-7095
        local slider = Turbine.UI.Lotro.ScrollBar();
1326 Thurallor-7095
        slider.labelItem = labelItem;
1327 Thurallor-7095
        slider.globalItem = globalItem;
1328 Thurallor-7095
        globalItem.slider = slider;
1329 Thurallor-7095
        slider:SetSize(200, 10);
1330 Thurallor-7095
        slider:SetBackground("Thurallor/SequenceBars/Images/scrollbar_background_horiz.tga");
1331 Thurallor-7095
        slider:SetBlendMode(Turbine.UI.BlendMode.Overlay);
1332 Thurallor-7095
        slider:SetParent(sliderItem.Label);
1333 Thurallor-7095
        slider:SetMinimum(13);
1334 Thurallor-7095
        slider:SetMaximum(96);
1335 Thurallor-7095
        slider:SetSmallChange(1);
1336 Thurallor-7095
        slider:SetLargeChange(10);
1337 Thurallor-7095
        slider:SetValue(self:GetScale());
1338 Thurallor-7095
        slider.ValueChanged = function(obj)
1339 Thurallor-7095
            self:SetScale(obj:GetValue());
1340 Thurallor-7095
            obj.labelItem:UpdateLabel();
1341 Thurallor-7095
            obj.labelItem:SetChecked(true);
1342 Thurallor-7095
            obj.globalItem:SetChecked(false);
1343 Thurallor-7095
        end
1344 Thurallor-7095
        item:GetItems():Add(sliderItem);
1345 Thurallor-7095
        L:SetContext(prevContext);
1346 116 Thurallor-7095
    elseif (itemName == "MouseWheel") then
1347 Thurallor-7095
        local prevContext = L:SetContext("MouseWheelMenu");
1348 Thurallor-7095
        self:AddSettingsMenuItem(item, "WheelDisabled");
1349 Thurallor-7095
        self:AddSettingsMenuItem(item, "WheelForwardFast");
1350 Thurallor-7095
        self:AddSettingsMenuItem(item, "WheelForwardSlow");
1351 Thurallor-7095
        self:AddSettingsMenuItem(item, "WheelForwardVerySlow");
1352 Thurallor-7095
        self:AddSettingsMenuItem(item, "WheelReverseFast");
1353 Thurallor-7095
        self:AddSettingsMenuItem(item, "WheelReverseSlow");
1354 Thurallor-7095
        self:AddSettingsMenuItem(item, "WheelReverseVerySlow");
1355 Thurallor-7095
        L:SetContext(prevContext);
1356 Thurallor-7095
    elseif (string.find("|WheelDisabled|WheelForwardFast|WheelForwardSlow|WheelForwardVerySlow|WheelReverseFast|WheelReverseSlow|WheelReverseVerySlow|", "|" .. itemName .. "|")) then
1357 Thurallor-7095
        local wheelSpeed = { ["WheelDisabled"] = 0; ["WheelForwardFast"] = 1; ["WheelForwardSlow"] = 0.5; ["WheelForwardVerySlow"] = 0.2; ["WheelReverseFast"] = -1; ["WheelReverseSlow"] = -0.5; ["WheelReverseVerySlow"] = -0.2; };
1358 Thurallor-7095
        local checked = (self.settings.wheelSpeed == wheelSpeed[itemName]);
1359 Thurallor-7095
        item:SetChecked(checked);
1360 Thurallor-7095
        item:SetEnabled(not checked);
1361 121 Thurallor-7095
        item.Click = function()
1362 116 Thurallor-7095
            self.wheelPosition = 0;
1363 Thurallor-7095
            self.settings.wheelSpeed = wheelSpeed[itemName];
1364 117 Thurallor-7095
            self:ReapplySettings();
1365 116 Thurallor-7095
        end
1366 2 Thurallor-7095
    elseif (itemName == "Animation") then
1367 Thurallor-7095
        local prevContext = L:SetContext("AnimationMenu");
1368 Thurallor-7095
        self:AddSettingsMenuItem(item, "Instantaneous");
1369 Thurallor-7095
        self:AddSettingsMenuItem(item, "Fast");
1370 Thurallor-7095
        self:AddSettingsMenuItem(item, "Slow");
1371 Thurallor-7095
        self:AddSettingsMenuItem(item, "VerySlow");
1372 Thurallor-7095
        self:AddSettingsMenuItem(item, "Disabled");
1373 Thurallor-7095
        L:SetContext(prevContext);
1374 11 Thurallor-7095
    elseif (string.find("|Instantaneous|Fast|Slow|VerySlow|Disabled|", "|" .. itemName .. "|")) then
1375 2 Thurallor-7095
        local duration = { ["Instantaneous"] = 0; ["Fast"] = 0.05; ["Slow"] = 0.1; ["VerySlow"] = 0.5; ["Disabled"] = -1; };
1376 Thurallor-7095
        local checked = (self.settings.animation.duration == duration[itemName]);
1377 Thurallor-7095
        item:SetChecked(checked);
1378 Thurallor-7095
        item:SetEnabled(not checked);
1379 121 Thurallor-7095
        item.Click = function()
1380 2 Thurallor-7095
            self:SetAnimationSpeed(duration[itemName]);
1381 Thurallor-7095
        end
1382 Thurallor-7095
    elseif (itemName == "Orientation") then
1383 Thurallor-7095
        local prevContext = L:SetContext("OrientationMenu");
1384 Thurallor-7095
        self:AddSettingsMenuItem(item, "Up");
1385 Thurallor-7095
        self:AddSettingsMenuItem(item, "Right");
1386 Thurallor-7095
        self:AddSettingsMenuItem(item, "Left");
1387 Thurallor-7095
        self:AddSettingsMenuItem(item, "Down");
1388 Thurallor-7095
        L:SetContext(prevContext);
1389 Thurallor-7095
    elseif ((itemName == "Up") or (itemName == "Down") or (itemName == "Left") or (itemName == "Right")) then
1390 Thurallor-7095
        local checked = (self.settings.orientation == itemName);
1391 Thurallor-7095
        item:SetChecked(checked);
1392 Thurallor-7095
        item:SetEnabled(not checked);
1393 121 Thurallor-7095
        item.Click = function()
1394 2 Thurallor-7095
            self.settings.orientation = itemName;
1395 Thurallor-7095
            self:SaveSettings(false);
1396 Thurallor-7095
            self:Redraw();
1397 6 Thurallor-7095
            self:MoveOntoScreen();
1398 2 Thurallor-7095
        end
1399 11 Thurallor-7095
    elseif ((itemName == "Width") or (itemName == "Height")) then
1400 2 Thurallor-7095
        local size = self.settings.visibleSlots;
1401 6 Thurallor-7095
        local displayWidth, displayHeight = Turbine.UI.Display.GetSize();
1402 Thurallor-7095
        local minSize = 1, maxSize;
1403 Thurallor-7095
        if ((self.settings.orientation == "Up") or (self.settings.orientation == "Down")) then
1404 Thurallor-7095
            maxSize = math.floor(displayHeight / self.settings.slotSize);
1405 Thurallor-7095
        else
1406 Thurallor-7095
            maxSize = math.floor(displayWidth / self.settings.slotSize);
1407 Thurallor-7095
        end
1408 158 Thurallor-7095
        local prevContext = L:SetContext("/BarMenu/SettingsMenu/HeightWidthMenu");
1409 Thurallor-7095
 
1410 Thurallor-7095
        local labelItem = Turbine.UI.MenuItem("", true, false);
1411 Thurallor-7095
        labelItem.UpdateLabel = function(obj)
1412 Thurallor-7095
            local size = self.settings.visibleSlots;
1413 Thurallor-7095
            local text;
1414 Thurallor-7095
            if (size == 1) then
1415 Thurallor-7095
                text = L:GetText("/BarMenu/SettingsMenu/HeightWidthMenu/Slot");
1416 13 Thurallor-7095
            else
1417 158 Thurallor-7095
                text = L:GetText("/BarMenu/SettingsMenu/HeightWidthMenu/Slots");
1418 2 Thurallor-7095
            end
1419 158 Thurallor-7095
            text = text:gsub("<num>", tostring(size));
1420 Thurallor-7095
            obj.Label:SetText(text);
1421 2 Thurallor-7095
        end
1422 158 Thurallor-7095
        labelItem:UpdateLabel();
1423 Thurallor-7095
        labelItem.Click = function(obj)
1424 Thurallor-7095
            obj.KeepOpen = true;
1425 Thurallor-7095
        end
1426 Thurallor-7095
        item:GetItems():Add(labelItem);
1427 Thurallor-7095
 
1428 160 Thurallor-7095
        local sliderItem = Turbine.UI.MenuItem("                                        ", false, false);
1429 158 Thurallor-7095
        local slider = Turbine.UI.Lotro.ScrollBar();
1430 Thurallor-7095
        slider.labelItem = labelItem;
1431 Thurallor-7095
        slider:SetSize(200, 10);
1432 Thurallor-7095
        slider:SetBackground("Thurallor/SequenceBars/Images/scrollbar_background_horiz.tga");
1433 Thurallor-7095
        slider:SetBlendMode(Turbine.UI.BlendMode.Overlay);
1434 Thurallor-7095
        slider:SetParent(sliderItem.Label);
1435 Thurallor-7095
        slider:SetMinimum(minSize);
1436 Thurallor-7095
        slider:SetMaximum(maxSize);
1437 Thurallor-7095
        slider:SetSmallChange(1);
1438 Thurallor-7095
        slider:SetLargeChange(5);
1439 Thurallor-7095
        slider:SetValue(size);
1440 Thurallor-7095
        slider.ValueChanged = function(obj)
1441 160 Thurallor-7095
            local size = obj:GetValue();
1442 Thurallor-7095
            self.cursorHomePosNudger:SetMaxValue(size);
1443 Thurallor-7095
            if (size < self.settings.cursorHomePosition) then
1444 Thurallor-7095
                self.settings.cursorHomePosition = size;
1445 158 Thurallor-7095
            end
1446 160 Thurallor-7095
            self:ResizeBar(size);
1447 Thurallor-7095
            self:MoveOntoScreen();
1448 158 Thurallor-7095
            obj.labelItem:UpdateLabel();
1449 Thurallor-7095
        end
1450 Thurallor-7095
        item:GetItems():Add(sliderItem);
1451 2 Thurallor-7095
        L:SetContext(prevContext);
1452 Thurallor-7095
    elseif (itemName == "Cursor") then
1453 Thurallor-7095
        local prevContext = L:SetContext("CursorMenu");
1454 Thurallor-7095
        self:AddSettingsMenuItem(item, "Style");
1455 Thurallor-7095
        self:AddSettingsMenuItem(item, "HomePosition");
1456 Thurallor-7095
        L:SetContext(prevContext);
1457 Thurallor-7095
    elseif (itemName == "HomePosition") then
1458 160 Thurallor-7095
        local homePos = self.settings.cursorHomePosition;
1459 Thurallor-7095
        local minPos, maxPos = 1, self.settings.visibleSlots;
1460 Thurallor-7095
        local labelItem = Turbine.UI.MenuItem(L:GetText("/BarMenu/SettingsMenu/CursorMenu/HomePositionMenu/Slot"):gsub("<num>", ""), true, false);
1461 Thurallor-7095
        labelItem.Click = function(obj)
1462 Thurallor-7095
            obj.KeepOpen = true;
1463 2 Thurallor-7095
        end
1464 160 Thurallor-7095
        item:GetItems():Add(labelItem);
1465 Thurallor-7095
 
1466 Thurallor-7095
        local nudgerItem = Turbine.UI.MenuItem(" ", false, false);
1467 Thurallor-7095
        local nudger = Thurallor.UI.Nudger(nudgerItem, Turbine.UI.Lotro.Font.TrajanPro14, homePos, minPos, maxPos);
1468 Thurallor-7095
        nudger:SetWidth(30);
1469 Thurallor-7095
        nudger:SetPosition(25, 5);
1470 Thurallor-7095
        nudger.ValueChanged = function(obj)
1471 Thurallor-7095
            self:Expand();
1472 Thurallor-7095
            self.settings.cursorHomePosition = obj:GetValue();
1473 Thurallor-7095
            self:SaveSettings(false);
1474 Thurallor-7095
            self:Redraw();
1475 Thurallor-7095
        end
1476 Thurallor-7095
        self.cursorHomePosNudger = nudger;
1477 Thurallor-7095
 
1478 Thurallor-7095
        nudgerItem:SetHeight(nudger:GetHeight() + 5);
1479 Thurallor-7095
        nudgerItem.SetSize = function() end; -- don't allow the size to be adjusted by ContextMenu
1480 Thurallor-7095
        local container = item:GetItems();
1481 Thurallor-7095
        container:Add(nudgerItem);
1482 Thurallor-7095
        container:Add(Turbine.UI.MenuItem(" ", false, false));
1483 Thurallor-7095
        container:Add(Turbine.UI.MenuItem(" ", false, false));
1484 2 Thurallor-7095
    elseif (itemName == "Style") then
1485 Thurallor-7095
        local prevContext = L:SetContext("StyleMenu");
1486 11 Thurallor-7095
        local styles = {};
1487 2 Thurallor-7095
        for name, info in pairs(resources.Cursor) do
1488 Thurallor-7095
            local checked = (name == self.settings.cursorStyle);
1489 11 Thurallor-7095
            local text = L:GetText(name);
1490 Thurallor-7095
            local style = Turbine.UI.MenuItem(text, not checked, checked);
1491 Thurallor-7095
            styles[text] = style;
1492 121 Thurallor-7095
            style.Click = function()
1493 2 Thurallor-7095
                self:SetCursorStyle(name);
1494 Thurallor-7095
                self:SaveSettings(false);
1495 Thurallor-7095
                self:Redraw();
1496 Thurallor-7095
            end
1497 Thurallor-7095
        end
1498 11 Thurallor-7095
        -- Display alphabetically.
1499 Thurallor-7095
        for text in sorted_keys(styles) do
1500 Thurallor-7095
            item:GetItems():Add(styles[text]);
1501 Thurallor-7095
        end
1502 2 Thurallor-7095
        L:SetContext(prevContext);
1503 Thurallor-7095
    elseif (itemName == "Caption") then
1504 Thurallor-7095
        local prevContext = L:SetContext("CaptionMenu");
1505 Thurallor-7095
        self:AddSettingsMenuItem(item, "Edit");
1506 26 Thurallor-7095
        self:AddSettingsMenuItem(item, "CaptionPosition");
1507 112 Thurallor-7095
        self:AddSettingsMenuItem(item, "CaptionVisible");
1508 Thurallor-7095
        self:AddSettingsMenuItem(item, "CaptionClickable");
1509 2 Thurallor-7095
        L:SetContext(prevContext);
1510 Thurallor-7095
    elseif (itemName == "Edit") then
1511 Thurallor-7095
        item:SetEnabled(not self.captionEditor);
1512 121 Thurallor-7095
        item.Click = function()
1513 2 Thurallor-7095
            self:EditCaption();
1514 Thurallor-7095
        end
1515 112 Thurallor-7095
    elseif (itemName == "CaptionClickable") then
1516 Thurallor-7095
        item:SetChecked((not self.settings.caption.clickThru) and (self.settings.caption.visible ~= "Never"));
1517 Thurallor-7095
        item:SetEnabled(self.settings.caption.visible ~= "Never");
1518 121 Thurallor-7095
        item.Click = function()
1519 112 Thurallor-7095
            self:SetCaptionClickThru(not self.settings.caption.clickThru);
1520 2 Thurallor-7095
        end
1521 112 Thurallor-7095
    elseif (itemName == "CaptionVisible") then
1522 Thurallor-7095
        local prevContext = L:SetContext("CaptionVisibleMenu");
1523 Thurallor-7095
                for _, option in pairs(L:GetItems()) do
1524 Thurallor-7095
                        local subItem = Turbine.UI.MenuItem(L:GetText(option), true, (self.settings.caption.visible == option));
1525 Thurallor-7095
                        subItem.Click = function()
1526 Thurallor-7095
                                self:SetCaptionVisible(option);
1527 Thurallor-7095
                        end
1528 Thurallor-7095
                        item:GetItems():Add(subItem);
1529 Thurallor-7095
                end
1530 Thurallor-7095
        L:SetContext(prevContext);
1531 26 Thurallor-7095
    elseif (itemName == "CaptionPosition") then
1532 Thurallor-7095
        local prevContext = L:SetContext("CaptionPositionMenu");
1533 2 Thurallor-7095
        if ((self.settings.orientation == "Up") or (self.settings.orientation == "Down")) then
1534 Thurallor-7095
            self:AddSettingsMenuItem(item, "Top");
1535 Thurallor-7095
            self:AddSettingsMenuItem(item, "Bottom");
1536 Thurallor-7095
        else -- "Left" or "Right"
1537 Thurallor-7095
            self:AddSettingsMenuItem(item, "LeftSide");
1538 Thurallor-7095
            self:AddSettingsMenuItem(item, "RightSide");
1539 Thurallor-7095
        end
1540 Thurallor-7095
        L:SetContext(prevContext);
1541 11 Thurallor-7095
    elseif (string.find("|Top|Bottom|LeftSide|RightSide|", "|" .. itemName .. "|")) then
1542 2 Thurallor-7095
        local beginPosMap = { Left = "RightSide"; Right = "LeftSide"; Up = "Bottom"; Down = "Top" };
1543 Thurallor-7095
        local amBeginPos = (itemName == beginPosMap[self.settings.orientation]);
1544 Thurallor-7095
        local beginPosSelected = (self.settings.caption.position == "beginning");
1545 Thurallor-7095
        local checked = (amBeginPos and beginPosSelected) or (not amBeginPos and not beginPosSelected);
1546 Thurallor-7095
        local myOrientation = (amBeginPos and "beginning") or "end";
1547 Thurallor-7095
        item:SetChecked(checked);
1548 Thurallor-7095
        item:SetEnabled(not checked);
1549 121 Thurallor-7095
        item.Click = function()
1550 2 Thurallor-7095
            self.settings.caption.position = myOrientation;
1551 Thurallor-7095
            self:SaveSettings(false);
1552 34 Thurallor-7095
            self:Redraw(true);
1553 6 Thurallor-7095
            self:MoveOntoScreen();
1554 2 Thurallor-7095
        end
1555 Thurallor-7095
    elseif (itemName == "Clone") then
1556 121 Thurallor-7095
        item.Click = function()
1557 2 Thurallor-7095
            self.parent:CloneBar(self.objectID);
1558 Thurallor-7095
        end
1559 Thurallor-7095
    elseif (itemName == "Group") then
1560 200 Thurallor-7095
        self.parent:AddSettingsMenuItem(item, "Root", self);
1561 Thurallor-7095
    elseif (itemName == "Global") then
1562 Thurallor-7095
        self.manager:AddSettingsMenuItem(item, "Root", self);
1563 2 Thurallor-7095
    elseif (itemName == "Delete") then
1564 121 Thurallor-7095
        item.Click = function()
1565 2 Thurallor-7095
            self.parent:DeleteBar(self.objectID);
1566 Thurallor-7095
        end
1567 Thurallor-7095
    end
1568 26 Thurallor-7095
    return item;
1569 2 Thurallor-7095
end
1570 Thurallor-7095
 
1571 128 Thurallor-7095
function Bar:SetTransparency(opacity)
1572 Thurallor-7095
    self.settings.opacity = opacity;
1573 Thurallor-7095
    self:SaveSettings();
1574 158 Thurallor-7095
    self:Redraw(true);
1575 128 Thurallor-7095
end
1576 Thurallor-7095
 
1577 158 Thurallor-7095
function Bar:GetTransparency()
1578 Thurallor-7095
    return self.settings.opacity or self.globals.uiOpacity;
1579 Thurallor-7095
end
1580 Thurallor-7095
 
1581 Thurallor-7095
function Bar:SetScale(scale)
1582 Thurallor-7095
    self.settings.scale = scale;
1583 Thurallor-7095
    self:SaveSettings();
1584 Thurallor-7095
    self:Redraw(true);
1585 Thurallor-7095
end
1586 Thurallor-7095
 
1587 Thurallor-7095
function Bar:GetScale()
1588 Thurallor-7095
    return self.settings.scale or self.globals.uiScale;
1589 Thurallor-7095
end
1590 Thurallor-7095
 
1591 2 Thurallor-7095
function Bar:ResizeBar(size)
1592 27 Thurallor-7095
    self:Expand();
1593 2 Thurallor-7095
    self.settings.visibleSlots = size;
1594 Thurallor-7095
    if (self.settings.cursorHomePosition > size) then
1595 Thurallor-7095
        self.settings.cursorHomePosition = size;
1596 Thurallor-7095
    end
1597 Thurallor-7095
    self:SaveSettings(false);
1598 Thurallor-7095
    self:Redraw();
1599 Thurallor-7095
end
1600 Thurallor-7095
 
1601 Thurallor-7095
function Bar:SetCursorStyle(style)
1602 Thurallor-7095
    if (style == nil) then
1603 Thurallor-7095
        style = self.settings.cursorStyle;
1604 Thurallor-7095
    end
1605 Thurallor-7095
    self.settings.cursorStyle = style;
1606 Thurallor-7095
    local resource = resources.Cursor[style];
1607 Thurallor-7095
 
1608 Thurallor-7095
    if (self.cursor) then
1609 13 Thurallor-7095
        self.cursor:SetParent(nil);
1610 2 Thurallor-7095
        self.cursor = nil;
1611 Thurallor-7095
    end
1612 13 Thurallor-7095
    self.cursor = Turbine.UI.Control();
1613 Thurallor-7095
    self.cursor:SetParent(self.slotContainer);
1614 2 Thurallor-7095
    self.cursor:SetMouseVisible(false);
1615 Thurallor-7095
    if (resource.ApplyColor) then
1616 Thurallor-7095
        self.cursor:SetBackColor(self.color);
1617 Thurallor-7095
    end
1618 Thurallor-7095
    local background = resources.Cursor[style].Background;
1619 Thurallor-7095
    if (background) then
1620 Thurallor-7095
        self.cursor:SetBackground(resource.Background);
1621 Thurallor-7095
        self.cursorWidth, self.cursorHeight = GetAssetSize(resource.Background);
1622 Thurallor-7095
        self.cursor:SetSize(self.cursorWidth, self.cursorHeight);
1623 Thurallor-7095
        -- for now, presume square shape
1624 Thurallor-7095
        self.cursorSize = math.ceil(self.cursorWidth / 2) * 2;
1625 Thurallor-7095
    else
1626 Thurallor-7095
        self.cursorSize = 36;
1627 Thurallor-7095
    end
1628 Thurallor-7095
    if (resource.BackColorBlendMode) then
1629 Thurallor-7095
        self.cursor:SetBackColorBlendMode(resource.BackColorBlendMode);
1630 Thurallor-7095
    end
1631 Thurallor-7095
    if (resource.BlendMode) then
1632 Thurallor-7095
        self.cursor:SetBlendMode(resource.BlendMode);
1633 Thurallor-7095
    end
1634 Thurallor-7095
    if (resource.ZOrder) then
1635 13 Thurallor-7095
        self.cursor:SetZOrder(2 + resource.ZOrder);
1636 2 Thurallor-7095
    end
1637 13 Thurallor-7095
--    self.cursor:SetVisible(not self:IsHidden());
1638 2 Thurallor-7095
    if (not resource.xOffset) then
1639 Thurallor-7095
        resource.xOffset = 0;
1640 Thurallor-7095
    end
1641 Thurallor-7095
    if (not resource.yOffset) then
1642 Thurallor-7095
        resource.yOffset = 0;
1643 Thurallor-7095
    end
1644 13 Thurallor-7095
 
1645 Thurallor-7095
    self.cursorMargin = math.ceil((self.cursorSize - self.settings.slotSize) / 2);
1646 16 Thurallor-7095
    self:SetCursorPos(self.cursorPos);
1647 2 Thurallor-7095
end
1648 Thurallor-7095
 
1649 Thurallor-7095
function Bar:SetLocked(state)
1650 Thurallor-7095
    self.settings.locked = state;
1651 Thurallor-7095
    self:SaveSettings(false);
1652 Thurallor-7095
end
1653 Thurallor-7095
 
1654 Thurallor-7095
function Bar:IsLocked()
1655 Thurallor-7095
    return self.settings.locked;
1656 Thurallor-7095
end
1657 Thurallor-7095
 
1658 16 Thurallor-7095
-- Scrolls the sequence such that the specified slot appears under the cursor
1659 Thurallor-7095
function Bar:SetCursorSlot(slot)
1660 20 Thurallor-7095
 
1661 21 Thurallor-7095
    local prevVisibleSlots = self.visibleSlots;
1662 16 Thurallor-7095
    self.visibleSlots = {};
1663 2 Thurallor-7095
 
1664 16 Thurallor-7095
    -- If advanced past the end of the sequence, start over at the beginning.
1665 Thurallor-7095
    if (slot > #self.slots) then
1666 Thurallor-7095
        slot = 1;
1667 2 Thurallor-7095
    end
1668 37 Thurallor-7095
 
1669 16 Thurallor-7095
    -- Find non-hidden slots to the left of the cursor
1670 36 Thurallor-7095
    local gameTime = Turbine.Engine.GetGameTime();
1671 16 Thurallor-7095
    local pos = self.cursorPos - 1;
1672 Thurallor-7095
    local s = slot - 1;
1673 Thurallor-7095
    while ((pos > 0) and (s > 0)) do
1674 Thurallor-7095
        local object = self.slots[s];
1675 36 Thurallor-7095
        if (not (object.hidden or (self.settings.hideInactiveBranches and self.sequence:SlotIsFolded(s, gameTime)))) then
1676 21 Thurallor-7095
            self.visibleSlots[object] = pos;
1677 16 Thurallor-7095
            pos = pos - 1;
1678 2 Thurallor-7095
        end
1679 16 Thurallor-7095
        s = s - 1;
1680 2 Thurallor-7095
    end
1681 16 Thurallor-7095
 
1682 Thurallor-7095
    self.cursorSlot = slot;
1683 Thurallor-7095
 
1684 Thurallor-7095
    -- Find non-hidden slots to the right of the cursor.
1685 Thurallor-7095
    -- Re-evaluate all conditionals except those to the left of the cursor.
1686 Thurallor-7095
    pos = self.cursorPos;
1687 Thurallor-7095
    s = slot;
1688 26 Thurallor-7095
    while ((pos <= self.displaySlots) and (s <= #self.slots)) do
1689 16 Thurallor-7095
        local object = self.slots[s];
1690 Thurallor-7095
        if (object.info.type == "If") then
1691 146 Thurallor-7095
            local success, condResult = pcall(object.condFunc, object, self.manager.player);
1692 Thurallor-7095
            object.condResult = (success and condResult) or false; -- nil => false
1693 16 Thurallor-7095
        end
1694 36 Thurallor-7095
        if (not (object.hidden or (self.settings.hideInactiveBranches and self.sequence:SlotIsFolded(s, gameTime)))) then
1695 21 Thurallor-7095
            self.visibleSlots[object] = pos;
1696 16 Thurallor-7095
            pos = pos + 1;
1697 Thurallor-7095
        end
1698 Thurallor-7095
        s = s + 1;
1699 Thurallor-7095
    end
1700 37 Thurallor-7095
 
1701 43 Thurallor-7095
    -- If no slots displayed, display the "reset" icon or "gears" if running continuously
1702 36 Thurallor-7095
    if (pos == self.cursorPos) then
1703 43 Thurallor-7095
        if (self.settings.continuous) then
1704 Thurallor-7095
            self.visibleSlots[self.gearsSlot] = pos;
1705 Thurallor-7095
        else
1706 Thurallor-7095
            self.visibleSlots[self.resetSlot] = pos;
1707 Thurallor-7095
        end
1708 36 Thurallor-7095
    end
1709 20 Thurallor-7095
 
1710 21 Thurallor-7095
    -- Make the old slots invisible
1711 20 Thurallor-7095
--if (self.settings.caption.text == "AoE Tank") then
1712 21 Thurallor-7095
--    Puts("prevVisibleSlots = " .. PrettyPrint(prevVisibleSlots, "", 1));
1713 20 Thurallor-7095
--end
1714 21 Thurallor-7095
    for object, pos in pairs(prevVisibleSlots) do
1715 Thurallor-7095
        if (not self.visibleSlots[object]) then
1716 Thurallor-7095
            object:SetParent(nil);
1717 Thurallor-7095
            object.pos = nil;
1718 Thurallor-7095
        end
1719 Thurallor-7095
    end
1720 17 Thurallor-7095
 
1721 21 Thurallor-7095
    -- Make the new slots visible
1722 Thurallor-7095
--if (self.settings.caption.text == "AoE Tank") then
1723 Thurallor-7095
--    Puts("self.visibleSlots = " .. PrettyPrint(prevVisibleSlots, "", 1));
1724 Thurallor-7095
--end
1725 Thurallor-7095
    if (not self.settings.hidden) then
1726 Thurallor-7095
        for object, pos in pairs(self.visibleSlots) do
1727 Thurallor-7095
            if (not prevVisibleSlots[object]) then
1728 Thurallor-7095
                object:SetParent(self.slotContainer);
1729 Thurallor-7095
            end
1730 Thurallor-7095
            local left, top = self:GetSlotCoords(pos);
1731 16 Thurallor-7095
            object:SetPosition(left - 1, top  - 1);
1732 21 Thurallor-7095
            object.pos = pos;
1733 16 Thurallor-7095
        end
1734 Thurallor-7095
    end
1735 2 Thurallor-7095
end
1736 Thurallor-7095
 
1737 43 Thurallor-7095
function Bar:StartExecuting()
1738 Thurallor-7095
    self.gearsSlot:SetRunning(true);
1739 Thurallor-7095
end
1740 Thurallor-7095
 
1741 Thurallor-7095
function Bar:StopExecuting()
1742 121 Thurallor-7095
    if (self.Log) then
1743 Thurallor-7095
        DoCallbacks(self, "Log", {"halting continuous execution", "BAR"});
1744 Thurallor-7095
    end
1745 43 Thurallor-7095
    self.gearsSlot:SetRunning(false);
1746 Thurallor-7095
end
1747 Thurallor-7095
 
1748 20 Thurallor-7095
function Bar:SlotClick(s, automatic)
1749 43 Thurallor-7095
 
1750 16 Thurallor-7095
    local slot = self.slots[s];
1751 34 Thurallor-7095
    if (automatic) then
1752 37 Thurallor-7095
        if (self.firstAutomaticClick) then
1753 Thurallor-7095
            if (self.wrapped and (s >= self.firstAutomaticClick)) then
1754 Thurallor-7095
                self.firstAutomaticClick = nil;
1755 43 Thurallor-7095
 
1756 Thurallor-7095
                -- If running continuously, tell the Gears object to perform a click at the next update ("Tick")
1757 Thurallor-7095
                if (self.settings.continuous) then
1758 Thurallor-7095
                    self.gearsSlot.Tick = function()
1759 Thurallor-7095
                        self.gearsSlot.Tick = nil; -- only once
1760 Thurallor-7095
                        local slot = self.slots[self.cursorSlot];
1761 Thurallor-7095
                        if (slot.info.automatic) then
1762 Thurallor-7095
                            self:SlotClick(s, true);
1763 Thurallor-7095
                        end
1764 Thurallor-7095
                    end
1765 Thurallor-7095
                end
1766 37 Thurallor-7095
                return;
1767 Thurallor-7095
            end
1768 Thurallor-7095
        else
1769 34 Thurallor-7095
            self.firstAutomaticClick = s;
1770 37 Thurallor-7095
            self.wrapped = false;
1771 34 Thurallor-7095
        end
1772 Thurallor-7095
    else
1773 Thurallor-7095
        self.firstAutomaticClick = nil;
1774 20 Thurallor-7095
        self.clickedPos = slot.pos;
1775 26 Thurallor-7095
        self.clickedSlot = s;
1776 180 Thurallor-7095
        self.reevaluatingConditionals = {};
1777 20 Thurallor-7095
    end
1778 Thurallor-7095
 
1779 17 Thurallor-7095
    -- Do the action associated with the slot, if any
1780 Thurallor-7095
    if (slot.actionFunc) then
1781 121 Thurallor-7095
        if (self.Log) then
1782 Thurallor-7095
            DoCallbacks(self, "Log", {"(slot " .. tostring(s) .. ") executing: " .. slot.info.type, "SPECIAL-SLOT"});
1783 Thurallor-7095
            if (slot.info.type == "GenerateEvent") then
1784 Thurallor-7095
                DoCallbacks(self, "Log", {"generated: " .. slot.info.eventName, "EVENT"});
1785 Thurallor-7095
            end
1786 Thurallor-7095
        end
1787 146 Thurallor-7095
        pcall(slot.actionFunc, slot, s);
1788 17 Thurallor-7095
    end
1789 Thurallor-7095
 
1790 199 Thurallor-7095
    -- Process reset slots
1791 Thurallor-7095
    if (slot.info.type == "Reset") then
1792 Thurallor-7095
        return self:Reset();
1793 Thurallor-7095
    end
1794 Thurallor-7095
 
1795 146 Thurallor-7095
    -- Process conditionals (if/then/else) and Lua scripts.
1796 17 Thurallor-7095
    if (slot.info.type == "If") then
1797 146 Thurallor-7095
        local success, condResult = pcall(slot.condFunc, slot, self.manager.player);
1798 Thurallor-7095
        slot.condResult = (success and condResult) or false; -- nil => false
1799 121 Thurallor-7095
        if (self.Log) then
1800 Thurallor-7095
            DoCallbacks(self, "Log", {"(slot " .. tostring(s) .. ") evaluating conditional: " .. tostring(slot.condResult), "SPECIAL-SLOT"});
1801 Thurallor-7095
        end
1802 182 Thurallor-7095
        if (automatic and slot.info.reevaluate) then
1803 180 Thurallor-7095
            self:ReevaluateContinuously(s);
1804 Thurallor-7095
        end
1805 17 Thurallor-7095
        if (not slot.condResult) then
1806 Thurallor-7095
            if (slot.elseSlot) then
1807 Thurallor-7095
                s = slot.elseSlot - 1;
1808 Thurallor-7095
            elseif (slot.endIfSlot) then
1809 16 Thurallor-7095
                s = slot.endIfSlot - 1;
1810 Thurallor-7095
            end
1811 2 Thurallor-7095
        end
1812 17 Thurallor-7095
    elseif (slot.info.type == "Else") then
1813 Thurallor-7095
        doElse = true;
1814 Thurallor-7095
        if (slot.ifSlot) then
1815 Thurallor-7095
            doElse = not self.slots[slot.ifSlot].condResult;
1816 6 Thurallor-7095
        end
1817 17 Thurallor-7095
        if (slot.endIfSlot and not doElse) then
1818 Thurallor-7095
            s = slot.endIfSlot - 1;
1819 Thurallor-7095
        end
1820 Thurallor-7095
    end
1821 20 Thurallor-7095
 
1822 34 Thurallor-7095
    local nextSlot = s + 1;
1823 Thurallor-7095
 
1824 20 Thurallor-7095
    -- If a previous advancement callback was never called, unregister it.
1825 Thurallor-7095
    self:UnregisterAdvanceCallback();
1826 16 Thurallor-7095
 
1827 20 Thurallor-7095
    if (slot.info.advanceEvent) then
1828 Thurallor-7095
        if (slot.info.advanceEvent == "ItemEquipped") then
1829 143 Thurallor-7095
            if (not IsEquipped(slot:GetItemName())) then
1830 Thurallor-7095
                slot.advanceFunc["ItemEquipped"] = function()
1831 146 Thurallor-7095
                    self:UnregisterAdvanceCallback();
1832 143 Thurallor-7095
--                    if (IsEquipped(slot:GetItemName()) then
1833 146 Thurallor-7095
                        self:AdvanceToSlot(nextSlot, "item equipped");
1834 143 Thurallor-7095
--                    end
1835 Thurallor-7095
                end
1836 Thurallor-7095
                AddCallback(Thurallor.Utils.Watcher, "ItemEquipped", slot.advanceFunc["ItemEquipped"]);
1837 147 Thurallor-7095
                table.insert(self.advancement, { object = Thurallor.Utils.Watcher, event = "ItemEquipped", func = slot.advanceFunc["ItemEquipped"] });
1838 34 Thurallor-7095
            end
1839 Thurallor-7095
        elseif (slot.info.advanceEvent == "DelayComplete") then
1840 143 Thurallor-7095
            slot.advanceFunc["Reset"] = function()
1841 146 Thurallor-7095
                self:UnregisterAdvanceCallback();
1842 Thurallor-7095
                self:AdvanceToSlot(nextSlot, "delay complete");
1843 43 Thurallor-7095
                if (self.settings.continuous) then
1844 Thurallor-7095
                    self.gearsSlot:SetDelaying(false);
1845 Thurallor-7095
                end
1846 20 Thurallor-7095
            end
1847 143 Thurallor-7095
            AddCallback(slot, "Reset", slot.advanceFunc["Reset"]);
1848 147 Thurallor-7095
            table.insert(self.advancement, { object = slot, event = "Reset", func = slot.advanceFunc["Reset"] });
1849 143 Thurallor-7095
        elseif (slot.info.advanceEvent == "SkillExecuted") then
1850 151 Thurallor-7095
            local skillNames = slot:GetSkillNames();
1851 Thurallor-7095
            if (skillNames) then
1852 Thurallor-7095
                local skill = slot:GetSkill();
1853 Thurallor-7095
                if (skill) then
1854 Thurallor-7095
 
1855 Thurallor-7095
                                        -- For most skills, we can use the ResetTimeChanged event to detect execution.
1856 154 Thurallor-7095
                    if (not slot.info.executeDetectByChat) then
1857 151 Thurallor-7095
                        slot.advanceFunc["ResetTimeChanged"] = function()
1858 146 Thurallor-7095
                            self:UnregisterAdvanceCallback();
1859 151 Thurallor-7095
                            self:AdvanceToSlot(nextSlot, "skill executed (cooldown reset detected)");
1860 143 Thurallor-7095
                        end
1861 151 Thurallor-7095
                        AddCallback(skill, "ResetTimeChanged", slot.advanceFunc["ResetTimeChanged"]);
1862 Thurallor-7095
                        table.insert(self.advancement, { object = skill, event = "ResetTimeChanged", func = slot.advanceFunc["ResetTimeChanged"] });
1863 Thurallor-7095
 
1864 Thurallor-7095
                    -- For other skills, we can wait for chat message indicating skill has fired.
1865 154 Thurallor-7095
                    else
1866 151 Thurallor-7095
                        for _, altName in pairs(skillNames) do
1867 Thurallor-7095
                            slot.advanceFunc[altName] = function(_, args)
1868 Thurallor-7095
                                if ((args.ChatType == Turbine.ChatType.PlayerCombat) and (string.find(args.Message, altName, 1, true))) then
1869 Thurallor-7095
                                    self:UnregisterAdvanceCallback();
1870 Thurallor-7095
                                    self:AdvanceToSlot(nextSlot, "skill executed (observed in combat log)");
1871 Thurallor-7095
                                end
1872 Thurallor-7095
                            end
1873 Thurallor-7095
                            AddCallback(Turbine.Chat, "Received", slot.advanceFunc[altName]);
1874 Thurallor-7095
                            table.insert(self.advancement, { object = Turbine.Chat, event = "Received", func = slot.advanceFunc[altName] });
1875 Thurallor-7095
                        end
1876 Thurallor-7095
 
1877 143 Thurallor-7095
                    end
1878 151 Thurallor-7095
                    -- Toggle skills only have a chat message when activated; when deactivated, they get a ResetTimeChanged
1879 Thurallor-7095
                    -- event.  Shouldn't be a problem, since by that time we won't be watching any more.
1880 Thurallor-7095
                else
1881 Thurallor-7095
                    -- The skill is unlearned, so it won't ever execute.
1882 Thurallor-7095
                    table.insert(self.advancement, { object = Turbine.Chat, event = "Never" });
1883 143 Thurallor-7095
                end
1884 151 Thurallor-7095
            else
1885 Thurallor-7095
                Puts("Unknown skill in slot " .. s .. "; don't know how to detect its execution");
1886 143 Thurallor-7095
            end
1887 20 Thurallor-7095
        end
1888 Thurallor-7095
    end
1889 113 Thurallor-7095
 
1890 114 Thurallor-7095
        -- If skill requires a target, don't advance.
1891 136 Thurallor-7095
        if (slot.info.requireTarget) then
1892 Thurallor-7095
        if ((slot.info.type == "SelectTarget") and (slot.entity == nil)) then
1893 146 Thurallor-7095
            if (self.Log) then
1894 Thurallor-7095
                DoCallbacks(self, "Log", {"failed: selection failed", "ADVANCE"});
1895 Thurallor-7095
            end
1896 136 Thurallor-7095
            return;
1897 Thurallor-7095
        elseif (Thurallor.Utils.Watcher.targetObject == nil) then
1898 146 Thurallor-7095
            if (self.Log) then
1899 Thurallor-7095
                DoCallbacks(self, "Log", {"failed: target required", "ADVANCE"});
1900 Thurallor-7095
            end
1901 143 Thurallor-7095
            self:UnregisterAdvanceCallback();
1902 136 Thurallor-7095
            return;
1903 Thurallor-7095
        end
1904 113 Thurallor-7095
        end
1905 34 Thurallor-7095
 
1906 20 Thurallor-7095
    -- Advance immediately.
1907 147 Thurallor-7095
    if (not next(self.advancement)) then
1908 143 Thurallor-7095
        self:AdvanceToSlot(nextSlot);
1909 Thurallor-7095
    end
1910 20 Thurallor-7095
end
1911 Thurallor-7095
 
1912 180 Thurallor-7095
function Bar:ReevaluateContinuously(s)
1913 Thurallor-7095
    local slot = self.slots[s];
1914 Thurallor-7095
    -- Reevaluate this conditional at the next frame update:
1915 Thurallor-7095
    table.insert(self.reevaluatingConditionals, { slot.condFunc, slot.condResult, s });
1916 Thurallor-7095
    self:SetWantsUpdates(true);
1917 Thurallor-7095
end
1918 Thurallor-7095
 
1919 34 Thurallor-7095
function Bar:StartSlotCooldown(s, delay)
1920 Thurallor-7095
    local slot = self.slots[s];
1921 Thurallor-7095
    slot.hiddenAfterReset = slot.hidden;
1922 43 Thurallor-7095
    if (self.settings.continuous) then
1923 Thurallor-7095
        self.gearsSlot:SetDelaying(true);
1924 Thurallor-7095
    else
1925 Thurallor-7095
        slot.hidden = false;
1926 Thurallor-7095
        self:SetCursorPos(self.clickedPos);
1927 Thurallor-7095
        self:SetCursorSlot(s);
1928 Thurallor-7095
    end
1929 34 Thurallor-7095
    slot:StartCooldown(delay);
1930 Thurallor-7095
end
1931 Thurallor-7095
 
1932 20 Thurallor-7095
function Bar:UnregisterAdvanceCallback()
1933 147 Thurallor-7095
    if (next(self.advancement)) then
1934 143 Thurallor-7095
        for _, info in pairs(self.advancement) do
1935 Thurallor-7095
            RemoveCallback(info.object, info.event, info.func);
1936 Thurallor-7095
        end
1937 147 Thurallor-7095
        self.advancement = {};
1938 20 Thurallor-7095
    end
1939 Thurallor-7095
end
1940 Thurallor-7095
 
1941 146 Thurallor-7095
function Bar:AdvanceToSlot(s, cause)
1942 20 Thurallor-7095
 
1943 17 Thurallor-7095
    if (s > #self.slots) then
1944 37 Thurallor-7095
        self.wrapped = true;
1945 180 Thurallor-7095
        self.reevaluatingConditionals = {};
1946 17 Thurallor-7095
        s = 1;
1947 Thurallor-7095
    end
1948 34 Thurallor-7095
    local slot = self.slots[s];
1949 Thurallor-7095
 
1950 121 Thurallor-7095
    if (self.Log) then
1951 146 Thurallor-7095
        if (cause) then
1952 Thurallor-7095
            DoCallbacks(self, "Log", {"to slot " .. tostring(s) .. ", caused by: " .. cause, "ADVANCE"});
1953 Thurallor-7095
        else
1954 Thurallor-7095
            DoCallbacks(self, "Log", {"to slot " .. tostring(s), "ADVANCE"});
1955 Thurallor-7095
        end
1956 121 Thurallor-7095
    end
1957 Thurallor-7095
 
1958 38 Thurallor-7095
    -- If the user didn't click on the currently selected slot, move the cursor.
1959 34 Thurallor-7095
    if (self.clickedPos ~= self.cursorPos) then
1960 Thurallor-7095
        self:SetCursorPos(self.clickedPos);
1961 Thurallor-7095
    end
1962 Thurallor-7095
 
1963 38 Thurallor-7095
    -- If the next slot is automatic, auto-click it.
1964 34 Thurallor-7095
    if (slot.info.automatic) then
1965 Thurallor-7095
        self:SetCursorSlot(s);
1966 25 Thurallor-7095
        return self:SlotClick(s, true);
1967 17 Thurallor-7095
    end
1968 16 Thurallor-7095
 
1969 38 Thurallor-7095
    -- If animation is disabled via settings, or stopped via a "Stop" slot, refold the slots and do nothing further.
1970 16 Thurallor-7095
    if ((self.settings.animation.duration == -1) or self.animationStopped) then
1971 26 Thurallor-7095
        self:SetCursorSlot(self.clickedSlot);
1972 16 Thurallor-7095
        return;
1973 2 Thurallor-7095
    end
1974 16 Thurallor-7095
 
1975 Thurallor-7095
    -- Do animation.
1976 34 Thurallor-7095
    self:SetCursorSlot(s);
1977 16 Thurallor-7095
    if (self.settings.animation.duration > 0) then
1978 Thurallor-7095
        self:Animate(0);
1979 Thurallor-7095
    end
1980 2 Thurallor-7095
end
1981 Thurallor-7095
 
1982 Thurallor-7095
function Bar:Update()
1983 180 Thurallor-7095
    local wantsMoreUpdates = false;
1984 17 Thurallor-7095
    if (self.animationStartTime) then
1985 Thurallor-7095
        local timeDelta = Turbine.Engine.GetGameTime() - self.animationStartTime;
1986 Thurallor-7095
        if (timeDelta > 0) then
1987 Thurallor-7095
            self:Animate(timeDelta);
1988 Thurallor-7095
        end
1989 180 Thurallor-7095
        if (self.animationStartTime) then
1990 Thurallor-7095
            wantsMoreUpdates = true;
1991 Thurallor-7095
        end
1992 2 Thurallor-7095
    end
1993 24 Thurallor-7095
--    if (self.delayedClick) then
1994 Thurallor-7095
--        self:SlotClick(self.delayedClick, true);
1995 180 Thurallor-7095
--        if (self.delayedClick) then
1996 Thurallor-7095
--            wantsMoreUpdates = true;
1997 Thurallor-7095
--        end
1998 24 Thurallor-7095
--    end
1999 20 Thurallor-7095
    if (self.mouseInside) then
2000 Thurallor-7095
        local mouseLeft, mouseTop = Turbine.UI.Display:GetMousePosition();
2001 42 Thurallor-7095
        if (not self:MouseInside(mouseLeft, mouseTop)) then
2002 20 Thurallor-7095
            self:MouseDepart();
2003 Thurallor-7095
        end
2004 180 Thurallor-7095
        if (self.mouseInside) then
2005 Thurallor-7095
            wantsMoreUpdates = true;
2006 Thurallor-7095
        end
2007 20 Thurallor-7095
    end
2008 180 Thurallor-7095
    local firstConditional = self.reevaluatingConditionals[1];
2009 Thurallor-7095
    if (firstConditional) then
2010 Thurallor-7095
        for _, condInfo in ipairs(self.reevaluatingConditionals) do
2011 Thurallor-7095
            local condFunc, prevResult, s = unpack(condInfo);
2012 Thurallor-7095
            local slot = self.slots[s];
2013 Thurallor-7095
            local success, condResult = pcall(condFunc, slot, self.manager.player);
2014 Thurallor-7095
            condResult = (success and condResult) or false; -- nil => false
2015 Thurallor-7095
            if (condResult ~= prevResult) then
2016 Thurallor-7095
                self.reevaluatingConditionals = {};
2017 Thurallor-7095
                self:AdvanceToSlot(firstConditional[3], "condition at slot " .. tostring(s) .. " changed from " .. tostring(prevResult) .. " to " .. tostring(condResult));
2018 183 Thurallor-7095
                break;
2019 180 Thurallor-7095
            end
2020 Thurallor-7095
        end
2021 Thurallor-7095
        wantsMoreUpdates = true;
2022 Thurallor-7095
    end
2023 Thurallor-7095
    if (not wantsMoreUpdates) then
2024 17 Thurallor-7095
        self:SetWantsUpdates(false);
2025 Thurallor-7095
    end
2026 2 Thurallor-7095
end
2027 Thurallor-7095
 
2028 Thurallor-7095
function Bar:SetAnimationSpeed(duration)
2029 Thurallor-7095
    self.settings.animation.duration = duration;
2030 Thurallor-7095
    self:SaveSettings(false);
2031 Thurallor-7095
end
2032 Thurallor-7095
 
2033 Thurallor-7095
-- Achieves the scrolling effect.  Gets called by Bar:Update().
2034 Thurallor-7095
function Bar:Animate(timeDelta)
2035 Thurallor-7095
    local progress = timeDelta / self.settings.animation.duration;
2036 Thurallor-7095
    if (progress == 0) then
2037 Thurallor-7095
        self.animationStartTime = Turbine.Engine.GetGameTime();
2038 Thurallor-7095
        self.animationDistance = self.settings.slotSize + self.settings.slotSpacing;
2039 Thurallor-7095
        self:SetWantsUpdates(true);
2040 20 Thurallor-7095
    elseif (progress >= 1) then
2041 2 Thurallor-7095
        progress = 1;
2042 20 Thurallor-7095
        self.animationStartTime = nil;
2043 2 Thurallor-7095
    end
2044 Thurallor-7095
    local displacement = math.floor(self.animationDistance * (1 - progress));
2045 Thurallor-7095
    if (self.settings.orientation == "Up") then
2046 13 Thurallor-7095
        self.slotContainer:SetTop(self.slotsTop - displacement);
2047 2 Thurallor-7095
    elseif (self.settings.orientation == "Down") then
2048 13 Thurallor-7095
        self.slotContainer:SetTop(self.slotsTop + displacement);
2049 2 Thurallor-7095
    elseif (self.settings.orientation == "Left") then
2050 13 Thurallor-7095
        self.slotContainer:SetLeft(self.slotsLeft - displacement);
2051 2 Thurallor-7095
    elseif (self.settings.orientation == "Right") then
2052 13 Thurallor-7095
        self.slotContainer:SetLeft(self.slotsLeft + displacement);
2053 2 Thurallor-7095
    end
2054 6 Thurallor-7095
 
2055 Thurallor-7095
    -- Make sure the item under the cursor is always clickable.  This hack is
2056 Thurallor-7095
    -- necessary because as the slot moves, no MouseEnter event occurs and
2057 Thurallor-7095
    -- hence no MouseClick events can be received.
2058 16 Thurallor-7095
    self.slots[self.cursorSlot]:SetVisible(false);
2059 Thurallor-7095
    self.slots[self.cursorSlot]:SetVisible(true);
2060 2 Thurallor-7095
end
2061 Thurallor-7095
 
2062 Thurallor-7095
function Bar:Destroy()
2063 13 Thurallor-7095
    if (self.sequenceEditor) then
2064 Thurallor-7095
        self.sequenceEditor:Close();
2065 Thurallor-7095
    end
2066 8 Thurallor-7095
    -- Unregister as event generator
2067 177 Thurallor-7095
    self.manager:SetEventGenerators(false, self);
2068 8 Thurallor-7095
    Node.Destroy(self);
2069 16 Thurallor-7095
    self.manager:SetIncludees(self.objectID, nil);
2070 2 Thurallor-7095
end
2071 Thurallor-7095
 
2072 Thurallor-7095
function Bar:GetVisibleLeft()
2073 13 Thurallor-7095
    local left = self:GetSlotsScreenCoords();
2074 2 Thurallor-7095
    return left;
2075 Thurallor-7095
end
2076 Thurallor-7095
 
2077 Thurallor-7095
function Bar:SetVisibleLeft(left)
2078 Thurallor-7095
    self:OffsetPosition(left - self:GetVisibleLeft(), 0);
2079 Thurallor-7095
end
2080 Thurallor-7095
 
2081 Thurallor-7095
function Bar:GetVisibleTop()
2082 13 Thurallor-7095
    local _, top = self:GetSlotsScreenCoords();
2083 2 Thurallor-7095
    return top;
2084 Thurallor-7095
end
2085 Thurallor-7095
 
2086 Thurallor-7095
function Bar:SetVisibleTop(top)
2087 Thurallor-7095
    self:OffsetPosition(0, top - self:GetVisibleTop());
2088 Thurallor-7095
end
2089 Thurallor-7095
 
2090 Thurallor-7095
function Bar:GetVisibleWidth()
2091 13 Thurallor-7095
    local _, _, width = self:GetSlotsScreenCoords();
2092 2 Thurallor-7095
    return width;
2093 Thurallor-7095
end
2094 Thurallor-7095
 
2095 Thurallor-7095
function Bar:GetVisibleHeight()
2096 13 Thurallor-7095
    local _, _, _, height = self:GetSlotsScreenCoords();
2097 2 Thurallor-7095
    return height;
2098 Thurallor-7095
end
2099 Thurallor-7095
 
2100 Thurallor-7095
function Bar:GetSlotCoords(slot)
2101 Thurallor-7095
    local slotSize = self.settings.slotSize + self.settings.slotSpacing;
2102 Thurallor-7095
    local offset = self.cursorMargin + (slot - 1) * slotSize;
2103 Thurallor-7095
    local left, top;
2104 Thurallor-7095
    if (self.settings.orientation == "Up") then
2105 Thurallor-7095
        left = self.cursorMargin;
2106 13 Thurallor-7095
        top = self.slotContainer:GetHeight() - slotSize - offset;
2107 2 Thurallor-7095
    elseif (self.settings.orientation == "Down") then
2108 Thurallor-7095
        left = self.cursorMargin;
2109 Thurallor-7095
        top = offset;
2110 Thurallor-7095
    elseif (self.settings.orientation == "Left") then
2111 13 Thurallor-7095
        left = self.slotContainer:GetWidth() - slotSize - offset;
2112 2 Thurallor-7095
        top = self.cursorMargin;
2113 Thurallor-7095
    else -- "Right"
2114 Thurallor-7095
        left = offset;
2115 Thurallor-7095
        top = self.cursorMargin;
2116 Thurallor-7095
    end
2117 Thurallor-7095
    return left, top
2118 Thurallor-7095
end
2119 Thurallor-7095
 
2120 199 Thurallor-7095
function Bar:Find(fromCtl)
2121 Thurallor-7095
    fromCtl.KeepOpen = true;
2122 2 Thurallor-7095
    self:MoveOntoScreen();
2123 199 Thurallor-7095
    self.zoomer = Thurallor.UI.Zoomer(fromCtl, self, 1.5);
2124 Thurallor-7095
    AddCallback(self.zoomer, "ZoomComplete", function()
2125 Thurallor-7095
        Turbine.UI.Window.Activate(self);
2126 Thurallor-7095
        self:Flash();
2127 Thurallor-7095
        self.zoomer = nil;
2128 Thurallor-7095
        fromCtl:GetParent():GetParent():Close();
2129 Thurallor-7095
    end);
2130 2 Thurallor-7095
end
2131 Thurallor-7095
 
2132 Thurallor-7095
function Bar:MoveOntoScreen()
2133 Thurallor-7095
    local screenWidth, screenHeight = Turbine.UI.Display:GetWidth(), Turbine.UI.Display:GetHeight();
2134 13 Thurallor-7095
    local left, top = self:PointToScreen(self.caption:GetLeft(), self.caption:GetTop());
2135 2 Thurallor-7095
    local right, bottom = left + self.caption:GetWidth(), top + self.caption:GetHeight();
2136 Thurallor-7095
    local deltaX, deltaY = 0, 0;
2137 Thurallor-7095
    if (left < 0) then
2138 Thurallor-7095
        deltaX = -left;
2139 Thurallor-7095
    elseif (right > screenWidth) then
2140 Thurallor-7095
        deltaX = screenWidth - right;
2141 Thurallor-7095
    end
2142 Thurallor-7095
    if (top < 0) then
2143 Thurallor-7095
        deltaY = -top;
2144 Thurallor-7095
    elseif (bottom > screenHeight) then
2145 Thurallor-7095
        deltaY = screenHeight - bottom;
2146 Thurallor-7095
    end
2147 Thurallor-7095
    self:OffsetPosition(deltaX, deltaY);
2148 Thurallor-7095
    self:SnapToGrid();
2149 Thurallor-7095
end
2150 Thurallor-7095
 
2151 Thurallor-7095
function Bar:Flash()
2152 13 Thurallor-7095
    self:Activate();
2153 2 Thurallor-7095
    self.caption.startTime = Turbine.Engine.GetGameTime();
2154 Thurallor-7095
    self.caption.label:SetVisible(true);
2155 13 Thurallor-7095
    if (not self.marquee) then
2156 Thurallor-7095
        self.marquee = Thurallor.UI.Marquee();
2157 Thurallor-7095
        self.marquee:SetParent(self);
2158 Thurallor-7095
        self.marquee:SetSize(self:GetSize());
2159 Thurallor-7095
    end
2160 2 Thurallor-7095
    self.caption.Update = function(caption, args)
2161 Thurallor-7095
        local timeDelta = Turbine.Engine.GetGameTime() - caption.startTime;
2162 Thurallor-7095
        if (timeDelta > 3) then
2163 Thurallor-7095
            caption.label:SetForeColor(self.color);
2164 112 Thurallor-7095
            caption.label:SetVisible((not self.settings.caption.clickThru) and (self.settings.caption.visible ~= "Never"));
2165 2 Thurallor-7095
            caption:SetWantsUpdates(false);
2166 13 Thurallor-7095
            self.marquee:SetParent(nil);
2167 Thurallor-7095
            self.marquee = nil;
2168 2 Thurallor-7095
        else
2169 Thurallor-7095
            local progress = (math.sin(timeDelta * 15) + 1) / 2; --math.modf(timeDelta / 0.3);
2170 Thurallor-7095
            caption.label:SetForeColor(Turbine.UI.Color(progress, 1, 1, 0));
2171 Thurallor-7095
        end
2172 Thurallor-7095
    end
2173 Thurallor-7095
    self.caption:SetWantsUpdates(true);
2174 177 Thurallor-7095
end
2175 Thurallor-7095
 
2176 Thurallor-7095
function Bar:RenameUserEvent(oldName, newName)
2177 Thurallor-7095
 
2178 Thurallor-7095
    -- Update event behaviors
2179 Thurallor-7095
    Node.RenameUserEvent(self, oldName, newName);
2180 Thurallor-7095
 
2181 Thurallor-7095
    -- Update "Generate User Event" slots
2182 178 Thurallor-7095
    local oldEvents = self.sequence:GetEvents();
2183 Thurallor-7095
    if (oldEvents[oldName]) then
2184 177 Thurallor-7095
 
2185 Thurallor-7095
        for s, info in ipairs(self.settings.sequenceItemInfo) do
2186 Thurallor-7095
            if ((info.type == "GenerateEvent") and (info.eventName == oldName)) then
2187 Thurallor-7095
                info.eventName = newName;
2188 Thurallor-7095
            end
2189 Thurallor-7095
        end
2190 Thurallor-7095
    end
2191 Thurallor-7095
 
2192 Thurallor-7095
    -- Update sequence editor, if such a slot is currently being edited
2193 Thurallor-7095
    if (self.sequenceEditor) then
2194 Thurallor-7095
        self.sequenceEditor:Redraw();
2195 Thurallor-7095
    end
2196 Thurallor-7095
 
2197 179 Thurallor-7095
    --self:Rebuild();
2198 Thurallor-7095
    --Manager needs to rebuild all bars after the change is complete, since included bars may not be changed yet.
2199 177 Thurallor-7095
end

All times are GMT -5. The time now is 01:20 PM.


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