Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow editor switch entities #3236 #90

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/engine/shared/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
32 changes: 32 additions & 0 deletions src/game/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CEditor*>(pUser);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/game/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ class CEditor : public IEditor
POPEVENT_LOAD_CURRENT,
POPEVENT_NEW,
POPEVENT_SAVE,
POPEVENT_ENTITIES,
};

int m_PopupEventType;
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions src/game/editor/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"))
Expand Down
Loading