From d19ba4f9798dd4f899bd3c6d809a583df98ab256 Mon Sep 17 00:00:00 2001 From: WiggleWizard <1405402+WiggleWizard@users.noreply.github.com> Date: Mon, 16 Sep 2024 14:49:25 +0100 Subject: [PATCH] Converted last components to new component drawing system --- Editor/src/ComponentsPanel/BonePanel.h | 17 +++---- Editor/src/ComponentsPanel/CameraPanel.h | 17 ++++--- .../ComponentsPanel/CapsuleColliderPanel.h | 31 +++++++------ .../CharacterControllerPanel.h | 20 +++++---- Editor/src/ComponentsPanel/ComponentPanel.h | 6 ++- .../ComponentsPanel/CylinderColliderPanel.h | 31 +++++++------ Editor/src/ComponentsPanel/LightPanel.h | 17 +++---- .../src/ComponentsPanel/MeshColliderPanel.h | 18 ++++---- Editor/src/ComponentsPanel/MeshPanel.h | 12 +++-- .../src/ComponentsPanel/NavMeshVolumePanel.h | 17 ++++--- Editor/src/ComponentsPanel/NetScriptPanel.cpp | 45 +++++++++++++++++-- Editor/src/ComponentsPanel/NetScriptPanel.h | 42 ++--------------- Editor/src/Windows/EditorSelectionPanel.cpp | 33 +++++--------- Editor/src/Windows/EditorSelectionPanel.h | 11 +---- 14 files changed, 155 insertions(+), 162 deletions(-) diff --git a/Editor/src/ComponentsPanel/BonePanel.h b/Editor/src/ComponentsPanel/BonePanel.h index dd1e075b..52e1fa6f 100644 --- a/Editor/src/ComponentsPanel/BonePanel.h +++ b/Editor/src/ComponentsPanel/BonePanel.h @@ -6,19 +6,20 @@ #include #include -class BonePanel : ComponentPanel +class BonePanel { public: - BonePanel() {} - - void Draw(Nuake::Entity entity) override + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { using namespace Nuake; - - if (!entity.HasComponent()) + + Nuake::BoneComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) + { return; - - auto& component = entity.GetComponent(); + } + Nuake::BoneComponent& component = *componentPtr; + BeginComponentTable(BONE, BoneComponent); { { diff --git a/Editor/src/ComponentsPanel/CameraPanel.h b/Editor/src/ComponentsPanel/CameraPanel.h index e162b40d..34b99fa4 100644 --- a/Editor/src/ComponentsPanel/CameraPanel.h +++ b/Editor/src/ComponentsPanel/CameraPanel.h @@ -3,17 +3,20 @@ #include #include "src/FileSystem/FileSystem.h" -class CameraPanel : ComponentPanel { +class CameraPanel { public: - CameraPanel() {} - - void Draw(Nuake::Entity entity) override + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { - if (!entity.HasComponent()) + using namespace Nuake; + + Nuake::CameraComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) + { return; - - auto& component = entity.GetComponent(); + } + Nuake::CameraComponent& component = *componentPtr; + BeginComponentTable(CAMERA, Nuake::CameraComponent); { { diff --git a/Editor/src/ComponentsPanel/CapsuleColliderPanel.h b/Editor/src/ComponentsPanel/CapsuleColliderPanel.h index 6ca7dce6..f6a4f294 100644 --- a/Editor/src/ComponentsPanel/CapsuleColliderPanel.h +++ b/Editor/src/ComponentsPanel/CapsuleColliderPanel.h @@ -3,48 +3,47 @@ #include -class CapsuleColliderPanel : ComponentPanel +class CapsuleColliderPanel { public: - CapsuleColliderPanel() = default; - - void Draw(Nuake::Entity entity) override + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { using namespace Nuake; - - if (!entity.HasComponent()) + + Nuake::CapsuleColliderComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) { return; } - - auto& [Capsule, Radius, Height, IsTrigger] = entity.GetComponent(); + Nuake::CapsuleColliderComponent& component = *componentPtr; + BeginComponentTable(CAPSULE COLLIDER, CapsuleColliderComponent) { { ImGui::Text("Radius"); ImGui::TableNextColumn(); - ImGui::DragFloat("##Radius", &Radius, 0.01f, 0.001f); - Radius = std::max(Radius, 0.001f); + ImGui::DragFloat("##Radius", &component.Radius, 0.01f, 0.001f); + component.Radius = std::max(component.Radius, 0.001f); ImGui::TableNextColumn(); - ComponentTableReset(Radius, 0.5f) + ComponentTableReset(component.Radius, 0.5f) } ImGui::TableNextColumn(); { ImGui::Text("Height"); ImGui::TableNextColumn(); - ImGui::DragFloat("##Height", &Height, 0.01f, 0.001f); - Height = std::max(Height, 0.001f); + ImGui::DragFloat("##Height", &component.Height, 0.01f, 0.001f); + component.Height = std::max(component.Height, 0.001f); ImGui::TableNextColumn(); - ComponentTableReset(Height, 1.0f) + ComponentTableReset(component.Height, 1.0f) } ImGui::TableNextColumn(); { ImGui::Text("Is Trigger"); ImGui::TableNextColumn(); - ImGui::Checkbox("##isTrigger", &IsTrigger); + ImGui::Checkbox("##isTrigger", &component.IsTrigger); ImGui::TableNextColumn(); - ComponentTableReset(IsTrigger, false); + ComponentTableReset(component.IsTrigger, false); } } EndComponentTable() diff --git a/Editor/src/ComponentsPanel/CharacterControllerPanel.h b/Editor/src/ComponentsPanel/CharacterControllerPanel.h index 6e7a1a8c..8d720286 100644 --- a/Editor/src/ComponentsPanel/CharacterControllerPanel.h +++ b/Editor/src/ComponentsPanel/CharacterControllerPanel.h @@ -3,18 +3,20 @@ #include #include "src/FileSystem/FileSystem.h" -class CharacterControllerPanel : ComponentPanel { - +class CharacterControllerPanel +{ public: - CharacterControllerPanel() {} - - void Draw(Nuake::Entity entity) override + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { - if (!entity.HasComponent()) - return; using namespace Nuake; - - auto& component = entity.GetComponent(); + + Nuake::CharacterControllerComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) + { + return; + } + Nuake::CharacterControllerComponent& component = *componentPtr; + BeginComponentTable(CHARACTER CONTROLLER, Nuake::CharacterControllerComponent); { { diff --git a/Editor/src/ComponentsPanel/ComponentPanel.h b/Editor/src/ComponentsPanel/ComponentPanel.h index 0ed64a4d..f3969f36 100644 --- a/Editor/src/ComponentsPanel/ComponentPanel.h +++ b/Editor/src/ComponentsPanel/ComponentPanel.h @@ -93,5 +93,7 @@ ImGui::Text(##name); class ComponentPanel { public: - virtual void Draw(Nuake::Entity entity) = 0; -}; \ No newline at end of file + virtual void Draw(Nuake::Entity entity); +}; + +inline void ComponentPanel::Draw(Nuake::Entity entity) {} diff --git a/Editor/src/ComponentsPanel/CylinderColliderPanel.h b/Editor/src/ComponentsPanel/CylinderColliderPanel.h index a3cfd1fb..aa49729b 100644 --- a/Editor/src/ComponentsPanel/CylinderColliderPanel.h +++ b/Editor/src/ComponentsPanel/CylinderColliderPanel.h @@ -3,48 +3,47 @@ #include -class CylinderColliderPanel : ComponentPanel +class CylinderColliderPanel { public: - CylinderColliderPanel() = default; - - void Draw(Nuake::Entity entity) override + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { using namespace Nuake; - - if (!entity.HasComponent()) + + Nuake::CylinderColliderComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) { return; } - - auto& [Cylinder, Radius, Height, IsTrigger] = entity.GetComponent(); + Nuake::CylinderColliderComponent& component = *componentPtr; + BeginComponentTable(CYLINDER COLLIDER, CylinderColliderComponent) { { ImGui::Text("Radius"); ImGui::TableNextColumn(); - ImGui::DragFloat("##Radius", &Radius, 0.01f, 0.001f); - Radius = std::max(Radius, 0.001f); + ImGui::DragFloat("##Radius", &component.Radius, 0.01f, 0.001f); + component.Radius = std::max(component.Radius, 0.001f); ImGui::TableNextColumn(); - ComponentTableReset(Radius, 0.5f) + ComponentTableReset(component.Radius, 0.5f) } ImGui::TableNextColumn(); { ImGui::Text("Height"); ImGui::TableNextColumn(); - ImGui::DragFloat("##Height", &Height, 0.01f, 0.0001f); - Height = std::max(Height, 0.001f); + ImGui::DragFloat("##Height", &component.Height, 0.01f, 0.0001f); + component.Height = std::max(component.Height, 0.001f); ImGui::TableNextColumn(); - ComponentTableReset(Height, 1.0f) + ComponentTableReset(component.Height, 1.0f) } ImGui::TableNextColumn(); { ImGui::Text("Is Trigger"); ImGui::TableNextColumn(); - ImGui::Checkbox("##isTrigger", &IsTrigger); + ImGui::Checkbox("##isTrigger", &component.IsTrigger); ImGui::TableNextColumn(); - ComponentTableReset(IsTrigger, false); + ComponentTableReset(component.IsTrigger, false); } } EndComponentTable() diff --git a/Editor/src/ComponentsPanel/LightPanel.h b/Editor/src/ComponentsPanel/LightPanel.h index 794ccece..07204b6f 100644 --- a/Editor/src/ComponentsPanel/LightPanel.h +++ b/Editor/src/ComponentsPanel/LightPanel.h @@ -2,17 +2,18 @@ #include "ComponentPanel.h" #include "src/Scene/Components/LightComponent.h" -class LightPanel :ComponentPanel { - +class LightPanel +{ public: - LightPanel() { } - void Draw(Nuake::Entity entity) override + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { - if (!entity.HasComponent()) - return; - - Nuake::LightComponent& component = entity.GetComponent(); + Nuake::LightComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) + { + return; + } + Nuake::LightComponent& component = *componentPtr; BeginComponentTable(LIGHT, Nuake::LightComponent); { diff --git a/Editor/src/ComponentsPanel/MeshColliderPanel.h b/Editor/src/ComponentsPanel/MeshColliderPanel.h index bfbe5012..ef77abc6 100644 --- a/Editor/src/ComponentsPanel/MeshColliderPanel.h +++ b/Editor/src/ComponentsPanel/MeshColliderPanel.h @@ -9,23 +9,25 @@ #include #include -class MeshColliderPanel : ComponentPanel { -private: - Scope _modelInspector; - bool _expanded = false; +class MeshColliderPanel : ComponentPanel +{ public: MeshColliderPanel() { CreateScope(); } - void Draw(Nuake::Entity entity) override + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { using namespace Nuake; - if (!entity.HasComponent()) + + Nuake::MeshColliderComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) + { return; - - MeshColliderComponent& component = entity.GetComponent(); + } + Nuake::MeshColliderComponent& component = *componentPtr; + BeginComponentTable(MESH, MeshColliderComponent); { ImGui::Text("Model"); diff --git a/Editor/src/ComponentsPanel/MeshPanel.h b/Editor/src/ComponentsPanel/MeshPanel.h index a38639f3..15770266 100644 --- a/Editor/src/ComponentsPanel/MeshPanel.h +++ b/Editor/src/ComponentsPanel/MeshPanel.h @@ -26,13 +26,17 @@ public: CreateScope(); } - void Draw(Nuake::Entity entity) override + void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { using namespace Nuake; - if (!entity.HasComponent()) + + Nuake::ModelComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) + { return; - - ModelComponent& component = entity.GetComponent(); + } + Nuake::ModelComponent& component = *componentPtr; + BeginComponentTable(MESH, ModelComponent); { ImGui::Text("Model"); diff --git a/Editor/src/ComponentsPanel/NavMeshVolumePanel.h b/Editor/src/ComponentsPanel/NavMeshVolumePanel.h index b6c8e878..1994864d 100644 --- a/Editor/src/ComponentsPanel/NavMeshVolumePanel.h +++ b/Editor/src/ComponentsPanel/NavMeshVolumePanel.h @@ -8,21 +8,20 @@ #include #include -class NavMeshVolumePanel : ComponentPanel { - +class NavMeshVolumePanel +{ public: - NavMeshVolumePanel() {} - - void Draw(Nuake::Entity entity) override + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) { using namespace Nuake; - - if (!entity.HasComponent()) + + Nuake::NavMeshVolumeComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) { return; } - - auto& component = entity.GetComponent(); + Nuake::NavMeshVolumeComponent& component = *componentPtr; + BeginComponentTable(NAVMESH VOLUME, NavMeshVolumeComponent); { { diff --git a/Editor/src/ComponentsPanel/NetScriptPanel.cpp b/Editor/src/ComponentsPanel/NetScriptPanel.cpp index ed046e0c..488200f2 100644 --- a/Editor/src/ComponentsPanel/NetScriptPanel.cpp +++ b/Editor/src/ComponentsPanel/NetScriptPanel.cpp @@ -8,13 +8,50 @@ #include #include +const std::string NET_TEMPLATE_SCRIPT_FIRST = R"(using Nuake.Net; -void NetScriptPanel::Draw(Nuake::Entity entity) +namespace NuakeShowcase { - if (!entity.HasComponent()) - return; + class )"; - auto& component = entity.GetComponent(); +const std::string NET_TEMPLATE_SCRIPT_SECOND = R"( : Entity + { + public override void OnInit() + { + // Called once at the start of the game + } + + + public override void OnUpdate(float dt) + { + // Called every frame + } + + public override void OnFixedUpdate(float dt) + { + // Called every fixed update + } + + + public override void OnDestroy() + { + // Called at the end of the game fixed update + } + } +} +)"; + +void NetScriptPanel::Draw(Nuake::Entity& entity, entt::meta_any& componentInstance) +{ + using namespace Nuake; + + Nuake::NetScriptComponent* componentPtr = componentInstance.try_cast(); + if (componentPtr == nullptr) + { + return; + } + Nuake::NetScriptComponent& component = *componentPtr; + BeginComponentTable(.NETSCRIPT, Nuake::NetScriptComponent); { { diff --git a/Editor/src/ComponentsPanel/NetScriptPanel.h b/Editor/src/ComponentsPanel/NetScriptPanel.h index 83bd725c..8cd6d7b3 100644 --- a/Editor/src/ComponentsPanel/NetScriptPanel.h +++ b/Editor/src/ComponentsPanel/NetScriptPanel.h @@ -1,45 +1,9 @@ #pragma once + #include "ComponentPanel.h" - -const std::string NET_TEMPLATE_SCRIPT_FIRST = R"(using Nuake.Net; - -namespace NuakeShowcase +class NetScriptPanel { - class )"; - -const std::string NET_TEMPLATE_SCRIPT_SECOND = R"( : Entity - { - public override void OnInit() - { - // Called once at the start of the game - } - - - public override void OnUpdate(float dt) - { - // Called every frame - } - - public override void OnFixedUpdate(float dt) - { - // Called every fixed update - } - - - public override void OnDestroy() - { - // Called at the end of the game fixed update - } - } -} -)"; - - -class NetScriptPanel : ComponentPanel { - public: - NetScriptPanel() {} - - void Draw(Nuake::Entity entity) override; + static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance); }; \ No newline at end of file diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index 6c150868..e704bb3e 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -28,6 +28,17 @@ EditorSelectionPanel::EditorSelectionPanel() virtualScene = CreateRef(); virtualScene->SetName("Virtual Scene"); virtualScene->CreateEntity("Camera").AddComponent(); + + RegisterComponentDrawer(); + RegisterComponentDrawer(&meshPanel); + RegisterComponentDrawer(); + RegisterComponentDrawer(); + RegisterComponentDrawer(); + RegisterComponentDrawer(); + RegisterComponentDrawer(); + RegisterComponentDrawer(); + RegisterComponentDrawer(); + RegisterComponentDrawer(); RegisterTypeDrawer(this); RegisterTypeDrawer(this); @@ -156,28 +167,6 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) } } - - // Draw each component properties panels. - mLightPanel.Draw(entity); - mNetScriptPanel.Draw(entity); - // mAudioEmitterPanel.Draw(entity); - // mParticleEmitterPanel.Draw(entity); - // mSpritePanel.Draw(entity); - mMeshPanel.Draw(entity); - // mSkinnedModelPanel.Draw(entity); - mBonePanel.Draw(entity); - // mQuakeMapPanel.Draw(entity); - mCameraPanel.Draw(entity); - // mRigidbodyPanel.Draw(entity); - // mBoxColliderPanel.Draw(entity); - // mSphereColliderPanel.Draw(entity); - mCapsuleColliderPanel.Draw(entity); - mCylinderColliderPanel.Draw(entity); - mMeshColliderPanel.Draw(entity); - mCharacterControllerPanel.Draw(entity); - mNavMeshVolumePanel.Draw(entity); - // mUiPanel.Draw(entity); - using namespace Nuake; float availWidth = ImGui::GetContentRegionAvail().x; diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 387b6603..6903db8e 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -33,16 +33,7 @@ class EditorSelectionPanel private: TransformPanel mTransformPanel; - LightPanel mLightPanel; - NetScriptPanel mNetScriptPanel; - MeshPanel mMeshPanel; - CameraPanel mCameraPanel; - MeshColliderPanel mMeshColliderPanel; - CapsuleColliderPanel mCapsuleColliderPanel; - CylinderColliderPanel mCylinderColliderPanel; - CharacterControllerPanel mCharacterControllerPanel; - BonePanel mBonePanel; - NavMeshVolumePanel mNavMeshVolumePanel; + MeshPanel meshPanel; Ref currentFile; Ref selectedResource;