diff --git a/modules/console/console.lua b/modules/console/console.lua index 75c142b4..0aadd155 100644 --- a/modules/console/console.lua +++ b/modules/console/console.lua @@ -3,6 +3,8 @@ Console = { } local console local logLocked = false local commandEnv = createEnvironment() +local maxLines = 80 +local numLines = 0 function Console.onLog(level, message, time) -- avoid logging while reporting logs (would cause a infinite loop) @@ -28,12 +30,18 @@ end function Console.addLine(text, color) -- create new label + local label = UILabel.create() label:setStyle('ConsoleLabel') label:setText(text) label:setForegroundColor(color) - console:insertChild(label, -1) + + numLines = numLines + 1 + if numLines > maxLines then + local firstLine = console:getChildByIndex(0) + firstLine:destroy() + end end function Console.create() diff --git a/modules/mainmenu/entergame.lua b/modules/mainmenu/entergame.lua index 3f7d72bc..5192a425 100644 --- a/modules/mainmenu/entergame.lua +++ b/modules/mainmenu/entergame.lua @@ -30,9 +30,9 @@ function EnterGame_connectToLoginServer() mainMenu:hide() end - local enterGameWindow = rootWidget:getChild("enterGameWindow") - local account = enterGameWindow:getChild("accountNameLineEdit"):getText() - local password = enterGameWindow:getChild("accountPasswordLineEdit"):getText() + local enterGameWindow = rootWidget:getChildById("enterGameWindow") + local account = enterGameWindow:getChildById("accountNameLineEdit"):getText() + local password = enterGameWindow:getChildById("accountPasswordLineEdit"):getText() protocolLogin:login(account, password) enterGameWindow:destroy() diff --git a/src/framework/luascript/luafunctions.cpp b/src/framework/luascript/luafunctions.cpp index 328c3e00..4257d24d 100644 --- a/src/framework/luascript/luafunctions.cpp +++ b/src/framework/luascript/luafunctions.cpp @@ -42,7 +42,8 @@ void LuaInterface::registerFunctions() g_lua.bindClassMemberFunction("fill", &UIWidget::fill); g_lua.bindClassMemberFunction("centerIn", &UIWidget::centerIn); g_lua.bindClassMemberFunction("addAnchor", &UIWidget::addAnchor); - g_lua.bindClassMemberFunction("getChild", &UIWidget::getChildById); + g_lua.bindClassMemberFunction("getChildById", &UIWidget::getChildById); + g_lua.bindClassMemberFunction("getChildByIndex", &UIWidget::getChildByIndex); g_lua.bindClassMemberFunction("insertChild", &UIWidget::insertChild); g_lua.bindClassMemberFunction("removeChild", &UIWidget::removeChild); g_lua.bindClassMemberFunction("addChild", &UIWidget::addChild); diff --git a/src/framework/net/protocol.cpp b/src/framework/net/protocol.cpp index 2e490b21..f4618675 100644 --- a/src/framework/net/protocol.cpp +++ b/src/framework/net/protocol.cpp @@ -16,8 +16,10 @@ void Protocol::connect(const std::string& host, uint16 port) void Protocol::disconnect() { - m_connection->close(); - m_connection.reset(); + if(m_connection) { + m_connection->close(); + m_connection.reset(); + } } void Protocol::send(OutputMessage& outputMessage) diff --git a/src/framework/ui/uibutton.cpp b/src/framework/ui/uibutton.cpp index 248ee09b..97844a41 100644 --- a/src/framework/ui/uibutton.cpp +++ b/src/framework/ui/uibutton.cpp @@ -17,7 +17,6 @@ UIButton::UIButton(): UIWidget(UITypeButton) UIButtonPtr UIButton::create() { UIButtonPtr button(new UIButton); - button->setStyle("Button"); return button; } diff --git a/src/framework/ui/uilineedit.cpp b/src/framework/ui/uilineedit.cpp index f5945dd3..83c30b95 100644 --- a/src/framework/ui/uilineedit.cpp +++ b/src/framework/ui/uilineedit.cpp @@ -288,12 +288,15 @@ void UILineEdit::appendCharacter(char c) void UILineEdit::removeCharacter(bool right) { if(m_cursorPos >= 0 && m_text.length() > 0) { - if(right && (uint)m_cursorPos < m_text.length()) - m_text.erase(m_text.begin() + m_cursorPos); - else if((uint)m_cursorPos == m_text.length()) { + if((uint)m_cursorPos >= m_text.length()) { 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(); } } @@ -355,7 +358,7 @@ void UILineEdit::onKeyPress(UIKeyEvent& event) { if(event.keyCode() == KC_DELETE) // erase right character removeCharacter(true); - else if(event.keyCode() == KC_BACK) // erase left character + else if(event.keyCode() == KC_BACK) // erase left character { removeCharacter(false); else if(event.keyCode() == KC_RIGHT) // move cursor right moveCursor(true); diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index b1124adc..8385c356 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -287,8 +287,8 @@ bool UIWidget::hasFocus() if(parent->hasFocus() && parent->getFocusedChild() == shared_from_this()) return true; } - // root widget always has focus - else if(asUIWidget() == g_ui.getRootWidget()) + // root parent always has focus + else if(asUIWidget() == getRootParent()) return true; return false; } @@ -350,7 +350,7 @@ UIWidgetPtr UIWidget::getChildById(const std::string& childId) else if(childId == "parent") return getParent(); else if(childId == "root") - return g_ui.getRootWidget(); + return getRootParent(); else if(childId == "prev") { if(UIWidgetPtr parent = getParent()) return parent->getChildBefore(asUIWidget()); @@ -468,7 +468,7 @@ void UIWidget::addChild(const UIWidgetPtr& childToAdd) updateChildrenLayout(); // always focus new children - if(childToAdd->isFocusable()) + if(childToAdd->isFocusable() && childToAdd->isExplicitlyVisible() && childToAdd->isExplicitlyEnabled()) focusChild(childToAdd, ActiveFocusReason); } diff --git a/src/framework/ui/uiwindow.cpp b/src/framework/ui/uiwindow.cpp index e14028d0..c655cad1 100644 --- a/src/framework/ui/uiwindow.cpp +++ b/src/framework/ui/uiwindow.cpp @@ -11,7 +11,6 @@ UIWindow::UIWindow(): UIWidget(UITypeWindow) UIWindowPtr UIWindow::create() { UIWindowPtr window(new UIWindow); - window->setStyle("Window"); return window; } diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index c06180f5..5873bc76 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -80,8 +80,8 @@ void Creature::drawInformation(int x, int y, bool useGray) g_graphics.bindColor(Color::white); // name - FontPtr font = g_fonts.getFont("tibia-12px-rounded"); - font->renderText(m_name, Rect(x-50, y-16, 100, 16), AlignTopCenter, fillColor); + FontPtr font = g_fonts.getFont("helvetica-14px-bold"); + font->renderText(m_name, Rect(x-100, y-16, 200, 16), AlignTopCenter, fillColor); } const ThingAttributes& Creature::getAttributes()