Skip to content

Commit 7444021

Browse files
committed
* Added a central message box for the editor.
* 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.
1 parent d029fe2 commit 7444021

File tree

13 files changed

+585
-14
lines changed

13 files changed

+585
-14
lines changed

TheForceEngine/TFE_Editor/AssetBrowser/assetBrowser.cpp

Lines changed: 332 additions & 11 deletions
Large diffs are not rendered by default.

TheForceEngine/TFE_Editor/AssetBrowser/assetBrowser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ namespace AssetBrowser
1515

1616
void update();
1717
void render();
18+
19+
void selectAll();
20+
void selectNone();
21+
void invertSelection();
1822
}

TheForceEngine/TFE_Editor/editor.cpp

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ namespace TFE_Editor
1919
EDIT_ASSET,
2020
EDIT_LEVEL,
2121
};
22+
23+
struct MessageBox
24+
{
25+
bool active = false;
26+
char id[512];
27+
char msg[TFE_MAX_PATH * 2] = "";
28+
};
2229

2330
static bool s_showPerf = true;
2431
static bool s_showEditor = true;
@@ -28,6 +35,8 @@ namespace TFE_Editor
2835
static bool s_configView = false;
2936
static WorkBuffer s_workBuffer;
3037

38+
static MessageBox s_msgBox = {};
39+
3140
static ImFont* s_fonts[FONT_COUNT * FONT_SIZE_COUNT] = { 0 };
3241

3342
void menu();
@@ -46,19 +55,49 @@ namespace TFE_Editor
4655
loadFonts();
4756
loadConfig();
4857
AssetBrowser::init();
58+
s_msgBox = {};
4959
}
5060

5161
void disable()
5262
{
5363
AssetBrowser::destroy();
5464
}
5565

66+
void messageBoxUi()
67+
{
68+
pushFont(FONT_SMALL);
69+
if (ImGui::BeginPopupModal(s_msgBox.id, nullptr, ImGuiWindowFlags_AlwaysAutoResize))
70+
{
71+
ImGuiStyle& style = ImGui::GetStyle();
72+
f32 textWidth = ImGui::CalcTextSize(s_msgBox.msg).x + style.FramePadding.x;
73+
f32 buttonWidth = ImGui::CalcTextSize("OK").x;
74+
75+
ImGui::Text(s_msgBox.msg);
76+
ImGui::Separator();
77+
78+
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (textWidth - buttonWidth) * 0.5f);
79+
if (ImGui::Button("OK"))
80+
{
81+
s_msgBox.active = false;
82+
ImGui::CloseCurrentPopup();
83+
}
84+
ImGui::EndPopup();
85+
}
86+
popFont();
87+
}
88+
5689
bool update(bool consoleOpen)
5790
{
5891
TFE_RenderBackend::clearWindow();
92+
93+
if (s_msgBox.active)
94+
{
95+
ImGui::OpenPopup(s_msgBox.id);
96+
}
97+
5998
menu();
6099

61-
if (configSetupRequired())
100+
if (configSetupRequired() && !s_msgBox.active)
62101
{
63102
s_editorMode = EDIT_CONFIG;
64103
}
@@ -75,9 +114,22 @@ namespace TFE_Editor
75114
AssetBrowser::update();
76115
}
77116

117+
if (s_msgBox.active)
118+
{
119+
messageBoxUi();
120+
}
121+
78122
if (TFE_Input::keyPressed(KEY_ESCAPE))
79123
{
80-
s_exitEditor = true;
124+
if (s_msgBox.active)
125+
{
126+
s_msgBox.active = false;
127+
ImGui::CloseCurrentPopup();
128+
}
129+
else
130+
{
131+
s_exitEditor = true;
132+
}
81133
}
82134

83135
return s_exitEditor;
@@ -149,6 +201,31 @@ namespace TFE_Editor
149201
}
150202
ImGui::EndMenu();
151203
}
204+
if (ImGui::BeginMenu("Select"))
205+
{
206+
if (ImGui::MenuItem("Select All", NULL, (bool*)NULL))
207+
{
208+
if (s_editorMode == EDIT_ASSET)
209+
{
210+
AssetBrowser::selectAll();
211+
}
212+
}
213+
if (ImGui::MenuItem("Select None", NULL, (bool*)NULL))
214+
{
215+
if (s_editorMode == EDIT_ASSET)
216+
{
217+
AssetBrowser::selectNone();
218+
}
219+
}
220+
if (ImGui::MenuItem("Invert Selection", NULL, (bool*)NULL))
221+
{
222+
if (s_editorMode == EDIT_ASSET)
223+
{
224+
AssetBrowser::invertSelection();
225+
}
226+
}
227+
ImGui::EndMenu();
228+
}
152229
}
153230
endMenuBar();
154231

