Adds new events to the editor

master
Joey Pollack 3 years ago
parent cd541e7d75
commit 73f2e06541

@ -11,5 +11,5 @@ High Importance:
Medium Importance: Medium Importance:
☐ Lines do not rotate correctly ☐ Lines do not rotate correctly
☐ Map Editor can be docked into the main window. The window IDs should prevent this. ☐ Map Editor can be docked into the main window. The window IDs should prevent this.
Map Editor does not grab tile sets if the Map Editor is opened before a project is loaded Map Editor does not grab tile sets if the Map Editor is opened before a project is loaded @done(22-09-07 15:00)
✔ Map Editor paints the wrong tiles when scrolling with the middle mouse button (this may have to do with the parent window having the scroll bar) @done(22-04-07 13:50) ✔ Map Editor paints the wrong tiles when scrolling with the middle mouse button (this may have to do with the parent window having the scroll bar) @done(22-04-07 13:50)

@ -36,17 +36,17 @@ Core:
Graphics: Graphics:
Re-write the renderer: Re-write the renderer:
Implement BeginScene and EndScene - these are called from the World OnRender Implement BeginScene and EndScene - these are called from the World OnRender @done(22-09-07 14:47)
☐ Organize Buffers ✔ Organize Buffers @done(22-09-07 14:47)
☐ Better FrameBuffer system ✔ Better FrameBuffer system @done(22-09-07 14:47)
Texture class - Does NOT load from files - takes raw data to construct Texture class - Does NOT load from files - takes raw data to construct @done(22-09-07 14:47)
☐ Add view matrix to the shader @critical ✔ Add view matrix to the shader @critical @done(22-09-07 14:47)
Remove projection matrix from the renderer internals @critical Remove projection matrix from the renderer internals @critical @done(22-09-07 14:47)
Move the openGL reference out of the Image class (OpenGL ID) and make the ID more generic Move the openGL reference out of the Image class (OpenGL ID) and make the ID more generic @done(22-09-07 14:47)
Add layer to interface API for setting the Images ID in a generic way Add layer to interface API for setting the Images ID in a generic way @done(22-09-07 14:47)
☐ Implement batch rendering @high ✔ Implement batch rendering @high @done(22-09-07 14:45)
☐ Allow vertices to be submitted before rendering ✔ Allow vertices to be submitted before rendering @done(22-09-07 14:45)
☐ Add texture sampler id to the vertex layout ✔ Add texture sampler id to the vertex layout @done(22-09-07 14:45)
✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM) ✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM)
✔ Add FreeType to the project @done (9/7/2021, 2:23:13 PM) ✔ Add FreeType to the project @done (9/7/2021, 2:23:13 PM)
✔ Add a new class for font loading/management and text rendering @done (9/7/2021, 3:57:08 PM) ✔ Add a new class for font loading/management and text rendering @done (9/7/2021, 3:57:08 PM)
@ -56,7 +56,7 @@ Graphics:
✔ Adjust the font loading code to use the binary file buffer instead of ifstream @done (9/17/2021, 6:11:06 PM) ✔ Adjust the font loading code to use the binary file buffer instead of ifstream @done (9/17/2021, 6:11:06 PM)
✔ Find a way to add rotation to shapes and images @done (10/29/2021, 7:35:14 PM) ✔ Find a way to add rotation to shapes and images @done (10/29/2021, 7:35:14 PM)
✔ Add a DrawPolygon method that takes vertices and draws arbirary shapes @done (10/29/2021, 6:24:14 PM) ✔ Add a DrawPolygon method that takes vertices and draws arbirary shapes @done (10/29/2021, 6:24:14 PM)
Allow DrawPolygon to add a texture to the polygon @low Allow DrawPolygon to add a texture to the polygon @low @cancelled(22-09-07 14:48)
✔ Refactor the drawing code to allow for rotation with cleaner code @high @done (10/29/2021, 8:36:24 PM) ✔ Refactor the drawing code to allow for rotation with cleaner code @high @done (10/29/2021, 8:36:24 PM)
✔ Test rotation of images @done (11/1/2021, 2:11:13 PM) ✔ Test rotation of images @done (11/1/2021, 2:11:13 PM)
✔ Fix line rotation @low @done (2/8/2022, 4:39:25 PM) ✔ Fix line rotation @low @done (2/8/2022, 4:39:25 PM)
@ -64,8 +64,8 @@ Graphics:
✔ Allow an image size to be passed in for rendering to an image @high @done (2/3/2022, 4:07:33 PM) ✔ Allow an image size to be passed in for rendering to an image @high @done (2/3/2022, 4:07:33 PM)
GUI: GUI:
☐ Improve the GUI API! ✔ Improve the GUI API! @done(22-09-07 14:48)
Implement a better way to handle popup windows and context menus Implement a better way to handle popup windows and context menus @done(22-09-07 14:48)
✔ Dear ImGui class with basic initialization @done (9/10/2021, 1:42:19 PM) ✔ Dear ImGui class with basic initialization @done (9/10/2021, 1:42:19 PM)
✔ Debug log window @done (9/10/2021, 4:44:48 PM) ✔ Debug log window @done (9/10/2021, 4:44:48 PM)
✔ Add key to show debug log window @done (9/13/2021, 6:47:44 PM) ✔ Add key to show debug log window @done (9/13/2021, 6:47:44 PM)
@ -109,7 +109,9 @@ ECS:
Components: Components:
✔ Tag @done(22-06-23 15:49) ✔ Tag @done(22-06-23 15:49)
☐ Transform ✔ Transform @done(22-09-07 14:49)
✔ Velocity @done(22-09-07 14:49)
✔ Camera @done(22-09-07 14:49)
☐ SpriteRenderer ☐ SpriteRenderer
☐ Animation Controller ☐ Animation Controller
☐ Script ☐ Script

