lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [UserEventsTab.lua] - Blame information for rev 178

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 176 Thurallor-7095
UserEventsTab = class(Thurallor.UI.TabCard);
2 Thurallor-7095
 
3 Thurallor-7095
function UserEventsTab:Constructor(manager)
4 177 Thurallor-7095
    Thurallor.UI.TabCard.Constructor(self, false, false);
5 176 Thurallor-7095
    self.manager = manager;
6 Thurallor-7095
 
7 Thurallor-7095
    self.inside = Turbine.UI.Control();
8 Thurallor-7095
    self:SetInteriorControl(self.inside);
9 Thurallor-7095
    self:SetInteriorAlignment(Turbine.UI.ContentAlignment.TopLeft);
10 Thurallor-7095
 
11 177 Thurallor-7095
    self:Localize();
12 176 Thurallor-7095
end
13 Thurallor-7095
 
14 Thurallor-7095
function UserEventsTab:Localize()
15 177 Thurallor-7095
    self:CloseSubwindows();
16 Thurallor-7095
    self:Redraw();
17 Thurallor-7095
 
18 176 Thurallor-7095
    self:SetTabText(L:GetText("/DirectoryWindow/EventHeading"));
19 177 Thurallor-7095
 
20 Thurallor-7095
    local function LocalizeButton(button, text)
21 Thurallor-7095
        local label = Turbine.UI.Label();
22 Thurallor-7095
        label:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
23 Thurallor-7095
        label:SetText(text);
24 Thurallor-7095
        label:AutoSize();
25 Thurallor-7095
        button:SetText(text);
26 Thurallor-7095
        button:SetWidth(label:GetWidth() + 12);
27 Thurallor-7095
    end
28 Thurallor-7095
    for _, buttonName in pairs(L:GetItems("/DirectoryWindow/EventButtons")) do
29 Thurallor-7095
        LocalizeButton(self[buttonName], L:GetText("/DirectoryWindow/EventButtons/" .. buttonName));
30 Thurallor-7095
    end
31 Thurallor-7095
 
32 Thurallor-7095
    self:ShowButtons();
33 176 Thurallor-7095
end
34 Thurallor-7095
 
35 177 Thurallor-7095
function UserEventsTab:EventIsDeletable(eventName)
36 Thurallor-7095
    local barList = self.manager:GetEventGenerators(eventName);
37 Thurallor-7095
    local nodeList = self.manager:GetEventListeners(eventName);
38 Thurallor-7095
    return not (barList or nodeList);
39 Thurallor-7095
end
40 Thurallor-7095
 
41 Thurallor-7095
function UserEventsTab:ShowButtons()
42 Thurallor-7095
    for _, buttonName in pairs(L:GetItems("/DirectoryWindow/EventButtons")) do
43 Thurallor-7095
        self[buttonName]:SetVisible(false);
44 Thurallor-7095
    end
45 Thurallor-7095
    self.createEventButton:SetVisible(true);
46 Thurallor-7095
    if (self.selectedEvent) then
47 Thurallor-7095
        if (self:EventIsDeletable(self.selectedEvent)) then
48 Thurallor-7095
            self.deleteEventButton:SetVisible(true);
49 Thurallor-7095
        end
50 Thurallor-7095
        if (self.manager:GetEventHotkeys(self.selectedEvent)) then
51 Thurallor-7095
            self.removeHotkeyButton:SetVisible(true);
52 Thurallor-7095
        else
53 Thurallor-7095
            self.addHotkeyButton:SetVisible(true);
54 Thurallor-7095
        end
55 Thurallor-7095
        if (self.manager:GetEventChatTriggers(self.selectedEvent)) then
56 Thurallor-7095
            self.removeChatTriggerButton:SetVisible(true);
57 Thurallor-7095
        else
58 Thurallor-7095
            self.addChatTriggerButton:SetVisible(true);
59 Thurallor-7095
        end
60 Thurallor-7095
    end
61 Thurallor-7095
 
62 Thurallor-7095
    -- Redistribute the buttons
63 Thurallor-7095
    local buttons = self.buttons:GetControls();
64 Thurallor-7095
    local left = 0;
65 Thurallor-7095
    for c = 1, buttons:GetCount() do
66 Thurallor-7095
        local ctl = buttons:Get(c);
67 Thurallor-7095
        ctl:SetLeft(left);
68 Thurallor-7095
        if (ctl:IsVisible()) then
69 Thurallor-7095
            left = left + ctl:GetWidth() + 4;
70 Thurallor-7095
        end