@@ -185,4 +262,17 @@ namespace TFE_Editor
185262
{
186263
ImGui::PopFont();
187264
}
265+
266+
void showMessageBox(const char* type, const char* msg, ...)
267+
{
268+
char fullStr[TFE_MAX_PATH * 2];
269+
va_list arg;
270+
va_start(arg, msg);
271+
vsprintf(fullStr, msg, arg);
272+
va_end(arg);
273+
274+
s_msgBox.active = true;
275+
strcpy(s_msgBox.msg, fullStr);
276+
sprintf(s_msgBox.id, "%s##MessageBox", type);
277+
}
188278
}

TheForceEngine/TFE_Editor/editor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace TFE_Editor
2626
void pushFont(FontType type);
2727
void popFont();
2828

29+
void showMessageBox(const char* type, const char* msg, ...);
30+
2931
// Resizable temporary memory.
3032
WorkBuffer& getWorkBuffer();
3133
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "editorProject.h"
2+
#include <TFE_Editor/editorConfig.h>
3+
#include <TFE_Editor/editor.h>
4+
#include <TFE_RenderBackend/renderBackend.h>
5+
#include <TFE_System/system.h>
6+
#include <TFE_System/parser.h>
7+
#include <TFE_FileSystem/filestream.h>
8+
#include <TFE_FileSystem/fileutil.h>
9+
#include <TFE_FileSystem/paths.h>
10+
#include <TFE_Archive/archive.h>
11+
#include <TFE_Ui/ui.h>
12+
13+
#include <TFE_Ui/imGUI/imgui.h>
14+
15+
namespace TFE_Editor
16+
{
17+
static Project* s_curProject = nullptr;
18+
19+
Project* getProject()
20+
{
21+
return s_curProject;
22+
}
23+
24+
void closeProject()
25+
{
26+
// TODO: Clear project specific editor data.
27+
s_curProject = nullptr;
28+
}
29+
30+
void saveProject()
31+
{
32+
}
33+
34+
bool ui_loadProject()
35+
{
36+
return false;
37+
}
38+
39+
void ui_newProject()
40+
{
41+
}
42+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
//////////////////////////////////////////////////////////////////////
3+
// The Force Engine Editor
4+
// A system built to view and edit Dark Forces data files.
5+
// The viewing aspect needs to be put in place at the beginning
6+
// in order to properly test elements in isolation without having
7+
// to "play" the game as intended.
8+
//////////////////////////////////////////////////////////////////////
9+
#include <TFE_System/types.h>
10+
#include <TFE_FileSystem/paths.h>
11+
#include <TFE_Game/igame.h>
12+
#include <string>
13+
14+
namespace TFE_Editor
15+
{
16+
enum ProjectType
17+
{
18+
PROJ_RESOURCE_ONLY = 0,
19+
PROJ_LEVELS,
20+
PROJ_COUNT
21+
};
22+
23+
enum FeatureSet
24+
{
25+
FSET_VANILLA = 0,
26+
FSET_TFE,
27+
FSET_COUNT
28+
};
29+
30+
struct Project
31+
{
32+
std::string name;
33+
std::string path;
34+
std::string desc;
35+
std::string authors;
36+
37+
ProjectType type;
38+
GameID game;
39+
FeatureSet featureSet;
40+
};
41+
42+
Project* getProject();
43+
44+
bool ui_loadProject();
45+
void ui_closeProject();
46+
void ui_newProject();
47+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "errorMessages.h"
2+
#include <assert.h>
3+
4+
namespace TFE_Editor
5+
{
6+
static const char* c_errorMsg[] =
7+
{
8+
// ERROR_INVALID_EXPORT_PATH
9+
"Export Path '%s' is invalid, cannot export assets!\n"
10+
"Please go to the 'Editor' menu, select 'Editor Config',\n"
11+
"and setup a valid 'Export Path'.",
12+
};
13+
14+
const char* getErrorMsg(EditorError err)
15+
{
16+
assert(err >= 0 && err < ERROR_COUNT);
17+
return c_errorMsg[err];
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
//////////////////////////////////////////////////////////////////////
3+
// The Force Engine Editor
4+
// A system built to view and edit Dark Forces data files.
5+
// The viewing aspect needs to be put in place at the beginning
6+
// in order to properly test elements in isolation without having
7+
// to "play" the game as intended.
8+
//////////////////////////////////////////////////////////////////////
9+
#include <TFE_System/types.h>
10+
#include <vector>
11+
12+
namespace TFE_Editor
13+
{
14+
enum EditorError
15+
{
16+
ERROR_INVALID_EXPORT_PATH = 0,
17+
ERROR_COUNT,
18+
};
19+
20+
const char* getErrorMsg(EditorError err);
21+
}

TheForceEngine/TFE_RenderBackend/Win32OpenGL/textureGpu.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,10 @@ void TextureGpu::clearSlots(u32 count, u32 start/* = 0*/)
234234
glBindTexture(GL_TEXTURE_2D, 0);
235235
}
236236
}
237+
238+
void TextureGpu::readCpu(u8* image)
239+
{
240+
glBindTexture(GL_TEXTURE_2D, m_gpuHandle);
241+
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
242+
glBindTexture(GL_TEXTURE_2D, 0);
243+
}

TheForceEngine/TFE_RenderBackend/textureGpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class TextureGpu
4747
u32 getHeight() const { return m_height; }
4848
u32 getLayers() const { return m_layers; }
4949

50+
void readCpu(u8* image);
51+
5052
inline u32 getHandle() const { return m_gpuHandle; }
5153

5254
private:

TheForceEngine/TheForceEngine.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ echo ^)";
454454
<ClInclude Include="TFE_Editor\EditorAsset\editorSprite.h" />
455455
<ClInclude Include="TFE_Editor\EditorAsset\editorTexture.h" />
456456
<ClInclude Include="TFE_Editor\editorConfig.h" />
457+
<ClInclude Include="TFE_Editor\editorProject.h" />
458+
<ClInclude Include="TFE_Editor\errorMessages.h" />
457459
<ClInclude Include="TFE_FileSystem\filestream.h" />
458460
<ClInclude Include="TFE_FileSystem\fileutil.h" />
459461
<ClInclude Include="TFE_FileSystem\memorystream.h" />
@@ -811,6 +813,8 @@ echo ^)";
811813
<ClCompile Include="TFE_Editor\EditorAsset\editorSprite.cpp" />
812814
<ClCompile Include="TFE_Editor\EditorAsset\editorTexture.cpp" />
813815
<ClCompile Include="TFE_Editor\editorConfig.cpp" />
816+
<ClCompile Include="TFE_Editor\editorProject.cpp" />
817+
<ClCompile Include="TFE_Editor\errorMessages.cpp" />
814818
<ClCompile Include="TFE_FileSystem\filestream.cpp" />
815819
<ClCompile Include="TFE_FileSystem\fileutil.cpp" />
816820
<ClCompile Include="TFE_FileSystem\memorystream.cpp" />

