lotrointerface.com
Search Downloads

LoTROInterface SVN Reminders

[/] [trunk/] [Thurallor/] [Reminders/] [RaidLockDialog.lua] - Rev 8

Compare with Previous | Blame | View Log

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

RaidLockDialog.instances = {};

local importPath = getfenv(1)._.Name;
local imagePath = string.gsub(string.gsub(importPath, "%.RaidLockDialog$", ""), "%.", "/") .. "/Images/";

function RaidLockDialog.GetInstance(win, lockName, settings, charSettings, charID, notes)
    local existingDialog = RaidLockDialog.instances[lockName];
    if (existingDialog) then
        existingDialog.notes = notes;
        return existingDialog;
    end
    return RaidLockDialog(win, lockName, settings, charSettings, charID, notes);
end

function RaidLockDialog:Constructor(win, lockName, settings, charSettings, charID, notes)
    -- Enforce only one such window per raid lock
    if (RaidLockDialog.instances[lockName]) then
        error("Dialog exists", 3);
    end
    RaidLockDialog.instances[lockName] = self;

    Turbine.UI.Lotro.Window.Constructor(self);
    local prevContext = L:SetContext("/RaidLockDialog");
    self:SetText(L:GetText("Title"));
    self:SetVisible(true);
    self:SetZOrder(win:GetZOrder() + 1);
    self:SetSize(600, 0);

    self.window = win;
    self.charID = charID or win.charID;
    self.notes = notes;
    self.charName = win:GetCharNameWithServer(charID);
    self.lockName = lockName;
    self.settings = settings;
    self.charSettings = charSettings;
    self.enabled = settings.enabled or false;
    self.currentDesc = settings.desc;
    self.currentLoc = settings.location;
    self.currentCat = settings.category;
    self.currentTab = settings.tab;

    self.resetTimesCtl = ResetTimesControl(settings.resetTimes, false);
    AddCallback(self.resetTimesCtl, "SizeChanged", function()
        self:DoLayout();
    end);
    AddCallback(self.resetTimesCtl, "ValidChanged", function (_, valid)
        self.okButton:SetEnabled(valid);
    end);

    -- Handle ENTER and ESC keys
    EnableEnterEscHandling(self);
    L:SetContext(prevContext);
    self:DoLayout();

    if (win.settings.raidLockDialog.position) then
        self:SetPosition(unpack(win.settings.raidLockDialog.position));
        SetUniquePosition(self, RaidLockDialog.instances);
    else
        CenterWindow(self);
    end
end

function RaidLockDialog:PositionChanged()
    self.window.settings.raidLockDialog.position = {self:GetPosition()};
    self.window:SaveSettings();
end

