lotrointerface.com
Search Downloads

LoTROInterface SVN Reminders

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

Compare with Previous | Blame | View Log

DelayControl = class(Turbine.UI.Control);

function DelayControl:Constructor(showDays, showHours, showMinutes, showSeconds)
    Turbine.UI.Control.Constructor(self);

    local font = Turbine.UI.Lotro.Font.Verdana14;

    local function AddNudger(left, value, minValue, maxValue)
        local nudger = Nudger(self, font, value, minValue, maxValue);
        AddCallback(nudger, "FocusGained", function()
            DoCallbacks(self, "FocusGained");
        end);
        AddCallback(nudger, "ValueChanged", function()
            DoCallbacks(self, "DelayChanged");
        end);
        nudger:SetPosition(left, 0);
        nudger:SetWidth(30);
        return nudger, left + 30;
    end

    local function AddLabel(left, 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() + 8, 20)
        label:SetParent(self);
        label:SetPosition(left, 13);
        return label, left + label:GetWidth();
    end

    -------------------------------
    -- * Delay from now:
    -------------------------------
    left = 0;
    if (showDays) then
        self.days, left = AddNudger(left, 0, 0, nil);
        label, left = AddLabel(left, L:GetText("/Time/Days") .. " ");
    end
    if (showHours) then
        self.hours, left = AddNudger(left, 0, 0, 23);
        label, left = AddLabel(left, L:GetText("/Time/Hours") .. " ");
    end
    if (showMinutes) then
        self.minutes, left = AddNudger(left, 0, 0, 59);
        label, left = AddLabel(left, L:GetText("/Time/Minutes") .. " ");
    end
    if (showSeconds) then
        self.seconds, left = AddNudger(left, 0, 0, 59);
        label, left = AddLabel(left, L:GetText("/Time/Seconds"));
    end
    
    self:SetSize(left, self.days:GetHeight());
end

function DelayControl:SetDelay(delay)
    delay = math.ceil(delay);
    local s = math.floor(delay % 60);
    local m = math.floor((delay % 3600) / 60);
    local h = math.floor((delay % 86400) / 3600);
    local d = math.floor(delay / 86400);
    if (self.days) then
        self.days:SetText(d);
    end
    if (self.hours) then
        self.hours:SetText(h);
    end
    if (self.minutes) then
        self.minutes:SetText(m);
    end
    if (self.seconds) then
        self.seconds:SetText(s);
    end
end

function DelayControl:GetDelay()
    local delay = 0;
    if (self.days) then
        delay = delay + tonumber(self.days:GetText()) * 24 * 60 * 60;
    end
    if (self.hours) then
        delay = delay + tonumber(self.hours:GetText()) * 60 * 60;
    end
    if (self.minutes) then
        delay = delay + tonumber(self.minutes:GetText()) * 60;
    end
    if (self.seconds) then
        delay = delay + tonumber(self.seconds:GetText());
    end
    return delay;
end

Compare with Previous | Blame


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


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