changeset 1101:3e5d70cfe20e

Award order fix, changed UIMSG_C0 to UIMSG_ClickAwardScrollBar
author Grumpy7
date Mon, 27 May 2013 12:45:17 +0200
parents b82375804b5d
children 79010db96ade
files GUIWindow.h UICharacter.cpp mm7_5.cpp
diffstat 3 files changed, 62 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/GUIWindow.h	Mon May 27 11:19:14 2013 +0100
+++ b/GUIWindow.h	Mon May 27 12:45:17 2013 +0200
@@ -152,7 +152,7 @@
   UIMSG_BD = 189,
   UIMSG_CastSpell_BE = 190,
   UIMSG_BF = 191,
-  UIMSG_C0 = 192,
+  UIMSG_ClickAwardScrollBar = 192,
   UIMSG_C1 = 192,
   UIMSG_C2 = 192,
 
--- a/UICharacter.cpp	Mon May 27 11:19:14 2013 +0100
+++ b/UICharacter.cpp	Mon May 27 12:45:17 2013 +0200
@@ -1,5 +1,7 @@
 #include <assert.h>
 
+#include <algorithm> 
+
 #include "MM7.h"
 
 #include "MapInfo.h"
@@ -2503,6 +2505,59 @@
         pGUIWindow_CurrentMenu->DrawText(pFontArrus, 266, v10, 0, pTmpBuf, 0, 0, 0);
 }
 
+//Award sort stuff. Should be removed after changing the award container to something other than array
+template<class Cont>
+typename Cont::iterator begin(Cont& c){
+    return c.begin();
+}
+
+template<class Cont>
+typename Cont::iterator end(Cont& c){
+    return c.end();
+}
+
+// overloads for C style arrays
+template<class T, std::size_t N>
+T* begin(T (&arr)[N]){
+    return &arr[0];
+}
+
+template<class T, std::size_t N>
+T* end(T (&arr)[N]){
+    return arr + N;
+}
+
+bool awardSort (int i,int j) { 
+    if (pAwards[i].uPriority == 0)  //none
+    {
+        return false;
+    }
+    else if (pAwards[j].uPriority == 0)
+    {
+        return true;
+    }
+    else if(pAwards[i].uPriority == 1)  //fines,arena stuff,etc
+    {
+        return false;
+    }
+    else if(pAwards[j].uPriority == 1)
+    {
+        return true;
+    }
+    else if(pAwards[i].uPriority == 5) //joined guilds
+    {
+        return false;
+    }
+    else if(pAwards[j].uPriority == 5)
+    {
+        return true;
+    }
+    else
+    {
+        return (pAwards[i].uPriority<pAwards[j].uPriority);
+    }
+}
+
 //----- (00419100) --------------------------------------------------------
 void FillAwardsData()
 {
@@ -2519,7 +2574,9 @@
         for (int i = 0; i < 105; ++i)
         {
             if ( _449B57_test_bit(pPlayer->_guilds_member_bits, i) && pAwards[i].pText )
+            {
                 achieved_awards[num_achieved_awards++] = (AwardType)i;
+            }
         }
         num_achieved_awards_2 = num_achieved_awards;
         num_achieved_awards = 0;
@@ -2527,23 +2584,9 @@
         //sort awards index 
         if (num_achieved_awards_2 > 0)
         {
-            for(int i=0; i<num_achieved_awards_2; ++i)
-                achieved_awards[num_achieved_awards_2 + i] = (AwardType)(rand() % 16);
-
-            for(int i=1; i<num_achieved_awards_2-1; ++i)
-                {
-                for (int j = i; j < num_achieved_awards_2-1; ++j )
-                    {
-                    auto tmp=achieved_awards[j];
-                    if (pAwards[j].uPriority < pAwards[i].uPriority)
-                        {
-                        achieved_awards[j] = achieved_awards[i];
-                        achieved_awards[i] = tmp;
-                        }
-                    }
-                }
-            }
+            std::stable_sort(begin(achieved_awards), end(achieved_awards), awardSort);
         }
+    }
 
 
 //----- (0043EF2B) --------------------------------------------------------
--- a/mm7_5.cpp	Mon May 27 11:19:14 2013 +0100
+++ b/mm7_5.cpp	Mon May 27 12:45:17 2013 +0200
@@ -2856,8 +2856,7 @@
           ++pMessageQueue_50CBD0->uNumMessages;*/
           pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
           continue;
-        case UIMSG_C0:
-			__debugbreak();
+        case UIMSG_ClickAwardScrollBar:
           dword_50651C = 1;
           if ( pMouse->GetCursorPos(&v211)->y > 178 )
             dword_50651C = -1;
@@ -10983,7 +10982,7 @@
                    1, 0, UIMSG_ClickAwardsDownBtn, 0, 0, "",
                    pIcons_LOD->GetTexture(uTextureID_ar_dn_up),
                    pIcons_LOD->GetTexture(uTextureID_ar_dn_dn), 0);
-    ptr_507BA4 = pGUIWindow_CurrentMenu->CreateButton(440, 62, 16, 232, 1, 0, UIMSG_C0, 0, 0, "", 0);
+    ptr_507BA4 = pGUIWindow_CurrentMenu->CreateButton(440, 62, 16, 232, 1, 0, UIMSG_ClickAwardScrollBar, 0, 0, "", 0);
   }
 }