mirror of
https://github.com/edubart/otclient.git
synced 2025-12-20 15:37:11 +01:00
Save miniwindows states
This commit is contained in:
@@ -2,6 +2,7 @@ UIMiniWindowContainer = extends(UIWidget)
|
||||
|
||||
function UIMiniWindowContainer.create()
|
||||
local container = UIMiniWindowContainer.internalCreate()
|
||||
container.scheduledWidgets = {}
|
||||
container:setFocusable(false)
|
||||
container:setPhantom(true)
|
||||
return container
|
||||
@@ -14,7 +15,9 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
|
||||
return true
|
||||
end
|
||||
|
||||
oldParent:removeChild(widget)
|
||||
if oldParent then
|
||||
oldParent:removeChild(widget)
|
||||
end
|
||||
|
||||
if widget.movedWidget then
|
||||
local index = self:getChildIndex(widget.movedWidget)
|
||||
@@ -27,6 +30,56 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMiniWindowContainer:swapInsert(widget, index)
|
||||
local oldParent = widget:getParent()
|
||||
local oldIndex = self:getChildIndex(widget)
|
||||
|
||||
if oldParent == self and oldIndex ~= index then
|
||||
local oldWidget = self:getChildByIndex(index)
|
||||
self:removeChild(oldWidget)
|
||||
self:insertChild(oldIndex, oldWidget)
|
||||
self:removeChild(widget)
|
||||
self:insertChild(index, widget)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMiniWindowContainer:scheduleInsert(widget, index)
|
||||
if index - 1 > self:getChildCount() then
|
||||
if self.scheduledWidgets[index] then
|
||||
warning('replacing scheduled widget id ' .. widget:getId())
|
||||
end
|
||||
self.scheduledWidgets[index] = widget
|
||||
else
|
||||
local oldParent = widget:getParent()
|
||||
if oldParent ~= self then
|
||||
oldParent:removeChild(widget)
|
||||
self:insertChild(index, widget)
|
||||
else
|
||||
self:swapInsert(widget, index)
|
||||
end
|
||||
|
||||
while true do
|
||||
local placed = false
|
||||
for nIndex,nWidget in pairs(self.scheduledWidgets) do
|
||||
if nIndex - 1 <= self:getChildCount() then
|
||||
self:insertChild(nIndex, nWidget)
|
||||
self.scheduledWidgets[nIndex] = nil
|
||||
placed = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not placed then break end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UIMiniWindowContainer:saveChildren()
|
||||
local children = self:getChildren()
|
||||
for i=1,#children do
|
||||
children[i]:saveParentIndex(self:getId(), i)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMiniWindowContainer:getClassName()
|
||||
return 'UIMiniWindowContainer'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user