Browse Source

some window moving

Eduardo Bart 9 years ago
parent
commit
46df3c7dbe
43 changed files with 164 additions and 50 deletions
  1. 1
    3
      TODO
  2. 1
    1
      addons/README.txt
  3. 1
    0
      modules/client_about/about.lua
  4. 1
    1
      modules/client_about/about.otmod
  5. 1
    1
      modules/client_about/about.otui
  6. 1
    0
      modules/client_background/background.lua
  7. 0
    1
      modules/client_background/background.otmod
  8. 0
    1
      modules/client_background/background.otui
  9. 1
    0
      modules/client_entergame/characterlist.lua
  10. 1
    1
      modules/client_entergame/characterlist.otui
  11. 1
    1
      modules/client_entergame/entergame.lua
  12. 0
    2
      modules/client_entergame/entergame.otmod
  13. 1
    0
      modules/client_main/client.lua
  14. 1
    1
      modules/client_modulemanager/modulemanager.lua
  15. 1
    0
      modules/client_options/options.lua
  16. 1
    0
      modules/client_terminal/terminal.lua
  17. 2
    0
      modules/client_topmenu/topmenu.lua
  18. 1
    1
      modules/core_lib/dispatcher.lua
  19. 1
    1
      modules/core_lib/math/color.lua
  20. 1
    1
      modules/core_lib/math/point.lua
  21. 1
    1
      modules/core_lib/math/rect.lua
  22. 1
    1
      modules/core_lib/math/size.lua
  23. 1
    1
      modules/core_styles/styles/items.otui
  24. 1
    2
      modules/core_styles/styles/panels.otui
  25. 1
    1
      modules/core_styles/styles/windows.otui
  26. 2
    2
      modules/core_widgets/core_widgets.otmod
  27. 4
    3
      modules/core_widgets/uiitem.lua
  28. 30
    0
      modules/core_widgets/uiminiwindow.lua
  29. 12
    0
      modules/core_widgets/uiminiwindowcontainer.lua
  30. 13
    1
      modules/core_widgets/uiwindow.lua
  31. 0
    0
      modules/game_miniwindow/miniwindow.lua
  32. 0
    6
      modules/game_miniwindow/miniwindow.otmod
  33. 0
    0
      modules/game_miniwindow/miniwindow.otui
  34. 13
    0
      src/framework/luafunctions.cpp
  35. 6
    0
      src/framework/luascript/luainterface.cpp
  36. 8
    0
      src/framework/luascript/luaobject.cpp
  37. 3
    0
      src/framework/luascript/luaobject.h
  38. 16
    0
      src/framework/ui/uimanager.cpp
  39. 27
    14
      src/framework/ui/uiwidget.cpp
  40. 2
    0
      src/framework/ui/uiwidget.h
  41. 3
    1
      src/otclient/luafunctions.cpp
  42. 1
    0
      src/otclient/otclient.cpp
  43. 1
    1
      src/otclient/ui/uiitem.cpp

+ 1
- 3
TODO View File

@@ -3,7 +3,6 @@ High priority TODO in order (before first public disclose)
3 3
 
4 4
 restore map moving
5 5
 multiline text edit
6
-fix auto repeats events
7 6
 remove UIGame
8 7
 move windows, navigate in containers
9 8
 complete miniwindow (close, minimize, resize, move)
@@ -11,9 +10,7 @@ create and bind all game functions/events
11 10
 let windows stay open while playing
12 11
 combat controls
13 12
 player status icons (poison, etc)
14
-modules managment interface
15 13
 load modules from zip files
16
-addons folder
17 14
 display exit box when exiting from game
18 15
 scrollbar and scrollable widgets
19 16
 
@@ -25,6 +22,7 @@ review directories loading search
25 22
 load modules from zip packages
26 23
 create a class for reading binary files
27 24
 rework lua/c++ logger
25
+replace autoload-antencedence with load-before/load-after
28 26
 
29 27
 == Graphics
30 28
 use CoordsBuffer in font

+ 1
- 1
addons/README.txt View File

