lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [Sequence.lua] - Blame information for rev 177

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

Line No. Rev Author Line
1 21 Thurallor-7095
Sequence = class();
2 13 Thurallor-7095
 
3 117 Thurallor-7095
function Sequence:Constructor(bar, info, wantsMouseWheelEvents)
4 16 Thurallor-7095
    self.bar = bar;
5 117 Thurallor-7095
    self.wantsMouseWheelEvents = wantsMouseWheelEvents;
6 16 Thurallor-7095
    self.manager = bar.manager;
7 Thurallor-7095
    self.visibleItems = {};
8 Thurallor-7095
 
9 Thurallor-7095
    -- Callbacks
10 Thurallor-7095
    self.ItemChanged = nil;
11 13 Thurallor-7095
 
12 16 Thurallor-7095
    if (not info) then
13 Thurallor-7095
        info = {};
14 Thurallor-7095
    end
15 Thurallor-7095
    self:SetInfo(info);
16 13 Thurallor-7095
end
17 Thurallor-7095
 
18 16 Thurallor-7095
function Sequence:SetInfo(newInfo)
19 Thurallor-7095
    self.slots = {};
20 Thurallor-7095
    self.events = {};
21 Thurallor-7095
    self.slotIndexMap = {};
22 Thurallor-7095
    self.includes = {};
23 Thurallor-7095
 
24 Thurallor-7095
    for i = 1, #newInfo, 1 do
25 Thurallor-7095
        self.i = i;
26 Thurallor-7095
        local info = newInfo[i];
27 Thurallor-7095
        self:ProcessInfoItem(info);
28 Thurallor-7095
    end
29 Thurallor-7095
 
30 Thurallor-7095
    self:ProcessConditionals();
31 13 Thurallor-7095
end
32 Thurallor-7095
 
33 16 Thurallor-7095
function Sequence:ProcessInfoItem(info)
34 117 Thurallor-7095
    local slot = Slot(info, self.wantsMouseWheelEvents);
35 16 Thurallor-7095
    slot.i = self.i;
36 Thurallor-7095
    slot.info = info;
37 Thurallor-7095
    if ((type(info) ~= "table") or not info.class) then
38 Thurallor-7095
        -- Empty slot; discard
39 Thurallor-7095
    elseif ((info.class == "Turbine.UI.Control") and (info.type == "Include")) then
40 Thurallor-7095
        if (info.include ~= self.bar:GetID()) then
41 Thurallor-7095
            if (not self:IncludeSequence(info.include)) then
42 Thurallor-7095
                info.include = nil;
43 Thurallor-7095
                self.bar:SaveSettings(false);
44 Thurallor-7095
            end
45 Thurallor-7095
        end
46 Thurallor-7095
    else
47 Thurallor-7095
        table.insert(self.slots, slot);
48 Thurallor-7095
        self.slotIndexMap[self.i] = #self.slots;
49 Thurallor-7095
        if (info.class ~= "Turbine.UI.Control") then
50 Thurallor-7095
            -- Standard quickslot; no further handling necessary
51 Thurallor-7095
        else
52 Thurallor-7095
            if (info.type == "GenerateEvent") then
53 177 Thurallor-7095
                self.events[info.eventName] = true;
54 16 Thurallor-7095
            end
55 Thurallor-7095
            if (info.action) then
56 Thurallor-7095
                slot.actionFunc = loadstring(info.action);
57 Thurallor-7095
            end
58 Thurallor-7095
        end
59 Thurallor-7095
    end
60 Thurallor-7095
end
61 Thurallor-7095
 
62 Thurallor-7095
function Sequence:IncludeSequence(barID)
63 Thurallor-7095
    local otherSettings = self.manager.settings.bars[barID];
64 Thurallor-7095
    if (otherSettings and not otherSettings.deleted) then
65 Thurallor-7095
        table.insert(self.includes, barID);
66 Thurallor-7095
        local otherInfo = otherSettings.sequenceItemInfo;
67 Thurallor-7095
        for i = 1, #otherInfo, 1 do
68 Thurallor-7095
            local info = otherInfo[i];
69 Thurallor-7095
            self:ProcessInfoItem(info);
70 Thurallor-7095
        end
71 Thurallor-7095
        return true;
72 Thurallor-7095
    else
73 Thurallor-7095
        return false;
74 Thurallor-7095
    end
