lotrointerface.com
Search Downloads

LoTROInterface SVN Reminders

[/] [trunk/] [Thurallor/] [Reminders/] [ConfirmDialog.lua] - Rev 2

Compare with Previous | Blame | View Log

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

function ConfirmDialog:Constructor(win, title)
    Turbine.UI.Lotro.Window.Constructor(self);
    local prevContext = L:SetContext("/ConfirmDialog");
    self:SetText(L:GetText("AreYouSure"));
    self:SetVisible(true);

    local font = Turbine.UI.Lotro.Font.Verdana14;
    local xmargin = 28;
    local parent = self;
    
    local function AddLabel(left, top, text)
        local label = Turbine.UI.Label();
        label:SetFont(font);
        label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
        label:SetText(text);
        label:SetMultiline(false);
        label:AutoSize();
        label:SetSize(label:GetWidth(), 20)
        label:SetParent(parent);
        label:SetPosition(left, top);
        return label, left + label:GetWidth();
    end
    
    local function AddButton(left, top, width, text)
        local button = Turbine.UI.Lotro.Button();
        button:SetParent(parent);
        button:SetText(text);
        button:SetPosition(left, top);
        button:SetWidth(width);
        return button, left + button:GetWidth() + 4;
    end

    local function AddCheckBox(left, top, width, text, expanded)
        local checkBox = Turbine.UI.Lotro.CheckBox();
        checkBox:SetFont(font);
        checkBox:SetParent(parent);
        checkBox:SetPosition(left, top);
        checkBox:SetChecked(expanded);
        checkBox:SetText(" " .. text);
        checkBox:SetSize(width, 24);
        return checkBox, top + 24;
    end
    
    local left, top = xmargin, 41;
    parent = self;
    local label = AddLabel(left, top, title .. "?");
    top = top + label:GetHeight() + 10;
    
    local buttons = Turbine.UI.Control();
    buttons:SetParent(self);
    buttons:SetPosition(xmargin, top);

    parent = buttons;
    self.yesButton, left = AddButton(0, 0, 50, L:GetText("Yes"));
    self.yesButton.Click = function()
        DoCallbacks(self, "Yes", self.askCheckBox:IsChecked());
        self:Close();
    end
    self.noButton, left = AddButton(left, 0, 50, L:GetText("No"));
    self.noButton.Click = function()
        DoCallbacks(self, "No", self.askCheckBox:IsChecked());
        self:Close();
    end
    buttons:SetSize(left, self.noButton:GetHeight());

    parent = self;
    font = Turbine.UI.Lotro.Font.Verdana12
    local left, top = xmargin + 10, top + buttons:GetHeight() + 10;
    self.askCheckBox = AddCheckBox(left, top, L:GetText("AskBeforeDeletingWidth"), L:GetText("AskBeforeDeleting"), true);
    self.askCheckBox.CheckedChanged = function()
        win.settings.askBeforeDeleting = self.askCheckBox:IsChecked();
        win:UpdateOptionsPanel();
        win:SaveSettings();
    end

    self:AutoSize();
    local width, height = self:GetSize();
    label:SetLeft(math.floor(0.5 + (width - label:GetWidth()) / 2));
    buttons:SetLeft(math.floor(0.5 + (width - buttons:GetWidth()) / 2));
    self:SetHeight(height - 20);

    -- Position this window so the "No" button is at the mouse position
    local x, y = Turbine.UI.Display.GetMousePosition();
    local left, top = self.noButton:PointToScreen(0, 0);
    left = left + math.floor(self.noButton:GetWidth() / 2);
    top = top + math.floor(self.noButton:GetHeight() / 2);
    left = math.max(0, self:GetLeft() + x - left);
    top = math.max(0, self:GetTop() + y - top);
    self:SetPosition(left, top);
    
    L:SetContext(prevContext);
end

function ConfirmDialog:Closing()
    DoCallbacks(self, "No", self.askCheckBox:IsChecked());
end

Compare with Previous | Blame


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


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