@@ -1 +1 @@
1
-You can plance any personal addons here.
1
+This folder work exactly as modules folder, however is intended to place only addons here.

+ 1
- 0
modules/client_about/about.lua View File

@@ -15,6 +15,7 @@ end
15 15
 function About.terminate()
16 16
   aboutButton:destroy()
17 17
   aboutButton = nil
18
+  About = nil
18 19
 end
19 20
 
20 21
 function About.openWebpage()

+ 1
- 1
modules/client_about/about.otmod View File

@@ -15,4 +15,4 @@ Module
15 15
     About.init()
16 16
 
17 17
   onUnload: |
18
-    About.terminate()
18
+    About.terminate()

+ 1
- 1
modules/client_about/about.otui View File

@@ -12,7 +12,7 @@ MainWindow
12 12
       text-align: center
13 13
       text: |-
14 14
         OTClient
15
-        Version 0.2.0
15
+        Version 0.4.0
16 16
         Created by edubart
17 17
       anchors.horizontalCenter: parent.horizontalCenter
18 18
       anchors.top: parent.top

+ 1
- 0
modules/client_background/background.lua View File

@@ -12,6 +12,7 @@ end
12 12
 function Background.terminate()
13 13
   background:destroy()
14 14
   background = nil
15
+  Background = nil
15 16
 end
16 17
 
17 18
 function Background.hide()

+ 0
- 1
modules/client_background/background.otmod View File

@@ -12,4 +12,3 @@ Module
12 12
 
13 13
   onUnload: |
14 14
     Background.terminate()
15
-

+ 0
- 1
modules/client_background/background.otui View File

@@ -9,4 +9,3 @@ Panel
9 9
   anchors.bottom: parent.bottom
10 10
   margin-top: 1
11 11
   focusable: false
12
-

+ 1
- 0
modules/client_entergame/characterlist.lua View File

@@ -63,6 +63,7 @@ function CharacterList.terminate()
63 63
     loadBox:destroy()
64 64
     loadBox = nil
65 65
   end
66
+  CharacterList = nil
66 67
 end
67 68
 
68 69
 function CharacterList.create(characters, premDays)

+ 1
- 1
modules/client_entergame/characterlist.otui View File

@@ -66,4 +66,4 @@ MainWindow
66 66
     width: 64
67 67
     anchors.right: parent.right
68 68
     anchors.bottom: parent.bottom
69
-    @onClick: CharacterList.destroy()
69
+    @onClick: CharacterList.destroy()

+ 1
- 1
modules/client_entergame/entergame.lua View File

@@ -97,6 +97,7 @@ function EnterGame.terminate()
97 97
   enterGameButton = nil
98 98
   motdButton:destroy()
99 99
   motdButton = nil
100
+  EnterGame = nil
100 101
 end
101 102
 
102 103
 function EnterGame.show()
@@ -144,4 +145,3 @@ end
144 145
 function EnterGame.displayMotd()
145 146
   displayInfoBox('Message of the day', motdMessage)
146 147
 end
147
-

+ 0
- 2
modules/client_entergame/entergame.otmod View File

@@ -14,5 +14,3 @@ Module
14 14
   onUnload: |
15 15
     EnterGame.terminate()
16 16
     CharacterList.terminate()
17
-
18
-

+ 1
- 0
modules/client_main/client.lua View File

@@ -34,4 +34,5 @@ function Client.terminate()
34 34
   Settings.set('window-size', g_window.getUnmaximizedSize())
35 35
   Settings.set('window-pos', g_window.getUnmaximizedPos())
36 36
   Settings.set('window-maximized', g_window.isMaximized())
37
+  Client = nil
37 38
 end

+ 1
- 1
modules/client_modulemanager/modulemanager.lua View File

@@ -27,6 +27,7 @@ function ModuleManager.terminate()
27 27
   moduleManagerButton:destroy()
28 28
   moduleManagerButton = nil
29 29
   moduleList = nil
30
+  ModuleManager = nil
30 31
 end
31 32
 
