diff --git a/TODO b/TODO index bb08df7c..ba418744 100644 --- a/TODO +++ b/TODO @@ -76,3 +76,4 @@ terminate rework of ui events propagation (for Key events) * lua engine make possible to bind non LuaObject derived classes on lua engine (for usage with Point,Rect,Color,Size) review usage of x,y/width,height in lua instead of point/size +calling UIWidget.getMarginTop(nil) makes client crashes diff --git a/modules/game/styles/miniwindow.otui b/modules/game/styles/miniwindow.otui index 07a990f9..f8aa79dd 100644 --- a/modules/game/styles/miniwindow.otui +++ b/modules/game/styles/miniwindow.otui @@ -66,7 +66,7 @@ MiniWindow < UIMiniWindow margin-bottom: 3 pixels-scroll: true - $disabled: + $!on: width: 0 ResizeBorder diff --git a/modules/game/widgets/uiminiwindow.lua b/modules/game/widgets/uiminiwindow.lua index fc71607b..b26a9838 100644 --- a/modules/game/widgets/uiminiwindow.lua +++ b/modules/game/widgets/uiminiwindow.lua @@ -27,6 +27,48 @@ function UIMiniWindow:onDragEnter(mousePos) return true end +function UIMiniWindow:onDragMove(mousePos, mouseMoved) + local oldMousePosY = mousePos.y - mouseMoved.y + local children = rootWidget:recursiveGetChildrenByPos(mousePos) + local overAnyWidget = false + for i=1,#children do + local child = children[i] + if child:getParent():getClassName() == 'UIMiniWindowContainer' then + overAnyWidget = true + + local childCenterY = child:getY() + child:getHeight() / 2 + if child == self.movedWidget and mousePos.y < childCenterY and oldMousePosY < childCenterY then + break + end + + if self.movedWidget then + self.widgetSetMargin(self.movedWidget, self.widgetGetMargin(self.movedWidget) - 10) + end + + if mousePos.y < childCenterY then + self.widgetSetMargin = child.setMarginTop + self.widgetGetMargin = child.getMarginTop + self.movedIndex = 0 + else + self.widgetSetMargin = child.setMarginBottom + self.widgetGetMargin = child.getMarginBottom + self.movedIndex = 1 + end + + self.widgetSetMargin(child, self.widgetGetMargin(child) + 10) + self.movedWidget = child + break + end + end + + if not overAnyWidget and self.movedWidget then + self.widgetSetMargin(self.movedWidget, self.widgetGetMargin(self.movedWidget) - 10) + self.movedWidget = nil + end + + return UIWindow.onDragMove(self, mousePos, mouseMoved) +end + function UIMiniWindow:onMousePress() local parent = self:getParent() if not parent then return false end @@ -37,7 +79,13 @@ function UIMiniWindow:onMousePress() end function UIMiniWindow:onDragLeave(droppedWidget, mousePos) - -- TODO: drop on other interfaces + if self.movedWidget then + self.widgetSetMargin(self.movedWidget, self.widgetGetMargin(self.movedWidget) - 10) + self.movedWidget = nil + self.widgetSetMargin = nil + self.widgetGetMargin = nil + self.movedIndex = nil + end end function UIMiniWindow:onFocusChange(focused) diff --git a/modules/game/widgets/uiminiwindowcontainer.lua b/modules/game/widgets/uiminiwindowcontainer.lua index 4e82f24d..a68b61ff 100644 --- a/modules/game/widgets/uiminiwindowcontainer.lua +++ b/modules/game/widgets/uiminiwindowcontainer.lua @@ -9,7 +9,20 @@ end function UIMiniWindowContainer:onDrop(widget, mousePos) if widget:getClassName() == 'UIMiniWindow' then - widget:setParent(self) + local oldParent = widget:getParent() + if oldParent == self then + return true + end + + oldParent:removeChild(widget) + + if widget.movedWidget then + local index = self:getChildIndex(widget.movedWidget) + self:insertChild(index + widget.movedIndex, widget) + else + self:addChild(widget) + end + return true end end