71 Thurallor-7095
    end
72 Thurallor-7095
end
73 Thurallor-7095
 
74 176 Thurallor-7095
function UserEventsTab:Redraw()
75 177 Thurallor-7095
    if (not self.instructions) then
76 Thurallor-7095
        local label = Turbine.UI.Label();
77 Thurallor-7095
        label:SetParent(self.inside);
78 Thurallor-7095
        label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
79 Thurallor-7095
        label:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
80 Thurallor-7095
        label:SetForeColor(Turbine.UI.Color.PaleGoldenrod);
81 Thurallor-7095
        self.instructions = label;
82 Thurallor-7095
    end
83 Thurallor-7095
    local lines = L:GetNumber("/DirectoryWindow/EventInstructionsLines") + 1;
84 Thurallor-7095
    self.instructions:SetHeight(lines * 14);
85 Thurallor-7095
    self.instructions:SetText(L:GetText("/DirectoryWindow/EventInstructions"));
86 Thurallor-7095
 
87 176 Thurallor-7095
    if (self.tableCtl) then
88 Thurallor-7095
        self.tableCtl:SetParent(nil);
89 Thurallor-7095
    end
90 Thurallor-7095
    self.tableCtl = EventTableControl(self.manager);
91 Thurallor-7095
    self.tableCtl:SetParent(self.inside);
92 Thurallor-7095
    self.tableCtl:SetPosition(0, self.instructions:GetHeight() + 2);
93 177 Thurallor-7095
    AddCallback(self.tableCtl, "SelectionChanged", function(ctl, args)
94 Thurallor-7095
        self:EventSelected(args.New);
95 176 Thurallor-7095
    end);
96 177 Thurallor-7095
    AddCallback(self.tableCtl, "HotkeyClicked", function(_, args)
97 Thurallor-7095
        self:ReplaceHotkey(args);
98 Thurallor-7095
    end);
99 Thurallor-7095
    AddCallback(self.tableCtl, "ChatTriggerClicked", function(_, args)
100 Thurallor-7095
        self:ReplaceChatTrigger(args);
101 Thurallor-7095
    end);
102 Thurallor-7095
 
103 Thurallor-7095
    if (not self.buttons) then
104 Thurallor-7095
        self.buttons = Turbine.UI.Control();
105 Thurallor-7095
        self.buttons:SetParent(self.inside);
106 Thurallor-7095
        for _, buttonName in ipairs({
107 Thurallor-7095
            "createEventButton",
108 Thurallor-7095
            "deleteEventButton",
109 Thurallor-7095
            "addHotkeyButton",
110 Thurallor-7095
            "removeHotkeyButton",
111 Thurallor-7095
            "addChatTriggerButton",
112 Thurallor-7095
            "removeChatTriggerButton"
113 Thurallor-7095
        }) do
114 Thurallor-7095
            self[buttonName] = Turbine.UI.Lotro.Button();
115 Thurallor-7095
            self[buttonName]:SetParent(self.buttons);
116 Thurallor-7095
            self[buttonName].Click = function(ctl) self:ButtonClicked(buttonName) end
117 Thurallor-7095
        end
118 Thurallor-7095
    end
119 Thurallor-7095
 
120 176 Thurallor-7095
    self:SetSize(self:GetSize());
121 Thurallor-7095
end
122 Thurallor-7095
 
123 Thurallor-7095
function UserEventsTab:SetSize(width, height)
124 Thurallor-7095
    Thurallor.UI.TabCard.SetSize(self, width, height);
125 177 Thurallor-7095
    self.inside:SetSize(width - 10, height - 30);
126 Thurallor-7095
    self.instructions:SetWidth(width - 10);
127 Thurallor-7095
    self.buttons:SetSize(width - 10, 20);
128 Thurallor-7095
    self.buttons:SetTop(height - 50);
129 Thurallor-7095
    self.tableCtl:SetSize(width - 10, height - 82);
130 176 Thurallor-7095
end
131 Thurallor-7095
 
132 177 Thurallor-7095
function UserEventsTab:CloseSubwindows()
133 Thurallor-7095
    if (self.hotkeyWindow) then
134 Thurallor-7095
        self.hotkeyWindow:Close();
135 Thurallor-7095
        self.hotkeyWindow = nil;
136 Thurallor-7095
    end
137 Thurallor-7095
    if (self.chatTriggerWindow) then
138 Thurallor-7095
        self.chatTriggerWindow:Close();
139 Thurallor-7095
        self.chatTriggerWindow = nil;
140 Thurallor-7095
    end
