2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
2014-06-06 18:10:14 +02:00
|
|
|
UIMiniWindow = extends(UIWindow, "UIMiniWindow")
|
2012-03-27 00:24:01 +02:00
|
|
|
|
|
|
|
function UIMiniWindow.create()
|
|
|
|
local miniwindow = UIMiniWindow.internalCreate()
|
|
|
|
return miniwindow
|
|
|
|
end
|
|
|
|
|
2012-06-21 21:31:22 +02:00
|
|
|
function UIMiniWindow:open(dontSave)
|
|
|
|
self:setVisible(true)
|
|
|
|
|
|
|
|
if not dontSave then
|
|
|
|
self:setSettings({closed = false})
|
|
|
|
end
|
|
|
|
|
|
|
|
signalcall(self.onOpen, self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:close(dontSave)
|
2012-08-21 07:35:08 +02:00
|
|
|
if not self:isExplicitlyVisible() then return end
|
2012-06-21 21:31:22 +02:00
|
|
|
self:setVisible(false)
|
|
|
|
|
|
|
|
if not dontSave then
|
|
|
|
self:setSettings({closed = true})
|
|
|
|
end
|
|
|
|
|
|
|
|
signalcall(self.onClose, self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:minimize(dontSave)
|
|
|
|
self:setOn(true)
|
|
|
|
self:getChildById('contentsPanel'):hide()
|
|
|
|
self:getChildById('miniwindowScrollBar'):hide()
|
|
|
|
self:getChildById('bottomResizeBorder'):hide()
|
|
|
|
self:getChildById('minimizeButton'):setOn(true)
|
2012-08-22 03:08:21 +02:00
|
|
|
self.maximizedHeight = self:getHeight()
|
2012-06-21 21:31:22 +02:00
|
|
|
self:setHeight(self.minimizedHeight)
|
|
|
|
|
|
|
|
if not dontSave then
|
|
|
|
self:setSettings({minimized = true})
|
|
|
|
end
|
|
|
|
|
|
|
|
signalcall(self.onMinimize, self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:maximize(dontSave)
|
|
|
|
self:setOn(false)
|
|
|
|
self:getChildById('contentsPanel'):show()
|
|
|
|
self:getChildById('miniwindowScrollBar'):show()
|
|
|
|
self:getChildById('bottomResizeBorder'):show()
|
|
|
|
self:getChildById('minimizeButton'):setOn(false)
|
2012-08-22 03:08:21 +02:00
|
|
|
self:setHeight(self:getSettings('height') or self.maximizedHeight)
|
2012-06-21 21:31:22 +02:00
|
|
|
|
|
|
|
if not dontSave then
|
|
|
|
self:setSettings({minimized = false})
|
|
|
|
end
|
|
|
|
|
2012-08-21 22:27:44 +02:00
|
|
|
local parent = self:getParent()
|
|
|
|
if parent and parent:getClassName() == 'UIMiniWindowContainer' then
|
|
|
|
parent:fitAll(self)
|
|
|
|
end
|
|
|
|
|
2012-06-21 21:31:22 +02:00
|
|
|
signalcall(self.onMaximize, self)
|
|
|
|
end
|
|
|
|
|
2012-08-21 23:40:47 +02:00
|
|
|
function UIMiniWindow:setup()
|
2012-06-21 21:31:22 +02:00
|
|
|
self:getChildById('closeButton').onClick =
|
|
|
|
function()
|
|
|
|
self:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
self:getChildById('minimizeButton').onClick =
|
|
|
|
function()
|
|
|
|
if self:isOn() then
|
|
|
|
self:maximize()
|
|
|
|
else
|
|
|
|
self:minimize()
|
|
|
|
end
|
|
|
|
end
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2013-01-08 06:09:00 +01:00
|
|
|
self:getChildById('miniwindowTopBar').onDoubleClick =
|
|
|
|
function()
|
|
|
|
if self:isOn() then
|
|
|
|
self:maximize()
|
|
|
|
else
|
|
|
|
self:minimize()
|
|
|
|
end
|
|
|
|
end
|
2012-06-21 21:31:22 +02:00
|
|
|
|
2012-06-24 14:41:39 +02:00
|
|
|
local oldParent = self:getParent()
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
local settings = g_settings.getNode('MiniWindows')
|
2012-06-21 21:31:22 +02:00
|
|
|
if settings then
|
|
|
|
local selfSettings = settings[self:getId()]
|
|
|
|
if selfSettings then
|
|
|
|
if selfSettings.parentId then
|
|
|
|
local parent = rootWidget:recursiveGetChildById(selfSettings.parentId)
|
|
|
|
if parent then
|
|
|
|
if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then
|
2012-06-24 14:41:39 +02:00
|
|
|
self.miniIndex = selfSettings.index
|
2012-06-21 21:31:22 +02:00
|
|
|
parent:scheduleInsert(self, selfSettings.index)
|
|
|
|
elseif selfSettings.position then
|
2013-01-16 20:57:05 +01:00
|
|
|
self:setParent(parent, true)
|
2012-06-21 21:31:22 +02:00
|
|
|
self:setPosition(topoint(selfSettings.position))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if selfSettings.minimized then
|
|
|
|
self:minimize(true)
|
2012-08-22 03:08:21 +02:00
|
|
|
else
|
|
|
|
if selfSettings.height and self:isResizeable() then
|
|
|
|
self:setHeight(selfSettings.height)
|
|
|
|
elseif selfSettings.height and not self:isResizeable() then
|
|
|
|
self:eraseSettings({height = true})
|
|
|
|
end
|
2012-06-21 21:31:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if selfSettings.closed then
|
|
|
|
self:close(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-24 14:41:39 +02:00
|
|
|
|
|
|
|
local newParent = self:getParent()
|
|
|
|
|
|
|
|
self.miniLoaded = true
|
|
|
|
|
2012-08-08 16:24:59 +02:00
|
|
|
if self.save then
|
|
|
|
if oldParent and oldParent:getClassName() == 'UIMiniWindowContainer' then
|
2012-08-21 07:35:08 +02:00
|
|
|
addEvent(function() oldParent:order() end)
|
2012-08-08 16:24:59 +02:00
|
|
|
end
|
|
|
|
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and newParent ~= oldParent then
|
2012-08-21 07:35:08 +02:00
|
|
|
addEvent(function() newParent:order() end)
|
2012-08-08 16:24:59 +02:00
|
|
|
end
|
2012-06-24 14:41:39 +02:00
|
|
|
end
|
2012-08-18 07:04:01 +02:00
|
|
|
|
2012-08-21 23:40:47 +02:00
|
|
|
self:fitOnParent()
|
2012-08-18 07:04:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:onVisibilityChange(visible)
|
2012-08-21 23:40:47 +02:00
|
|
|
self:fitOnParent()
|
2012-03-28 16:10:21 +02:00
|
|
|
end
|
|
|
|
|
2012-03-27 00:24:01 +02:00
|
|
|
function UIMiniWindow:onDragEnter(mousePos)
|
|
|
|
local parent = self:getParent()
|
|
|
|
if not parent then return false end
|
|
|
|
|
|
|
|
if parent:getClassName() == 'UIMiniWindowContainer' then
|
|
|
|
local containerParent = parent:getParent()
|
|
|
|
parent:removeChild(self)
|
|
|
|
containerParent:addChild(self)
|
2012-06-21 21:31:22 +02:00
|
|
|
parent:saveChildren()
|
2012-03-27 00:24:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local oldPos = self:getPosition()
|
|
|
|
self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y }
|
|
|
|
self:setPosition(oldPos)
|
2012-03-28 16:10:21 +02:00
|
|
|
self.free = true
|
2012-03-27 00:24:01 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-08-17 23:36:53 +02:00
|
|
|
function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
|
|
|
|
if self.movedWidget then
|
2013-02-28 03:45:03 +01:00
|
|
|
self.setMovedChildMargin(self.movedOldMargin or 0)
|
2012-08-17 23:36:53 +02:00
|
|
|
self.movedWidget = nil
|
|
|
|
self.setMovedChildMargin = nil
|
2013-02-28 03:45:03 +01:00
|
|
|
self.movedOldMargin = nil
|
2012-08-17 23:36:53 +02:00
|
|
|
self.movedIndex = nil
|
|
|
|
end
|
|
|
|
|
2012-08-21 00:50:18 +02:00
|
|
|
self:saveParent(self:getParent())
|
2012-08-17 23:36:53 +02:00
|
|
|
end
|
|
|
|
|
2012-06-11 07:38:08 +02:00
|
|
|
function UIMiniWindow:onDragMove(mousePos, mouseMoved)
|
|
|
|
local oldMousePosY = mousePos.y - mouseMoved.y
|
2012-06-11 16:10:03 +02:00
|
|
|
local children = rootWidget:recursiveGetChildrenByMarginPos(mousePos)
|
2012-06-11 07:38:08 +02:00
|
|
|
local overAnyWidget = false
|
|
|
|
for i=1,#children do
|
|
|
|
local child = children[i]
|
|
|
|
if child:getParent():getClassName() == 'UIMiniWindowContainer' then
|
|
|
|
overAnyWidget = true
|
|
|
|
|
|
|
|
local childCenterY = child:getY() + child:getHeight() / 2
|
|
|
|
if child == self.movedWidget and mousePos.y < childCenterY and oldMousePosY < childCenterY then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.movedWidget then
|
2013-02-28 03:45:03 +01:00
|
|
|
self.setMovedChildMargin(self.movedOldMargin or 0)
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin = nil
|
2012-06-11 07:38:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if mousePos.y < childCenterY then
|
2013-02-28 03:45:03 +01:00
|
|
|
self.movedOldMargin = child:getMarginTop()
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin = function(v) child:setMarginTop(v) end
|
2012-06-11 07:38:08 +02:00
|
|
|
self.movedIndex = 0
|
|
|
|
else
|
2013-02-28 03:45:03 +01:00
|
|
|
self.movedOldMargin = child:getMarginBottom()
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin = function(v) child:setMarginBottom(v) end
|
2012-06-11 07:38:08 +02:00
|
|
|
self.movedIndex = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
self.movedWidget = child
|
2012-06-11 16:10:03 +02:00
|
|
|
self.setMovedChildMargin(self:getHeight())
|
2012-06-11 07:38:08 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not overAnyWidget and self.movedWidget then
|
2013-02-28 03:45:03 +01:00
|
|
|
self.setMovedChildMargin(self.movedOldMargin or 0)
|
2012-06-11 07:38:08 +02:00
|
|
|
self.movedWidget = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return UIWindow.onDragMove(self, mousePos, mouseMoved)
|
|
|
|
end
|
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
function UIMiniWindow:onMousePress()
|
|
|
|
local parent = self:getParent()
|
|
|
|
if not parent then return false end
|
|
|
|
if parent:getClassName() ~= 'UIMiniWindowContainer' then
|
|
|
|
self:raise()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-27 00:24:01 +02:00
|
|
|
function UIMiniWindow:onFocusChange(focused)
|
|
|
|
if not focused then return end
|
|
|
|
local parent = self:getParent()
|
|
|
|
if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then
|
|
|
|
self:raise()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-21 07:35:08 +02:00
|
|
|
function UIMiniWindow:onHeightChange(height)
|
2012-08-22 03:08:21 +02:00
|
|
|
if not self:isOn() then
|
|
|
|
self:setSettings({height = height})
|
|
|
|
end
|
2012-08-21 23:40:47 +02:00
|
|
|
self:fitOnParent()
|
2012-08-18 07:04:01 +02:00
|
|
|
end
|
|
|
|
|
2012-08-21 22:27:44 +02:00
|
|
|
function UIMiniWindow:getSettings(name)
|
2012-08-22 03:08:21 +02:00
|
|
|
if not self.save then return nil end
|
2012-08-21 22:27:44 +02:00
|
|
|
local settings = g_settings.getNode('MiniWindows')
|
|
|
|
if settings then
|
|
|
|
local selfSettings = settings[self:getId()]
|
|
|
|
if selfSettings then
|
|
|
|
return selfSettings[name]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2012-06-21 21:31:22 +02:00
|
|
|
function UIMiniWindow:setSettings(data)
|
2012-06-24 14:41:39 +02:00
|
|
|
if not self.save then return end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
local settings = g_settings.getNode('MiniWindows')
|
2012-06-21 21:31:22 +02:00
|
|
|
if not settings then
|
|
|
|
settings = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local id = self:getId()
|
|
|
|
if not settings[id] then
|
|
|
|
settings[id] = {}
|
|
|
|
end
|
2012-03-28 16:10:21 +02:00
|
|
|
|
2012-06-21 21:31:22 +02:00
|
|
|
for key,value in pairs(data) do
|
|
|
|
settings[id][key] = value
|
2012-03-28 16:10:21 +02:00
|
|
|
end
|
2012-06-21 21:31:22 +02:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_settings.setNode('MiniWindows', settings)
|
2012-03-28 16:10:21 +02:00
|
|
|
end
|
|
|
|
|
2012-08-22 03:08:21 +02:00
|
|
|
function UIMiniWindow:eraseSettings(data)
|
|
|
|
if not self.save then return end
|
|
|
|
|
|
|
|
local settings = g_settings.getNode('MiniWindows')
|
|
|
|
if not settings then
|
|
|
|
settings = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local id = self:getId()
|
|
|
|
if not settings[id] then
|
|
|
|
settings[id] = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
for key,value in pairs(data) do
|
|
|
|
settings[id][key] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
g_settings.setNode('MiniWindows', settings)
|
|
|
|
end
|
|
|
|
|
2012-08-21 00:50:18 +02:00
|
|
|
function UIMiniWindow:saveParent(parent)
|
|
|
|
local parent = self:getParent()
|
|
|
|
if parent then
|
|
|
|
if parent:getClassName() == 'UIMiniWindowContainer' then
|
|
|
|
parent:saveChildren()
|
|
|
|
else
|
|
|
|
self:saveParentPosition(parent:getId(), self:getPosition())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-21 21:31:22 +02:00
|
|
|
function UIMiniWindow:saveParentPosition(parentId, position)
|
|
|
|
local selfSettings = {}
|
|
|
|
selfSettings.parentId = parentId
|
|
|
|
selfSettings.position = pointtostring(position)
|
|
|
|
self:setSettings(selfSettings)
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:saveParentIndex(parentId, index)
|
|
|
|
local selfSettings = {}
|
|
|
|
selfSettings.parentId = parentId
|
|
|
|
selfSettings.index = index
|
|
|
|
self:setSettings(selfSettings)
|
2012-08-03 15:25:47 +02:00
|
|
|
self.miniIndex = index
|
2012-03-28 21:09:45 +02:00
|
|
|
end
|
2012-07-13 01:40:55 +02:00
|
|
|
|
|
|
|
function UIMiniWindow:disableResize()
|
|
|
|
self:getChildById('bottomResizeBorder'):disable()
|
|
|
|
end
|
2012-08-22 16:21:02 +02:00
|
|
|
|
|
|
|
function UIMiniWindow:enableResize()
|
|
|
|
self:getChildById('bottomResizeBorder'):enable()
|
|
|
|
end
|
2012-08-17 23:36:53 +02:00
|
|
|
|
2012-08-21 23:40:47 +02:00
|
|
|
function UIMiniWindow:fitOnParent()
|
|
|
|
local parent = self:getParent()
|
|
|
|
if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then
|
|
|
|
parent:fitAll(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-16 20:57:05 +01:00
|
|
|
function UIMiniWindow:setParent(parent, dontsave)
|
2012-08-21 23:40:47 +02:00
|
|
|
UIWidget.setParent(self, parent)
|
2013-01-16 20:57:05 +01:00
|
|
|
if not dontsave then
|
|
|
|
self:saveParent(parent)
|
|
|
|
end
|
2012-08-21 23:40:47 +02:00
|
|
|
self:fitOnParent()
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:setHeight(height)
|
|
|
|
UIWidget.setHeight(self, height)
|
|
|
|
signalcall(self.onHeightChange, self, height)
|
|
|
|
end
|
|
|
|
|
2012-08-21 00:50:18 +02:00
|
|
|
function UIMiniWindow:setContentHeight(height)
|
|
|
|
local contentsPanel = self:getChildById('contentsPanel')
|
|
|
|
local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom()
|
2012-08-21 22:27:44 +02:00
|
|
|
|
|
|
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
|
|
|
resizeBorder:setParentSize(minHeight + height)
|
2012-08-21 00:50:18 +02:00
|
|
|
end
|
|
|
|
|
2012-08-18 07:04:01 +02:00
|
|
|
function UIMiniWindow:setContentMinimumHeight(height)
|
|
|
|
local contentsPanel = self:getChildById('contentsPanel')
|
|
|
|
local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom()
|
|
|
|
|
2012-08-17 23:36:53 +02:00
|
|
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
2012-08-18 07:04:01 +02:00
|
|
|
resizeBorder:setMinimum(minHeight + height)
|
2012-08-17 23:36:53 +02:00
|
|
|
end
|
|
|
|
|
2012-08-18 07:04:01 +02:00
|
|
|
function UIMiniWindow:setContentMaximumHeight(height)
|
|
|
|
local contentsPanel = self:getChildById('contentsPanel')
|
|
|
|
local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom()
|
|
|
|
|
2012-08-17 23:36:53 +02:00
|
|
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
2012-08-18 07:04:01 +02:00
|
|
|
resizeBorder:setMaximum(minHeight + height)
|
2012-08-17 23:36:53 +02:00
|
|
|
end
|
2012-08-21 07:35:08 +02:00
|
|
|
|
|
|
|
function UIMiniWindow:getMinimumHeight()
|
|
|
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
|
|
|
return resizeBorder:getMinimum()
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIMiniWindow:getMaximumHeight()
|
|
|
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
|
|
|
return resizeBorder:getMaximum()
|
|
|
|
end
|
2012-08-21 23:40:47 +02:00
|
|
|
|
|
|
|
function UIMiniWindow:isResizeable()
|
|
|
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
2012-08-22 05:33:44 +02:00
|
|
|
return resizeBorder:isExplicitlyVisible() and resizeBorder:isEnabled()
|
2012-08-21 23:40:47 +02:00
|
|
|
end
|