Browse Source

Save miniwindows states

Henrique Santiago 8 years ago
parent
commit
a7c17cec2e

+ 4
- 0
modules/client_options/general.otui View File

@@ -34,3 +34,7 @@ Panel
34 34
   OptionCheckBox
35 35
     id: enableMusic
36 36
     !text: tr('Enable music')
37
+
38
+  OptionCheckBox
39
+    id: showLeftPanel
40
+    !text: tr('Show left panel')

+ 6
- 1
modules/client_options/options.lua View File

@@ -14,7 +14,8 @@ local options = { vsync = false,
14 14
                   showLevelsInConsole = true,
15 15
                   showPrivateMessagesInConsole = false,
16 16
                   showPrivateMessagesOnScreen = true,
17
-                  enableMusic = true }
17
+                  enableMusic = true,
18
+                  showLeftPanel = false }
18 19
 local generalPanel
19 20
 local graphicsPanel
20 21
 
@@ -129,6 +130,10 @@ function Options.setOption(key, value)
129 130
     addEvent(function()
130 131
       g_sounds.enableMusic(value)
131 132
     end)
133
+  elseif key == 'showLeftPanel' then
134
+    addEvent(function()
135
+      GameInterface.getLeftPanel():setOn(value)
136
+    end)
132 137
   end
133 138
   Settings.set(key, value)
134 139
   options[key] = value

+ 1
- 1
modules/client_options/options.otui View File

@@ -17,7 +17,7 @@ OptionCheckBox < CheckBox
17 17
 MainWindow
18 18
   id: optionsWindow
19 19
   !text: tr('Options')
20
-  size: 350 240
20
+  size: 350 280
21 21
 
22 22
   @onEnter: Options.hide()
23 23
   @onEscape: Options.hide()

+ 1
- 1
modules/client_skins/skins/default/styles/spinboxes.otui View File

@@ -4,7 +4,7 @@ SpinBox < UISpinBox
4 4
   size: 86 20
5 5
   text-offset: 0 3
6 6
   text-margin: 3
7
-  image-source: images/panel_flat.png
7
+  image-source: /images/panel_flat.png
8 8
   image-border: 1
9 9
 
10 10
   $disabled:

+ 131
- 22
modules/corelib/widgets/uiminiwindow.lua View File

@@ -5,9 +5,102 @@ function UIMiniWindow.create()
5 5
   return miniwindow
6 6
 end
7 7
 
8
+function UIMiniWindow:getClassName()
9
+  return 'UIMiniWindow'
10
+end
11
+
12
+function UIMiniWindow:open(dontSave)
13
+  self:setVisible(true)
14
+
15
+  if not dontSave then
16
+    self:setSettings({closed = false})
17
+  end
18
+
19
+  signalcall(self.onOpen, self)
20
+end
21
+
22
+function UIMiniWindow:close(dontSave)
23
+  self:setVisible(false)
24
+
25
+  if not dontSave then
26
+    self:setSettings({closed = true})
27
+  end
28
+
29
+  signalcall(self.onClose, self)
30
+end
31
+
32
+function UIMiniWindow:minimize(dontSave)
33
+  self:setOn(true)
34
+  self:getChildById('contentsPanel'):hide()
35
+  self:getChildById('miniwindowScrollBar'):hide()
36
+  self:getChildById('bottomResizeBorder'):hide()
37
+  self:getChildById('minimizeButton'):setOn(true)
38
+  self.savedHeight = self:getHeight()
39
+  self:setHeight(self.minimizedHeight)
40
+
41
+  if not dontSave then
42
+    self:setSettings({minimized = true})
43
+  end
44
+
45
+  signalcall(self.onMinimize, self)
46
+end
47
+
48
+function UIMiniWindow:maximize(dontSave)
49
+  self:setOn(false)
50
+  self:getChildById('contentsPanel'):show()
51
+  self:getChildById('miniwindowScrollBar'):show()
52
+  self:getChildById('bottomResizeBorder'):show()
53
+  self:getChildById('minimizeButton'):setOn(false)
54
+  self:setHeight(self.savedHeight)
55
+
56
+  if not dontSave then
57
+    self:setSettings({minimized = false})
58
+  end
59
+
60
+  signalcall(self.onMaximize, self)
61
+end
62
+
8 63
 function UIMiniWindow:onSetup()
