From 8d89d1194a53b74b0e405c051fcb49093e391670 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Tue, 21 Aug 2012 18:40:47 -0300 Subject: [PATCH] More fixes to miniwindow --- modules/corelib/ui/uiminiwindow.lua | 40 +++++++++++++------ modules/corelib/ui/uiminiwindowcontainer.lua | 2 +- modules/corelib/ui/uiresizeborder.lua | 2 - modules/game_battle/battle.lua | 1 + .../game_combatcontrols/combatcontrols.lua | 2 + modules/game_containers/containers.lua | 2 + modules/game_healthinfo/healthinfo.lua | 2 + modules/game_interface/gameinterface.lua | 1 - modules/game_inventory/inventory.lua | 1 + modules/game_minimap/minimap.lua | 1 + modules/game_skills/skills.lua | 1 + modules/game_viplist/viplist.lua | 1 + 12 files changed, 39 insertions(+), 17 deletions(-) diff --git a/modules/corelib/ui/uiminiwindow.lua b/modules/corelib/ui/uiminiwindow.lua index 7e11f8f3..748f88b4 100644 --- a/modules/corelib/ui/uiminiwindow.lua +++ b/modules/corelib/ui/uiminiwindow.lua @@ -66,7 +66,7 @@ function UIMiniWindow:maximize(dontSave) signalcall(self.onMaximize, self) end -function UIMiniWindow:onSetup() +function UIMiniWindow:setup() self:getChildById('closeButton').onClick = function() self:close() @@ -126,16 +126,11 @@ function UIMiniWindow:onSetup() end end - if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and self:isVisible() then - newParent:fitAll(self) - end + self:fitOnParent() end function UIMiniWindow:onVisibilityChange(visible) - local parent = self:getParent() - if visible and parent and parent:getClassName() == 'UIMiniWindowContainer' then - parent:fitAll(self) - end + self:fitOnParent() end function UIMiniWindow:onDragEnter(mousePos) @@ -227,11 +222,7 @@ end function UIMiniWindow:onHeightChange(height) self:setSettings({height = height}) - - local parent = self:getParent() - if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then - parent:fitAll(self) - end + self:fitOnParent() end function UIMiniWindow:getSettings(name) @@ -295,6 +286,24 @@ function UIMiniWindow:disableResize() self:getChildById('bottomResizeBorder'):disable() end +function UIMiniWindow:fitOnParent() + local parent = self:getParent() + if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then + parent:fitAll(self) + end +end + +function UIMiniWindow:setParent(parent) + UIWidget.setParent(self, parent) + self:saveParent(parent) + self:fitOnParent() +end + +function UIMiniWindow:setHeight(height) + UIWidget.setHeight(self, height) + signalcall(self.onHeightChange, self, height) +end + function UIMiniWindow:setContentHeight(height) local contentsPanel = self:getChildById('contentsPanel') local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom() @@ -328,3 +337,8 @@ function UIMiniWindow:getMaximumHeight() local resizeBorder = self:getChildById('bottomResizeBorder') return resizeBorder:getMaximum() end + +function UIMiniWindow:isResizeable() + local resizeBorder = self:getChildById('bottomResizeBorder') + return resizeBorder:isVisible() and resizeBorder:isEnabled() +end diff --git a/modules/corelib/ui/uiminiwindowcontainer.lua b/modules/corelib/ui/uiminiwindowcontainer.lua index 13f27c75..b6c22cac 100644 --- a/modules/corelib/ui/uiminiwindowcontainer.lua +++ b/modules/corelib/ui/uiminiwindowcontainer.lua @@ -35,7 +35,7 @@ function UIMiniWindowContainer:fitAll(noRemoveChild) -- try to resize noRemoveChild local maximumHeight = selfHeight - (sumHeight - noRemoveChild:getHeight()) - if noRemoveChild:getMinimumHeight() <= maximumHeight then + if noRemoveChild:isResizeable() and noRemoveChild:getMinimumHeight() <= maximumHeight then sumHeight = sumHeight - noRemoveChild:getHeight() + maximumHeight addEvent(function() noRemoveChild:setHeight(maximumHeight) end) end diff --git a/modules/corelib/ui/uiresizeborder.lua b/modules/corelib/ui/uiresizeborder.lua index 50f33e7c..4a747499 100644 --- a/modules/corelib/ui/uiresizeborder.lua +++ b/modules/corelib/ui/uiresizeborder.lua @@ -48,12 +48,10 @@ function UIResizeBorder:onMouseMove(mousePos, mouseMoved) local delta = mousePos.y - self:getY() - self:getHeight()/2 newSize = math.min(math.max(parent:getHeight() + delta, self.minimum), self.maximum) parent:setHeight(newSize) - signalcall(parent.onHeightChange, parent, newSize) else local delta = mousePos.x - self:getX() - self:getWidth()/2 newSize = math.min(math.max(parent:getWidth() + delta, self.minimum), self.maximum) parent:setWidth(newSize) - signalcall(parent.onWidthChange, parent, newSize) end self:checkBoundary(newSize) diff --git a/modules/game_battle/battle.lua b/modules/game_battle/battle.lua index 5480ad14..bbf0795b 100644 --- a/modules/game_battle/battle.lua +++ b/modules/game_battle/battle.lua @@ -65,6 +65,7 @@ function init() onGameEnd = removeAllCreatures } ) checkCreatures() + battleWindow:setup() end function terminate() diff --git a/modules/game_combatcontrols/combatcontrols.lua b/modules/game_combatcontrols/combatcontrols.lua index 9acd6c37..051db4ed 100644 --- a/modules/game_combatcontrols/combatcontrols.lua +++ b/modules/game_combatcontrols/combatcontrols.lua @@ -40,6 +40,8 @@ function init() if g_game.isOnline() then online() end + + combatControlsWindow:setup() end function terminate() diff --git a/modules/game_containers/containers.lua b/modules/game_containers/containers.lua index 1e1031f5..bd0bd923 100644 --- a/modules/game_containers/containers.lua +++ b/modules/game_containers/containers.lua @@ -98,6 +98,8 @@ function onContainerOpen(container, previousContainer) local filledLines = math.max(math.ceil(container:getItemsCount() / layout:getNumColumns()), 1) containerWindow:setContentHeight(filledLines*cellSize.height) end + + containerWindow:setup() end function onContainerClose(container) diff --git a/modules/game_healthinfo/healthinfo.lua b/modules/game_healthinfo/healthinfo.lua index b4307f9e..51054f1e 100644 --- a/modules/game_healthinfo/healthinfo.lua +++ b/modules/game_healthinfo/healthinfo.lua @@ -56,6 +56,8 @@ function init() onSoulChange(localPlayer, localPlayer:getSoul()) onFreeCapacityChange(localPlayer, localPlayer:getFreeCapacity()) end + + healthInfoWindow:setup() end function terminate() diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index e2fc546d..7af75deb 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -486,7 +486,6 @@ function onLeftPanelVisibilityChange(leftPanel, visible) local children = leftPanel:getChildren() for i=1,#children do children[i]:setParent(gameRightPanel) - children[i]:saveParent(gameRightPanel) end end end diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index 119f4de2..e23c4db5 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -29,6 +29,7 @@ function init() inventoryPanel = inventoryWindow:getChildById('contentsPanel') refresh() + inventoryWindow:setup() end function terminate() diff --git a/modules/game_minimap/minimap.lua b/modules/game_minimap/minimap.lua index 3e4ea5bb..d768a524 100644 --- a/modules/game_minimap/minimap.lua +++ b/modules/game_minimap/minimap.lua @@ -40,6 +40,7 @@ function init() minimapWidget.onMouseWheel = onMinimapMouseWheel reset() + minimapWindow:setup() end function terminate() diff --git a/modules/game_skills/skills.lua b/modules/game_skills/skills.lua index 3369abd3..a70778ae 100644 --- a/modules/game_skills/skills.lua +++ b/modules/game_skills/skills.lua @@ -31,6 +31,7 @@ function init() g_keyboard.bindKeyDown('Ctrl+S', toggle) refresh() + skillsWindow:setup() end function terminate() diff --git a/modules/game_viplist/viplist.lua b/modules/game_viplist/viplist.lua index e732a334..9035544d 100644 --- a/modules/game_viplist/viplist.lua +++ b/modules/game_viplist/viplist.lua @@ -15,6 +15,7 @@ function init() vipWindow = g_ui.loadUI('viplist.otui', modules.game_interface.getRightPanel()) refresh() + vipWindow:setup() end function terminate()