diff --git a/modules/client_modulemanager/modulemanager.lua b/modules/client_modulemanager/modulemanager.lua index 4d6f8b6e..dc372f49 100644 --- a/modules/client_modulemanager/modulemanager.lua +++ b/modules/client_modulemanager/modulemanager.lua @@ -105,7 +105,6 @@ function ModuleManager.updateModuleInfo(moduleName) moduleManagerWindow:recursiveGetChildById('moduleName'):setText(name) moduleManagerWindow:recursiveGetChildById('moduleDescription'):setText(description) - moduleManagerWindow:recursiveGetChildById('moduleDescription'):wrapText() moduleManagerWindow:recursiveGetChildById('moduleAuthor'):setText(author) moduleManagerWindow:recursiveGetChildById('moduleWebsite'):setText(website) moduleManagerWindow:recursiveGetChildById('moduleVersion'):setText(version) diff --git a/modules/client_modulemanager/modulemanager.otui b/modules/client_modulemanager/modulemanager.otui index 2d58499e..3cb4b6b5 100644 --- a/modules/client_modulemanager/modulemanager.otui +++ b/modules/client_modulemanager/modulemanager.otui @@ -85,6 +85,7 @@ MainWindow ModuleValueLabel id: moduleDescription height: 100 + text-wrap: true //ModuleInfoLabel // text: Autoload diff --git a/modules/core_lib/mouse.lua b/modules/core_lib/mouse.lua index 0f6e8a90..ccefbc28 100644 --- a/modules/core_lib/mouse.lua +++ b/modules/core_lib/mouse.lua @@ -16,6 +16,10 @@ function Mouse.restoreCursor() g_window.restoreMouseCursor() end +function Mouse.isPressed() + return g_ui.getPressedWidget() == nil +end + function Mouse.bindAutoPress(widget, callback) connect(widget, { onMousePress = function(widget, mousePos, mouseButton) callback() diff --git a/modules/core_lib/ui/tooltip.lua b/modules/core_lib/ui/tooltip.lua index df593d49..a8fdd19c 100644 --- a/modules/core_lib/ui/tooltip.lua +++ b/modules/core_lib/ui/tooltip.lua @@ -21,7 +21,7 @@ end local function onWidgetHoverChange(widget, hovered) if hovered then - if widget.tooltip then + if widget.tooltip and not Mouse.isPressed() then ToolTip.display(widget.tooltip) currentHoveredWidget = widget end diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 1e297efe..653dbd97 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -229,8 +229,14 @@ function Console.clear() channels = {} channels[0] = 'Default' - consoleTabBar:getTab('Default').tabPanel:destroyChildren() - consoleTabBar:getTab('Server Log').tabPanel:destroyChildren() + consoleTabBar:getTab('Default').tabPanel:getChildById('consoleBuffer'):destroyChildren() + consoleTabBar:getTab('Server Log').tabPanel:getChildById('consoleBuffer'):destroyChildren() + + local npcTab = consoleTabBar:getTab('NPCs') + if npcTab then + consoleTabBar:removeTab(npcTab) + end + consoleLineEdit:clearText() if channelsWindow then diff --git a/modules/game_console/console.otui b/modules/game_console/console.otui index 44db53ac..c3e50d94 100644 --- a/modules/game_console/console.otui +++ b/modules/game_console/console.otui @@ -2,6 +2,9 @@ ConsoleLabel < UILabel font: verdana-11px-antialised height: 14 color: yellow + margin-left: 2 + text-wrap: true + text-auto-resize: true ConsoleTabBar < TabBar ConsoleTabBarPanel < TabBarPanel diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index 9cf0e734..aca30df8 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -37,7 +37,6 @@ local function displayMessage(msgtype, msg, time) if msgtype.wrap then label:setWidth(label:getParent():getWidth()) - label:wrapText() label:setHeight(label:getTextSize().height) else label:resizeToText() diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 6ac2f434..92a976f4 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -294,14 +294,15 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("getImageBorderLeft", &UIWidget::getImageBorderLeft); g_lua.bindClassMemberFunction("resizeToText", &UIWidget::resizeToText); g_lua.bindClassMemberFunction("clearText", &UIWidget::clearText); - g_lua.bindClassMemberFunction("wrapText", &UIWidget::wrapText); g_lua.bindClassMemberFunction("setText", &UIWidget::setText); g_lua.bindClassMemberFunction("setTextAlign", &UIWidget::setTextAlign); g_lua.bindClassMemberFunction("setTextOffset", &UIWidget::setTextOffset); + g_lua.bindClassMemberFunction("setTextWrap", &UIWidget::setTextWrap); g_lua.bindClassMemberFunction("setFont", &UIWidget::setFont); g_lua.bindClassMemberFunction("getText", &UIWidget::getText); g_lua.bindClassMemberFunction("getTextAlign", &UIWidget::getTextAlign); g_lua.bindClassMemberFunction("getTextOffset", &UIWidget::getTextOffset); + g_lua.bindClassMemberFunction("getTextWrap", &UIWidget::getTextWrap); g_lua.bindClassMemberFunction("getFont", &UIWidget::getFont); g_lua.bindClassMemberFunction("getTextSize", &UIWidget::getTextSize); @@ -502,6 +503,7 @@ void Application::registerLuaFunctions() g_lua.bindClassStaticFunction("g_ui", "createWidgetFromOTML", std::bind(&UIManager::createWidgetFromOTML, &g_ui, _1, _2)); g_lua.bindClassStaticFunction("g_ui", "getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui)); g_lua.bindClassStaticFunction("g_ui", "getDraggingWidget", std::bind(&UIManager::getDraggingWidget, &g_ui)); + g_lua.bindClassStaticFunction("g_ui", "getPressedWidget", std::bind(&UIManager::getPressedWidget, &g_ui)); g_lua.bindClassStaticFunction("g_ui", "setDebugBoxesDrawing", std::bind(&UIManager::setDebugBoxesDrawing, &g_ui, _1)); g_lua.bindClassStaticFunction("g_ui", "isDrawingDebugBoxes", std::bind(&UIManager::setDebugBoxesDrawing, &g_ui, _1)); diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 2ecaa749..c853b0b3 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -1251,13 +1251,14 @@ void UIWidget::onStyleApply(const std::string& styleName, const OTMLNodePtr& sty void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect) { callLuaField("onGeometryChange", oldRect, newRect); + + if(m_textWrap && oldRect.size() != newRect.size()) + updateText(); } void UIWidget::onLayoutUpdate() { callLuaField("onLayoutUpdate"); - if(UIWidgetPtr parent = getParent()) - parent->onLayoutUpdate(); } void UIWidget::onFocusChange(bool focused, Fw::FocusReason reason) diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 15f89eac..1aec856f 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -436,6 +436,7 @@ public: // text related private: void initText(); + void updateText(); void parseTextStyle(const OTMLNodePtr& styleNode); Boolean m_textMustRecache; @@ -449,25 +450,31 @@ protected: virtual void onFontChange(const std::string& font); std::string m_text; + std::string m_drawText; Fw::AlignmentFlag m_textAlign; Point m_textOffset; + Boolean m_textWrap; + Boolean m_textAutoResize; FontPtr m_font; public: void resizeToText() { setSize(getTextSize()); } void clearText() { setText(""); } - void wrapText(); void setText(const std::string& text); - void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; m_textMustRecache = true; } - void setTextOffset(const Point& offset) { m_textOffset = offset; m_textMustRecache = true; } + void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; updateText(); } + void setTextOffset(const Point& offset) { m_textOffset = offset; updateText(); } + void setTextWrap(bool textWrap) { m_textWrap = textWrap; updateText(); } + void setTextAutoResize(bool textAutoResize) { m_textAutoResize = textAutoResize; updateText(); } void setFont(const std::string& fontName); std::string getText() { return m_text; } + std::string getDrawText() { return m_drawText; } Fw::AlignmentFlag getTextAlign() { return m_textAlign; } Point getTextOffset() { return m_textOffset; } + bool getTextWrap() { return m_textWrap; } std::string getFont() { return m_font->getName(); } - Size getTextSize() { return m_font->calculateTextRectSize(m_text); } + Size getTextSize() { return m_font->calculateTextRectSize(m_drawText); } }; #endif diff --git a/src/framework/ui/uiwidgettext.cpp b/src/framework/ui/uiwidgettext.cpp index 9d1c5101..45d61c68 100644 --- a/src/framework/ui/uiwidgettext.cpp +++ b/src/framework/ui/uiwidgettext.cpp @@ -33,6 +33,29 @@ void UIWidget::initText() m_textCoordsBuffer.enableHardwareCaching(); } +void UIWidget::updateText() +{ + if(m_textWrap && m_rect.isValid()) + m_drawText = m_font->wrapText(m_text, getWidth() - m_textOffset.x); + else + m_drawText = m_text; + + // update rect size + if(!m_rect.isValid()) { + Size textSize = getTextSize(); + Size newSize = getSize(); + if(newSize.width() <= 0) + newSize.setWidth(textSize.width()); + if(newSize.height() <= 0) + newSize.setHeight(textSize.height()); + setSize(newSize); + } else if(m_textAutoResize) { + setSize(getTextSize()); + } + + m_textMustRecache = true; +} + void UIWidget::parseTextStyle(const OTMLNodePtr& styleNode) { for(const OTMLNodePtr& node : styleNode->children()) { @@ -42,6 +65,10 @@ void UIWidget::parseTextStyle(const OTMLNodePtr& styleNode) setTextAlign(Fw::translateAlignment(node->value())); else if(node->tag() == "text-offset") setTextOffset(node->value()); + else if(node->tag() == "text-wrap") + setTextWrap(node->value()); + else if(node->tag() == "text-auto-resize") + setTextAutoResize(node->value()); else if(node->tag() == "font") setFont(node->value()); } @@ -49,7 +76,7 @@ void UIWidget::parseTextStyle(const OTMLNodePtr& styleNode) void UIWidget::drawText(const Rect& screenCoords) { - if(m_text.length() == 0 || m_color.aF() == 0.0f) + if(m_drawText.length() == 0 || m_color.aF() == 0.0f) return; if(screenCoords != m_textCachedScreenCoords || m_textMustRecache) { @@ -58,7 +85,7 @@ void UIWidget::drawText(const Rect& screenCoords) m_textCoordsBuffer.clear(); - m_font->calculateDrawTextCoords(m_textCoordsBuffer, m_text, screenCoords.translated(m_textOffset), m_textAlign); + m_font->calculateDrawTextCoords(m_textCoordsBuffer, m_drawText, screenCoords.translated(m_textOffset), m_textAlign); } g_painter.setColor(m_color); @@ -75,11 +102,6 @@ void UIWidget::onFontChange(const std::string& font) callLuaField("onFontChange", font); } -void UIWidget::wrapText() -{ - setText(m_font->wrapText(m_text, getWidth() - m_textOffset.x)); -} - void UIWidget::setText(const std::string& text) { if(m_text == text) @@ -87,25 +109,14 @@ void UIWidget::setText(const std::string& text) std::string oldText = m_text; m_text = text; - - // update rect size - if(!m_rect.isValid()) { - Size textSize = m_font->calculateTextRectSize(m_text); - Size newSize = getSize(); - if(newSize.width() <= 0) - newSize.setWidth(textSize.width()); - if(newSize.height() <= 0) - newSize.setHeight(textSize.height()); - setSize(newSize); - } + updateText(); onTextChange(text, oldText); - m_textMustRecache = true; } void UIWidget::setFont(const std::string& fontName) { m_font = g_fonts.getFont(fontName); + updateText(); onFontChange(fontName); - m_textMustRecache = true; }