Fixed issue #79 and some miniwindows bugs

This commit is contained in:
Henrique Santiago 2012-08-21 17:27:44 -03:00
parent ea4dd2f8e6
commit f27f005757
4 changed files with 68 additions and 33 deletions

View File

@ -37,7 +37,6 @@ function UIMiniWindow:minimize(dontSave)
self:getChildById('miniwindowScrollBar'):hide() self:getChildById('miniwindowScrollBar'):hide()
self:getChildById('bottomResizeBorder'):hide() self:getChildById('bottomResizeBorder'):hide()
self:getChildById('minimizeButton'):setOn(true) self:getChildById('minimizeButton'):setOn(true)
self.savedHeight = self:getHeight()
self:setHeight(self.minimizedHeight) self:setHeight(self.minimizedHeight)
if not dontSave then if not dontSave then
@ -53,12 +52,17 @@ function UIMiniWindow:maximize(dontSave)
self:getChildById('miniwindowScrollBar'):show() self:getChildById('miniwindowScrollBar'):show()
self:getChildById('bottomResizeBorder'):show() self:getChildById('bottomResizeBorder'):show()
self:getChildById('minimizeButton'):setOn(false) self:getChildById('minimizeButton'):setOn(false)
self:setHeight(self.savedHeight) self:setHeight(self:getSettings('height'))
if not dontSave then if not dontSave then
self:setSettings({minimized = false}) self:setSettings({minimized = false})
end end
local parent = self:getParent()
if parent and parent:getClassName() == 'UIMiniWindowContainer' then
parent:fitAll(self)
end
signalcall(self.onMaximize, self) signalcall(self.onMaximize, self)
end end
@ -88,7 +92,6 @@ function UIMiniWindow:onSetup()
if parent then if parent then
if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then
self.miniIndex = selfSettings.index self.miniIndex = selfSettings.index
--addEvent(function() parent:scheduleInsert(self, selfSettings.index) end)
parent:scheduleInsert(self, selfSettings.index) parent:scheduleInsert(self, selfSettings.index)
elseif selfSettings.position then elseif selfSettings.position then
self:setParent(parent) self:setParent(parent)
@ -100,15 +103,13 @@ function UIMiniWindow:onSetup()
if selfSettings.minimized then if selfSettings.minimized then
self:minimize(true) self:minimize(true)
elseif selfSettings.height then
self:setHeight(selfSettings.height)
end end
if selfSettings.closed then if selfSettings.closed then
self:close(true) self:close(true)
end end
if selfSettings.height then
self:setHeight(selfSettings.height)
end
end end
end end
@ -233,6 +234,17 @@ function UIMiniWindow:onHeightChange(height)
end end
end end
function UIMiniWindow:getSettings(name)
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
function UIMiniWindow:setSettings(data) function UIMiniWindow:setSettings(data)
if not self.save then return end if not self.save then return end
@ -286,7 +298,9 @@ end
function UIMiniWindow:setContentHeight(height) function UIMiniWindow:setContentHeight(height)
local contentsPanel = self:getChildById('contentsPanel') local contentsPanel = self:getChildById('contentsPanel')
local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom() local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom()
self:setHeight(minHeight + height)
local resizeBorder = self:getChildById('bottomResizeBorder')
resizeBorder:setParentSize(minHeight + height)
end end
function UIMiniWindow:setContentMinimumHeight(height) function UIMiniWindow:setContentMinimumHeight(height)

View File

@ -40,6 +40,7 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
addEvent(function() noRemoveChild:setHeight(maximumHeight) end) addEvent(function() noRemoveChild:setHeight(maximumHeight) end)
end end
-- TODO: most likely, minimum and maximum size are not set yet, so code above might not work properly. onSetup event
-- TODO: try to resize another widget? -- TODO: try to resize another widget?
-- TODO: try to find another panel? -- TODO: try to find another panel?

View File

