From 0f50ea9709d643b8adade6ecc993ac1a5cab7e38 Mon Sep 17 00:00:00 2001 From: Bamcane Date: Fri, 1 Mar 2024 19:22:18 +0800 Subject: [PATCH] Allow editor switch entities --- src/engine/shared/storage.cpp | 1 + src/game/editor/editor.cpp | 32 ++++++++++++++++++++++++++++++++ src/game/editor/editor.h | 2 ++ src/game/editor/popups.cpp | 13 +++++++++++++ 4 files changed, 48 insertions(+) diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index 4c2605a17a..8543aac3b9 100644 --- a/src/engine/shared/storage.cpp +++ b/src/engine/shared/storage.cpp @@ -70,6 +70,7 @@ class CStorage : public IStorage fs_makedir(GetPath(TYPE_SAVE, "maps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "downloadedmaps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "skins", aPath, sizeof(aPath))); + fs_makedir(GetPath(TYPE_SAVE, "editor", aPath, sizeof(aPath))); } fs_makedir(GetPath(TYPE_SAVE, "dumps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "demos", aPath, sizeof(aPath))); diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index c70987b438..57dca6b588 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -561,6 +561,7 @@ void CEditor::CallbackOpenMap(const char *pFileName, int StorageType, void *pUse pEditor->m_aFileName[0] = 0; } } + void CEditor::CallbackAppendMap(const char *pFileName, int StorageType, void *pUser) { CEditor *pEditor = (CEditor*)pUser; @@ -571,6 +572,7 @@ void CEditor::CallbackAppendMap(const char *pFileName, int StorageType, void *pU pEditor->m_Dialog = DIALOG_NONE; } + void CEditor::CallbackSaveMap(const char *pFileName, int StorageType, void *pUser) { CEditor *pEditor = static_cast(pUser); @@ -592,6 +594,26 @@ void CEditor::CallbackSaveMap(const char *pFileName, int StorageType, void *pUse pEditor->m_Dialog = DIALOG_NONE; } +void CEditor::CallbackOpenEntities(const char *pFileName, int StorageType, void *pUser) +{ + CEditor *pEditor = (CEditor*)pUser; + CImageInfo ImgInfo; + if(!pEditor->Graphics()->LoadPNG(&ImgInfo, pFileName, StorageType)) + return; + + if((ImgInfo.m_Width % 16) || (ImgInfo.m_Height % 16)) + { + pEditor->m_PopupEventType = POPEVENT_ENTITIES; + pEditor->m_PopupEventActivated = true; + return; + } + + pEditor->m_EntitiesTexture = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_MULTI_DIMENSION); + pEditor->m_Map.m_pGameLayer->m_Texture = pEditor->m_EntitiesTexture; + + pEditor->m_Dialog = DIALOG_NONE; +} + void CEditor::DoToolbar(CUIRect ToolBar) { CUIRect TB_Top, TB_Bottom; @@ -3017,6 +3039,16 @@ void CEditor::FilelistPopulate(int StorageType) Item.m_StorageType = IStorage::TYPE_SAVE; m_CompleteFileList.add(Item); } + if(!str_comp(m_pFileDialogPath, "editor")) + { + CFilelistItem Item; + str_copy(Item.m_aFilename, "entities.png", sizeof(Item.m_aFilename)); + str_copy(Item.m_aName, "Vanilla", sizeof(Item.m_aName)); + Item.m_IsDir = false; + Item.m_IsLink = true; + Item.m_StorageType = IStorage::TYPE_ALL; + m_CompleteFileList.add(Item); + } Storage()->ListDirectory(StorageType, m_pFileDialogPath, EditorListdirCallback, this); RefreshFilteredFileList(); m_FilesSelectedIndex = m_FilteredFileList.size() ? 0 : -1; diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 6be2ec26fb..b68a44b7fa 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -652,6 +652,7 @@ class CEditor : public IEditor POPEVENT_LOAD_CURRENT, POPEVENT_NEW, POPEVENT_SAVE, + POPEVENT_ENTITIES, }; int m_PopupEventType; @@ -810,6 +811,7 @@ class CEditor : public IEditor static void CallbackOpenMap(const char *pFileName, int StorageType, void *pUser); static void CallbackAppendMap(const char *pFileName, int StorageType, void *pUser); static void CallbackSaveMap(const char *pFileName, int StorageType, void *pUser); + static void CallbackOpenEntities(const char *pFileName, int StorageType, void *pUser); void PopupSelectImageInvoke(int Current, float x, float y); int PopupSelectImageResult(); diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index fbda32a803..80cf2823eb 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -708,6 +708,8 @@ bool CEditor::PopupEvent(void *pContext, CUIRect View) pEditor->UI()->DoLabel(&Label, "New map", 20.0f, TEXTALIGN_CENTER); else if(pEditor->m_PopupEventType == POPEVENT_SAVE) pEditor->UI()->DoLabel(&Label, "Save map", 20.0f, TEXTALIGN_CENTER); + else if(pEditor->m_PopupEventType == POPEVENT_ENTITIES) + pEditor->UI()->DoLabel(&Label, "Load entities", 20.0f, TEXTALIGN_CENTER); View.HSplitBottom(10.0f, &View, 0); View.HSplitBottom(20.0f, &View, &ButtonBar); @@ -726,6 +728,8 @@ bool CEditor::PopupEvent(void *pContext, CUIRect View) pEditor->UI()->DoLabel(&Label, "The map currently contains unsaved data; you may want to save it before you create a new map.\nContinue anyway?", 10.0f, TEXTALIGN_LEFT, Label.w-10.0f); else if(pEditor->m_PopupEventType == POPEVENT_SAVE) pEditor->UI()->DoLabel(&Label, "This file already exists.\nDo you want to overwrite it?", 10.0f, TEXTALIGN_LEFT); + else if(pEditor->m_PopupEventType == POPEVENT_ENTITIES) + pEditor->UI()->DoLabel(&Label, "The width or height of the entities texture is not divisible by 16", 10.0f, TEXTALIGN_LEFT); // button bar ButtonBar.VSplitLeft(30.0f, 0, &ButtonBar); @@ -1201,6 +1205,7 @@ bool CEditor::PopupMenuFile(void *pContext, CUIRect View) static int s_OpenCurrentButton = 0; static int s_AppendButton = 0; static int s_ExitButton = 0; + static int s_EntitiesButton = 0; CUIRect Slot; View.HSplitTop(2.0f, &Slot, &View); @@ -1282,6 +1287,14 @@ bool CEditor::PopupMenuFile(void *pContext, CUIRect View) return true; } + View.HSplitTop(10.0f, &Slot, &View); + View.HSplitTop(12.0f, &Slot, &View); + if(pEditor->DoButton_MenuItem(&s_EntitiesButton, "Load Entities", 0, &Slot, 0, "Load a image as the editor game entities")) + { + pEditor->InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_IMG, "Load entities", "Load", "editor", "", pEditor->CallbackOpenEntities, pEditor); + return true; + } + View.HSplitTop(10.0f, &Slot, &View); View.HSplitTop(12.0f, &Slot, &View); if(pEditor->DoButton_MenuItem(&s_ExitButton, "Exit", 0, &Slot, 0, "Exits from the editor"))