lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [ChatTriggerWindow.lua] - Rev 177

Compare with Previous | Blame | View Log

ChatTriggerWindow = class(Turbine.UI.Lotro.Window);

local function AddLabel(parent, left, top, text)
    local label = Turbine.UI.Label();
    label:SetFont(Turbine.UI.Lotro.Font.Verdana14);
    label:SetForeColor(Turbine.UI.Color.Silver);
    label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleRight);
    label:SetText(text);
    label:SetSize(100, 14);
    label:SetParent(parent);
    label:SetPosition(left, top);
    return label, left + label:GetWidth(), top + label:GetHeight();
end

local function AddTextBox(parent, left, top, text)
    local textbox = Turbine.UI.Lotro.TextBox();
    textbox:SetFont(Turbine.UI.Lotro.Font.Verdana14);
    textbox:SetForeColor(Turbine.UI.Color.White);
    textbox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
    textbox:SetText(text);
    textbox:SetSize(270, 24);
    textbox:SetParent(parent);
    textbox:SetPosition(left, top);
    return textbox, left + textbox:GetWidth(), top + textbox:GetHeight();
end

function ChatTriggerWindow:Constructor(channel, pattern)
    Turbine.UI.Lotro.Window.Constructor(self);
    self:SetVisible(true);
    self:SetSize(450, 150);
    CenterWindow(self);

    self.localChatNames, self.localChatNameToChatType, self.chatTypeToLocalChatName = {}, {}, {};
    local prevContext = L:SetContext("/Turbine/ChatType");
    for _, name in pairs(L:GetItems("/Turbine/ChatType")) do
        local chatType = Turbine.ChatType[name];
        local localChatName = L:GetText(name);
        table.insert(self.localChatNames, localChatName);
        self.localChatNameToChatType[localChatName] = chatType
        self.chatTypeToLocalChatName[chatType] = localChatName;
    end
    table.sort(self.localChatNames);

    L:SetContext("/ChatTriggerWindow");
    self:SetText(L:GetText("Title"));

    local left, top = 20, 48;
    local label, left = AddLabel(self, left, top, L:GetText("Channel"));

    self.selectedChannel = channel or Turbine.ChatType.PlayerCombat;
    local dropDown = Thurallor.UI.DropDown(self.localChatNames, self.chatTypeToLocalChatName[self.selectedChannel]);
    dropDown:SetParent(self);
    dropDown:SetPosition(left + 6, top - 1);
    dropDown:SetWidth(170);
    AddCallback(dropDown, "SelectionChanged", function(_, args)
        self.selectedChannel = self.localChatNameToChatType[args.Item];
    end);
    self.channelDropDown = dropDown;

    left, top = 20, top + 26;
    local label, left = AddLabel(self, left, top, L:GetText("Pattern"));

    self.pattern = pattern or "";
    self.patternTextBox = AddTextBox(self, left + 6, top - 5, self.pattern);
    AddCallback(self.patternTextBox, "TextChanged", function(ctl)
        self.pattern = ctl:GetText();
    end);
    AddCallback(self.patternTextBox, "KeyDown", function(ctl, args)
        self:KeyDown(args);
    end);
    self:Activate();
    self.patternTextBox:Focus();

    local button = Turbine.UI.Lotro.Button();
    button:SetText(L:GetText("Ok"));
    button:SetParent(self);
    button:SetPosition(200, 108);
    AddCallback(button, "Click", function()
        self:Accept();
    end);
    self.okButton = button;

    L:SetContext(prevContext);
end

function ChatTriggerWindow:KeyDown(args)
    if (args.Action == Turbine.UI.Lotro.Action.EnterKey) then
        self:Accept();
    elseif (args.Action == Turbine.UI.Lotro.Action.Escape) then
        self:Close();
    end
end

function ChatTriggerWindow:Accept()
    self.pattern = self.pattern:gsub("\n", "");
    local text = "[" .. self.chatTypeToLocalChatName[self.selectedChannel] .. "] " .. self.pattern;
    DoCallbacks(self, "Accepted", { ChatType = self.selectedChannel; Pattern = self.pattern; Text = text });
    self.accepted = true;
    self:Close();
end

function ChatTriggerWindow:Closing()
    if (not self.accepted) then
        DoCallbacks(self, "Canceled");
    end
end

Compare with Previous | Blame


All times are GMT -5. The time now is 07:41 AM.


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