function RaidLockDialog:DoLayout()
    local settings = self.settings;
    local label, textBox, checkBox;
    local xmargin = 28;
    local width = self:GetWidth() - 2 * xmargin;
    
    local function AddLabel(parent, top, text, height)
        local label = Turbine.UI.Label();
        label:SetFont(Turbine.UI.Lotro.Font.Verdana14);
        label:SetFontStyle(Turbine.UI.FontStyle.Outline);
        label:SetOutlineColor(Turbine.UI.Color.Black);
        label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
        label:SetText(text);
        label:SetParent(parent);
        label:SetPosition(xmargin, top);
        label:SetSize(width, height);
        return label, top + height + 10;
    end

    local function AddCheckBox(parent, top, text, expanded)
        local checkBox = Turbine.UI.Lotro.CheckBox();
        checkBox:SetFont(Turbine.UI.Lotro.Font.Verdana14);
        checkBox:SetFontStyle(Turbine.UI.FontStyle.Outline);
        checkBox:SetOutlineColor(Turbine.UI.Color.Black);
        checkBox:SetParent(parent);
        checkBox:SetPosition(2 * xmargin, top);
        checkBox:SetSize(self:GetWidth(), 16);
        checkBox:SetChecked(expanded);
        if (expanded) then
            text = text .. ":";
        end
        checkBox:SetText(" " .. text);
        return checkBox, top + 24;
    end
    
    local function AddRadioButton(parent, top, text, selected)
        local button = Thurallor.UI.RadioButton(parent, text, selected);
        button:SetFont(Turbine.UI.Lotro.Font.Verdana14);
        button:SetPosition(2 * xmargin, top);
        button:SetSize(width, 14);
        return button, top + 20;
    end

    local function AddTextBox(parent, top, value)
        local textBox = Turbine.UI.Lotro.TextBox();
        textBox:SetParent(parent);
        textBox:SetSelectable(true);
        textBox:SetMultiline(false);
        textBox:SetFont(Turbine.UI.Lotro.Font.Verdana14);
        textBox:SetForeColor(Turbine.UI.Color.PaleGoldenrod);
        textBox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
        textBox:SetText(value);
        textBox:SetPosition(2 * xmargin + L:GetText("ColumnWidth"), top);
        textBox:SetSize(width - textBox:GetLeft(), 22);
        return textBox, top + 34;
    end

    function AddDropDown(parent, top, indent, items, selectedItem)
        local dropDown = Thurallor.UI.DropDown(items, selectedItem);
        dropDown:SetParent(parent);
        dropDown:SetFont(Turbine.UI.Lotro.Font.Verdana14);
        dropDown:SetPosition(2 * xmargin + indent, top);
        dropDown:SetSize(width - dropDown:GetLeft(), 22);
        dropDown:SetAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
        return dropDown, top + 34;
    end

    self:GetControls():Clear();
    collectgarbage();
    local prevContext = L:SetContext("/RaidLockDialog");

    local top = 39;
    local highlight = Turbine.UI.Control();
    highlight:SetBlendMode(Turbine.UI.BlendMode.Overlay);
    highlight:SetBackground(imagePath .. "options_panel_divider.tga");
    highlight:SetParent(self);
    highlight:SetSize(400, 30);
    highlight:SetPosition(math.floor(0.5 + (self:GetWidth() - 400)/2), top);

    label, top = AddLabel(self, top, self.lockName, 30);
    label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
    label:SetFont(Turbine.UI.Lotro.Font.TrajanPro20);
    label:SetForeColor(Turbine.UI.Color.Yellow);

    top = top - 10;
    label, top = AddLabel(self, top, self.charName, 14);
    label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
    label:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
    label:SetForeColor(Turbine.UI.Color.Silver);
    top = top + 10; -- skip some space

    local text = L:GetText("Question");
    label, top = AddLabel(self, top, text, 14 * L:GetText("QuestionLines"));
    label:SetTextAlignment(Turbine.UI.ContentAlignment.BottomLeft);

    yesButton, top = AddRadioButton(self, top, L:GetText("Yes"), self.enabled);
    yesButton.Clicked = function()
        self.enabled = true;
        self:DoLayout();
    end
    noButton, top = AddRadioButton(self, top, L:GetText("No"), not self.enabled);
    noButton.Clicked = function()
        self.enabled = false;
        self:DoLayout();
    end
    Thurallor.UI.RadioButton.LinkPeers({ yesButton, noButton });

    if (self.enabled) then
    
        top = top + 10; -- skip some space

        label, top = AddLabel(self, top, L:GetText("Options") .. ":", 14);
        
        checkBox, top = AddCheckBox(self, top, L:GetText("/MainWindow/ColumnHeadings/Description"), self.currentDesc);
        if (self.currentDesc) then
            self.desc = AddTextBox(self, top - 27, self.currentDesc);
            self.desc.TextChanged = function(ctl)
                self.currentDesc = ctl:GetText();
            end
        end
        checkBox.CheckedChanged = function(ctl)
            self.currentDesc = (ctl:IsChecked() and (settings.desc or self.lockName)) or nil;
            self:DoLayout();
        end

        checkBox, top = AddCheckBox(self, top, L:GetText("/MainWindow/ColumnHeadings/Location"), self.currentLoc);
        if (self.currentLoc) then
            self.location = AddTextBox(self, top - 27, self.currentLoc);
            self.location.TextChanged = function(ctl)
                self.currentLoc = ctl:GetText();
            end
            local cmd = "/" .. L:GetText("/ShellCommand/Command") .. " " .. L:GetText("/ShellCommand/SetLoc") .. " " .. L:GetClientLanguageText("/Chat/loc");
            local getLocButton = Thurallor.UI.TrickButton(cmd, Turbine.ChatType.Standard, nil);
            getLocButton:SetParent(self);
            getLocButton:SetFont(Turbine.UI.Lotro.Font.Verdana14);
            getLocButton:SetText(L:GetText("GetCurrentLocation"));
            getLocButton:SetWidth(L:GetText("GetCurrentLocationWidth"));
            getLocButton:SetPosition(width - getLocButton:GetWidth(), self.location:GetTop() + 1);
            AddCallback(getLocButton, "MouseEnter", function()
                self.window.LocationChanged = function()
                    self.currentLoc = self.window.location;
                    self.location:SetText(self.currentLoc);
                end
            end);
            self.location:SetWidth(getLocButton:GetLeft() - self.location:GetLeft() - 4);
        end
        checkBox.CheckedChanged = function(ctl)
            self.currentLoc = (ctl:IsChecked() and (settings.location or "")) or nil;
            self:DoLayout();
        end

        local catNames, catExists = self.window:GetUserCategories();
        checkBox, top = AddCheckBox(self, top, L:GetText("/MainWindow/ColumnHeadings/Category"), self.currentCat);
        if (self.currentCat) then
            dropDown = AddDropDown(self, top - 27, L:GetText("ColumnWidth"), catNames, self.currentCat);
            dropDown:SetWidth(200);
            dropDown.SelectionChanged = function(ctl, args)
                self.currentCat = args.Item;
            end
        end
        checkBox.CheckedChanged = function(ctl)
            self.currentCat = (ctl:IsChecked() and (settings.category or self.charSettings.autoReminders.raidlocks.category)) or nil;
            self:DoLayout();
        end

        local tabNames, tabExists = self.window:GetUserTabs();
        checkBox, top = AddCheckBox(self, top, L:GetText("Tab"), self.currentTab);
        if (self.currentTab) then
            dropDown = AddDropDown(self, top - 27, L:GetText("ColumnWidth"), tabNames, self.currentTab);
            dropDown:SetWidth(200);
            dropDown.SelectionChanged = function(ctl, args)
                self.currentTab = args.Item;
            end
        end
        checkBox.CheckedChanged = function(ctl)
            self.currentTab = (ctl:IsChecked() and (settings.tab or self.charSettings.autoReminders.raidlocks.tab)) or nil;
            self:DoLayout();
        end

        top = top + 10; -- skip some space

        label, top = AddLabel(self, top, L:GetText("LockResetsAt"), 14);

        self.resetTimesCtl:SetParent(self);
        self.resetTimesCtl:SetPosition(math.floor(0.5 + (self:GetWidth() - self.resetTimesCtl:GetWidth()) / 2), top);
        top = top + self.resetTimesCtl:GetHeight();
    end
    
    top = top + 10; -- skip some space

    self.okButton = Turbine.UI.Lotro.Button();
    self.okButton:SetFont(Turbine.UI.Lotro.Font.Verdana14);
    self.okButton:SetParent(self);
    local reuseExpiredReminders = self.window.settings.reuseExpiredReminders;
    self.nowCheckbox = AddCheckBox(self, top + 2, L:GetText("/RaidLockDialog/RemindMeNow"));
    self.nowCheckbox:SetChecked(reuseExpiredReminders);
    if (self.enabled) then
        self.okButton:SetWidth(L:GetText("/RaidLockDialog/RemindMeWidth"));
        self.okButton:SetText(L:GetText("/RaidLockDialog/RemindMe"));
        Thurallor.UI.Tooltip(L:GetText("/RaidLockDialog/RemindMeNowTooltip")):Attach(self.nowCheckbox);
    else
        self.okButton:SetWidth(L:GetText("/RaidLockDialog/DontRemindMeWidth"));
        self.okButton:SetText(L:GetText("/RaidLockDialog/DontRemindMe"));
        self.nowCheckbox:SetParent(nil);
    end
    self.okButton:SetPosition(math.floor(0.5 + (self:GetWidth() - self.okButton:GetWidth()) / 2), top);
    self.nowCheckbox:SetLeft(self.okButton:GetLeft() + self.okButton:GetWidth() + 6);
    top = top + self.okButton:GetHeight();
    self:SetHeight(top + 24);
    L:SetContext(prevContext);
    
    self.okButton.SetEnabled = function(_, enable)
        -- Lotro.Button can't get mouse events while disabled.  Need to superimpose another control.
        if (enable and not self.okButton:IsEnabled()) then
            self.okMask:SetParent(nil);
            self.okMask = nil;
        elseif (not enable and self.okButton:IsEnabled()) then
            self.okMask = Turbine.UI.Control();
            self.okMask:SetParent(self.okButton);
            self.okMask:SetSize(self.okButton:GetSize());
            Thurallor.UI.Tooltip(L:GetText("/ResetTimesDialog/NotOkTooltip")):Attach(self.okMask);
        end
        Turbine.UI.Lotro.Button.SetEnabled(self.okButton, enable);
    end
    self.okButton.Click = function()
        settings.enabled = self.enabled;
        settings.desc = self.currentDesc;
        settings.location = self.currentLoc;
        settings.category = self.currentCat;
        settings.tab = self.currentTab;
        settings.resetTimes = self.resetTimesCtl:GetTimeSpec();
        if (self.enabled and self.nowCheckbox:IsChecked()) then
            local event = self.window:AddRaidLockReminder(self.lockName, 0, 0, 0, nil, self.charID, self.notes);
            if (event) then
                event:ZoomToEvent(self);
            end
        end
        self.window:SaveSettings();
        self.window:UpdateOptionsPanel();
        DoCallbacks(self, "Accepted");
        self:Close();
    end
end

function RaidLockDialog:EnterKeyPressed()
    DoCallbacks(self.okButton, "Click");
end

function RaidLockDialog:EscapeKeyPressed()
    self:Close();
end

function RaidLockDialog:Closing()
    RaidLockDialog.instances[self.lockName] = nil;
end

Compare with Previous | Blame


All times are GMT -5. The time now is 10:09 PM.


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