9
-  self:getChildById('closeButton').onClick = function() signalcall(self.onClose, self) end
10
-  self:getChildById('minimizeButton').onClick = function() signalcall(self.onMinimize, self) end
64
+  self:getChildById('closeButton').onClick =
65
+    function()
66
+      self:close()
67
+    end
68
+
69
+  self:getChildById('minimizeButton').onClick =
70
+    function()
71
+      if self:isOn() then
72
+        self:maximize()
73
+      else
74
+        self:minimize()
75
+      end
76
+    end
77
+
78
+  local settings = Settings.getNode('MiniWindows')
79
+  if settings then
80
+    local selfSettings = settings[self:getId()]
81
+    if selfSettings then
82
+      if selfSettings.parentId then
83
+        local parent = rootWidget:recursiveGetChildById(selfSettings.parentId)
84
+        if parent then
85
+          if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then
86
+            parent:scheduleInsert(self, selfSettings.index)
87
+          elseif selfSettings.position then
88
+            self:setParent(parent)
89
+            self:setPosition(topoint(selfSettings.position))
90
+            self:bindRectToParent()
91
+          end
92
+        end
93
+      end
94
+
95
+      if selfSettings.minimized then
96
+        self:minimize(true)
97
+      end
98
+
99
+      if selfSettings.closed then
100
+        self:close(true)
101
+      end
102
+    end
103
+  end
11 104
 end
12 105
 
13 106
 function UIMiniWindow:onDragEnter(mousePos)
@@ -18,6 +111,7 @@ function UIMiniWindow:onDragEnter(mousePos)
18 111
     local containerParent = parent:getParent()
19 112
     parent:removeChild(self)
20 113
     containerParent:addChild(self)
114
+    parent:saveChildren()
21 115
   end
22 116
 
23 117
   local oldPos = self:getPosition()
@@ -84,6 +178,15 @@ function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
84 178
     self.setMovedChildMargin = nil
85 179
     self.movedIndex = nil
86 180
   end
181
+
182
+  local parent = self:getParent()
183
+  if parent then
184
+    if parent:getClassName() == 'UIMiniWindowContainer' then
185
+      parent:saveChildren()
186
+    else
187
+      self:saveParentPosition(parent:getId(), self:getPosition())
188
+    end
189
+  end
87 190
 end
88 191
 
89 192
 function UIMiniWindow:onFocusChange(focused)
@@ -95,28 +198,34 @@ function UIMiniWindow:onFocusChange(focused)
95 198
   end
96 199
 end
97 200
 
98
-function UIMiniWindow:onClose()
99
-end
201
+function UIMiniWindow:setSettings(data)
202
+  local settings = Settings.getNode('MiniWindows')
203
+  if not settings then
204
+    settings = {}
205
+  end
206
+
207
+  local id = self:getId()
208
+  if not settings[id] then
209
+    settings[id] = {}
210
+  end
100 211
 
101
-function UIMiniWindow:onMinimize()
102
-  if self:isOn() then
103
-    self:setOn(false)
104
-    self:getChildById('contentsPanel'):show()
105
-    self:getChildById('miniwindowScrollBar'):show()
106
-    self:getChildById('bottomResizeBorder'):show()
107
-    self:getChildById('minimizeButton'):setOn(false)
108
-    self:setHeight(self.savedHeight)
109
-  else
110
-    self.savedHeight = self:getHeight()
111
-    self:setHeight(self.minimizedHeight)
112
-    self:setOn(true)
113
-    self:getChildById('contentsPanel'):hide()
114
-    self:getChildById('miniwindowScrollBar'):hide()
115
-    self:getChildById('bottomResizeBorder'):hide()
116
-    self:getChildById('minimizeButton'):setOn(true)
212
+  for key,value in pairs(data) do
213
+    settings[id][key] = value
117 214
   end
215
+
216
+  Settings.setNode('MiniWindows', settings)
118 217
 end
119 218
 
120
-function UIMiniWindow:getClassName()
121
-  return 'UIMiniWindow'
219
+function UIMiniWindow:saveParentPosition(parentId, position)
220
+  local selfSettings = {}
221
+  selfSettings.parentId = parentId
222
+  selfSettings.position = pointtostring(position)
223
+  self:setSettings(selfSettings)
224
+end
225
+
226
+function UIMiniWindow:saveParentIndex(parentId, index)
227
+  local selfSettings = {}
228
+  selfSettings.parentId = parentId
229
+  selfSettings.index = index
230
+  self:setSettings(selfSettings)
122 231
 end

+ 54
- 1
modules/corelib/widgets/uiminiwindowcontainer.lua View File