32 33
 function ModuleManager.hide()
@@ -37,7 +38,6 @@ function ModuleManager.show()
37 38
   moduleManagerWindow:show()
38 39
   moduleManagerWindow:focus()
39 40
   moduleManagerWindow:raise()
40
-
41 41
 end
42 42
 
43 43
 function ModuleManager.toggle()

+ 1
- 0
modules/client_options/options.lua View File

@@ -34,6 +34,7 @@ function Options.terminate()
34 34
   optionsWindow = nil
35 35
   optionsButton:destroy()
36 36
   optionsButton = nil
37
+  Options = nil
37 38
 end
38 39
 
39 40
 function Options.toggle()

+ 1
- 0
modules/client_terminal/terminal.lua View File

@@ -137,6 +137,7 @@ function Terminal.terminate()
137 137
   terminalWidget:destroy()
138 138
   terminalWidget = nil
139 139
   commandEnv = nil
140
+  Terminal = nil
140 141
 end
141 142
 
142 143
 function Terminal.toggle()

+ 2
- 0
modules/client_topmenu/topmenu.lua View File

@@ -39,6 +39,8 @@ function TopMenu.terminate()
39 39
 
40 40
   disconnect(Game, { onLogin = TopMenu.showGameButtons,
41 41
                      onLogout = TopMenu.hideGameButtons })
42
+
43
+  TopMenu = nil
42 44
 end
43 45
 
44 46
 function TopMenu.addButton(id, description, icon, callback, right)

+ 1
- 1
modules/core_lib/dispatcher.lua View File

@@ -1,4 +1,4 @@
1
-function scheduleEvent(func, delay)
1
+function scheduleEvent(callback, delay)
2 2
   local event = g_dispatcher.scheduleEvent(callback, delay)
3 3
 
4 4
   -- must hold a reference to the callback, otherwise it would be collected

+ 1
- 1
modules/core_lib/math/color.lua View File

@@ -1 +1 @@
1
-Color = {}
1
+Color = {}

+ 1
- 1
modules/core_lib/math/point.lua View File

@@ -1 +1 @@
1
-Point = {}
1
+Point = {}

+ 1
- 1
modules/core_lib/math/rect.lua View File

@@ -1 +1 @@
1
-Rect = {}
1
+Rect = {}

+ 1
- 1
modules/core_lib/math/size.lua View File

@@ -1 +1 @@
1
-Size = {}
1
+Size = {}

+ 1
- 1
modules/core_styles/styles/items.otui View File

@@ -2,4 +2,4 @@ Item < UIItem
2 2
   size: 34 34
3 3
   image-source: /core_styles/images/item.png
4 4
   font: verdana-11px-rounded
5
-  border-color: white
5
+  border-color: white

+ 1
- 2
modules/core_styles/styles/panels.otui View File

@@ -10,8 +10,7 @@ TopPanel < Panel
10 10
   image-source: /core_styles/images/top_panel.png
11 11
   image-repeated: true
12 12
 
13
-InterfacePanel < Panel
14
-  focusable: false
13
+InterfacePanel < UIMiniWindowContainer
15 14
   image-source: /core_styles/images/interface_panel.png
16 15
   image-border: 4
17 16
 

+ 1
- 1
modules/core_styles/styles/windows.otui View File

@@ -18,7 +18,7 @@ Window < UIWindow
18 18
 MainWindow < Window
19 19
   anchors.centerIn: parent
20 20
 
21
-MiniWindow < UIWindow
21
+MiniWindow < UIMiniWindow
22 22
   font: verdana-11px-antialised
23 23
   //icon: /core_styles/icons/login.png
24 24
   icon-rect: 4 4 16 16

+ 2
- 2
modules/core_widgets/core_widgets.otmod View File

@@ -19,12 +19,12 @@ Module
19 19
     dofile 'uitabbar'
20 20
     dofile 'uipopupmenu'
21 21
     dofile 'uiwindow'
22
+    dofile 'uiminiwindow'
23
+    dofile 'uiminiwindowcontainer'
22 24
     dofile 'uiitem'
