1
0
Fork 0

Fix issue #21, but miniwindows can be a lot smarter

master
Henrique Santiago vor 12 Jahren
Ursprung c185e709b3
Commit 2142ee765d

@ -3,7 +3,6 @@ UIMiniWindow = extends(UIWindow)
function UIMiniWindow.create()
local miniwindow = UIMiniWindow.internalCreate()
miniwindow.isSetup = false
return miniwindow
end
@ -22,6 +21,7 @@ function UIMiniWindow:open(dontSave)
end
function UIMiniWindow:close(dontSave)
if not self:isExplicitlyVisible() then return end
self:setVisible(false)
if not dontSave then
@ -88,6 +88,7 @@ function UIMiniWindow:onSetup()
if parent then
if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then
self.miniIndex = selfSettings.index
--addEvent(function() parent:scheduleInsert(self, selfSettings.index) end)
parent:scheduleInsert(self, selfSettings.index)
elseif selfSettings.position then
self:setParent(parent)
@ -109,8 +110,6 @@ function UIMiniWindow:onSetup()
self:setHeight(selfSettings.height)
end
end
self.isSetup = true
end
local newParent = self:getParent()
@ -119,24 +118,22 @@ function UIMiniWindow:onSetup()
if self.save then
if oldParent and oldParent:getClassName() == 'UIMiniWindowContainer' then
oldParent:order()
addEvent(function() oldParent:order() end)
end
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and newParent ~= oldParent then
newParent:order()
addEvent(function() newParent:order() end)
end
end
if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and self:isVisible() then
-- not on input event, must rework
--newParent:fitAll(self)
newParent:fitAll(self)
end
end
function UIMiniWindow:onVisibilityChange(visible)
local parent = self:getParent()
if visible and parent and parent:getClassName() == 'UIMiniWindowContainer' then
-- not on input event, must rework
--parent:fitAll(self)
parent:fitAll(self)
end
end
@ -220,7 +217,6 @@ function UIMiniWindow:onMousePress()
end
function UIMiniWindow:onFocusChange(focused)
-- miniwindows only raises when its outside MiniWindowContainers
if not focused then return end
local parent = self:getParent()
if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then
@ -228,15 +224,12 @@ function UIMiniWindow:onFocusChange(focused)
end
end
function UIMiniWindow:onGeometryChange(oldRect, rect)
if self.isSetup then
self:setSettings({height = rect.height})
end
function UIMiniWindow:onHeightChange(height)
self:setSettings({height = height})
local parent = self:getParent()
if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then
-- not on input event, must rework
--parent:fitAll(self)
parent:fitAll(self)
end
end
@ -311,3 +304,13 @@ function UIMiniWindow:setContentMaximumHeight(height)
local resizeBorder = self:getChildById('bottomResizeBorder')
resizeBorder:setMaximum(minHeight + height)
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 children = self:getChildren()
for i=1,#children do
sumHeight = sumHeight + children[i]:getHeight()
if children[i]:isVisible() then
sumHeight = sumHeight + children[i]:getHeight()
end
end
local selfHeight = self:getHeight()
local selfHeight = self:getHeight() - (self:getMarginTop() + self:getMarginBottom() + self:getPaddingTop() + self:getPaddingBottom())
if sumHeight <= selfHeight then
return
end
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
for i=#children,1,-1 do
if sumHeight < selfHeight then
if sumHeight <= selfHeight then
break
end
@ -47,7 +59,7 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
-- try to remove save widget
for i=#children,1,-1 do
if sumHeight < selfHeight then
if sumHeight <= selfHeight then
break
end
@ -63,11 +75,6 @@ function UIMiniWindowContainer:fitAll(noRemoveChild)
for i=1,#removeChildren do
removeChildren[i]:close()
end
-- dont let noRemoveChild be bigger than self
if noRemoveChild:getHeight() > selfHeight - 20 then
noRemoveChild:setHeight(selfHeight - 20)
end
end
function UIMiniWindowContainer:onDrop(widget, mousePos)
@ -88,6 +95,7 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
self:addChild(widget)
end
self:fitAll(widget)
return true
end
end
@ -114,7 +122,9 @@ function UIMiniWindowContainer:scheduleInsert(widget, index)
else
local oldParent = widget:getParent()
if oldParent ~= self then
oldParent:removeChild(widget)
if oldParent then
oldParent:removeChild(widget)
end
self:insertChild(index, widget)
while true do