@@ -2,6 +2,7 @@ UIMiniWindowContainer = extends(UIWidget)
2 2
 
3 3
 function UIMiniWindowContainer.create()
4 4
   local container = UIMiniWindowContainer.internalCreate()
5
+  container.scheduledWidgets = {}
5 6
   container:setFocusable(false)
6 7
   container:setPhantom(true)
7 8
   return container
@@ -14,7 +15,9 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
14 15
   		return true
15 16
   	end
16 17
 
17
-  	oldParent:removeChild(widget)
18
+    if oldParent then
19
+  	  oldParent:removeChild(widget)
20
+    end
18 21
 
19 22
   	if widget.movedWidget then
20 23
   		local index = self:getChildIndex(widget.movedWidget)
@@ -27,6 +30,56 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
27 30
   end
28 31
 end
29 32
 
33
+function UIMiniWindowContainer:swapInsert(widget, index)
34
+  local oldParent = widget:getParent()
35
+  local oldIndex = self:getChildIndex(widget)
36
+
37
+  if oldParent == self and oldIndex ~= index then
38
+    local oldWidget = self:getChildByIndex(index)
39
+    self:removeChild(oldWidget)
40
+    self:insertChild(oldIndex, oldWidget)
41
+    self:removeChild(widget)
42
+    self:insertChild(index, widget)
43
+  end
44
+end
45
+
46
+function UIMiniWindowContainer:scheduleInsert(widget, index)
47
+  if index - 1 > self:getChildCount() then
48
+    if self.scheduledWidgets[index] then
49
+      warning('replacing scheduled widget id ' .. widget:getId())
50
+    end
51
+    self.scheduledWidgets[index] = widget
52
+  else
53
+    local oldParent = widget:getParent()
54
+    if oldParent ~= self then
55
+      oldParent:removeChild(widget)
56
+      self:insertChild(index, widget)
57
+    else
58
+      self:swapInsert(widget, index)
59
+    end
60
+
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
69
+        end
70
+      end
71
+      if not placed then break end
72
+    end
73
+  end
74
+end
75
+
76
+function UIMiniWindowContainer:saveChildren()
77
+  local children = self:getChildren()
78
+  for i=1,#children do
79
+    children[i]:saveParentIndex(self:getId(), i)
80
+  end
81
+end
82
+
30 83
 function UIMiniWindowContainer:getClassName()
31 84
   return 'UIMiniWindowContainer'
32 85
 end

+ 12
- 0
modules/corelib/widgets/uiresizeborder.lua View File

@@ -80,12 +80,24 @@ function UIResizeBorder:onStyleApply(styleName, styleNode)
80 80
   end
81 81
 end
82 82
 
83
+function UIResizeBorder:onVisibilityChange(visible)
84
+  if visible and self.maximum == self.minimum then
85
+    self:hide()
86
+  end
87
+end
88
+
83 89
 function UIResizeBorder:setMaximum(maximum)
84 90
   self.maximum  = maximum
91
+  if self.maximum == self.minimum then
92
+    self:hide()
93
+  end
85 94
 end
86 95
 
87 96
 function UIResizeBorder:setMinimum(minimum)
88 97
   self.minimum = minimum
98
+  if self.maximum == self.minimum then
99
+    self:hide()
100
+  end
89 101
 end
90 102
 
91 103
 function UIResizeBorder:getMaximum() return self.maximum end

+ 12
- 4
modules/game_battle/battle.lua View File

@@ -36,7 +36,7 @@ table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } )
36 36
 
37 37
 -- public functions
38 38
 function Battle.init()
39
-  battleWindow = displayUI('battle.otui', GameInterface.getLeftPanel())
39
+  battleWindow = displayUI('battle.otui', GameInterface.getRightPanel())
40 40
   battleButton = TopMenu.addGameToggleButton('battleButton', tr('Battle') .. ' (Ctrl+B)', 'battle.png', Battle.toggle)
41 41
   battleButton:setOn(true)
42 42
   Keyboard.bindKeyDown('Ctrl+B', Battle.toggle)
@@ -93,9 +93,17 @@ function Battle.terminate()
93 93
 end
94 94
 
95 95
 function Battle.toggle()