23 25
     dofile 'uimessagebox'
24 26
 
25 27
     dofile 'tooltip'
26
-    --dofile 'messagebox/messagebox'
27
-
28 28
     ToolTip.init()
29 29
 
30 30
   onUnload: |

+ 4
- 3
modules/core_widgets/uiitem.lua View File

@@ -12,7 +12,7 @@ function UIItem:onDragEnter(mousePos)
12 12
   return true
13 13
 end
14 14
 
15
-function UIItem:onDragLeave(widget, mousePos)
15
+function UIItem:onDragLeave(droppedWidget, mousePos)
16 16
   if self:isVirtual() then return false end
17 17
 
18 18
   if not self.parsed then
@@ -53,8 +53,9 @@ end
53 53
 function UIItem:onHoverChange(hovered)
54 54
   if self:isVirtual() then return end
55 55
 
56
-  if g_ui.getDraggingWidget() and self ~= g_ui.getDraggingWidget() then
57
-    if hovered then
56
+  local dragginWidget = g_ui.getDraggingWidget()
57
+  if dragginWidget and self ~= dragginWidget then
58
+    if dragginWidget:getClassName() == 'UIItem' and not dragginWidget:isVirtual() and hovered then
58 59
       self:setBorderWidth(1)
59 60
     else
60 61
       self:setBorderWidth(0)

+ 30
- 0
modules/core_widgets/uiminiwindow.lua View File

@@ -0,0 +1,30 @@
1
+UIMiniWindow = extends(UIWindow)
2
+
3
+function UIMiniWindow.create()
4
+  local miniwindow = UIMiniWindow.internalCreate()
5
+  return miniwindow
6
+end
7
+
8
+function UIMiniWindow:onMousePress(mousePos, mouseButton)
9
+  local parent = self:getParent()
10
+  if parent:getClassName() ~= 'UIMiniWindowContainer' then
11
+    self:raise()
12
+  end
13
+end
14
+
15
+function UIMiniWindow:onDragEnter(mousePos)
16
+  local parent = self:getParent()
17
+  if parent:getClassName() == 'UIMiniWindowContainer' then
18
+    local containerParent = parent:getParent()
19
+    parent:removeChild(self)
20
+    containerParent:addChild(self)
21
+  end
22
+
23
+  local oldPos = self:getPosition()
24
+  self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y }
25
+  self:setPosition(oldPos)
26
+end
27
+
28
+function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
29
+  -- TODO: drop on other interfaces
30
+end

+ 12
- 0
modules/core_widgets/uiminiwindowcontainer.lua View File

@@ -0,0 +1,12 @@
1
+UIMiniWindowContainer = extends(UIWidget)
2
+
3
+function UIMiniWindowContainer.create()
4
+  local container = UIMiniWindowContainer.internalCreate()
5
+  container:setFocusable(false)
6
+  container:setPhantom(true)
7
+  return container
8
+end
9
+
10
+function UIMiniWindowContainer:getClassName()
11
+  return 'UIMiniWindowContainer'
12
+end

+ 13
- 1
modules/core_widgets/uiwindow.lua View File

@@ -3,6 +3,7 @@ UIWindow = extends(UIWidget)
3 3
 function UIWindow.create()
4 4
   local window = UIWindow.internalCreate()
5 5
   window:setTextAlign(AlignTopCenter)
6
+  window:setDragable(true)
6 7
   return window
7 8
 end
8 9
 
@@ -20,6 +21,17 @@ function UIWindow:onMousePress(mousePos, mouseButton)
20 21
 
21 22
 end
22 23
 
23
-function UIWindow:onGeometryChange(oldRect, newRect)
24
+function UIWindow:onDragEnter(mousePos)
25
+  self:breakAnchors()
26
+  self.movingReference = { x = mousePos.x - self:getX(), y = mousePos.y - self:getY() }
27
+end
28
+
29
+function UIWindow:onDragLeave(droppedWidget, mousePos)
30
+  -- TODO: auto detect and reconnect anchors
31
+end
24 32
 
