console max lines

master
Eduardo Bart 13 years ago
parent 4ebb201da2
commit 8007e37796

@ -3,6 +3,8 @@ Console = { }
local console local console
local logLocked = false local logLocked = false
local commandEnv = createEnvironment() local commandEnv = createEnvironment()
local maxLines = 80
local numLines = 0
function Console.onLog(level, message, time) function Console.onLog(level, message, time)
-- avoid logging while reporting logs (would cause a infinite loop) -- avoid logging while reporting logs (would cause a infinite loop)
@ -28,12 +30,18 @@ end
function Console.addLine(text, color) function Console.addLine(text, color)
-- create new label -- create new label
local label = UILabel.create() local label = UILabel.create()
label:setStyle('ConsoleLabel') label:setStyle('ConsoleLabel')
label:setText(text) label:setText(text)
label:setForegroundColor(color) label:setForegroundColor(color)
console:insertChild(label, -1) console:insertChild(label, -1)
numLines = numLines + 1
if numLines > maxLines then
local firstLine = console:getChildByIndex(0)
firstLine:destroy()
end
end end
function Console.create() function Console.create()

@ -30,9 +30,9 @@ function EnterGame_connectToLoginServer()
mainMenu:hide() mainMenu:hide()
end end
local enterGameWindow = rootWidget:getChild("enterGameWindow") local enterGameWindow = rootWidget:getChildById("enterGameWindow")
local account = enterGameWindow:getChild("accountNameLineEdit"):getText() local account = enterGameWindow:getChildById("accountNameLineEdit"):getText()
local password = enterGameWindow:getChild("accountPasswordLineEdit"):getText() local password = enterGameWindow:getChildById("accountPasswordLineEdit"):getText()
protocolLogin:login(account, password) protocolLogin:login(account, password)
enterGameWindow:destroy() enterGameWindow:destroy()

@ -42,7 +42,8 @@ void LuaInterface::registerFunctions()
g_lua.bindClassMemberFunction<UIWidget>("fill", &UIWidget::fill); g_lua.bindClassMemberFunction<UIWidget>("fill", &UIWidget::fill);
g_lua.bindClassMemberFunction<UIWidget>("centerIn", &UIWidget::centerIn); g_lua.bindClassMemberFunction<UIWidget>("centerIn", &UIWidget::centerIn);
g_lua.bindClassMemberFunction<UIWidget>("addAnchor", &UIWidget::addAnchor); g_lua.bindClassMemberFunction<UIWidget>("addAnchor", &UIWidget::addAnchor);
g_lua.bindClassMemberFunction<UIWidget>("getChild", &UIWidget::getChildById); g_lua.bindClassMemberFunction<UIWidget>("getChildById", &UIWidget::getChildById);
g_lua.bindClassMemberFunction<UIWidget>("getChildByIndex", &UIWidget::getChildByIndex);
g_lua.bindClassMemberFunction<UIWidget>("insertChild", &UIWidget::insertChild); g_lua.bindClassMemberFunction<UIWidget>("insertChild", &UIWidget::insertChild);
g_lua.bindClassMemberFunction<UIWidget>("removeChild", &UIWidget::removeChild); g_lua.bindClassMemberFunction<UIWidget>("removeChild", &UIWidget::removeChild);
g_lua.bindClassMemberFunction<UIWidget>("addChild", &UIWidget::addChild); g_lua.bindClassMemberFunction<UIWidget>("addChild", &UIWidget::addChild);

@ -16,8 +16,10 @@ void Protocol::connect(const std::string& host, uint16 port)
void Protocol::disconnect() void Protocol::disconnect()
{ {
m_connection->close(); if(m_connection) {
m_connection.reset(); m_connection->close();
m_connection.reset();
}
} }
void Protocol::send(OutputMessage& outputMessage) void Protocol::send(OutputMessage& outputMessage)

@ -17,7 +17,6 @@ UIButton::UIButton(): UIWidget(UITypeButton)
UIButtonPtr UIButton::create() UIButtonPtr UIButton::create()
{ {
UIButtonPtr button(new UIButton); UIButtonPtr button(new UIButton);
button->setStyle("Button");
return button; return button;
} }