@ -37,23 +37,15 @@ function UIResizeBorder:onMouseMove(mousePos, mouseMoved)
if self.vertical then
local delta = mousePos.y - self:getY() - self:getHeight()/2
local parent = self:getParent()
local newsize = math.min(math.max(parent:getHeight() + delta, self.minimum), self.maximum)
self.newsize = newsize
if not self.event or self.event:isExecuted() then
self.event = addEvent(function()
parent:setHeight(self.newsize)
end)
end
local 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
local parent = self:getParent()
local newsize = math.min(math.max(parent:getWidth() + delta, self.minimum), self.maximum)
self.newsize = newsize
if not self.event or self.event:isExecuted() then
self.event = addEvent(function()
parent:setWidth(self.newsize)
end)
end
local newSize = math.min(math.max(parent:getWidth() + delta, self.minimum), self.maximum)
parent:setWidth(newSize)
signalcall(parent.onWidthChange, parent, newSize)
end
return true
end

@ -28,9 +28,9 @@ table.insert(LifeBarColors, {percentAbove = -1, color = '#4F0000' } )
function init()
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:setOn(true)
battleWindow = g_ui.loadUI('battle.otui', modules.game_interface.getRightPanel())
g_keyboard.bindKeyDown('Ctrl+B', toggle)
-- this disables scrollbar auto hiding

@ -35,10 +35,11 @@ function init()
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)
healthInfoWindow:disableResize()
healthInfoButton:setOn(true)
healthInfoWindow = g_ui.loadUI('healthinfo.otui', modules.game_interface.getRightPanel())
healthInfoWindow:disableResize()
healthBar = healthInfoWindow:recursiveGetChildById('healthBar')
manaBar = healthInfoWindow:recursiveGetChildById('manaBar')
healthLabel = healthInfoWindow:recursiveGetChildById('healthLabel')

@ -21,11 +21,12 @@ function init()
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:disableResize()
inventoryPanel = inventoryWindow:getChildById('contentsPanel')
inventoryButton = TopMenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', 'inventory.png', toggle)
inventoryButton:setOn(true)
refresh()
end

@ -24,9 +24,10 @@ function init()
onGameStart = refresh
})
skillsWindow = g_ui.loadUI('skills.otui', modules.game_interface.getRightPanel())
skillsButton = TopMenu.addRightGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', toggle)
skillsButton:setOn(true)
skillsWindow = g_ui.loadUI('skills.otui', modules.game_interface.getRightPanel())
g_keyboard.bindKeyDown('Ctrl+S', toggle)
refresh()

@ -10,9 +10,9 @@ function init()
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:setOn(true)
vipWindow = g_ui.loadUI('viplist.otui', modules.game_interface.getRightPanel())
refresh()
end

@ -449,6 +449,6 @@ UIWidgetPtr UIManager::createWidgetFromOTML(const OTMLNodePtr& widgetNode, const
} else
stdext::throw_exception(stdext::format("unable to create widget of type '%s'", widgetType));
widget->callLuaField("onSetup");
return widget;
}

@ -177,7 +177,7 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
index = index <= 0 ? (m_children.size() + index) : index-1;
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;
}
@ -504,10 +504,6 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
callLuaField("onStyleApply", styleNode->tag(), styleNode);
if(m_firstOnStyle) {
auto self = static_self_cast<UIWidget>();
g_dispatcher.addEvent([self] {
self->callLuaField("onSetup");
});
// always focus new child
if(isFocusable() && isExplicitlyVisible() && isExplicitlyEnabled())
focus();

Laden…
Abbrechen
Speichern