33
+function UIWindow:onDragMove(mousePos, mouseMoved)
34
+  local pos = { x = mousePos.x - self.movingReference.x, y = mousePos.y - self.movingReference.y }
35
+  self:setPosition(pos)
36
+  self:bindRectToParent()
25 37
 end

+ 0
- 0
modules/game_miniwindow/miniwindow.lua View File


+ 0
- 6
modules/game_miniwindow/miniwindow.otmod View File

@@ -1,6 +0,0 @@
1
-Module
2
-  name: game_miniwindow
3
-  description: Manage game miniwindow
4
-  author: OTClient team
5
-  website: https://github.com/edubart/otclient
6
-  onLoad:

+ 0
- 0
modules/game_miniwindow/miniwindow.otui View File


+ 13
- 0
src/framework/luafunctions.cpp View File

@@ -103,6 +103,8 @@ void Application::registerLuaFunctions()
103 103
     g_lua.bindClassMemberFunction<UIWidget>("setChecked", &UIWidget::setChecked);
104 104
     g_lua.bindClassMemberFunction<UIWidget>("setFocusable", &UIWidget::setFocusable);
105 105
     g_lua.bindClassMemberFunction<UIWidget>("setPhantom", &UIWidget::setPhantom);
106
+    g_lua.bindClassMemberFunction<UIWidget>("setDragging", &UIWidget::setDragging);
107
+    g_lua.bindClassMemberFunction<UIWidget>("setDragable", &UIWidget::setDragable);
106 108
     g_lua.bindClassMemberFunction<UIWidget>("setFixedSize", &UIWidget::setFixedSize);
107 109
     g_lua.bindClassMemberFunction<UIWidget>("setLastFocusReason", &UIWidget::setLastFocusReason);
108 110
     g_lua.bindClassMemberFunction<UIWidget>("setAutoRepeatDelay", &UIWidget::setAutoRepeatDelay);
@@ -120,6 +122,7 @@ void Application::registerLuaFunctions()
120 122
     g_lua.bindClassMemberFunction<UIWidget>("getChildByIndex", &UIWidget::getChildByIndex);
121 123
     g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildById", &UIWidget::recursiveGetChildById);
122 124
     g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildByPos", &UIWidget::recursiveGetChildByPos);