@ -288,12 +288,15 @@ void UILineEdit::appendCharacter(char c)
void UILineEdit::removeCharacter(bool right) void UILineEdit::removeCharacter(bool right)
{ {
if(m_cursorPos >= 0 && m_text.length() > 0) { if(m_cursorPos >= 0 && m_text.length() > 0) {
if(right && (uint)m_cursorPos < m_text.length()) if((uint)m_cursorPos >= m_text.length()) {
m_text.erase(m_text.begin() + m_cursorPos);
else if((uint)m_cursorPos == m_text.length()) {
m_text.erase(m_text.begin() + (--m_cursorPos)); m_text.erase(m_text.begin() + (--m_cursorPos));
blinkCursor(); } else {
if(right)
m_text.erase(m_text.begin() + m_cursorPos);
else if(m_cursorPos > 0)
m_text.erase(m_text.begin() + --m_cursorPos);
} }
blinkCursor();
update(); update();
} }
} }
@ -355,7 +358,7 @@ void UILineEdit::onKeyPress(UIKeyEvent& event)
{ {
if(event.keyCode() == KC_DELETE) // erase right character if(event.keyCode() == KC_DELETE) // erase right character
removeCharacter(true); removeCharacter(true);
else if(event.keyCode() == KC_BACK) // erase left character else if(event.keyCode() == KC_BACK) // erase left character {
removeCharacter(false); removeCharacter(false);
else if(event.keyCode() == KC_RIGHT) // move cursor right else if(event.keyCode() == KC_RIGHT) // move cursor right
moveCursor(true); moveCursor(true);

@ -287,8 +287,8 @@ bool UIWidget::hasFocus()
if(parent->hasFocus() && parent->getFocusedChild() == shared_from_this()) if(parent->hasFocus() && parent->getFocusedChild() == shared_from_this())
return true; return true;
} }
// root widget always has focus // root parent always has focus
else if(asUIWidget() == g_ui.getRootWidget()) else if(asUIWidget() == getRootParent())
return true; return true;
return false; return false;
} }
@ -350,7 +350,7 @@ UIWidgetPtr UIWidget::getChildById(const std::string& childId)
else if(childId == "parent") else if(childId == "parent")
return getParent(); return getParent();
else if(childId == "root") else if(childId == "root")
return g_ui.getRootWidget(); return getRootParent();
else if(childId == "prev") { else if(childId == "prev") {
if(UIWidgetPtr parent = getParent()) if(UIWidgetPtr parent = getParent())
return parent->getChildBefore(asUIWidget()); return parent->getChildBefore(asUIWidget());
@ -468,7 +468,7 @@ void UIWidget::addChild(const UIWidgetPtr& childToAdd)
updateChildrenLayout(); updateChildrenLayout();
// always focus new children // always focus new children
if(childToAdd->isFocusable()) if(childToAdd->isFocusable() && childToAdd->isExplicitlyVisible() && childToAdd->isExplicitlyEnabled())
focusChild(childToAdd, ActiveFocusReason); focusChild(childToAdd, ActiveFocusReason);
} }

@ -11,7 +11,6 @@ UIWindow::UIWindow(): UIWidget(UITypeWindow)
UIWindowPtr UIWindow::create() UIWindowPtr UIWindow::create()
{ {
UIWindowPtr window(new UIWindow); UIWindowPtr window(new UIWindow);
window->setStyle("Window");
return window; return window;
} }

@ -80,8 +80,8 @@ void Creature::drawInformation(int x, int y, bool useGray)
g_graphics.bindColor(Color::white); g_graphics.bindColor(Color::white);
// name // name
FontPtr font = g_fonts.getFont("tibia-12px-rounded"); FontPtr font = g_fonts.getFont("helvetica-14px-bold");
font->renderText(m_name, Rect(x-50, y-16, 100, 16), AlignTopCenter, fillColor); font->renderText(m_name, Rect(x-100, y-16, 200, 16), AlignTopCenter, fillColor);
} }
const ThingAttributes& Creature::getAttributes() const ThingAttributes& Creature::getAttributes()

Loading…
Cancel
Save