diff --git a/modules/corelib/ui/uiminiwindowcontainer.lua b/modules/corelib/ui/uiminiwindowcontainer.lua index a95841588..7c3774902 100644 --- a/modules/corelib/ui/uiminiwindowcontainer.lua +++ b/modules/corelib/ui/uiminiwindowcontainer.lua @@ -9,6 +9,20 @@ function UIMiniWindowContainer.create() return container end +function UIMiniWindowContainer:getEmptySpaceHeight() + local sumHeight = 0 + local children = self:getChildren() + + for i=1,#children do + if children[i]:isVisible() then + sumHeight = sumHeight + children[i]:getHeight() + end + end + local selfHeight = self:getHeight() - (self:getPaddingTop() + self:getPaddingBottom()) + + return selfHeight - sumHeight +end + -- TODO: connect to window onResize event -- TODO: try to resize another widget? -- TODO: try to find another panel? @@ -78,12 +92,16 @@ function UIMiniWindowContainer:fitAll(noRemoveChild) -- close widgets for i=1,#removeChildren do - removeChildren[i]:close() + signalcall(removeChildren[i].onRemoveFromContainer, removeChildren[i]) + + if removeChildren[i]:getParent():getId() == self:getId() then + removeChildren[i]:close() + end end end function UIMiniWindowContainer:onDrop(widget, mousePos) - if widget:getClassName() == 'UIMiniWindow' then + if widget.UIMiniWindowContainer then local oldParent = widget:getParent() if oldParent == self then return true diff --git a/modules/game_containers/containers.lua b/modules/game_containers/containers.lua index 9265942db..580b00581 100644 --- a/modules/game_containers/containers.lua +++ b/modules/game_containers/containers.lua @@ -85,7 +85,7 @@ function onContainerOpen(container, previousContainer) previousContainer.window = nil previousContainer.itemsPanel = nil else - containerWindow = g_ui.createWidget('ContainerWindow', modules.game_interface.getRightPanel()) + containerWindow = g_ui.createWidget('ContainerWindow') end containerWindow:setId('container' .. container:getId()) local containerPanel = containerWindow:getChildById('contentsPanel') @@ -140,6 +140,10 @@ function onContainerOpen(container, previousContainer) containerWindow:setContentHeight(filledLines*cellSize.height) end + if not previousContainer then + modules.game_interface.addToPanels(containerWindow) + end + containerWindow:setup() end diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index fa9d47995..e2aca2fb4 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -362,6 +362,33 @@ function updateStretchShrink() end end +function addToPanels(uiWidget) + uiWidget.onRemoveFromContainer = function(widget) + if gameLeftPanel:isOn() then + if widget:getParent():getId() == 'gameRightPanel' then + if gameLeftPanel:getEmptySpaceHeight() - widget:getHeight() >= 0 then + widget:setParent(gameLeftPanel) + end + elseif widget:getParent():getId() == 'gameLeftPanel' then + if gameRightPanel:getEmptySpaceHeight() - widget:getHeight() >= 0 then + widget:setParent(gameRightPanel) + end + end + end + end + + if not gameLeftPanel:isOn() then + uiWidget:setParent(gameRightPanel) + return + end + + if gameRightPanel:getEmptySpaceHeight() - uiWidget:getHeight() >= 0 then + uiWidget:setParent(gameRightPanel) + else + uiWidget:setParent(gameLeftPanel) + end +end + function onMouseGrabberRelease(self, mousePosition, mouseButton) if selectedThing == nil then return false end if mouseButton == MouseLeftButton then