lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [UserEventsTab.lua] - Rev 178

Compare with Previous | Blame | View Log

UserEventsTab = class(Thurallor.UI.TabCard);

function UserEventsTab:Constructor(manager)
    Thurallor.UI.TabCard.Constructor(self, false, false);
    self.manager = manager;
    
    self.inside = Turbine.UI.Control();
    self:SetInteriorControl(self.inside);
    self:SetInteriorAlignment(Turbine.UI.ContentAlignment.TopLeft);

    self:Localize();
end

function UserEventsTab:Localize()
    self:CloseSubwindows();
    self:Redraw();

    self:SetTabText(L:GetText("/DirectoryWindow/EventHeading"));

    local function LocalizeButton(button, text)
        local label = Turbine.UI.Label();
        label:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
        label:SetText(text);
        label:AutoSize();
        button:SetText(text);
        button:SetWidth(label:GetWidth() + 12);
    end
    for _, buttonName in pairs(L:GetItems("/DirectoryWindow/EventButtons")) do
        LocalizeButton(self[buttonName], L:GetText("/DirectoryWindow/EventButtons/" .. buttonName));
    end

    self:ShowButtons();
end

function UserEventsTab:EventIsDeletable(eventName)
    local barList = self.manager:GetEventGenerators(eventName);
    local nodeList = self.manager:GetEventListeners(eventName);
    return not (barList or nodeList);
end

function UserEventsTab:ShowButtons()
    for _, buttonName in pairs(L:GetItems("/DirectoryWindow/EventButtons")) do
        self[buttonName]:SetVisible(false);
    end
    self.createEventButton:SetVisible(true);
    if (self.selectedEvent) then
        if (self:EventIsDeletable(self.selectedEvent)) then
            self.deleteEventButton:SetVisible(true);
        end
        if (self.manager:GetEventHotkeys(self.selectedEvent)) then
            self.removeHotkeyButton:SetVisible(true);
        else
            self.addHotkeyButton:SetVisible(true);
        end
        if (self.manager:GetEventChatTriggers(self.selectedEvent)) then
            self.removeChatTriggerButton:SetVisible(true);
        else
            self.addChatTriggerButton:SetVisible(true);
        end
    end

    -- Redistribute the buttons
    local buttons = self.buttons:GetControls();
    local left = 0;
    for c = 1, buttons:GetCount() do
        local ctl = buttons:Get(c);
        ctl:SetLeft(left);
        if (ctl:IsVisible()) then
            left = left + ctl:GetWidth() + 4;
        end
    end
end

function UserEventsTab:Redraw()
    if (not self.instructions) then
        local label = Turbine.UI.Label();
        label:SetParent(self.inside);
        label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
        label:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
        label:SetForeColor(Turbine.UI.Color.PaleGoldenrod);
        self.instructions = label;
    end
    local lines = L:GetNumber("/DirectoryWindow/EventInstructionsLines") + 1;
    self.instructions:SetHeight(lines * 14);
    self.instructions:SetText(L:GetText("/DirectoryWindow/EventInstructions"));
    
    if (self.tableCtl) then
        self.tableCtl:SetParent(nil);
    end
    self.tableCtl = EventTableControl(self.manager);
    self.tableCtl:SetParent(self.inside);
    self.tableCtl:SetPosition(0, self.instructions:GetHeight() + 2);
    AddCallback(self.tableCtl, "SelectionChanged", function(ctl, args)
        self:EventSelected(args.New);
    end);
    AddCallback(self.tableCtl, "HotkeyClicked", function(_, args)
        self:ReplaceHotkey(args);
    end);
    AddCallback(self.tableCtl, "ChatTriggerClicked", function(_, args)
        self:ReplaceChatTrigger(args);
    end);

    if (not self.buttons) then
        self.buttons = Turbine.UI.Control();
        self.buttons:SetParent(self.inside);
        for _, buttonName in ipairs({
            "createEventButton",
            "deleteEventButton",
            "addHotkeyButton",
            "removeHotkeyButton",
            "addChatTriggerButton",
            "removeChatTriggerButton"
        }) do
            self[buttonName] = Turbine.UI.Lotro.Button();
            self[buttonName]:SetParent(self.buttons);
            self[buttonName].Click = function(ctl) self:ButtonClicked(buttonName) end
        end
    end

    self:SetSize(self:GetSize());
