From 46df3c7dbedf903e86c2ef2e10c8b74e0d55d06b Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 6 Feb 2012 22:41:53 -0200 Subject: [PATCH] some window moving --- TODO | 4 +- addons/README.txt | 2 +- modules/client_about/about.lua | 1 + modules/client_about/about.otmod | 2 +- modules/client_about/about.otui | 2 +- modules/client_background/background.lua | 1 + modules/client_background/background.otmod | 1 - modules/client_background/background.otui | 1 - modules/client_entergame/characterlist.lua | 1 + modules/client_entergame/characterlist.otui | 2 +- modules/client_entergame/entergame.lua | 2 +- modules/client_entergame/entergame.otmod | 2 - modules/client_main/client.lua | 1 + .../client_modulemanager/modulemanager.lua | 2 +- modules/client_options/options.lua | 1 + modules/client_terminal/terminal.lua | 1 + modules/client_topmenu/topmenu.lua | 2 + modules/core_lib/dispatcher.lua | 2 +- modules/core_lib/math/color.lua | 2 +- modules/core_lib/math/point.lua | 2 +- modules/core_lib/math/rect.lua | 2 +- modules/core_lib/math/size.lua | 2 +- modules/core_styles/styles/items.otui | 2 +- modules/core_styles/styles/panels.otui | 3 +- modules/core_styles/styles/windows.otui | 2 +- modules/core_widgets/core_widgets.otmod | 4 +- modules/core_widgets/uiitem.lua | 7 ++-- modules/core_widgets/uiminiwindow.lua | 30 ++++++++++++++ .../core_widgets/uiminiwindowcontainer.lua | 12 ++++++ modules/core_widgets/uiwindow.lua | 16 +++++++- modules/game_miniwindow/miniwindow.lua | 0 modules/game_miniwindow/miniwindow.otmod | 6 --- modules/game_miniwindow/miniwindow.otui | 0 src/framework/luafunctions.cpp | 13 ++++++ src/framework/luascript/luainterface.cpp | 6 +++ src/framework/luascript/luaobject.cpp | 8 ++++ src/framework/luascript/luaobject.h | 3 ++ src/framework/ui/uimanager.cpp | 16 ++++++++ src/framework/ui/uiwidget.cpp | 41 ++++++++++++------- src/framework/ui/uiwidget.h | 2 + src/otclient/luafunctions.cpp | 4 +- src/otclient/otclient.cpp | 1 + src/otclient/ui/uiitem.cpp | 2 +- 43 files changed, 165 insertions(+), 51 deletions(-) create mode 100644 modules/core_widgets/uiminiwindow.lua create mode 100644 modules/core_widgets/uiminiwindowcontainer.lua delete mode 100644 modules/game_miniwindow/miniwindow.lua delete mode 100644 modules/game_miniwindow/miniwindow.otmod delete mode 100644 modules/game_miniwindow/miniwindow.otui diff --git a/TODO b/TODO index fe93f026..efdad0b1 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,6 @@ High priority TODO in order (before first public disclose) restore map moving multiline text edit -fix auto repeats events remove UIGame move windows, navigate in containers complete miniwindow (close, minimize, resize, move) @@ -11,9 +10,7 @@ create and bind all game functions/events let windows stay open while playing combat controls player status icons (poison, etc) -modules managment interface load modules from zip files -addons folder display exit box when exiting from game scrollbar and scrollable widgets @@ -25,6 +22,7 @@ review directories loading search load modules from zip packages create a class for reading binary files rework lua/c++ logger +replace autoload-antencedence with load-before/load-after == Graphics use CoordsBuffer in font diff --git a/addons/README.txt b/addons/README.txt index 136500ff..01f17ae5 100644 --- a/addons/README.txt +++ b/addons/README.txt @@ -1 +1 @@ -You can plance any personal addons here. +This folder work exactly as modules folder, however is intended to place only addons here. diff --git a/modules/client_about/about.lua b/modules/client_about/about.lua index 41f54714..f53cc384 100644 --- a/modules/client_about/about.lua +++ b/modules/client_about/about.lua @@ -15,6 +15,7 @@ end function About.terminate() aboutButton:destroy() aboutButton = nil + About = nil end function About.openWebpage() diff --git a/modules/client_about/about.otmod b/modules/client_about/about.otmod index 898f15ae..f461baa4 100644 --- a/modules/client_about/about.otmod +++ b/modules/client_about/about.otmod @@ -15,4 +15,4 @@ Module About.init() onUnload: | - About.terminate() \ No newline at end of file + About.terminate() diff --git a/modules/client_about/about.otui b/modules/client_about/about.otui index 3ea64eed..37fcb63b 100644 --- a/modules/client_about/about.otui +++ b/modules/client_about/about.otui @@ -12,7 +12,7 @@ MainWindow text-align: center text: |- OTClient - Version 0.2.0 + Version 0.4.0 Created by edubart anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top diff --git a/modules/client_background/background.lua b/modules/client_background/background.lua index b184d6d4..3b237b84 100644 --- a/modules/client_background/background.lua +++ b/modules/client_background/background.lua @@ -12,6 +12,7 @@ end function Background.terminate() background:destroy() background = nil + Background = nil end function Background.hide() diff --git a/modules/client_background/background.otmod b/modules/client_background/background.otmod index ddf8d386..0a8ecfd9 100644 --- a/modules/client_background/background.otmod +++ b/modules/client_background/background.otmod @@ -12,4 +12,3 @@ Module onUnload: | Background.terminate() - diff --git a/modules/client_background/background.otui b/modules/client_background/background.otui index e9b13332..9eebbb86 100644 --- a/modules/client_background/background.otui +++ b/modules/client_background/background.otui @@ -9,4 +9,3 @@ Panel anchors.bottom: parent.bottom margin-top: 1 focusable: false - diff --git a/modules/client_entergame/characterlist.lua b/modules/client_entergame/characterlist.lua index 52d56332..06ece5e0 100644 --- a/modules/client_entergame/characterlist.lua +++ b/modules/client_entergame/characterlist.lua @@ -63,6 +63,7 @@ function CharacterList.terminate() loadBox:destroy() loadBox = nil end + CharacterList = nil end function CharacterList.create(characters, premDays) diff --git a/modules/client_entergame/characterlist.otui b/modules/client_entergame/characterlist.otui index 144ec202..00f4cf9c 100644 --- a/modules/client_entergame/characterlist.otui +++ b/modules/client_entergame/characterlist.otui @@ -66,4 +66,4 @@ MainWindow width: 64 anchors.right: parent.right anchors.bottom: parent.bottom - @onClick: CharacterList.destroy() \ No newline at end of file + @onClick: CharacterList.destroy() diff --git a/modules/client_entergame/entergame.lua b/modules/client_entergame/entergame.lua index df66c35f..a3fa2020 100644 --- a/modules/client_entergame/entergame.lua +++ b/modules/client_entergame/entergame.lua @@ -97,6 +97,7 @@ function EnterGame.terminate() enterGameButton = nil motdButton:destroy() motdButton = nil + EnterGame = nil end function EnterGame.show() @@ -144,4 +145,3 @@ end function EnterGame.displayMotd() displayInfoBox('Message of the day', motdMessage) end - diff --git a/modules/client_entergame/entergame.otmod b/modules/client_entergame/entergame.otmod index 9da96cde..85a2e8d4 100644 --- a/modules/client_entergame/entergame.otmod +++ b/modules/client_entergame/entergame.otmod @@ -14,5 +14,3 @@ Module onUnload: | EnterGame.terminate() CharacterList.terminate() - - diff --git a/modules/client_main/client.lua b/modules/client_main/client.lua index 60f1450f..5fcc36e5 100644 --- a/modules/client_main/client.lua +++ b/modules/client_main/client.lua @@ -34,4 +34,5 @@ function Client.terminate() Settings.set('window-size', g_window.getUnmaximizedSize()) Settings.set('window-pos', g_window.getUnmaximizedPos()) Settings.set('window-maximized', g_window.isMaximized()) + Client = nil end diff --git a/modules/client_modulemanager/modulemanager.lua b/modules/client_modulemanager/modulemanager.lua index b13e7be1..0abe9544 100644 --- a/modules/client_modulemanager/modulemanager.lua +++ b/modules/client_modulemanager/modulemanager.lua @@ -27,6 +27,7 @@ function ModuleManager.terminate() moduleManagerButton:destroy() moduleManagerButton = nil moduleList = nil + ModuleManager = nil end function ModuleManager.hide() @@ -37,7 +38,6 @@ function ModuleManager.show() moduleManagerWindow:show() moduleManagerWindow:focus() moduleManagerWindow:raise() - end function ModuleManager.toggle() diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index e5c9ef7c..e2225613 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -34,6 +34,7 @@ function Options.terminate() optionsWindow = nil optionsButton:destroy() optionsButton = nil + Options = nil end function Options.toggle() diff --git a/modules/client_terminal/terminal.lua b/modules/client_terminal/terminal.lua index 9b405f88..5118748d 100644 --- a/modules/client_terminal/terminal.lua +++ b/modules/client_terminal/terminal.lua @@ -137,6 +137,7 @@ function Terminal.terminate() terminalWidget:destroy() terminalWidget = nil commandEnv = nil + Terminal = nil end function Terminal.toggle() diff --git a/modules/client_topmenu/topmenu.lua b/modules/client_topmenu/topmenu.lua index 22bd8e0f..bdfd89d2 100644 --- a/modules/client_topmenu/topmenu.lua +++ b/modules/client_topmenu/topmenu.lua @@ -39,6 +39,8 @@ function TopMenu.terminate() disconnect(Game, { onLogin = TopMenu.showGameButtons, onLogout = TopMenu.hideGameButtons }) + + TopMenu = nil end function TopMenu.addButton(id, description, icon, callback, right) diff --git a/modules/core_lib/dispatcher.lua b/modules/core_lib/dispatcher.lua index 8c9f12e5..e1997a63 100644 --- a/modules/core_lib/dispatcher.lua +++ b/modules/core_lib/dispatcher.lua @@ -1,4 +1,4 @@ -function scheduleEvent(func, delay) +function scheduleEvent(callback, delay) local event = g_dispatcher.scheduleEvent(callback, delay) -- must hold a reference to the callback, otherwise it would be collected diff --git a/modules/core_lib/math/color.lua b/modules/core_lib/math/color.lua index de25e286..252a928e 100644 --- a/modules/core_lib/math/color.lua +++ b/modules/core_lib/math/color.lua @@ -1 +1 @@ -Color = {} \ No newline at end of file +Color = {} diff --git a/modules/core_lib/math/point.lua b/modules/core_lib/math/point.lua index 2cc54826..30270699 100644 --- a/modules/core_lib/math/point.lua +++ b/modules/core_lib/math/point.lua @@ -1 +1 @@ -Point = {} \ No newline at end of file +Point = {} diff --git a/modules/core_lib/math/rect.lua b/modules/core_lib/math/rect.lua index 9cd6b13b..ab9ae295 100644 --- a/modules/core_lib/math/rect.lua +++ b/modules/core_lib/math/rect.lua @@ -1 +1 @@ -Rect = {} \ No newline at end of file +Rect = {} diff --git a/modules/core_lib/math/size.lua b/modules/core_lib/math/size.lua index 25598c0a..0a51797b 100644 --- a/modules/core_lib/math/size.lua +++ b/modules/core_lib/math/size.lua @@ -1 +1 @@ -Size = {} \ No newline at end of file +Size = {} diff --git a/modules/core_styles/styles/items.otui b/modules/core_styles/styles/items.otui index 2c99b081..1422a9d3 100644 --- a/modules/core_styles/styles/items.otui +++ b/modules/core_styles/styles/items.otui @@ -2,4 +2,4 @@ Item < UIItem size: 34 34 image-source: /core_styles/images/item.png font: verdana-11px-rounded - border-color: white \ No newline at end of file + border-color: white diff --git a/modules/core_styles/styles/panels.otui b/modules/core_styles/styles/panels.otui index 7631b54b..dad6e0ec 100644 --- a/modules/core_styles/styles/panels.otui +++ b/modules/core_styles/styles/panels.otui @@ -10,8 +10,7 @@ TopPanel < Panel image-source: /core_styles/images/top_panel.png image-repeated: true -InterfacePanel < Panel - focusable: false +InterfacePanel < UIMiniWindowContainer image-source: /core_styles/images/interface_panel.png image-border: 4 diff --git a/modules/core_styles/styles/windows.otui b/modules/core_styles/styles/windows.otui index 9b8aac48..e87190d5 100644 --- a/modules/core_styles/styles/windows.otui +++ b/modules/core_styles/styles/windows.otui @@ -18,7 +18,7 @@ Window < UIWindow MainWindow < Window anchors.centerIn: parent -MiniWindow < UIWindow +MiniWindow < UIMiniWindow font: verdana-11px-antialised //icon: /core_styles/icons/login.png icon-rect: 4 4 16 16 diff --git a/modules/core_widgets/core_widgets.otmod b/modules/core_widgets/core_widgets.otmod index 332cccd8..95836e90 100644 --- a/modules/core_widgets/core_widgets.otmod +++ b/modules/core_widgets/core_widgets.otmod @@ -19,12 +19,12 @@ Module dofile 'uitabbar' dofile 'uipopupmenu' dofile 'uiwindow' + dofile 'uiminiwindow' + dofile 'uiminiwindowcontainer' dofile 'uiitem' dofile 'uimessagebox' dofile 'tooltip' - --dofile 'messagebox/messagebox' - ToolTip.init() onUnload: | diff --git a/modules/core_widgets/uiitem.lua b/modules/core_widgets/uiitem.lua index 403b607c..8c2fe476 100644 --- a/modules/core_widgets/uiitem.lua +++ b/modules/core_widgets/uiitem.lua @@ -12,7 +12,7 @@ function UIItem:onDragEnter(mousePos) return true end -function UIItem:onDragLeave(widget, mousePos) +function UIItem:onDragLeave(droppedWidget, mousePos) if self:isVirtual() then return false end if not self.parsed then @@ -53,8 +53,9 @@ end function UIItem:onHoverChange(hovered) if self:isVirtual() then return end - if g_ui.getDraggingWidget() and self ~= g_ui.getDraggingWidget() then - if hovered then + local dragginWidget = g_ui.getDraggingWidget() + if dragginWidget and self ~= dragginWidget then + if dragginWidget:getClassName() == 'UIItem' and not dragginWidget:isVirtual() and hovered then self:setBorderWidth(1) else self:setBorderWidth(0) diff --git a/modules/core_widgets/uiminiwindow.lua b/modules/core_widgets/uiminiwindow.lua new file mode 100644 index 00000000..2efd620b --- /dev/null +++ b/modules/core_widgets/uiminiwindow.lua @@ -0,0 +1,30 @@ +UIMiniWindow = extends(UIWindow) + +function UIMiniWindow.create() + local miniwindow = UIMiniWindow.internalCreate() + return miniwindow +end + +function UIMiniWindow:onMousePress(mousePos, mouseButton) + local parent = self:getParent() + if parent:getClassName() ~= 'UIMiniWindowContainer' then + self:raise() + end +end + +function UIMiniWindow:onDragEnter(mousePos) + local parent = self:getParent() + if parent:getClassName() == 'UIMiniWindowContainer' then + local containerParent = parent:getParent() + parent:removeChild(self) + containerParent:addChild(self) + end + + local oldPos = self:getPosition() + self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y } + self:setPosition(oldPos) +end + +function UIMiniWindow:onDragLeave(droppedWidget, mousePos) + -- TODO: drop on other interfaces +end diff --git a/modules/core_widgets/uiminiwindowcontainer.lua b/modules/core_widgets/uiminiwindowcontainer.lua new file mode 100644 index 00000000..7f9dbec2 --- /dev/null +++ b/modules/core_widgets/uiminiwindowcontainer.lua @@ -0,0 +1,12 @@ +UIMiniWindowContainer = extends(UIWidget) + +function UIMiniWindowContainer.create() + local container = UIMiniWindowContainer.internalCreate() + container:setFocusable(false) + container:setPhantom(true) + return container +end + +function UIMiniWindowContainer:getClassName() + return 'UIMiniWindowContainer' +end diff --git a/modules/core_widgets/uiwindow.lua b/modules/core_widgets/uiwindow.lua index 5d599d64..fa1fda25 100644 --- a/modules/core_widgets/uiwindow.lua +++ b/modules/core_widgets/uiwindow.lua @@ -3,6 +3,7 @@ UIWindow = extends(UIWidget) function UIWindow.create() local window = UIWindow.internalCreate() window:setTextAlign(AlignTopCenter) + window:setDragable(true) return window end @@ -20,6 +21,17 @@ function UIWindow:onMousePress(mousePos, mouseButton) end -function UIWindow:onGeometryChange(oldRect, newRect) - +function UIWindow:onDragEnter(mousePos) + self:breakAnchors() + self.movingReference = { x = mousePos.x - self:getX(), y = mousePos.y - self:getY() } +end + +function UIWindow:onDragLeave(droppedWidget, mousePos) + -- TODO: auto detect and reconnect anchors +end + +function UIWindow:onDragMove(mousePos, mouseMoved) + local pos = { x = mousePos.x - self.movingReference.x, y = mousePos.y - self.movingReference.y } + self:setPosition(pos) + self:bindRectToParent() end diff --git a/modules/game_miniwindow/miniwindow.lua b/modules/game_miniwindow/miniwindow.lua deleted file mode 100644 index e69de29b..00000000 diff --git a/modules/game_miniwindow/miniwindow.otmod b/modules/game_miniwindow/miniwindow.otmod deleted file mode 100644 index 32ef9fda..00000000 --- a/modules/game_miniwindow/miniwindow.otmod +++ /dev/null @@ -1,6 +0,0 @@ -Module - name: game_miniwindow - description: Manage game miniwindow - author: OTClient team - website: https://github.com/edubart/otclient - onLoad: diff --git a/modules/game_miniwindow/miniwindow.otui b/modules/game_miniwindow/miniwindow.otui deleted file mode 100644 index e69de29b..00000000 diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 4fd8ea4b..fe2b1866 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -103,6 +103,8 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("setChecked", &UIWidget::setChecked); g_lua.bindClassMemberFunction("setFocusable", &UIWidget::setFocusable); g_lua.bindClassMemberFunction("setPhantom", &UIWidget::setPhantom); + g_lua.bindClassMemberFunction("setDragging", &UIWidget::setDragging); + g_lua.bindClassMemberFunction("setDragable", &UIWidget::setDragable); g_lua.bindClassMemberFunction("setFixedSize", &UIWidget::setFixedSize); g_lua.bindClassMemberFunction("setLastFocusReason", &UIWidget::setLastFocusReason); g_lua.bindClassMemberFunction("setAutoRepeatDelay", &UIWidget::setAutoRepeatDelay); @@ -120,6 +122,7 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("getChildByIndex", &UIWidget::getChildByIndex); g_lua.bindClassMemberFunction("recursiveGetChildById", &UIWidget::recursiveGetChildById); g_lua.bindClassMemberFunction("recursiveGetChildByPos", &UIWidget::recursiveGetChildByPos); + g_lua.bindClassMemberFunction("recursiveGetChildrenByPos", &UIWidget::recursiveGetChildrenByPos); g_lua.bindClassMemberFunction("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById); g_lua.bindClassMemberFunction("asUIWidget", &UIWidget::asUIWidget); g_lua.bindClassMemberFunction("resize", &UIWidget::resize); @@ -145,6 +148,8 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("isExplicitlyVisible", &UIWidget::isExplicitlyVisible); g_lua.bindClassMemberFunction("isFocusable", &UIWidget::isFocusable); g_lua.bindClassMemberFunction("isPhantom", &UIWidget::isPhantom); + g_lua.bindClassMemberFunction("isDragable", &UIWidget::isDragable); + g_lua.bindClassMemberFunction("isDragging", &UIWidget::isDragging); g_lua.bindClassMemberFunction("isFixedSize", &UIWidget::isFixedSize); g_lua.bindClassMemberFunction("isDestroyed", &UIWidget::isDestroyed); g_lua.bindClassMemberFunction("hasChildren", &UIWidget::hasChildren); @@ -186,7 +191,15 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("setIconSize", &UIWidget::setIconSize); g_lua.bindClassMemberFunction("setIconRect", &UIWidget::setIconRect); g_lua.bindClassMemberFunction("setBorderWidth", &UIWidget::setBorderWidth); + g_lua.bindClassMemberFunction("setBorderWidthTop", &UIWidget::setBorderWidthTop); + g_lua.bindClassMemberFunction("setBorderWidthRight", &UIWidget::setBorderWidthRight); + g_lua.bindClassMemberFunction("setBorderWidthBottom", &UIWidget::setBorderWidthBottom); + g_lua.bindClassMemberFunction("setBorderWidthLeft", &UIWidget::setBorderWidthLeft); g_lua.bindClassMemberFunction("setBorderColor", &UIWidget::setBorderColor); + g_lua.bindClassMemberFunction("setBorderColorTop", &UIWidget::setBorderColorTop); + g_lua.bindClassMemberFunction("setBorderColorRight", &UIWidget::setBorderColorRight); + g_lua.bindClassMemberFunction("setBorderColorBottom", &UIWidget::setBorderColorBottom); + g_lua.bindClassMemberFunction("setBorderColorLeft", &UIWidget::setBorderColorLeft); g_lua.bindClassMemberFunction("setMargin", &UIWidget::setMargin); g_lua.bindClassMemberFunction("setMarginHorizontal", &UIWidget::setMarginHorizontal); g_lua.bindClassMemberFunction("setMarginVertical", &UIWidget::setMarginVertical); diff --git a/src/framework/luascript/luainterface.cpp b/src/framework/luascript/luainterface.cpp index 86c22f25..e6b32668 100644 --- a/src/framework/luascript/luainterface.cpp +++ b/src/framework/luascript/luainterface.cpp @@ -50,6 +50,12 @@ void LuaInterface::init() registerClass(); bindClassMemberFunction("getUseCount", &LuaObject::getUseCount); bindClassMemberFunction("getClassName", &LuaObject::getClassName); + + registerClassMemberFunction("getFieldsTable", (LuaCppFunction) ([](LuaInterface* lua) { + LuaObjectPtr obj = g_lua.popObject(); + obj->luaGetFieldsTable(); + return 1; + })); } void LuaInterface::terminate() diff --git a/src/framework/luascript/luaobject.cpp b/src/framework/luascript/luaobject.cpp index 3f761528..b1909527 100644 --- a/src/framework/luascript/luaobject.cpp +++ b/src/framework/luascript/luaobject.cpp @@ -65,6 +65,14 @@ void LuaObject::luaGetField(const std::string& key) } } +void LuaObject::luaGetFieldsTable() +{ + if(m_fieldsTableRef != -1) + g_lua.getRef(m_fieldsTableRef); + else + g_lua.pushNil(); +} + int LuaObject::getUseCount() { return shared_from_this().use_count() - 1; diff --git a/src/framework/luascript/luaobject.h b/src/framework/luascript/luaobject.h index a5de7922..87ffedc7 100644 --- a/src/framework/luascript/luaobject.h +++ b/src/framework/luascript/luaobject.h @@ -57,6 +57,9 @@ public: /// Gets a field from this lua object, the result is pushed onto the stack void luaGetField(const std::string& key); + /// Gets the table containing all stored fields of this lua object, the result is pushed onto the stack + void luaGetFieldsTable(); + /// Returns the number of references of this object /// @note each userdata of this object on lua counts as a reference int getUseCount(); diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index de45e7ac..f98df4f6 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -79,6 +79,22 @@ void UIManager::inputEvent(const InputEvent& event) break; case Fw::MouseReleaseInputEvent: m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton); + if(m_draggingWidget && event.mouseButton == Fw::MouseLeftButton) { + auto clickedChildren = m_rootWidget->recursiveGetChildrenByPos(event.mousePos); + UIWidgetPtr droppedWidget; + for(const UIWidgetPtr& child : clickedChildren) { + if(child != m_draggingWidget) { + droppedWidget = child; + break; + } + } + if(droppedWidget) + droppedWidget->onDrop(m_draggingWidget, event.mousePos); + + m_draggingWidget->onDragLeave(droppedWidget, event.mousePos); + m_draggingWidget->setDragging(false); + m_draggingWidget = nullptr; + } break; case Fw::MouseMoveInputEvent: m_mouseReceiver->updateState(Fw::HoverState); diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 63e9ee9b..c0a67de0 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -743,12 +743,6 @@ void UIWidget::setPhantom(bool phantom) void UIWidget::setDragging(bool dragging) { - if(dragging) { - g_ui.setDraggingWidget(asUIWidget()); - } else { - if(g_ui.getDraggingWidget() == asUIWidget()) - g_ui.setDraggingWidget(nullptr); - } m_dragging = dragging; } @@ -898,6 +892,22 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos) return nullptr; } +UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos) +{ + UIWidgetList children; + for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) { + const UIWidgetPtr& child = (*it); + if(child->isExplicitlyVisible() && child->containsPoint(childPos)) { + UIWidgetList subChildren = child->recursiveGetChildrenByPos(childPos); + if(!subChildren.empty()) + children.insert(children.end(), subChildren.begin(), subChildren.end()); + else if(!child->isPhantom()) + children.push_back(child); + } + } + return children; +} + UIWidgetPtr UIWidget::backwardsGetWidgetById(const std::string& id) { UIWidgetPtr widget = getChildById(id); @@ -1141,6 +1151,11 @@ void UIWidget::onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos) callLuaField("onDragLeave", droppedWidget, mousePos); } +bool UIWidget::onDragMove(const Point& mousePos, const Point& mouseMoved) +{ + return callLuaField("onDragMove", mousePos, mouseMoved); +} + void UIWidget::onDrop(UIWidgetPtr draggedWidget, const Point& mousePos) { callLuaField("onDrop", draggedWidget, mousePos); @@ -1184,13 +1199,6 @@ bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button) if(isPressed() && getRect().contains(mousePos)) onClick(mousePos); - UIWidgetPtr draggedWidget = g_ui.getDraggingWidget(); - if(draggedWidget && button == Fw::MouseLeftButton && (containsPoint(mousePos) || asUIWidget() == g_ui.getRootWidget())) { - onDrop(draggedWidget, mousePos); - draggedWidget->onDragLeave(asUIWidget(), mousePos); - draggedWidget->setDragging(false); - } - return callLuaField("onMouseRelease", mousePos, button); } @@ -1202,6 +1210,11 @@ bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved) onDragEnter(mousePos - mouseMoved); } + if(m_dragging) { + if(onDragMove(mousePos, mouseMoved)) + return true; + } + return callLuaField("onMouseMove", mousePos, mouseMoved); } @@ -1354,7 +1367,7 @@ bool UIWidget::propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton bu UIWidgetList children; for(const UIWidgetPtr& child : m_children) { // events on hidden or disabled widgets are discarded - if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible()) + if((!child->isExplicitlyEnabled() || !child->isExplicitlyVisible()) && (!child->isPressed() && button == Fw::MouseLeftButton)) continue; // mouse release events go to all children diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 7685d8c6..1f62082e 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -140,6 +140,7 @@ public: UIWidgetPtr getChildByIndex(int index); UIWidgetPtr recursiveGetChildById(const std::string& id); UIWidgetPtr recursiveGetChildByPos(const Point& childPos); + UIWidgetList recursiveGetChildrenByPos(const Point& childPos); UIWidgetPtr backwardsGetWidgetById(const std::string& id); UIWidgetPtr asUIWidget() { return std::static_pointer_cast(shared_from_this()); } @@ -175,6 +176,7 @@ protected: virtual void onHoverChange(bool hovered); virtual void onDragEnter(const Point& mousePos); virtual void onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos); + virtual bool onDragMove(const Point& mousePos, const Point& mouseMoved); virtual void onDrop(UIWidgetPtr draggedWidget, const Point& mousePos); virtual bool onKeyText(const std::string& keyText); virtual bool onKeyDown(uchar keyCode, int keyboardModifiers); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 41922212..1a0bfa3a 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -229,14 +229,16 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("create", []{ return UIItemPtr(new UIItem); }); g_lua.bindClassMemberFunction("setItemId", &UIItem::setItemId); g_lua.bindClassMemberFunction("setItemCount", &UIItem::setItemCount); + g_lua.bindClassMemberFunction("setItemSubType", &UIItem::setItemSubType); g_lua.bindClassMemberFunction("setItem", &UIItem::setItem); g_lua.bindClassMemberFunction("setVirtual", &UIItem::setVirtual); + g_lua.bindClassMemberFunction("clearItem", &UIItem::clearItem); g_lua.bindClassMemberFunction("getItemId", &UIItem::getItemId); g_lua.bindClassMemberFunction("getItemCount", &UIItem::getItemCount); + g_lua.bindClassMemberFunction("getItemSubType", &UIItem::getItemSubType); g_lua.bindClassMemberFunction("getItem", &UIItem::getItem); g_lua.bindClassMemberFunction("isVirtual", &UIItem::isVirtual); - g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UICreaturePtr(new UICreature); } ); g_lua.bindClassMemberFunction("getCreature", &UICreature::getCreature); diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index 6cbf52c8..a6ff82dd 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -44,6 +44,7 @@ void OTClient::init(const std::vector& args) // client modules 100-499 g_modules.autoLoadModules(499); g_modules.ensureModuleLoaded("client_main"); + g_modules.ensureModuleLoaded("client_tibiafiles"); // game modules 500-999 g_modules.autoLoadModules(999); g_modules.ensureModuleLoaded("game"); diff --git a/src/otclient/ui/uiitem.cpp b/src/otclient/ui/uiitem.cpp index 0810b925..c3aec1fc 100644 --- a/src/otclient/ui/uiitem.cpp +++ b/src/otclient/ui/uiitem.cpp @@ -54,7 +54,7 @@ void UIItem::draw() void UIItem::setItemId(int id) { - if(!m_item) + if(!m_item && id != 0) m_item = Item::create(id); else { // remove item