Merge pull request #9053 from KebsCS/pr-custom-editor-entities

Add custom editor entities
This commit is contained in:
Robert Müller 2024-09-28 08:42:22 +00:00 committed by GitHub
commit 4031cd1b67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 2 deletions

View file

@ -938,6 +938,37 @@ bool CEditor::CallbackSaveSound(const char *pFileName, int StorageType, void *pU
return false;
}
bool CEditor::CallbackCustomEntities(const char *pFileName, int StorageType, void *pUser)
{
CEditor *pEditor = (CEditor *)pUser;
char aBuf[IO_MAX_PATH_LENGTH];
IStorage::StripPathAndExtension(pFileName, aBuf, sizeof(aBuf));
if(std::find(pEditor->m_vSelectEntitiesFiles.begin(), pEditor->m_vSelectEntitiesFiles.end(), std::string(aBuf)) != pEditor->m_vSelectEntitiesFiles.end())
{
pEditor->ShowFileDialogError("Custom entities cannot have the same name as default entities.");
return false;
}
CImageInfo ImgInfo;
if(!pEditor->Graphics()->LoadPng(ImgInfo, pFileName, StorageType))
{
pEditor->ShowFileDialogError("Failed to load image from file '%s'.", pFileName);
return false;
}
pEditor->m_SelectEntitiesImage = aBuf;
pEditor->m_AllowPlaceUnusedTiles = -1;
pEditor->m_PreventUnusedTilesWasWarned = false;
pEditor->Graphics()->UnloadTexture(&pEditor->m_EntitiesTexture);
pEditor->m_EntitiesTexture = pEditor->Graphics()->LoadTextureRawMove(ImgInfo, pEditor->GetTextureUsageFlag());
pEditor->m_Dialog = DIALOG_NONE;
return true;
}
void CEditor::DoAudioPreview(CUIRect View, const void *pPlayPauseButtonId, const void *pStopButtonId, const void *pSeekBarId, int SampleId)
{
CUIRect Button, SeekBar;

View file

@ -910,6 +910,7 @@ public:
static bool CallbackAddTileart(const char *pFilepath, int StorageType, void *pUser);
static bool CallbackSaveImage(const char *pFileName, int StorageType, void *pUser);
static bool CallbackSaveSound(const char *pFileName, int StorageType, void *pUser);
static bool CallbackCustomEntities(const char *pFileName, int StorageType, void *pUser);
void PopupSelectImageInvoke(int Current, float x, float y);
int PopupSelectImageResult();

View file

@ -230,6 +230,7 @@ CUi::EPopupMenuFunctionResult CEditor::PopupMenuSettings(void *pContext, CUIRect
pEditor->m_vSelectEntitiesFiles.clear();
pEditor->Storage()->ListDirectory(IStorage::TYPE_ALL, "editor/entities", EntitiesListdirCallback, pEditor);
std::sort(pEditor->m_vSelectEntitiesFiles.begin(), pEditor->m_vSelectEntitiesFiles.end());
pEditor->m_vSelectEntitiesFiles.emplace_back("Custom…");
static SPopupMenuId s_PopupEntitiesId;
pEditor->Ui()->DoPopupMenu(&s_PopupEntitiesId, Slot.x, Slot.y + Slot.h, 250, pEditor->m_vSelectEntitiesFiles.size() * 14.0f + 10.0f, pEditor, PopupEntities);
@ -2767,12 +2768,17 @@ CUi::EPopupMenuFunctionResult CEditor::PopupEntities(void *pContext, CUIRect Vie
{
if(pEditor->m_vSelectEntitiesFiles[i] != pEditor->m_SelectEntitiesImage)
{
if(i == pEditor->m_vSelectEntitiesFiles.size() - 1)
{
pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_IMG, "Custom Entities", "Load", "assets/entities", false, CallbackCustomEntities, pEditor);
return CUi::POPUP_CLOSE_CURRENT;
}
pEditor->m_SelectEntitiesImage = pEditor->m_vSelectEntitiesFiles[i];
pEditor->m_AllowPlaceUnusedTiles = pEditor->m_SelectEntitiesImage == "DDNet" ? 0 : -1;
pEditor->m_PreventUnusedTilesWasWarned = false;
if(pEditor->m_EntitiesTexture.IsValid())
pEditor->Graphics()->UnloadTexture(&pEditor->m_EntitiesTexture);
pEditor->Graphics()->UnloadTexture(&pEditor->m_EntitiesTexture);
char aBuf[IO_MAX_PATH_LENGTH];
str_format(aBuf, sizeof(aBuf), "editor/entities/%s.png", pName);