You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.6 KiB
104 lines
2.6 KiB
12 years ago
|
-- @docclass
|
||
12 years ago
|
UIMiniWindowContainer = extends(UIWidget)
|
||
|
|
||
|
function UIMiniWindowContainer.create()
|
||
|
local container = UIMiniWindowContainer.internalCreate()
|
||
12 years ago
|
container.scheduledWidgets = {}
|
||
12 years ago
|
container:setFocusable(false)
|
||
|
container:setPhantom(true)
|
||
|
return container
|
||
|
end
|
||
|
|
||
12 years ago
|
function UIMiniWindowContainer:onDrop(widget, mousePos)
|
||
12 years ago
|
if widget:getClassName() == 'UIMiniWindow' then
|
||
12 years ago
|
local oldParent = widget:getParent()
|
||
|
if oldParent == self then
|
||
|
return true
|
||
|
end
|
||
|
|
||
12 years ago
|
if oldParent then
|
||
|
oldParent:removeChild(widget)
|
||
|
end
|
||
12 years ago
|
|
||
|
if widget.movedWidget then
|
||
|
local index = self:getChildIndex(widget.movedWidget)
|
||
|
self:insertChild(index + widget.movedIndex, widget)
|
||
|
else
|
||
|
self:addChild(widget)
|
||
|
end
|
||
12 years ago
|
|
||
12 years ago
|
return true
|
||
|
end
|
||
12 years ago
|
end
|
||
|
|
||
12 years ago
|
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)
|
||
|
|
||
12 years ago
|
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
|
||
12 years ago
|
end
|
||
12 years ago
|
if not placed then break end
|
||
12 years ago
|
end
|
||
12 years ago
|
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function UIMiniWindowContainer:order()
|
||
|
local children = self:getChildren()
|
||
|
for i=1,#children do
|
||
|
if not children[i].miniLoaded then return end
|
||
|
end
|
||
|
|
||
|
for i=1,#children do
|
||
|
if children[i].miniIndex then
|
||
|
self:swapInsert(children[i], children[i].miniIndex)
|
||
12 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function UIMiniWindowContainer:saveChildren()
|
||
|
local children = self:getChildren()
|
||
12 years ago
|
local ignoreIndex = 0
|
||
12 years ago
|
for i=1,#children do
|
||
12 years ago
|
if children[i].save then
|
||
|
children[i]:saveParentIndex(self:getId(), i - ignoreIndex)
|
||
|
else
|
||
|
ignoreIndex = ignoreIndex + 1
|
||
|
end
|
||
12 years ago
|
end
|
||
|
end
|
||
|
|
||
12 years ago
|
function UIMiniWindowContainer:getClassName()
|
||
|
return 'UIMiniWindowContainer'
|
||
|
end
|