125
+    g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildrenByPos", &UIWidget::recursiveGetChildrenByPos);
123 126
     g_lua.bindClassMemberFunction<UIWidget>("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById);
124 127
     g_lua.bindClassMemberFunction<UIWidget>("asUIWidget", &UIWidget::asUIWidget);
125 128
     g_lua.bindClassMemberFunction<UIWidget>("resize", &UIWidget::resize);
@@ -145,6 +148,8 @@ void Application::registerLuaFunctions()
145 148
     g_lua.bindClassMemberFunction<UIWidget>("isExplicitlyVisible", &UIWidget::isExplicitlyVisible);
146 149
     g_lua.bindClassMemberFunction<UIWidget>("isFocusable", &UIWidget::isFocusable);
147 150
     g_lua.bindClassMemberFunction<UIWidget>("isPhantom", &UIWidget::isPhantom);
151
+    g_lua.bindClassMemberFunction<UIWidget>("isDragable", &UIWidget::isDragable);
152
+    g_lua.bindClassMemberFunction<UIWidget>("isDragging", &UIWidget::isDragging);
148 153
     g_lua.bindClassMemberFunction<UIWidget>("isFixedSize", &UIWidget::isFixedSize);
149 154
     g_lua.bindClassMemberFunction<UIWidget>("isDestroyed", &UIWidget::isDestroyed);
150 155
     g_lua.bindClassMemberFunction<UIWidget>("hasChildren", &UIWidget::hasChildren);
@@ -186,7 +191,15 @@ void Application::registerLuaFunctions()
186 191
     g_lua.bindClassMemberFunction<UIWidget>("setIconSize", &UIWidget::setIconSize);
187 192
     g_lua.bindClassMemberFunction<UIWidget>("setIconRect", &UIWidget::setIconRect);
188 193
     g_lua.bindClassMemberFunction<UIWidget>("setBorderWidth", &UIWidget::setBorderWidth);
194
+    g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthTop", &UIWidget::setBorderWidthTop);
195
+    g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthRight", &UIWidget::setBorderWidthRight);
196
+    g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthBottom", &UIWidget::setBorderWidthBottom);
197
+    g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthLeft", &UIWidget::setBorderWidthLeft);
189 198
     g_lua.bindClassMemberFunction<UIWidget>("setBorderColor", &UIWidget::setBorderColor);
199
+    g_lua.bindClassMemberFunction<UIWidget>("setBorderColorTop", &UIWidget::setBorderColorTop);
200
+    g_lua.bindClassMemberFunction<UIWidget>("setBorderColorRight", &UIWidget::setBorderColorRight);
201
+    g_lua.bindClassMemberFunction<UIWidget>("setBorderColorBottom", &UIWidget::setBorderColorBottom);
202
+    g_lua.bindClassMemberFunction<UIWidget>("setBorderColorLeft", &UIWidget::setBorderColorLeft);
190 203
     g_lua.bindClassMemberFunction<UIWidget>("setMargin", &UIWidget::setMargin);
191 204
     g_lua.bindClassMemberFunction<UIWidget>("setMarginHorizontal", &UIWidget::setMarginHorizontal);
192 205
     g_lua.bindClassMemberFunction<UIWidget>("setMarginVertical", &UIWidget::setMarginVertical);

+ 6
- 0
src/framework/luascript/luainterface.cpp View File

@@ -50,6 +50,12 @@ void LuaInterface::init()
50 50
     registerClass<LuaObject>();
51 51
     bindClassMemberFunction<LuaObject>("getUseCount", &LuaObject::getUseCount);
52 52
     bindClassMemberFunction<LuaObject>("getClassName", &LuaObject::getClassName);
53
+
54
+    registerClassMemberFunction<LuaObject>("getFieldsTable", (LuaCppFunction) ([](LuaInterface* lua) {
55
+        LuaObjectPtr obj = g_lua.popObject();
56
+        obj->luaGetFieldsTable();
57
+        return 1;
58
+    }));
53 59
 }
54 60
 
55 61
 void LuaInterface::terminate()

+ 8
- 0
src/framework/luascript/luaobject.cpp View File

@@ -65,6 +65,14 @@ void LuaObject::luaGetField(const std::string& key)
65 65
     }
66 66
 }
67 67
 
68
+void LuaObject::luaGetFieldsTable()
69
+{
70
+    if(m_fieldsTableRef != -1)
71
+        g_lua.getRef(m_fieldsTableRef);
72
+    else
73
+        g_lua.pushNil();
74
+}
75
+
68 76
 int LuaObject::getUseCount()
