diff --git a/modules/client_skins/skins/default/styles/miniwindow.otui b/modules/client_skins/skins/default/styles/miniwindow.otui index 56d1ea8c..9822526f 100644 --- a/modules/client_skins/skins/default/styles/miniwindow.otui +++ b/modules/client_skins/skins/default/styles/miniwindow.otui @@ -75,7 +75,7 @@ MiniWindow < UIMiniWindow anchors.left: parent.left anchors.right: parent.right height: 3 - minimum: 64 + minimum: 48 background: #ffffff88 MiniWindowContents < ScrollablePanel diff --git a/modules/corelib/ui/uiminiwindow.lua b/modules/corelib/ui/uiminiwindow.lua index 98e4d3fa..d64c1b05 100644 --- a/modules/corelib/ui/uiminiwindow.lua +++ b/modules/corelib/ui/uiminiwindow.lua @@ -3,6 +3,7 @@ UIMiniWindow = extends(UIWindow) function UIMiniWindow.create() local miniwindow = UIMiniWindow.internalCreate() + miniwindow.isSetup = false return miniwindow end @@ -103,7 +104,13 @@ function UIMiniWindow:onSetup() if selfSettings.closed then self:close(true) end + + if selfSettings.height then + self:setHeight(selfSettings.height) + end end + + self.isSetup = true end local newParent = self:getParent() @@ -118,6 +125,19 @@ function UIMiniWindow:onSetup() newParent:order() end end + + if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and self:isVisible() then + -- not on input event, must rework + --newParent:fitAll(self) + end +end + +function UIMiniWindow:onVisibilityChange(visible) + local parent = self:getParent() + if visible and parent and parent:getClassName() == 'UIMiniWindowContainer' then + -- not on input event, must rework + --parent:fitAll(self) + end end function UIMiniWindow:onDragEnter(mousePos) @@ -215,6 +235,18 @@ function UIMiniWindow:onFocusChange(focused) end end +function UIMiniWindow:onGeometryChange(oldRect, rect) + if self.isSetup then + self:setSettings({height = rect.height}) + end + + local parent = self:getParent() + if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then + -- not on input event, must rework + --parent:fitAll(self) + end +end + function UIMiniWindow:setSettings(data) if not self.save then return end @@ -254,12 +286,18 @@ function UIMiniWindow:disableResize() self:getChildById('bottomResizeBorder'):disable() end -function UIMiniWindow:setMinimumHeight(height) +function UIMiniWindow:setContentMinimumHeight(height) + local contentsPanel = self:getChildById('contentsPanel') + local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom() + local resizeBorder = self:getChildById('bottomResizeBorder') - resizeBorder:setMinimum(height) + resizeBorder:setMinimum(minHeight + height) end -function UIMiniWindow:setMaximumHeight(height) +function UIMiniWindow:setContentMaximumHeight(height) + local contentsPanel = self:getChildById('contentsPanel') + local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom() + local resizeBorder = self:getChildById('bottomResizeBorder') - resizeBorder:setMaximum(height) + resizeBorder:setMaximum(minHeight + height) end diff --git a/modules/corelib/ui/uiminiwindowcontainer.lua b/modules/corelib/ui/uiminiwindowcontainer.lua index 033a2f4a..e5e5b1b2 100644 --- a/modules/corelib/ui/uiminiwindowcontainer.lua +++ b/modules/corelib/ui/uiminiwindowcontainer.lua @@ -13,6 +13,63 @@ function UIMiniWindowContainer:getClassName() return 'UIMiniWindowContainer' end +function UIMiniWindowContainer:fitAll(noRemoveChild) + if not self:isVisible() then + return + end + + local sumHeight = 0 + local children = self:getChildren() + for i=1,#children do + sumHeight = sumHeight + children[i]:getHeight() + end + + local selfHeight = self:getHeight() + if sumHeight <= selfHeight then + return + end + + local removeChildren = {} + + -- try to remove no-save widget + for i=#children,1,-1 do + if sumHeight < selfHeight then + break + end + + local child = children[i] + if child ~= noRemoveChild and not child.save then + local childHeight = child:getHeight() + sumHeight = sumHeight - childHeight + table.insert(removeChildren, child) + end + end + + -- try to remove save widget + for i=#children,1,-1 do + if sumHeight < selfHeight then + break + end + + local child = children[i] + if child ~= noRemoveChild then + local childHeight = child:getHeight() + sumHeight = sumHeight - childHeight + table.insert(removeChildren, child) + end + end + + -- close widgets + for i=1,#removeChildren do + removeChildren[i]:close() + end + + -- dont let noRemoveChild be bigger than self + if noRemoveChild:getHeight() > selfHeight - 20 then + noRemoveChild:setHeight(selfHeight - 20) + end +end + function UIMiniWindowContainer:onDrop(widget, mousePos) if widget:getClassName() == 'UIMiniWindow' then local oldParent = widget:getParent() diff --git a/modules/corelib/ui/uiresizeborder.lua b/modules/corelib/ui/uiresizeborder.lua index bc68744f..0da82a99 100644 --- a/modules/corelib/ui/uiresizeborder.lua +++ b/modules/corelib/ui/uiresizeborder.lua @@ -92,6 +92,11 @@ function UIResizeBorder:setMaximum(maximum) if self.maximum == self.minimum then self:hide() end + + local parent = self:getParent() + if self:isVisible() and parent:getHeight() > maximum then + parent:setHeight(maximum) + end end function UIResizeBorder:setMinimum(minimum) @@ -99,6 +104,11 @@ function UIResizeBorder:setMinimum(minimum) if self.maximum == self.minimum then self:hide() end + + local parent = self:getParent() + if self:isVisible() and parent:getHeight() < minimum then + parent:setHeight(minimum) + end end function UIResizeBorder:getMaximum() return self.maximum end diff --git a/modules/game_battle/battle.lua b/modules/game_battle/battle.lua index e15546eb..5d1b2e6f 100644 --- a/modules/game_battle/battle.lua +++ b/modules/game_battle/battle.lua @@ -33,6 +33,10 @@ function init() battleButton:setOn(true) g_keyboard.bindKeyDown('Ctrl+B', toggle) + -- this disables scrollbar auto hiding + local scrollbar = battleWindow:getChildById('miniwindowScrollBar') + scrollbar:mergeStyle({ ['$!on'] = { }}) + battlePanel = battleWindow:recursiveGetChildById('battlePanel') hidePlayersButton = battleWindow:recursiveGetChildById('hidePlayers') diff --git a/modules/game_containers/container.otui b/modules/game_containers/container.otui index d4ff4af2..b23d532b 100644 --- a/modules/game_containers/container.otui +++ b/modules/game_containers/container.otui @@ -31,4 +31,3 @@ ContainerWindow < MiniWindow type: grid cell-size: 34 34 flow: true - diff --git a/modules/game_containers/containers.lua b/modules/game_containers/containers.lua index b2dc0481..e7dabd82 100644 --- a/modules/game_containers/containers.lua +++ b/modules/game_containers/containers.lua @@ -88,6 +88,11 @@ function onContainerOpen(container, previousContainer) container.window = containerWindow container.itemsPanel = containerPanel + + local layout = containerPanel:getLayout() + local cellSize = layout:getCellSize() + containerWindow:setContentMinimumHeight(cellSize.height*1) + containerWindow:setContentMaximumHeight(cellSize.height*layout:getNumLines()) end function onContainerClose(container) diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index b368de91..b73d4a11 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -600,6 +600,9 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("setFlow", &UIGridLayout::setFlow); g_lua.bindClassMemberFunction("setNumColumns", &UIGridLayout::setNumColumns); g_lua.bindClassMemberFunction("setNumLines", &UIGridLayout::setNumLines); + g_lua.bindClassMemberFunction("getNumColumns", &UIGridLayout::getNumColumns); + g_lua.bindClassMemberFunction("getNumLines", &UIGridLayout::getNumLines); + g_lua.bindClassMemberFunction("getCellSize", &UIGridLayout::getCellSize); g_lua.bindClassMemberFunction("isUIGridLayout", &UIGridLayout::isUIGridLayout); // UIAnchorLayout diff --git a/src/framework/ui/uigridlayout.cpp b/src/framework/ui/uigridlayout.cpp index a5caf593..54599bd8 100644 --- a/src/framework/ui/uigridlayout.cpp +++ b/src/framework/ui/uigridlayout.cpp @@ -37,7 +37,6 @@ void UIGridLayout::applyStyle(const OTMLNodePtr& styleNode) { UILayout::applyStyle(styleNode); - for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "cell-size") setCellSize(node->value()); @@ -83,8 +82,13 @@ bool UIGridLayout::internalUpdate() Point topLeft = clippingRect.topLeft(); int numColumns = m_numColumns; - if(m_flow && m_cellSize.width() > 0) + if(m_flow && m_cellSize.width() > 0) { numColumns = clippingRect.width() / (m_cellSize.width() + m_cellSpacing); + if(numColumns > 0) { + m_numColumns = numColumns; + m_numLines = std::ceil(widgets.size() / (float)numColumns); + } + } if(numColumns <= 0) numColumns = 1; diff --git a/src/framework/ui/uigridlayout.h b/src/framework/ui/uigridlayout.h index 6891ee7f..e81f012a 100644 --- a/src/framework/ui/uigridlayout.h +++ b/src/framework/ui/uigridlayout.h @@ -45,6 +45,10 @@ public: void setFitChildren(bool enable) { m_fitChildren = enable; update(); } void setFlow(bool enable) { m_flow = enable; update(); } + Size getCellSize() { return m_cellSize; } + int getNumColumns() { return m_numColumns; } + int getNumLines() { return m_numLines; } + virtual bool isUIGridLayout() { return true; } protected: @@ -61,4 +65,3 @@ private: }; #endif - diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index f107add7..b1a22465 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -180,7 +180,11 @@ void Game::processOpenContainer(int containerId, const ItemPtr& containerItem, c m_containers[containerId] = container; container->onAddItems(items); + // we might want to close a container here + enableBotCall(); container->onOpen(previousContainer); + disableBotCall(); + if(previousContainer) previousContainer->onClose(); }