Browse Source

Sorting VIP list by name

@ #209
What should sorting by type do?
Sam 7 years ago
parent
commit
2f9e2c3e33
1 changed files with 37 additions and 3 deletions
  1. 37
    3
      modules/game_viplist/viplist.lua

+ 37
- 3
modules/game_viplist/viplist.lua View File

@@ -88,6 +88,23 @@ function isHiddingOffline()
88 88
   return settings['hideOffline']
89 89
 end
90 90
 
91
+function getSortedBy()
92
+  local settings = g_settings.getNode('VipList')
93
+  if not settings then
94
+    return 'status'
95
+  end
96
+  return settings['sortedBy']
97
+end
98
+
99
+function sortBy(state)
100
+  settings = {}
101
+  settings['sortedBy'] = state
102
+  g_settings.mergeNode('VipList', settings)
103
+
104
+  refresh()
105
+end
106
+
107
+
91 108
 function onAddVip(id, name, state)
92 109
   local vipList = vipWindow:getChildById('contentsPanel')
93 110
 
@@ -118,13 +135,13 @@ function onAddVip(id, name, state)
118 135
   
119 136
   for i=1,childrenCount do
120 137
     local child = vipList:getChildByIndex(i)
121
-    if state == VipState.Online and child.vipState ~= VipState.Online then
138
+    if state == VipState.Online and child.vipState ~= VipState.Online and getSortedBy() == 'status' then
122 139
       vipList:insertChild(i, label)
123 140
       return
124 141
     end
125 142
 
126
-    if (state ~= VipState.Online and child.vipState ~= VipState.Online)
127
-      or (state == VipState.Online and child.vipState == VipState.Online) then
143
+    if ((state ~= VipState.Online and child.vipState ~= VipState.Online)
144
+      or (state == VipState.Online and child.vipState == VipState.Online)) or getSortedBy() == 'name' then
128 145
       
129 146
       local childText = child:getText():lower()
130 147
       local length = math.min(childText:len(), nameLower:len())
@@ -167,6 +184,14 @@ function onVipListMousePress(widget, mousePos, mouseButton)
167 184
   else
168 185
     menu:addOption(tr('Show Offline'), function() hideOffline(false) end)
169 186
   end
187
+  
188
+  if not(getSortedBy() == 'name') then
189
+    menu:addOption(tr('Sort by name'), function() sortBy('name') end)
190
+  end
191
+  
192
+  if not(getSortedBy() == 'status') then
193
+    menu:addOption(tr('Sort by status'), function() sortBy('status') end)
194
+  end
170 195
 
171 196
   menu:display(mousePos)
172 197
 
@@ -196,6 +221,15 @@ function onVipListLabelMousePress(widget, mousePos, mouseButton)
196 221
   else
197 222
     menu:addOption(tr('Show Offline'), function() hideOffline(false) end)
198 223
   end
224
+  
225
+  if not(getSortedBy() == 'name') then
226
+    menu:addOption(tr('Sort by name'), function() sortBy('name') end)
227
+  end
228
+  
229
+  if not(getSortedBy() == 'status') then
230
+    menu:addOption(tr('Sort by status'), function() sortBy('status') end)
231
+  end 
232
+  
199 233
   menu:display(mousePos)
200 234
 
201 235
   return true

Loading…
Cancel
Save