Browse Source

Fixes to miniwindows

Henrique Santiago 8 years ago
parent
commit
39403e612f

+ 16
- 0
modules/corelib/widgets/uiminiwindow.lua View File

@@ -75,6 +75,8 @@ function UIMiniWindow:onSetup()
75 75
       end
76 76
     end
77 77
 
78
+  local oldParent = self:getParent()
79
+
78 80
   local settings = Settings.getNode('MiniWindows')
79 81
   if settings then
80 82
     local selfSettings = settings[self:getId()]
@@ -83,6 +85,7 @@ function UIMiniWindow:onSetup()
83 85
         local parent = rootWidget:recursiveGetChildById(selfSettings.parentId)
84 86
         if parent then
85 87
           if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then
88
+            self.miniIndex = selfSettings.index
86 89
             parent:scheduleInsert(self, selfSettings.index)
87 90
           elseif selfSettings.position then
88 91
             self:setParent(parent)
@@ -101,6 +104,17 @@ function UIMiniWindow:onSetup()
101 104
       end
102 105
     end
103 106
   end
107
+
108
+  local newParent = self:getParent()
109
+
110
+  self.miniLoaded = true
111
+
112
+  if oldParent and oldParent:getClassName() == 'UIMiniWindowContainer' then
113
+    oldParent:order()
114
+  end
115
+  if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and newParent ~= oldParent then
116
+    newParent:order()
117
+  end
104 118
 end
105 119
 
106 120
 function UIMiniWindow:onDragEnter(mousePos)
@@ -199,6 +213,8 @@ function UIMiniWindow:onFocusChange(focused)
199 213
 end
200 214
 
201 215
 function UIMiniWindow:setSettings(data)
216
+  if not self.save then return end
217
+
202 218
   local settings = Settings.getNode('MiniWindows')
203 219
   if not settings then
204 220
     settings = {}

+ 30
- 13
modules/corelib/widgets/uiminiwindowcontainer.lua View File

@@ -54,29 +54,46 @@ function UIMiniWindowContainer:scheduleInsert(widget, index)
54 54
     if oldParent ~= self then
55 55
       oldParent:removeChild(widget)
56 56
       self:insertChild(index, widget)
57
-    else
58
-      self:swapInsert(widget, index)
59
-    end
60 57
 
61
-    while true do
62
-      local placed = false
63
-      for nIndex,nWidget in pairs(self.scheduledWidgets) do
64
-        if nIndex - 1 <= self:getChildCount() then
65
-          self:insertChild(nIndex, nWidget)
66
-          self.scheduledWidgets[nIndex] = nil
67
-          placed = true
68
-          break
58
+      while true do
59
+        local placed = false
60
+        for nIndex,nWidget in pairs(self.scheduledWidgets) do
61
+          if nIndex - 1 <= self:getChildCount() then
62
+            self:insertChild(nIndex, nWidget)
63
+            self.scheduledWidgets[nIndex] = nil
64
+            placed = true
65
+            break
66
+          end
69 67
         end
68
+        if not placed then break end
70 69
       end
71
-      if not placed then break end
70
+
71
+    end
72
+  end
73
+end
74
+
75
+function UIMiniWindowContainer:order()
76
+  local children = self:getChildren()
77
+  for i=1,#children do
78
+    if not children[i].miniLoaded then return end
79
+  end
80
+
81
+  for i=1,#children do
82
+    if children[i].miniIndex then
83
+      self:swapInsert(children[i], children[i].miniIndex)
72 84
     end
73 85
   end
74 86
 end
75 87
 
76 88
 function UIMiniWindowContainer:saveChildren()
77 89
   local children = self:getChildren()
90
+  local ignoreIndex = 0
78 91
   for i=1,#children do
79
-    children[i]:saveParentIndex(self:getId(), i)
92
+    if children[i].save then
93
+      children[i]:saveParentIndex(self:getId(), i - ignoreIndex)
94
+    else
95
+      ignoreIndex = ignoreIndex + 1
96
+    end
80 97
   end
81 98
 end
82 99
 

+ 1
- 0
modules/game_battle/battle.otui View File

@@ -42,6 +42,7 @@ MiniWindow
42 42
   height: 166
43 43
   icon: battle.png
44 44
   @onClose: Battle.onMiniWindowClose()
45
+  &save: true
45 46
 
46 47
   MiniWindowContents
47 48
     BattlePlayers

+ 1
- 0
modules/game_combatcontrols/combatcontrols.otui View File

@@ -25,6 +25,7 @@ MiniWindow
25 25
   icon: combatcontrols.png
26 26
   height: 64
27 27
   @onClose: CombatControls.onMiniWindowClose()
28
+  &save: true
28 29
 
29 30
   MiniWindowContents
30 31
     FightOffensiveBox

+ 1
- 0
modules/game_healthbar/healthbar.otui View File

@@ -46,6 +46,7 @@ MiniWindow
46 46
   !text: tr('Health Bar')
47 47
   height: 86
48 48
   @onClose: HealthBar.onMiniWindowClose()
49
+  &save: true
49 50
 
50 51
   MiniWindowContents
51 52
     HealthBar

+ 1
- 0
modules/game_inventory/inventory.otui View File

@@ -4,6 +4,7 @@ MiniWindow
4 4
   icon: inventory.png
5 5
   height: 180
6 6
   @onClose: Inventory.onMiniWindowClose()
7
+  &save: true
7 8
 
8 9
   MiniWindowContents
9 10
     Item

+ 8
- 5
modules/game_minimap/minimap.lua View File

@@ -83,16 +83,19 @@ function Minimap.terminate()
83 83
 end
84 84
 
85 85
 function Minimap.toggle()
86
-  local visible = not minimapWindow:isExplicitlyVisible()
87
-  if visible then
88
-    minimapWindow:open()
89
-    minimapButton:setOn(true)
90
-  else
86
+  if minimapButton:isOn() then
91 87
     minimapWindow:close()
92 88
     minimapButton:setOn(false)
89
+  else
90
+    minimapWindow:open()
91
+    minimapButton:setOn(true)
93 92
   end
94 93
 end
95 94
 
95
+function Minimap.onMiniWindowClose()
96
+  minimapButton:setOn(false)
97
+end
98
+
96 99
 function Minimap.reset()
97 100
   local player = g_game.getLocalPlayer()
98 101
   if not player then return end

+ 2
- 0
modules/game_minimap/minimap.otui View File

@@ -3,6 +3,8 @@ MiniWindow
3 3
   !text: tr('Minimap')
4 4
   height: 150
5 5
   icon: minimap.png
6
+  @onClose: Minimap.onMiniWindowClose()
7
+  &save: true
6 8
 
7 9
   MiniWindowContents
8 10
     padding: 3

+ 1
- 0
modules/game_skills/skills.otui View File

@@ -36,6 +36,7 @@ MiniWindow
36 36
   height: 150
37 37
   icon: skills.png
38 38
   @onClose: Skills.onMiniWindowClose()
39
+  &save: true
39 40
 
40 41
   MiniWindowContents
41 42
     anchors.fill: parent

+ 1
- 0
modules/game_viplist/viplist.otui View File

@@ -9,6 +9,7 @@ MiniWindow
9 9
   height: 100
10 10
   icon: viplist.png
11 11
   @onClose: VipList.onMiniWindowClose()
12
+  &save: true
12 13
 
13 14
   MiniWindowContents
14 15
     layout: verticalBox

Loading…
Cancel
Save