75 Thurallor-7095
end
76 Thurallor-7095
 
77 Thurallor-7095
function Sequence:GetIncludes()
78 Thurallor-7095
    return self.includes;
79 Thurallor-7095
end
80 Thurallor-7095
 
81 Thurallor-7095
-- Returns the new index of a slot after empty slots are removed
82 Thurallor-7095
function Sequence:GetNewIndex(oldIndex)
83 Thurallor-7095
    return self.slotIndexMap[oldIndex];
84 Thurallor-7095
end
85 Thurallor-7095
 
86 Thurallor-7095
function Sequence:GetOldIndex(newIndex)
87 Thurallor-7095
    return self.slots[newIndex].i;
88 Thurallor-7095
end
89 Thurallor-7095
 
90 Thurallor-7095
function Sequence:GetSlots()
91 Thurallor-7095
    return self.slots;
92 Thurallor-7095
end
93 Thurallor-7095
 
94 Thurallor-7095
function Sequence:GetSlot(index)
95 Thurallor-7095
    return self.slots[index];
96 Thurallor-7095
end
97 Thurallor-7095
 
98 Thurallor-7095
function Sequence:GetEvents()
99 Thurallor-7095
    return self.events;
100 Thurallor-7095
end
101 Thurallor-7095
 
102 Thurallor-7095
-- Populate the 'ifSlot', 'elseSlot', and 'endIfSlot' members of slots.
103 Thurallor-7095
function Sequence:ProcessConditionals()
104 Thurallor-7095
    local stack = { {} };
105 Thurallor-7095
    local parentIfSlot, parentElseSlot = nil, nil;
106 Thurallor-7095
    for s = 1, #self.slots, 1 do
107 Thurallor-7095
        local slot = self.slots[s];
108 Thurallor-7095
        local info = slot.info;
109 Thurallor-7095
        slot.parentIfSlot, slot.parentElseSlot = parentIfSlot, parentElseSlot;
110 Thurallor-7095
        if (info.type == "If") then
111 Thurallor-7095
            slot.ifSlot, slot.elseSlot, slot.endIfSlot = nil, nil, nil;
112 Thurallor-7095
            -- Do argument substitutions
113 Thurallor-7095
            slot.condExpr = info.condExpr;
114 Thurallor-7095
            if (info.condArgs) then
115 Thurallor-7095
                for name, value in pairs(info.condArgs) do
116 20 Thurallor-7095
                    slot.condExpr = string.gsub(slot.condExpr, "<" .. name .. ">", tostring(value));
117 16 Thurallor-7095
                end
118 Thurallor-7095
            end
119 Thurallor-7095
            slot.condFunc = loadstring(slot.condExpr);
120 Thurallor-7095
            table.insert(stack, { info.type, s });
121 Thurallor-7095
            parentIfSlot = s;
122 Thurallor-7095
            parentElseSlot = nil;
123 Thurallor-7095
        elseif (info.type == "Else") then
124 Thurallor-7095
            local lastType, lastLoc = unpack(table.remove(stack));
125 Thurallor-7095
            if (lastType == "If") then
126 Thurallor-7095
                local ifItem = self.slots[lastLoc];
127 Thurallor-7095
                ifItem.elseSlot = s;
128 Thurallor-7095
                slot.ifSlot, slot.elseSlot, slot.endIfSlot = lastLoc, nil, nil;
129 Thurallor-7095
                table.insert(stack, { info.type, s });
130 Thurallor-7095
                slot.parentIfSlot, slot.parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot;
131 Thurallor-7095
                parentIfSlot = nil;
132 Thurallor-7095
                parentElseSlot = s;
133 Thurallor-7095
            else -- Syntax error: Unmatched braces
134 Thurallor-7095
                Puts("Error: \"Else\" at slot " .. tostring(slot.i) .. " has no matching \"If\".");
135 Thurallor-7095
                table.insert(stack, { lastType, lastLoc });
136 Thurallor-7095
            end
137 Thurallor-7095
        elseif (info.type == "EndIf") then
138 Thurallor-7095
            local lastType, lastLoc = unpack(table.remove(stack));
139 Thurallor-7095
            if (lastType == "If") then
140 Thurallor-7095
                local ifItem = self.slots[lastLoc];
141 Thurallor-7095
                ifItem.endIfSlot = s;
142 Thurallor-7095
                slot.ifSlot, slot.elseSlot, slot.endIfSlot = lastLoc, nil, nil;
143 Thurallor-7095
                slot.parentIfSlot, slot.parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot;
144 Thurallor-7095
                parentIfSlot, parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot;
145 Thurallor-7095
            elseif (lastType == "Else") then
146 Thurallor-7095
                local elseItem = self.slots[lastLoc];
147 Thurallor-7095
                local ifItem = self.slots[elseItem.ifSlot];
148 Thurallor-7095
                ifItem.endIfSlot = s;
149 Thurallor-7095
                elseItem.endIfSlot = s;
150 Thurallor-7095
                slot.ifSlot, slot.elseSlot, slot.endIfSlot = elseItem.ifSlot, lastLoc, nil;
151 Thurallor-7095
                slot.parentIfSlot, slot.parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot;
152 Thurallor-7095
                parentIfSlot, parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot;
153 Thurallor-7095
            else -- Syntax error: Unmatched braces
154 Thurallor-7095
                Puts("Error: \"EndIf\" at slot " .. tostring(slot.i) .. " has no matching \"If\".");
155 Thurallor-7095
                table.insert(stack, { lastType, lastLoc });
156 Thurallor-7095
            end
157 Thurallor-7095
        end
158 Thurallor-7095
    end
159 Thurallor-7095
    while (#stack > 1) do
160 Thurallor-7095
        local t, s = unpack(table.remove(stack));
161 Thurallor-7095
        local slot = self.slots[s];
162 Thurallor-7095
        Puts("Error: \"" .. t .. "\" at slot " .. tostring(slot.i) .. " has no matching \"EndIf\".");
163 Thurallor-7095
    end
164 Thurallor-7095
--for s = 1, #self.slots, 1 do
165 Thurallor-7095
--    local slot = self.slots[s];
166 Thurallor-7095
--    Puts(tostring(s) .. ". parentIfSlot/parentElseSlot/ifSlot/elseSlot/endIfSlot = " .. tostring(slot.parentIfSlot) .. "/" .. tostring(slot.parentElseSlot) .. "/" .. tostring(slot.ifSlot) .. "/" .. tostring(slot.elseSlot) .. "/" .. tostring(slot.endIfSlot) .. "; condExpr = " .. tostring(slot.info.condExpr) .. "; condFunc = " .. tostring(slot.condFunc));
167 Thurallor-7095
--end
168 Thurallor-7095
end
169 Thurallor-7095
 
170 Thurallor-7095
function Sequence:UnfoldAllSlots()
171 Thurallor-7095
    for s = 1, #self.slots, 1 do
172 Thurallor-7095
        self.slots[s].condResult = nil;
173 36 Thurallor-7095
        self.slots[s].foldTime = nil;
174 16 Thurallor-7095
    end
175 Thurallor-7095
end
176 Thurallor-7095
 
177 36 Thurallor-7095
-- There is currently no reason to evaluate folding more than once at any given game time;
178 Thurallor-7095
-- hence the gameTime argument equals the current game time, a cached folding value is returned.
179 Thurallor-7095
function Sequence:SlotIsFolded(s, gameTime)
180 16 Thurallor-7095
    local slot = self.slots[s];
181 36 Thurallor-7095
    if (slot.foldTime == gameTime) then
182 Thurallor-7095
        return slot.isFolded;
183 Thurallor-7095
    end
184 16 Thurallor-7095
    if (slot.parentIfSlot) then
185 Thurallor-7095
        local ifSlot = self.slots[slot.parentIfSlot];
186 36 Thurallor-7095
        slot.isFolded = self:SlotIsFolded(slot.parentIfSlot, gameTime) or (not ifSlot.condResult);
187 16 Thurallor-7095
    elseif (slot.parentElseSlot) then
188 Thurallor-7095
        local elseSlot = self.slots[slot.parentElseSlot];
189 Thurallor-7095
        local ifSlot = self.slots[elseSlot.ifSlot];
190 36 Thurallor-7095
        slot.isFolded = self:SlotIsFolded(slot.parentElseSlot, gameTime) or ifSlot.condResult;
191 16 Thurallor-7095
    else
192 36 Thurallor-7095
        slot.isFolded = false;
193 16 Thurallor-7095
    end
194 36 Thurallor-7095
    slot.foldTime = gameTime;
195 Thurallor-7095
    return slot.isFolded;
196 16 Thurallor-7095
end

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


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