141 176 Thurallor-7095
end
142 177 Thurallor-7095
 
143 Thurallor-7095
function UserEventsTab:EventSelected(eventName)
144 Thurallor-7095
    self:CloseSubwindows();
145 Thurallor-7095
    self.selectedEvent = eventName;
146 Thurallor-7095
    self:ShowButtons();
147 Thurallor-7095
end
148 Thurallor-7095
 
149 Thurallor-7095
function UserEventsTab:ButtonClicked(buttonName)
150 Thurallor-7095
    if (buttonName == "createEventButton") then
151 Thurallor-7095
        local newEventText = L:GetText("/SequenceEditor/NewEvent");
152 Thurallor-7095
        local eventName = newEventText;
153 Thurallor-7095
        local i = 1;
154 Thurallor-7095
        while (self.tableCtl:GetRow(eventName)) do
155 Thurallor-7095
            i = i + 1;
156 Thurallor-7095
            eventName = newEventText .. " " .. tostring(i);
157 Thurallor-7095
        end
158 Thurallor-7095
        self.tableCtl:CreateEvent(eventName);
159 Thurallor-7095
    elseif (buttonName == "deleteEventButton") then
160 Thurallor-7095
        self.tableCtl:DeleteEvent(self.selectedEvent);
161 Thurallor-7095
    elseif (buttonName == "addHotkeyButton") then
162 Thurallor-7095
        self:ReplaceHotkey();
163 Thurallor-7095
    elseif (buttonName == "addChatTriggerButton") then
164 Thurallor-7095
        self:ReplaceChatTrigger();
165 Thurallor-7095
    elseif (buttonName == "removeHotkeyButton") then
166 Thurallor-7095
        self.manager:ClearEventHotkeys(self.selectedEvent);
167 Thurallor-7095
        self.tableCtl:UpdateCellContents(self.selectedEvent);
168 Thurallor-7095
        self:ShowButtons();
169 Thurallor-7095
    elseif (buttonName == "removeChatTriggerButton") then
170 Thurallor-7095
        self.manager:ClearEventChatTriggers(self.selectedEvent);
171 Thurallor-7095
        self.tableCtl:UpdateCellContents(self.selectedEvent);
172 Thurallor-7095
        self:ShowButtons();
173 Thurallor-7095
    end
174 Thurallor-7095
end
175 Thurallor-7095
 
176 Thurallor-7095
function UserEventsTab:ReplaceHotkey()
177 Thurallor-7095
    self:CloseSubwindows();
178 Thurallor-7095
    self.hotkeyWindow = HotkeyAssignWindow();
179 Thurallor-7095
    self.hotkeyWindow.KeySelected = function(_, args)
180 Thurallor-7095
        self.manager:ClearEventHotkeys(self.selectedEvent);
181 Thurallor-7095
        self.manager:SetEventHotkey(self.selectedEvent, args.Action, args.Event, args.Text);
182 Thurallor-7095
        self.tableCtl:UpdateCellContents(self.selectedEvent);
183 Thurallor-7095
        self:ShowButtons();
184 Thurallor-7095
        self.hotkeyWindow = nil;
185 Thurallor-7095
    end
186 Thurallor-7095
    self.hotkeyWindow.Canceled = function()
187 Thurallor-7095
        self.hotkeyWindow = nil;
188 Thurallor-7095
    end
189 Thurallor-7095
end
190 Thurallor-7095
 
191 Thurallor-7095
function UserEventsTab:ReplaceChatTrigger(args)
192 178 Thurallor-7095
        args = args or {};
193 177 Thurallor-7095
        self:CloseSubwindows();
194 Thurallor-7095
        self.chatTriggerWindow = ChatTriggerWindow(args.ChatType, args.Pattern);
195 Thurallor-7095
        self.chatTriggerWindow.Accepted = function(_, args)
196 Thurallor-7095
            self.manager:ClearEventChatTriggers(self.selectedEvent);
197 Thurallor-7095
            self.manager:SetEventChatTrigger(self.selectedEvent, args.ChatType, args.Pattern, args.Text);
198 Thurallor-7095
            self.tableCtl:UpdateCellContents(self.selectedEvent);
199 Thurallor-7095
            self:ShowButtons();
200 Thurallor-7095
            self.chatTriggerWindow = nil;
201 Thurallor-7095
        end
202 Thurallor-7095
        self.chatTriggerWindow.Canceled = function()
203 Thurallor-7095
            self.chatTriggerWindow = nil;
204 Thurallor-7095
        end
205 Thurallor-7095
end

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


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