@ -65,8 +65,14 @@ namespace lunarium
void Texture::Destroy(Texture** ppTex) void Texture::Destroy(Texture** ppTex)
{ {
if (!(*ppTex))
{
return;
}
(*ppTex)->Unbind(); (*ppTex)->Unbind();
glDeleteTextures(1, &(*ppTex)->mGLID); glDeleteTextures(1, &(*ppTex)->mGLID);
delete (*ppTex);
(*ppTex) = nullptr; (*ppTex) = nullptr;
} }

@ -84,9 +84,7 @@ namespace lunarium { namespace editor
} }
float rot = comp.Camera.GetRotation(); float rot = comp.Camera.GetRotation();
ImGui::Text("Rotation Angle: "); if (ImGuiExt::FloatControl("Rotation", rot, 0.0f, 85.0f))
ImGui::SameLine();
if (ImGui::DragFloat("##rotation", &rot, 0.5f, 0.0f, 360.0f))
{ {
comp.Camera.SetRotation(rot); comp.Camera.SetRotation(rot);
} }

@ -119,9 +119,9 @@ namespace lunarium { namespace editor
return nlohmann::ordered_json(); return nlohmann::ordered_json();
} }
void World::DrawProperties() bool World::DrawProperties()
{ {
return false;
} }
}} }}

@ -26,7 +26,7 @@ namespace lunarium { namespace editor
ContentManager* ContentManager::mpInstance = nullptr; ContentManager* ContentManager::mpInstance = nullptr;
ContentManager::ContentManager() ContentManager::ContentManager()
: mpProject(nullptr), mNextID(0) : mpProject(nullptr), mNextID(0), mpEditor(nullptr)
{ {
} }
@ -50,6 +50,12 @@ namespace lunarium { namespace editor
} }
} }
void ContentManager::SetEditor(Editor* pEditor)
{
mpEditor = pEditor;
}
OpRes ContentManager::Load(Project* project) OpRes ContentManager::Load(Project* project)
{ {
Unload(); Unload();
@ -149,6 +155,7 @@ namespace lunarium { namespace editor
} }
mAssets[pAsset->mID] = pAsset; mAssets[pAsset->mID] = pAsset;
mpEditor->OnNewAsset(pAsset);
} }
return OpRes::OK(); return OpRes::OK();
@ -273,6 +280,7 @@ namespace lunarium { namespace editor
id = asset->mID; id = asset->mID;
Save().LogIfFailed(Editor::LogCat, "Asset was created"); Save().LogIfFailed(Editor::LogCat, "Asset was created");
mpEditor->OnNewAsset(asset);
return OpRes::OK(); return OpRes::OK();
} }
@ -309,6 +317,8 @@ namespace lunarium { namespace editor
mAssets[pAsset->mID] = pAsset; mAssets[pAsset->mID] = pAsset;
id = pAsset->mID; id = pAsset->mID;
mpEditor->OnNewAsset(pAsset);
return OpRes::OK(); return OpRes::OK();
} }

