Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions modules/corelib/ui/uiminiwindowcontainer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion modules/game_containers/containers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions modules/game_interface/gameinterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down