Skip to content

Commit

Permalink
* Added a central message box for the editor.
Browse files Browse the repository at this point in the history
* Added a central place for error messages.
* Added the ability to read back texture data to the CPU.
* Added multi-select.
* Added the ability to override the palette for an entire selection or
or reset to default.
* Added the ability to export selected assets.
* Stubbed out the editor project system.
  • Loading branch information
luciusDXL committed Sep 30, 2023
1 parent d029fe2 commit 7444021
Show file tree
Hide file tree
Showing 13 changed files with 585 additions and 14 deletions.
343 changes: 332 additions & 11 deletions TheForceEngine/TFE_Editor/AssetBrowser/assetBrowser.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions TheForceEngine/TFE_Editor/AssetBrowser/assetBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ namespace AssetBrowser

void update();
void render();

void selectAll();
void selectNone();
void invertSelection();
}
94 changes: 92 additions & 2 deletions TheForceEngine/TFE_Editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace TFE_Editor
EDIT_ASSET,
EDIT_LEVEL,
};

struct MessageBox
{
bool active = false;
char id[512];
char msg[TFE_MAX_PATH * 2] = "";
};

static bool s_showPerf = true;
static bool s_showEditor = true;
Expand All @@ -28,6 +35,8 @@ namespace TFE_Editor
static bool s_configView = false;
static WorkBuffer s_workBuffer;

static MessageBox s_msgBox = {};

static ImFont* s_fonts[FONT_COUNT * FONT_SIZE_COUNT] = { 0 };

void menu();
Expand All @@ -46,19 +55,49 @@ namespace TFE_Editor
loadFonts();
loadConfig();
AssetBrowser::init();
s_msgBox = {};
}

void disable()
{
AssetBrowser::destroy();
}

void messageBoxUi()
{
pushFont(FONT_SMALL);
if (ImGui::BeginPopupModal(s_msgBox.id, nullptr, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGuiStyle& style = ImGui::GetStyle();
f32 textWidth = ImGui::CalcTextSize(s_msgBox.msg).x + style.FramePadding.x;
f32 buttonWidth = ImGui::CalcTextSize("OK").x;

ImGui::Text(s_msgBox.msg);
ImGui::Separator();

ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (textWidth - buttonWidth) * 0.5f);
if (ImGui::Button("OK"))
{
s_msgBox.active = false;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
popFont();
}

bool update(bool consoleOpen)
{
TFE_RenderBackend::clearWindow();

if (s_msgBox.active)
{
ImGui::OpenPopup(s_msgBox.id);
}

menu();

if (configSetupRequired())
if (configSetupRequired() && !s_msgBox.active)
{
s_editorMode = EDIT_CONFIG;
}
Expand All @@ -75,9 +114,22 @@ namespace TFE_Editor
AssetBrowser::update();
}

if (s_msgBox.active)
{
messageBoxUi();
}

if (TFE_Input::keyPressed(KEY_ESCAPE))
{
s_exitEditor = true;
if (s_msgBox.active)
{
s_msgBox.active = false;
ImGui::CloseCurrentPopup();
}
else
{
s_exitEditor = true;
}
}

return s_exitEditor;
Expand Down Expand Up @@ -149,6 +201,31 @@ namespace TFE_Editor
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Select"))
{
if (ImGui::MenuItem("Select All", NULL, (bool*)NULL))
{
if (s_editorMode == EDIT_ASSET)
{
AssetBrowser::selectAll();
}
}
if (ImGui::MenuItem("Select None", NULL, (bool*)NULL))
{
if (s_editorMode == EDIT_ASSET)
{
AssetBrowser::selectNone();
}
}
if (ImGui::MenuItem("Invert Selection", NULL, (bool*)NULL))
{
if (s_editorMode == EDIT_ASSET)
{
AssetBrowser::invertSelection();
}
}
ImGui::EndMenu();
}
}
endMenuBar();

Expand Down Expand Up @@ -185,4 +262,17 @@ namespace TFE_Editor
{
ImGui::PopFont();
}

void showMessageBox(const char* type, const char* msg, ...)
{
char fullStr[TFE_MAX_PATH * 2];
va_list arg;
va_start(arg, msg);
vsprintf(fullStr, msg, arg);
va_end(arg);

s_msgBox.active = true;
strcpy(s_msgBox.msg, fullStr);
sprintf(s_msgBox.id, "%s##MessageBox", type);
}
}
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_Editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace TFE_Editor
void pushFont(FontType type);
void popFont();

void showMessageBox(const char* type, const char* msg, ...);

// Resizable temporary memory.
WorkBuffer& getWorkBuffer();
}
42 changes: 42 additions & 0 deletions TheForceEngine/TFE_Editor/editorProject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "editorProject.h"
#include <TFE_Editor/editorConfig.h>
#include <TFE_Editor/editor.h>
#include <TFE_RenderBackend/renderBackend.h>
#include <TFE_System/system.h>
#include <TFE_System/parser.h>
#include <TFE_FileSystem/filestream.h>
#include <TFE_FileSystem/fileutil.h>
#include <TFE_FileSystem/paths.h>
#include <TFE_Archive/archive.h>
#include <TFE_Ui/ui.h>

#include <TFE_Ui/imGUI/imgui.h>

namespace TFE_Editor
{
static Project* s_curProject = nullptr;

Project* getProject()
{
return s_curProject;
}

void closeProject()
{
// TODO: Clear project specific editor data.
s_curProject = nullptr;
}

void saveProject()
{
}

bool ui_loadProject()
{
return false;
}

void ui_newProject()
{
}
}
47 changes: 47 additions & 0 deletions TheForceEngine/TFE_Editor/editorProject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once
//////////////////////////////////////////////////////////////////////
// The Force Engine Editor
// A system built to view and edit Dark Forces data files.
// The viewing aspect needs to be put in place at the beginning
// in order to properly test elements in isolation without having
// to "play" the game as intended.
//////////////////////////////////////////////////////////////////////
#include <TFE_System/types.h>
#include <TFE_FileSystem/paths.h>
#include <TFE_Game/igame.h>
#include <string>

