From 42b05df7174ceae28e220b5cd4c7aca6cd92242c Mon Sep 17 00:00:00 2001
From: Henrique Santiago <henrique_santiago93@hotmail.com>
Date: Thu, 24 Jan 2013 20:57:51 -0200
Subject: [PATCH] Hotkeys order, minimap mark windw changes

---
 modules/corelib/string.lua               | 17 +++++++
 modules/game_hotkeys/hotkeys_manager.lua | 22 ++++++++-
 modules/game_minimap/flagwindow.otui     | 62 ++++++++++++------------
 modules/game_minimap/minimap.otui        |  1 -
 4 files changed, 67 insertions(+), 35 deletions(-)

diff --git a/modules/corelib/string.lua b/modules/corelib/string.lua
index 348f989c..4da2a034 100644
--- a/modules/corelib/string.lua
+++ b/modules/corelib/string.lua
@@ -50,3 +50,20 @@ function string:explode(sep, limit)
   return t
 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
diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua
index 43b80701..6ee7bb4d 100644
--- a/modules/game_hotkeys/hotkeys_manager.lua
+++ b/modules/game_hotkeys/hotkeys_manager.lua
@@ -252,10 +252,28 @@ end
 function addKeyCombo(messageBox, keyCombo, keySettings)
   local label = nil
   if currentHotkeysList:getChildById(keyCombo) == nil then
-    local label = g_ui.createWidget('HotkeyListLabel', currentHotkeysList)
+    local label = g_ui.createWidget('HotkeyListLabel')
+
+    local children = currentHotkeysList:getChildren()
+    if #children == 0 then
+      currentHotkeysList:addChild(label)
+    else
+      local add = false
+      for i=1,#children do
+        if keyCombo:operatorLess(children[i]:getId()) then
+          currentHotkeysList:insertChild(i, label)
+          add = true
+          break
+        end
+      end
+      if not add then
+        currentHotkeysList:addChild(label)
+      end
+    end
+
     label:setId(keyCombo)
     label:setColor(HotkeyColors.text)
-    label:setText(keyCombo..': ')
+    label:setText(keyCombo .. ': ')
     if keySettings then
       hotkeyLabelSelectedOnList = label
       label.keyCombo = keyCombo
diff --git a/modules/game_minimap/flagwindow.otui b/modules/game_minimap/flagwindow.otui
index 706d2d15..c83ccc0e 100644
--- a/modules/game_minimap/flagwindow.otui
+++ b/modules/game_minimap/flagwindow.otui
@@ -26,7 +26,7 @@ FlagButton < CheckBox
 FlagWindow < MainWindow
   id: flagWindow
   !text: tr('Create Map Mark')
-  size: 196 170
+  size: 196 185
 
   Label
     id: position
@@ -48,69 +48,68 @@ FlagWindow < MainWindow
     anchors.left: parent.left
     anchors.top: prev.bottom
     width: 158
-  
+
   FlagButton
     id: flag1
     anchors.left: parent.left
     anchors.top: prev.bottom
     margin-top: 6
     margin-left: 0  
-      
+
   FlagButton
     id: flag2
     icon-clip: 11 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag3
     icon-clip: 22 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag4
     icon-clip: 33 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag5
     icon-clip: 44 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag6
     icon-clip: 55 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag7
     icon-clip: 66 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag8
     icon-clip: 77 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag9
     icon-clip: 88 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag10
     icon-clip: 99 0 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-    
-  
+
   FlagButton
     id: flag11
     icon-clip: 0 11 11 11
@@ -118,73 +117,72 @@ FlagWindow < MainWindow
     anchors.top: prev.bottom
     margin-top: 6
     margin-left: 0  
-      
+
   FlagButton
     id: flag12
     icon-clip: 11 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag13
     icon-clip: 22 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag14
     icon-clip: 33 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag15
     icon-clip: 44 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag16
     icon-clip: 55 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag17
     icon-clip: 66 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag18
     icon-clip: 77 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag19
     icon-clip: 88 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-      
+
   FlagButton
     id: flag20
     icon-clip: 99 11 11 11
     anchors.left: prev.right
     anchors.top: prev.top
-    
+
   Button
     id: okButton
     !text: tr('Ok')
-    anchors.top: prev.bottom
-    anchors.left: parent.left
-    margin-top: 10
-    width: 60
-    
+    width: 64
+    anchors.right: next.left
+    anchors.bottom: parent.bottom
+    margin-right: 10
+
   Button
     id: cancelButton
     !text: tr('Cancel')
-    anchors.top: prev.top
-    anchors.left: prev.right
-    margin-left: 15
-    width: 60
+    width: 64
+    anchors.right: parent.right
+    anchors.bottom: parent.bottom
diff --git a/modules/game_minimap/minimap.otui b/modules/game_minimap/minimap.otui
index 8bd4dc48..831b0912 100644
--- a/modules/game_minimap/minimap.otui
+++ b/modules/game_minimap/minimap.otui
@@ -104,4 +104,3 @@ MiniWindow
       anchors.top: parent.top
       margin: 4
       @onClick: center()
-