lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [SequenceEditor.lua] - Blame information for rev 140

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

Line No. Rev Author Line
1 2 Thurallor-7095
SequenceEditor = class(Turbine.UI.Lotro.Window);
2 Thurallor-7095
 
3 7 Thurallor-7095
-- Class variable keeping track of all SequenceEditor instances:
4 Thurallor-7095
SequenceEditor.instances = {};
5 Thurallor-7095
 
6 2 Thurallor-7095
function SequenceEditor:Constructor(bar, settings)
7 Thurallor-7095
    Turbine.UI.Lotro.Window.Constructor(self);
8 7 Thurallor-7095
    SequenceEditor.instances[self] = true;
9 2 Thurallor-7095
 
10 Thurallor-7095
    self.bar = bar;
11 Thurallor-7095
    self.manager = self.bar.manager;
12 Thurallor-7095
    self.settings = settings;
13 20 Thurallor-7095
    self.globals = self.manager.settings;
14 2 Thurallor-7095
 
15 Thurallor-7095
    self:SetText(bar:GetName());
16 13 Thurallor-7095
    self:SetZOrder(2);
17 2 Thurallor-7095
    self:SetVisible(true);
18 Thurallor-7095
 
19 33 Thurallor-7095
    local minWidth = L:GetText("/SequenceEditor/MinWidth");
20 2 Thurallor-7095
    if (not self.settings.sequenceEditor) then
21 Thurallor-7095
        self.settings.sequenceEditor = {};
22 7 Thurallor-7095
        self.settings.sequenceEditor.defaultIcon = resources.BlankIcons[3];
23 2 Thurallor-7095
    end
24 Thurallor-7095
    if (self.settings.sequenceEditor.position) then
25 Thurallor-7095
        self:SetPosition(unpack(self.settings.sequenceEditor.position));
26 Thurallor-7095
    else
27 Thurallor-7095
        self:SetPosition(self.bar:GetPosition());
28 Thurallor-7095
    end
29 Thurallor-7095
    if (self.settings.sequenceEditor.size) then
30 Thurallor-7095
        self:SetSize(unpack(self.settings.sequenceEditor.size));
31 Thurallor-7095
    else
32 33 Thurallor-7095
        self:SetSize(minWidth, 187);
33 2 Thurallor-7095
    end
34 13 Thurallor-7095
 
35 16 Thurallor-7095
    self.relatedSlots = {};
36 Thurallor-7095
 
37 13 Thurallor-7095
    -- Enforce minimum size
38 33 Thurallor-7095
    self:SetMinimumWidth(minWidth);
39 Thurallor-7095
    if (self:GetWidth() < minWidth) then
40 Thurallor-7095
        self:SetWidth(minWidth);
41 Thurallor-7095
    end
42 13 Thurallor-7095
    self:SetMinimumHeight(142);
43 Thurallor-7095
    self:SetResizable(true);
44 Thurallor-7095
 
45 2 Thurallor-7095
    self:Redraw();
46 18 Thurallor-7095
    AddCallback(self, "SizeChanged", function()
47 47 Thurallor-7095
        self.skipUpdates = 2;
48 Thurallor-7095
        self:SetWantsUpdates(true); --redraw during update cycle
49 18 Thurallor-7095
    end);
50 20 Thurallor-7095
 
51 Thurallor-7095
    self:SelectSlot(nil);
52 2 Thurallor-7095
end
53 Thurallor-7095
 
54 16 Thurallor-7095
function SequenceEditor:UpdateBar()
55 Thurallor-7095
    self.bar:ShortcutChanged();
56 Thurallor-7095
    self.manager:NotifyIncluders(self.bar:GetID());
57 Thurallor-7095
end
58 Thurallor-7095
 
59 7 Thurallor-7095
function SequenceEditor:Activated()
60 Thurallor-7095
    -- Find the maximum Z order among all other Sequence Editors.
61 Thurallor-7095
    local maxZ = self:GetZOrder() - 1;
62 Thurallor-7095
    for editor in keys(SequenceEditor.instances) do
63 Thurallor-7095
        if (editor ~= self) then
64 Thurallor-7095
            local z = editor:GetZOrder();
65 Thurallor-7095
            if (z > maxZ) then
66 Thurallor-7095
                maxZ = z;
67 Thurallor-7095
            end
68 Thurallor-7095
        end
69 Thurallor-7095
    end
70 Thurallor-7095
 
71 Thurallor-7095
    if (maxZ == 2147483647) then
72 Thurallor-7095
        -- Move all other SequenceEditors back to make room at the front.
73 Thurallor-7095
        for editor in keys(SequenceEditor.instances) do
74 Thurallor-7095
            editor:SetZOrder(editor:GetZOrder() - 1);
75 Thurallor-7095
        end
76 Thurallor-7095
        maxZ = maxZ - 1;
77 Thurallor-7095
    end
78 Thurallor-7095
 
79 Thurallor-7095
    -- Move the newly-activated Sequence Editor to the front of the stack.
80 Thurallor-7095
    self:SetZOrder(maxZ + 1);
81 Thurallor-7095
end
82 Thurallor-7095
 
83 2 Thurallor-7095
function SequenceEditor:SetText(barName)
84 Thurallor-7095
    local title = L:GetText("/SequenceEditor/Title");
85 Thurallor-7095
    title = string.gsub(title, "<name>", barName);
86 Thurallor-7095
    Turbine.UI.Lotro.Window.SetText(self, title);
87 Thurallor-7095
end
88 Thurallor-7095
 
89 Thurallor-7095
function SequenceEditor:SaveSettings()
90 Thurallor-7095
    self.bar:SaveSettings();
91 Thurallor-7095
end
92 Thurallor-7095
 
93 Thurallor-7095
function SequenceEditor:Redraw()
94 46 Thurallor-7095
    if (self.noRedraw) then
95 Thurallor-7095
        return;
96 Thurallor-7095
    end
97 2 Thurallor-7095
    local width, height = self:GetSize();
98 Thurallor-7095
    local xMargin = 16;
99 Thurallor-7095
    local topMargin = 35;
100 Thurallor-7095
    local bottomMargin = 42;
101 47 Thurallor-7095
    local minSlotTabCardWidth = L:GetNumber("/SequenceEditor/SlotTabCardWidth");
102 Thurallor-7095
 
103 2 Thurallor-7095
    if (not self.slotTabCard) then
104 Thurallor-7095
        self.slotTabCard = Thurallor.UI.TabCard();
105 Thurallor-7095
        self.slotTabCard:SetParent(self);
106 35 Thurallor-7095
        self.slotTabCard:SetTabWidth(L:GetNumber("/SequenceEditor/SlotTabWidth"));
107 2 Thurallor-7095
        self.slotTabCard:SetTabText(L:GetText("/SequenceEditor/SlotTab"));
108 20 Thurallor-7095
 
109 Thurallor-7095
        -- When mouse reenters the area, redisplay the current slot in case options have changed.
110 Thurallor-7095
        self.slotTabCard.MouseEnter = function(ctl)
111 Thurallor-7095
            if (not ctl.mouseInside) then
112 Thurallor-7095
                ctl.mouseInside = true;
113 Thurallor-7095
                self:DisplaySlot(self.selectedSlot);
114 Thurallor-7095
            end
115 Thurallor-7095
        end
116 Thurallor-7095
        self.MouseEnter = function()
117 Thurallor-7095
            if (self.slotTabCard.mouseInside) then
118 Thurallor-7095
                local left, top = self.slotTabCard:GetMousePosition();
119 Thurallor-7095
                local width, height = self.slotTabCard:GetSize();
120 Thurallor-7095
                if ((left < 0) or (left >= width) or (top < 0) or (top >= height)) then
121 Thurallor-7095
                    self.slotTabCard.mouseInside = false;
122 Thurallor-7095
                end
123 Thurallor-7095
            end
124 Thurallor-7095
        end
125 47 Thurallor-7095
 
126 Thurallor-7095
        -- When slot properties card size changes, redisplay the current slot
127 Thurallor-7095
        self.slotTabCard.SizeChanged = function()
128 Thurallor-7095
            self:DisplaySlot(self.selectedSlot);
129 Thurallor-7095
        end
130 2 Thurallor-7095
    end
131 Thurallor-7095
 
132 Thurallor-7095
    if (not self.sequenceTabCard) then
133 Thurallor-7095
        self.sequenceTabCard = Thurallor.UI.TabCard();
134 Thurallor-7095
        self.sequenceTabCard:SetTabWidth(120);
135 Thurallor-7095
        self.sequenceTabCard:SetTabText(L:GetText("/SequenceEditor/SequenceTab"));
136 13 Thurallor-7095
        self.slotPanel = Turbine.UI.Control();
137 Thurallor-7095
        self.sequenceTabCard:SetInteriorControl(self.slotPanel);
138 Thurallor-7095
        self.sequenceTabCard:SetInteriorAlignment(Turbine.UI.ContentAlignment.TopLeft);
139 47 Thurallor-7095
 
140 Thurallor-7095
        -- When sequence card size changes, update the slot grid layout
141 Thurallor-7095
        self.sequenceTabCard.SizeChanged = function()
142 Thurallor-7095
            self:DeleteEmptyTrailingSlots();
143 Thurallor-7095
            local slotPanelWidth = self.sequenceTabCard:GetWidth() - 6;
144 Thurallor-7095
            self.slotSize = self.settings.slotSize + self.settings.slotSpacing;
145 Thurallor-7095
            self.slotsWide = math.floor((slotPanelWidth - 3) / self.slotSize);
