lotrointerface.com
Search Downloads

LoTROInterface SVN Reminders

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

Compare with Previous | Blame | View Log

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

function NotesDialog:Constructor(event)
    Turbine.UI.Lotro.Window.Constructor(self);
    self:SetText(L:GetText("/MainWindow/ColumnHeadings/Notes"));
    self:SetVisible(true);
    self.event, self.window = event, event.tab.window;

    -- 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);
        self:SetWantsUpdates(false);
    end
    -- Register the callback now, but first make sure it isn't already registered
    self.Closing();
    AddCallback(event, "Destroyed", self.eventDestroyedFunc);

    -- Make this window prevent access to the main window while it's open
    self:SetZOrder(self.window:GetZOrder() + 1);
    self.window:WaitForChild(self);

    local text = self.event:GetNotes();
    self.textCtl = Turbine.UI.Lotro.TextBox();
    self.textCtl:SetFont(Turbine.UI.Lotro.Font.Verdana14);
    self.textCtl:SetText(text);
    
    self.scrollBar = Turbine.UI.Lotro.ScrollBar();
    self.scrollBar:SetOrientation(Turbine.UI.Orientation.Vertical);

    self.id = id;
    self.window = event.tab.window;
    self.settings = self.window.settings.NotesDialog or {};
    self.window.settings.NotesDialog = self.settings;

    -- Restore saved size / position
    local defaultSize = { 250, 200 };
    local width, height = unpack(self.settings.size or defaultSize);
    local screenWidth, screenHeight = Turbine.UI.Display.GetSize();
    local defaultLeft = math.floor((screenWidth - width) / 2);
    local defaultTop = math.floor((screenHeight - height) / 2);
    local left, top = unpack(self.settings.position or { defaultLeft, defaultTop });
    self:SetSize(width, height);
    self:SetPosition(left, top);
    self:SetMinimumSize(250, 109);
    self:SetResizable(true);
    EnsureOnScreen(self);
    
    -- Handle ENTER and ESC keys
    EnableEnterEscHandling(self);
    
    self:Focus();
end

-- Wait a tick, then activate and focus
function NotesDialog:Focus()
    self.textCtl.Update = function(textCtl)
        self:Activate();
        textCtl:Focus();
        textCtl:SetWantsUpdates(false);
    end
    self.textCtl:SetWantsUpdates(true);
end

function NotesDialog:SizeChanged()
    self:DoLayout();
    self.settings.size = { self:GetSize() };
    self.window:SaveSettings();
    self:Focus();
end

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

function NotesDialog:DoLayout()
    local width, height = self:GetSize();
    local xmargin = 28;
    local ymargin = 20;
    local buttonHeight = 20;

    self:GetControls():Clear();
    collectgarbage();

    local top = ymargin + 19;
    self.textCtl:SetParent(self);
    self.textCtl:SetPosition(xmargin, top);
    self.textCtl:SetSize(width - 2 * xmargin, height - top - 10 - buttonHeight - ymargin);

    local left = xmargin + self.textCtl:GetWidth();
    self.scrollBar:SetParent(self);
    self.scrollBar:SetPosition(left, top)
    self.scrollBar:SetSize(10, self.textCtl:GetHeight());
    self.textCtl:SetVerticalScrollBar(nil);
    self.textCtl:SetVerticalScrollBar(self.scrollBar);
    
    top = top + self.textCtl:GetHeight() + 10; -- skip some space

    local buttons = Turbine.UI.Control();
    buttons:SetParent(self);
    buttons:SetTop(top);

    local function AddButton(parent, 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;
    end

    self.okButton = AddButton(buttons, 0, 0, 50, L:GetText("/ExpireTimeDialog/Ok"));
    self.okButton.Click = function()
        local text = self.textCtl:GetText();
        text = text:gsub("^[%c%s]+", ""):gsub("[%c%s]+$", "");
        DoCallbacks(self, "Ok", { text = text });
        self:Close();
    end
    left = self.okButton:GetWidth() + 4;
    
    self.cancelButton = AddButton(buttons, left, 0, L:GetText("/ExpireTimeDialog/CancelWidth"), L:GetText("/ExpireTimeDialog/Cancel"));
    self.cancelButton.Click = function()
        self:Close();
    end

    buttons:SetSize(left + self.cancelButton:GetWidth(), buttonHeight);
    buttons:SetLeft(math.floor(0.5 + (width - buttons:GetWidth()) / 2));
end

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

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

Compare with Previous | Blame


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


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