@ -9,6 +9,14 @@ function UIResizeBorder.create()
return resizeborder return resizeborder
end end
function UIResizeBorder:onSetup()
if self:getWidth() > self:getHeight() then
self.vertical = true
else
self.vertical = false
end
end
function UIResizeBorder:onHoverChange(hovered) function UIResizeBorder:onHoverChange(hovered)
if hovered then if hovered then
if g_mouse.isCursorChanged() or g_mouse.isPressed() then return end if g_mouse.isCursorChanged() or g_mouse.isPressed() then return end
@ -34,19 +42,21 @@ end
function UIResizeBorder:onMouseMove(mousePos, mouseMoved) function UIResizeBorder:onMouseMove(mousePos, mouseMoved)
if self:isPressed() then if self:isPressed() then
local parent = self:getParent()
local newSize = 0
if self.vertical then if self.vertical then
local delta = mousePos.y - self:getY() - self:getHeight()/2 local delta = mousePos.y - self:getY() - self:getHeight()/2
local parent = self:getParent() newSize = math.min(math.max(parent:getHeight() + delta, self.minimum), self.maximum)
local newSize = math.min(math.max(parent:getHeight() + delta, self.minimum), self.maximum)
parent:setHeight(newSize) parent:setHeight(newSize)
signalcall(parent.onHeightChange, parent, newSize) signalcall(parent.onHeightChange, parent, newSize)
else else
local delta = mousePos.x - self:getX() - self:getWidth()/2 local delta = mousePos.x - self:getX() - self:getWidth()/2
local parent = self:getParent() newSize = math.min(math.max(parent:getWidth() + delta, self.minimum), self.maximum)
local newSize = math.min(math.max(parent:getWidth() + delta, self.minimum), self.maximum)
parent:setWidth(newSize) parent:setWidth(newSize)
signalcall(parent.onWidthChange, parent, newSize) signalcall(parent.onWidthChange, parent, newSize)
end end
self:checkBoundary(newSize)
return true return true
end end
end end
@ -77,27 +87,41 @@ end
function UIResizeBorder:setMaximum(maximum) function UIResizeBorder:setMaximum(maximum)
self.maximum = maximum self.maximum = maximum
if self.maximum == self.minimum then self:checkBoundary()
self:hide()
end
local parent = self:getParent()
if self:isVisible() and parent:getHeight() > maximum then
parent:setHeight(maximum)
end
end end
function UIResizeBorder:setMinimum(minimum) function UIResizeBorder:setMinimum(minimum)
self.minimum = minimum self.minimum = minimum
if self.maximum == self.minimum then self:checkBoundary()
self:hide()
end
local parent = self:getParent()
if self:isVisible() and parent:getHeight() < minimum then
parent:setHeight(minimum)
end
end end
function UIResizeBorder:getMaximum() return self.maximum end function UIResizeBorder:getMaximum() return self.maximum end
function UIResizeBorder:getMinimum() return self.minimum end function UIResizeBorder:getMinimum() return self.minimum end
function UIResizeBorder:setParentSize(size)
local parent = self:getParent()
if self.vertical then
parent:setHeight(size)
else
parent:setWidth(size)
end
self:checkBoundary(size)
end
function UIResizeBorder:getParentSize()
local parent = self:getParent()
if self.vertical then
return parent:getHeight()
else
return parent:getWidth()
end
end
function UIResizeBorder:checkBoundary(size)
size = size or self:getParentSize()
if self.maximum == self.minimum and size == self.maximum then
self:hide()
else
self:show()
end
end

View File

@ -7,10 +7,6 @@ LoginServerUpdateNeeded = 30
LoginServerCharacterList = 100 LoginServerCharacterList = 100
function ProtocolLogin:login(host, port, accountName, accountPassword) function ProtocolLogin:login(host, port, accountName, accountPassword)
if string.len(accountName) == 0 or string.len(accountPassword) == 0 then
signalcall(self.onError, self, tr("You must enter an account name and password."))
return
end
if string.len(host) == 0 or port == nil or port == 0 then if string.len(host) == 0 or port == nil or port == 0 then
signalcall(self.onError, self, tr("You must enter a valid server address and port.")) signalcall(self.onError, self, tr("You must enter a valid server address and port."))
return return