96
-  local visible = not battleWindow:isExplicitlyVisible()
97
-  battleWindow:setVisible(visible)
98
-  battleButton:setOn(visible)
96
+  if battleButton:isOn() then
97
+    battleWindow:close()
98
+    battleButton:setOn(false)
99
+  else
100
+    battleWindow:open()
101
+    battleButton:setOn(true)
102
+  end
103
+end
104
+
105
+function Battle.onMiniWindowClose()
106
+  battleButton:setOn(false)
99 107
 end
100 108
 
101 109
 function Battle.addAllCreatures()

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

@@ -41,7 +41,7 @@ MiniWindow
41 41
   !text: tr('Battle')
42 42
   height: 166
43 43
   icon: battle.png
44
-  @onClose: Battle.toggle()
44
+  @onClose: Battle.onMiniWindowClose()
45 45
 
46 46
   MiniWindowContents
47 47
     BattlePlayers

+ 10
- 3
modules/game_combatcontrols/combatcontrols.lua View File

@@ -129,8 +129,15 @@ function CombatControls.offline()
129 129
 end
130 130
 
131 131
 function CombatControls.toggle()
132
-  local visible = not combatControlsWindow:isExplicitlyVisible()
133
-  combatControlsWindow:setVisible(visible)
134
-  combatControlsButton:setOn(visible)
132
+  if combatControlsButton:isOn() then
133
+    combatControlsWindow:close()
134
+    combatControlsButton:setOn(false)
135
+  else
136
+    combatControlsWindow:open()
137
+    combatControlsButton:setOn(true)
138
+  end
135 139
 end
136 140
 
141
+function CombatControls.onMiniWindowClose()
142
+  combatControlsButton:setOn(false)
143
+end

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

@@ -20,10 +20,11 @@ SafeFightBox < CombatBox
20 20
   image-source: /game_combatcontrols/icons/safefight.png
21 21
 
22 22
 MiniWindow
23
+  id: combatControlsWindow
23 24
   !text: tr('Combat Controls')
24 25
   icon: combatcontrols.png
25 26
   height: 64
26
-  @onClose: CombatControls.toggle()
27
+  @onClose: CombatControls.onMiniWindowClose()
27 28
 
28 29
   MiniWindowContents
29 30
     FightOffensiveBox

+ 12
- 4
modules/game_healthbar/healthbar.lua View File

@@ -35,7 +35,7 @@ function HealthBar.init()
35 35
 
36 36
   connect(g_game, { onGameEnd = HealthBar.offline })
37 37
 
38
-  healthBarWindow = displayUI('healthbar.otui', GameInterface.getLeftPanel())
38
+  healthBarWindow = displayUI('healthbar.otui', GameInterface.getRightPanel())
39 39
   healthBarButton = TopMenu.addGameToggleButton('healthBarButton', tr('Health Bar'), 'healthbar.png', HealthBar.toggle)
40 40
   healthBarButton:setOn(true)
41 41
   healthBar = healthBarWindow:recursiveGetChildById('healthBar')
@@ -71,9 +71,17 @@ function HealthBar.terminate()
71 71
 end
72 72
 
73 73
 function HealthBar.toggle()
74
-  local visible = not healthBarWindow:isExplicitlyVisible()
75
-  healthBarWindow:setVisible(visible)
76
-  healthBarButton:setOn(visible)
74
+  if healthBarButton:isOn() then
75
+    healthBarWindow:close()
76
+    healthBarButton:setOn(false)
77
+  else
78
+    healthBarWindow:open()
79
+    healthBarButton:setOn(true)
80
+  end
81
+end
82
+
83
+function HealthBar.onMiniWindowClose()
84
+  healthBarButton:setOn(false)
77 85
 end
78 86
 
79 87
 function HealthBar.offline()

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

@@ -45,7 +45,7 @@ MiniWindow
45 45
   id: healthBarWindow
46 46
   !text: tr('Health Bar')
47 47
   height: 86
48
-  @onClose: HealthBar.toggle()
48
+  @onClose: HealthBar.onMiniWindowClose()
49 49
 
50 50
   MiniWindowContents
51 51
     HealthBar
@@ -61,4 +61,3 @@ MiniWindow
61 61
       margin-top: 5      
62 62
       anchors.top: prev.bottom
63 63
       anchors.horizontalcenter: parent.horizontalcenter
64
-      

+ 11
- 0
modules/game_interface/gameinterface.lua View File

@@ -9,6 +9,15 @@ local gameBottomPanel
9 9
 local logoutButton
10 10
 local mouseGrabberWidget
11 11
 