69 77
 {
70 78
     return shared_from_this().use_count() - 1;

+ 3
- 0
src/framework/luascript/luaobject.h View File

@@ -57,6 +57,9 @@ public:
57 57
     /// Gets a field from this lua object, the result is pushed onto the stack
58 58
     void luaGetField(const std::string& key);
59 59
 
60
+    /// Gets the table containing all stored fields of this lua object, the result is pushed onto the stack
61
+    void luaGetFieldsTable();
62
+
60 63
     /// Returns the number of references of this object
61 64
     /// @note each userdata of this object on lua counts as a reference
62 65
     int getUseCount();

+ 16
- 0
src/framework/ui/uimanager.cpp View File

@@ -79,6 +79,22 @@ void UIManager::inputEvent(const InputEvent& event)
79 79
             break;
80 80
         case Fw::MouseReleaseInputEvent:
81 81
             m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
82
+            if(m_draggingWidget && event.mouseButton == Fw::MouseLeftButton) {
83
+                auto clickedChildren = m_rootWidget->recursiveGetChildrenByPos(event.mousePos);
84
+                UIWidgetPtr droppedWidget;
85
+                for(const UIWidgetPtr& child : clickedChildren) {
86
+                    if(child != m_draggingWidget) {
87
+                        droppedWidget = child;
88
+                        break;
89
+                    }
90
+                }
91
+                if(droppedWidget)
92
+                    droppedWidget->onDrop(m_draggingWidget, event.mousePos);
93
+
94
+                m_draggingWidget->onDragLeave(droppedWidget, event.mousePos);
95
+                m_draggingWidget->setDragging(false);
96
+                m_draggingWidget = nullptr;
97
+            }
82 98
             break;
83 99
         case Fw::MouseMoveInputEvent:
84 100
             m_mouseReceiver->updateState(Fw::HoverState);

+ 27
- 14
src/framework/ui/uiwidget.cpp View File

@@ -743,12 +743,6 @@ void UIWidget::setPhantom(bool phantom)
743 743
 
744 744
 void UIWidget::setDragging(bool dragging)
745 745
 {
746
-    if(dragging) {
747
-        g_ui.setDraggingWidget(asUIWidget());
748
-    } else {
749
-        if(g_ui.getDraggingWidget() == asUIWidget())
750
-            g_ui.setDraggingWidget(nullptr);
751
-    }
752 746
     m_dragging = dragging;
753 747
 }
754 748
 
@@ -898,6 +892,22 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
898 892
     return nullptr;
899 893
 }
900 894
 
895
+UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
896
+{
897
+    UIWidgetList children;
898
+    for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
899
+        const UIWidgetPtr& child = (*it);
900
+        if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
901
+            UIWidgetList subChildren = child->recursiveGetChildrenByPos(childPos);
902
+            if(!subChildren.empty())
903
+                children.insert(children.end(), subChildren.begin(), subChildren.end());
904
+            else if(!child->isPhantom())
905
+                children.push_back(child);
906
+        }
907
+    }
908
+    return children;
909
+}
910
+
901 911
 UIWidgetPtr UIWidget::backwardsGetWidgetById(const std::string& id)
902 912
 {
903 913
     UIWidgetPtr widget = getChildById(id);
@@ -1141,6 +1151,11 @@ void UIWidget::onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos)
1141 1151
     callLuaField("onDragLeave", droppedWidget, mousePos);
1142 1152
 }
1143 1153
 
1154
+bool UIWidget::onDragMove(const Point& mousePos, const Point& mouseMoved)
1155
+{
1156
+    return callLuaField("onDragMove", mousePos, mouseMoved);
1157
+}
1158
+
1144 1159
 void UIWidget::onDrop(UIWidgetPtr draggedWidget, const Point& mousePos)
1145 1160
 {
1146 1161
     callLuaField("onDrop", draggedWidget, mousePos);
@@ -1184,13 +1199,6 @@ bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
1184 1199
     if(isPressed() && getRect().contains(mousePos))
1185 1200
         onClick(mousePos);
1186 1201
 
1187
-    UIWidgetPtr draggedWidget = g_ui.getDraggingWidget();
1188
-    if(draggedWidget && button == Fw::MouseLeftButton && (containsPoint(mousePos) || asUIWidget() == g_ui.getRootWidget())) {
1189
-        onDrop(draggedWidget, mousePos);
1190
-        draggedWidget->onDragLeave(asUIWidget(), mousePos);
1191
-        draggedWidget->setDragging(false);
1192
-    }
1193
-
1194 1202
     return callLuaField<bool>("onMouseRelease", mousePos, button);
1195 1203
 }
1196 1204
 
@@ -1202,6 +1210,11 @@ bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
1202 1210
         onDragEnter(mousePos - mouseMoved);
1203 1211
     }
1204 1212
 
1213
+    if(m_dragging) {
1214
+        if(onDragMove(mousePos, mouseMoved))
1215
+            return true;
1216
+    }
1217
+
1205 1218
     return callLuaField<bool>("onMouseMove", mousePos, mouseMoved);
1206 1219
 }
1207 1220
 
@@ -1354,7 +1367,7 @@ bool UIWidget::propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton bu
1354 1367
     UIWidgetList children;
