mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 05:58:19 +00:00
Add custom editor entities
This commit is contained in:
parent
2a64dac091
commit
486de46f9d
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue