lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

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

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

All times are GMT -5. The time now is 10:45 AM.


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