@ -24,6 +24,7 @@ namespace lunarium { namespace editor
class Project; class Project;
class EditorAsset; class EditorAsset;
class Editor;
class ContentManager class ContentManager
{ {
@ -32,6 +33,8 @@ namespace lunarium { namespace editor
static ContentManager& GetInstance(); static ContentManager& GetInstance();
static void FreeInstance(); static void FreeInstance();
void SetEditor(Editor* pEditor);
[[nodiscard]] OpRes Load(Project* project); [[nodiscard]] OpRes Load(Project* project);
[[nodiscard]] OpRes Save(); [[nodiscard]] OpRes Save();
void Unload(); void Unload();
@ -55,6 +58,7 @@ namespace lunarium { namespace editor
private: private:
static ContentManager* mpInstance; static ContentManager* mpInstance;
Editor* mpEditor;
Project* mpProject; Project* mpProject;
std::filesystem::path mContentFile; std::filesystem::path mContentFile;
std::map<uint64_t, EditorAsset*> mAssets; std::map<uint64_t, EditorAsset*> mAssets;

@ -31,7 +31,8 @@ namespace lunarium { namespace editor
[[nodiscard]] virtual OpRes LoadRawFile() = 0; [[nodiscard]] virtual OpRes LoadRawFile() = 0;
virtual void DrawProperties() = 0; /// @return returns true if the properties were updated
virtual bool DrawProperties() = 0;
// [[nodiscard]] virtual OpRes LoadFromJSON(nlohmann::json& node) = 0; // [[nodiscard]] virtual OpRes LoadFromJSON(nlohmann::json& node) = 0;

@ -153,6 +153,7 @@ namespace lunarium { namespace editor
Sizei map_size_pixels = { mTileSize.Width * mSizeInTiles.Width, mTileSize.Height * mSizeInTiles.Height }; Sizei map_size_pixels = { mTileSize.Width * mSizeInTiles.Width, mTileSize.Height * mSizeInTiles.Height };
// Draw Map // Draw Map
std::vector<int> warned_ids;
for (int i = 0; i < mSizeInTiles.Width; i++) for (int i = 0; i < mSizeInTiles.Width; i++)
{ {
for (int j = 0; j < mSizeInTiles.Height; j++) for (int j = 0; j < mSizeInTiles.Height; j++)
@ -177,6 +178,12 @@ namespace lunarium { namespace editor
} }
TileSet* set = mTileSets[id]; TileSet* set = mTileSets[id];
if (set->GetTileSize() != mTileSize)
{
Logger::Warn(Editor::LogCat, "Tile Map contains tiles from a differently sized Tile Set with id: %d", id);
}
Rectangle dest = Rectangle::MakeFromTopLeft(i * mTileSize.Width, j * mTileSize.Height, mTileSize.Width, mTileSize.Height); Rectangle dest = Rectangle::MakeFromTopLeft(i * mTileSize.Width, j * mTileSize.Height, mTileSize.Width, mTileSize.Height);
Rectangle src = set->GetTileRect(mpMap[i][j].TileIndex); Rectangle src = set->GetTileRect(mpMap[i][j].TileIndex);
@ -204,8 +211,8 @@ namespace lunarium { namespace editor
} }
void TileMap::DrawDebugGUI() bool TileMap::DrawProperties()
{ {
return false;
} }
}} }}

@ -42,7 +42,7 @@ namespace lunarium { namespace editor
// Call during render to texture phase // Call during render to texture phase
void Render(lunarium::Renderer2D* g); void Render(lunarium::Renderer2D* g);
void DrawProperties(); bool DrawProperties();
void DrawDebugGUI(); void DrawDebugGUI();

@ -173,7 +173,7 @@ namespace lunarium { namespace editor
} }
void TileSet::DrawProperties() bool TileSet::DrawProperties()
{ {
int size[2] = { mTileSize.Width, mTileSize.Height }; int size[2] = { mTileSize.Width, mTileSize.Height };
ImGui::Text("Tile Size: "); ImGui::Text("Tile Size: ");
@ -181,6 +181,9 @@ namespace lunarium { namespace editor
if (ImGui::DragInt2("##Tile Size", size)) if (ImGui::DragInt2("##Tile Size", size))
{ {
SetTileSize({size[0], size[1]}); SetTileSize({size[0], size[1]});
return true;
} }
return false;
} }
}} }}

