diff --git a/modules/corelib/widgets/uiminiwindow.lua b/modules/corelib/widgets/uiminiwindow.lua index 371a7e35..e6659342 100644 --- a/modules/corelib/widgets/uiminiwindow.lua +++ b/modules/corelib/widgets/uiminiwindow.lua @@ -75,6 +75,8 @@ function UIMiniWindow:onSetup() end end + local oldParent = self:getParent() + local settings = Settings.getNode('MiniWindows') if settings then local selfSettings = settings[self:getId()] @@ -83,6 +85,7 @@ function UIMiniWindow:onSetup() local parent = rootWidget:recursiveGetChildById(selfSettings.parentId) if parent then if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then + self.miniIndex = selfSettings.index parent:scheduleInsert(self, selfSettings.index) elseif selfSettings.position then self:setParent(parent) @@ -101,6 +104,17 @@ function UIMiniWindow:onSetup() end end end + + local newParent = self:getParent() + + self.miniLoaded = true + + if oldParent and oldParent:getClassName() == 'UIMiniWindowContainer' then + oldParent:order() + end + if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and newParent ~= oldParent then + newParent:order() + end end function UIMiniWindow:onDragEnter(mousePos) @@ -199,6 +213,8 @@ function UIMiniWindow:onFocusChange(focused) end function UIMiniWindow:setSettings(data) + if not self.save then return end + local settings = Settings.getNode('MiniWindows') if not settings then settings = {} diff --git a/modules/corelib/widgets/uiminiwindowcontainer.lua b/modules/corelib/widgets/uiminiwindowcontainer.lua index 074ebbde..c434bf0a 100644 --- a/modules/corelib/widgets/uiminiwindowcontainer.lua +++ b/modules/corelib/widgets/uiminiwindowcontainer.lua @@ -54,29 +54,46 @@ function UIMiniWindowContainer:scheduleInsert(widget, index) if oldParent ~= self then oldParent:removeChild(widget) self:insertChild(index, widget) - else - self:swapInsert(widget, index) - end - while true do - local placed = false - for nIndex,nWidget in pairs(self.scheduledWidgets) do - if nIndex - 1 <= self:getChildCount() then - self:insertChild(nIndex, nWidget) - self.scheduledWidgets[nIndex] = nil - placed = true - break + while true do + local placed = false + for nIndex,nWidget in pairs(self.scheduledWidgets) do + if nIndex - 1 <= self:getChildCount() then + self:insertChild(nIndex, nWidget) + self.scheduledWidgets[nIndex] = nil + placed = true + break + end end + if not placed then break end end - if not placed then break end + + end + end +end + +function UIMiniWindowContainer:order() + local children = self:getChildren() + for i=1,#children do + if not children[i].miniLoaded then return end + end + + for i=1,#children do + if children[i].miniIndex then + self:swapInsert(children[i], children[i].miniIndex) end end end function UIMiniWindowContainer:saveChildren() local children = self:getChildren() + local ignoreIndex = 0 for i=1,#children do - children[i]:saveParentIndex(self:getId(), i) + if children[i].save then + children[i]:saveParentIndex(self:getId(), i - ignoreIndex) + else + ignoreIndex = ignoreIndex + 1 + end end end diff --git a/modules/game_battle/battle.otui b/modules/game_battle/battle.otui index 8a6853df..e7bd547e 100644 --- a/modules/game_battle/battle.otui +++ b/modules/game_battle/battle.otui @@ -42,6 +42,7 @@ MiniWindow height: 166 icon: battle.png @onClose: Battle.onMiniWindowClose() + &save: true MiniWindowContents BattlePlayers diff --git a/modules/game_combatcontrols/combatcontrols.otui b/modules/game_combatcontrols/combatcontrols.otui index 86a51d07..74f1cf44 100644 --- a/modules/game_combatcontrols/combatcontrols.otui +++ b/modules/game_combatcontrols/combatcontrols.otui @@ -25,6 +25,7 @@ MiniWindow icon: combatcontrols.png height: 64 @onClose: CombatControls.onMiniWindowClose() + &save: true MiniWindowContents FightOffensiveBox diff --git a/modules/game_healthbar/healthbar.otui b/modules/game_healthbar/healthbar.otui index 52833477..0a11bc8e 100644 --- a/modules/game_healthbar/healthbar.otui +++ b/modules/game_healthbar/healthbar.otui @@ -46,6 +46,7 @@ MiniWindow !text: tr('Health Bar') height: 86 @onClose: HealthBar.onMiniWindowClose() + &save: true MiniWindowContents HealthBar diff --git a/modules/game_inventory/inventory.otui b/modules/game_inventory/inventory.otui index 11ec1685..05398711 100644 --- a/modules/game_inventory/inventory.otui +++ b/modules/game_inventory/inventory.otui @@ -4,6 +4,7 @@ MiniWindow icon: inventory.png height: 180 @onClose: Inventory.onMiniWindowClose() + &save: true MiniWindowContents Item diff --git a/modules/game_minimap/minimap.lua b/modules/game_minimap/minimap.lua index 0b6d6dd3..760a9d18 100644 --- a/modules/game_minimap/minimap.lua +++ b/modules/game_minimap/minimap.lua @@ -83,16 +83,19 @@ function Minimap.terminate() end function Minimap.toggle() - local visible = not minimapWindow:isExplicitlyVisible() - if visible then - minimapWindow:open() - minimapButton:setOn(true) - else + if minimapButton:isOn() then minimapWindow:close() minimapButton:setOn(false) + else + minimapWindow:open() + minimapButton:setOn(true) end end +function Minimap.onMiniWindowClose() + minimapButton:setOn(false) +end + function Minimap.reset() local player = g_game.getLocalPlayer() if not player then return end diff --git a/modules/game_minimap/minimap.otui b/modules/game_minimap/minimap.otui index a0609d11..4260a11c 100644 --- a/modules/game_minimap/minimap.otui +++ b/modules/game_minimap/minimap.otui @@ -3,6 +3,8 @@ MiniWindow !text: tr('Minimap') height: 150 icon: minimap.png + @onClose: Minimap.onMiniWindowClose() + &save: true MiniWindowContents padding: 3 diff --git a/modules/game_skills/skills.otui b/modules/game_skills/skills.otui index 9b151741..be1082b0 100644 --- a/modules/game_skills/skills.otui +++ b/modules/game_skills/skills.otui @@ -36,6 +36,7 @@ MiniWindow height: 150 icon: skills.png @onClose: Skills.onMiniWindowClose() + &save: true MiniWindowContents anchors.fill: parent diff --git a/modules/game_viplist/viplist.otui b/modules/game_viplist/viplist.otui index 359707bd..9684de27 100644 --- a/modules/game_viplist/viplist.otui +++ b/modules/game_viplist/viplist.otui @@ -9,6 +9,7 @@ MiniWindow height: 100 icon: viplist.png @onClose: VipList.onMiniWindowClose() + &save: true MiniWindowContents layout: verticalBox