diff --git a/data/editor/entities.png b/data/editor/entities/DDNet.png similarity index 100% rename from data/editor/entities.png rename to data/editor/entities/DDNet.png diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 6110951c7..0128789e2 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -1,5 +1,8 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ + +#include + #include #include #include @@ -1010,6 +1013,16 @@ void CEditor::CallbackSaveCopyMap(const char *pFileName, int StorageType, void * pEditor->m_Dialog = DIALOG_NONE; } +static int EntitiesListdirCallback(const char *pName, int IsDir, int StorageType, void *pUser) { + CEditor *pEditor = (CEditor*)pUser; + if (!IsDir && str_endswith(pName, ".png")) { + std::string Name = pName; + pEditor->m_SelectEntitiesFiles.push_back(Name.substr(0, Name.length() - 4)); + } + + return 0; +} + void CEditor::DoToolbar(CUIRect ToolBar) { CUIRect TB_Top, TB_Bottom; @@ -1142,8 +1155,18 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(45.0f, &Button, &TB_Top); if(DoButton_Editor(&Button, "Entities", 0, &Button, 0, "Choose game layer entities image for different gametypes")) { + m_SelectEntitiesFiles.clear(); + Storage()->ListDirectory(IStorage::TYPE_ALL, "editor/entities", EntitiesListdirCallback, this); + std::sort(m_SelectEntitiesFiles.begin(), m_SelectEntitiesFiles.end()); + + for(int i = 0; i < (int)m_SelectEntitiesFiles.size(); i++) { + if (m_SelectEntitiesFiles[i] == "DDNet") + m_SelectEntitiesImage = i; + } + static int s_EntitiesPopupID = 0; - UiInvokePopupMenu(&s_EntitiesPopupID, 0, Button.x, Button.y+18.0f, 100, 100, PopupEntities); + UiInvokePopupMenu(&s_EntitiesPopupID, 0, Button.x, Button.y+18.0f, + 250, m_SelectEntitiesFiles.size()*14 + 10, PopupEntities); } TB_Top.VSplitLeft(10.0f, 0, &TB_Top); @@ -5767,7 +5790,7 @@ void CEditor::Init() ms_CheckerTexture = Graphics()->LoadTexture("editor/checker.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); ms_BackgroundTexture = Graphics()->LoadTexture("editor/background.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); ms_CursorTexture = Graphics()->LoadTexture("editor/cursor.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); - ms_EntitiesTexture = Graphics()->LoadTexture("editor/entities.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); + ms_EntitiesTexture = Graphics()->LoadTexture("editor/entities/DDNet.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); ms_FrontTexture = Graphics()->LoadTexture("editor/front.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); ms_TeleTexture = Graphics()->LoadTexture("editor/tele.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 65d292c92..6d76dc7b4 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -3,6 +3,8 @@ #ifndef GAME_EDITOR_EDITOR_H #define GAME_EDITOR_EDITOR_H +#include +#include #include #include @@ -856,6 +858,9 @@ public: int m_FilesCur; int m_FilesStopAt; + std::vector m_SelectEntitiesFiles; + int m_SelectEntitiesImage; + float m_WorldOffsetX; float m_WorldOffsetY; float m_EditorOffsetX; diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 7c45d4a3f..7e6c11c41 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -1655,28 +1655,24 @@ int CEditor::PopupColorPicker(CEditor *pEditor, CUIRect View) return 0; } -static int g_SelectEntitiesImage = 0; - int CEditor::PopupEntities(CEditor *pEditor, CUIRect View) { - const char *EntitiesChoices[][2] = { - {"Standard", "editor/entities.png"}, - {"Clear DDNet", "editor/entities_clear/ddnet.png"}, - {"Clear DDrace", "editor/entities_clear/ddrace.png"}, - {"Clear Race", "editor/entities_clear/race.png"}, - {"Clear FNG", "editor/entities_clear/fng.png"}, - {"Clear Vanilla", "editor/entities_clear/vanilla.png"}}; - - for(int i = 0; i < (int)(sizeof(EntitiesChoices)/sizeof(*EntitiesChoices)); i++) + for(int i = 0; i < (int)pEditor->m_SelectEntitiesFiles.size(); i++) { CUIRect Button; View.HSplitTop(14.0f, &Button, &View); - if(pEditor->DoButton_MenuItem(EntitiesChoices[i], EntitiesChoices[i][0], i==g_SelectEntitiesImage, &Button)) { - if (i != g_SelectEntitiesImage) { - g_SelectEntitiesImage = i; + const char *Name = pEditor->m_SelectEntitiesFiles[i].c_str(); + + if(pEditor->DoButton_MenuItem(Name, Name, i==pEditor->m_SelectEntitiesImage, &Button)) { + if (i != pEditor->m_SelectEntitiesImage) { + pEditor->m_SelectEntitiesImage = i; + + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "editor/entities/%s.png", Name); + pEditor->Graphics()->UnloadTexture(ms_EntitiesTexture); - ms_EntitiesTexture = pEditor->Graphics()->LoadTexture(EntitiesChoices[i][1], IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); + ms_EntitiesTexture = pEditor->Graphics()->LoadTexture(aBuf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); } } }