List all game layer entities images in directory

This commit is contained in:
Tim Schumacher 2018-10-02 23:08:17 +02:00
parent bee694a8cb
commit fd52bc7a26
No known key found for this signature in database
GPG key ID: A3D69E3DA9A0FF34
4 changed files with 41 additions and 17 deletions

View file

Before

Width:  |  Height:  |  Size: 331 KiB

After

Width:  |  Height:  |  Size: 331 KiB

View file

@ -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 <algorithm>
#include <base/tl/array.h>
#include <base/system.h>
#include <base/color.h>
@ -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);

View file

@ -3,6 +3,8 @@
#ifndef GAME_EDITOR_EDITOR_H
#define GAME_EDITOR_EDITOR_H
#include <vector>
#include <string>
#include <math.h>
#include <base/math.h>
@ -856,6 +858,9 @@ public:
int m_FilesCur;
int m_FilesStopAt;
std::vector<std::string> m_SelectEntitiesFiles;
int m_SelectEntitiesImage;
float m_WorldOffsetX;
float m_WorldOffsetY;
float m_EditorOffsetX;

View file

@ -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);
}
}
}