146 Thurallor-7095
            self.slotsHigh = math.max(math.ceil(#self.settings.sequenceItemInfo / self.slotsWide) + 1, 2);
147 Thurallor-7095
            self:ExtendSequenceTo(self.slotsHigh * self.slotsWide);
148 Thurallor-7095
            self.slotPanel:SetSize(self.slotsWide * self.slotSize + 3, self.slotsHigh * self.slotSize + 3);
149 Thurallor-7095
            self.slotPanel:SetBackColor(self.bar.color);
150 Thurallor-7095
 
151 Thurallor-7095
            -- Draw some quickslots
152 Thurallor-7095
            if (not self.sequenceItems) then
153 Thurallor-7095
                self.sequenceItems = {};
154 Thurallor-7095
            end
155 Thurallor-7095
            local s = 1;
156 Thurallor-7095
            for y = 1, self.slotsHigh, 1 do
157 Thurallor-7095
                for x = 1, self.slotsWide, 1 do
158 Thurallor-7095
                    self:RebuildSlot(s, x, y);
159 Thurallor-7095
                    s = s + 1;
160 Thurallor-7095
                end
161 Thurallor-7095
            end
162 Thurallor-7095
        end
163 Thurallor-7095
 
164 2 Thurallor-7095
    end
165 Thurallor-7095
 
166 47 Thurallor-7095
    if (not self.splitControl) then
167 Thurallor-7095
        self.splitControl = Thurallor.UI.SplitControl(Turbine.UI.Orientation.Horizontal, self.sequenceTabCard, self.slotTabCard);
168 Thurallor-7095
        self.splitControl:SetParent(self);
169 Thurallor-7095
        self.splitControl:SetPosition(xMargin, topMargin);
170 Thurallor-7095
        self.splitControl:SetSashSize(5);
171 Thurallor-7095
        self.splitControl:SetSpacing(3);
172 Thurallor-7095
        if (self.settings.sequenceEditor.sashPosition == nil) then
173 Thurallor-7095
            self.splitControl:SetSashPosition(1);
174 Thurallor-7095
            self.settings.sequenceEditor.sashPosition = self.splitControl:GetSashPosition();
175 Thurallor-7095
        else
176 Thurallor-7095
            self.splitControl:SetSashPosition(self.settings.sequenceEditor.sashPosition);
177 2 Thurallor-7095
        end
178 48 Thurallor-7095
        AddCallback(self.splitControl, "SashPositionChanged", function()
179 47 Thurallor-7095
            self.settings.sequenceEditor.sashPosition = self.splitControl:GetSashPosition();
180 Thurallor-7095
            self:SaveSettings();
181 48 Thurallor-7095
        end);
182 2 Thurallor-7095
    end
183 47 Thurallor-7095
    local splitControlWidth = width - (2 * xMargin);
184 Thurallor-7095
    self.splitControl:SetSize(splitControlWidth, height - (topMargin + bottomMargin));
185 Thurallor-7095
    self.sequenceTabCard:SizeChanged();
186 Thurallor-7095
 
187 Thurallor-7095
    -- Enforce minimum width for slot properties card
188 Thurallor-7095
    self.splitControl:SetMaximumSashPosition((splitControlWidth - minSlotTabCardWidth - 5.5) / splitControlWidth);
189 Thurallor-7095
    -- Enforce minimum width for sequence card
190 Thurallor-7095
    self.splitControl:SetMinimumSashPosition(124 / splitControlWidth);
191 Thurallor-7095
 
192 2 Thurallor-7095
    if (not self.instructions) then
193 Thurallor-7095
        self.instructions = Turbine.UI.Label();
194 Thurallor-7095
        self.instructions:SetParent(self);
195 Thurallor-7095
        self.instructions:SetMouseVisible(false);
196 Thurallor-7095
        self.instructions:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
197 Thurallor-7095
        self.instructions:SetFont(Turbine.UI.Lotro.Font.TrajanPro15);
198 Thurallor-7095
        self.instructions:SetMultiline(true);
199 Thurallor-7095
        self.instructions:SetForeColor(Turbine.UI.Color.PaleGoldenrod);
200 Thurallor-7095
        self.instructions:SetText(L:GetText("/SequenceEditor/Instructions"));
201 Thurallor-7095
    end
202 Thurallor-7095
    self.instructions:SetSize(self:GetWidth() - 2 * xMargin, 30);
203 Thurallor-7095
    self.instructions:SetPosition(xMargin, self:GetHeight() - 40);
204 13 Thurallor-7095
 
205 Thurallor-7095
    if (self.selectedSlot) then
206 Thurallor-7095
        self:SelectSlot(self.selectedSlot);
207 2 Thurallor-7095
    end
208 Thurallor-7095
end
209 Thurallor-7095
 
210 15 Thurallor-7095
function SequenceEditor:SetMinimumHeight(height)
211 Thurallor-7095
    Turbine.UI.Window.SetMinimumHeight(self, height);
212 Thurallor-7095
    if (self:GetHeight() < height) then
213 Thurallor-7095
        self:SetHeight(height);
214 47 Thurallor-7095
        self.skipUpdates = 0;
215 Thurallor-7095
        self:SetWantsUpdates(true);
216 15 Thurallor-7095
    end
217 Thurallor-7095
end
218 Thurallor-7095
 
219 47 Thurallor-7095
function SequenceEditor:Update()
220 Thurallor-7095
    if (self.skipUpdates > 0) then
221 Thurallor-7095
        self.skipUpdates = self.skipUpdates - 1;
222 Thurallor-7095
    else
223 Thurallor-7095
        self:Redraw();
224 Thurallor-7095
        self.settings.sequenceEditor.size = {self:GetSize()};
225 Thurallor-7095
        self:SaveSettings();
226 Thurallor-7095
        self:SetWantsUpdates(false);
227 Thurallor-7095
    end
228 2 Thurallor-7095
end
229 Thurallor-7095
 
230 Thurallor-7095
function SequenceEditor:PositionChanged()
231 Thurallor-7095
    self.settings.sequenceEditor.position = {self:GetPosition()};
232 Thurallor-7095
    self:SaveSettings();
233 Thurallor-7095
end
234 Thurallor-7095
 
235 Thurallor-7095
function SequenceEditor:DisplaySlot(s)
236 20 Thurallor-7095
    if (self.ItemMovedCallback) then
237 Thurallor-7095
        RemoveCallback(Thurallor.Utils.Watcher, "ItemMoved", self.ItemMovedCallback);
238 Thurallor-7095
        self.ItemMovedCallback = nil;
239 Thurallor-7095
    end
240 Thurallor-7095
 
241 2 Thurallor-7095
    self.slotTabCard:SetInteriorControl(nil);
242 Thurallor-7095
    self.slotTabCard:SetTabText(L:GetText("/SequenceEditor/SlotTab"));
243 7 Thurallor-7095
    if ((s == nil) or (s > #self.settings.sequenceItemInfo)) then
244 Thurallor-7095
        self.slotTabCard:SetVisible(false);
245 2 Thurallor-7095
        return;
246 7 Thurallor-7095
    else
247 Thurallor-7095
        self.slotTabCard:SetVisible(true);
248 2 Thurallor-7095
    end
249 Thurallor-7095
    self:ExtendSequenceTo(s);
250 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
251 47 Thurallor-7095
    local slotTabCardWidth = self.slotTabCard:GetWidth();
252 2 Thurallor-7095
 
253 Thurallor-7095
    -- Update slot tab caption and create properties container
254 Thurallor-7095
    self.slotTabCard:SetTabText(L:GetText("/SequenceEditor/SlotTab") .. " " .. tostring(s));
255 Thurallor-7095
    self.slotProperties = Turbine.UI.Control();
256 Thurallor-7095
    self.slotTabCard:SetInteriorControl(self.slotProperties);
257 47 Thurallor-7095
    self.slotProperties:SetWidth(slotTabCardWidth - 17);
258 13 Thurallor-7095
 
259 7 Thurallor-7095
    local function UpdateIcon()
260 35 Thurallor-7095
        local center = math.floor((slotTabCardWidth - 20) / 2);
261 34 Thurallor-7095
        self.selectedIcon = self:BuildSlot(s, self.slotProperties, self.selectedIcon, center - 16, 10);
262 13 Thurallor-7095
        self.selectedIcon.numLabel:SetText(nil);     -- don't display slot number overlay
263 Thurallor-7095
        self.selectedIcon.numLabel.MouseClick = nil; -- disable right-click menu
264 Thurallor-7095
        self.selectedIcon.numLabel.MouseDown = nil;  -- disable dragging
265 15 Thurallor-7095
        self.selectedIcon:SetActionEnabled(true);
266 Thurallor-7095
        self.selectedIcon:SetAllowDrop(true);
267 7 Thurallor-7095
        self:RebuildSlot(s, nil, nil, true);
268 Thurallor-7095
    end
269 Thurallor-7095
    UpdateIcon();
270 2 Thurallor-7095
 
271 Thurallor-7095
    -- Create a function for adding a centered line of text to the properties control
272 Thurallor-7095
    local AddLabel = function(top, text, color)
273 Thurallor-7095
        local label = Turbine.UI.Label();
274 Thurallor-7095
        label:SetParent(self.slotProperties);
275 Thurallor-7095
        label:SetPosition(0, top);
276 35 Thurallor-7095
        label:SetSize(slotTabCardWidth - 20, 16);
277 2 Thurallor-7095
        top = top + 16;
278 Thurallor-7095
        label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
279 Thurallor-7095
        label:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
280 Thurallor-7095
        label:SetForeColor(color);
281 Thurallor-7095
        label:SetMarkupEnabled(true);
282 Thurallor-7095
        label:SetText(text);
283 Thurallor-7095
        return top, label;
284 Thurallor-7095
    end
285 20 Thurallor-7095
 
286 Thurallor-7095
    -- Create a function for adding a centered button to the properties control
287 47 Thurallor-7095
    local AddButton = function(top, width, text, font)
288 20 Thurallor-7095
        local button = Turbine.UI.Lotro.Button();
289 Thurallor-7095
        button:SetParent(self.slotProperties);
290 Thurallor-7095
        local left = math.floor((self.slotProperties:GetWidth() - width) / 2);
291 Thurallor-7095
        button:SetPosition(left, top + 2);
292 Thurallor-7095
        button:SetWidth(width);
293 47 Thurallor-7095
        if (font == nil) then
294 Thurallor-7095
            font = Turbine.UI.Lotro.Font.TrajanPro14;
295 Thurallor-7095
        end
296 Thurallor-7095
        button:SetFont(font);
297 20 Thurallor-7095
        button:SetText(text);
298 Thurallor-7095
        top = top + 2 + button:GetHeight();
299 Thurallor-7095
        return top, button;
300 Thurallor-7095
    end
301 Thurallor-7095
 
302 2 Thurallor-7095
    -- Create a function for adding a centered text box to the properties control
303 47 Thurallor-7095
    local AddTextBox = function(top, text, color, resizable, textBoxSize)
304 2 Thurallor-7095
        local textBox = Turbine.UI.Lotro.TextBox();
305 Thurallor-7095
        textBox:SetParent(self.slotProperties);
306 Thurallor-7095
        textBox:SetPosition(0, top);
307 35 Thurallor-7095
        textBox:SetSize(slotTabCardWidth - 20, 20);
308 47 Thurallor-7095
        if (textBoxSize) then
309 Thurallor-7095
            textBox:SetHeight(textBoxSize[2]);
310 Thurallor-7095
        end
311 Thurallor-7095
        top = top + textBox:GetHeight();
312 2 Thurallor-7095
        textBox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
313 7 Thurallor-7095
        textBox:SetMultiline(false);
314 2 Thurallor-7095
        textBox:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
315 Thurallor-7095
        textBox:SetForeColor(color);
316 Thurallor-7095
        textBox:SetText(text);
317 47 Thurallor-7095
        if (resizable) then
318 Thurallor-7095
            textBox.resizer = Thurallor.UI.Resizer(textBox);
319 Thurallor-7095
            textBox.resizer:SetMinimumHeight(20);
320 Thurallor-7095
            textBox.resizer:SetMinimumWidth(slotTabCardWidth - 20);
321 Thurallor-7095
            textBox.resizer:SetMaximumWidth(slotTabCardWidth - 20);
322 Thurallor-7095
        end
323 2 Thurallor-7095
        return top, textBox;
324 Thurallor-7095
    end
325 6 Thurallor-7095
 
326 20 Thurallor-7095
    -- Create a function for adding a left-justified checkbox to the properties control
327 6 Thurallor-7095
    local AddCheckBox = function(top, text, color, checked)
328 Thurallor-7095
        local checkBox = Turbine.UI.Lotro.CheckBox();
329 Thurallor-7095
        checkBox:SetParent(self.slotProperties);
330 Thurallor-7095
        checkBox:SetPosition(0, top);
331 35 Thurallor-7095
        checkBox:SetSize(slotTabCardWidth - 20, 20);
332 6 Thurallor-7095
        top = top + 20;
333 Thurallor-7095
        checkBox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
334 Thurallor-7095
        checkBox:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
335 Thurallor-7095
        checkBox:SetForeColor(color);
336 Thurallor-7095
        checkBox:SetText(text);
337 Thurallor-7095
        if (checked) then
338 Thurallor-7095
            checkBox:SetChecked(true);
339 Thurallor-7095
        end
340 Thurallor-7095
        return top, checkBox;
341 Thurallor-7095
    end
342 2 Thurallor-7095
 
343 6 Thurallor-7095
    -- Create a function for adding a left-justified radio button to the properties control
344 Thurallor-7095
    local AddRadioButton = function(top, text, color, checked)
345 Thurallor-7095
        local button = Thurallor.UI.RadioButton(self.slotProperties, text, checked);
346 Thurallor-7095
        button:SetPosition(0, top);
347 35 Thurallor-7095
        button:SetSize(slotTabCardWidth - 20, 16);
348 6 Thurallor-7095
        top = top + 16;
349 Thurallor-7095
        button:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
350 Thurallor-7095
        button:SetForeColor(color);
351 Thurallor-7095
        return top, button;
352 Thurallor-7095
    end
353 Thurallor-7095
 
354 Thurallor-7095
    -- Create a function for adding a drop-down listbox to the properties control
355 16 Thurallor-7095
    local AddDropDown = function(top, items, default)
356 128 Thurallor-7095
        local dropDown = Thurallor.UI.DropDown(items, default or items[1]);
357 6 Thurallor-7095
        dropDown:SetParent(self.slotProperties);
358 Thurallor-7095
        dropDown:SetPosition(0, top);
359 35 Thurallor-7095
        dropDown:SetWidth(slotTabCardWidth - 20);
360 6 Thurallor-7095
        top = top + dropDown:GetHeight();
361 Thurallor-7095
        return top, dropDown;
362 Thurallor-7095
    end
363 7 Thurallor-7095
 
364 16 Thurallor-7095
    -- Create a function for adding a pull-down hierarchical menu to the properties control
365 Thurallor-7095
    local AddPullDown = function(top, items, default)
366 Thurallor-7095
        local pullDown = Thurallor.UI.PullDownMenu(items, default);
367 Thurallor-7095
        pullDown:SetParent(self.slotProperties);
368 Thurallor-7095
        pullDown:SetPosition(0, top);
369 35 Thurallor-7095
        pullDown:SetWidth(slotTabCardWidth - 20);
370 16 Thurallor-7095
        top = top + pullDown:GetHeight();
371 Thurallor-7095
        return top, pullDown;
372 Thurallor-7095
    end
373 Thurallor-7095
 
374 7 Thurallor-7095
    -- Create a function for adding a horizontal scrollbar to the properties control
375 Thurallor-7095
    local AddSlider = function(top, minimum, maximum, value)
376 Thurallor-7095
        local scrollBar = Turbine.UI.Lotro.ScrollBar();
377 Thurallor-7095
        scrollBar:SetParent(self.slotProperties);
378 Thurallor-7095
        scrollBar:SetPosition(0, top);
379 35 Thurallor-7095
        scrollBar:SetSize(slotTabCardWidth - 20, 10);
380 7 Thurallor-7095
        scrollBar:SetMinimum(minimum);
381 Thurallor-7095
        scrollBar:SetMaximum(maximum);
382 Thurallor-7095
        scrollBar:SetSmallChange(1);
383 Thurallor-7095
        scrollBar:SetValue(value);
384 Thurallor-7095
        top = top + 10;
385 Thurallor-7095
        return top, scrollBar;
386 Thurallor-7095
    end
387 34 Thurallor-7095
 
388 Thurallor-7095
    -- Create a function for adding an expand/collapse section header to the properties control
389 Thurallor-7095
    local AddSection = function(top, text, color, expanded)
390 Thurallor-7095
        local button = Turbine.UI.Control();
391 Thurallor-7095
        button:SetParent(self.slotProperties);
392 Thurallor-7095
        button:SetPosition(0, top);
393 Thurallor-7095
        button:SetSize(16, 16);
394 Thurallor-7095
        button:SetBlendMode(Turbine.UI.BlendMode.Overlay);
395 Thurallor-7095
        local label = Turbine.UI.Label();
396 Thurallor-7095
        label:SetParent(self.slotProperties);
397 Thurallor-7095
        label:SetPosition(18, top);
398 35 Thurallor-7095
        label:SetSize(slotTabCardWidth - 20 - 18, 16);
399 34 Thurallor-7095
        top = top + 16;
400 Thurallor-7095
        label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
401 Thurallor-7095
        label:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
402 Thurallor-7095
        label:SetForeColor(color);
403 Thurallor-7095
        label:SetMarkupEnabled(true);
404 Thurallor-7095
        label:SetText(text);
405 Thurallor-7095
        function button.MouseClick()
406 Thurallor-7095
            if (button.expanded) then
407 Thurallor-7095
                button:SetBackground(resources.Icon.Expand);
408 Thurallor-7095
                button.expanded = false;
409 Thurallor-7095
                DoCallbacks(button, "ExpandedChanged", false);
410 Thurallor-7095
            else
411 Thurallor-7095
                button:SetBackground(resources.Icon.Collapse);
412 Thurallor-7095
                button.expanded = true;
413 Thurallor-7095
                DoCallbacks(button, "ExpandedChanged", true);
414 Thurallor-7095
            end
415 Thurallor-7095
        end
416 Thurallor-7095
        label.MouseClick = button.MouseClick;
417 Thurallor-7095
        button.expanded = not expanded;
418 Thurallor-7095
        button:MouseClick();
419 Thurallor-7095
        return top, button;
420 Thurallor-7095
    end
421 6 Thurallor-7095
 
422 2 Thurallor-7095
    -- Draw the caption
423 Thurallor-7095
    local top = 54;
424 Thurallor-7095
    if (info.class == "Turbine.UI.Lotro.Quickslot") then
425 Thurallor-7095
        top = AddLabel(top, L:GetText("/SequenceEditor/StandardQuickslot"), Turbine.UI.Color.PaleGoldenrod);
426 135 Thurallor-7095
    elseif ((info.class == "Turbine.UI.Control") or (info.class == "Turbine.UI.Lotro.EntityControl")) then
427 2 Thurallor-7095
        top = AddLabel(top, L:GetText("/SequenceEditor/SpecialSlot") .. ":", Turbine.UI.Color.PaleGoldenrod);
428 32 Thurallor-7095
        local label;
429 Thurallor-7095
        top, label = AddLabel(top, info.toolTip, Turbine.UI.Color.PaleGoldenrod);
430 Thurallor-7095
        -- Some German strings need line wrapping here.
431 Thurallor-7095
        label:SetHeight(32);
432 Thurallor-7095
        label:SetTextAlignment(Turbine.UI.ContentAlignment.TopCenter);
433 2 Thurallor-7095
    end
434 Thurallor-7095
 
435 Thurallor-7095
    -- Draw the arguments
436 Thurallor-7095
    if (info.class == "Turbine.UI.Lotro.Quickslot") then
437 Thurallor-7095
        top = top + 16; -- skip a line
438 Thurallor-7095
        for key, value in pairs(Turbine.UI.Lotro.ShortcutType) do
439 Thurallor-7095
            if (info.type == value) then
440 Thurallor-7095
                top = AddLabel(top, L:GetText("/SequenceEditor/ShortcutType") .. ": " .. L:GetText("/SequenceEditor/ShortcutTypes/" .. key), Turbine.UI.Color.Goldenrod);
441 Thurallor-7095
                break;
442 Thurallor-7095
            end
443 Thurallor-7095
        end
444 7 Thurallor-7095
 
445 Thurallor-7095
        if (info.type == Turbine.UI.Lotro.ShortcutType.Alias) then
446 Thurallor-7095
            -- Allow the user to specify the command
447 Thurallor-7095
            top = top + 16; -- skip a line
448 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/ChatCommand") .. ":", Turbine.UI.Color.Goldenrod);
449 Thurallor-7095
            local textBox;
450 Thurallor-7095
            top, textBox = AddTextBox(top, info.Data, Turbine.UI.Color.White);
451 Thurallor-7095
            textBox.TextChanged = function(sender, args)
452 Thurallor-7095
                local text = sender:GetText();
453 Thurallor-7095
                -- Remove carriage returns
454 Thurallor-7095
                local stripped = string.gsub(text, "\n", "");
455 Thurallor-7095
                if (stripped ~= text) then
456 Thurallor-7095
                    sender:SetText(stripped);
457 Thurallor-7095
                    text = stripped;
458 Thurallor-7095
                end
459 Thurallor-7095
                info.Data = text;
460 16 Thurallor-7095
                self:UpdateBar();
461 7 Thurallor-7095
            end
462 20 Thurallor-7095
        elseif (info.type == Turbine.UI.Lotro.ShortcutType.Item) then
463 Thurallor-7095
            local shortcut = Turbine.UI.Lotro.Shortcut(info.type, info.Data);
464 Thurallor-7095
            local item = shortcut:GetItem();
465 128 Thurallor-7095
            if (pcall(item.GetMaxStackSize, item)) then
466 Thurallor-7095
                if (item:GetMaxStackSize() == 1) then -- equippable
467 Thurallor-7095
 
468 Thurallor-7095
                    -- Allow the user to specify immediate advance, or wait-for-equip
469 Thurallor-7095
                    top = top + 16; -- skip a line
470 Thurallor-7095
                    top = AddLabel(top, L:GetText("/SequenceEditor/AdvanceToNextSlot") .. ":", Turbine.UI.Color.Goldenrod);
471 Thurallor-7095
                    local button1, button2;
472 Thurallor-7095
                    top, button1 = AddRadioButton(top, L:GetText("/SequenceEditor/WithLeftClick"), Turbine.UI.Color.DarkGoldenrod, (not info.advanceEvent));
473 Thurallor-7095
                    top, button2 = AddRadioButton(top, L:GetText("/SequenceEditor/WhenItemEquipped"), Turbine.UI.Color.DarkGoldenrod, info.advanceEvent);
474 Thurallor-7095
                    Thurallor.UI.RadioButton.LinkPeers({button1, button2});
475 Thurallor-7095
 
476 Thurallor-7095
                    button1.Clicked = function()
477 Thurallor-7095
                        info.advanceEvent = nil;
478 Thurallor-7095
                        self:UpdateBar();
479 Thurallor-7095
                    end
480 Thurallor-7095
                    button2.Clicked = function()
481 Thurallor-7095
                        info.advanceEvent = "ItemEquipped";
482 Thurallor-7095
                        self:UpdateBar();
483 Thurallor-7095
                    end
484 20 Thurallor-7095
                end
485 128 Thurallor-7095
            -- else "invalid entity" -- probably an item that no longer exists in your inventory
486 20 Thurallor-7095
            end
487 7 Thurallor-7095
        end
488 Thurallor-7095
 
489 135 Thurallor-7095
    elseif (info.class == "Turbine.UI.Lotro.EntityControl") then
490 Thurallor-7095
        if (info.type == "SelectTarget") then
491 Thurallor-7095
 
492 Thurallor-7095
            local getTargetFuncs = {
493 Thurallor-7095
                -- args are: watcher, localPlayer, info.raidMemberName
494 Thurallor-7095
                ["Self"] =                  "local _, player = ...; return player;";
495 136 Thurallor-7095
                ["CurrentTarget"] =         "local watcher = ...; return watcher:GetPlayerTarget();";
496 Thurallor-7095
                ["CurrentTargetsTarget"] =  "local watcher = ...; return watcher:GetTargetsTarget();";
497 135 Thurallor-7095
                ["Pet"] =                   "local _, player = ...; return player:GetPet();";
498 Thurallor-7095
                ["RaidLeader"] =            "local watcher = ...; return watcher.GetParty():GetLeader();";
499 Thurallor-7095
                ["RaidMemberByName"] =      "local watcher, _, name = ...; return watcher.GetPartyMemberByName(name, true);";
500 Thurallor-7095
                ["NextRaidMember"] =        "local watcher = ...; return watcher.GetNextPartyMember();";
501 Thurallor-7095
                ["FirstAssistee"] =         "local watcher = ...; return watcher.GetPartyAssistTarget(1);";
502 Thurallor-7095
                ["SecondAssistee"] =        "local watcher = ...; return watcher.GetPartyAssistTarget(2);";
503 Thurallor-7095
                ["ThirdAssistee"] =         "local watcher = ...; return watcher.GetPartyAssistTarget(3);";
504 Thurallor-7095
                ["FourthAssistee"] =        "local watcher = ...; return watcher.GetPartyAssistTarget(4);";
505 Thurallor-7095
                ["NextAssistee"] =          "local watcher = ...; return watcher.GetNextAssistTarget();";
506 Thurallor-7095
                ["FirstAssisteesTarget"] =  "local watcher = ...; local target = watcher.GetPartyAssistTarget(1); return (target and target:GetTarget());";
507 Thurallor-7095
                ["SecondAssisteesTarget"] = "local watcher = ...; local target = watcher.GetPartyAssistTarget(2); return (target and target:GetTarget());";
508 Thurallor-7095
                ["ThirdAssisteesTarget"] =  "local watcher = ...; local target = watcher.GetPartyAssistTarget(3); return (target and target:GetTarget());";
509 Thurallor-7095
                ["FourthAssisteesTarget"] = "local watcher = ...; local target = watcher.GetPartyAssistTarget(4); return (target and target:GetTarget());";
510 Thurallor-7095
                ["NextAssisteesTarget"] =   "local watcher = ...; local target = watcher.GetNextAssistTarget(); return (target and target:GetTarget());";
511 Thurallor-7095
            };
512 Thurallor-7095
 
513 Thurallor-7095
            -- Allow the user to choose the target category
514 Thurallor-7095
            top = top + 16; -- skip a line
515 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/Target") .. ":", Turbine.UI.Color.Goldenrod);
516 Thurallor-7095
 
517 Thurallor-7095
            local currentItem = info.target;
518 Thurallor-7095
            info.getTargetFunc = getTargetFuncs[currentItem];
519 Thurallor-7095
            local prevContext;
520 Thurallor-7095
            prevContext = L:SetContext("/SequenceEditor/TargetMenu");
521 Thurallor-7095
            local targs, localTargs = L:GetItems(), {};
522 Thurallor-7095
            for targ in values(targs) do
523 Thurallor-7095
                table.insert(localTargs, L:GetText(targ));
524 Thurallor-7095
            end
525 Thurallor-7095
            table.sort(localTargs);
526 Thurallor-7095
            local dropDown;
527 Thurallor-7095
            top, dropDown = AddDropDown(top, localTargs, L:GetText(currentItem));
528 Thurallor-7095
            dropDown:SetAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
529 Thurallor-7095
            dropDown:SetExpandedWidth(math.max(220, slotTabCardWidth - 20));
530 Thurallor-7095
            dropDown.ItemChanged = function(sender, args)
531 Thurallor-7095
                for targ in values(targs) do
532 Thurallor-7095
                    if (L:GetText(targ) == args.Text) then
533 Thurallor-7095
                        info.target = targ;
534 Thurallor-7095
                        self:DisplaySlot(self.selectedSlot);
535 Thurallor-7095
                        self:UpdateBar();
536 Thurallor-7095
                        break;
537 Thurallor-7095
                    end
538 Thurallor-7095
                end
539 Thurallor-7095
            end
540 Thurallor-7095
 
541 Thurallor-7095
            -- If "Raid Member" is chosen, allow the user to select raid member by name
542 Thurallor-7095
            if (info.target == "RaidMemberByName") then
543 Thurallor-7095
                if ((info.raidMemberName == nil) or (info.raidMemberName == "")) then
544 Thurallor-7095
                    info.raidMemberName = self.manager.player:GetName();
545 Thurallor-7095
                end
546 Thurallor-7095
                local textBox;
547 Thurallor-7095
                top, textBox = AddTextBox(top, info.raidMemberName, Turbine.UI.Color.White);
548 Thurallor-7095
                textBox.TextChanged = function(sender, args)
549 Thurallor-7095
                    local text = sender:GetText();
550 Thurallor-7095
                    -- Remove carriage returns
551 Thurallor-7095
                    local stripped = string.gsub(text, "\n", "");
552 Thurallor-7095
                    if (stripped ~= text) then
553 Thurallor-7095
                        sender:SetText(stripped);
554 Thurallor-7095
                        text = stripped;
555 Thurallor-7095
                    end
556 Thurallor-7095
                    info.raidMemberName = text;
557 Thurallor-7095
                    self:UpdateBar();
558 Thurallor-7095
                end
559 Thurallor-7095
            end
560 Thurallor-7095
 
561 Thurallor-7095
            -- Evaluate the target selection and display the name of the targeted entity
562 Thurallor-7095
            top, label = AddLabel(top, "", Turbine.UI.Color.Goldenrod);
563 Thurallor-7095
            label.Update = function()
564 Thurallor-7095
                local entity = loadstring(info.getTargetFunc)(self.manager.watcher, self.manager.player, info.raidMemberName);
565 Thurallor-7095
                if (entity) then
566 Thurallor-7095
                    label:SetText("(" .. entity:GetName() .. ")");
567 Thurallor-7095
                    label:SetForeColor(Turbine.UI.Color.Lime);
568 Thurallor-7095
                else
569 Thurallor-7095
                    label:SetText(L:GetText("/SequenceEditor/NoTarget"));
570 Thurallor-7095
                    label:SetForeColor(Turbine.UI.Color.Red);
571 Thurallor-7095
                end
572 Thurallor-7095
            end
573 Thurallor-7095
            label:SetWantsUpdates(true);
574 Thurallor-7095
        end
575 Thurallor-7095
 
576 2 Thurallor-7095
    elseif (info.class == "Turbine.UI.Control") then
577 34 Thurallor-7095
        if (info.type == "Delay") then
578 Thurallor-7095
 
579 Thurallor-7095
            -- Allow the user to specify the delay period
580 Thurallor-7095
            top = top + 16; -- skip a line
581 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/DelayPeriod") .. ":", Turbine.UI.Color.Goldenrod);
582 Thurallor-7095
            local textBox;
583 Thurallor-7095
            _, textBox = AddTextBox(top, info.delay, Turbine.UI.Color.White);
584 Thurallor-7095
            textBox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleRight);
585 35 Thurallor-7095
            local center = math.floor((slotTabCardWidth - 20) / 2);
586 34 Thurallor-7095
            textBox:SetWidth(50);
587 Thurallor-7095
            textBox:SetLeft(center - 2 - 50);
588 Thurallor-7095
            top, label = AddLabel(top + 2, L:GetText("/SequenceEditor/Seconds"), Turbine.UI.Color.DarkGoldenrod);
589 Thurallor-7095
            label:SetLeft(center + 2);
590 Thurallor-7095
            label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
591 Thurallor-7095
            textBox.TextChanged = function(sender, args)
592 Thurallor-7095
                info.delay = tonumber(sender:GetText());
593 Thurallor-7095
                info.action = "local item, s = ...; item.bar:StartSlotCooldown(s, " .. tostring(info.delay) .. ");";
594 Thurallor-7095
                self:UpdateBar();
595 Thurallor-7095
            end
596 Thurallor-7095
        elseif (info.type == "GenerateEvent") then
597 6 Thurallor-7095
 
598 Thurallor-7095
            -- Allow the user to specify the event name
599 Thurallor-7095
            top = top + 16; -- skip a line
600 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/EventName") .. ":", Turbine.UI.Color.Goldenrod);
601 2 Thurallor-7095
            local textBox;
602 Thurallor-7095
            top, textBox = AddTextBox(top, info.eventName, Turbine.UI.Color.White);
603 Thurallor-7095
            textBox.TextChanged = function(sender, args)
604 5 Thurallor-7095
                local text = sender:GetText();
605 Thurallor-7095
                -- Remove carriage returns
606 Thurallor-7095
                local stripped = string.gsub(text, "\n", "");
607 Thurallor-7095
                if (stripped ~= text) then
608 Thurallor-7095
                    sender:SetText(stripped);
609 Thurallor-7095
                    text = stripped;
610 Thurallor-7095
                end
611 Thurallor-7095
                info.eventName = text;
612 16 Thurallor-7095
                self:UpdateBar();
613 2 Thurallor-7095
            end
614 6 Thurallor-7095
        elseif (info.type == "SetUnequipDestination") then
615 Thurallor-7095
 
616 20 Thurallor-7095
            -- Temporary method to allow users to discover bag slot numbers.
617 Thurallor-7095
            self.ItemMovedCallback = function(sender, args)
618 Thurallor-7095
                local str = L:GetText("/ItemMoved");
619 Thurallor-7095
                str = string.gsub(str, "<source>", tostring(args.OldIndex));
620 Thurallor-7095
                str = string.gsub(str, "<destination>", tostring(args.NewIndex));
621 Thurallor-7095
                Puts(str);
622 Thurallor-7095
            end
623 Thurallor-7095
            AddCallback(Thurallor.Utils.Watcher, "ItemMoved", self.ItemMovedCallback);
624 Thurallor-7095
 
625 6 Thurallor-7095
            -- Allow the user to specify the desired bag slot
626 Thurallor-7095
            top = top + 16; -- skip a line
627 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/PreferredBagSlot") .. ":", Turbine.UI.Color.Goldenrod);
628 Thurallor-7095
 
629 114 Thurallor-7095
            top, textBox = AddTextBox(top, tostring(info.bagSlot), Turbine.UI.Color.White);
630 Thurallor-7095
            textBox:SetFont(Turbine.UI.Lotro.Font.Verdana14);
631 Thurallor-7095
            textBox.TextChanged = function(sender, args)
632 Thurallor-7095
                local series = Thurallor.Utils.Series(sender:GetText())
633 Thurallor-7095
                info.bagSlot = series:tostring();
634 16 Thurallor-7095
                self:UpdateBar();
635 6 Thurallor-7095
            end
636 Thurallor-7095
        elseif (string.match(info.type, "^Remove ")) then
637 Thurallor-7095
 
638 Thurallor-7095
            -- Allow the user to edit choose the item to be unequipped
639 Thurallor-7095
            top = top + 16; -- skip a line
640 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/EquipmentType") .. ":", Turbine.UI.Color.Goldenrod);
641 Thurallor-7095
 
642 Thurallor-7095
            local currentItem = string.sub(info.type, 8);
643 Thurallor-7095
            local prevContext = L:SetContext("/SequenceEditor/EquipmentSlots");
644 Thurallor-7095
            local eqSlots, localEqSlots = L:GetItems(), {};
645 Thurallor-7095
            for slot in values(eqSlots) do
646 Thurallor-7095
                table.insert(localEqSlots, L:GetText(slot));
647 Thurallor-7095
            end
648 Thurallor-7095
            table.sort(localEqSlots);
649 Thurallor-7095
            local dropDown;
650 16 Thurallor-7095
            top, dropDown = AddDropDown(top, localEqSlots, L:GetText(currentItem));
651 122 Thurallor-7095
            dropDown:SetExpandedWidth(math.max(220, slotTabCardWidth - 20));
652 6 Thurallor-7095
            dropDown.ItemChanged = function(sender, args)
653 Thurallor-7095
                for slot in values(eqSlots) do
654 Thurallor-7095
                    if (L:GetText(slot) == args.Text) then
655 122 Thurallor-7095
                        self:DeleteSlot(s);
656 6 Thurallor-7095
                        self:CreateRemovalSlot(s, slot, info.bagSlot);
657 Thurallor-7095
                        break;
658 Thurallor-7095
                    end
659 Thurallor-7095
                end
660 Thurallor-7095
            end
661 16 Thurallor-7095
        elseif (info.type == "If") then
662 Thurallor-7095
 
663 Thurallor-7095
            -- Allow the user to specify the conditional expression
664 Thurallor-7095
            top = top + 16; -- skip a line
665 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/Condition") .. ":", Turbine.UI.Color.Goldenrod);
666 Thurallor-7095
 
667 Thurallor-7095
            local prevContext = L:SetContext("/SequenceEditor/ConditionTypes");
668 Thurallor-7095
            local condInfo = {
669 20 Thurallor-7095
                ["Always"] =                      { expr = "return true;" };
670 Thurallor-7095
                ["Never"] =                       { expr = "return false;" };
671 43 Thurallor-7095
                ["SkillReady"] =                  {  arg = "skillName";
672 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.SkillReady(<skillName>));" };
673 Thurallor-7095
                ["SkillNotReady"] =               {  arg = "skillName";
674 Thurallor-7095
                                                    expr = "return (not Thurallor.Utils.Watcher.SkillReady(<skillName>));" };
675 48 Thurallor-7095
                ["SkillUsable"] =                 {  arg = "skillName";
676 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.SkillUsable(<skillName>));" };
677 Thurallor-7095
                ["SkillNotUsable"] =              {  arg = "skillName";
678 Thurallor-7095
                                                    expr = "return (not Thurallor.Utils.Watcher.SkillUsable(<skillName>));" };
679 41 Thurallor-7095
                ["SkillTrained"] =                {  arg = "skillName";
680 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.SkillTrained(<skillName>));" };
681 Thurallor-7095
                ["SkillNotTrained"] =             {  arg = "skillName";
682 Thurallor-7095
                                                    expr = "return (not Thurallor.Utils.Watcher.SkillTrained(<skillName>));" };
683 20 Thurallor-7095
                ["PlayerEffectDisease"] =         { expr = "return Thurallor.Utils.Watcher.PlayerHasEffectCategory(Turbine.Gameplay.EffectCategory.Disease);" };
684 Thurallor-7095
                ["PlayerEffectFear"] =            { expr = "return Thurallor.Utils.Watcher.PlayerHasEffectCategory(Turbine.Gameplay.EffectCategory.Fear);" };
685 Thurallor-7095
                ["PlayerEffectPoison"] =          { expr = "return Thurallor.Utils.Watcher.PlayerHasEffectCategory(Turbine.Gameplay.EffectCategory.Poison);" };
686 Thurallor-7095
                ["PlayerEffectWound"] =           { expr = "return Thurallor.Utils.Watcher.PlayerHasEffectCategory(Turbine.Gameplay.EffectCategory.Wound);" };
687 Thurallor-7095
                ["PlayerEffectOther"] =           {  arg = "effect";
688 Thurallor-7095
                                                    expr = "return Thurallor.Utils.Watcher.PlayerHasEffect(<effect>);" };
689 Thurallor-7095
                ["NotPlayerEffectOther"] =        {  arg = "effect";
690 Thurallor-7095
                                                    expr = "return (not Thurallor.Utils.Watcher.PlayerHasEffect(<effect>));" };
691 23 Thurallor-7095
-- Target effects tracking is so buggy as to be useless.  Hoping Turbine addresses this bug soon.
692 Thurallor-7095
--                ["TargetEffectDisease"] =         { expr = "return Thurallor.Utils.Watcher.TargetHasEffectCategory(Turbine.Gameplay.EffectCategory.Disease);" };
693 Thurallor-7095
--                ["TargetEffectFear"] =            { expr = "return Thurallor.Utils.Watcher.TargetHasEffectCategory(Turbine.Gameplay.EffectCategory.Fear);" };
694 Thurallor-7095
--                ["TargetEffectPoison"] =          { expr = "return Thurallor.Utils.Watcher.TargetHasEffectCategory(Turbine.Gameplay.EffectCategory.Poison);" };
695 Thurallor-7095
--                ["TargetEffectWound"] =           { expr = "return Thurallor.Utils.Watcher.TargetHasEffectCategory(Turbine.Gameplay.EffectCategory.Wound);" };
696 Thurallor-7095
--                ["TargetEffectOther"] =           {  arg = "effect";
697 Thurallor-7095
--                                                    expr = "return Thurallor.Utils.Watcher.TargetHasEffect(<effect>);" };
698 Thurallor-7095
--                ["NotTargetEffectOther"] =        {  arg = "effect";
699 Thurallor-7095
--                                                    expr = "return (not Thurallor.Utils.Watcher.TargetHasEffect(<effect>));" };
700 111 Thurallor-7095
                ["PlayerInCombat"] =              { expr = "local _, player = ...; return player:IsInCombat();" };
701 Thurallor-7095
                ["PlayerOutOfCombat"] =           { expr = "local _, player = ...; return not player:IsInCombat();" };
702 20 Thurallor-7095
                ["PlayerMorale < x"] =            {  arg = "x";
703 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetMorale() < <x>)" };
704 Thurallor-7095
                ["PlayerMorale < x%"] =           {  arg = "x";
705 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetMorale() < player:GetBaseMaxMorale() * <x> / 100)" };
706 Thurallor-7095
                ["PlayerMorale > x"] =            {  arg = "x";
707 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetMorale() > <x>)" };
708 Thurallor-7095
                ["PlayerMorale > x%"] =           {  arg = "x";
709 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetMorale() > player:GetBaseMaxMorale() * <x> / 100)" };
710 140 Thurallor-7095
                ["TargetIsFellow"] =              { expr = "local _, player = ...; return Thurallor.Utils.Watcher.TargetIsPartyMember();" };
711 Thurallor-7095
                ["TargetNotFellow"] =             { expr = "local _, player = ...; return not Thurallor.Utils.Watcher.TargetIsPartyMember();" };
712 20 Thurallor-7095
                ["TargetMorale < x"] =            {  arg = "x";
713 117 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and target.GetMorale and (target:GetMorale() < <x>))" };
714 20 Thurallor-7095
                ["TargetMorale < x%"] =           {  arg = "x";
715 117 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and target.GetMorale and (target:GetMorale() < target:GetBaseMaxMorale() * <x> / 100))" };
716 20 Thurallor-7095
                ["TargetMorale > x"] =            {  arg = "x";
717 117 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and target.GetMorale and (target:GetMorale() > <x>))" };
718 20 Thurallor-7095
                ["TargetMorale > x%"] =           {  arg = "x";
719 117 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and target.GetMorale and (target:GetMorale() > target:GetBaseMaxMorale() * <x> / 100))" };
720 20 Thurallor-7095
                ["PlayerPower < x"] =             {  arg = "x";
721 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetPower() < <x>)" };
722 Thurallor-7095
                ["PlayerPower < x%"] =            {  arg = "x";
723 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetPower() < player:GetBaseMaxPower() * <x> / 100)" };
724 Thurallor-7095
                ["PlayerPower > x"] =             {  arg = "x";
725 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetPower() > <x>)" };
726 Thurallor-7095
                ["PlayerPower > x%"] =            {  arg = "x";
727 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetPower() > player:GetBaseMaxPower() * <x> / 100)" };
728 Thurallor-7095
                ["TargetPower < x"] =             {  arg = "x";
729 117 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and target.GetPower and (target:GetPower() < <x>))" };
730 20 Thurallor-7095
                ["TargetPower < x%"] =            {  arg = "x";
731 117 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and target.GetPower and (target:GetPower() < target:GetBaseMaxPower() * <x> / 100))" };
732 20 Thurallor-7095
                ["TargetPower > x"] =             {  arg = "x";
733 117 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and target.GetPower and (target:GetPower() > <x>))" };
734 20 Thurallor-7095
                ["TargetPower > x%"] =            {  arg = "x";
735 117 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and target.GetPower and (target:GetPower() > target:GetBaseMaxPower() * <x> / 100))" };
736 111 Thurallor-7095
                ["ChampionPlayerFervor < x"] =    {  arg = "x";
737 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetFervor and (attribs:GetFervor() < <x>);" };
738 Thurallor-7095
                ["ChampionPlayerFervor > x"] =    {  arg = "x";
739 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetFervor and (attribs:GetFervor() > <x>);" };
740 20 Thurallor-7095
                ["BeorningPlayerWrath < x%"] =    {  arg = "x";
741 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetWrath and (attribs:GetWrath() < <x>);" };
742 Thurallor-7095
                ["BeorningPlayerWrath > x%"] =    {  arg = "x";
743 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetWrath and (attribs:GetWrath() > <x>);" };
744 Thurallor-7095
                ["BeorningInBearForm"] =          { expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.IsInBearForm and attribs:IsInBearForm();" };
745 Thurallor-7095
                ["BeorningNotInBearForm"] =       { expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.IsInBearForm and (not attribs:IsInBearForm());" };
746 40 Thurallor-7095
                ["HunterFocus < x"] =             {  arg = "x";
747 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetFocus and (attribs:GetFocus() < <x>);" };
748 Thurallor-7095
                ["HunterFocus > x"] =             {  arg = "x";
749 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetFocus and (attribs:GetFocus() > <x>);" };
750 124 Thurallor-7095
                ["RunekeeperAttunement < x"] =    {  arg = "x";
751 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetAttunement and (attribs:GetAttunement() < <x>);" };
752 Thurallor-7095
                ["RunekeeperAttunement > x"] =    {  arg = "x";
753 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetAttunement and (attribs:GetAttunement() > <x>);" };
754 Thurallor-7095
                ["RunekeeperCharged"] =           { expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.IsCharged and attribs:IsCharged();" };
755 Thurallor-7095
                ["RunekeeperNotCharged"] =        { expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.IsCharged and (not attribs:IsCharged());" };
756 20 Thurallor-7095
                ["ItemEquipped"] =                {  arg = { "eqItemName", "eqSlot" };
757 Thurallor-7095
                                                    expr = "return IsEquipped(<eqItemName>, <eqSlot>);" };
758 Thurallor-7095
                ["ItemNotEquipped"] =             {  arg = { "eqItemName", "eqSlot" };
759 Thurallor-7095
                                                    expr = "return (not IsEquipped(<eqItemName>, <eqSlot>));" };
760 30 Thurallor-7095
                ["ItemQuantity > x"] =            {  arg = { "stackItemName", "x" };
761 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.GetItemQuantity(<stackItemName>) > <x>);" };
762 Thurallor-7095
                ["ItemQuantity < x"] =            {  arg = { "stackItemName", "x" };
763 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.GetItemQuantity(<stackItemName>) < <x>);" };
764 111 Thurallor-7095
                ["StanceSelected"] =              {  arg = "stance";
765 119 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.GetStance() == <stance>);" };
766 20 Thurallor-7095
                ["LuaScript"] =                   {  arg = "script";
767 Thurallor-7095
                                                    expr = "<script>" };
768 16 Thurallor-7095
            };
769 Thurallor-7095
            local condNames = {};
770 Thurallor-7095
            for k in keys(condInfo) do
771 Thurallor-7095
                table.insert(condNames, L:GetText(k));
772 Thurallor-7095
            end
773 Thurallor-7095
            table.sort(condNames);
774 Thurallor-7095
 
775 20 Thurallor-7095
            local function SwitchArgs(arg)
776 16 Thurallor-7095
                if (not info.condArgs) then
777 Thurallor-7095
                    info.condArgs = {};
778 Thurallor-7095
                end
779 Thurallor-7095
                if (not arg) then
780 Thurallor-7095
                    info.condArgs = nil;
781 Thurallor-7095
                elseif ((arg == "x") and not info.condArgs.x) then
782 Thurallor-7095
                    info.condArgs = { x = 0 };
783 41 Thurallor-7095
                elseif ((arg == "skillName") and not info.condArgs.skillName) then
784 Thurallor-7095
                    info.condArgs = { skillName = "nil" };
785 16 Thurallor-7095
                elseif ((arg == "skill") and not info.condArgs.skill) then
786 Thurallor-7095
                    info.condArgs = { skill = 0 };
787 20 Thurallor-7095
                elseif ((arg == "effect") and not info.condArgs.effect) then
788 22 Thurallor-7095
                    info.condArgs = { effect = "nil" };
789 111 Thurallor-7095
                elseif ((arg == "stance") and not info.condArgs.stance) then
790 Thurallor-7095
                    info.condArgs = { stance = 0 };
791 16 Thurallor-7095
                elseif ((arg == "script") and not info.condArgs.script) then
792 Thurallor-7095
                    if (info.condExpr) then
793 Thurallor-7095
                        local script = info.condExpr;
794 Thurallor-7095
                        if (info.condArgs) then
795 Thurallor-7095
                            for name, value in pairs(info.condArgs) do
796 Thurallor-7095
                                script = string.gsub(script, "<" .. name .. ">", tostring(value));
797 Thurallor-7095
                            end
798 Thurallor-7095
                        end
799 Thurallor-7095
                        info.condArgs = { script = script };
800 Thurallor-7095
                    else
801 Thurallor-7095
                        info.condArgs = { script = "return true;" };
802 Thurallor-7095
                    end
803 20 Thurallor-7095
                elseif (type(arg) == "table") then
804 Thurallor-7095
                    -- Multiple args
805 Thurallor-7095
                    local prevArgs = info.condArgs;
806 Thurallor-7095
                    info.condArgs = {};
807 Thurallor-7095
                    for argName in values(arg) do
808 Thurallor-7095
                        if (prevArgs[argName]) then
809 Thurallor-7095
                            info.condArgs[argName] = prevArgs[argName];
810 16 Thurallor-7095
                        end
811 20 Thurallor-7095
                        if ((argName == "eqItemName") and not info.condArgs.eqItemName) then
812 Thurallor-7095
                            info.condArgs.eqItemName = "nil";
813 30 Thurallor-7095
                        elseif ((argName == "stackItemName") and not info.condArgs.stackItemName) then
814 Thurallor-7095
                            info.condArgs.stackItemName = "nil";
815 20 Thurallor-7095
                        elseif ((argName == "eqSlot") and not info.condArgs.eqSlot) then
816 Thurallor-7095
                            info.condArgs.eqSlot = "nil";
817 30 Thurallor-7095
                        elseif ((argName == "x") and not info.condArgs.x) then
818 Thurallor-7095
                            info.condArgs.x  = 0;
819 16 Thurallor-7095
                        end
820 Thurallor-7095
                    end
821 Thurallor-7095
                end
822 20 Thurallor-7095
                info.condExpr = condInfo[info.condName].expr;
823 16 Thurallor-7095
            end
824 Thurallor-7095
 
825 Thurallor-7095
            local dropDown;
826 Thurallor-7095
            top, dropDown = AddDropDown(top, condNames, L:GetText(info.condName));
827 47 Thurallor-7095
            dropDown:SetExpandedWidth(math.max(300, slotTabCardWidth - 20));
828 16 Thurallor-7095
            dropDown:SetAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
829 Thurallor-7095
            dropDown.ItemChanged = function(sender, args)
830 Thurallor-7095
                local prevContext = L:SetContext("/SequenceEditor/ConditionTypes");
831 Thurallor-7095
                info.condName = L:GetItem(args.Text);
832 Thurallor-7095
                L:SetContext(prevContext);
833 Thurallor-7095
                local arg = condInfo[info.condName].arg;
834 20 Thurallor-7095
                SwitchArgs(arg);
835 16 Thurallor-7095
                self:UpdateBar();
836 20 Thurallor-7095
                self:DisplaySlot(self.selectedSlot);
837 16 Thurallor-7095
            end
838 Thurallor-7095
 
839 20 Thurallor-7095
            SwitchArgs(condInfo[info.condName].arg);
840 Thurallor-7095
            L:SetContext(prevContext);
841 16 Thurallor-7095
 
842 20 Thurallor-7095
            -- Display additional arguments depending on the current condition type
843 Thurallor-7095
            if (info.condArgs) then
844 30 Thurallor-7095
                if (info.condArgs.stackItemName) then
845 Thurallor-7095
                    local function GetStackableItems()
846 Thurallor-7095
                        local hash = {};
847 Thurallor-7095
                        local backpack = self.manager.player:GetBackpack();
848 Thurallor-7095
                        for i = 1, backpack:GetSize(), 1 do
849 Thurallor-7095
                            local item = backpack:GetItem(i);
850 Thurallor-7095
                            if (item and (item:GetMaxStackSize() > 1)) then
851 Thurallor-7095
                                hash[item:GetName()] = true;
852 Thurallor-7095
                            end
853 Thurallor-7095
                        end
854 Thurallor-7095
                        local items = {};
855 Thurallor-7095
                        for key in sorted_keys(hash) do
856 Thurallor-7095
                            table.insert(items, key);
857 Thurallor-7095
                        end
858 Thurallor-7095
                        return items;
859 Thurallor-7095
                    end
860 Thurallor-7095
                    local stackItemNames = GetStackableItems();
861 Thurallor-7095
                    local dropDown;
862 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, stackItemNames);
863 47 Thurallor-7095
                    dropDown:SetExpandedWidth(math.max(400, slotTabCardWidth - 20));
864 30 Thurallor-7095
                    dropDown.ItemChanged = function(sender, args)
865 Thurallor-7095
                        info.condArgs.stackItemName = "\"" .. args.Text .. "\"";
866 Thurallor-7095
                        self:UpdateBar();
867 Thurallor-7095
                    end
868 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
869 41 Thurallor-7095
                    local name = info.condArgs.stackItemName;
870 Thurallor-7095
                    if (name == "nil") then
871 Thurallor-7095
                        name = stackItemNames[1];
872 Thurallor-7095
                        if (name) then
873 Thurallor-7095
                            dropDown:ItemChanged({Text = name});
874 Thurallor-7095
                        end
875 Thurallor-7095
                    else
876 Thurallor-7095
                        dropDown:SetText(string.sub(name, 2, -2));
877 30 Thurallor-7095
                    end
878 Thurallor-7095
                end
879 20 Thurallor-7095
                if (info.condArgs.x) then
880 Thurallor-7095
                    local _, xLabel = AddLabel(top + 3, "", Turbine.UI.Color.DarkGoldenrod);
881 Thurallor-7095
                    xLabel:SetWidth(30);
882 Thurallor-7095
                    xLabel:SetFont(Turbine.UI.Lotro.Font.Verdana16);
883 Thurallor-7095
                    xLabel:SetText("x =");
884 Thurallor-7095
 
885 Thurallor-7095
                    local xField;
886 Thurallor-7095
                    top, xField = AddTextBox(top + 2, "", Turbine.UI.Color.White);
887 Thurallor-7095
                    xField:SetLeft(30);
888 35 Thurallor-7095
                    xField:SetWidth(slotTabCardWidth - 50);
889 20 Thurallor-7095
                    xField.TextChanged = function(sender)
890 Thurallor-7095
                        info.condArgs.x = tonumber(sender:GetText());
891 23 Thurallor-7095
                        if (not info.condArgs.x) then
892 Thurallor-7095
                            info.condArgs.x = 0;
893 Thurallor-7095
                        end
894 20 Thurallor-7095
                        self:UpdateBar();
895 Thurallor-7095
                    end
896 Thurallor-7095
                    xField:SetText(info.condArgs.x);
897 Thurallor-7095
                    xLabel:SetParent(self.slotProperties);
898 Thurallor-7095
                    xField:SetText(tostring(info.condArgs.x));
899 Thurallor-7095
                    xField:SetParent(self.slotProperties);
900 Thurallor-7095
                end
901 41 Thurallor-7095
                if (info.condArgs.skillName) then
902 43 Thurallor-7095
                    local trainedSkills = Thurallor.Utils.Watcher.GetTrainedSkillsInfo();
903 Thurallor-7095
                    local skills = Thurallor.Utils.Watcher.GetSkillsInfo(true);
904 Thurallor-7095
                    local displayNames = {};
905 Thurallor-7095
                    local untrained = L:GetText("/SequenceEditor/Untrained");
906 Thurallor-7095
                    for n = 1, #skills.names, 1 do
907 Thurallor-7095
                        local name = skills.names[n];
908 Thurallor-7095
                        if (not trainedSkills.byName[name]) then
909 Thurallor-7095
                            name = name .. " (" .. untrained .. ")";
910 Thurallor-7095
                        end
911 Thurallor-7095
                        table.insert(displayNames, name);
912 Thurallor-7095
                    end
913 20 Thurallor-7095
                    local dropDown;
914 43 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, displayNames);
915 47 Thurallor-7095
                    dropDown:SetExpandedWidth(math.max(300, slotTabCardWidth - 20));
916 20 Thurallor-7095
                    dropDown.ItemChanged = function(sender, args)
917 43 Thurallor-7095
                        local text = string.gsub(args.Text, " %(" .. L:GetText("/SequenceEditor/Untrained") .. "%)$", "");
918 Thurallor-7095
                        dropDown:SetText(text);
919 Thurallor-7095
                        info.condArgs.skillName = "\"" .. text .. "\"";
920 41 Thurallor-7095
                        self:UpdateBar();
921 Thurallor-7095
                    end
922 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
923 Thurallor-7095
                    local skillName = info.condArgs.skillName;
924 Thurallor-7095
                    if (skillName == "nil") then
925 43 Thurallor-7095
                        skillName = skills.names[1]; -- first one always will be a trained skill
926 41 Thurallor-7095
                        dropDown:ItemChanged({Text = skillName});
927 Thurallor-7095
                    else
928 Thurallor-7095
                        skillName = string.gsub(skillName, "\"", "")
929 Thurallor-7095
                        dropDown:SetText(skillName);
930 Thurallor-7095
                    end
931 Thurallor-7095
                end
932 20 Thurallor-7095
                if (info.condArgs.effect) then
933 Thurallor-7095
                    local effectNames = Thurallor.Utils.Watcher.GetKnownEffectNames();
934 Thurallor-7095
                    if (#effectNames >= 1) then
935 Thurallor-7095
                        table.insert(effectNames, 1, L:GetText("/SequenceEditor/ConditionTypes/OtherEffect"));
936 Thurallor-7095
                        local dropDown;
937 Thurallor-7095
                        top, dropDown = AddDropDown(top + 2, effectNames);
938 47 Thurallor-7095
                        dropDown:SetExpandedWidth(math.max(300, slotTabCardWidth - 20));
939 23 Thurallor-7095
                        function dropDown.ItemChanged(ctl, args)
940 22 Thurallor-7095
                            local effectNames = Thurallor.Utils.Watcher.GetKnownEffectNames();
941 Thurallor-7095
                            local other = L:GetText("/SequenceEditor/ConditionTypes/OtherEffect");
942 Thurallor-7095
                            table.insert(effectNames, 1, other);
943 20 Thurallor-7095
                            if (args.Text == other) then
944 Thurallor-7095
                                local ok = L:GetText("/ExportWindow/OK");
945 Thurallor-7095
                                local window = Alert(other,
946 Thurallor-7095
                                    L:GetText("/SequenceEditor/ConditionTypes/OtherEffectHelp"),
947 Thurallor-7095
                                    ok);
948 Thurallor-7095
                                CenterWindow(window);
949 Thurallor-7095
                                window.label:SetFont(Turbine.UI.Lotro.Font.Verdana14);
950 Thurallor-7095
                                window.label:SetText(window.label:GetText());
951 Thurallor-7095
                                window.buttons[ok].Click = function()
952 Thurallor-7095
                                    window:Close();
953 Thurallor-7095
                                end
954 Thurallor-7095
                                dropDown:SetText(string.gsub(info.condArgs.effect, "\"", ""));
955 22 Thurallor-7095
                            elseif (not args.Text) then
956 Thurallor-7095
                                return;
957 20 Thurallor-7095
                            else
958 Thurallor-7095
                                info.condArgs.effect = "\"" .. args.Text .. "\"";
959 Thurallor-7095
                                self:UpdateBar();
960 Thurallor-7095
                            end
961 Thurallor-7095
                        end
962 Thurallor-7095
                        dropDown:SetParent(self.slotProperties);
963 Thurallor-7095
                        local effect = info.condArgs.effect;
964 22 Thurallor-7095
                        if (effect == "nil") then
965 20 Thurallor-7095
                            effect = effectNames[2];
966 41 Thurallor-7095
                            dropDown:SetText(effect);
967 Thurallor-7095
                            dropDown:ItemChanged({Text = effect});
968 22 Thurallor-7095
                        else
969 Thurallor-7095
                            effect = string.gsub(effect, "\"", "")
970 41 Thurallor-7095
                            dropDown:SetText(effect);
971 20 Thurallor-7095
                        end
972 Thurallor-7095
                    end
973 Thurallor-7095
                end
974 111 Thurallor-7095
                if (info.condArgs.stance) then
975 Thurallor-7095
                    local stanceNames = L:GetSortedTexts("/SequenceEditor/Stance");
976 Thurallor-7095
                    local dropDown;
977 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, stanceNames);
978 Thurallor-7095
                    dropDown:SetExpandedWidth(math.max(500, slotTabCardWidth - 20));
979 Thurallor-7095
                    function dropDown.ItemChanged(ctl, args)
980 Thurallor-7095
                        local prevContext = L:SetContext("/SequenceEditor/Stance");
981 Thurallor-7095
                        local stance = L:GetItem(args.Text);
982 Thurallor-7095
                        info.condArgs.stance = tonumber(stance);
983 Thurallor-7095
                        self:UpdateBar();
984 Thurallor-7095
                    end
985 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
986 Thurallor-7095
                    local stance = info.condArgs.stance;
987 Thurallor-7095
                    dropDown:SetText(L:GetText("/SequenceEditor/Stance/" .. tostring(stance)));
988 Thurallor-7095
                end
989 20 Thurallor-7095
                if (info.condArgs.script) then
990 47 Thurallor-7095
                    top, self.scriptBox = AddTextBox(top + 2, info.condArgs.script, Turbine.UI.Color.White, true, self.settings.sequenceEditor.scriptBoxSize);
991 Thurallor-7095
                    self.scriptBox:SetZOrder(1);
992 Thurallor-7095
                    self.scriptBox:SetMultiline(true);
993 Thurallor-7095
                    self.scriptBox:SetTextAlignment(Turbine.UI.ContentAlignment.TopLeft);
994 Thurallor-7095
                    self.scriptBox:SetFont(Turbine.UI.Lotro.Font.Verdana12);
995 48 Thurallor-7095
                    self.scriptBox.prevText = info.condArgs.script;
996 20 Thurallor-7095
                    self.scriptBox:SetWantsUpdates(true);
997 47 Thurallor-7095
                    function self.scriptBox.Resized()
998 Thurallor-7095
                        self.settings.sequenceEditor.scriptBoxSize = {self.scriptBox:GetSize()};
999 Thurallor-7095
                        self:SaveSettings();
1000 Thurallor-7095
                        self:DisplaySlot(self.selectedSlot);
1001 Thurallor-7095
                    end
1002 20 Thurallor-7095
                    self.scriptBox.Update = function(sender)
1003 Thurallor-7095
                        local script = sender:GetText();
1004 Thurallor-7095
                        if (script ~= sender.prevText) then
1005 Thurallor-7095
                            local success, errorMsg = loadstring(script, "Slot " .. tostring(s));
1006 Thurallor-7095
                            if (success) then
1007 Thurallor-7095
                                self.scriptBox:SetBackColor(Turbine.UI.Color.Black);
1008 Thurallor-7095
                                info.condArgs.script = script;
1009 Thurallor-7095
                                self:UpdateBar();
1010 Thurallor-7095
                            else
1011 Thurallor-7095
                                self.scriptBox:SetBackColor(Turbine.UI.Color.Red);
1012 Thurallor-7095
                            end
1013 Thurallor-7095
                        end
1014 Thurallor-7095
                        sender.prevText = script;
1015 Thurallor-7095
                    end
1016 Thurallor-7095
                end
1017 Thurallor-7095
                if (info.condArgs.eqItemName) then
1018 Thurallor-7095
                    local function GetEquippableItems()
1019 Thurallor-7095
                        local hash = { [L:GetText("/SequenceEditor/AnyEqItem")] = true };
1020 Thurallor-7095
                        for container in values({ self.manager.player:GetBackpack(), self.manager.player:GetEquipment() }) do
1021 Thurallor-7095
                            for i = 1, container:GetSize(), 1 do
1022 Thurallor-7095
                                local item = container:GetItem(i);
1023 30 Thurallor-7095
                                if (item and (item:GetMaxStackSize() == 1)) then
1024 Thurallor-7095
                                    hash[item:GetName()] = true;
1025 20 Thurallor-7095
                                end
1026 Thurallor-7095
                            end
1027 Thurallor-7095
                        end
1028 Thurallor-7095
                        local items = {};
1029 Thurallor-7095
                        for key in sorted_keys(hash) do
1030 Thurallor-7095
                            table.insert(items, key);
1031 Thurallor-7095
                        end
1032 Thurallor-7095
                        return items;
1033 Thurallor-7095
                    end
1034 Thurallor-7095
                    local eqItemNames = GetEquippableItems();
1035 Thurallor-7095
                    local anyItem = L:GetText("/SequenceEditor/AnyEqItem");
1036 Thurallor-7095
                    local dropDown;
1037 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, eqItemNames);
1038 47 Thurallor-7095
                    dropDown:SetExpandedWidth(math.max(400, slotTabCardWidth - 20));
1039 20 Thurallor-7095
                    dropDown.ItemChanged = function(sender, args)
1040 Thurallor-7095
                        local anyItem = L:GetText("/SequenceEditor/AnyEqItem");
1041 Thurallor-7095
                        if (args.Text == anyItem) then
1042 Thurallor-7095
                            info.condArgs.eqItemName = "nil";
1043 Thurallor-7095
                        else
1044 Thurallor-7095
                            info.condArgs.eqItemName = "\"" .. args.Text .. "\"";
1045 Thurallor-7095
                        end
1046 Thurallor-7095
                        self:UpdateBar();
1047 Thurallor-7095
                    end
1048 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
1049 Thurallor-7095
                    if (info.condArgs.eqItemName == "nil") then
1050 Thurallor-7095
                        dropDown:SetText(anyItem);
1051 Thurallor-7095
                    else
1052 Thurallor-7095
                        local name = string.sub(info.condArgs.eqItemName, 2, -2);
1053 Thurallor-7095
                        dropDown:SetText(name);
1054 Thurallor-7095
                    end
1055 Thurallor-7095
                end
1056 Thurallor-7095
                if (info.condArgs.eqSlot) then
1057 Thurallor-7095
                    local prevContext = L:SetContext("/SequenceEditor/EquipmentSlots");
1058 Thurallor-7095
                    local eqSlotNames, localEqSlotNames, eqSlotValues = L:GetItems(), {}, {};
1059 Thurallor-7095
                    for slot in values(eqSlotNames) do
1060 Thurallor-7095
                        local text = L:GetText(slot);
1061 Thurallor-7095
                        table.insert(localEqSlotNames, text);
1062 Thurallor-7095
                        eqSlotValues[text] = tostring(Turbine.Gameplay.Equipment[slot]);
1063 Thurallor-7095
                    end
1064 Thurallor-7095
                    local anySlot = L:GetText("/SequenceEditor/AnyEqSlot");
1065 Thurallor-7095
                    eqSlotValues[anySlot] = "nil";
1066 Thurallor-7095
                    table.insert(localEqSlotNames, anySlot);
1067 Thurallor-7095
                    table.sort(localEqSlotNames);
1068 Thurallor-7095
                    local dropDown;
1069 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, localEqSlotNames);
1070 Thurallor-7095
                    dropDown.ItemChanged = function(sender, args)
1071 Thurallor-7095
                        info.condArgs.eqSlot = eqSlotValues[args.Text];
1072 Thurallor-7095
                        self:UpdateBar();
1073 Thurallor-7095
                    end
1074 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
1075 Thurallor-7095
                    if (info.condArgs.eqSlot == "nil") then
1076 Thurallor-7095
                        dropDown:SetText(anySlot);
1077 Thurallor-7095
                    else
1078 Thurallor-7095
                        local slotName = Search(Turbine.Gameplay.Equipment, tonumber(info.condArgs.eqSlot));
1079 Thurallor-7095
                        dropDown:SetText(L:GetText(slotName));
1080 Thurallor-7095
                    end
1081 Thurallor-7095
                    L:SetContext(prevContext);
1082 Thurallor-7095
                end
1083 Thurallor-7095
            end
1084 47 Thurallor-7095
 
1085 Thurallor-7095
            -- Evaluate the condition and display the current value
1086 Thurallor-7095
            local function GetValueStr()
1087 Thurallor-7095
                local sequence = self.bar.sequence;
1088 Thurallor-7095
                local slot = sequence:GetSlot(sequence:GetNewIndex(s));
1089 49 Thurallor-7095
                if (slot and slot.condFunc) then
1090 Thurallor-7095
                    local text = L:GetText("/SequenceEditor/False");
1091 Thurallor-7095
                    if (slot.condFunc(slot, self.manager.player)) then
1092 Thurallor-7095
                        text = L:GetText("/SequenceEditor/True");
1093 Thurallor-7095
                    end
1094 Thurallor-7095
                    return "(" .. text .. ")";
1095 47 Thurallor-7095
                end
1096 Thurallor-7095
            end
1097 Thurallor-7095
            if (info.condArgs and info.condArgs.script) then
1098 Thurallor-7095
                top, button = AddButton(top, 40, "â–º", Turbine.UI.Lotro.Font.Arial12);
1099 Thurallor-7095
                top, label = AddLabel(top, "", Turbine.UI.Color.Goldenrod);
1100 Thurallor-7095
                AddCallback(button, "Click", function()
1101 Thurallor-7095
                    label:SetText(GetValueStr());
1102 Thurallor-7095
                end);
1103 Thurallor-7095
                AddCallback(button, "MouseLeave", function()
1104 Thurallor-7095
                    label:SetText("");
1105 Thurallor-7095
                end);
1106 Thurallor-7095
            else
1107 Thurallor-7095
                top, label = AddLabel(top, "", Turbine.UI.Color.Goldenrod);
1108 Thurallor-7095
                label.Update = function()
1109 Thurallor-7095
                    label:SetText(GetValueStr());
1110 Thurallor-7095
                end
1111 Thurallor-7095
                label:SetWantsUpdates(true);
1112 Thurallor-7095
            end
1113 Thurallor-7095
 
1114 16 Thurallor-7095
        elseif (info.type == "Include") then
1115 Thurallor-7095
            top = top + 16; -- skip a line
1116 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/OtherSequence") .. ":", Turbine.UI.Color.Goldenrod);
1117 Thurallor-7095
            local function GetObjectTree()
1118 Thurallor-7095
                -- Get a list of all bar IDs.
1119 Thurallor-7095
                local objectIDs = self.manager:FindAllDescendentIDs(nil, true, false);
1120 Thurallor-7095
 
1121 Thurallor-7095
                -- Including self doesn't make sense, so prevent that.
1122 Thurallor-7095
                local foundSelf;
1123 Thurallor-7095
                for o = 1, #objectIDs, 1 do
1124 Thurallor-7095
                    local object = self.manager:GetObject(objectIDs[o]);
1125 Thurallor-7095
                    if (object == self.bar) then
1126 Thurallor-7095
                        foundSelf = o;
1127 Thurallor-7095
                    end
1128 Thurallor-7095
                end
1129 Thurallor-7095
                if (foundSelf) then
1130 Thurallor-7095
                    table.remove(objectIDs, foundSelf);
1131 Thurallor-7095
                end
1132 Thurallor-7095
 
1133 Thurallor-7095
                -- Add nonempty groups.
1134 17 Thurallor-7095
                local groupIDs = {};
1135 Thurallor-7095
                for o = 1, #objectIDs, 1 do
1136 Thurallor-7095
                    local objectID = objectIDs[o];
1137 Thurallor-7095
                    local object = self.manager:GetObject(objectID);
1138 Thurallor-7095
                    while (object.parent) do
1139 Thurallor-7095
                        object = object.parent;
1140 Thurallor-7095
                        objectID = object:GetID();
1141 Thurallor-7095
                        if (objectID) then
1142 Thurallor-7095
                            groupIDs[objectID] = 1;
1143 16 Thurallor-7095
                        end
1144 Thurallor-7095
                    end
1145 17 Thurallor-7095
                end
1146 Thurallor-7095
                for groupID in keys(groupIDs) do
1147 Thurallor-7095
                    table.insert(objectIDs, groupID);
1148 Thurallor-7095
                end
1149 16 Thurallor-7095
 
1150 Thurallor-7095
                -- Create item list for PullDownMenu.
1151 Thurallor-7095
                local items = {};
1152 Thurallor-7095
                for o = 1, #objectIDs, 1 do
1153 Thurallor-7095
                    local objectID = objectIDs[o];
1154 Thurallor-7095
                    local object = self.manager:GetObject(objectID);
1155 Thurallor-7095
                    local parentID = nil;
1156 Thurallor-7095
                    if (object.parent) then
1157 Thurallor-7095
                        parentID = object.parent:GetID();
1158 Thurallor-7095
                    end
1159 Thurallor-7095
                    table.insert(items, { objectID, object:GetName(), parentID });
1160 Thurallor-7095
                end
1161 Thurallor-7095
                return items;
1162 Thurallor-7095
            end
1163 Thurallor-7095
            local pullDown;
1164 Thurallor-7095
            top, pullDown = AddPullDown(top, GetObjectTree(), info.include);
1165 Thurallor-7095
            pullDown.SelectionChanged = function(sender, id)
1166 Thurallor-7095
                info.include = id;
1167 Thurallor-7095
                self:UpdateBar();
1168 20 Thurallor-7095
                self:SelectSlot(s);
1169 16 Thurallor-7095
            end
1170 20 Thurallor-7095
            AddCallback(pullDown, "MouseClick", function(sender, args)
1171 Thurallor-7095
                -- Right-click displays the bar menu.
1172 Thurallor-7095
                if (args.Button == Turbine.UI.MouseButton.Right) then
1173 Thurallor-7095
                    if (info.include) then
1174 Thurallor-7095
                        local bar = self.manager.objects[info.include];
1175 Thurallor-7095
                        if (bar) then
1176 Thurallor-7095
                            bar:ShowSettingsMenu();
1177 Thurallor-7095
                        end
1178 Thurallor-7095
                    end
1179 Thurallor-7095
                end
1180 Thurallor-7095
            end);
1181 6 Thurallor-7095
 
1182 20 Thurallor-7095
            -- Add the "unlink" button if a sequence is selected.
1183 Thurallor-7095
            if (info.include) then
1184 Thurallor-7095
                local button;
1185 Thurallor-7095
                local text, width = L:GetText("/SequenceEditor/Unlink"), L:GetNumber("/SequenceEditor/UnlinkButtonWidth");
1186 Thurallor-7095
                top, button = AddButton(top, width, text);
1187 Thurallor-7095
                AddCallback(button, "Click", function()
1188 Thurallor-7095
                    self:UnlinkIncludedSequence(s);
1189 Thurallor-7095
                end);
1190 Thurallor-7095
            end
1191 Thurallor-7095
        end
1192 Thurallor-7095
 
1193 16 Thurallor-7095
        -- Allow the user to specify whether activation is click-based or automatic.
1194 Thurallor-7095
        if (info.type ~= "Include") then
1195 6 Thurallor-7095
            top = top + 16; -- skip a line
1196 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/Activation") .. ":", Turbine.UI.Color.Goldenrod);
1197 Thurallor-7095
            local button1, button2;
1198 Thurallor-7095
            top, button1 = AddRadioButton(top, L:GetText("/SequenceEditor/WithLeftClick"), Turbine.UI.Color.DarkGoldenrod, (not info.automatic));
1199 Thurallor-7095
            top, button2 = AddRadioButton(top, L:GetText("/SequenceEditor/Automatic"), Turbine.UI.Color.DarkGoldenrod, info.automatic);
1200 Thurallor-7095
            Thurallor.UI.RadioButton.LinkPeers({button1, button2});
1201 Thurallor-7095
            button1.Clicked = function()
1202 Thurallor-7095
                info.automatic = nil;
1203 16 Thurallor-7095
                self:UpdateBar();
1204 6 Thurallor-7095
            end
1205 Thurallor-7095
            button2.Clicked = function()
1206 Thurallor-7095
                info.automatic = true;
1207 16 Thurallor-7095
                self:UpdateBar();
1208 6 Thurallor-7095
            end
1209 2 Thurallor-7095
        end
1210 Thurallor-7095
    end
1211 Thurallor-7095
 
1212 136 Thurallor-7095
    -- Allow the user to specify that advancement should not occur until there is a target
1213 Thurallor-7095
    if ((info.type == Turbine.UI.Lotro.ShortcutType.Skill) or (info.type == "SelectTarget")) then
1214 Thurallor-7095
        top = top + 16; -- skip a line
1215 Thurallor-7095
        local checkbox;
1216 Thurallor-7095
        top, checkbox = AddCheckBox(top, L:GetText("/SequenceEditor/RequireTarget"), Turbine.UI.Color.Goldenrod, info.requireTarget);
1217 Thurallor-7095
 
1218 Thurallor-7095
        checkbox.CheckedChanged = function(chkbx)
1219 Thurallor-7095
            if (chkbx:IsChecked()) then
1220 Thurallor-7095
                info.requireTarget = true;
1221 Thurallor-7095
            else
1222 Thurallor-7095
                info.requireTarget = nil;
1223 Thurallor-7095
            end
1224 Thurallor-7095
            self:UpdateBar();
1225 Thurallor-7095
        end
1226 Thurallor-7095
    end
1227 Thurallor-7095
 
1228 34 Thurallor-7095
    -- Allow the user to modify slot appearance (text, icon)
1229 15 Thurallor-7095
    top = top + 16; -- skip a line
1230 34 Thurallor-7095
    local button;
1231 Thurallor-7095
    top, button = AddSection(top, L:GetText("/SequenceEditor/Appearance"), Turbine.UI.Color.Goldenrod, self.appearanceExpanded);
1232 Thurallor-7095
    function button.ExpandedChanged(sender, expanded)
1233 Thurallor-7095
        self.appearanceExpanded = expanded;
1234 Thurallor-7095
        self:DisplaySlot(self.selectedSlot);
1235 Thurallor-7095
    end
1236 Thurallor-7095
 
1237 Thurallor-7095
    if (self.appearanceExpanded) then
1238 Thurallor-7095
 
1239 Thurallor-7095
        -- Allow the user to optionally overlay some text
1240 Thurallor-7095
        top = top + 16; -- skip a line
1241 Thurallor-7095
        top = AddLabel(top, L:GetText("/SequenceEditor/TextOverlay") .. ":", Turbine.UI.Color.Goldenrod);
1242 Thurallor-7095
        local textBox;
1243 Thurallor-7095
        top, textBox = AddTextBox(top, info.textOverlay, Turbine.UI.Color.White);
1244 Thurallor-7095
        textBox:SetFont(Turbine.UI.Lotro.Font.Verdana12);
1245 Thurallor-7095
        textBox.TextChanged = function(sender, args)
1246 Thurallor-7095
            local text = sender:GetText();
1247 Thurallor-7095
            if (text == "") then
1248 Thurallor-7095
                text = nil;
1249 Thurallor-7095
            end
1250 Thurallor-7095
            info.textOverlay = text;
1251 Thurallor-7095
            UpdateIcon();
1252 Thurallor-7095
            self:UpdateBar();
1253 7 Thurallor-7095
        end
1254 34 Thurallor-7095
 
1255 Thurallor-7095
        -- Allow the user to optionally change the icon
1256 Thurallor-7095
        top = top + 16; -- skip a line
1257 Thurallor-7095
        top = AddLabel(top, L:GetText("/SequenceEditor/ChangeIcon") .. ":", Turbine.UI.Color.Goldenrod);
1258 Thurallor-7095
        local button1, button2, slider2, button3, slider3, button4, textbox;
1259 Thurallor-7095
        top, button1 = AddRadioButton(top, L:GetText("/SequenceEditor/DefaultIcon"), Turbine.UI.Color.DarkGoldenrod);
1260 Thurallor-7095
        top, button2 = AddRadioButton(top, L:GetText("/SequenceEditor/BlankIcon"), Turbine.UI.Color.DarkGoldenrod);
1261 Thurallor-7095
        top, slider2 = AddSlider(top, 1, #resources.BlankIcons, 1);
1262 Thurallor-7095
        slider2:SetLeft(12);
1263 Thurallor-7095
        slider2:SetWidth(slider2:GetWidth() - 12);
1264 Thurallor-7095
        top, button3 = AddRadioButton(top, L:GetText("/SequenceEditor/SkillIcon"), Turbine.UI.Color.DarkGoldenrod);
1265 Thurallor-7095
        local skillsInfo = Thurallor.Utils.Watcher.GetSkillsInfo();
1266 Thurallor-7095
        local gambitsInfo = Thurallor.Utils.Watcher.GetGambitsInfo();
1267 Thurallor-7095
        self.skillIcons = {};
1268 Thurallor-7095
        for id in sorted_keys(skillsInfo.byIcon) do
1269 Thurallor-7095
            table.insert(self.skillIcons, id);
1270 Thurallor-7095
        end
1271 Thurallor-7095
        for id in sorted_keys(gambitsInfo.byIcon) do
1272 Thurallor-7095
            table.insert(self.skillIcons, id);
1273 Thurallor-7095
        end
1274 Thurallor-7095
        top, slider3 = AddSlider(top, 1, #self.skillIcons, 1);
1275 Thurallor-7095
        slider3:SetLeft(12);
1276 Thurallor-7095
        slider3:SetWidth(slider3:GetWidth() - 12);
1277 Thurallor-7095
        top, button4 = AddRadioButton(top, L:GetText("/SequenceEditor/SpecificIconID"), Turbine.UI.Color.DarkGoldenrod);
1278 Thurallor-7095
        top, textBox = AddTextBox(top, "", Turbine.UI.Color.White);
1279 47 Thurallor-7095
        textBox:SetFont(Turbine.UI.Lotro.Font.Verdana12);
1280 34 Thurallor-7095
        textBox:SetLeft(12);
1281 Thurallor-7095
        textBox:SetWidth(textBox:GetWidth() - 12);
1282 Thurallor-7095
        if (info.altIcon == nil) then
1283 Thurallor-7095
            button1:SetChecked(true);
1284 Thurallor-7095
        else
1285 Thurallor-7095
            local blankIcon = Search(resources.BlankIcons, info.altIcon);
1286 Thurallor-7095
            if (blankIcon) then
1287 Thurallor-7095
                button2:SetChecked(true);
1288 Thurallor-7095
                slider2:SetValue(blankIcon);
1289 Thurallor-7095
            else
1290 Thurallor-7095
                local skillIcon = Search(self.skillIcons, info.altIcon);
1291 Thurallor-7095
                if (skillIcon) then
1292 Thurallor-7095
                    button3:SetChecked(true);
1293 Thurallor-7095
                    slider3:SetValue(skillIcon);
1294 Thurallor-7095
                else
1295 Thurallor-7095
                    button4:SetChecked(true);
1296 Thurallor-7095
                end
1297 Thurallor-7095
            end
1298 Thurallor-7095
        end
1299 Thurallor-7095
        local function UpdateIconID()
1300 Thurallor-7095
            local id = info.altIcon;
1301 Thurallor-7095
            if (id == nil) then
1302 Thurallor-7095
                id = info.background;
1303 Thurallor-7095
            end
1304 Thurallor-7095
            if (type(id) == "number") then
1305 Thurallor-7095
                textBox:SetText(string.format("0x%8.8X", id));
1306 Thurallor-7095
            elseif (type(id) == "string") then
1307 Thurallor-7095
                textBox:SetText(id);
1308 Thurallor-7095
            else
1309 Thurallor-7095
                -- Get icon ID from quickslot
1310 Thurallor-7095
 
1311 Thurallor-7095
            end
1312 Thurallor-7095
        end
1313 Thurallor-7095
        UpdateIconID();
1314 Thurallor-7095
        Thurallor.UI.RadioButton.LinkPeers({button1, button2, button3, button4});
1315 Thurallor-7095
        function button1.Clicked()
1316 Thurallor-7095
            info.altIcon = nil;
1317 Thurallor-7095
            UpdateIcon();
1318 Thurallor-7095
            UpdateIconID();
1319 Thurallor-7095
            self:UpdateBar();
1320 Thurallor-7095
        end
1321 Thurallor-7095
        function button2.Clicked()
1322 Thurallor-7095
            slider2:ValueChanged();
1323 Thurallor-7095
        end
1324 Thurallor-7095
        function button3.Clicked()
1325 Thurallor-7095
            slider3:ValueChanged();
1326 Thurallor-7095
        end
1327 Thurallor-7095
        function button4.Clicked()
1328 Thurallor-7095
            textBox:TextChanged();
1329 Thurallor-7095
        end
1330 Thurallor-7095
        slider2.ValueChanged = function(sender)
1331 Thurallor-7095
            if (not button2:IsChecked()) then
1332 Thurallor-7095
                button2:MouseClick();
1333 Thurallor-7095
                return;
1334 Thurallor-7095
            end
1335 Thurallor-7095
            info.altIcon = resources.BlankIcons[sender:GetValue()];
1336 Thurallor-7095
            UpdateIcon();
1337 Thurallor-7095
            UpdateIconID();
1338 Thurallor-7095
            self:UpdateBar();
1339 Thurallor-7095
            self.settings.sequenceEditor.defaultIcon = info.altIcon;
1340 Thurallor-7095
        end
1341 Thurallor-7095
        slider3.ValueChanged = function(sender)
1342 Thurallor-7095
            if (not button3:IsChecked()) then
1343 Thurallor-7095
                button3:MouseClick();
1344 Thurallor-7095
                return;
1345 Thurallor-7095
            end
1346 Thurallor-7095
            info.altIcon = self.skillIcons[sender:GetValue()];
1347 Thurallor-7095
            UpdateIcon();
1348 Thurallor-7095
            UpdateIconID();
1349 Thurallor-7095
            self:UpdateBar();
1350 Thurallor-7095
            self.settings.sequenceEditor.defaultIcon = info.altIcon;
1351 Thurallor-7095
        end
1352 Thurallor-7095
        function textBox.FocusGained()
1353 Thurallor-7095
            button4:MouseClick();
1354 Thurallor-7095
        end
1355 Thurallor-7095
        textBox.TextChanged = function(sender)
1356 Thurallor-7095
            if (not button4:IsChecked()) then
1357 Thurallor-7095
                return;
1358 Thurallor-7095
            end
1359 Thurallor-7095
            local id = sender:GetText();
1360 Thurallor-7095
            if (tonumber(id) ~= nil) then
1361 Thurallor-7095
                id = tonumber(id);
1362 Thurallor-7095
            end
1363 Thurallor-7095
            local valid = pcall(GetAssetSize, id);
1364 Thurallor-7095
            if (valid) then
1365 Thurallor-7095
                textBox:SetForeColor(Turbine.UI.Color.White);
1366 Thurallor-7095
                info.altIcon = id;
1367 Thurallor-7095
                UpdateIcon();
1368 Thurallor-7095
                self:UpdateBar();
1369 Thurallor-7095
            else
1370 Thurallor-7095
                textBox:SetForeColor(Turbine.UI.Color.Red);
1371 Thurallor-7095
            end
1372 Thurallor-7095
        end
1373 2 Thurallor-7095
    end
1374 Thurallor-7095
 
1375 Thurallor-7095
    self.slotProperties:SetHeight(top);
1376 15 Thurallor-7095
    self:SetMinimumHeight(top + 110);
1377 2 Thurallor-7095
end
1378 Thurallor-7095
 
1379 13 Thurallor-7095
function SequenceEditor:FindSlotAtPosition(x, y, drawCaret)
1380 7 Thurallor-7095
    local originX, originY = self.slotPanel:GetParent():PointToScreen(self.slotPanel:GetPosition());
1381 13 Thurallor-7095
    local relX, relY = x - originX, y - originY + 3;
1382 Thurallor-7095
    local posX, posY = 1 + math.floor(relX / self.slotSize + 0.5), 1 + math.floor(relY / self.slotSize);
1383 7 Thurallor-7095
    local s = nil;
1384 13 Thurallor-7095
    if ((posX >= 1) and (posX <= self.slotsWide + 1) and (posY >= 1) and (posY <= self.slotsHigh)) then
1385 7 Thurallor-7095
        s = ((posY - 1) * self.slotsWide) + posX;
1386 Thurallor-7095
    end
1387 13 Thurallor-7095
    if ((posX == self.slotsWide + 1) and (posY == self.slotsHigh)) then
1388 Thurallor-7095
        s = nil;
1389 Thurallor-7095
    end
1390 7 Thurallor-7095
 
1391 Thurallor-7095
    -- Update caret position.
1392 Thurallor-7095
    if ((not drawCaret) or (not s)) then
1393 Thurallor-7095
        -- Hide carets in all Sequence Editors
1394 Thurallor-7095
        for editor in keys(SequenceEditor.instances) do
1395 Thurallor-7095
            if (editor.caret) then
1396 Thurallor-7095
                editor.caret:SetParent(nil);
1397 Thurallor-7095
                editor.caret = nil;
1398 Thurallor-7095
            end
1399 Thurallor-7095
        end
1400 Thurallor-7095
    else
1401 Thurallor-7095
        if (not self.caret) then
1402 Thurallor-7095
            self.caret = Turbine.UI.Control();
1403 Thurallor-7095
            self.caret:SetParent(self.slotPanel);
1404 Thurallor-7095
            self.caret:SetBackground(resources.Icon.Caret);
1405 Thurallor-7095
            self.caret:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
1406 Thurallor-7095
            self.caret:SetSize(3, 36)
1407 Thurallor-7095
        end
1408 Thurallor-7095
        self.caret:SetPosition((posX - 1) * self.slotSize, (posY - 1) * self.slotSize);
1409 Thurallor-7095
    end
1410 Thurallor-7095
 
1411 Thurallor-7095
    return s;
1412 Thurallor-7095
end
1413 Thurallor-7095
 
1414 13 Thurallor-7095
function SequenceEditor:FindForeignSlotAtPosition(x, y, drawCaret)
1415 7 Thurallor-7095
 
1416 Thurallor-7095
    -- Find the frontmost SequenceEditor under the mouse cursor
1417 Thurallor-7095
    local frontEditor = self;
1418 Thurallor-7095
    local maxZ = -2147483648;
1419 Thurallor-7095
    for editor in keys(SequenceEditor.instances) do
1420 Thurallor-7095
        if (editor ~= self) then
1421 Thurallor-7095
            local left, top = editor:GetPosition();
1422 Thurallor-7095
            local width, height = editor:GetSize();
1423 13 Thurallor-7095
            if ((x >= left) and (x <= left + width) and (y >= top) and (y <= top + height)) then
1424 7 Thurallor-7095
                if (editor:GetZOrder() >= maxZ) then
1425 Thurallor-7095
                    frontEditor = editor;
1426 Thurallor-7095
                    maxZ = editor:GetZOrder();
1427 Thurallor-7095
                end
1428 Thurallor-7095
            end
1429 Thurallor-7095
        end
1430 Thurallor-7095
    end
1431 Thurallor-7095
 
1432 13 Thurallor-7095
    return frontEditor, frontEditor:FindSlotAtPosition(x, y, drawCaret);
1433 7 Thurallor-7095
end
1434 Thurallor-7095
 
1435 13 Thurallor-7095
function SequenceEditor:BuildSlot(slot, parent, object, left, top)
1436 Thurallor-7095
--Puts("BuildSlot(" .. tostring(slot) .. ", " .. tostring(parent) .. ", " .. tostring(object) .. ", " .. tostring(left) .. ", " .. tostring(top));
1437 2 Thurallor-7095
 
1438 Thurallor-7095
    -- Get slot info, or initialize to default
1439 13 Thurallor-7095
    local info = self.settings.sequenceItemInfo[slot];
1440 Thurallor-7095
    if (object) then
1441 Thurallor-7095
        -- Reuse the existing object
1442 Thurallor-7095
        object:SetParent(parent);
1443 Thurallor-7095
        object:SetInfo(info);
1444 Thurallor-7095
        object:SetPosition(left, top);
1445 Thurallor-7095
        object:SetNumLabel(slot);
1446 Thurallor-7095
        return object;
1447 2 Thurallor-7095
    end
1448 Thurallor-7095
 
1449 13 Thurallor-7095
    -- Need to create a new object
1450 Thurallor-7095
    object = Slot(info);
1451 Thurallor-7095
    object:SetPosition(left, top);
1452 Thurallor-7095
    object:SetNumLabel(slot);
1453 2 Thurallor-7095
    object:SetParent(parent);
1454 13 Thurallor-7095
    object:SetActionEnabled(false);
1455 Thurallor-7095
    object:SetAllowDrop(true);
1456 Thurallor-7095
    object:SetDraggable(true);
1457 2 Thurallor-7095
 
1458 7 Thurallor-7095
    -- Desired mouse behaviors:
1459 Thurallor-7095
    --   Left-click selects the slot and shows its properties in the "Slot" tab.
1460 Thurallor-7095
    --   Right-click displays the settings menu.
1461 Thurallor-7095
    --   Left-button-drag initiates a drag-and-drop (move) operation.
1462 2 Thurallor-7095
 
1463 13 Thurallor-7095
    object.ShortcutChanged = function(sender, shortcutType, shortcutData)
1464 Thurallor-7095
        local s = sender:GetNumLabel();
1465 2 Thurallor-7095
        self:ExtendSequenceTo(s);
1466 13 Thurallor-7095
        local info = sender:GetInfo();
1467 Thurallor-7095
        self.settings.sequenceItemInfo[s] = info;
1468 Thurallor-7095
 
1469 Thurallor-7095
        if (shortcutType == Turbine.UI.Lotro.ShortcutType.Alias) then
1470 7 Thurallor-7095
            info.textOverlay = string.gsub(info.Data, "^/", "");
1471 Thurallor-7095
            info.textOverlay = string.gsub(info.textOverlay, "%s.*$", "");
1472 Thurallor-7095
            info.background = self.settings.sequenceEditor.defaultIcon;
1473 13 Thurallor-7095
            sender:SetInfo(info);
1474 7 Thurallor-7095
        end
1475 13 Thurallor-7095
 
1476 16 Thurallor-7095
        self:UpdateBar();
1477 122 Thurallor-7095
        self:Redraw();
1478 2 Thurallor-7095
        self:SelectSlot(s);
1479 Thurallor-7095
    end
1480 Thurallor-7095
 
1481 13 Thurallor-7095
    object.MouseClick = function(sender, args)
1482 2 Thurallor-7095
        -- Left-click selects the slot and shows its properties in the "Slot" tab.
1483 Thurallor-7095
        if (args.Button == Turbine.UI.MouseButton.Left) then
1484 13 Thurallor-7095
            self:SelectSlot(sender:GetNumLabel());
1485 2 Thurallor-7095
 
1486 Thurallor-7095
        -- Right-click displays the settings menu.
1487 Thurallor-7095
        elseif (args.Button == Turbine.UI.MouseButton.Right) then
1488 13 Thurallor-7095
            self.clickedItem = sender:GetNumLabel();
1489 2 Thurallor-7095
            self:ShowContextMenu();
1490 Thurallor-7095
        end
1491 Thurallor-7095
    end
1492 Thurallor-7095
 
1493 13 Thurallor-7095
    object.DropPositionValid = function(sender, left, top)
1494 Thurallor-7095
        local s = sender:GetNumLabel();
1495 Thurallor-7095
 
1496 Thurallor-7095
        -- Draw a "caret" showing where the slot will be inserted.
1497 Thurallor-7095
        local editor = self;
1498 Thurallor-7095
        local newSlot = self:FindSlotAtPosition(left, top, true);
1499 Thurallor-7095
        if (not newSlot) then
1500 Thurallor-7095
            editor, newSlot = self:FindForeignSlotAtPosition(left, top, true);
1501 7 Thurallor-7095
        end
1502 13 Thurallor-7095
        if ((editor == self) and ((newSlot == s) or (newSlot == s + 1))) then
1503 Thurallor-7095
            self:FindSlotAtPosition(0, 0, false); -- hide caret if returning to the same position
1504 Thurallor-7095
        end
1505 Thurallor-7095
        return newSlot; -- if newSlot is nil, a red "X" will be shown
1506 7 Thurallor-7095
    end
1507 Thurallor-7095
 
1508 13 Thurallor-7095
    object.DragDropComplete = function(sender, left, top)
1509 Thurallor-7095
        local s = sender:GetNumLabel();
1510 2 Thurallor-7095
 
1511 13 Thurallor-7095
        -- Select destination slot.  Hide the caret.
1512 Thurallor-7095
        local editor = self;
1513 Thurallor-7095
        local newSlot = self:FindSlotAtPosition(left, top, false);
1514 Thurallor-7095
        if (not newSlot) then
1515 Thurallor-7095
            editor, newSlot = self:FindForeignSlotAtPosition(left, top, false);
1516 Thurallor-7095
        end
1517 Thurallor-7095
 
1518 Thurallor-7095
        -- Do the move operation, and redraw.
1519 Thurallor-7095
        if (newSlot and (editor ~= self)) then
1520 Thurallor-7095
            editor:InsertSlot(newSlot, self.settings.sequenceItemInfo[s]);
1521 Thurallor-7095
            self:DeleteSlot(s);
1522 Thurallor-7095
        elseif (newSlot and (newSlot ~= s) and (newSlot ~= s + 1)) then
1523 Thurallor-7095
            self:MoveSlot(s, newSlot);
1524 Thurallor-7095
        else
1525 Thurallor-7095
            self:Redraw();
1526 Thurallor-7095
        end
1527 Thurallor-7095
    end
1528 Thurallor-7095
 
1529 2 Thurallor-7095
    return object;
1530 Thurallor-7095
end
1531 Thurallor-7095
 
1532 7 Thurallor-7095
function SequenceEditor:RebuildSlot(s, x, y, alreadyDisplaying)
1533 2 Thurallor-7095
    local oldObject = self.sequenceItems[s];
1534 Thurallor-7095
 
1535 Thurallor-7095
    -- If x and y aren't specified, then presumably the object has already been positioned previously
1536 Thurallor-7095
    if (x == nil) then
1537 Thurallor-7095
        x = oldObject.x;
1538 Thurallor-7095
        y = oldObject.y;
1539 Thurallor-7095
    end
1540 Thurallor-7095
    local left, top = self:GetSlotPosition(x, y);
1541 Thurallor-7095
 
1542 Thurallor-7095
    local newObject = self:BuildSlot(s, self.slotPanel, oldObject, left, top);
1543 Thurallor-7095
    newObject.x = x;
1544 Thurallor-7095
    newObject.y = y;
1545 Thurallor-7095
    self.sequenceItems[s] = newObject;
1546 Thurallor-7095
 
1547 7 Thurallor-7095
    if (not alreadyDisplaying and (self.selectedSlot == s)) then
1548 2 Thurallor-7095
        self:DisplaySlot(s);
1549 Thurallor-7095
    end
1550 Thurallor-7095
end
1551 Thurallor-7095
 
1552 Thurallor-7095
function SequenceEditor:SelectSlot(s)
1553 13 Thurallor-7095
--Puts("SelectSlot(" .. tostring(s) .. "): self.selectedSlot = " .. tostring(self.selectedSlot));
1554 2 Thurallor-7095
    if (self.selectedSlot) then
1555 13 Thurallor-7095
        local object = self.sequenceItems[self.selectedSlot];
1556 Thurallor-7095
        object:SetSelected(false);
1557 Thurallor-7095
        local info = self.settings.sequenceItemInfo[self.selectedSlot];
1558 Thurallor-7095
        if (info and (info.class == "Turbine.UI.Lotro.Quickslot") and (not info.type)) then
1559 2 Thurallor-7095
            -- Delete empty shortcut
1560 13 Thurallor-7095
            info.class = nil;
1561 2 Thurallor-7095
        end
1562 Thurallor-7095
    end
1563 16 Thurallor-7095
    for o = 1, #self.relatedSlots, 1 do
1564 Thurallor-7095
        local otherSlot, otherObject = unpack(self.relatedSlots[o]);
1565 Thurallor-7095
        otherObject:SetSelected(nil);
1566 Thurallor-7095
        self.relatedSlots[o] = nil;
1567 Thurallor-7095
    end
1568 2 Thurallor-7095
    if (s ~= nil) then
1569 7 Thurallor-7095
        local info = self.settings.sequenceItemInfo[s];
1570 13 Thurallor-7095
        if ((not info) or (not info.class)) then
1571 7 Thurallor-7095
            s = nil;
1572 Thurallor-7095
        else
1573 13 Thurallor-7095
            local object = self.sequenceItems[s];
1574 Thurallor-7095
            object:SetSelected(true);
1575 16 Thurallor-7095
            local sequence = self.bar:GetSequence();
1576 Thurallor-7095
            local barObject = sequence:GetSlot(sequence:GetNewIndex(s));
1577 Thurallor-7095
            if (barObject) then
1578 Thurallor-7095
                for otherSlot, _ in pairs({ifSlot = 1; elseSlot = 1; endIfSlot = 1}) do
1579 Thurallor-7095
                    if (barObject[otherSlot]) then
1580 Thurallor-7095
                        local otherObject = self.sequenceItems[sequence:GetOldIndex(barObject[otherSlot])];
1581 Thurallor-7095
                        otherObject:SetSelected(true, Turbine.UI.Color.Yellow);
1582 Thurallor-7095
                        table.insert(self.relatedSlots, {otherSlot, otherObject});
1583 Thurallor-7095
                    end
1584 Thurallor-7095
                end
1585 Thurallor-7095
            end
1586 7 Thurallor-7095
        end
1587 2 Thurallor-7095
    end
1588 Thurallor-7095
    self.selectedSlot = s;
1589 Thurallor-7095
    self:DisplaySlot(s);
1590 Thurallor-7095
end
1591 Thurallor-7095
 
1592 Thurallor-7095
function SequenceEditor:GetSlotPosition(x, y)
1593 Thurallor-7095
    local left = (x - 1) * (self.settings.slotSize + self.settings.slotSpacing) - self.settings.slotSpacing;
1594 Thurallor-7095
    local top = (y - 1) * (self.settings.slotSize + self.settings.slotSpacing) - self.settings.slotSpacing;
1595 Thurallor-7095
    return left, top;
1596 Thurallor-7095
end
1597 Thurallor-7095
 
1598 Thurallor-7095
function SequenceEditor:Closing()
1599 7 Thurallor-7095
    SequenceEditor.instances[self] = nil;
1600 2 Thurallor-7095
    self:DeleteEmptyTrailingSlots();
1601 16 Thurallor-7095
    self:UpdateBar();
1602 20 Thurallor-7095
    if (self.ItemMovedCallback) then
1603 Thurallor-7095
        RemoveCallback(Thurallor.Utils.Watcher, "ItemMoved", self.ItemMovedCallback);
1604 Thurallor-7095
        self.ItemMovedCallback = nil;
1605 Thurallor-7095
    end
1606 2 Thurallor-7095
end
1607 Thurallor-7095
 
1608 Thurallor-7095
function SequenceEditor:Close()
1609 Thurallor-7095
    Turbine.UI.Lotro.Window.Close(self);
1610 Thurallor-7095
end
1611 Thurallor-7095
 
1612 Thurallor-7095
function SequenceEditor:ShowContextMenu()
1613 Thurallor-7095
    -- Build the settings menu.
1614 18 Thurallor-7095
    self.settingsMenu = Turbine.UI.ContextMenu();
1615 2 Thurallor-7095
    local prevContext = L:SetContext("/SequenceEditor/RightClickMenu");
1616 Thurallor-7095
    self:AddSettingsMenuItem(self.settingsMenu, "Root", false);
1617 Thurallor-7095
    L:SetContext(prevContext);
1618 Thurallor-7095
    self.settingsMenu:ShowMenu();
1619 Thurallor-7095
end
1620 Thurallor-7095
 
1621 Thurallor-7095
function SequenceEditor:AddSettingsMenuItem(parent, itemName)
1622 Thurallor-7095
    local item = Turbine.UI.MenuItem(L:GetText(itemName), true, false);
1623 Thurallor-7095
    parent:GetItems():Add(item);
1624 Thurallor-7095
 
1625 Thurallor-7095
    if (itemName == "Root") then
1626 Thurallor-7095
        parent:GetItems():Clear();
1627 34 Thurallor-7095
        self:AddSettingsMenuItem(parent, "CreateSpecialSlot");
1628 Thurallor-7095
        self:AddSettingsMenuItem(parent, "InsertEmptySlot");
1629 7 Thurallor-7095
        self:AddSettingsMenuItem(parent, "CloneSlot");
1630 2 Thurallor-7095
        self:AddSettingsMenuItem(parent, "DeleteSlot");
1631 7 Thurallor-7095
    elseif (itemName == "CloneSlot") then
1632 121 Thurallor-7095
        item.Click = function()
1633 7 Thurallor-7095
            self:CloneSlot(self.clickedItem);
1634 Thurallor-7095
        end
1635 2 Thurallor-7095
    elseif (itemName == "InsertEmptySlot") then
1636 121 Thurallor-7095
        item.Click = function()
1637 2 Thurallor-7095
            self:InsertEmptySlot(self.clickedItem);
1638 Thurallor-7095
        end
1639 Thurallor-7095
    elseif (itemName == ("DeleteSlot")) then
1640 121 Thurallor-7095
        item.Click = function()
1641 2 Thurallor-7095
            self:DeleteSlot(self.clickedItem);
1642 Thurallor-7095
        end
1643 Thurallor-7095
    elseif (itemName == "CreateSpecialSlot") then
1644 Thurallor-7095
        local prevContext = L:SetContext("SpecialSlotMenu");
1645 34 Thurallor-7095
        local texts = L:GetSortedTexts();
1646 Thurallor-7095
        for i = 1, #texts, 1 do
1647 Thurallor-7095
            self:AddSettingsMenuItem(item, L:GetItem(texts[i]));
1648 Thurallor-7095
        end
1649 2 Thurallor-7095
        L:SetContext(prevContext);
1650 6 Thurallor-7095
    elseif (string.find("StopAnimating|GenerateEvent|SetUnequipDestination", itemName)) then
1651 121 Thurallor-7095
        item.Click = function()
1652 2 Thurallor-7095
            self:CreateCommandSlot(self.clickedItem, itemName, item:GetText());
1653 Thurallor-7095
        end
1654 7 Thurallor-7095
    elseif (itemName == "ChatCommand") then
1655 Thurallor-7095
        local commands = Turbine.Shell.GetCommands();
1656 Thurallor-7095
        local index = math.random(#commands);
1657 121 Thurallor-7095
        item.Click = function()
1658 7 Thurallor-7095
            self:CreateAliasSlot(self.clickedItem, "/" .. commands[index]);
1659 Thurallor-7095
        end
1660 2 Thurallor-7095
    elseif (itemName == "RemoveEquipment") then
1661 121 Thurallor-7095
        item.Click = function()
1662 6 Thurallor-7095
            self:CreateRemovalSlot(self.clickedItem, "Gloves");
1663 2 Thurallor-7095
        end
1664 16 Thurallor-7095
    elseif ((itemName == "IfThen") or (itemName == "IfThenElse")) then
1665 121 Thurallor-7095
        item.Click = function()
1666 16 Thurallor-7095
            self:CreateConditional(self.clickedItem, itemName);
1667 Thurallor-7095
        end
1668 Thurallor-7095
    elseif (itemName == "Include") then
1669 121 Thurallor-7095
        item.Click = function()
1670 16 Thurallor-7095
            self:CreateIncludeSlot(self.clickedItem);
1671 Thurallor-7095
        end
1672 34 Thurallor-7095
    elseif (itemName == "Delay") then
1673 121 Thurallor-7095
        item.Click = function()
1674 34 Thurallor-7095
            self:CreateDelaySlot(self.clickedItem);
1675 Thurallor-7095
        end
1676 135 Thurallor-7095
    elseif (itemName == "SelectTarget") then
1677 Thurallor-7095
        item.Click = function()
1678 Thurallor-7095
            self:CreateSelectTargetSlot(self.clickedItem);
1679 Thurallor-7095
        end
1680 2 Thurallor-7095
    end
1681 Thurallor-7095
end
1682 Thurallor-7095
 
1683 7 Thurallor-7095
function SequenceEditor:CreateAliasSlot(s, command)
1684 34 Thurallor-7095
    self:InsertEmptySlot(s);
1685 7 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1686 Thurallor-7095
    info.class = "Turbine.UI.Lotro.Quickslot";
1687 Thurallor-7095
    info.background = nil;
1688 Thurallor-7095
    info.type = Turbine.UI.Lotro.ShortcutType.Alias;
1689 Thurallor-7095
    info.Data = command;
1690 34 Thurallor-7095
    info.altIcon = self.settings.sequenceEditor.defaultIcon;
1691 16 Thurallor-7095
    if (info.background) then
1692 Thurallor-7095
        info.textOverlay = string.gsub(info.Data, "^/", "");
1693 Thurallor-7095
        info.textOverlay = string.gsub(info.textOverlay, "%s.*$", "");
1694 Thurallor-7095
    end
1695 7 Thurallor-7095
    self:RebuildSlot(s);
1696 16 Thurallor-7095
    self:UpdateBar();
1697 7 Thurallor-7095
    self:Redraw();
1698 Thurallor-7095
    self:SelectSlot(s);
1699 Thurallor-7095
end
1700 Thurallor-7095
 
1701 34 Thurallor-7095
function SequenceEditor:CreateDelaySlot(s)
1702 Thurallor-7095
    self:InsertEmptySlot(s);
1703 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1704 Thurallor-7095
    info.class = "Turbine.UI.Control";
1705 Thurallor-7095
    info.background = resources.Icon.Clock;
1706 Thurallor-7095
    info.altIcon = nil;
1707 Thurallor-7095
    info.type = "Delay";
1708 Thurallor-7095
    info.toolTip = L:GetText("/SequenceEditor/RightClickMenu/SpecialSlotMenu/Delay");
1709 Thurallor-7095
    info.delay = 0.25;
1710 Thurallor-7095
    info.action = "local item, s = ...; item.bar:StartSlotCooldown(s, " .. tostring(info.delay) .. ");";
1711 Thurallor-7095
    info.advanceEvent = "DelayComplete";
1712 Thurallor-7095
 
1713 Thurallor-7095
    self:RebuildSlot(s);
1714 Thurallor-7095
    self:UpdateBar();
1715 Thurallor-7095
    self:Redraw();
1716 Thurallor-7095
    self:SelectSlot(s);
1717 Thurallor-7095
end
1718 Thurallor-7095
 
1719 135 Thurallor-7095
function SequenceEditor:CreateSelectTargetSlot(s)
1720 Thurallor-7095
    self:InsertEmptySlot(s);
1721 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1722 Thurallor-7095
    info.class = "Turbine.UI.Lotro.EntityControl";
1723 Thurallor-7095
    info.altIcon = nil;
1724 Thurallor-7095
    info.type = "SelectTarget";
1725 Thurallor-7095
    info.toolTip = L:GetText("/SequenceEditor/RightClickMenu/SpecialSlotMenu/SelectTarget");
1726 Thurallor-7095
    info.target = "Self";
1727 Thurallor-7095
    info.getTargetFunc = "local _, player = ...; return player;";
1728 Thurallor-7095
 
1729 Thurallor-7095
    self:RebuildSlot(s);
1730 Thurallor-7095
    self:UpdateBar();
1731 Thurallor-7095
    self:Redraw();
1732 Thurallor-7095
    self:SelectSlot(s);
1733 Thurallor-7095
 
1734 Thurallor-7095
end
1735 Thurallor-7095
 
1736 16 Thurallor-7095
function SequenceEditor:CreateIncludeSlot(s)
1737 34 Thurallor-7095
    self:InsertEmptySlot(s);
1738 16 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1739 Thurallor-7095
    info.class = "Turbine.UI.Control";
1740 Thurallor-7095
    info.background = resources.Icon.Include;
1741 34 Thurallor-7095
    info.altIcon = nil;
1742 16 Thurallor-7095
    info.type = "Include";
1743 Thurallor-7095
    info.toolTip = L:GetText("/SequenceEditor/RightClickMenu/SpecialSlotMenu/Include");
1744 Thurallor-7095
 
1745 Thurallor-7095
    self:RebuildSlot(s);
1746 Thurallor-7095
    self:UpdateBar();
1747 Thurallor-7095
    self:Redraw();
1748 Thurallor-7095
    self:SelectSlot(s);
1749 Thurallor-7095
end
1750 7 Thurallor-7095
 
1751 20 Thurallor-7095
function SequenceEditor:UnlinkIncludedSequence(s)
1752 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1753 Thurallor-7095
    if (not info.include) then
1754 Thurallor-7095
        return;
1755 Thurallor-7095
    end
1756 Thurallor-7095
    local otherSequenceSettings = self.globals.bars[info.include];
1757 Thurallor-7095
    if (not otherSequenceSettings) then
1758 Thurallor-7095
        return;
1759 Thurallor-7095
    end
1760 Thurallor-7095
    local otherItemInfo = otherSequenceSettings.sequenceItemInfo;
1761 Thurallor-7095
    self:DeleteSlot(s);
1762 Thurallor-7095
    for i = 1, #otherItemInfo, 1 do
1763 Thurallor-7095
        if (otherItemInfo[i].class) then
1764 Thurallor-7095
            table.insert(self.settings.sequenceItemInfo, s + i - 1, {});
1765 Thurallor-7095
            DeepTableCopy(otherItemInfo[i], self.settings.sequenceItemInfo[s + i - 1]);
1766 Thurallor-7095
        end
1767 Thurallor-7095
    end
1768 Thurallor-7095
    self:Redraw();
1769 Thurallor-7095
    self:SelectSlot(s);
1770 Thurallor-7095
end
1771 Thurallor-7095
 
1772 16 Thurallor-7095
function SequenceEditor:CreateConditional(s, condType)
1773 34 Thurallor-7095
    local prevContext = L:SetContext("/SequenceEditor");
1774 16 Thurallor-7095
    local ifSlot = s;
1775 46 Thurallor-7095
    self.noRedraw = true;
1776 20 Thurallor-7095
    self:InsertEmptySlot(s);
1777 16 Thurallor-7095
    if (condType == "IfThenElse") then
1778 20 Thurallor-7095
        self:InsertEmptySlot(s);
1779 16 Thurallor-7095
    end
1780 20 Thurallor-7095
    self:InsertEmptySlot(s);
1781 16 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1782 Thurallor-7095
    info.class = "Turbine.UI.Control";
1783 Thurallor-7095
    info.background = resources.Icon["If"];
1784 34 Thurallor-7095
    info.altIcon = nil;
1785 16 Thurallor-7095
    info.type = "If";
1786 Thurallor-7095
    info.condName = "Always";
1787 Thurallor-7095
    info.condExpr = "return true;";
1788 Thurallor-7095
    info.toolTip = L:GetText("If");
1789 Thurallor-7095
    info.automatic = true;
1790 Thurallor-7095
    if (condType == "IfThenElse") then
1791 Thurallor-7095
        s = s + 1;
1792 Thurallor-7095
        info = self.settings.sequenceItemInfo[s];
1793 Thurallor-7095
        info.class = "Turbine.UI.Control";
1794 Thurallor-7095
        info.background = resources.Icon["Else"];
1795 34 Thurallor-7095
        info.altIcon = nil;
1796 16 Thurallor-7095
        info.type = "Else";
1797 Thurallor-7095
        info.toolTip = L:GetText("Else");
1798 Thurallor-7095
        info.automatic = true;
1799 Thurallor-7095
    end
1800 Thurallor-7095
    s = s + 1;
1801 Thurallor-7095
    info = self.settings.sequenceItemInfo[s];
1802 Thurallor-7095
    info.class = "Turbine.UI.Control";
1803 Thurallor-7095
    info.background = resources.Icon["EndIf"];
1804 34 Thurallor-7095
    info.altIcon = nil;
1805 16 Thurallor-7095
    info.type = "EndIf";
1806 Thurallor-7095
    info.toolTip = L:GetText("EndIf");
1807 Thurallor-7095
    info.automatic = true;
1808 46 Thurallor-7095
    self.noRedraw = false;
1809 16 Thurallor-7095
    self:Redraw();
1810 Thurallor-7095
    self:UpdateBar();
1811 Thurallor-7095
    self:SelectSlot(ifSlot);
1812 Thurallor-7095
    L:SetContext(prevContext);
1813 Thurallor-7095
end
1814 Thurallor-7095
 
1815 2 Thurallor-7095
function SequenceEditor:CreateCommandSlot(s, slotName, toolTip)
1816 34 Thurallor-7095
    self:InsertEmptySlot(s);
1817 2 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1818 Thurallor-7095
    info.class = "Turbine.UI.Control";
1819 Thurallor-7095
    info.background = resources.Icon[slotName];
1820 34 Thurallor-7095
    info.altIcon = nil;
1821 2 Thurallor-7095
    if (slotName == "StopAnimating") then
1822 43 Thurallor-7095
        info.action = "local item = ...; item.bar.animationStopped = true; ";
1823 2 Thurallor-7095
    elseif (slotName == "GenerateEvent") then
1824 32 Thurallor-7095
        info.eventName = L:GetText("/SequenceEditor/NewEvent");
1825 34 Thurallor-7095
        info.action = "local item = ...; item.bar.manager:PropagateEvent(item.info.eventName);";
1826 6 Thurallor-7095
    elseif (slotName == "SetUnequipDestination") then
1827 Thurallor-7095
        info.bagSlot = 1;
1828 34 Thurallor-7095
        info.action = "local item = ...; item.bar.manager:SetUnequipDestination(item.info.bagSlot);";
1829 2 Thurallor-7095
    end
1830 Thurallor-7095
    info.type = slotName;
1831 Thurallor-7095
    info.toolTip = toolTip;
1832 Thurallor-7095
    self:RebuildSlot(s);
1833 16 Thurallor-7095
    self:UpdateBar();
1834 2 Thurallor-7095
    self:Redraw();
1835 Thurallor-7095
    self:SelectSlot(s);
1836 Thurallor-7095
end
1837 Thurallor-7095
 
1838 6 Thurallor-7095
function SequenceEditor:CreateRemovalSlot(s, eqSlotName, bagSlot)
1839 34 Thurallor-7095
    self:InsertEmptySlot(s);
1840 2 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1841 Thurallor-7095
    info.class = "Turbine.UI.Control";
1842 6 Thurallor-7095
    info.background = resources.Icon["Unequip" .. eqSlotName];
1843 34 Thurallor-7095
    info.altIcon = nil;
1844 Thurallor-7095
    info.action = "local item = ...; item.bar.manager:Unequip(Turbine.Gameplay.Equipment." .. eqSlotName .. ");";
1845 6 Thurallor-7095
    info.type = "Remove " .. eqSlotName;
1846 Thurallor-7095
 
1847 Thurallor-7095
    local prevContext = L:SetContext("/SequenceEditor");
1848 Thurallor-7095
    local toolTip = L:GetText("RemoveItem");
1849 Thurallor-7095
    L:SetContext("EquipmentSlots");
1850 Thurallor-7095
    local localEqSlotName = L:GetText(eqSlotName);
1851 Thurallor-7095
    info.toolTip = string.gsub(toolTip, "<item>", localEqSlotName);
1852 Thurallor-7095
    L:SetContext(prevContext);
1853 Thurallor-7095
 
1854 2 Thurallor-7095
    self:RebuildSlot(s);
1855 16 Thurallor-7095
    self:UpdateBar();
1856 2 Thurallor-7095
    self:Redraw();
1857 Thurallor-7095
    self:SelectSlot(s);
1858 Thurallor-7095
end
1859 Thurallor-7095
 
1860 Thurallor-7095
function SequenceEditor:ExtendSequenceTo(s)
1861 Thurallor-7095
    if (s <= #self.settings.sequenceItemInfo) then
1862 Thurallor-7095
        return false;
1863 Thurallor-7095
    end
1864 Thurallor-7095
    while (s > #self.settings.sequenceItemInfo) do
1865 Thurallor-7095
        table.insert(self.settings.sequenceItemInfo, {});
1866 Thurallor-7095
    end
1867 Thurallor-7095
    return true;
1868 Thurallor-7095
end
1869 Thurallor-7095
 
1870 Thurallor-7095
function SequenceEditor:DeleteEmptyTrailingSlots()
1871 Thurallor-7095
    local sequenceItemInfo = self.settings.sequenceItemInfo;
1872 Thurallor-7095
    for s = #sequenceItemInfo, 1, -1 do
1873 Thurallor-7095
        local info = sequenceItemInfo[s];
1874 Thurallor-7095
        if (not info.class) then
1875 Thurallor-7095
            table.remove(sequenceItemInfo, s);
1876 5 Thurallor-7095
            -- Remove empty slot displays
1877 Thurallor-7095
            if (self.sequenceItems) then
1878 Thurallor-7095
                local object = self.sequenceItems[s];
1879 Thurallor-7095
                if (object) then
1880 Thurallor-7095
                    if (object.numLabel) then
1881 Thurallor-7095
                        object.numLabel:SetParent(nil);
1882 Thurallor-7095
                    end
1883 Thurallor-7095
                    object:SetParent(nil);
1884 Thurallor-7095
                    self.sequenceItems[s] = nil;
1885 Thurallor-7095
                end
1886 Thurallor-7095
            end
1887 2 Thurallor-7095
        else
1888 Thurallor-7095
            break;
1889 Thurallor-7095
        end
1890 Thurallor-7095
    end
1891 Thurallor-7095
end
1892 Thurallor-7095
 
1893 7 Thurallor-7095
function SequenceEditor:CloneSlot(s)
1894 Thurallor-7095
    self:InsertEmptySlot(s);
1895 Thurallor-7095
    DeepTableCopy(self.settings.sequenceItemInfo[s + 1], self.settings.sequenceItemInfo[s]);
1896 Thurallor-7095
    self:RebuildSlot(s);
1897 16 Thurallor-7095
    self:UpdateBar();
1898 7 Thurallor-7095
    self:Redraw();
1899 Thurallor-7095
    self:SelectSlot(s);
1900 Thurallor-7095
end
1901 Thurallor-7095
 
1902 Thurallor-7095
function SequenceEditor:MoveSlot(sourceSlot, destSlot)
1903 Thurallor-7095
    self:InsertEmptySlot(destSlot);
1904 Thurallor-7095
    if (sourceSlot >= destSlot) then
1905 Thurallor-7095
        sourceSlot = sourceSlot + 1;
1906 Thurallor-7095
    end
1907 Thurallor-7095
    DeepTableCopy(self.settings.sequenceItemInfo[sourceSlot], self.settings.sequenceItemInfo[destSlot]);
1908 Thurallor-7095
    self:RebuildSlot(destSlot);
1909 Thurallor-7095
    self:DeleteSlot(sourceSlot);
1910 Thurallor-7095
    if (sourceSlot <= destSlot) then
1911 Thurallor-7095
        destSlot = destSlot - 1;
1912 Thurallor-7095
    end
1913 16 Thurallor-7095
    self:UpdateBar();
1914 7 Thurallor-7095
    self:Redraw();
1915 Thurallor-7095
    self:SelectSlot(destSlot);
1916 Thurallor-7095
end
1917 Thurallor-7095
 
1918 Thurallor-7095
function SequenceEditor:InsertSlot(s, info)
1919 2 Thurallor-7095
    if (s > #self.settings.sequenceItemInfo) then
1920 Thurallor-7095
        self:ExtendSequenceTo(s);
1921 Thurallor-7095
    else
1922 Thurallor-7095
        table.insert(self.settings.sequenceItemInfo, s, {});
1923 Thurallor-7095
    end
1924 7 Thurallor-7095
    if (info) then
1925 Thurallor-7095
        DeepTableCopy(info, self.settings.sequenceItemInfo[s]);
1926 Thurallor-7095
    end
1927 2 Thurallor-7095
    self:Redraw();
1928 16 Thurallor-7095
    self:UpdateBar();
1929 2 Thurallor-7095
    self:SelectSlot(s);
1930 Thurallor-7095
end
1931 Thurallor-7095
 
1932 7 Thurallor-7095
function SequenceEditor:InsertEmptySlot(s)
1933 Thurallor-7095
    self:InsertSlot(s, nil);
1934 Thurallor-7095
end
1935 Thurallor-7095
 
1936 2 Thurallor-7095
function SequenceEditor:DeleteSlot(s)
1937 Thurallor-7095
    table.remove(self.settings.sequenceItemInfo, s);
1938 Thurallor-7095
    self:Redraw();
1939 16 Thurallor-7095
    self:UpdateBar();
1940 2 Thurallor-7095
    self:ExtendSequenceTo(s);
1941 Thurallor-7095
    self:SelectSlot(nil);
1942 Thurallor-7095
end

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


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