Fix issue #21, but miniwindows can be a lot smarter
This commit is contained in:
parent
c185e709b3
commit
2142ee765d
|
@ -3,7 +3,6 @@ UIMiniWindow = extends(UIWindow)
|
||||||
|
|
||||||
function UIMiniWindow.create()
|
function UIMiniWindow.create()
|
||||||
local miniwindow = UIMiniWindow.internalCreate()
|
local miniwindow = UIMiniWindow.internalCreate()
|
||||||
miniwindow.isSetup = false
|
|
||||||
return miniwindow
|
return miniwindow
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,6 +21,7 @@ function UIMiniWindow:open(dontSave)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMiniWindow:close(dontSave)
|
function UIMiniWindow:close(dontSave)
|
||||||
|
if not self:isExplicitlyVisible() then return end
|
||||||
self:setVisible(false)
|
self:setVisible(false)
|
||||||
|
|
||||||
if not dontSave then
|
if not dontSave then
|
||||||
|
@ -88,6 +88,7 @@ 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)
|
||||||
|
@ -109,8 +110,6 @@ function UIMiniWindow:onSetup()
|
||||||
self:setHeight(selfSettings.height)
|
self:setHeight(selfSettings.height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.isSetup = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local newParent = self:getParent()
|
local newParent = self:getParent()
|
||||||
|
@ -119,24 +118,22 @@ function UIMiniWindow:onSetup()
|
||||||
|
|
||||||
if self.save then
|
if self.save then
|
||||||
if oldParent and oldParent:getClassName() == 'UIMiniWindowContainer' then
|
if oldParent and oldParent:getClassName() == 'UIMiniWindowContainer' then
|
||||||
oldParent:order()
|
addEvent(function() oldParent:order() end)
|
||||||
end
|
end
|
||||||
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and newParent ~= oldParent then
|
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and newParent ~= oldParent then
|
||||||
newParent:order()
|
addEvent(function() newParent:order() end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and self:isVisible() then
|
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and self:isVisible() then
|
||||||
-- not on input event, must rework
|
newParent:fitAll(self)
|
||||||
--newParent:fitAll(self)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMiniWindow:onVisibilityChange(visible)
|
function UIMiniWindow:onVisibilityChange(visible)
|
||||||
local parent = self:getParent()
|
local parent = self:getParent()
|
||||||
if visible and parent and parent:getClassName() == 'UIMiniWindowContainer' then
|
if visible and parent and parent:getClassName() == 'UIMiniWindowContainer' then
|
||||||
-- not on input event, must rework
|
parent:fitAll(self)
|
||||||
--parent:fitAll(self)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -220,7 +217,6 @@ function UIMiniWindow:onMousePress()
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMiniWindow:onFocusChange(focused)
|
function UIMiniWindow:onFocusChange(focused)
|
||||||
-- miniwindows only raises when its outside MiniWindowContainers
|
|
||||||
if not focused then return end
|
if not focused then return end
|
||||||
local parent = self:getParent()
|
local parent = self:getParent()
|
||||||
if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then
|
if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then
|
||||||
|
@ -228,15 +224,12 @@ function UIMiniWindow:onFocusChange(focused)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMiniWindow:onGeometryChange(oldRect, rect)
|
function UIMiniWindow:onHeightChange(height)
|
||||||
if self.isSetup then
|
self:setSettings({height = height})
|
||||||
self:setSettings({height = rect.height})
|
|
||||||
end
|
|
||||||
|
|
||||||
local parent = self:getParent()
|
local parent = self:getParent()
|
||||||
if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then
|
if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then
|
||||||
-- not on input event, must rework
|
parent:fitAll(self)
|
||||||
--parent:fitAll(self)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -311,3 +304,13 @@ function UIMiniWindow:setContentMaximumHeight(height)
|
||||||
local resizeBorder = self:getChildById('bottomResizeBorder')
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
||||||
resizeBorder:setMaximum(minHeight + height)
|
resizeBorder:setMaximum(minHeight + height)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UIMiniWindow:getMinimumHeight()
|
||||||
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
||||||
|
return resizeBorder:getMinimum()
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIMiniWindow:getMaximumHeight()
|
||||||
|
local resizeBorder = self:getChildById('bottomResizeBorder')
|
||||||
|
return resizeBorder:getMaximum()
|
||||||
|
end
|
||||||
|
|
|
@ -21,19 +21,31 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
|
||||||
local sumHeight = 0
|
local sumHeight = 0
|
||||||
local children = self:getChildren()
|
local children = self:getChildren()
|
||||||
for i=1,#children do
|
for i=1,#children do
|
||||||
|
if children[i]:isVisible() then
|
||||||
sumHeight = sumHeight + children[i]:getHeight()
|
sumHeight = sumHeight + children[i]:getHeight()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local selfHeight = self:getHeight()
|
local selfHeight = self:getHeight() - (self:getMarginTop() + self:getMarginBottom() + self:getPaddingTop() + self:getPaddingBottom())
|
||||||
if sumHeight <= selfHeight then
|
if sumHeight <= selfHeight then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local removeChildren = {}
|
local removeChildren = {}
|
||||||
|
|
||||||
|
-- try to resize noRemoveChild
|
||||||
|
local maximumHeight = selfHeight - (sumHeight - noRemoveChild:getHeight())
|
||||||
|
if noRemoveChild:getMinimumHeight() <= maximumHeight then
|
||||||
|
sumHeight = sumHeight - noRemoveChild:getHeight() + maximumHeight
|
||||||
|
addEvent(function() noRemoveChild:setHeight(maximumHeight) end)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: try to resize another widget?
|
||||||
|
-- TODO: try to find another panel?
|
||||||
|
|
||||||
-- try to remove no-save widget
|
-- try to remove no-save widget
|
||||||
for i=#children,1,-1 do
|
for i=#children,1,-1 do
|
||||||
if sumHeight < selfHeight then
|
if sumHeight <= selfHeight then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,7 +59,7 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
|
||||||
|
|
||||||
-- try to remove save widget
|
-- try to remove save widget
|
||||||
for i=#children,1,-1 do
|
for i=#children,1,-1 do
|
||||||
if sumHeight < selfHeight then
|
if sumHeight <= selfHeight then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,11 +75,6 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
|
||||||
for i=1,#removeChildren do
|
for i=1,#removeChildren do
|
||||||
removeChildren[i]:close()
|
removeChildren[i]:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- dont let noRemoveChild be bigger than self
|
|
||||||
if noRemoveChild:getHeight() > selfHeight - 20 then
|
|
||||||
noRemoveChild:setHeight(selfHeight - 20)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMiniWindowContainer:onDrop(widget, mousePos)
|
function UIMiniWindowContainer:onDrop(widget, mousePos)
|
||||||
|
@ -88,6 +95,7 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
|
||||||
self:addChild(widget)
|
self:addChild(widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:fitAll(widget)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -114,7 +122,9 @@ function UIMiniWindowContainer:scheduleInsert(widget, index)
|
||||||
else
|
else
|
||||||
local oldParent = widget:getParent()
|
local oldParent = widget:getParent()
|
||||||
if oldParent ~= self then
|
if oldParent ~= self then
|
||||||
|
if oldParent then
|
||||||
oldParent:removeChild(widget)
|
oldParent:removeChild(widget)
|
||||||
|
end
|
||||||
self:insertChild(index, widget)
|
self:insertChild(index, widget)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
|
|
@ -37,23 +37,15 @@ function UIResizeBorder:onMouseMove(mousePos, mouseMoved)
|
||||||
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()
|
local parent = self:getParent()
|
||||||
local 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)
|
||||||
self.newsize = newsize
|
parent:setHeight(newSize)
|
||||||
if not self.event or self.event:isExecuted() then
|
signalcall(parent.onHeightChange, parent, newSize)
|
||||||
self.event = addEvent(function()
|
|
||||||
parent:setHeight(self.newsize)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
local delta = mousePos.x - self:getX() - self:getWidth()/2
|
local delta = mousePos.x - self:getX() - self:getWidth()/2
|
||||||
local parent = self:getParent()
|
local parent = self:getParent()
|
||||||
local 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)
|
||||||
self.newsize = newsize
|
parent:setWidth(newSize)
|
||||||
if not self.event or self.event:isExecuted() then
|
signalcall(parent.onWidthChange, parent, newSize)
|
||||||
self.event = addEvent(function()
|
|
||||||
parent:setWidth(self.newsize)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,9 +28,9 @@ table.insert(LifeBarColors, {percentAbove = -1, color = '#4F0000' } )
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
g_ui.importStyle('battlebutton.otui')
|
g_ui.importStyle('battlebutton.otui')
|
||||||
battleWindow = g_ui.loadUI('battle.otui', modules.game_interface.getRightPanel())
|
|
||||||
battleButton = TopMenu.addRightGameToggleButton('battleButton', tr('Battle') .. ' (Ctrl+B)', 'battle.png', toggle)
|
battleButton = TopMenu.addRightGameToggleButton('battleButton', tr('Battle') .. ' (Ctrl+B)', 'battle.png', toggle)
|
||||||
battleButton:setOn(true)
|
battleButton:setOn(true)
|
||||||
|
battleWindow = g_ui.loadUI('battle.otui', modules.game_interface.getRightPanel())
|
||||||
g_keyboard.bindKeyDown('Ctrl+B', toggle)
|
g_keyboard.bindKeyDown('Ctrl+B', toggle)
|
||||||
|
|
||||||
-- this disables scrollbar auto hiding
|
-- this disables scrollbar auto hiding
|
||||||
|
|
|
@ -35,10 +35,11 @@ function init()
|
||||||
|
|
||||||
connect(g_game, { onGameEnd = offline })
|
connect(g_game, { onGameEnd = offline })
|
||||||
|
|
||||||
healthInfoWindow = g_ui.loadUI('healthinfo.otui', modules.game_interface.getRightPanel())
|
|
||||||
healthInfoButton = TopMenu.addRightGameToggleButton('healthInfoButton', tr('Health Information'), 'healthinfo.png', toggle)
|
healthInfoButton = TopMenu.addRightGameToggleButton('healthInfoButton', tr('Health Information'), 'healthinfo.png', toggle)
|
||||||
healthInfoWindow:disableResize()
|
|
||||||
healthInfoButton:setOn(true)
|
healthInfoButton:setOn(true)
|
||||||
|
|
||||||
|
healthInfoWindow = g_ui.loadUI('healthinfo.otui', modules.game_interface.getRightPanel())
|
||||||
|
healthInfoWindow:disableResize()
|
||||||
healthBar = healthInfoWindow:recursiveGetChildById('healthBar')
|
healthBar = healthInfoWindow:recursiveGetChildById('healthBar')
|
||||||
manaBar = healthInfoWindow:recursiveGetChildById('manaBar')
|
manaBar = healthInfoWindow:recursiveGetChildById('manaBar')
|
||||||
healthLabel = healthInfoWindow:recursiveGetChildById('healthLabel')
|
healthLabel = healthInfoWindow:recursiveGetChildById('healthLabel')
|
||||||
|
|
|
@ -21,11 +21,12 @@ function init()
|
||||||
|
|
||||||
g_keyboard.bindKeyDown('Ctrl+I', toggle)
|
g_keyboard.bindKeyDown('Ctrl+I', toggle)
|
||||||
|
|
||||||
|
inventoryButton = TopMenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', 'inventory.png', toggle)
|
||||||
|
inventoryButton:setOn(true)
|
||||||
|
|
||||||
inventoryWindow = g_ui.loadUI('inventory.otui', modules.game_interface.getRightPanel())
|
inventoryWindow = g_ui.loadUI('inventory.otui', modules.game_interface.getRightPanel())
|
||||||
inventoryWindow:disableResize()
|
inventoryWindow:disableResize()
|
||||||
inventoryPanel = inventoryWindow:getChildById('contentsPanel')
|
inventoryPanel = inventoryWindow:getChildById('contentsPanel')
|
||||||
inventoryButton = TopMenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', 'inventory.png', toggle)
|
|
||||||
inventoryButton:setOn(true)
|
|
||||||
|
|
||||||
refresh()
|
refresh()
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,9 +24,10 @@ function init()
|
||||||
onGameStart = refresh
|
onGameStart = refresh
|
||||||
})
|
})
|
||||||
|
|
||||||
skillsWindow = g_ui.loadUI('skills.otui', modules.game_interface.getRightPanel())
|
|
||||||
skillsButton = TopMenu.addRightGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', toggle)
|
skillsButton = TopMenu.addRightGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', toggle)
|
||||||
skillsButton:setOn(true)
|
skillsButton:setOn(true)
|
||||||
|
skillsWindow = g_ui.loadUI('skills.otui', modules.game_interface.getRightPanel())
|
||||||
|
|
||||||
g_keyboard.bindKeyDown('Ctrl+S', toggle)
|
g_keyboard.bindKeyDown('Ctrl+S', toggle)
|
||||||
|
|
||||||
refresh()
|
refresh()
|
||||||
|
|
|
@ -10,9 +10,9 @@ function init()
|
||||||
|
|
||||||
g_keyboard.bindKeyDown('Ctrl+P', toggle)
|
g_keyboard.bindKeyDown('Ctrl+P', toggle)
|
||||||
|
|
||||||
vipWindow = g_ui.loadUI('viplist.otui', modules.game_interface.getRightPanel())
|
|
||||||
vipButton = TopMenu.addRightGameToggleButton('vipListButton', tr('VIP list') .. ' (Ctrl+P)', 'viplist.png', toggle)
|
vipButton = TopMenu.addRightGameToggleButton('vipListButton', tr('VIP list') .. ' (Ctrl+P)', 'viplist.png', toggle)
|
||||||
vipButton:setOn(true)
|
vipButton:setOn(true)
|
||||||
|
vipWindow = g_ui.loadUI('viplist.otui', modules.game_interface.getRightPanel())
|
||||||
|
|
||||||
refresh()
|
refresh()
|
||||||
end
|
end
|
||||||
|
|
|
@ -449,6 +449,6 @@ UIWidgetPtr UIManager::createWidgetFromOTML(const OTMLNodePtr& widgetNode, const
|
||||||
} else
|
} else
|
||||||
stdext::throw_exception(stdext::format("unable to create widget of type '%s'", widgetType));
|
stdext::throw_exception(stdext::format("unable to create widget of type '%s'", widgetType));
|
||||||
|
|
||||||
|
widget->callLuaField("onSetup");
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
|
||||||
index = index <= 0 ? (m_children.size() + index) : index-1;
|
index = index <= 0 ? (m_children.size() + index) : index-1;
|
||||||
|
|
||||||
if(!(index >= 0 && (uint)index <= m_children.size())) {
|
if(!(index >= 0 && (uint)index <= m_children.size())) {
|
||||||
g_logger.traceError("attemp to insert a child in an invalid index");
|
g_logger.traceError("attempt to insert a child in an invalid index");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,10 +504,6 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
|
||||||
callLuaField("onStyleApply", styleNode->tag(), styleNode);
|
callLuaField("onStyleApply", styleNode->tag(), styleNode);
|
||||||
|
|
||||||
if(m_firstOnStyle) {
|
if(m_firstOnStyle) {
|
||||||
auto self = static_self_cast<UIWidget>();
|
|
||||||
g_dispatcher.addEvent([self] {
|
|
||||||
self->callLuaField("onSetup");
|
|
||||||
});
|
|
||||||
// always focus new child
|
// always focus new child
|
||||||
if(isFocusable() && isExplicitlyVisible() && isExplicitlyEnabled())
|
if(isFocusable() && isExplicitlyVisible() && isExplicitlyEnabled())
|
||||||
focus();
|
focus();
|
||||||
|
|
Loading…
Reference in New Issue