@ -28,7 +28,7 @@ namespace lunarium { namespace editor
OpRes Deserialize(nlohmann::ordered_json& node); OpRes Deserialize(nlohmann::ordered_json& node);
bool IsValidNode(nlohmann::ordered_json& node); bool IsValidNode(nlohmann::ordered_json& node);
nlohmann::ordered_json AsJSON(); nlohmann::ordered_json AsJSON();
void DrawProperties(); bool DrawProperties();
void SetTileSetID(int id); void SetTileSetID(int id);
int GetTileSetID() const; int GetTileSetID() const;

@ -34,7 +34,7 @@ namespace lunarium { namespace editor
[[nodiscord]] virtual bool IsValidNode(nlohmann::ordered_json& node); [[nodiscord]] virtual bool IsValidNode(nlohmann::ordered_json& node);
[[nodiscard]] virtual nlohmann::ordered_json AsJSON(); [[nodiscard]] virtual nlohmann::ordered_json AsJSON();
void DrawProperties(); bool DrawProperties();
lunarium::World* GetWorld(); lunarium::World* GetWorld();
void UnloadWorld(); void UnloadWorld();

@ -7,6 +7,7 @@
******************************************************************************/ ******************************************************************************/
#include "editor.h" #include "editor.h"
#include "editor/contents/editor_asset.h"
#include <utils/helpers.h> #include <utils/helpers.h>
#include <gui/panel_manager.h> #include <gui/panel_manager.h>
@ -27,7 +28,6 @@
// Tools // Tools
#include "tools/map_editor/map_editor.h" #include "tools/map_editor/map_editor.h"
#include <world/components.h>
// Game objects // Game objects
#include <world/world.h> #include <world/world.h>
@ -61,6 +61,8 @@ namespace editor
ImGui::GetIO().ConfigWindowsMoveFromTitleBarOnly = true; ImGui::GetIO().ConfigWindowsMoveFromTitleBarOnly = true;
GUI::GetInstance().SetStyle(GuiStyle::STYLE_CHARCOAL); GUI::GetInstance().SetStyle(GuiStyle::STYLE_CHARCOAL);
ContentManager::GetInstance().SetEditor(this);
// Init editor panels // Init editor panels
mAboutPanel.SetOpen(false); mAboutPanel.SetOpen(false);
@ -73,7 +75,7 @@ namespace editor
mPanelManager.AddPanel(new AssetBrowser("", this), mPanels.AssetBrowser).LogIfFailed(LogCat); mPanelManager.AddPanel(new AssetBrowser("", this), mPanels.AssetBrowser).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldTree(this), mPanels.WorldTree).LogIfFailed(LogCat); mPanelManager.AddPanel(new WorldTree(this), mPanels.WorldTree).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldView(), mPanels.WorldView).LogIfFailed(LogCat); mPanelManager.AddPanel(new WorldView(), mPanels.WorldView).LogIfFailed(LogCat);
mPanelManager.AddPanel(new PropertiesView(), mPanels.PropertiesView).LogIfFailed(LogCat); mPanelManager.AddPanel(new PropertiesView(this), mPanels.PropertiesView).LogIfFailed(LogCat);
return OpRes::OK(); return OpRes::OK();
} }
@ -136,7 +138,7 @@ namespace editor
if (mAboutPanel.IsOpen()) if (mAboutPanel.IsOpen())
{ {
mAboutPanel.DoFrame(); mAboutPanel.OnUIRender();
} }
} }
@ -279,7 +281,7 @@ namespace editor
SetAssetDirectory(outPath.parent_path() / std::filesystem::path("contents/assets")); SetAssetDirectory(outPath.parent_path() / std::filesystem::path("contents/assets"));
} }
if (mpMapEditor) mpMapEditor->ReloadTileSets();
} }
else if (result == FileSystem::DialogResult::CANCEL) else if (result == FileSystem::DialogResult::CANCEL)
{ {
@ -472,5 +474,24 @@ namespace editor
{ {
((PropertiesView*)mPanelManager.GetPanel(mPanels.PropertiesView))->SetSelection(pAsset); ((PropertiesView*)mPanelManager.GetPanel(mPanels.PropertiesView))->SetSelection(pAsset);
} }
void Editor::OnNewAsset(EditorAsset* pAsset)
{
if (pAsset->GetType() == AssetType::EATYPE_TILE_SET)
{
if (mpMapEditor)
{
mpMapEditor->ReloadTileSets();
}
}
}
void Editor::OnAssetUpdate(EditorAsset* pAsset)
{
if (pAsset->GetType() == AssetType::EATYPE_TILE_SET)
{
if (mpMapEditor) mpMapEditor->ReloadTileSets();
}
}
} }
} }