TheForceEngine/TheForceEngine.vcxproj.filters

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,12 @@
12911291
<ClInclude Include="TFE_Editor\AssetBrowser\assetBrowser.h">
12921292
<Filter>Source\TFE_Editor\AssetBrowser</Filter>
12931293
</ClInclude>
1294+
<ClInclude Include="TFE_Editor\editorProject.h">
1295+
<Filter>Source\TFE_Editor</Filter>
1296+
</ClInclude>
1297+
<ClInclude Include="TFE_Editor\errorMessages.h">
1298+
<Filter>Source\TFE_Editor</Filter>
1299+
</ClInclude>
12941300
</ItemGroup>
12951301
<ItemGroup>
12961302
<ClCompile Include="main.cpp">
@@ -2190,6 +2196,12 @@
21902196
<ClCompile Include="TFE_Editor\AssetBrowser\assetBrowser.cpp">
21912197
<Filter>Source\TFE_Editor\AssetBrowser</Filter>
21922198
</ClCompile>
2199+
<ClCompile Include="TFE_Editor\editorProject.cpp">
2200+
<Filter>Source\TFE_Editor</Filter>
2201+
</ClCompile>
2202+
<ClCompile Include="TFE_Editor\errorMessages.cpp">
2203+
<Filter>Source\TFE_Editor</Filter>
2204+
</ClCompile>
21932205
</ItemGroup>
21942206
<ItemGroup>
21952207
<ResourceCompile Include="TheForceEngine.rc">

TheForceEngine/gitVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const char c_gitVersion[] = R"(
2-
v1.09.530-11-gd9a077bd
2+
v1.09.530-13-gd029fe2b
33
)";

0 commit comments

Comments
 (0)