Another sort function for hotkeys

master
Henrique Santiago 11 years ago
parent 42b05df717
commit 839495fa9b

@ -49,21 +49,3 @@ function string:explode(sep, limit)
table.insert(t, tmp) table.insert(t, tmp)
return t return t
end end
function string:operatorLess(other)
local selfLower = self:lower()
local otherLower = other:lower()
local selfLen = self:len()
local otherLen = other:len()
local minLen = math.min(selfLen, otherLen)
for i=1,minLen do
local selfByteI = string.byte(selfLower, i)
local otherByteI = string.byte(otherLower, i)
if selfByteI < otherByteI then
return true
elseif selfByteI > otherByteI then
return false
end
end
return selfLen < otherLen
end

@ -253,27 +253,28 @@ function addKeyCombo(messageBox, keyCombo, keySettings)
local label = nil local label = nil
if currentHotkeysList:getChildById(keyCombo) == nil then if currentHotkeysList:getChildById(keyCombo) == nil then
local label = g_ui.createWidget('HotkeyListLabel') local label = g_ui.createWidget('HotkeyListLabel')
label:setId(keyCombo)
label:setColor(HotkeyColors.text)
label:setText(keyCombo .. ': ')
local children = currentHotkeysList:getChildren() local children = currentHotkeysList:getChildren()
if #children == 0 then children[#children+1] = label
currentHotkeysList:addChild(label) table.sort(children, function(a,b)
else if a:getId():len() < b:getId():len() then
local add = false return true
for i=1,#children do elseif a:getId():len() == b:getId():len() then
if keyCombo:operatorLess(children[i]:getId()) then return a:getId() < b:getId()
currentHotkeysList:insertChild(i, label) else
add = true return false
break
end
end end
if not add then end)
currentHotkeysList:addChild(label) for i=1,#children do
if children[i] == label then
currentHotkeysList:insertChild(i, label)
break
end end
end end
label:setId(keyCombo)
label:setColor(HotkeyColors.text)
label:setText(keyCombo .. ': ')
if keySettings then if keySettings then
hotkeyLabelSelectedOnList = label hotkeyLabelSelectedOnList = label
label.keyCombo = keyCombo label.keyCombo = keyCombo

Loading…
Cancel
Save