namespace TFE_Editor
{
enum ProjectType
{
PROJ_RESOURCE_ONLY = 0,
PROJ_LEVELS,
PROJ_COUNT
};

enum FeatureSet
{
FSET_VANILLA = 0,
FSET_TFE,
FSET_COUNT
};

struct Project
{
std::string name;
std::string path;
std::string desc;
std::string authors;

ProjectType type;
GameID game;
FeatureSet featureSet;
};

Project* getProject();

bool ui_loadProject();
void ui_closeProject();
void ui_newProject();
}
19 changes: 19 additions & 0 deletions TheForceEngine/TFE_Editor/errorMessages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "errorMessages.h"
#include <assert.h>

namespace TFE_Editor
{
static const char* c_errorMsg[] =
{
// ERROR_INVALID_EXPORT_PATH
"Export Path '%s' is invalid, cannot export assets!\n"
"Please go to the 'Editor' menu, select 'Editor Config',\n"
"and setup a valid 'Export Path'.",
};

const char* getErrorMsg(EditorError err)
{
assert(err >= 0 && err < ERROR_COUNT);
return c_errorMsg[err];
}
}
21 changes: 21 additions & 0 deletions TheForceEngine/TFE_Editor/errorMessages.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
//////////////////////////////////////////////////////////////////////
// The Force Engine Editor
// A system built to view and edit Dark Forces data files.
// The viewing aspect needs to be put in place at the beginning
// in order to properly test elements in isolation without having
// to "play" the game as intended.
//////////////////////////////////////////////////////////////////////
#include <TFE_System/types.h>
#include <vector>

namespace TFE_Editor
{
enum EditorError
{
ERROR_INVALID_EXPORT_PATH = 0,
ERROR_COUNT,
};

const char* getErrorMsg(EditorError err);
}
7 changes: 7 additions & 0 deletions TheForceEngine/TFE_RenderBackend/Win32OpenGL/textureGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,10 @@ void TextureGpu::clearSlots(u32 count, u32 start/* = 0*/)
glBindTexture(GL_TEXTURE_2D, 0);
}
}

void TextureGpu::readCpu(u8* image)
{
glBindTexture(GL_TEXTURE_2D, m_gpuHandle);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glBindTexture(GL_TEXTURE_2D, 0);
}
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_RenderBackend/textureGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class TextureGpu
u32 getHeight() const { return m_height; }
u32 getLayers() const { return m_layers; }

void readCpu(u8* image);

inline u32 getHandle() const { return m_gpuHandle; }

private:
Expand Down
4 changes: 4 additions & 0 deletions TheForceEngine/TheForceEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ echo ^)";
<ClInclude Include="TFE_Editor\EditorAsset\editorSprite.h" />
<ClInclude Include="TFE_Editor\EditorAsset\editorTexture.h" />
<ClInclude Include="TFE_Editor\editorConfig.h" />
<ClInclude Include="TFE_Editor\editorProject.h" />
<ClInclude Include="TFE_Editor\errorMessages.h" />
<ClInclude Include="TFE_FileSystem\filestream.h" />
<ClInclude Include="TFE_FileSystem\fileutil.h" />
<ClInclude Include="TFE_FileSystem\memorystream.h" />
Expand Down Expand Up @@ -811,6 +813,8 @@ echo ^)";
<ClCompile Include="TFE_Editor\EditorAsset\editorSprite.cpp" />
<ClCompile Include="TFE_Editor\EditorAsset\editorTexture.cpp" />
<ClCompile Include="TFE_Editor\editorConfig.cpp" />
<ClCompile Include="TFE_Editor\editorProject.cpp" />
<ClCompile Include="TFE_Editor\errorMessages.cpp" />
<ClCompile Include="TFE_FileSystem\filestream.cpp" />
<ClCompile Include="TFE_FileSystem\fileutil.cpp" />
<ClCompile Include="TFE_FileSystem\memorystream.cpp" />
Expand Down
12 changes: 12 additions & 0 deletions TheForceEngine/TheForceEngine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,12 @@
<ClInclude Include="TFE_Editor\AssetBrowser\assetBrowser.h">
<Filter>Source\TFE_Editor\AssetBrowser</Filter>
</ClInclude>
<ClInclude Include="TFE_Editor\editorProject.h">
<Filter>Source\TFE_Editor</Filter>
</ClInclude>
<ClInclude Include="TFE_Editor\errorMessages.h">
<Filter>Source\TFE_Editor</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
Expand Down Expand Up @@ -2190,6 +2196,12 @@
<ClCompile Include="TFE_Editor\AssetBrowser\assetBrowser.cpp">
<Filter>Source\TFE_Editor\AssetBrowser</Filter>
</ClCompile>
<ClCompile Include="TFE_Editor\editorProject.cpp">
<Filter>Source\TFE_Editor</Filter>
</ClCompile>
<ClCompile Include="TFE_Editor\errorMessages.cpp">
<Filter>Source\TFE_Editor</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="TheForceEngine.rc">
Expand Down
2 changes: 1 addition & 1 deletion TheForceEngine/gitVersion.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const char c_gitVersion[] = R"(
v1.09.530-11-gd9a077bd
v1.09.530-13-gd029fe2b
)";

0 comments on commit 7444021

Please sign in to comment.