@ -59,6 +59,8 @@ namespace lunarium { namespace editor
void OnEntitySelect(lunarium::Entity* pEnt); void OnEntitySelect(lunarium::Entity* pEnt);
void ChangeWorld(lunarium::World* pWorld); void ChangeWorld(lunarium::World* pWorld);
void OnAssetSelected(EditorAsset* pAsset); void OnAssetSelected(EditorAsset* pAsset);
void OnNewAsset(EditorAsset* pAsset);
void OnAssetUpdate(EditorAsset* pAsset);
private: private:
Editor(const Editor&) = delete; Editor(const Editor&) = delete;

@ -16,18 +16,19 @@ namespace lunarium
namespace editor namespace editor
{ {
AboutPanel::AboutPanel() AboutPanel::AboutPanel()
: Panel("About", PanelDockZone::DDZ_NONE, false, (int)ImGuiWindowFlags_NoCollapse) : Panel("About", PanelDockZone::DDZ_NONE, false, (ImGuiWindowFlags)ImGuiWindowFlags_NoCollapse
| ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoResize)
{ {
} }
void AboutPanel::PreBegin() void AboutPanel::PreBegin()
{ {
ImGui::SetNextWindowSize(ImVec2(300, ImGui::GetFrameHeight() * 20)); ImGui::SetNextWindowSize(ImVec2(200, ImGui::GetFrameHeight() * 10));
} }
void AboutPanel::DoFrame() void AboutPanel::DoFrame()
{ {
ImGui::TextWrapped("Lunarium Editor Version %s - Written by Joey Pollack", Version::GetVersion().ToString().c_str()); ImGui::TextWrapped("Lunarium Editor Version%s\n\t- Written by Joey Pollack", Version::GetVersion().ToString().c_str());
} }
} }
} }

@ -8,6 +8,7 @@
******************************************************************************/ ******************************************************************************/
#include "properties_view.h" #include "properties_view.h"
#include "editor/editor.h"
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <gui/imgui_ext.h> #include <gui/imgui_ext.h>
#include <editor/editor.h> #include <editor/editor.h>
@ -32,9 +33,9 @@ if (ImGui::Selectable(str_name)){\
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {
PropertiesView::PropertiesView() PropertiesView::PropertiesView(Editor* pEditor)
: Panel("Properties", PanelDockZone::DDZ_RIGHT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), : Panel("Properties", PanelDockZone::DDZ_RIGHT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mpSelectedAsset(nullptr), mpSelectedEntity(nullptr), mIsLocked(false) mpSelectedAsset(nullptr), mpSelectedEntity(nullptr), mIsLocked(false), mpEditor(pEditor)
{ {
// ADD COMPONENT POPUP // ADD COMPONENT POPUP
AddPopup(Popup::ADD_COMP, "Add Component", [](Panel* p) AddPopup(Popup::ADD_COMP, "Add Component", [](Panel* p)
@ -183,7 +184,10 @@ namespace lunarium { namespace editor
{ {
if (mpSelectedAsset) if (mpSelectedAsset)
{ {
mpSelectedAsset->DrawProperties(); if (mpSelectedAsset->DrawProperties())
{
mpEditor->OnAssetUpdate(mpSelectedAsset);
}
} }
} }

@ -20,11 +20,12 @@ namespace editor
{ {
class CustromProperty; class CustromProperty;
class EditorAsset; class EditorAsset;
class Editor;
class PropertiesView : public Panel class PropertiesView : public Panel
{ {
public: public:
PropertiesView(); PropertiesView(Editor* pEditor);
void SetSelection(Entity* pEntity); void SetSelection(Entity* pEntity);
void SetSelection(EditorAsset* pAsset); void SetSelection(EditorAsset* pAsset);
@ -33,6 +34,7 @@ namespace editor
private: private:
bool mIsLocked; bool mIsLocked;
Editor* mpEditor;
std::vector<CustromProperty*> mCustomProps; std::vector<CustromProperty*> mCustomProps;
// Only ONE of these should be set at a time // Only ONE of these should be set at a time

@ -53,6 +53,13 @@ namespace lunarium { namespace editor
Open(); Open();
ReloadTileSets();
return OpRes::OK();
}
void MapEditor::ReloadTileSets()
{
std::vector<EditorAsset*> tile_sets; std::vector<EditorAsset*> tile_sets;
ContentManager::GetInstance().GetAllAssetsByType(tile_sets, AssetType::EATYPE_TILE_SET); ContentManager::GetInstance().GetAllAssetsByType(tile_sets, AssetType::EATYPE_TILE_SET);
for (int i = 0; i < tile_sets.size(); i++) for (int i = 0; i < tile_sets.size(); i++)
@ -62,7 +69,21 @@ namespace lunarium { namespace editor
//((TileSetView*)mPanelManager.GetPanel(gui::PanelType::PT_TILE_SET_VIEW))->SetTileSet((TileSet*)tile_sets[i]); //((TileSetView*)mPanelManager.GetPanel(gui::PanelType::PT_TILE_SET_VIEW))->SetTileSet((TileSet*)tile_sets[i]);
} }
return OpRes::OK(); if (mpMap)
{
// Add all tilesets that match the Map's tile size
((TileSetView*)mPanelManager.GetPanel(mPanels.TileSetView))->ClearTileSets();
for (auto iter = mTileSets.begin(); iter != mTileSets.end(); iter++)
{
if (iter->second->GetTileSize() == mpMap->GetTileSize())
{
mpMap->AddTileSet(iter->second->GetTileSetID(), iter->second);
((TileSetView*)mPanelManager.GetPanel(mPanels.TileSetView))->AddTileSet(iter->second);
}
}
((MapCanvas*)mPanelManager.GetPanel(mPanels.MapCanvas))->SetTileMap(mpMap);
}
} }
void MapEditor::Shutdown() void MapEditor::Shutdown()

@ -49,6 +49,7 @@ namespace editor
const std::map<int, TileSet*>* GetTileSets() const; const std::map<int, TileSet*>* GetTileSets() const;
void ReloadTileSets();
void ChangeSelectedTile(TileRef tile); void ChangeSelectedTile(TileRef tile);

@ -168,6 +168,7 @@ namespace lunarium { namespace editor
mTileSets.clear(); mTileSets.clear();
mpSelectedTileSet = nullptr; mpSelectedTileSet = nullptr;
mSelectedTile = {-1, -1}; mSelectedTile = {-1, -1};
Texture::Destroy(&mpViewImage);
Invalidate(true); Invalidate(true);
} }

Loading…
Cancel
Save