nominations_extended: Sort the nomination list by vote count
This commit is contained in:
		
							parent
							
								
									f3792affba
								
							
						
					
					
						commit
						aebf120544
					
				@ -725,6 +725,26 @@ void AttemptAdminRemoveMap(int client, const char[] filter = "")
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int NominateListSortCmp(int index1, int index2, Handle array, Handle hndl)
 | 
			
		||||
{
 | 
			
		||||
	char map1[PLATFORM_MAX_PATH];
 | 
			
		||||
	char map2[PLATFORM_MAX_PATH];
 | 
			
		||||
	GetArrayString(array, index1, map1, sizeof(map1));
 | 
			
		||||
	GetArrayString(array, index2, map2, sizeof(map2));
 | 
			
		||||
 | 
			
		||||
	int count1, count2;
 | 
			
		||||
	
 | 
			
		||||
	StringMap sm = view_as<StringMap>(hndl);
 | 
			
		||||
	
 | 
			
		||||
	sm.GetValue(map1, count1);
 | 
			
		||||
	sm.GetValue(map2, count2);
 | 
			
		||||
 | 
			
		||||
	if (count1 == count2)
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	return count1 > count2 ? -1 : 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "")
 | 
			
		||||
{
 | 
			
		||||
    int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
 | 
			
		||||
@ -750,23 +770,29 @@ bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "")
 | 
			
		||||
        {
 | 
			
		||||
            int nominate_count_for_particular_map = 0;
 | 
			
		||||
            sm.GetValue(map, nominate_count_for_particular_map);
 | 
			
		||||
            nominate_count_for_particular_map++;
 | 
			
		||||
            sm.SetValue(map, nominate_count_for_particular_map, true);
 | 
			
		||||
            sm.SetValue(map, nominate_count_for_particular_map + 1, true);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    for(int i = 0; i < GetArraySize(MapList); i++)
 | 
			
		||||
 | 
			
		||||
    StringMapSnapshot sm_snapshot = sm.Snapshot();
 | 
			
		||||
    ArrayList SortedList = CreateArray(arraySize);
 | 
			
		||||
 | 
			
		||||
    for(int i = 0; i < sm_snapshot.Length; i++)
 | 
			
		||||
    {
 | 
			
		||||
        GetArrayString(MapList, i, map, sizeof(map));
 | 
			
		||||
        sm_snapshot.GetKey(i, map, sizeof(map));
 | 
			
		||||
        SortedList.PushString(map);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SortedList.SortCustom(NominateListSortCmp, sm);
 | 
			
		||||
 | 
			
		||||
    for(int i = 0; i < GetArraySize(SortedList); i++)
 | 
			
		||||
    {
 | 
			
		||||
        GetArrayString(SortedList, i, map, sizeof(map));
 | 
			
		||||
 | 
			
		||||
        if(!filter[0] || StrContains(map, filter, false) != -1)
 | 
			
		||||
        {
 | 
			
		||||
            int nominate_count_for_particular_map = 0;
 | 
			
		||||
            sm.GetValue(map, nominate_count_for_particular_map);
 | 
			
		||||
            if (nominate_count_for_particular_map == -1)
 | 
			
		||||
            {
 | 
			
		||||
                //we already displayed vote count for this particular map
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            strcopy(display, sizeof(display), map);
 | 
			
		||||
 | 
			
		||||
            bool VIPRestriction = GetMapVIPRestriction(map);
 | 
			
		||||
@ -775,28 +801,23 @@ bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "")
 | 
			
		||||
 | 
			
		||||
            int owner = GetArrayCell(OwnerList, i);
 | 
			
		||||
            char spelling[8];
 | 
			
		||||
            if (nominate_count_for_particular_map == 1)
 | 
			
		||||
            {
 | 
			
		||||
                Format(spelling, sizeof(spelling), "Vote");
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                Format(spelling, sizeof(spelling), "Votes");
 | 
			
		||||
            }
 | 
			
		||||
            Format(spelling, sizeof(spelling), nominate_count_for_particular_map == 1 ? "Vote" : "Votes");
 | 
			
		||||
 | 
			
		||||
            if(!owner)
 | 
			
		||||
                Format(display, sizeof(display), "%s (Admin)", display);
 | 
			
		||||
            else
 | 
			
		||||
                Format(display, sizeof(display), "%s (%i %s)", display, nominate_count_for_particular_map, spelling);
 | 
			
		||||
            nominate_count_for_particular_map = -1;
 | 
			
		||||
            sm.SetValue(map, nominate_count_for_particular_map, true);
 | 
			
		||||
 | 
			
		||||
            AddMenuItem(menu, map, display);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    delete MapList;
 | 
			
		||||
    delete OwnerList;
 | 
			
		||||
    delete SortedList;
 | 
			
		||||
    delete sm;
 | 
			
		||||
    delete sm_snapshot;
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user