parent
0bb991e14e
commit
ab7400c51d
|
@ -75,7 +75,7 @@ MiniWindow < UIMiniWindow
|
|||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: 3
|
||||
minimum: 64
|
||||
minimum: 48
|
||||
background: #ffffff88
|
||||
|
||||
MiniWindowContents < ScrollablePanel
|
||||
|
|
|
@ -3,6 +3,7 @@ UIMiniWindow = extends(UIWindow)
|
|||
|
||||
function UIMiniWindow.create()
|
||||
local miniwindow = UIMiniWindow.internalCreate()
|
||||
miniwindow.isSetup = false
|
||||
return miniwindow
|
||||
end
|
||||
|
||||
|
@ -103,9 +104,15 @@ 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()
|
||||
|
||||
self.miniLoaded = true
|
||||
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -31,4 +31,3 @@ ContainerWindow < MiniWindow
|
|||
type: grid
|
||||
cell-size: 34 34
|
||||
flow: true
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -600,6 +600,9 @@ void Application::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<UIGridLayout>("setFlow", &UIGridLayout::setFlow);
|
||||
g_lua.bindClassMemberFunction<UIGridLayout>("setNumColumns", &UIGridLayout::setNumColumns);
|
||||
g_lua.bindClassMemberFunction<UIGridLayout>("setNumLines", &UIGridLayout::setNumLines);
|
||||
g_lua.bindClassMemberFunction<UIGridLayout>("getNumColumns", &UIGridLayout::getNumColumns);
|
||||
g_lua.bindClassMemberFunction<UIGridLayout>("getNumLines", &UIGridLayout::getNumLines);
|
||||
g_lua.bindClassMemberFunction<UIGridLayout>("getCellSize", &UIGridLayout::getCellSize);
|
||||
g_lua.bindClassMemberFunction<UIGridLayout>("isUIGridLayout", &UIGridLayout::isUIGridLayout);
|
||||
|
||||
// UIAnchorLayout
|
||||
|
|
|
@ -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<Size>());
|
||||
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue