Adds new events to the editor

master
Joey Pollack 3 years ago
parent cd541e7d75
commit 73f2e06541

@ -11,5 +11,5 @@ High Importance:
Medium Importance:
☐ Lines do not rotate correctly
☐ 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)

@ -36,17 +36,17 @@ Core:
Graphics:
Re-write the renderer:
Implement BeginScene and EndScene - these are called from the World OnRender
☐ Organize Buffers
☐ Better FrameBuffer system
Texture class - Does NOT load from files - takes raw data to construct
☐ Add view matrix to the shader @critical
Remove projection matrix from the renderer internals @critical
Move the openGL reference out of the Image class (OpenGL ID) and make the ID more generic
Add layer to interface API for setting the Images ID in a generic way
☐ Implement batch rendering @high
☐ Allow vertices to be submitted before rendering
☐ Add texture sampler id to the vertex layout
Implement BeginScene and EndScene - these are called from the World OnRender @done(22-09-07 14:47)
✔ Organize Buffers @done(22-09-07 14:47)
✔ Better FrameBuffer system @done(22-09-07 14:47)
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 @done(22-09-07 14:47)
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 @done(22-09-07 14:47)
Add layer to interface API for setting the Images ID in a generic way @done(22-09-07 14:47)
✔ Implement batch rendering @high @done(22-09-07 14:45)
✔ Allow vertices to be submitted before rendering @done(22-09-07 14:45)
✔ 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)
✔ 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)
@ -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)
✔ 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)
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)
✔ Test rotation of images @done (11/1/2021, 2:11:13 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)
GUI:
☐ Improve the GUI API!
Implement a better way to handle popup windows and context menus
✔ Improve the GUI API! @done(22-09-07 14:48)
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)
✔ 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)
@ -109,7 +109,9 @@ ECS:
Components:
✔ 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
☐ Animation Controller
☐ Script

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

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

@ -119,9 +119,9 @@ namespace lunarium { namespace editor
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()
: 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)
{
Unload();
@ -149,6 +155,7 @@ namespace lunarium { namespace editor
}
mAssets[pAsset->mID] = pAsset;
mpEditor->OnNewAsset(pAsset);
}
return OpRes::OK();
@ -273,6 +280,7 @@ namespace lunarium { namespace editor
id = asset->mID;
Save().LogIfFailed(Editor::LogCat, "Asset was created");
mpEditor->OnNewAsset(asset);
return OpRes::OK();
}
@ -309,6 +317,8 @@ namespace lunarium { namespace editor
mAssets[pAsset->mID] = pAsset;
id = pAsset->mID;
mpEditor->OnNewAsset(pAsset);
return OpRes::OK();
}

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

@ -31,7 +31,8 @@ namespace lunarium { namespace editor
[[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;

@ -153,6 +153,7 @@ namespace lunarium { namespace editor
Sizei map_size_pixels = { mTileSize.Width * mSizeInTiles.Width, mTileSize.Height * mSizeInTiles.Height };
// Draw Map
std::vector<int> warned_ids;
for (int i = 0; i < mSizeInTiles.Width; i++)
{
for (int j = 0; j < mSizeInTiles.Height; j++)
@ -177,6 +178,12 @@ namespace lunarium { namespace editor
}
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 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
void Render(lunarium::Renderer2D* g);
void DrawProperties();
bool DrawProperties();
void DrawDebugGUI();

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

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

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

@ -7,6 +7,7 @@
******************************************************************************/
#include "editor.h"
#include "editor/contents/editor_asset.h"
#include <utils/helpers.h>
#include <gui/panel_manager.h>
@ -27,7 +28,6 @@
// Tools
#include "tools/map_editor/map_editor.h"
#include <world/components.h>
// Game objects
#include <world/world.h>
@ -61,6 +61,8 @@ namespace editor
ImGui::GetIO().ConfigWindowsMoveFromTitleBarOnly = true;
GUI::GetInstance().SetStyle(GuiStyle::STYLE_CHARCOAL);
ContentManager::GetInstance().SetEditor(this);
// Init editor panels
mAboutPanel.SetOpen(false);
@ -73,7 +75,7 @@ namespace editor
mPanelManager.AddPanel(new AssetBrowser("", this), mPanels.AssetBrowser).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldTree(this), mPanels.WorldTree).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();
}
@ -136,7 +138,7 @@ namespace editor
if (mAboutPanel.IsOpen())
{
mAboutPanel.DoFrame();
mAboutPanel.OnUIRender();
}
}
@ -278,8 +280,8 @@ namespace editor
((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))->
SetAssetDirectory(outPath.parent_path() / std::filesystem::path("contents/assets"));
}
if (mpMapEditor) mpMapEditor->ReloadTileSets();
}
else if (result == FileSystem::DialogResult::CANCEL)
{
@ -472,5 +474,24 @@ namespace editor
{
((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 ChangeWorld(lunarium::World* pWorld);
void OnAssetSelected(EditorAsset* pAsset);
void OnNewAsset(EditorAsset* pAsset);
void OnAssetUpdate(EditorAsset* pAsset);
private:
Editor(const Editor&) = delete;

@ -16,18 +16,19 @@ namespace lunarium
namespace editor
{
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()
{
ImGui::SetNextWindowSize(ImVec2(300, ImGui::GetFrameHeight() * 20));
ImGui::SetNextWindowSize(ImVec2(200, ImGui::GetFrameHeight() * 10));
}
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 "editor/editor.h"
#include <dearimgui/imgui.h>
#include <gui/imgui_ext.h>
#include <editor/editor.h>
@ -32,9 +33,9 @@ if (ImGui::Selectable(str_name)){\
namespace lunarium { namespace editor
{
PropertiesView::PropertiesView()
PropertiesView::PropertiesView(Editor* pEditor)
: 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
AddPopup(Popup::ADD_COMP, "Add Component", [](Panel* p)
@ -183,7 +184,10 @@ namespace lunarium { namespace editor
{
if (mpSelectedAsset)
{
mpSelectedAsset->DrawProperties();
if (mpSelectedAsset->DrawProperties())
{
mpEditor->OnAssetUpdate(mpSelectedAsset);
}
}
}

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

@ -53,6 +53,13 @@ namespace lunarium { namespace editor
Open();
ReloadTileSets();
return OpRes::OK();
}
void MapEditor::ReloadTileSets()
{
std::vector<EditorAsset*> tile_sets;
ContentManager::GetInstance().GetAllAssetsByType(tile_sets, AssetType::EATYPE_TILE_SET);
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]);
}
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()

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

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

Loading…
Cancel
Save