mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Use std::vector for assets menu list items instead of sorted_array
This commit is contained in:
parent
2ea0c49f8b
commit
96c97d5bb7
|
@ -7,6 +7,8 @@
|
|||
#include <base/vmath.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
#include <engine/demo.h>
|
||||
#include <engine/friends.h>
|
||||
#include <engine/shared/config.h>
|
||||
|
@ -252,11 +254,11 @@ public:
|
|||
};
|
||||
|
||||
protected:
|
||||
sorted_array<SCustomEntities> m_EntitiesList;
|
||||
sorted_array<SCustomGame> m_GameList;
|
||||
sorted_array<SCustomEmoticon> m_EmoticonList;
|
||||
sorted_array<SCustomParticle> m_ParticlesList;
|
||||
sorted_array<SCustomHud> m_HudList;
|
||||
std::vector<SCustomEntities> m_EntitiesList;
|
||||
std::vector<SCustomGame> m_GameList;
|
||||
std::vector<SCustomEmoticon> m_EmoticonList;
|
||||
std::vector<SCustomParticle> m_ParticlesList;
|
||||
std::vector<SCustomHud> m_HudList;
|
||||
|
||||
bool m_IsInit = false;
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ int CMenus::EntitiesScan(const char *pName, int IsDir, int DirType, void *pUser)
|
|||
SCustomEntities EntitiesItem;
|
||||
str_copy(EntitiesItem.m_aName, pName, sizeof(EntitiesItem.m_aName));
|
||||
CMenus::LoadEntities(&EntitiesItem, pUser);
|
||||
pThis->m_EntitiesList.add(EntitiesItem);
|
||||
pThis->m_EntitiesList.push_back(EntitiesItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ int CMenus::EntitiesScan(const char *pName, int IsDir, int DirType, void *pUser)
|
|||
SCustomEntities EntitiesItem;
|
||||
str_copy(EntitiesItem.m_aName, aName, sizeof(EntitiesItem.m_aName));
|
||||
CMenus::LoadEntities(&EntitiesItem, pUser);
|
||||
pThis->m_EntitiesList.add(EntitiesItem);
|
||||
pThis->m_EntitiesList.push_back(EntitiesItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ static void LoadAsset(TName *pAssetItem, const char *pAssetName, IGraphics *pGra
|
|||
}
|
||||
|
||||
template<typename TName>
|
||||
static int AssetScan(const char *pName, int IsDir, int DirType, sorted_array<TName> &AssetList, const char *pAssetName, IGraphics *pGraphics, void *pUser)
|
||||
static int AssetScan(const char *pName, int IsDir, int DirType, std::vector<TName> &AssetList, const char *pAssetName, IGraphics *pGraphics, void *pUser)
|
||||
{
|
||||
auto *pRealUser = (SMenuAssetScanUser *)pUser;
|
||||
if(IsDir)
|
||||
|
@ -177,7 +177,7 @@ static int AssetScan(const char *pName, int IsDir, int DirType, sorted_array<TNa
|
|||
TName AssetItem;
|
||||
str_copy(AssetItem.m_aName, pName, sizeof(AssetItem.m_aName));
|
||||
LoadAsset(&AssetItem, pAssetName, pGraphics, pUser);
|
||||
AssetList.add(AssetItem);
|
||||
AssetList.push_back(AssetItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -192,7 +192,7 @@ static int AssetScan(const char *pName, int IsDir, int DirType, sorted_array<TNa
|
|||
TName AssetItem;
|
||||
str_copy(AssetItem.m_aName, aName, sizeof(AssetItem.m_aName));
|
||||
LoadAsset(&AssetItem, pAssetName, pGraphics, pUser);
|
||||
AssetList.add(AssetItem);
|
||||
AssetList.push_back(AssetItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,18 +233,18 @@ int CMenus::HudScan(const char *pName, int IsDir, int DirType, void *pUser)
|
|||
return AssetScan(pName, IsDir, DirType, pThis->m_HudList, "hud", pGraphics, pUser);
|
||||
}
|
||||
|
||||
static sorted_array<const CMenus::SCustomEntities *> s_SearchEntitiesList;
|
||||
static sorted_array<const CMenus::SCustomGame *> s_SearchGamesList;
|
||||
static sorted_array<const CMenus::SCustomEmoticon *> s_SearchEmoticonsList;
|
||||
static sorted_array<const CMenus::SCustomParticle *> s_SearchParticlesList;
|
||||
static sorted_array<const CMenus::SCustomHud *> s_SearchHudList;
|
||||
static std::vector<const CMenus::SCustomEntities *> s_SearchEntitiesList;
|
||||
static std::vector<const CMenus::SCustomGame *> s_SearchGamesList;
|
||||
static std::vector<const CMenus::SCustomEmoticon *> s_SearchEmoticonsList;
|
||||
static std::vector<const CMenus::SCustomParticle *> s_SearchParticlesList;
|
||||
static std::vector<const CMenus::SCustomHud *> s_SearchHudList;
|
||||
|
||||
static const int NumberOfAssetsTabs = 5;
|
||||
static bool s_InitCustomList[NumberOfAssetsTabs] = {
|
||||
true,
|
||||
};
|
||||
|
||||
static int s_CustomListSize[NumberOfAssetsTabs] = {
|
||||
static size_t s_CustomListSize[NumberOfAssetsTabs] = {
|
||||
0,
|
||||
};
|
||||
|
||||
|
@ -252,7 +252,7 @@ static char s_aFilterString[NumberOfAssetsTabs][50];
|
|||
|
||||
static int s_CurCustomTab = ASSETS_TAB_ENTITIES;
|
||||
|
||||
static const CMenus::SCustomItem *GetCustomItem(int CurTab, int Index)
|
||||
static const CMenus::SCustomItem *GetCustomItem(int CurTab, size_t Index)
|
||||
{
|
||||
if(CurTab == ASSETS_TAB_ENTITIES)
|
||||
return s_SearchEntitiesList[Index];
|
||||
|
@ -269,9 +269,9 @@ static const CMenus::SCustomItem *GetCustomItem(int CurTab, int Index)
|
|||
}
|
||||
|
||||
template<typename TName>
|
||||
void ClearAssetList(sorted_array<TName> &List, IGraphics *pGraphics)
|
||||
void ClearAssetList(std::vector<TName> &List, IGraphics *pGraphics)
|
||||
{
|
||||
for(int i = 0; i < List.size(); ++i)
|
||||
for(size_t i = 0; i < List.size(); ++i)
|
||||
{
|
||||
if(List[i].m_RenderTexture.IsValid())
|
||||
pGraphics->UnloadTexture(&(List[i].m_RenderTexture));
|
||||
|
@ -284,9 +284,9 @@ void CMenus::ClearCustomItems(int CurTab)
|
|||
{
|
||||
if(CurTab == ASSETS_TAB_ENTITIES)
|
||||
{
|
||||
for(int i = 0; i < m_EntitiesList.size(); ++i)
|
||||
for(auto &Entity : m_EntitiesList)
|
||||
{
|
||||
for(auto &Image : m_EntitiesList[i].m_aImages)
|
||||
for(auto &Image : Entity.m_aImages)
|
||||
{
|
||||
if(Image.m_Texture.IsValid())
|
||||
Graphics()->UnloadTexture(&Image.m_Texture);
|
||||
|
@ -330,24 +330,25 @@ void CMenus::ClearCustomItems(int CurTab)
|
|||
}
|
||||
|
||||
template<typename TName, typename TCaller>
|
||||
void InitAssetList(sorted_array<TName> &AssetList, const char *pAssetPath, const char *pAssetName, FS_LISTDIR_CALLBACK pfnCallback, IGraphics *pGraphics, IStorage *pStorage, TCaller Caller)
|
||||
void InitAssetList(std::vector<TName> &AssetList, const char *pAssetPath, const char *pAssetName, FS_LISTDIR_CALLBACK pfnCallback, IGraphics *pGraphics, IStorage *pStorage, TCaller Caller)
|
||||
{
|
||||
if(AssetList.size() == 0)
|
||||
if(AssetList.empty())
|
||||
{
|
||||
TName AssetItem;
|
||||
str_copy(AssetItem.m_aName, "default", sizeof(AssetItem.m_aName));
|
||||
LoadAsset(&AssetItem, pAssetName, pGraphics, Caller);
|
||||
AssetList.add(AssetItem);
|
||||
AssetList.push_back(AssetItem);
|
||||
|
||||
// load assets
|
||||
pStorage->ListDirectory(IStorage::TYPE_ALL, pAssetPath, pfnCallback, Caller);
|
||||
std::sort(AssetList.begin(), AssetList.end());
|
||||
}
|
||||
if(AssetList.size() != s_CustomListSize[s_CurCustomTab])
|
||||
s_InitCustomList[s_CurCustomTab] = true;
|
||||
}
|
||||
|
||||
template<typename TName>
|
||||
int InitSearchList(sorted_array<const TName *> &SearchList, sorted_array<TName> &AssetList)
|
||||
int InitSearchList(std::vector<const TName *> &SearchList, std::vector<TName> &AssetList)
|
||||
{
|
||||
SearchList.clear();
|
||||
int ListSize = AssetList.size();
|
||||
|
@ -359,7 +360,7 @@ int InitSearchList(sorted_array<const TName *> &SearchList, sorted_array<TName>
|
|||
if(s_aFilterString[s_CurCustomTab][0] != '\0' && !str_utf8_find_nocase(s->m_aName, s_aFilterString[s_CurCustomTab]))
|
||||
continue;
|
||||
|
||||
SearchList.add_unsorted(s);
|
||||
SearchList.push_back(s);
|
||||
}
|
||||
return AssetList.size();
|
||||
}
|
||||
|
@ -397,15 +398,16 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
|
|||
};
|
||||
if(s_CurCustomTab == ASSETS_TAB_ENTITIES)
|
||||
{
|
||||
if(m_EntitiesList.size() == 0)
|
||||
if(m_EntitiesList.empty())
|
||||
{
|
||||
SCustomEntities EntitiesItem;
|
||||
str_copy(EntitiesItem.m_aName, "default", sizeof(EntitiesItem.m_aName));
|
||||
LoadEntities(&EntitiesItem, &User);
|
||||
m_EntitiesList.add(EntitiesItem);
|
||||
m_EntitiesList.push_back(EntitiesItem);
|
||||
|
||||
// load entities
|
||||
Storage()->ListDirectory(IStorage::TYPE_ALL, "assets/entities", EntitiesScan, &User);
|
||||
std::sort(m_EntitiesList.begin(), m_EntitiesList.end());
|
||||
}
|
||||
if(m_EntitiesList.size() != s_CustomListSize[s_CurCustomTab])
|
||||
s_InitCustomList[s_CurCustomTab] = true;
|
||||
|
@ -447,7 +449,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
|
|||
if(s_aFilterString[s_CurCustomTab][0] != '\0' && !str_utf8_find_nocase(s->m_aName, s_aFilterString[s_CurCustomTab]))
|
||||
continue;
|
||||
|
||||
s_SearchEntitiesList.add_unsorted(s);
|
||||
s_SearchEntitiesList.push_back(s);
|
||||
}
|
||||
}
|
||||
else if(s_CurCustomTab == ASSETS_TAB_GAME)
|
||||
|
@ -475,7 +477,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
|
|||
float TextureWidth = 150;
|
||||
float TextureHeight = 150;
|
||||
|
||||
int SearchListSize = 0;
|
||||
size_t SearchListSize = 0;
|
||||
|
||||
if(s_CurCustomTab == ASSETS_TAB_ENTITIES)
|
||||
{
|
||||
|
@ -501,7 +503,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
|
|||
}
|
||||
|
||||
UiDoListboxStart(&s_InitCustomList[s_CurCustomTab], &CustomList, TextureHeight + 15.0f + 10.0f + Margin, "", "", SearchListSize, CustomList.w / (Margin + TextureWidth), OldSelected, s_ScrollValue, true);
|
||||
for(int i = 0; i < SearchListSize; ++i)
|
||||
for(size_t i = 0; i < SearchListSize; ++i)
|
||||
{
|
||||
const SCustomItem *s = GetCustomItem(s_CurCustomTab, i);
|
||||
if(s == NULL)
|
||||
|
@ -533,7 +535,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
|
|||
OldSelected = i;
|
||||
}
|
||||
|
||||
CListboxItem Item = UiDoListboxNextItem(s, OldSelected == i);
|
||||
CListboxItem Item = UiDoListboxNextItem(s, OldSelected >= 0 && (size_t)OldSelected == i);
|
||||
CUIRect ItemRect = Item.m_Rect;
|
||||
ItemRect.Margin(Margin / 2, &ItemRect);
|
||||
if(Item.m_Visible)
|
||||
|
|
Loading…
Reference in a new issue