lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

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

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 Thurallor-7095
        self:_SizeChanged();
48 Thurallor-7095
    end);
49 20 Thurallor-7095
 
50 Thurallor-7095
    self:SelectSlot(nil);
51 2 Thurallor-7095
end
52 Thurallor-7095
 
53 16 Thurallor-7095
function SequenceEditor:UpdateBar()
54 Thurallor-7095
    self.bar:ShortcutChanged();
55 Thurallor-7095
    self.manager:NotifyIncluders(self.bar:GetID());
56 Thurallor-7095
end
57 Thurallor-7095
 
58 7 Thurallor-7095
function SequenceEditor:Activated()
59 Thurallor-7095
    -- Find the maximum Z order among all other Sequence Editors.
60 Thurallor-7095
    local maxZ = self:GetZOrder() - 1;
61 Thurallor-7095
    for editor in keys(SequenceEditor.instances) do
62 Thurallor-7095
        if (editor ~= self) then
63 Thurallor-7095
            local z = editor:GetZOrder();
64 Thurallor-7095
            if (z > maxZ) then
65 Thurallor-7095
                maxZ = z;
66 Thurallor-7095
            end
67 Thurallor-7095
        end
68 Thurallor-7095
    end
69 Thurallor-7095
 
70 Thurallor-7095
    if (maxZ == 2147483647) then
71 Thurallor-7095
        -- Move all other SequenceEditors back to make room at the front.
72 Thurallor-7095
        for editor in keys(SequenceEditor.instances) do
73 Thurallor-7095
            editor:SetZOrder(editor:GetZOrder() - 1);
74 Thurallor-7095
        end
75 Thurallor-7095
        maxZ = maxZ - 1;
76 Thurallor-7095
    end
77 Thurallor-7095
 
78 Thurallor-7095
    -- Move the newly-activated Sequence Editor to the front of the stack.
79 Thurallor-7095
    self:SetZOrder(maxZ + 1);
80 Thurallor-7095
end
81 Thurallor-7095
 
82 2 Thurallor-7095
function SequenceEditor:SetText(barName)
83 Thurallor-7095
    local title = L:GetText("/SequenceEditor/Title");
84 Thurallor-7095
    title = string.gsub(title, "<name>", barName);
85 Thurallor-7095
    Turbine.UI.Lotro.Window.SetText(self, title);
86 Thurallor-7095
end
87 Thurallor-7095
 
88 Thurallor-7095
function SequenceEditor:SaveSettings()
89 Thurallor-7095
    self.bar:SaveSettings();
90 Thurallor-7095
end
91 Thurallor-7095
 
92 Thurallor-7095
function SequenceEditor:Redraw()
93 Thurallor-7095
    local width, height = self:GetSize();
94 Thurallor-7095
 
95 Thurallor-7095
    local xMargin = 16;
96 Thurallor-7095
    local topMargin = 35;
97 Thurallor-7095
    local bottomMargin = 42;
98 33 Thurallor-7095
    local slotTabWidth = L:GetNumber("/SequenceEditor/SlotTabWidth");
99 2 Thurallor-7095
 
100 Thurallor-7095
    if (not self.slotTabCard) then
101 Thurallor-7095
        self.slotTabCard = Thurallor.UI.TabCard();
102 Thurallor-7095
        self.slotTabCard:SetParent(self);
103 Thurallor-7095
        self.slotTabCard:SetTop(topMargin);
104 33 Thurallor-7095
        self.slotTabCard:SetWidth(slotTabWidth);
105 2 Thurallor-7095
        self.slotTabCard:SetTabWidth(120);
106 Thurallor-7095
        self.slotTabCard:SetTabText(L:GetText("/SequenceEditor/SlotTab"));
107 20 Thurallor-7095
 
108 Thurallor-7095
        -- When mouse reenters the area, redisplay the current slot in case options have changed.
109 Thurallor-7095
        self.slotTabCard.MouseEnter = function(ctl)
110 Thurallor-7095
            if (not ctl.mouseInside) then
111 Thurallor-7095
                ctl.mouseInside = true;
112 Thurallor-7095
                self:DisplaySlot(self.selectedSlot);
113 Thurallor-7095
            end
114 Thurallor-7095
        end
115 Thurallor-7095
        self.MouseEnter = function()
116 Thurallor-7095
            if (self.slotTabCard.mouseInside) then
117 Thurallor-7095
                local left, top = self.slotTabCard:GetMousePosition();
118 Thurallor-7095
                local width, height = self.slotTabCard:GetSize();
119 Thurallor-7095
                if ((left < 0) or (left >= width) or (top < 0) or (top >= height)) then
120 Thurallor-7095
                    self.slotTabCard.mouseInside = false;
121 Thurallor-7095
                end
122 Thurallor-7095
            end
123 Thurallor-7095
        end
124 2 Thurallor-7095
    end
125 33 Thurallor-7095
    self.slotTabCard:SetLeft(width - slotTabWidth - xMargin);
126 2 Thurallor-7095
    self.slotTabCard:SetHeight(height - topMargin - bottomMargin);
127 Thurallor-7095
 
128 Thurallor-7095
    if (not self.sequenceTabCard) then
129 Thurallor-7095
        self.sequenceTabCard = Thurallor.UI.TabCard();
130 Thurallor-7095
        self.sequenceTabCard:SetParent(self);
131 Thurallor-7095
        self.sequenceTabCard:SetPosition(xMargin, topMargin);
132 Thurallor-7095
        self.sequenceTabCard:SetTabWidth(120);
133 Thurallor-7095
        self.sequenceTabCard:SetTabText(L:GetText("/SequenceEditor/SequenceTab"));
134 13 Thurallor-7095
        self.slotPanel = Turbine.UI.Control();
135 Thurallor-7095
        self.sequenceTabCard:SetInteriorControl(self.slotPanel);
136 Thurallor-7095
        self.sequenceTabCard:SetInteriorAlignment(Turbine.UI.ContentAlignment.TopLeft);
137 2 Thurallor-7095
    end
138 Thurallor-7095
    self.sequenceTabCard:SetSize(self.slotTabCard:GetLeft() - xMargin - 8, self.slotTabCard:GetHeight());
139 Thurallor-7095
 
140 Thurallor-7095
    self:DeleteEmptyTrailingSlots();
141 13 Thurallor-7095
    local slotPanelWidth = self.sequenceTabCard:GetWidth() - 6;
142 7 Thurallor-7095
    self.slotSize = self.settings.slotSize + self.settings.slotSpacing;
143 Thurallor-7095
    self.slotsWide = math.floor((slotPanelWidth - 3) / self.slotSize);
