mirror of
https://github.com/edubart/otclient.git
synced 2025-12-20 23:47:12 +01:00
Save miniwindows states
This commit is contained in:
@@ -5,9 +5,102 @@ function UIMiniWindow.create()
|
||||
return miniwindow
|
||||
end
|
||||
|
||||
function UIMiniWindow:getClassName()
|
||||
return 'UIMiniWindow'
|
||||
end
|
||||
|
||||
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)
|
||||
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)
|
||||
self.savedHeight = self:getHeight()
|
||||
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)
|
||||
self:setHeight(self.savedHeight)
|
||||
|
||||
if not dontSave then
|
||||
self:setSettings({minimized = false})
|
||||
end
|
||||
|
||||
signalcall(self.onMaximize, self)
|
||||
end
|
||||
|
||||
function UIMiniWindow:onSetup()
|
||||
self:getChildById('closeButton').onClick = function() signalcall(self.onClose, self) end
|
||||
self:getChildById('minimizeButton').onClick = function() signalcall(self.onMinimize, self) end
|
||||
self:getChildById('closeButton').onClick =
|
||||
function()
|
||||
self:close()
|
||||
end
|
||||
|
||||
self:getChildById('minimizeButton').onClick =
|
||||
function()
|
||||
if self:isOn() then
|
||||
self:maximize()
|
||||
else
|
||||
self:minimize()
|
||||
end
|
||||
end
|
||||
|
||||
local settings = Settings.getNode('MiniWindows')
|
||||
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
|
||||
parent:scheduleInsert(self, selfSettings.index)
|
||||
elseif selfSettings.position then
|
||||
self:setParent(parent)
|
||||
self:setPosition(topoint(selfSettings.position))
|
||||
self:bindRectToParent()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if selfSettings.minimized then
|
||||
self:minimize(true)
|
||||
end
|
||||
|
||||
if selfSettings.closed then
|
||||
self:close(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UIMiniWindow:onDragEnter(mousePos)
|
||||
@@ -18,6 +111,7 @@ function UIMiniWindow:onDragEnter(mousePos)
|
||||
local containerParent = parent:getParent()
|
||||
parent:removeChild(self)
|
||||
containerParent:addChild(self)
|
||||
parent:saveChildren()
|
||||
end
|
||||
|
||||
local oldPos = self:getPosition()
|
||||
@@ -84,6 +178,15 @@ function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
|
||||
self.setMovedChildMargin = nil
|
||||
self.movedIndex = nil
|
||||
end
|
||||
|
||||
local parent = self:getParent()
|
||||
if parent then
|
||||
if parent:getClassName() == 'UIMiniWindowContainer' then
|
||||
parent:saveChildren()
|
||||
else
|
||||
self:saveParentPosition(parent:getId(), self:getPosition())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UIMiniWindow:onFocusChange(focused)
|
||||
@@ -95,28 +198,34 @@ function UIMiniWindow:onFocusChange(focused)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMiniWindow:onClose()
|
||||
end
|
||||
|
||||
function UIMiniWindow:onMinimize()
|
||||
if self:isOn() then
|
||||
self:setOn(false)
|
||||
self:getChildById('contentsPanel'):show()
|
||||
self:getChildById('miniwindowScrollBar'):show()
|
||||
self:getChildById('bottomResizeBorder'):show()
|
||||
self:getChildById('minimizeButton'):setOn(false)
|
||||
self:setHeight(self.savedHeight)
|
||||
else
|
||||
self.savedHeight = self:getHeight()
|
||||
self:setHeight(self.minimizedHeight)
|
||||
self:setOn(true)
|
||||
self:getChildById('contentsPanel'):hide()
|
||||
self:getChildById('miniwindowScrollBar'):hide()
|
||||
self:getChildById('bottomResizeBorder'):hide()
|
||||
self:getChildById('minimizeButton'):setOn(true)
|
||||
function UIMiniWindow:setSettings(data)
|
||||
local settings = 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] = value
|
||||
end
|
||||
|
||||
Settings.setNode('MiniWindows', settings)
|
||||
end
|
||||
|
||||
function UIMiniWindow:getClassName()
|
||||
return 'UIMiniWindow'
|
||||
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)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user