lotrointerface.com
Search Downloads

LoTROInterface SVN Reminders

[/] [trunk/] [Thurallor/] [Reminders/] [PostponeTimeDialog.lua] - Rev 5

Compare with Previous | Blame | View Log

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

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

function PostponeTimeDialog:Constructor(event)
    Turbine.UI.Lotro.Window.Constructor(self);
    local prevContext = L:SetContext("/PostponeTimeDialog");
    self:SetText(L:GetText("Title"));
    self:SetVisible(true);
    self.event = event;

    -- If the event is deleted, we should close this window
    self.eventDestroyedFunc = function()
        self:Close();
    end
    -- If the window is closed, we should unregister the callback
    self.Closing = function()
        RemoveCallback(event, "Destroyed", self.eventDestroyedFunc);
    end
    -- Register the callback now, but first make sure it isn't already registered
    self.Closing();
    AddCallback(event, "Destroyed", self.eventDestroyedFunc);
    
    local font = Turbine.UI.Lotro.Font.Verdana14;
    local xmargin = 28;
    local parent = self;
    
    local function AddRadioButton(left, top, text, selected)
        local button = Thurallor.UI.RadioButton(parent, " " .. text, selected);
        button:SetFont(font);
        button:SetPosition(left, top);
        button:AutoSize();
        button:SetHeight(14);
        return button, left + button:GetWidth();
    end
    
    local function AddLabel(left, top, text)
        local label = Turbine.UI.Label();
        label:SetFont(font);
        label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
        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 left, top = xmargin, 41;
    
    local before_text, after_text = string.match(L:GetText("Instructions"), "^(.*)<icon>(.*)$");
    
    local label, left = AddLabel(left, top, before_text);

    local icon = Turbine.UI.Control();
    icon:SetParent(self);
    icon:SetBlendMode(Turbine.UI.BlendMode.Overlay);
    icon:SetBackground(imagePath .. "next_login.tga");
    icon:SetPosition(left, top);
    icon:SetSize(22, 22);
    left = left + 22;
    
    label = AddLabel(left, top, after_text);
    left, top = 2 * xmargin, top + label:GetHeight() + 10;

    -------------------------------
    -- * Delay from now:
    -------------------------------
    self.atNextLogin = AddRadioButton(left, top, L:GetText("DeferUntilNextLogin"), false);
    top = top + self.atNextLogin:GetHeight() + 10;

    self.postponeUntil = AddRadioButton(left, top, L:GetText("PostponeFor"), false);
    left, top = 3 * xmargin, top + self.postponeUntil:GetHeight() + 10;
    
    self.delayControl = DelayControl(true, true, true, true);
    self.delayControl:SetParent(self);
    self.delayControl:SetPosition(left, top);
    AddCallback(self.delayControl, "FocusGained", function()
        self.postponeUntil:MouseClick();
    end);
    top = top + self.delayControl:GetHeight() + 10;
    
    self.fromExpiration = AddRadioButton(left, top, L:GetText("FromPreviousExpiration"), true);
    top = top + self.fromExpiration:GetHeight();
    self.fromNow = AddRadioButton(left, top, L:GetText("FromCurrentTime"), false);
    top = top + self.fromNow:GetHeight() + 10;

    Thurallor.UI.RadioButton.LinkPeers({ self.fromNow, self.fromExpiration });
    
    left = 2 * xmargin;

    self.dailyResetTime = AddRadioButton(left, top, L:GetText("DeferUntilDailyResetTime"), false);
    top = top + self.dailyResetTime:GetHeight() + 10;

    self.scheduledResetTime = AddRadioButton(left, top, L:GetText("DeferUntilScheduledResetTime"), false);
    top = top + self.scheduledResetTime:GetHeight() + 10;
    
    self.never = AddRadioButton(left, top, L:GetText("TurnOffTimer"), false);
    top = top + self.never:GetHeight() + 10;
    
    Thurallor.UI.RadioButton.LinkPeers({ self.dailyResetTime, self.scheduledResetTime, self.postponeUntil, self.never, self.atNextLogin });

    local buttons = Turbine.UI.Control();
    buttons:SetParent(self);
    buttons:SetPosition(xmargin, top);

    parent = buttons;
    self.okButton, left = AddButton(0, 0, 50, L:GetText("/ExpireTimeDialog/Ok"));
    self.okButton.Click = function()
        if (self.postponeUntil:IsChecked()) then
            self.event.settings.postpone.delay = math.max(1, self.delayControl:GetDelay());
            if (self.fromNow:IsChecked()) then
                self.event.settings.postpone.method = "DelayFromNow";
            else -- self.fromExpiration:IsChecked()
                self.event.settings.postpone.method = "DelayFromExpiration";
            end
        elseif (self.dailyResetTime:IsChecked()) then
            self.event.settings.postpone.method = "DailyResetTime";
        elseif (self.scheduledResetTime:IsChecked()) then
            self.event.settings.postpone.method = "ScheduledResetTime";
        elseif (self.never:IsChecked()) then
            self.event.settings.postpone.method = "Never";
        else -- self.atNextLogin:IsChecked()
            self.event.settings.postpone.method = "AtNextLogin";
        end
        self:Close();
    end
    
    self.cancelButton, left = AddButton(left, 0, L:GetText("/ExpireTimeDialog/CancelWidth"), L:GetText("/ExpireTimeDialog/Cancel"));
    self.cancelButton.Click = function()
        self:Close();
    end
    buttons:SetSize(left - 4, self.cancelButton:GetHeight());
    self:AutoSize();
    local width, height = self:GetSize();
    buttons:SetLeft(math.floor(0.5 + (width - buttons:GetWidth()) / 2));

    -- Position this window so it's center is at the mouse position
    local x, y = Turbine.UI.Display.GetMousePosition();
    local left = math.max(0, x - math.floor(width / 2));
    local top = math.max(0, y - math.floor(height / 2));
    self:SetPosition(left, top);
    EnsureOnScreen(self);
    
    -- Handle ENTER and ESC keys
    EnableEnterEscHandling(self);

    -- Intelligently set the initial radio button choice:
    self.delayControl:SetDelay(event.settings.postpone.delay or (30 * 60));
    if (event.settings.postpone.method =="DelayFromNow") then
        self.postponeUntil:MouseClick();
        self.fromNow:MouseClick();
    elseif (event.settings.postpone.method =="DelayFromExpiration") then
        self.postponeUntil:MouseClick();
        self.fromExpiration:MouseClick();
    elseif (event.settings.postpone.method =="DailyResetTime") then
        self.dailyResetTime:MouseClick();
    elseif (event.settings.postpone.method =="ScheduledResetTime") then
        self.scheduledResetTime:MouseClick();
    elseif (event.settings.postpone.method =="Never") then
        self.never:MouseClick();
    else -- (event.settings.postpone.method =="AtNextLogin")
        self.atNextLogin:MouseClick();
    end
    L:SetContext(prevContext);
end

function PostponeTimeDialog:Close()
    DoCallbacks(self, "Closing");
    Turbine.UI.Lotro.Window.Close(self);
end

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

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

Compare with Previous | Blame


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


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