mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
Fix issue #21, but miniwindows can be a lot smarter
This commit is contained in:
@@ -3,7 +3,6 @@ UIMiniWindow = extends(UIWindow)
|
||||
|
||||
function UIMiniWindow.create()
|
||||
local miniwindow = UIMiniWindow.internalCreate()
|
||||
miniwindow.isSetup = false
|
||||
return miniwindow
|
||||
end
|
||||
|
||||
@@ -22,6 +21,7 @@ function UIMiniWindow:open(dontSave)
|
||||
end
|
||||
|
||||
function UIMiniWindow:close(dontSave)
|
||||
if not self:isExplicitlyVisible() then return end
|
||||
self:setVisible(false)
|
||||
|
||||
if not dontSave then
|
||||
@@ -88,6 +88,7 @@ function UIMiniWindow:onSetup()
|
||||
if parent then
|
||||
if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then
|
||||
self.miniIndex = selfSettings.index
|
||||
--addEvent(function() parent:scheduleInsert(self, selfSettings.index) end)
|
||||
parent:scheduleInsert(self, selfSettings.index)
|
||||
elseif selfSettings.position then
|
||||
self:setParent(parent)
|
||||
@@ -109,8 +110,6 @@ function UIMiniWindow:onSetup()
|
||||
self:setHeight(selfSettings.height)
|
||||
end
|
||||
end
|
||||
|
||||
self.isSetup = true
|
||||
end
|
||||
|
||||
local newParent = self:getParent()
|
||||
@@ -119,24 +118,22 @@ function UIMiniWindow:onSetup()
|
||||
|
||||
if self.save then
|
||||
if oldParent and oldParent:getClassName() == 'UIMiniWindowContainer' then
|
||||
oldParent:order()
|
||||
addEvent(function() oldParent:order() end)
|
||||
end
|
||||
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and newParent ~= oldParent then
|
||||
newParent:order()
|
||||
addEvent(function() newParent:order() end)
|
||||
end
|
||||
end
|
||||
|
||||
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and self:isVisible() then
|
||||
-- not on input event, must rework
|
||||
--newParent:fitAll(self)
|
||||
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)
|
||||
parent:fitAll(self)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -220,7 +217,6 @@ function UIMiniWindow:onMousePress()
|
||||
end
|
||||
|
||||
function UIMiniWindow:onFocusChange(focused)
|
||||
-- miniwindows only raises when its outside MiniWindowContainers
|
||||
if not focused then return end
|
||||
local parent = self:getParent()
|
||||
if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then
|
||||
@@ -228,15 +224,12 @@ function UIMiniWindow:onFocusChange(focused)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMiniWindow:onGeometryChange(oldRect, rect)
|
||||
if self.isSetup then
|
||||
self:setSettings({height = rect.height})
|
||||
end
|
||||
function UIMiniWindow:onHeightChange(height)
|
||||
self:setSettings({height = height})
|
||||
|
||||
local parent = self:getParent()
|
||||
if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then
|
||||
-- not on input event, must rework
|
||||
--parent:fitAll(self)
|
||||
parent:fitAll(self)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -311,3 +304,13 @@ function UIMiniWindow:setContentMaximumHeight(height)
|
||||
local resizeBorder = self:getChildById('bottomResizeBorder')
|
||||
resizeBorder:setMaximum(minHeight + height)
|
||||
end
|
||||
|
||||
function UIMiniWindow:getMinimumHeight()
|
||||
local resizeBorder = self:getChildById('bottomResizeBorder')
|
||||
return resizeBorder:getMinimum()
|
||||
end
|
||||
|
||||
function UIMiniWindow:getMaximumHeight()
|
||||
local resizeBorder = self:getChildById('bottomResizeBorder')
|
||||
return resizeBorder:getMaximum()
|
||||
end
|
||||
|
@@ -21,19 +21,31 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
|
||||
local sumHeight = 0
|
||||
local children = self:getChildren()
|
||||
for i=1,#children do
|
||||
sumHeight = sumHeight + children[i]:getHeight()
|
||||
if children[i]:isVisible() then
|
||||
sumHeight = sumHeight + children[i]:getHeight()
|
||||
end
|
||||
end
|
||||
|
||||
local selfHeight = self:getHeight()
|
||||
local selfHeight = self:getHeight() - (self:getMarginTop() + self:getMarginBottom() + self:getPaddingTop() + self:getPaddingBottom())
|
||||
if sumHeight <= selfHeight then
|
||||
return
|
||||
end
|
||||
|
||||
local removeChildren = {}
|
||||
|
||||
-- try to resize noRemoveChild
|
||||
local maximumHeight = selfHeight - (sumHeight - noRemoveChild:getHeight())
|
||||
if noRemoveChild:getMinimumHeight() <= maximumHeight then
|
||||
sumHeight = sumHeight - noRemoveChild:getHeight() + maximumHeight
|
||||
addEvent(function() noRemoveChild:setHeight(maximumHeight) end)
|
||||
end
|
||||
|
||||
-- TODO: try to resize another widget?
|
||||
-- TODO: try to find another panel?
|
||||
|
||||
-- try to remove no-save widget
|
||||
for i=#children,1,-1 do
|
||||
if sumHeight < selfHeight then
|
||||
if sumHeight <= selfHeight then
|
||||
break
|
||||
end
|
||||
|
||||
@@ -47,7 +59,7 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
|
||||
|
||||
-- try to remove save widget
|
||||
for i=#children,1,-1 do
|
||||
if sumHeight < selfHeight then
|
||||
if sumHeight <= selfHeight then
|
||||
break
|
||||
end
|
||||
|
||||
@@ -63,11 +75,6 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
|
||||
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)
|
||||
@@ -88,6 +95,7 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
|
||||
self:addChild(widget)
|
||||
end
|
||||
|
||||
self:fitAll(widget)
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -114,7 +122,9 @@ function UIMiniWindowContainer:scheduleInsert(widget, index)
|
||||
else
|
||||
local oldParent = widget:getParent()
|
||||
if oldParent ~= self then
|
||||
oldParent:removeChild(widget)
|
||||
if oldParent then
|
||||
oldParent:removeChild(widget)
|
||||
end
|
||||
self:insertChild(index, widget)
|
||||
|
||||
while true do
|
||||
|
@@ -37,23 +37,15 @@ function UIResizeBorder:onMouseMove(mousePos, mouseMoved)
|
||||
if self.vertical then
|
||||
local delta = mousePos.y - self:getY() - self:getHeight()/2
|
||||
local parent = self:getParent()
|
||||
local newsize = math.min(math.max(parent:getHeight() + delta, self.minimum), self.maximum)
|
||||
self.newsize = newsize
|
||||
if not self.event or self.event:isExecuted() then
|
||||
self.event = addEvent(function()
|
||||
parent:setHeight(self.newsize)
|
||||
end)
|
||||
end
|
||||
local newSize = math.min(math.max(parent:getHeight() + delta, self.minimum), self.maximum)
|
||||
parent:setHeight(newSize)
|
||||
signalcall(parent.onHeightChange, parent, newSize)
|
||||
else
|
||||
local delta = mousePos.x - self:getX() - self:getWidth()/2
|
||||
local parent = self:getParent()
|
||||
local newsize = math.min(math.max(parent:getWidth() + delta, self.minimum), self.maximum)
|
||||
self.newsize = newsize
|
||||
if not self.event or self.event:isExecuted() then
|
||||
self.event = addEvent(function()
|
||||
parent:setWidth(self.newsize)
|
||||
end)
|
||||
end
|
||||
local newSize = math.min(math.max(parent:getWidth() + delta, self.minimum), self.maximum)
|
||||
parent:setWidth(newSize)
|
||||
signalcall(parent.onWidthChange, parent, newSize)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
Reference in New Issue
Block a user