12
+local function onLeftPanelVisibilityChange(leftPanel, visible)
13
+  if not visible then
14
+    local children = leftPanel:getChildren()
15
+    for i=1,#children do
16
+      children[i]:setParent(gameRightPanel)
17
+    end
18
+  end
19
+end
20
+
12 21
 function GameInterface.init()
13 22
   connect(g_game, { onGameStart = GameInterface.show }, true)
14 23
   connect(g_game, { onGameEnd = GameInterface.hide }, true)
@@ -24,6 +33,7 @@ function GameInterface.init()
24 33
   gameRightPanel = gameRootPanel:getChildById('gameRightPanel')
25 34
   gameLeftPanel = gameRootPanel:getChildById('gameLeftPanel')
26 35
   gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
36
+  connect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
27 37
 
28 38
   logoutButton = TopMenu.addRightButton('logoutButton', 'Logout', '/images/logout.png', GameInterface.tryLogout)
29 39
   logoutButton:hide()
@@ -63,6 +73,7 @@ end
63 73
 function GameInterface.terminate()
64 74
   disconnect(g_game, { onGameStart = GameInterface.show })
65 75
   disconnect(g_game, { onGameEnd = GameInterface.hide })
76
+  disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
66 77
 
67 78
   logoutButton:destroy()
68 79
   logoutButton = nil

+ 6
- 0
modules/game_interface/gameinterface.otui View File

@@ -40,6 +40,11 @@ UIWidget
40 40
     anchors.top: parent.top
41 41
     anchors.bottom: parent.bottom
42 42
     focusable: false
43
+    visible: true
44
+    on: true
45
+    $!on:
46
+      width: 0
47
+      visible: false
43 48
 
44 49
   GameSidePanel
45 50
     id: gameRightPanel
@@ -49,6 +54,7 @@ UIWidget
49 54
     anchors.top: parent.top
50 55
     anchors.bottom: parent.bottom
51 56
     focusable: false
57
+    on: true
52 58
 
53 59
   Splitter
54 60
     id: bottomSplitter

+ 11
- 4
modules/game_inventory/inventory.lua View File

@@ -14,7 +14,6 @@ function Inventory.init()
14 14
   Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
15 15
 
16 16
   inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel())
17
-  inventoryWindow.onClose = Inventory.toggle
18 17
   inventoryPanel = inventoryWindow:getChildById('contentsPanel')
19 18
   inventoryButton = TopMenu.addGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', 'inventory.png', Inventory.toggle)
20 19
   inventoryButton:setOn(true)
@@ -50,9 +49,17 @@ function Inventory.refresh()
50 49
 end
51 50
 
52 51
 function Inventory.toggle()
53
-  local visible = not inventoryWindow:isExplicitlyVisible()
54
-  inventoryWindow:setVisible(visible)
55
-  inventoryButton:setOn(visible)
52
+  if inventoryButton:isOn() then
53
+    inventoryWindow:close()
54
+    inventoryButton:setOn(false)
55
+  else
56
+    inventoryWindow:open()
57
+    inventoryButton:setOn(true)
58
+  end
59
+end
60
+
61
+function Inventory.onMiniWindowClose()
62
+  inventoryButton:setOn(false)
56 63
 end
57 64
 
58 65
 -- hooked events

+ 2
- 2
modules/game_inventory/inventory.otui View File

@@ -1,9 +1,9 @@
1 1
 MiniWindow
2
-  id: inventoryMiniWindow
2
+  id: inventoryWindow
3 3
   !text: tr('Inventory')
4 4
   icon: inventory.png
5 5
   height: 180
6
-  @onClose: Inventory.toggle()
6
+  @onClose: Inventory.onMiniWindowClose()
7 7
 
8 8
   MiniWindowContents
9 9
     Item

+ 12
- 4
modules/game_skills/skills.lua View File

@@ -35,7 +35,7 @@ function Skills.init()
35 35
     onSkillChange = Skills.onSkillChange
36 36
   })
37 37
 
38
-  skillsWindow = displayUI('skills.otui', GameInterface.getLeftPanel())
38
+  skillsWindow = displayUI('skills.otui', GameInterface.getRightPanel())
39 39
   skillsButton = TopMenu.addGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', Skills.toggle)
40 40
   skillsButton:setOn(true)
41 41
   Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
@@ -84,9 +84,17 @@ function Skills.refresh()
84 84
 end
85 85
 
86 86
 function Skills.toggle()