1355 1368
     for(const UIWidgetPtr& child : m_children) {
1356 1369
         // events on hidden or disabled widgets are discarded
1357
-        if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible())
1370
+        if((!child->isExplicitlyEnabled() || !child->isExplicitlyVisible()) && (!child->isPressed() && button == Fw::MouseLeftButton))
1358 1371
             continue;
1359 1372
 
1360 1373
         // mouse release events go to all children

+ 2
- 0
src/framework/ui/uiwidget.h View File

@@ -140,6 +140,7 @@ public:
140 140
     UIWidgetPtr getChildByIndex(int index);
141 141
     UIWidgetPtr recursiveGetChildById(const std::string& id);
142 142
     UIWidgetPtr recursiveGetChildByPos(const Point& childPos);
143
+    UIWidgetList recursiveGetChildrenByPos(const Point& childPos);
143 144
     UIWidgetPtr backwardsGetWidgetById(const std::string& id);
144 145
 
145 146
     UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
@@ -175,6 +176,7 @@ protected:
175 176
     virtual void onHoverChange(bool hovered);
176 177
     virtual void onDragEnter(const Point& mousePos);
177 178
     virtual void onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
179
+    virtual bool onDragMove(const Point& mousePos, const Point& mouseMoved);
178 180
     virtual void onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
179 181
     virtual bool onKeyText(const std::string& keyText);
180 182
     virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);

+ 3
- 1
src/otclient/luafunctions.cpp View File

@@ -229,14 +229,16 @@ void OTClient::registerLuaFunctions()
229 229
     g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); });
230 230
     g_lua.bindClassMemberFunction<UIItem>("setItemId", &UIItem::setItemId);
231 231
     g_lua.bindClassMemberFunction<UIItem>("setItemCount", &UIItem::setItemCount);
232
+    g_lua.bindClassMemberFunction<UIItem>("setItemSubType", &UIItem::setItemSubType);
232 233
     g_lua.bindClassMemberFunction<UIItem>("setItem", &UIItem::setItem);
233 234
     g_lua.bindClassMemberFunction<UIItem>("setVirtual", &UIItem::setVirtual);
235
+    g_lua.bindClassMemberFunction<UIItem>("clearItem", &UIItem::clearItem);
234 236
     g_lua.bindClassMemberFunction<UIItem>("getItemId", &UIItem::getItemId);
235 237
     g_lua.bindClassMemberFunction<UIItem>("getItemCount", &UIItem::getItemCount);
238
+    g_lua.bindClassMemberFunction<UIItem>("getItemSubType", &UIItem::getItemSubType);
236 239
     g_lua.bindClassMemberFunction<UIItem>("getItem", &UIItem::getItem);
237 240
     g_lua.bindClassMemberFunction<UIItem>("isVirtual", &UIItem::isVirtual);
238 241
 
239
-
240 242
     g_lua.registerClass<UICreature, UIWidget>();
241 243
     g_lua.bindClassStaticFunction<UICreature>("create", []{ return UICreaturePtr(new UICreature); } );
242 244
     g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);

+ 1
- 0
src/otclient/otclient.cpp View File

@@ -44,6 +44,7 @@ void OTClient::init(const std::vector<std::string>& args)
44 44
     // client modules 100-499
45 45
     g_modules.autoLoadModules(499);
46 46
     g_modules.ensureModuleLoaded("client_main");
47
+    g_modules.ensureModuleLoaded("client_tibiafiles");
47 48
     // game modules 500-999
48 49
     g_modules.autoLoadModules(999);
49 50
     g_modules.ensureModuleLoaded("game");

+ 1
- 1
src/otclient/ui/uiitem.cpp View File

@@ -54,7 +54,7 @@ void UIItem::draw()
54 54
 
55 55
 void UIItem::setItemId(int id)
56 56
 {
57
-    if(!m_item)
57
+    if(!m_item && id != 0)
58 58
         m_item = Item::create(id);
59 59
     else {
60 60
         // remove item

Loading…
Cancel
Save