144 Thurallor-7095
    self.slotsHigh = math.max(math.ceil(#self.settings.sequenceItemInfo / self.slotsWide) + 1, 2);
145 Thurallor-7095
    self:ExtendSequenceTo(self.slotsHigh * self.slotsWide);
146 Thurallor-7095
    self.slotPanel:SetSize(self.slotsWide * self.slotSize + 3, self.slotsHigh * self.slotSize + 3);
147 2 Thurallor-7095
    self.slotPanel:SetBackColor(self.bar.color);
148 Thurallor-7095
 
149 Thurallor-7095
    -- Draw some quickslots
150 Thurallor-7095
    if (not self.sequenceItems) then
151 Thurallor-7095
        self.sequenceItems = {};
152 Thurallor-7095
    end
153 Thurallor-7095
    local s = 1;
154 7 Thurallor-7095
    for y = 1, self.slotsHigh, 1 do
155 2 Thurallor-7095
        for x = 1, self.slotsWide, 1 do
156 Thurallor-7095
            self:RebuildSlot(s, x, y);
157 Thurallor-7095
            s = s + 1;
158 Thurallor-7095
        end
159 Thurallor-7095
    end
160 Thurallor-7095
 
161 Thurallor-7095
    if (not self.instructions) then
162 Thurallor-7095
        self.instructions = Turbine.UI.Label();
163 Thurallor-7095
        self.instructions:SetParent(self);
164 Thurallor-7095
        self.instructions:SetMouseVisible(false);
165 Thurallor-7095
        self.instructions:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
166 Thurallor-7095
        self.instructions:SetFont(Turbine.UI.Lotro.Font.TrajanPro15);
167 Thurallor-7095
        self.instructions:SetMultiline(true);
168 Thurallor-7095
        self.instructions:SetForeColor(Turbine.UI.Color.PaleGoldenrod);
169 Thurallor-7095
        self.instructions:SetText(L:GetText("/SequenceEditor/Instructions"));
170 Thurallor-7095
    end
171 Thurallor-7095
    self.instructions:SetSize(self:GetWidth() - 2 * xMargin, 30);
172 Thurallor-7095
    self.instructions:SetPosition(xMargin, self:GetHeight() - 40);
173 13 Thurallor-7095
 
174 Thurallor-7095
    if (self.selectedSlot) then
175 Thurallor-7095
        self:SelectSlot(self.selectedSlot);
176 2 Thurallor-7095
    end
177 Thurallor-7095
end
178 Thurallor-7095
 
179 15 Thurallor-7095
function SequenceEditor:SetMinimumHeight(height)
180 Thurallor-7095
    Turbine.UI.Window.SetMinimumHeight(self, height);
181 Thurallor-7095
    if (self:GetHeight() < height) then
182 Thurallor-7095
        self:SetHeight(height);
183 Thurallor-7095
    end
184 Thurallor-7095
end
185 Thurallor-7095
 
186 18 Thurallor-7095
function SequenceEditor:_SizeChanged()
187 2 Thurallor-7095
    self:Redraw();
188 Thurallor-7095
    self.settings.sequenceEditor.size = {self:GetSize()};
189 Thurallor-7095
    self:SaveSettings();
190 Thurallor-7095
end
191 Thurallor-7095
 
192 Thurallor-7095
function SequenceEditor:PositionChanged()
193 Thurallor-7095
    self.settings.sequenceEditor.position = {self:GetPosition()};
194 Thurallor-7095
    self:SaveSettings();
195 Thurallor-7095
end
196 Thurallor-7095
 
197 Thurallor-7095
function SequenceEditor:DisplaySlot(s)
198 20 Thurallor-7095
    if (self.ItemMovedCallback) then
199 Thurallor-7095
        RemoveCallback(Thurallor.Utils.Watcher, "ItemMoved", self.ItemMovedCallback);
200 Thurallor-7095
        self.ItemMovedCallback = nil;
201 Thurallor-7095
    end
202 Thurallor-7095
 
203 2 Thurallor-7095
    self.slotTabCard:SetInteriorControl(nil);
204 Thurallor-7095
    self.slotTabCard:SetTabText(L:GetText("/SequenceEditor/SlotTab"));
205 7 Thurallor-7095
    if ((s == nil) or (s > #self.settings.sequenceItemInfo)) then
206 Thurallor-7095
        self.slotTabCard:SetVisible(false);
207 2 Thurallor-7095
        return;
208 7 Thurallor-7095
    else
209 Thurallor-7095
        self.slotTabCard:SetVisible(true);
210 2 Thurallor-7095
    end
211 Thurallor-7095
    self:ExtendSequenceTo(s);
212 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
213 33 Thurallor-7095
    local slotTabWidth = L:GetNumber("/SequenceEditor/SlotTabWidth");
214 2 Thurallor-7095
 
215 Thurallor-7095
    -- Update slot tab caption and create properties container
216 Thurallor-7095
    self.slotTabCard:SetTabText(L:GetText("/SequenceEditor/SlotTab") .. " " .. tostring(s));
217 Thurallor-7095
    self.slotProperties = Turbine.UI.Control();
218 Thurallor-7095
    self.slotTabCard:SetInteriorControl(self.slotProperties);
219 Thurallor-7095
    local width = self.slotTabCard:GetWidth() - 17;
220 Thurallor-7095
    self.slotProperties:SetWidth(width);
221 13 Thurallor-7095
 
222 7 Thurallor-7095
    local function UpdateIcon()
223 13 Thurallor-7095
        self.selectedIcon = self:BuildSlot(s, self.slotProperties, self.selectedIcon, 72, 10);
224 Thurallor-7095
        self.selectedIcon.numLabel:SetText(nil);     -- don't display slot number overlay
225 Thurallor-7095
        self.selectedIcon.numLabel.MouseClick = nil; -- disable right-click menu
226 Thurallor-7095
        self.selectedIcon.numLabel.MouseDown = nil;  -- disable dragging
227 15 Thurallor-7095
        self.selectedIcon:SetActionEnabled(true);
228 Thurallor-7095
        self.selectedIcon:SetAllowDrop(true);
229 7 Thurallor-7095
        self:RebuildSlot(s, nil, nil, true);
230 Thurallor-7095
    end
231 Thurallor-7095
    UpdateIcon();
232 2 Thurallor-7095
 
233 Thurallor-7095
    -- Create a function for adding a centered line of text to the properties control
234 Thurallor-7095
    local AddLabel = function(top, text, color)
235 Thurallor-7095
        local label = Turbine.UI.Label();
236 Thurallor-7095
        label:SetParent(self.slotProperties);
237 Thurallor-7095
        label:SetPosition(0, top);
238 33 Thurallor-7095
        label:SetSize(slotTabWidth - 20, 16);
239 2 Thurallor-7095
        top = top + 16;
240 Thurallor-7095
        label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
241 Thurallor-7095
        label:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
242 Thurallor-7095
        label:SetForeColor(color);
243 Thurallor-7095
        label:SetMarkupEnabled(true);
244 Thurallor-7095
        label:SetText(text);
245 Thurallor-7095
        return top, label;
246 Thurallor-7095
    end
247 20 Thurallor-7095
 
248 Thurallor-7095
    -- Create a function for adding a centered button to the properties control
249 Thurallor-7095
    local AddButton = function(top, width, text)
250 Thurallor-7095
        local button = Turbine.UI.Lotro.Button();
251 Thurallor-7095
        button:SetParent(self.slotProperties);
252 Thurallor-7095
        local left = math.floor((self.slotProperties:GetWidth() - width) / 2);
253 Thurallor-7095
        button:SetPosition(left, top + 2);
254 Thurallor-7095
        button:SetWidth(width);
255 Thurallor-7095
        button:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
256 Thurallor-7095
        button:SetText(text);
257 Thurallor-7095
        top = top + 2 + button:GetHeight();
258 Thurallor-7095
        return top, button;
259 Thurallor-7095
    end
260 Thurallor-7095
 
261 2 Thurallor-7095
    -- Create a function for adding a centered text box to the properties control
262 Thurallor-7095
    local AddTextBox = function(top, text, color)
263 Thurallor-7095
        local textBox = Turbine.UI.Lotro.TextBox();
264 Thurallor-7095
        textBox:SetParent(self.slotProperties);
265 Thurallor-7095
        textBox:SetPosition(0, top);
266 33 Thurallor-7095
        textBox:SetSize(slotTabWidth - 20, 20);
267 2 Thurallor-7095
        top = top + 20;
268 Thurallor-7095
        textBox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
269 7 Thurallor-7095
        textBox:SetMultiline(false);
270 2 Thurallor-7095
        textBox:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
271 Thurallor-7095
        textBox:SetForeColor(color);
272 Thurallor-7095
        textBox:SetText(text);
273 Thurallor-7095
        return top, textBox;
274 Thurallor-7095
    end
275 6 Thurallor-7095
 
276 20 Thurallor-7095
    -- Create a function for adding a left-justified checkbox to the properties control
277 6 Thurallor-7095
    local AddCheckBox = function(top, text, color, checked)
278 Thurallor-7095
        local checkBox = Turbine.UI.Lotro.CheckBox();
279 Thurallor-7095
        checkBox:SetParent(self.slotProperties);
280 Thurallor-7095
        checkBox:SetPosition(0, top);
281 33 Thurallor-7095
        checkBox:SetSize(slotTabWidth - 20, 20);
282 6 Thurallor-7095
        top = top + 20;
283 Thurallor-7095
        checkBox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
284 Thurallor-7095
        checkBox:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
285 Thurallor-7095
        checkBox:SetForeColor(color);
286 Thurallor-7095
        checkBox:SetText(text);
287 Thurallor-7095
        if (checked) then
288 Thurallor-7095
            checkBox:SetChecked(true);
289 Thurallor-7095
        end
290 Thurallor-7095
        return top, checkBox;
291 Thurallor-7095
    end
292 2 Thurallor-7095
 
293 6 Thurallor-7095
    -- Create a function for adding a left-justified radio button to the properties control
294 Thurallor-7095
    local AddRadioButton = function(top, text, color, checked)
295 Thurallor-7095
        local button = Thurallor.UI.RadioButton(self.slotProperties, text, checked);
296 Thurallor-7095
        button:SetPosition(0, top);
297 33 Thurallor-7095
        button:SetSize(slotTabWidth - 20, 16);
298 6 Thurallor-7095
        top = top + 16;
299 Thurallor-7095
        button:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
300 Thurallor-7095
        button:SetForeColor(color);
301 Thurallor-7095
        return top, button;
302 Thurallor-7095
    end
303 Thurallor-7095
 
304 Thurallor-7095
    -- Create a function for adding a drop-down listbox to the properties control
305 16 Thurallor-7095
    local AddDropDown = function(top, items, default)
306 6 Thurallor-7095
        local dropDown = Thurallor.UI.DropDown(items, default);
307 Thurallor-7095
        dropDown:SetParent(self.slotProperties);
308 Thurallor-7095
        dropDown:SetPosition(0, top);
309 33 Thurallor-7095
        dropDown:SetWidth(slotTabWidth - 20);
310 6 Thurallor-7095
        top = top + dropDown:GetHeight();
311 Thurallor-7095
        return top, dropDown;
312 Thurallor-7095
    end
313 7 Thurallor-7095
 
314 16 Thurallor-7095
    -- Create a function for adding a pull-down hierarchical menu to the properties control
315 Thurallor-7095
    local AddPullDown = function(top, items, default)
316 Thurallor-7095
        local pullDown = Thurallor.UI.PullDownMenu(items, default);
317 Thurallor-7095
        pullDown:SetParent(self.slotProperties);
318 Thurallor-7095
        pullDown:SetPosition(0, top);
319 33 Thurallor-7095
        pullDown:SetWidth(slotTabWidth - 20);
320 16 Thurallor-7095
        top = top + pullDown:GetHeight();
321 Thurallor-7095
        return top, pullDown;
322 Thurallor-7095
    end
323 Thurallor-7095
 
324 7 Thurallor-7095
    -- Create a function for adding a horizontal scrollbar to the properties control
325 Thurallor-7095
    local AddSlider = function(top, minimum, maximum, value)
326 Thurallor-7095
        local scrollBar = Turbine.UI.Lotro.ScrollBar();
327 Thurallor-7095
        scrollBar:SetParent(self.slotProperties);
328 Thurallor-7095
        scrollBar:SetPosition(0, top);
329 33 Thurallor-7095
        scrollBar:SetSize(slotTabWidth - 20, 10);
330 7 Thurallor-7095
        scrollBar:SetMinimum(minimum);
331 Thurallor-7095
        scrollBar:SetMaximum(maximum);
332 Thurallor-7095
        scrollBar:SetSmallChange(1);
333 Thurallor-7095
        scrollBar:SetValue(value);
334 Thurallor-7095
        top = top + 10;
335 Thurallor-7095
        return top, scrollBar;
336 Thurallor-7095
    end
337 6 Thurallor-7095
 
338 2 Thurallor-7095
    -- Draw the caption
339 Thurallor-7095
    local top = 54;
340 Thurallor-7095
    if (info.class == "Turbine.UI.Lotro.Quickslot") then
341 Thurallor-7095
        top = AddLabel(top, L:GetText("/SequenceEditor/StandardQuickslot"), Turbine.UI.Color.PaleGoldenrod);
342 Thurallor-7095
    elseif (info.class == "Turbine.UI.Control") then
343 Thurallor-7095
        top = AddLabel(top, L:GetText("/SequenceEditor/SpecialSlot") .. ":", Turbine.UI.Color.PaleGoldenrod);
344 32 Thurallor-7095
        local label;
345 Thurallor-7095
        top, label = AddLabel(top, info.toolTip, Turbine.UI.Color.PaleGoldenrod);
346 Thurallor-7095
        -- Some German strings need line wrapping here.
347 Thurallor-7095
        label:SetHeight(32);
348 Thurallor-7095
        label:SetTextAlignment(Turbine.UI.ContentAlignment.TopCenter);
349 2 Thurallor-7095
    end
350 Thurallor-7095
 
351 Thurallor-7095
    -- Draw the arguments
352 Thurallor-7095
    if (info.class == "Turbine.UI.Lotro.Quickslot") then
353 Thurallor-7095
        top = top + 16; -- skip a line
354 Thurallor-7095
        for key, value in pairs(Turbine.UI.Lotro.ShortcutType) do
355 Thurallor-7095
            if (info.type == value) then
356 Thurallor-7095
                top = AddLabel(top, L:GetText("/SequenceEditor/ShortcutType") .. ": " .. L:GetText("/SequenceEditor/ShortcutTypes/" .. key), Turbine.UI.Color.Goldenrod);
357 Thurallor-7095
                break;
358 Thurallor-7095
            end
359 Thurallor-7095
        end
360 7 Thurallor-7095
 
361 Thurallor-7095
        if (info.type == Turbine.UI.Lotro.ShortcutType.Alias) then
362 Thurallor-7095
            -- Allow the user to optionally change the icon
363 Thurallor-7095
            top = top + 16; -- skip a line
364 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/ChangeIcon") .. ":", Turbine.UI.Color.Goldenrod);
365 Thurallor-7095
            local minimum, maximum = 0, #resources.BlankIcons;
366 15 Thurallor-7095
            local value = Search(resources.BlankIcons, info.background);
367 7 Thurallor-7095
            local slider;
368 Thurallor-7095
            top, slider = AddSlider(top, minumum, maximum, value);
369 Thurallor-7095
            slider.ValueChanged = function(sender)
370 Thurallor-7095
                local value = sender:GetValue();
371 Thurallor-7095
                if (value == 0) then
372 Thurallor-7095
                    info.background = nil;
373 Thurallor-7095
                else
374 Thurallor-7095
                    info.background = resources.BlankIcons[value];
375 Thurallor-7095
                end
376 Thurallor-7095
                UpdateIcon();
377 16 Thurallor-7095
                self:UpdateBar();
378 7 Thurallor-7095
 
379 Thurallor-7095
                self.settings.sequenceEditor.defaultIcon = info.background;
380 Thurallor-7095
                self:SaveSettings();
381 Thurallor-7095
            end
382 Thurallor-7095
 
383 Thurallor-7095
            -- Allow the user to specify the command
384 Thurallor-7095
            top = top + 16; -- skip a line
385 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/ChatCommand") .. ":", Turbine.UI.Color.Goldenrod);
386 Thurallor-7095
            local textBox;
387 Thurallor-7095
            top, textBox = AddTextBox(top, info.Data, Turbine.UI.Color.White);
388 Thurallor-7095
            textBox.TextChanged = function(sender, args)
389 Thurallor-7095
                local text = sender:GetText();
390 Thurallor-7095
                -- Remove carriage returns
391 Thurallor-7095
                local stripped = string.gsub(text, "\n", "");
392 Thurallor-7095
                if (stripped ~= text) then
393 Thurallor-7095
                    sender:SetText(stripped);
394 Thurallor-7095
                    text = stripped;
395 Thurallor-7095
                end
396 Thurallor-7095
                info.Data = text;
397 16 Thurallor-7095
                self:UpdateBar();
398 7 Thurallor-7095
            end
399 20 Thurallor-7095
        elseif (info.type == Turbine.UI.Lotro.ShortcutType.Item) then
400 Thurallor-7095
            local shortcut = Turbine.UI.Lotro.Shortcut(info.type, info.Data);
401 Thurallor-7095
            local item = shortcut:GetItem();
402 30 Thurallor-7095
            if (item:GetMaxStackSize() == 1) then -- equippable
403 20 Thurallor-7095
 
404 Thurallor-7095
                -- Allow the user to specify immediate advance, or wait-for-equip
405 Thurallor-7095
                top = top + 16; -- skip a line
406 Thurallor-7095
                top = AddLabel(top, L:GetText("/SequenceEditor/AdvanceToNextSlot") .. ":", Turbine.UI.Color.Goldenrod);
407 Thurallor-7095
                local button1, button2;
408 Thurallor-7095
                top, button1 = AddRadioButton(top, L:GetText("/SequenceEditor/WithLeftClick"), Turbine.UI.Color.DarkGoldenrod, (not info.advanceEvent));
409 Thurallor-7095
                top, button2 = AddRadioButton(top, L:GetText("/SequenceEditor/WhenItemEquipped"), Turbine.UI.Color.DarkGoldenrod, info.advanceEvent);
410 Thurallor-7095
                Thurallor.UI.RadioButton.LinkPeers({button1, button2});
411 Thurallor-7095
 
412 Thurallor-7095
                button1.Clicked = function()
413 Thurallor-7095
                    info.advanceEvent = nil;
414 Thurallor-7095
                    self:UpdateBar();
415 Thurallor-7095
                end
416 Thurallor-7095
                button2.Clicked = function()
417 Thurallor-7095
                    info.advanceEvent = "ItemEquipped";
418 Thurallor-7095
                    self:UpdateBar();
419 Thurallor-7095
                end
420 Thurallor-7095
            end
421 7 Thurallor-7095
        end
422 Thurallor-7095
 
423 2 Thurallor-7095
    elseif (info.class == "Turbine.UI.Control") then
424 Thurallor-7095
        if (info.type == "GenerateEvent") then
425 6 Thurallor-7095
 
426 Thurallor-7095
            -- Allow the user to specify the event name
427 Thurallor-7095
            top = top + 16; -- skip a line
428 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/EventName") .. ":", Turbine.UI.Color.Goldenrod);
429 2 Thurallor-7095
            local textBox;
430 Thurallor-7095
            top, textBox = AddTextBox(top, info.eventName, Turbine.UI.Color.White);
431 Thurallor-7095
            textBox.TextChanged = function(sender, args)
432 5 Thurallor-7095
                local text = sender:GetText();
433 Thurallor-7095
                -- Remove carriage returns
434 Thurallor-7095
                local stripped = string.gsub(text, "\n", "");
435 Thurallor-7095
                if (stripped ~= text) then
436 Thurallor-7095
                    sender:SetText(stripped);
437 Thurallor-7095
                    text = stripped;
438 Thurallor-7095
                end
439 Thurallor-7095
                info.eventName = text;
440 16 Thurallor-7095
                self:UpdateBar();
441 2 Thurallor-7095
            end
442 6 Thurallor-7095
        elseif (info.type == "SetUnequipDestination") then
443 Thurallor-7095
 
444 20 Thurallor-7095
            -- Temporary method to allow users to discover bag slot numbers.
445 Thurallor-7095
            self.ItemMovedCallback = function(sender, args)
446 Thurallor-7095
                local str = L:GetText("/ItemMoved");
447 Thurallor-7095
                str = string.gsub(str, "<source>", tostring(args.OldIndex));
448 Thurallor-7095
                str = string.gsub(str, "<destination>", tostring(args.NewIndex));
449 Thurallor-7095
                Puts(str);
450 Thurallor-7095
            end
451 Thurallor-7095
            AddCallback(Thurallor.Utils.Watcher, "ItemMoved", self.ItemMovedCallback);
452 Thurallor-7095
 
453 6 Thurallor-7095
            -- Allow the user to specify the desired bag slot
454 Thurallor-7095
            top = top + 16; -- skip a line
455 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/PreferredBagSlot") .. ":", Turbine.UI.Color.Goldenrod);
456 Thurallor-7095
 
457 Thurallor-7095
            local lp = Turbine.Gameplay.LocalPlayer:GetInstance();
458 Thurallor-7095
            local bags = lp:GetBackpack();
459 Thurallor-7095
            local inventory = {}, currentItemName;
460 Thurallor-7095
            for i = 1, bags:GetSize() do
461 Thurallor-7095
                table.insert(inventory, tostring(i));
462 Thurallor-7095
                if (i == info.bagSlot) then
463 Thurallor-7095
                    currentItemName = itemName;
464 Thurallor-7095
                end
465 Thurallor-7095
            end
466 16 Thurallor-7095
            top, dropDown = AddDropDown(top, inventory, tostring(info.bagSlot));
467 6 Thurallor-7095
            dropDown:SetWidth(50);
468 Thurallor-7095
            dropDown:SetLeft(65);
469 Thurallor-7095
            dropDown.ItemChanged = function(sender, args)
470 Thurallor-7095
                info.bagSlot = tonumber(args.Text);
471 16 Thurallor-7095
                self:UpdateBar();
472 6 Thurallor-7095
            end
473 Thurallor-7095
        elseif (string.match(info.type, "^Remove ")) then
474 Thurallor-7095
 
475 Thurallor-7095
            -- Allow the user to edit choose the item to be unequipped
476 Thurallor-7095
            top = top + 16; -- skip a line
477 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/EquipmentType") .. ":", Turbine.UI.Color.Goldenrod);
478 Thurallor-7095
 
479 Thurallor-7095
            local currentItem = string.sub(info.type, 8);
480 Thurallor-7095
            local prevContext = L:SetContext("/SequenceEditor/EquipmentSlots");
481 Thurallor-7095
            local eqSlots, localEqSlots = L:GetItems(), {};
482 Thurallor-7095
            for slot in values(eqSlots) do
483 Thurallor-7095
                table.insert(localEqSlots, L:GetText(slot));
484 Thurallor-7095
            end
485 Thurallor-7095
            table.sort(localEqSlots);
486 Thurallor-7095
            local dropDown;
487 16 Thurallor-7095
            top, dropDown = AddDropDown(top, localEqSlots, L:GetText(currentItem));
488 6 Thurallor-7095
            dropDown.ItemChanged = function(sender, args)
489 Thurallor-7095
                for slot in values(eqSlots) do
490 Thurallor-7095
                    if (L:GetText(slot) == args.Text) then
491 Thurallor-7095
                        self:CreateRemovalSlot(s, slot, info.bagSlot);
492 Thurallor-7095
                        break;
493 Thurallor-7095
                    end
494 Thurallor-7095
                end
495 Thurallor-7095
            end
496 16 Thurallor-7095
        elseif (info.type == "If") then
497 Thurallor-7095
 
498 Thurallor-7095
            -- Allow the user to specify the conditional expression
499 Thurallor-7095
            top = top + 16; -- skip a line
500 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/Condition") .. ":", Turbine.UI.Color.Goldenrod);
501 Thurallor-7095
 
502 Thurallor-7095
            local prevContext = L:SetContext("/SequenceEditor/ConditionTypes");
503 Thurallor-7095
            local condInfo = {
504 20 Thurallor-7095
                ["Always"] =                      { expr = "return true;" };
505 Thurallor-7095
                ["Never"] =                       { expr = "return false;" };
506 Thurallor-7095
                ["SkillReady"] =                  {  arg = "skill";
507 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.SkillReady(<skill>));" };
508 Thurallor-7095
                ["SkillNotReady"] =               {  arg = "skill";
509 Thurallor-7095
                                                    expr = "return (not Thurallor.Utils.Watcher.SkillReady(<skill>));" };
510 Thurallor-7095
                ["PlayerEffectDisease"] =         { expr = "return Thurallor.Utils.Watcher.PlayerHasEffectCategory(Turbine.Gameplay.EffectCategory.Disease);" };
511 Thurallor-7095
                ["PlayerEffectFear"] =            { expr = "return Thurallor.Utils.Watcher.PlayerHasEffectCategory(Turbine.Gameplay.EffectCategory.Fear);" };
512 Thurallor-7095
                ["PlayerEffectPoison"] =          { expr = "return Thurallor.Utils.Watcher.PlayerHasEffectCategory(Turbine.Gameplay.EffectCategory.Poison);" };
513 Thurallor-7095
                ["PlayerEffectWound"] =           { expr = "return Thurallor.Utils.Watcher.PlayerHasEffectCategory(Turbine.Gameplay.EffectCategory.Wound);" };
514 Thurallor-7095
                ["PlayerEffectOther"] =           {  arg = "effect";
515 Thurallor-7095
                                                    expr = "return Thurallor.Utils.Watcher.PlayerHasEffect(<effect>);" };
516 Thurallor-7095
                ["NotPlayerEffectOther"] =        {  arg = "effect";
517 Thurallor-7095
                                                    expr = "return (not Thurallor.Utils.Watcher.PlayerHasEffect(<effect>));" };
518 23 Thurallor-7095
-- Target effects tracking is so buggy as to be useless.  Hoping Turbine addresses this bug soon.
519 Thurallor-7095
--                ["TargetEffectDisease"] =         { expr = "return Thurallor.Utils.Watcher.TargetHasEffectCategory(Turbine.Gameplay.EffectCategory.Disease);" };
520 Thurallor-7095
--                ["TargetEffectFear"] =            { expr = "return Thurallor.Utils.Watcher.TargetHasEffectCategory(Turbine.Gameplay.EffectCategory.Fear);" };
521 Thurallor-7095
--                ["TargetEffectPoison"] =          { expr = "return Thurallor.Utils.Watcher.TargetHasEffectCategory(Turbine.Gameplay.EffectCategory.Poison);" };
522 Thurallor-7095
--                ["TargetEffectWound"] =           { expr = "return Thurallor.Utils.Watcher.TargetHasEffectCategory(Turbine.Gameplay.EffectCategory.Wound);" };
523 Thurallor-7095
--                ["TargetEffectOther"] =           {  arg = "effect";
524 Thurallor-7095
--                                                    expr = "return Thurallor.Utils.Watcher.TargetHasEffect(<effect>);" };
525 Thurallor-7095
--                ["NotTargetEffectOther"] =        {  arg = "effect";
526 Thurallor-7095
--                                                    expr = "return (not Thurallor.Utils.Watcher.TargetHasEffect(<effect>));" };
527 20 Thurallor-7095
                ["PlayerMorale < x"] =            {  arg = "x";
528 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetMorale() < <x>)" };
529 Thurallor-7095
                ["PlayerMorale < x%"] =           {  arg = "x";
530 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetMorale() < player:GetBaseMaxMorale() * <x> / 100)" };
531 Thurallor-7095
                ["PlayerMorale > x"] =            {  arg = "x";
532 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetMorale() > <x>)" };
533 Thurallor-7095
                ["PlayerMorale > x%"] =           {  arg = "x";
534 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetMorale() > player:GetBaseMaxMorale() * <x> / 100)" };
535 Thurallor-7095
                ["TargetMorale < x"] =            {  arg = "x";
536 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and (target:GetMorale() < <x>))" };
537 Thurallor-7095
                ["TargetMorale < x%"] =           {  arg = "x";
538 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and (target:GetMorale() < target:GetBaseMaxMorale() * <x> / 100))" };
539 Thurallor-7095
                ["TargetMorale > x"] =            {  arg = "x";
540 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and (target:GetMorale() > <x>))" };
541 Thurallor-7095
                ["TargetMorale > x%"] =           {  arg = "x";
542 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and (target:GetMorale() > target:GetBaseMaxMorale() * <x> / 100))" };
543 Thurallor-7095
                ["PlayerPower < x"] =             {  arg = "x";
544 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetPower() < <x>)" };
545 Thurallor-7095
                ["PlayerPower < x%"] =            {  arg = "x";
546 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetPower() < player:GetBaseMaxPower() * <x> / 100)" };
547 Thurallor-7095
                ["PlayerPower > x"] =             {  arg = "x";
548 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetPower() > <x>)" };
549 Thurallor-7095
                ["PlayerPower > x%"] =            {  arg = "x";
550 Thurallor-7095
                                                    expr = "local _, player = ...; return (player:GetPower() > player:GetBaseMaxPower() * <x> / 100)" };
551 Thurallor-7095
                ["TargetPower < x"] =             {  arg = "x";
552 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and (target:GetPower() < <x>))" };
553 Thurallor-7095
                ["TargetPower < x%"] =            {  arg = "x";
554 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and (target:GetPower() < target:GetBaseMaxPower() * <x> / 100))" };
555 Thurallor-7095
                ["TargetPower > x"] =             {  arg = "x";
556 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and (target:GetPower() > <x>)" };
557 Thurallor-7095
                ["TargetPower > x%"] =            {  arg = "x";
558 Thurallor-7095
                                                    expr = "local _, player = ...; local target = player:GetTarget(); return (target and (target:GetPower() > target:GetBaseMaxPower() * <x> / 100))" };
559 Thurallor-7095
                ["BeorningPlayerWrath < x%"] =    {  arg = "x";
560 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetWrath and (attribs:GetWrath() < <x>);" };
561 Thurallor-7095
                ["BeorningPlayerWrath > x%"] =    {  arg = "x";
562 Thurallor-7095
                                                    expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.GetWrath and (attribs:GetWrath() > <x>);" };
563 Thurallor-7095
                ["BeorningInBearForm"] =          { expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.IsInBearForm and attribs:IsInBearForm();" };
564 Thurallor-7095
                ["BeorningNotInBearForm"] =       { expr = "local _, player = ...; local attribs = player:GetClassAttributes(); return attribs.IsInBearForm and (not attribs:IsInBearForm());" };
565 Thurallor-7095
                ["ItemEquipped"] =                {  arg = { "eqItemName", "eqSlot" };
566 Thurallor-7095
                                                    expr = "return IsEquipped(<eqItemName>, <eqSlot>);" };
567 Thurallor-7095
                ["ItemNotEquipped"] =             {  arg = { "eqItemName", "eqSlot" };
568 Thurallor-7095
                                                    expr = "return (not IsEquipped(<eqItemName>, <eqSlot>));" };
569 30 Thurallor-7095
                ["ItemQuantity > x"] =            {  arg = { "stackItemName", "x" };
570 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.GetItemQuantity(<stackItemName>) > <x>);" };
571 Thurallor-7095
                ["ItemQuantity < x"] =            {  arg = { "stackItemName", "x" };
572 Thurallor-7095
                                                    expr = "return (Thurallor.Utils.Watcher.GetItemQuantity(<stackItemName>) < <x>);" };
573 20 Thurallor-7095
                ["LuaScript"] =                   {  arg = "script";
574 Thurallor-7095
                                                    expr = "<script>" };
575 16 Thurallor-7095
            };
576 Thurallor-7095
            local condNames = {};
577 Thurallor-7095
            for k in keys(condInfo) do
578 Thurallor-7095
                table.insert(condNames, L:GetText(k));
579 Thurallor-7095
            end
580 Thurallor-7095
            table.sort(condNames);
581 Thurallor-7095
 
582 20 Thurallor-7095
            local function SwitchArgs(arg)
583 16 Thurallor-7095
                if (not info.condArgs) then
584 Thurallor-7095
                    info.condArgs = {};
585 Thurallor-7095
                end
586 Thurallor-7095
                if (not arg) then
587 Thurallor-7095
                    info.condArgs = nil;
588 Thurallor-7095
                elseif ((arg == "x") and not info.condArgs.x) then
589 Thurallor-7095
                    info.condArgs = { x = 0 };
590 Thurallor-7095
                elseif ((arg == "skill") and not info.condArgs.skill) then
591 Thurallor-7095
                    info.condArgs = { skill = 0 };
592 20 Thurallor-7095
                elseif ((arg == "effect") and not info.condArgs.effect) then
593 22 Thurallor-7095
                    info.condArgs = { effect = "nil" };
594 16 Thurallor-7095
                elseif ((arg == "script") and not info.condArgs.script) then
595 Thurallor-7095
                    if (info.condExpr) then
596 Thurallor-7095
                        local script = info.condExpr;
597 Thurallor-7095
                        if (info.condArgs) then
598 Thurallor-7095
                            for name, value in pairs(info.condArgs) do
599 Thurallor-7095
                                script = string.gsub(script, "<" .. name .. ">", tostring(value));
600 Thurallor-7095
                            end
601 Thurallor-7095
                        end
602 Thurallor-7095
                        info.condArgs = { script = script };
603 Thurallor-7095
                    else
604 Thurallor-7095
                        info.condArgs = { script = "return true;" };
605 Thurallor-7095
                    end
606 20 Thurallor-7095
                elseif (type(arg) == "table") then
607 Thurallor-7095
                    -- Multiple args
608 Thurallor-7095
                    local prevArgs = info.condArgs;
609 Thurallor-7095
                    info.condArgs = {};
610 Thurallor-7095
                    for argName in values(arg) do
611 Thurallor-7095
                        if (prevArgs[argName]) then
612 Thurallor-7095
                            info.condArgs[argName] = prevArgs[argName];
613 16 Thurallor-7095
                        end
614 20 Thurallor-7095
                        if ((argName == "eqItemName") and not info.condArgs.eqItemName) then
615 Thurallor-7095
                            info.condArgs.eqItemName = "nil";
616 30 Thurallor-7095
                        elseif ((argName == "stackItemName") and not info.condArgs.stackItemName) then
617 Thurallor-7095
                            info.condArgs.stackItemName = "nil";
618 20 Thurallor-7095
                        elseif ((argName == "eqSlot") and not info.condArgs.eqSlot) then
619 Thurallor-7095
                            info.condArgs.eqSlot = "nil";
620 30 Thurallor-7095
                        elseif ((argName == "x") and not info.condArgs.x) then
621 Thurallor-7095
                            info.condArgs.x  = 0;
622 16 Thurallor-7095
                        end
623 Thurallor-7095
                    end
624 Thurallor-7095
                end
625 20 Thurallor-7095
                info.condExpr = condInfo[info.condName].expr;
626 16 Thurallor-7095
            end
627 Thurallor-7095
 
628 Thurallor-7095
            local dropDown;
629 Thurallor-7095
            top, dropDown = AddDropDown(top, condNames, L:GetText(info.condName));
630 Thurallor-7095
            dropDown:SetExpandedWidth(300);
631 Thurallor-7095
            dropDown:SetAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
632 Thurallor-7095
            dropDown.ItemChanged = function(sender, args)
633 Thurallor-7095
                local prevContext = L:SetContext("/SequenceEditor/ConditionTypes");
634 Thurallor-7095
                info.condName = L:GetItem(args.Text);
635 Thurallor-7095
                L:SetContext(prevContext);
636 Thurallor-7095
                local arg = condInfo[info.condName].arg;
637 20 Thurallor-7095
                SwitchArgs(arg);
638 16 Thurallor-7095
                self:UpdateBar();
639 20 Thurallor-7095
                self:DisplaySlot(self.selectedSlot);
640 16 Thurallor-7095
            end
641 Thurallor-7095
 
642 20 Thurallor-7095
            SwitchArgs(condInfo[info.condName].arg);
643 Thurallor-7095
            L:SetContext(prevContext);
644 16 Thurallor-7095
 
645 20 Thurallor-7095
            -- Display additional arguments depending on the current condition type
646 Thurallor-7095
            if (info.condArgs) then
647 30 Thurallor-7095
                if (info.condArgs.stackItemName) then
648 Thurallor-7095
                    local function GetStackableItems()
649 Thurallor-7095
                        local hash = {};
650 Thurallor-7095
                        local backpack = self.manager.player:GetBackpack();
651 Thurallor-7095
                        for i = 1, backpack:GetSize(), 1 do
652 Thurallor-7095
                            local item = backpack:GetItem(i);
653 Thurallor-7095
                            if (item and (item:GetMaxStackSize() > 1)) then
654 Thurallor-7095
                                hash[item:GetName()] = true;
655 Thurallor-7095
                            end
656 Thurallor-7095
                        end
657 Thurallor-7095
                        local items = {};
658 Thurallor-7095
                        for key in sorted_keys(hash) do
659 Thurallor-7095
                            table.insert(items, key);
660 Thurallor-7095
                        end
661 Thurallor-7095
                        return items;
662 Thurallor-7095
                    end
663 Thurallor-7095
                    local stackItemNames = GetStackableItems();
664 Thurallor-7095
                    local dropDown;
665 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, stackItemNames);
666 Thurallor-7095
                    dropDown:SetExpandedWidth(400);
667 Thurallor-7095
                    dropDown.ItemChanged = function(sender, args)
668 Thurallor-7095
                        info.condArgs.stackItemName = "\"" .. args.Text .. "\"";
669 Thurallor-7095
                        self:UpdateBar();
670 Thurallor-7095
                    end
671 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
672 Thurallor-7095
                    if (info.condArgs.stackItemName ~= "nil") then
673 Thurallor-7095
                        local name = string.sub(info.condArgs.stackItemName, 2, -2);
674 Thurallor-7095
                        dropDown:SetText(name);
675 Thurallor-7095
                    end
676 Thurallor-7095
                end
677 20 Thurallor-7095
                if (info.condArgs.x) then
678 Thurallor-7095
                    local _, xLabel = AddLabel(top + 3, "", Turbine.UI.Color.DarkGoldenrod);
679 Thurallor-7095
                    xLabel:SetWidth(30);
680 Thurallor-7095
                    xLabel:SetFont(Turbine.UI.Lotro.Font.Verdana16);
681 Thurallor-7095
                    xLabel:SetText("x =");
682 Thurallor-7095
 
683 Thurallor-7095
                    local xField;
684 Thurallor-7095
                    top, xField = AddTextBox(top + 2, "", Turbine.UI.Color.White);
685 Thurallor-7095
                    xField:SetLeft(30);
686 33 Thurallor-7095
                    xField:SetWidth(slotTabWidth - 50);
687 20 Thurallor-7095
                    xField.TextChanged = function(sender)
688 Thurallor-7095
                        info.condArgs.x = tonumber(sender:GetText());
689 23 Thurallor-7095
                        if (not info.condArgs.x) then
690 Thurallor-7095
                            info.condArgs.x = 0;
691 Thurallor-7095
                        end
692 20 Thurallor-7095
                        self:UpdateBar();
693 Thurallor-7095
                    end
694 Thurallor-7095
                    xField:SetText(info.condArgs.x);
695 Thurallor-7095
                    xLabel:SetParent(self.slotProperties);
696 Thurallor-7095
                    xField:SetText(tostring(info.condArgs.x));
697 Thurallor-7095
                    xField:SetParent(self.slotProperties);
698 Thurallor-7095
                end
699 Thurallor-7095
                if (info.condArgs.skill) then
700 Thurallor-7095
                    local skills = Thurallor.Utils.Watcher.GetSkillsInfo();
701 Thurallor-7095
                    local dropDown;
702 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, skills.names);
703 Thurallor-7095
                    dropDown:SetExpandedWidth(300);
704 Thurallor-7095
                    dropDown.ItemChanged = function(sender, args)
705 Thurallor-7095
                        local skills = Thurallor.Utils.Watcher.GetSkillsInfo();
706 Thurallor-7095
                        local skill = skills.byName[args.Text];
707 Thurallor-7095
                        info.condArgs.skill = 0;
708 Thurallor-7095
                        if (skill) then
709 Thurallor-7095
                            info.condArgs.skill = skill:GetSkillInfo():GetIconImageID();
710 Thurallor-7095
                        end
711 Thurallor-7095
                        self:UpdateBar();
712 Thurallor-7095
                    end
713 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
714 Thurallor-7095
                    local skill = skills.byIcon[info.condArgs.skill];
715 Thurallor-7095
                    if (skill) then
716 Thurallor-7095
                        local name = skill:GetSkillInfo():GetName();
717 Thurallor-7095
                        dropDown:SetText(name);
718 Thurallor-7095
                    end
719 Thurallor-7095
                end
720 Thurallor-7095
                if (info.condArgs.effect) then
721 Thurallor-7095
                    local effectNames = Thurallor.Utils.Watcher.GetKnownEffectNames();
722 Thurallor-7095
                    if (#effectNames >= 1) then
723 Thurallor-7095
                        table.insert(effectNames, 1, L:GetText("/SequenceEditor/ConditionTypes/OtherEffect"));
724 Thurallor-7095
                        local dropDown;
725 Thurallor-7095
                        top, dropDown = AddDropDown(top + 2, effectNames);
726 Thurallor-7095
                        dropDown:SetExpandedWidth(300);
727 23 Thurallor-7095
                        function dropDown.ItemChanged(ctl, args)
728 22 Thurallor-7095
                            local effectNames = Thurallor.Utils.Watcher.GetKnownEffectNames();
729 Thurallor-7095
                            local other = L:GetText("/SequenceEditor/ConditionTypes/OtherEffect");
730 Thurallor-7095
                            table.insert(effectNames, 1, other);
731 20 Thurallor-7095
                            if (args.Text == other) then
732 Thurallor-7095
                                local ok = L:GetText("/ExportWindow/OK");
733 Thurallor-7095
                                local window = Alert(other,
734 Thurallor-7095
                                    L:GetText("/SequenceEditor/ConditionTypes/OtherEffectHelp"),
735 Thurallor-7095
                                    ok);
736 Thurallor-7095
                                CenterWindow(window);
737 Thurallor-7095
                                window.label:SetFont(Turbine.UI.Lotro.Font.Verdana14);
738 Thurallor-7095
                                window.label:SetText(window.label:GetText());
739 Thurallor-7095
                                window.buttons[ok].Click = function()
740 Thurallor-7095
                                    window:Close();
741 Thurallor-7095
                                end
742 Thurallor-7095
                                dropDown:SetText(string.gsub(info.condArgs.effect, "\"", ""));
743 22 Thurallor-7095
                            elseif (not args.Text) then
744 Thurallor-7095
                                return;
745 20 Thurallor-7095
                            else
746 Thurallor-7095
                                info.condArgs.effect = "\"" .. args.Text .. "\"";
747 Thurallor-7095
                                self:UpdateBar();
748 Thurallor-7095
                            end
749 Thurallor-7095
                        end
750 Thurallor-7095
                        dropDown:SetParent(self.slotProperties);
751 Thurallor-7095
                        local effect = info.condArgs.effect;
752 22 Thurallor-7095
                        if (effect == "nil") then
753 20 Thurallor-7095
                            effect = effectNames[2];
754 22 Thurallor-7095
                        else
755 Thurallor-7095
                            effect = string.gsub(effect, "\"", "")
756 20 Thurallor-7095
                        end
757 22 Thurallor-7095
                        dropDown:SetText(effect);
758 Thurallor-7095
                        dropDown:ItemChanged({Text = effect});
759 20 Thurallor-7095
                    end
760 Thurallor-7095
                end
761 Thurallor-7095
                if (info.condArgs.script) then
762 Thurallor-7095
                    top, self.scriptBox = AddTextBox(top + 2, info.condArgs.script, Turbine.UI.Color.White)
763 Thurallor-7095
                    self.scriptBox:SetFont(Turbine.UI.Lotro.Font.Verdana10);
764 Thurallor-7095
                    self.scriptBox.prevText = nil;
765 Thurallor-7095
                    self.scriptBox:SetWantsUpdates(true);
766 Thurallor-7095
                    self.scriptBox.Update = function(sender)
767 Thurallor-7095
                        local script = sender:GetText();
768 Thurallor-7095
                        if (script ~= sender.prevText) then
769 Thurallor-7095
                            local success, errorMsg = loadstring(script, "Slot " .. tostring(s));
770 Thurallor-7095
                            if (success) then
771 Thurallor-7095
                                self.scriptBox:SetBackColor(Turbine.UI.Color.Black);
772 Thurallor-7095
                                info.condArgs.script = script;
773 Thurallor-7095
                                self:UpdateBar();
774 Thurallor-7095
                            else
775 Thurallor-7095
                                self.scriptBox:SetBackColor(Turbine.UI.Color.Red);
776 Thurallor-7095
                            end
777 Thurallor-7095
                        end
778 Thurallor-7095
                        sender.prevText = script;
779 Thurallor-7095
                    end
780 Thurallor-7095
                end
781 Thurallor-7095
                if (info.condArgs.eqItemName) then
782 Thurallor-7095
                    local function GetEquippableItems()
783 Thurallor-7095
                        local hash = { [L:GetText("/SequenceEditor/AnyEqItem")] = true };
784 Thurallor-7095
                        for container in values({ self.manager.player:GetBackpack(), self.manager.player:GetEquipment() }) do
785 Thurallor-7095
                            for i = 1, container:GetSize(), 1 do
786 Thurallor-7095
                                local item = container:GetItem(i);
787 30 Thurallor-7095
                                if (item and (item:GetMaxStackSize() == 1)) then
788 Thurallor-7095
                                    hash[item:GetName()] = true;
789 20 Thurallor-7095
                                end
790 Thurallor-7095
                            end
791 Thurallor-7095
                        end
792 Thurallor-7095
                        local items = {};
793 Thurallor-7095
                        for key in sorted_keys(hash) do
794 Thurallor-7095
                            table.insert(items, key);
795 Thurallor-7095
                        end
796 Thurallor-7095
                        return items;
797 Thurallor-7095
                    end
798 Thurallor-7095
                    local eqItemNames = GetEquippableItems();
799 Thurallor-7095
                    local anyItem = L:GetText("/SequenceEditor/AnyEqItem");
800 Thurallor-7095
                    local dropDown;
801 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, eqItemNames);
802 Thurallor-7095
                    dropDown:SetExpandedWidth(400);
803 Thurallor-7095
                    dropDown.ItemChanged = function(sender, args)
804 Thurallor-7095
                        local anyItem = L:GetText("/SequenceEditor/AnyEqItem");
805 Thurallor-7095
                        if (args.Text == anyItem) then
806 Thurallor-7095
                            info.condArgs.eqItemName = "nil";
807 Thurallor-7095
                        else
808 Thurallor-7095
                            info.condArgs.eqItemName = "\"" .. args.Text .. "\"";
809 Thurallor-7095
                        end
810 Thurallor-7095
                        self:UpdateBar();
811 Thurallor-7095
                    end
812 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
813 Thurallor-7095
                    if (info.condArgs.eqItemName == "nil") then
814 Thurallor-7095
                        dropDown:SetText(anyItem);
815 Thurallor-7095
                    else
816 Thurallor-7095
                        local name = string.sub(info.condArgs.eqItemName, 2, -2);
817 Thurallor-7095
                        dropDown:SetText(name);
818 Thurallor-7095
                    end
819 Thurallor-7095
                end
820 Thurallor-7095
                if (info.condArgs.eqSlot) then
821 Thurallor-7095
                    local prevContext = L:SetContext("/SequenceEditor/EquipmentSlots");
822 Thurallor-7095
                    local eqSlotNames, localEqSlotNames, eqSlotValues = L:GetItems(), {}, {};
823 Thurallor-7095
                    for slot in values(eqSlotNames) do
824 Thurallor-7095
                        local text = L:GetText(slot);
825 Thurallor-7095
                        table.insert(localEqSlotNames, text);
826 Thurallor-7095
                        eqSlotValues[text] = tostring(Turbine.Gameplay.Equipment[slot]);
827 Thurallor-7095
                    end
828 Thurallor-7095
                    local anySlot = L:GetText("/SequenceEditor/AnyEqSlot");
829 Thurallor-7095
                    eqSlotValues[anySlot] = "nil";
830 Thurallor-7095
                    table.insert(localEqSlotNames, anySlot);
831 Thurallor-7095
                    table.sort(localEqSlotNames);
832 Thurallor-7095
                    local dropDown;
833 Thurallor-7095
                    top, dropDown = AddDropDown(top + 2, localEqSlotNames);
834 Thurallor-7095
                    dropDown.ItemChanged = function(sender, args)
835 Thurallor-7095
                        info.condArgs.eqSlot = eqSlotValues[args.Text];
836 Thurallor-7095
                        self:UpdateBar();
837 Thurallor-7095
                    end
838 Thurallor-7095
                    dropDown:SetParent(self.slotProperties);
839 Thurallor-7095
                    if (info.condArgs.eqSlot == "nil") then
840 Thurallor-7095
                        dropDown:SetText(anySlot);
841 Thurallor-7095
                    else
842 Thurallor-7095
                        local slotName = Search(Turbine.Gameplay.Equipment, tonumber(info.condArgs.eqSlot));
843 Thurallor-7095
                        dropDown:SetText(L:GetText(slotName));
844 Thurallor-7095
                    end
845 Thurallor-7095
                    L:SetContext(prevContext);
846 Thurallor-7095
                end
847 Thurallor-7095
            end
848 16 Thurallor-7095
        elseif (info.type == "Include") then
849 Thurallor-7095
            top = top + 16; -- skip a line
850 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/OtherSequence") .. ":", Turbine.UI.Color.Goldenrod);
851 Thurallor-7095
            local function GetObjectTree()
852 Thurallor-7095
                -- Get a list of all bar IDs.
853 Thurallor-7095
                local objectIDs = self.manager:FindAllDescendentIDs(nil, true, false);
854 Thurallor-7095
 
855 Thurallor-7095
                -- Including self doesn't make sense, so prevent that.
856 Thurallor-7095
                local foundSelf;
857 Thurallor-7095
                for o = 1, #objectIDs, 1 do
858 Thurallor-7095
                    local object = self.manager:GetObject(objectIDs[o]);
859 Thurallor-7095
                    if (object == self.bar) then
860 Thurallor-7095
                        foundSelf = o;
861 Thurallor-7095
                    end
862 Thurallor-7095
                end
863 Thurallor-7095
                if (foundSelf) then
864 Thurallor-7095
                    table.remove(objectIDs, foundSelf);
865 Thurallor-7095
                end
866 Thurallor-7095
 
867 Thurallor-7095
                -- Add nonempty groups.
868 17 Thurallor-7095
                local groupIDs = {};
869 Thurallor-7095
                for o = 1, #objectIDs, 1 do
870 Thurallor-7095
                    local objectID = objectIDs[o];
871 Thurallor-7095
                    local object = self.manager:GetObject(objectID);
872 Thurallor-7095
                    while (object.parent) do
873 Thurallor-7095
                        object = object.parent;
874 Thurallor-7095
                        objectID = object:GetID();
875 Thurallor-7095
                        if (objectID) then
876 Thurallor-7095
                            groupIDs[objectID] = 1;
877 16 Thurallor-7095
                        end
878 Thurallor-7095
                    end
879 17 Thurallor-7095
                end
880 Thurallor-7095
                for groupID in keys(groupIDs) do
881 Thurallor-7095
                    table.insert(objectIDs, groupID);
882 Thurallor-7095
                end
883 16 Thurallor-7095
 
884 Thurallor-7095
                -- Create item list for PullDownMenu.
885 Thurallor-7095
                local items = {};
886 Thurallor-7095
                for o = 1, #objectIDs, 1 do
887 Thurallor-7095
                    local objectID = objectIDs[o];
888 Thurallor-7095
                    local object = self.manager:GetObject(objectID);
889 Thurallor-7095
                    local parentID = nil;
890 Thurallor-7095
                    if (object.parent) then
891 Thurallor-7095
                        parentID = object.parent:GetID();
892 Thurallor-7095
                    end
893 Thurallor-7095
                    table.insert(items, { objectID, object:GetName(), parentID });
894 Thurallor-7095
                end
895 Thurallor-7095
                return items;
896 Thurallor-7095
            end
897 Thurallor-7095
            local pullDown;
898 Thurallor-7095
            top, pullDown = AddPullDown(top, GetObjectTree(), info.include);
899 Thurallor-7095
            pullDown.SelectionChanged = function(sender, id)
900 Thurallor-7095
                info.include = id;
901 Thurallor-7095
                self:UpdateBar();
902 20 Thurallor-7095
                self:SelectSlot(s);
903 16 Thurallor-7095
            end
904 20 Thurallor-7095
            AddCallback(pullDown, "MouseClick", function(sender, args)
905 Thurallor-7095
                -- Right-click displays the bar menu.
906 Thurallor-7095
                if (args.Button == Turbine.UI.MouseButton.Right) then
907 Thurallor-7095
                    if (info.include) then
908 Thurallor-7095
                        local bar = self.manager.objects[info.include];
909 Thurallor-7095
                        if (bar) then
910 Thurallor-7095
                            bar:ShowSettingsMenu();
911 Thurallor-7095
                        end
912 Thurallor-7095
                    end
913 Thurallor-7095
                end
914 Thurallor-7095
            end);
915 6 Thurallor-7095
 
916 20 Thurallor-7095
            -- Add the "unlink" button if a sequence is selected.
917 Thurallor-7095
            if (info.include) then
918 Thurallor-7095
                local button;
919 Thurallor-7095
                local text, width = L:GetText("/SequenceEditor/Unlink"), L:GetNumber("/SequenceEditor/UnlinkButtonWidth");
920 Thurallor-7095
                top, button = AddButton(top, width, text);
921 Thurallor-7095
                AddCallback(button, "Click", function()
922 Thurallor-7095
                    self:UnlinkIncludedSequence(s);
923 Thurallor-7095
                end);
924 Thurallor-7095
            end
925 Thurallor-7095
        end
926 Thurallor-7095
 
927 16 Thurallor-7095
        -- Allow the user to specify whether activation is click-based or automatic.
928 Thurallor-7095
        if (info.type ~= "Include") then
929 6 Thurallor-7095
            top = top + 16; -- skip a line
930 Thurallor-7095
            top = AddLabel(top, L:GetText("/SequenceEditor/Activation") .. ":", Turbine.UI.Color.Goldenrod);
931 Thurallor-7095
            local button1, button2;
932 Thurallor-7095
            top, button1 = AddRadioButton(top, L:GetText("/SequenceEditor/WithLeftClick"), Turbine.UI.Color.DarkGoldenrod, (not info.automatic));
933 Thurallor-7095
            top, button2 = AddRadioButton(top, L:GetText("/SequenceEditor/Automatic"), Turbine.UI.Color.DarkGoldenrod, info.automatic);
934 Thurallor-7095
            Thurallor.UI.RadioButton.LinkPeers({button1, button2});
935 Thurallor-7095
 
936 Thurallor-7095
            button1.Clicked = function()
937 Thurallor-7095
                info.automatic = nil;
938 16 Thurallor-7095
                self:UpdateBar();
939 6 Thurallor-7095
            end
940 Thurallor-7095
            button2.Clicked = function()
941 Thurallor-7095
                info.automatic = true;
942 16 Thurallor-7095
                self:UpdateBar();
943 6 Thurallor-7095
            end
944 2 Thurallor-7095
        end
945 Thurallor-7095
    end
946 Thurallor-7095
 
947 7 Thurallor-7095
    -- Allow the user to optionally overlay some text
948 15 Thurallor-7095
    top = top + 16; -- skip a line
949 Thurallor-7095
    top = AddLabel(top, L:GetText("/SequenceEditor/TextOverlay") .. ":", Turbine.UI.Color.Goldenrod);
950 Thurallor-7095
    local textBox;
951 Thurallor-7095
    top, textBox = AddTextBox(top, info.textOverlay, Turbine.UI.Color.White);
952 Thurallor-7095
    textBox:SetFont(Turbine.UI.Lotro.Font.Verdana12);
953 Thurallor-7095
    textBox.TextChanged = function(sender, args)
954 Thurallor-7095
        local text = sender:GetText();
955 Thurallor-7095
        if (text == "") then
956 Thurallor-7095
            text = nil;
957 7 Thurallor-7095
        end
958 15 Thurallor-7095
        info.textOverlay = text;
959 Thurallor-7095
        UpdateIcon();
960 16 Thurallor-7095
        self:UpdateBar();
961 2 Thurallor-7095
    end
962 Thurallor-7095
 
963 Thurallor-7095
    self.slotProperties:SetHeight(top);
964 15 Thurallor-7095
    self:SetMinimumHeight(top + 110);
965 2 Thurallor-7095
end
966 Thurallor-7095
 
967 13 Thurallor-7095
function SequenceEditor:FindSlotAtPosition(x, y, drawCaret)
968 7 Thurallor-7095
    local originX, originY = self.slotPanel:GetParent():PointToScreen(self.slotPanel:GetPosition());
969 13 Thurallor-7095
    local relX, relY = x - originX, y - originY + 3;
970 Thurallor-7095
    local posX, posY = 1 + math.floor(relX / self.slotSize + 0.5), 1 + math.floor(relY / self.slotSize);
971 7 Thurallor-7095
    local s = nil;
972 13 Thurallor-7095
    if ((posX >= 1) and (posX <= self.slotsWide + 1) and (posY >= 1) and (posY <= self.slotsHigh)) then
973 7 Thurallor-7095
        s = ((posY - 1) * self.slotsWide) + posX;
974 Thurallor-7095
    end
975 13 Thurallor-7095
    if ((posX == self.slotsWide + 1) and (posY == self.slotsHigh)) then
976 Thurallor-7095
        s = nil;
977 Thurallor-7095
    end
978 7 Thurallor-7095
 
979 Thurallor-7095
    -- Update caret position.
980 Thurallor-7095
    if ((not drawCaret) or (not s)) then
981 Thurallor-7095
        -- Hide carets in all Sequence Editors
982 Thurallor-7095
        for editor in keys(SequenceEditor.instances) do
983 Thurallor-7095
            if (editor.caret) then
984 Thurallor-7095
                editor.caret:SetParent(nil);
985 Thurallor-7095
                editor.caret = nil;
986 Thurallor-7095
            end
987 Thurallor-7095
        end
988 Thurallor-7095
    else
989 Thurallor-7095
        if (not self.caret) then
990 Thurallor-7095
            self.caret = Turbine.UI.Control();
991 Thurallor-7095
            self.caret:SetParent(self.slotPanel);
992 Thurallor-7095
            self.caret:SetBackground(resources.Icon.Caret);
993 Thurallor-7095
            self.caret:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
994 Thurallor-7095
            self.caret:SetSize(3, 36)
995 Thurallor-7095
        end
996 Thurallor-7095
        self.caret:SetPosition((posX - 1) * self.slotSize, (posY - 1) * self.slotSize);
997 Thurallor-7095
    end
998 Thurallor-7095
 
999 Thurallor-7095
    return s;
1000 Thurallor-7095
end
1001 Thurallor-7095
 
1002 13 Thurallor-7095
function SequenceEditor:FindForeignSlotAtPosition(x, y, drawCaret)
1003 7 Thurallor-7095
 
1004 Thurallor-7095
    -- Find the frontmost SequenceEditor under the mouse cursor
1005 Thurallor-7095
    local frontEditor = self;
1006 Thurallor-7095
    local maxZ = -2147483648;
1007 Thurallor-7095
    for editor in keys(SequenceEditor.instances) do
1008 Thurallor-7095
        if (editor ~= self) then
1009 Thurallor-7095
            local left, top = editor:GetPosition();
1010 Thurallor-7095
            local width, height = editor:GetSize();
1011 13 Thurallor-7095
            if ((x >= left) and (x <= left + width) and (y >= top) and (y <= top + height)) then
1012 7 Thurallor-7095
                if (editor:GetZOrder() >= maxZ) then
1013 Thurallor-7095
                    frontEditor = editor;
1014 Thurallor-7095
                    maxZ = editor:GetZOrder();
1015 Thurallor-7095
                end
1016 Thurallor-7095
            end
1017 Thurallor-7095
        end
1018 Thurallor-7095
    end
1019 Thurallor-7095
 
1020 13 Thurallor-7095
    return frontEditor, frontEditor:FindSlotAtPosition(x, y, drawCaret);
1021 7 Thurallor-7095
end
1022 Thurallor-7095
 
1023 13 Thurallor-7095
function SequenceEditor:BuildSlot(slot, parent, object, left, top)
1024 Thurallor-7095
--Puts("BuildSlot(" .. tostring(slot) .. ", " .. tostring(parent) .. ", " .. tostring(object) .. ", " .. tostring(left) .. ", " .. tostring(top));
1025 2 Thurallor-7095
 
1026 Thurallor-7095
    -- Get slot info, or initialize to default
1027 13 Thurallor-7095
    local info = self.settings.sequenceItemInfo[slot];
1028 Thurallor-7095
    if (object) then
1029 Thurallor-7095
        -- Reuse the existing object
1030 Thurallor-7095
        object:SetParent(parent);
1031 Thurallor-7095
        object:SetInfo(info);
1032 Thurallor-7095
        object:SetPosition(left, top);
1033 Thurallor-7095
        object:SetNumLabel(slot);
1034 Thurallor-7095
        return object;
1035 2 Thurallor-7095
    end
1036 Thurallor-7095
 
1037 13 Thurallor-7095
    -- Need to create a new object
1038 Thurallor-7095
    object = Slot(info);
1039 Thurallor-7095
    object:SetPosition(left, top);
1040 Thurallor-7095
    object:SetNumLabel(slot);
1041 2 Thurallor-7095
    object:SetParent(parent);
1042 13 Thurallor-7095
    object:SetActionEnabled(false);
1043 Thurallor-7095
    object:SetAllowDrop(true);
1044 Thurallor-7095
    object:SetDraggable(true);
1045 2 Thurallor-7095
 
1046 7 Thurallor-7095
    -- Desired mouse behaviors:
1047 Thurallor-7095
    --   Left-click selects the slot and shows its properties in the "Slot" tab.
1048 Thurallor-7095
    --   Right-click displays the settings menu.
1049 Thurallor-7095
    --   Left-button-drag initiates a drag-and-drop (move) operation.
1050 2 Thurallor-7095
 
1051 13 Thurallor-7095
    object.ShortcutChanged = function(sender, shortcutType, shortcutData)
1052 Thurallor-7095
        local s = sender:GetNumLabel();
1053 2 Thurallor-7095
        self:ExtendSequenceTo(s);
1054 13 Thurallor-7095
        local info = sender:GetInfo();
1055 Thurallor-7095
        self.settings.sequenceItemInfo[s] = info;
1056 Thurallor-7095
 
1057 Thurallor-7095
        if (shortcutType == Turbine.UI.Lotro.ShortcutType.Alias) then
1058 7 Thurallor-7095
            info.textOverlay = string.gsub(info.Data, "^/", "");
1059 Thurallor-7095
            info.textOverlay = string.gsub(info.textOverlay, "%s.*$", "");
1060 Thurallor-7095
            info.background = self.settings.sequenceEditor.defaultIcon;
1061 13 Thurallor-7095
            sender:SetInfo(info);
1062 7 Thurallor-7095
        end
1063 13 Thurallor-7095
 
1064 16 Thurallor-7095
        self:UpdateBar();
1065 2 Thurallor-7095
        self:SelectSlot(s);
1066 Thurallor-7095
    end
1067 Thurallor-7095
 
1068 13 Thurallor-7095
    object.MouseClick = function(sender, args)
1069 2 Thurallor-7095
        -- Left-click selects the slot and shows its properties in the "Slot" tab.
1070 Thurallor-7095
        if (args.Button == Turbine.UI.MouseButton.Left) then
1071 13 Thurallor-7095
            self:SelectSlot(sender:GetNumLabel());
1072 2 Thurallor-7095
 
1073 Thurallor-7095
        -- Right-click displays the settings menu.
1074 Thurallor-7095
        elseif (args.Button == Turbine.UI.MouseButton.Right) then
1075 13 Thurallor-7095
            self.clickedItem = sender:GetNumLabel();
1076 2 Thurallor-7095
            self:ShowContextMenu();
1077 Thurallor-7095
        end
1078 Thurallor-7095
    end
1079 Thurallor-7095
 
1080 13 Thurallor-7095
    object.DropPositionValid = function(sender, left, top)
1081 Thurallor-7095
        local s = sender:GetNumLabel();
1082 Thurallor-7095
 
1083 Thurallor-7095
        -- Draw a "caret" showing where the slot will be inserted.
1084 Thurallor-7095
        local editor = self;
1085 Thurallor-7095
        local newSlot = self:FindSlotAtPosition(left, top, true);
1086 Thurallor-7095
        if (not newSlot) then
1087 Thurallor-7095
            editor, newSlot = self:FindForeignSlotAtPosition(left, top, true);
1088 7 Thurallor-7095
        end
1089 13 Thurallor-7095
        if ((editor == self) and ((newSlot == s) or (newSlot == s + 1))) then
1090 Thurallor-7095
            self:FindSlotAtPosition(0, 0, false); -- hide caret if returning to the same position
1091 Thurallor-7095
        end
1092 Thurallor-7095
        return newSlot; -- if newSlot is nil, a red "X" will be shown
1093 7 Thurallor-7095
    end
1094 Thurallor-7095
 
1095 13 Thurallor-7095
    object.DragDropComplete = function(sender, left, top)
1096 Thurallor-7095
        local s = sender:GetNumLabel();
1097 2 Thurallor-7095
 
1098 13 Thurallor-7095
        -- Select destination slot.  Hide the caret.
1099 Thurallor-7095
        local editor = self;
1100 Thurallor-7095
        local newSlot = self:FindSlotAtPosition(left, top, false);
1101 Thurallor-7095
        if (not newSlot) then
1102 Thurallor-7095
            editor, newSlot = self:FindForeignSlotAtPosition(left, top, false);
1103 Thurallor-7095
        end
1104 Thurallor-7095
 
1105 Thurallor-7095
        -- Do the move operation, and redraw.
1106 Thurallor-7095
        if (newSlot and (editor ~= self)) then
1107 Thurallor-7095
            editor:InsertSlot(newSlot, self.settings.sequenceItemInfo[s]);
1108 Thurallor-7095
            self:DeleteSlot(s);
1109 Thurallor-7095
        elseif (newSlot and (newSlot ~= s) and (newSlot ~= s + 1)) then
1110 Thurallor-7095
            self:MoveSlot(s, newSlot);
1111 Thurallor-7095
        else
1112 Thurallor-7095
            self:Redraw();
1113 Thurallor-7095
        end
1114 Thurallor-7095
    end
1115 Thurallor-7095
 
1116 2 Thurallor-7095
    return object;
1117 Thurallor-7095
end
1118 Thurallor-7095
 
1119 7 Thurallor-7095
function SequenceEditor:RebuildSlot(s, x, y, alreadyDisplaying)
1120 2 Thurallor-7095
    local oldObject = self.sequenceItems[s];
1121 Thurallor-7095
 
1122 Thurallor-7095
    -- If x and y aren't specified, then presumably the object has already been positioned previously
1123 Thurallor-7095
    if (x == nil) then
1124 Thurallor-7095
        x = oldObject.x;
1125 Thurallor-7095
        y = oldObject.y;
1126 Thurallor-7095
    end
1127 Thurallor-7095
    local left, top = self:GetSlotPosition(x, y);
1128 Thurallor-7095
 
1129 Thurallor-7095
    local newObject = self:BuildSlot(s, self.slotPanel, oldObject, left, top);
1130 Thurallor-7095
    newObject.x = x;
1131 Thurallor-7095
    newObject.y = y;
1132 Thurallor-7095
    self.sequenceItems[s] = newObject;
1133 Thurallor-7095
 
1134 7 Thurallor-7095
    if (not alreadyDisplaying and (self.selectedSlot == s)) then
1135 2 Thurallor-7095
        self:DisplaySlot(s);
1136 Thurallor-7095
    end
1137 Thurallor-7095
end
1138 Thurallor-7095
 
1139 Thurallor-7095
function SequenceEditor:SelectSlot(s)
1140 13 Thurallor-7095
--Puts("SelectSlot(" .. tostring(s) .. "): self.selectedSlot = " .. tostring(self.selectedSlot));
1141 2 Thurallor-7095
    if (self.selectedSlot) then
1142 13 Thurallor-7095
        local object = self.sequenceItems[self.selectedSlot];
1143 Thurallor-7095
        object:SetSelected(false);
1144 Thurallor-7095
        local info = self.settings.sequenceItemInfo[self.selectedSlot];
1145 Thurallor-7095
        if (info and (info.class == "Turbine.UI.Lotro.Quickslot") and (not info.type)) then
1146 2 Thurallor-7095
            -- Delete empty shortcut
1147 13 Thurallor-7095
            info.class = nil;
1148 2 Thurallor-7095
        end
1149 Thurallor-7095
    end
1150 16 Thurallor-7095
    for o = 1, #self.relatedSlots, 1 do
1151 Thurallor-7095
        local otherSlot, otherObject = unpack(self.relatedSlots[o]);
1152 Thurallor-7095
        otherObject:SetSelected(nil);
1153 Thurallor-7095
        self.relatedSlots[o] = nil;
1154 Thurallor-7095
    end
1155 2 Thurallor-7095
    if (s ~= nil) then
1156 7 Thurallor-7095
        local info = self.settings.sequenceItemInfo[s];
1157 13 Thurallor-7095
        if ((not info) or (not info.class)) then
1158 7 Thurallor-7095
            s = nil;
1159 Thurallor-7095
        else
1160 13 Thurallor-7095
            local object = self.sequenceItems[s];
1161 Thurallor-7095
            object:SetSelected(true);
1162 16 Thurallor-7095
            local sequence = self.bar:GetSequence();
1163 Thurallor-7095
            local barObject = sequence:GetSlot(sequence:GetNewIndex(s));
1164 Thurallor-7095
            if (barObject) then
1165 Thurallor-7095
                for otherSlot, _ in pairs({ifSlot = 1; elseSlot = 1; endIfSlot = 1}) do
1166 Thurallor-7095
                    if (barObject[otherSlot]) then
1167 Thurallor-7095
                        local otherObject = self.sequenceItems[sequence:GetOldIndex(barObject[otherSlot])];
1168 Thurallor-7095
                        otherObject:SetSelected(true, Turbine.UI.Color.Yellow);
1169 Thurallor-7095
                        table.insert(self.relatedSlots, {otherSlot, otherObject});
1170 Thurallor-7095
                    end
1171 Thurallor-7095
                end
1172 Thurallor-7095
            end
1173 7 Thurallor-7095
        end
1174 2 Thurallor-7095
    end
1175 Thurallor-7095
    self.selectedSlot = s;
1176 Thurallor-7095
    self:DisplaySlot(s);
1177 Thurallor-7095
end
1178 Thurallor-7095
 
1179 Thurallor-7095
function SequenceEditor:GetSlotPosition(x, y)
1180 Thurallor-7095
    local left = (x - 1) * (self.settings.slotSize + self.settings.slotSpacing) - self.settings.slotSpacing;
1181 Thurallor-7095
    local top = (y - 1) * (self.settings.slotSize + self.settings.slotSpacing) - self.settings.slotSpacing;
1182 Thurallor-7095
    return left, top;
1183 Thurallor-7095
end
1184 Thurallor-7095
 
1185 Thurallor-7095
function SequenceEditor:Closing()
1186 7 Thurallor-7095
    SequenceEditor.instances[self] = nil;
1187 2 Thurallor-7095
    self:DeleteEmptyTrailingSlots();
1188 16 Thurallor-7095
    self:UpdateBar();
1189 20 Thurallor-7095
    if (self.ItemMovedCallback) then
1190 Thurallor-7095
        RemoveCallback(Thurallor.Utils.Watcher, "ItemMoved", self.ItemMovedCallback);
1191 Thurallor-7095
        self.ItemMovedCallback = nil;
1192 Thurallor-7095
    end
1193 2 Thurallor-7095
end
1194 Thurallor-7095
 
1195 Thurallor-7095
function SequenceEditor:Close()
1196 Thurallor-7095
    Turbine.UI.Lotro.Window.Close(self);
1197 Thurallor-7095
end
1198 Thurallor-7095
 
1199 Thurallor-7095
function SequenceEditor:ShowContextMenu()
1200 Thurallor-7095
    -- Build the settings menu.
1201 18 Thurallor-7095
    self.settingsMenu = Turbine.UI.ContextMenu();
1202 2 Thurallor-7095
    local prevContext = L:SetContext("/SequenceEditor/RightClickMenu");
1203 Thurallor-7095
    self:AddSettingsMenuItem(self.settingsMenu, "Root", false);
1204 Thurallor-7095
    L:SetContext(prevContext);
1205 Thurallor-7095
    self.settingsMenu:ShowMenu();
1206 Thurallor-7095
end
1207 Thurallor-7095
 
1208 Thurallor-7095
function SequenceEditor:AddSettingsMenuItem(parent, itemName)
1209 Thurallor-7095
    local item = Turbine.UI.MenuItem(L:GetText(itemName), true, false);
1210 Thurallor-7095
    parent:GetItems():Add(item);
1211 Thurallor-7095
 
1212 Thurallor-7095
    if (itemName == "Root") then
1213 Thurallor-7095
        parent:GetItems():Clear();
1214 7 Thurallor-7095
        self:AddSettingsMenuItem(parent, "CloneSlot");
1215 2 Thurallor-7095
        self:AddSettingsMenuItem(parent, "InsertEmptySlot");
1216 Thurallor-7095
        self:AddSettingsMenuItem(parent, "DeleteSlot");
1217 Thurallor-7095
        self:AddSettingsMenuItem(parent, "CreateSpecialSlot");
1218 7 Thurallor-7095
    elseif (itemName == "CloneSlot") then
1219 Thurallor-7095
        item.Click = function(sender, args)
1220 Thurallor-7095
            self:CloneSlot(self.clickedItem);
1221 Thurallor-7095
        end
1222 2 Thurallor-7095
    elseif (itemName == "InsertEmptySlot") then
1223 Thurallor-7095
        item.Click = function(sender, args)
1224 Thurallor-7095
            self:InsertEmptySlot(self.clickedItem);
1225 Thurallor-7095
        end
1226 Thurallor-7095
    elseif (itemName == ("DeleteSlot")) then
1227 Thurallor-7095
        item.Click = function(sender, args)
1228 Thurallor-7095
            self:DeleteSlot(self.clickedItem);
1229 Thurallor-7095
        end
1230 Thurallor-7095
    elseif (itemName == "CreateSpecialSlot") then
1231 Thurallor-7095
        local prevContext = L:SetContext("SpecialSlotMenu");
1232 Thurallor-7095
        self:AddSettingsMenuItem(item, "RemoveEquipment");
1233 7 Thurallor-7095
        self:AddSettingsMenuItem(item, "ChatCommand");
1234 2 Thurallor-7095
        self:AddSettingsMenuItem(item, "StopAnimating");
1235 Thurallor-7095
        self:AddSettingsMenuItem(item, "GenerateEvent");
1236 6 Thurallor-7095
        self:AddSettingsMenuItem(item, "SetUnequipDestination");
1237 16 Thurallor-7095
        self:AddSettingsMenuItem(item, "IfThen");
1238 Thurallor-7095
        self:AddSettingsMenuItem(item, "IfThenElse");
1239 Thurallor-7095
        self:AddSettingsMenuItem(item, "Include");
1240 2 Thurallor-7095
        L:SetContext(prevContext);
1241 6 Thurallor-7095
    elseif (string.find("StopAnimating|GenerateEvent|SetUnequipDestination", itemName)) then
1242 2 Thurallor-7095
        item.Click = function(sender, args)
1243 Thurallor-7095
            self:CreateCommandSlot(self.clickedItem, itemName, item:GetText());
1244 Thurallor-7095
        end
1245 7 Thurallor-7095
    elseif (itemName == "ChatCommand") then
1246 Thurallor-7095
        local commands = Turbine.Shell.GetCommands();
1247 Thurallor-7095
        local index = math.random(#commands);
1248 Thurallor-7095
        item.Click = function(sender, args)
1249 Thurallor-7095
            self:CreateAliasSlot(self.clickedItem, "/" .. commands[index]);
1250 Thurallor-7095
        end
1251 2 Thurallor-7095
    elseif (itemName == "RemoveEquipment") then
1252 6 Thurallor-7095
        item.Click = function(sender, args)
1253 Thurallor-7095
            self:CreateRemovalSlot(self.clickedItem, "Gloves");
1254 2 Thurallor-7095
        end
1255 16 Thurallor-7095
    elseif ((itemName == "IfThen") or (itemName == "IfThenElse")) then
1256 Thurallor-7095
        item.Click = function(sender, args)
1257 Thurallor-7095
            self:CreateConditional(self.clickedItem, itemName);
1258 Thurallor-7095
        end
1259 Thurallor-7095
    elseif (itemName == "Include") then
1260 Thurallor-7095
        item.Click = function(sender, args)
1261 Thurallor-7095
            self:CreateIncludeSlot(self.clickedItem);
1262 Thurallor-7095
        end
1263 2 Thurallor-7095
    end
1264 Thurallor-7095
end
1265 Thurallor-7095
 
1266 7 Thurallor-7095
function SequenceEditor:CreateAliasSlot(s, command)
1267 Thurallor-7095
    self:ExtendSequenceTo(s);
1268 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1269 Thurallor-7095
    info.class = "Turbine.UI.Lotro.Quickslot";
1270 Thurallor-7095
    info.background = nil;
1271 Thurallor-7095
    info.type = Turbine.UI.Lotro.ShortcutType.Alias;
1272 Thurallor-7095
    info.Data = command;
1273 Thurallor-7095
    info.background = self.settings.sequenceEditor.defaultIcon;
1274 16 Thurallor-7095
    if (info.background) then
1275 Thurallor-7095
        info.textOverlay = string.gsub(info.Data, "^/", "");
1276 Thurallor-7095
        info.textOverlay = string.gsub(info.textOverlay, "%s.*$", "");
1277 Thurallor-7095
    end
1278 7 Thurallor-7095
    self:RebuildSlot(s);
1279 16 Thurallor-7095
    self:UpdateBar();
1280 7 Thurallor-7095
    self:Redraw();
1281 Thurallor-7095
    self:SelectSlot(s);
1282 Thurallor-7095
end
1283 Thurallor-7095
 
1284 16 Thurallor-7095
function SequenceEditor:CreateIncludeSlot(s)
1285 Thurallor-7095
    self:ExtendSequenceTo(s);
1286 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1287 Thurallor-7095
    info.class = "Turbine.UI.Control";
1288 Thurallor-7095
    info.background = resources.Icon.Include;
1289 Thurallor-7095
    info.type = "Include";
1290 Thurallor-7095
    info.toolTip = L:GetText("/SequenceEditor/RightClickMenu/SpecialSlotMenu/Include");
1291 Thurallor-7095
 
1292 Thurallor-7095
    self:RebuildSlot(s);
1293 Thurallor-7095
    self:UpdateBar();
1294 Thurallor-7095
    self:Redraw();
1295 Thurallor-7095
    self:SelectSlot(s);
1296 Thurallor-7095
end
1297 7 Thurallor-7095
 
1298 20 Thurallor-7095
function SequenceEditor:UnlinkIncludedSequence(s)
1299 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1300 Thurallor-7095
    if (not info.include) then
1301 Thurallor-7095
        return;
1302 Thurallor-7095
    end
1303 Thurallor-7095
    local otherSequenceSettings = self.globals.bars[info.include];
1304 Thurallor-7095
    if (not otherSequenceSettings) then
1305 Thurallor-7095
        return;
1306 Thurallor-7095
    end
1307 Thurallor-7095
    local otherItemInfo = otherSequenceSettings.sequenceItemInfo;
1308 Thurallor-7095
    self:DeleteSlot(s);
1309 Thurallor-7095
    for i = 1, #otherItemInfo, 1 do
1310 Thurallor-7095
        if (otherItemInfo[i].class) then
1311 Thurallor-7095
            table.insert(self.settings.sequenceItemInfo, s + i - 1, {});
1312 Thurallor-7095
            DeepTableCopy(otherItemInfo[i], self.settings.sequenceItemInfo[s + i - 1]);
1313 Thurallor-7095
        end
1314 Thurallor-7095
    end
1315 Thurallor-7095
    self:Redraw();
1316 Thurallor-7095
    self:SelectSlot(s);
1317 Thurallor-7095
end
1318 Thurallor-7095
 
1319 16 Thurallor-7095
function SequenceEditor:CreateConditional(s, condType)
1320 Thurallor-7095
    local prevContext = L:SetContext("/SequenceEditor/RightClickMenu/SpecialSlotMenu");
1321 Thurallor-7095
    local ifSlot = s;
1322 20 Thurallor-7095
    self:InsertEmptySlot(s);
1323 16 Thurallor-7095
    if (condType == "IfThenElse") then
1324 20 Thurallor-7095
        self:InsertEmptySlot(s);
1325 16 Thurallor-7095
    end
1326 20 Thurallor-7095
    self:InsertEmptySlot(s);
1327 16 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1328 Thurallor-7095
    info.class = "Turbine.UI.Control";
1329 Thurallor-7095
    info.background = resources.Icon["If"];
1330 Thurallor-7095
    info.type = "If";
1331 Thurallor-7095
    info.condName = "Always";
1332 Thurallor-7095
    info.condExpr = "return true;";
1333 Thurallor-7095
    info.toolTip = L:GetText("If");
1334 Thurallor-7095
    info.automatic = true;
1335 Thurallor-7095
    if (condType == "IfThenElse") then
1336 Thurallor-7095
        s = s + 1;
1337 Thurallor-7095
        info = self.settings.sequenceItemInfo[s];
1338 Thurallor-7095
        info.class = "Turbine.UI.Control";
1339 Thurallor-7095
        info.background = resources.Icon["Else"];
1340 Thurallor-7095
        info.type = "Else";
1341 Thurallor-7095
        info.toolTip = L:GetText("Else");
1342 Thurallor-7095
        info.automatic = true;
1343 Thurallor-7095
    end
1344 Thurallor-7095
    s = s + 1;
1345 Thurallor-7095
    info = self.settings.sequenceItemInfo[s];
1346 Thurallor-7095
    info.class = "Turbine.UI.Control";
1347 Thurallor-7095
    info.background = resources.Icon["EndIf"];
1348 Thurallor-7095
    info.type = "EndIf";
1349 Thurallor-7095
    info.toolTip = L:GetText("EndIf");
1350 Thurallor-7095
    info.automatic = true;
1351 Thurallor-7095
    self:Redraw();
1352 Thurallor-7095
    self:UpdateBar();
1353 Thurallor-7095
    self:SelectSlot(ifSlot);
1354 Thurallor-7095
    L:SetContext(prevContext);
1355 Thurallor-7095
end
1356 Thurallor-7095
 
1357 2 Thurallor-7095
function SequenceEditor:CreateCommandSlot(s, slotName, toolTip)
1358 Thurallor-7095
    self:ExtendSequenceTo(s);
1359 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1360 Thurallor-7095
    info.class = "Turbine.UI.Control";
1361 Thurallor-7095
    info.background = resources.Icon[slotName];
1362 Thurallor-7095
    if (slotName == "StopAnimating") then
1363 Thurallor-7095
        info.action = "local item, args = ...; item.bar.animationStopped = true;";
1364 Thurallor-7095
    elseif (slotName == "GenerateEvent") then
1365 32 Thurallor-7095
        info.eventName = L:GetText("/SequenceEditor/NewEvent");
1366 13 Thurallor-7095
        info.action = "local item, args = ...; item.bar.manager:PropagateEvent(item.info.eventName);";
1367 6 Thurallor-7095
    elseif (slotName == "SetUnequipDestination") then
1368 Thurallor-7095
        info.bagSlot = 1;
1369 13 Thurallor-7095
        info.action = "local item, args = ...; item.bar.manager:SetUnequipDestination(item.info.bagSlot);";
1370 2 Thurallor-7095
    end
1371 Thurallor-7095
    info.type = slotName;
1372 Thurallor-7095
    info.toolTip = toolTip;
1373 Thurallor-7095
    self:RebuildSlot(s);
1374 16 Thurallor-7095
    self:UpdateBar();
1375 2 Thurallor-7095
    self:Redraw();
1376 Thurallor-7095
    self:SelectSlot(s);
1377 Thurallor-7095
end
1378 Thurallor-7095
 
1379 6 Thurallor-7095
function SequenceEditor:CreateRemovalSlot(s, eqSlotName, bagSlot)
1380 2 Thurallor-7095
    self:ExtendSequenceTo(s);
1381 Thurallor-7095
    local info = self.settings.sequenceItemInfo[s];
1382 Thurallor-7095
    info.class = "Turbine.UI.Control";
1383 6 Thurallor-7095
    info.background = resources.Icon["Unequip" .. eqSlotName];
1384 Thurallor-7095
    info.action = "local item, args = ...; item.bar.manager:Unequip(Turbine.Gameplay.Equipment." .. eqSlotName .. ");";
1385 Thurallor-7095
    info.type = "Remove " .. eqSlotName;
1386 Thurallor-7095
 
1387 Thurallor-7095
    local prevContext = L:SetContext("/SequenceEditor");
1388 Thurallor-7095
    local toolTip = L:GetText("RemoveItem");
1389 Thurallor-7095
    L:SetContext("EquipmentSlots");
1390 Thurallor-7095
    local localEqSlotName = L:GetText(eqSlotName);
1391 Thurallor-7095
    info.toolTip = string.gsub(toolTip, "<item>", localEqSlotName);
1392 Thurallor-7095
    L:SetContext(prevContext);
1393 Thurallor-7095
 
1394 2 Thurallor-7095
    self:RebuildSlot(s);
1395 16 Thurallor-7095
    self:UpdateBar();
1396 2 Thurallor-7095
    self:Redraw();
1397 Thurallor-7095
    self:SelectSlot(s);
1398 Thurallor-7095
end
1399 Thurallor-7095
 
1400 Thurallor-7095
function SequenceEditor:ExtendSequenceTo(s)
1401 Thurallor-7095
    if (s <= #self.settings.sequenceItemInfo) then
1402 Thurallor-7095
        return false;
1403 Thurallor-7095
    end
1404 Thurallor-7095
    while (s > #self.settings.sequenceItemInfo) do
1405 Thurallor-7095
        table.insert(self.settings.sequenceItemInfo, {});
1406 Thurallor-7095
    end
1407 Thurallor-7095
    return true;
1408 Thurallor-7095
end
1409 Thurallor-7095
 
1410 Thurallor-7095
function SequenceEditor:DeleteEmptyTrailingSlots()
1411 Thurallor-7095
    local sequenceItemInfo = self.settings.sequenceItemInfo;
1412 Thurallor-7095
    for s = #sequenceItemInfo, 1, -1 do
1413 Thurallor-7095
        local info = sequenceItemInfo[s];
1414 Thurallor-7095
        if (not info.class) then
1415 Thurallor-7095
            table.remove(sequenceItemInfo, s);
1416 5 Thurallor-7095
            -- Remove empty slot displays
1417 Thurallor-7095
            if (self.sequenceItems) then
1418 Thurallor-7095
                local object = self.sequenceItems[s];
1419 Thurallor-7095
                if (object) then
1420 Thurallor-7095
                    if (object.numLabel) then
1421 Thurallor-7095
                        object.numLabel:SetParent(nil);
1422 Thurallor-7095
                    end
1423 Thurallor-7095
                    object:SetParent(nil);
1424 Thurallor-7095
                    self.sequenceItems[s] = nil;
1425 Thurallor-7095
                end
1426 Thurallor-7095
            end
1427 2 Thurallor-7095
        else
1428 Thurallor-7095
            break;
1429 Thurallor-7095
        end
1430 Thurallor-7095
    end
1431 Thurallor-7095
end
1432 Thurallor-7095
 
1433 7 Thurallor-7095
function SequenceEditor:CloneSlot(s)
1434 Thurallor-7095
    self:InsertEmptySlot(s);
1435 Thurallor-7095
    DeepTableCopy(self.settings.sequenceItemInfo[s + 1], self.settings.sequenceItemInfo[s]);
1436 Thurallor-7095
    self:RebuildSlot(s);
1437 16 Thurallor-7095
    self:UpdateBar();
1438 7 Thurallor-7095
    self:Redraw();
1439 Thurallor-7095
    self:SelectSlot(s);
1440 Thurallor-7095
end
1441 Thurallor-7095
 
1442 Thurallor-7095
function SequenceEditor:MoveSlot(sourceSlot, destSlot)
1443 Thurallor-7095
    self:InsertEmptySlot(destSlot);
1444 Thurallor-7095
    if (sourceSlot >= destSlot) then
1445 Thurallor-7095
        sourceSlot = sourceSlot + 1;
1446 Thurallor-7095
    end
1447 Thurallor-7095
    DeepTableCopy(self.settings.sequenceItemInfo[sourceSlot], self.settings.sequenceItemInfo[destSlot]);
1448 Thurallor-7095
    self:RebuildSlot(destSlot);
1449 Thurallor-7095
    self:DeleteSlot(sourceSlot);
1450 Thurallor-7095
    if (sourceSlot <= destSlot) then
1451 Thurallor-7095
        destSlot = destSlot - 1;
1452 Thurallor-7095
    end
1453 16 Thurallor-7095
    self:UpdateBar();
1454 7 Thurallor-7095
    self:Redraw();
1455 Thurallor-7095
    self:SelectSlot(destSlot);
1456 Thurallor-7095
end
1457 Thurallor-7095
 
1458 Thurallor-7095
function SequenceEditor:InsertSlot(s, info)
1459 2 Thurallor-7095
    if (s > #self.settings.sequenceItemInfo) then
1460 Thurallor-7095
        self:ExtendSequenceTo(s);
1461 Thurallor-7095
    else
1462 Thurallor-7095
        table.insert(self.settings.sequenceItemInfo, s, {});
1463 Thurallor-7095
    end
1464 7 Thurallor-7095
    if (info) then
1465 Thurallor-7095
        DeepTableCopy(info, self.settings.sequenceItemInfo[s]);
1466 Thurallor-7095
    end
1467 2 Thurallor-7095
    self:Redraw();
1468 16 Thurallor-7095
    self:UpdateBar();
1469 2 Thurallor-7095
    self:SelectSlot(s);
1470 Thurallor-7095
end
1471 Thurallor-7095
 
1472 7 Thurallor-7095
function SequenceEditor:InsertEmptySlot(s)
1473 Thurallor-7095
    self:InsertSlot(s, nil);
1474 Thurallor-7095
end
1475 Thurallor-7095
 
1476 2 Thurallor-7095
function SequenceEditor:DeleteSlot(s)
1477 Thurallor-7095
    table.remove(self.settings.sequenceItemInfo, s);
1478 Thurallor-7095
    self:Redraw();
1479 16 Thurallor-7095
    self:UpdateBar();
1480 2 Thurallor-7095
    self:ExtendSequenceTo(s);
1481 Thurallor-7095
    self:SelectSlot(nil);
1482 Thurallor-7095
end

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


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