end

function UserEventsTab:SetSize(width, height)
    Thurallor.UI.TabCard.SetSize(self, width, height);
    self.inside:SetSize(width - 10, height - 30);
    self.instructions:SetWidth(width - 10);
    self.buttons:SetSize(width - 10, 20);
    self.buttons:SetTop(height - 50);
    self.tableCtl:SetSize(width - 10, height - 82);
end

function UserEventsTab:CloseSubwindows()
    if (self.hotkeyWindow) then
        self.hotkeyWindow:Close();
        self.hotkeyWindow = nil;
    end
    if (self.chatTriggerWindow) then
        self.chatTriggerWindow:Close();
        self.chatTriggerWindow = nil;
    end
end

function UserEventsTab:EventSelected(eventName)
    self:CloseSubwindows();
    self.selectedEvent = eventName;
    self:ShowButtons();
end

function UserEventsTab:ButtonClicked(buttonName)
    if (buttonName == "createEventButton") then
        local newEventText = L:GetText("/SequenceEditor/NewEvent");
        local eventName = newEventText;
        local i = 1;
        while (self.tableCtl:GetRow(eventName)) do
            i = i + 1;
            eventName = newEventText .. " " .. tostring(i);
        end
        self.tableCtl:CreateEvent(eventName);
    elseif (buttonName == "deleteEventButton") then
        self.tableCtl:DeleteEvent(self.selectedEvent);
    elseif (buttonName == "addHotkeyButton") then
        self:ReplaceHotkey();
    elseif (buttonName == "addChatTriggerButton") then
        self:ReplaceChatTrigger();
    elseif (buttonName == "removeHotkeyButton") then
        self.manager:ClearEventHotkeys(self.selectedEvent);
        self.tableCtl:UpdateCellContents(self.selectedEvent);
        self:ShowButtons();
    elseif (buttonName == "removeChatTriggerButton") then
        self.manager:ClearEventChatTriggers(self.selectedEvent);
        self.tableCtl:UpdateCellContents(self.selectedEvent);
        self:ShowButtons();
    end
end

function UserEventsTab:ReplaceHotkey()
    self:CloseSubwindows();
    self.hotkeyWindow = HotkeyAssignWindow();
    self.hotkeyWindow.KeySelected = function(_, args)
        self.manager:ClearEventHotkeys(self.selectedEvent);
        self.manager:SetEventHotkey(self.selectedEvent, args.Action, args.Event, args.Text);
        self.tableCtl:UpdateCellContents(self.selectedEvent);
        self:ShowButtons();
        self.hotkeyWindow = nil;
    end
    self.hotkeyWindow.Canceled = function()
        self.hotkeyWindow = nil;
    end
end

function UserEventsTab:ReplaceChatTrigger(args)
        args = args or {};
        self:CloseSubwindows();
        self.chatTriggerWindow = ChatTriggerWindow(args.ChatType, args.Pattern);
        self.chatTriggerWindow.Accepted = function(_, args)
            self.manager:ClearEventChatTriggers(self.selectedEvent);
            self.manager:SetEventChatTrigger(self.selectedEvent, args.ChatType, args.Pattern, args.Text);
            self.tableCtl:UpdateCellContents(self.selectedEvent);
            self:ShowButtons();
            self.chatTriggerWindow = nil;
        end
        self.chatTriggerWindow.Canceled = function()
            self.chatTriggerWindow = nil;
        end
end

Compare with Previous | Blame


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


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