87
-  local visible = not skillsWindow:isExplicitlyVisible()
88
-  skillsWindow:setVisible(visible)
89
-  skillsButton:setOn(visible)
87
+  if skillsButton:isOn() then
88
+    skillsWindow:close()
89
+    skillsButton:setOn(false)
90
+  else
91
+    skillsWindow:open()
92
+    skillsButton:setOn(true)
93
+  end
94
+end
95
+
96
+function Skills.onMiniWindowClose()
97
+  skillsButton:setOn(false)
90 98
 end
91 99
 
92 100
 function Skills.onSkillButtonClick(button)

+ 2
- 2
modules/game_skills/skills.otui View File

@@ -33,9 +33,9 @@ SkillPercentPanel < ProgressBar
33 33
 MiniWindow
34 34
   id: skillWindow
35 35
   !text: tr('Skills')
36
-  height: 350
36
+  height: 150
37 37
   icon: skills.png
38
-  @onClose: Skills.toggle()
38
+  @onClose: Skills.onMiniWindowClose()
39 39
 
40 40
   MiniWindowContents
41 41
     anchors.fill: parent

+ 12
- 4
modules/game_viplist/viplist.lua View File

@@ -14,7 +14,7 @@ function VipList.init()
14 14
 
15 15
   Keyboard.bindKeyDown('Ctrl+P', VipList.toggle)
16 16
 
17
-  vipWindow = displayUI('viplist.otui', GameInterface.getLeftPanel())
17
+  vipWindow = displayUI('viplist.otui', GameInterface.getRightPanel())
18 18
   vipButton = TopMenu.addGameToggleButton('vipListButton', tr('VIP list') .. ' (Ctrl+P)', 'viplist.png', VipList.toggle)
19 19
   vipButton:setOn(true)
20 20
 
@@ -48,9 +48,17 @@ function VipList.clear()
48 48
 end
49 49
 
50 50
 function VipList.toggle()
51
-  local visible = not vipWindow:isExplicitlyVisible()
52
-  vipWindow:setVisible(visible)
53
-  vipButton:setOn(visible)
51
+  if vipButton:isOn() then
52
+    vipWindow:close()
53
+    vipButton:setOn(false)
54
+  else
55
+    vipWindow:open()
56
+    vipButton:setOn(true)
57
+  end
58
+end
59
+
60
+function VipList.onMiniWindowClose()
61
+  vipButton:setOn(false)
54 62
 end
55 63
 
56 64
 function VipList.createAddWindow()

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

@@ -8,7 +8,7 @@ MiniWindow
8 8
   !text: tr('VIP List')
9 9
   height: 100
10 10
   icon: viplist.png
11
-  @onClose: VipList.toggle()
11
+  @onClose: VipList.onMiniWindowClose()
12 12
 
13 13
   MiniWindowContents
14 14
     layout: verticalBox

+ 12
- 1
src/framework/ui/uiwidget.cpp View File

@@ -375,6 +375,11 @@ void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index)
375 375
     if(!child)
376 376
         return;
377 377
 
378
+    if((uint)index - 1 > m_children.size()) {
379
+        g_logger.error(stdext::format("moving %s to index %d on %s", child->getId(), index, m_id));
380
+        return;
381
+    }
382
+
378 383
     // remove and push child again
379 384
     auto it = std::find(m_children.begin(), m_children.end(), child);
380 385
     if(it == m_children.end()) {
@@ -384,6 +389,7 @@ void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index)
384 389
     m_children.erase(it);
385 390
     m_children.insert(m_children.begin() + index - 1, child);
386 391
     updateChildrenIndexStates();
392
+    updateLayout();
387 393
 }
388 394
 
389 395
 void UIWidget::lockChild(const UIWidgetPtr& child)
@@ -751,7 +757,10 @@ void UIWidget::destroyChildren()
751 757
 
752 758
 void UIWidget::setId(const std::string& id)
753 759
 {
754
-    m_id = id;
760
+    if(id != m_id) {
761
+        m_id = id;
762
+        callLuaField("onIdChange", id);
763
+    }
755 764
 }
756 765
 
757 766
 void UIWidget::setParent(const UIWidgetPtr& parent)
@@ -885,6 +894,8 @@ void UIWidget::setVisible(bool visible)
885 894
             g_ui.onWidgetAppear(asUIWidget());
886 895
         else
887 896
             g_ui.onWidgetDisappear(asUIWidget());
897
+
898
+        callLuaField("onVisibilityChange", visible);
888 899
     }
889 900
 }
890 901
 

Loading…
Cancel
Save