Commit d6eff563 authored by Johannes Braun's avatar Johannes Braun
Browse files

Added ability to rename nodes.

parent 16c0b334
......@@ -189,6 +189,10 @@ void drawSceneWindow()
{
ImGui::OpenPopup("attach_scene");
}
if (ImGui::FeatureButton("Rename Node", ImVec2(ImGui::GetContentRegionAvailWidth(), 32)))
{
ImGui::OpenPopup("rn_curr_node");
}
if(ImGui::BeginPopup("del_curr_node"))
{
......@@ -229,6 +233,27 @@ void drawSceneWindow()
ImGui::EndPopup();
}
if (ImGui::BeginPopup("rn_curr_node"))
{
ImGui::Text("What shall be the name of the new node?");
static char buf[64] = {};
ImGui::InputText("Node Name", buf, 128);
if (ImGui::AntiFeatureButton("Rename!"))
{
if (selected_node)
selected_node->rename(buf);
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel"))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
if (ImGui::BeginPopup("attach_scene"))
{
static auto root = current_scene_root;
......@@ -274,28 +299,33 @@ void drawSceneWindow()
case 2: // Components (if available)
selected_node->iterateComponentsStable([](core::GraphNodeComponent& component)
{
component.onGui();
if (ImGui::AntiFeatureButton("Delete", ImVec2(ImGui::GetContentRegionAvailWidth(), 24)))
{
ImGui::OpenPopup("del_comp");
}
if (ImGui::BeginPopup("del_comp"))
ImGui::PushID(("component-"+std::to_string(component.id())).c_str());
if (ImGui::CollapsingHeader(component.typeName().c_str()))
{
ImGui::Text("Do you really want to delete this node?");
if (ImGui::AntiFeatureButton("Yes"))
component.onGui();
if (ImGui::AntiFeatureButton("Delete", ImVec2(ImGui::GetContentRegionAvailWidth(), 24)))
{
component.detachAs<core::GraphNodeComponent>();
ImGui::CloseCurrentPopup();
ImGui::OpenPopup("del_comp");
}
ImGui::SameLine();
if (ImGui::Button("No"))
if (ImGui::BeginPopup("del_comp"))
{
ImGui::CloseCurrentPopup();
ImGui::Text("Do you really want to delete this node?");
if (ImGui::AntiFeatureButton("Yes"))
{
component.detachAs<core::GraphNodeComponent>();
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("No"))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
ImGui::EndPopup();
}
ImGui::PopID();
ImGui::Spacing();
});
......
......@@ -7,6 +7,11 @@
namespace glare::component
{
FramerateCounter::FramerateCounter()
: GraphNodeComponent("Framerate Counter")
{
}
void FramerateCounter::onUpdate()
{
frame++;
......
......@@ -8,6 +8,8 @@ namespace glare::component
class FramerateCounter : public core::GraphNodeComponent
{
public:
FramerateCounter();
void onUpdate() override;
private:
......
......@@ -12,7 +12,7 @@ namespace glare::component
size_t PlayerController::s_current_id = 0;
PlayerController::PlayerController()
: m_id(s_current_id++)
: GraphNodeComponent("Player Controller"), m_id(s_current_id++)
{
core::Callbacks::addKeyActionCallback("player_controller" + std::to_string(m_id), std::bind(&PlayerController::onKeyAction, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
core::Callbacks::addMouseButtonCallback("player_controller" + std::to_string(m_id), std::bind(&PlayerController::onMouseButtonAction, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
......@@ -79,15 +79,9 @@ namespace glare::component
void PlayerController::onGui()
{
if (isPossessed())
{
if (ImGui::ComponentHeader("Player Controller", owner()->name().c_str(), GraphNodeComponent::id()))
{
ImGui::DragFloat("Movement Speed", &m_speed, 0.5f);
ImGui::DragFloat("Rotation Speed", &m_rotation_speed, 0.01f);
ImGui::DragFloat("Shift Multiplier", &m_boost, 0.5f);
}
}
ImGui::DragFloat("Movement Speed", &m_speed, 0.5f);
ImGui::DragFloat("Rotation Speed", &m_rotation_speed, 0.01f);
ImGui::DragFloat("Shift Multiplier", &m_boost, 0.5f);
}
void PlayerController::onUpdate()
......
......@@ -5,6 +5,7 @@ namespace glare::component
{
Rotator::Rotator()
: GraphNodeComponent("Rotator")
{
}
......
......@@ -3,6 +3,7 @@
namespace glare::core
{
SoundSource::SoundSource()
: GraphNodeComponent("Sound Source")
{
al::sourcef(m_source, al::SourceParam::ePitch, m_pitch);
al::sourcef(m_source, al::SourceParam::eGain, m_gain);
......
......@@ -2,6 +2,7 @@
#define INCLUDE_COMPONENT_H
#include <memory>
#include <string>
namespace glare::core
{
......@@ -18,6 +19,7 @@ namespace glare::core
friend class ComponentContainer<GraphNode, GraphNodeComponent>;
friend class GraphNode;
public:
GraphNodeComponent(const std::string& type_name) : m_type_name(type_name) {}
virtual ~GraphNodeComponent();
/**
......@@ -36,8 +38,10 @@ namespace glare::core
std::shared_ptr<T> detachAs();
std::shared_ptr<GraphNode> owner() const;
uint64_t id();
const std::string& typeName() const;
private:
std::string m_type_name;
std::weak_ptr<GraphNode> m_owner;
uint64_t m_id = 0;
};
......@@ -84,6 +88,11 @@ namespace glare::core
}
return m_id;
}
inline const std::string& GraphNodeComponent::typeName() const
{
return m_type_name;
}
}
#include "node.h"
......
......@@ -70,4 +70,9 @@ namespace glare::core
{
return m_name;
}
void GraphNode::rename(const std::string& name)
{
m_name = name;
}
}
......@@ -44,6 +44,7 @@ namespace glare::core
glm::mat4 absoluteTransform() const;
std::string name() const;
void rename(const std::string& name);
math::Transform transform;
......
......@@ -8,12 +8,12 @@
namespace glare::core
{
Camera::Camera(unsigned int width, unsigned int height, Projection projection)
: m_width(width), m_height(height), m_projection(projection)
: GraphNodeComponent("Camera"), m_width(width), m_height(height), m_projection(projection)
{
}
Camera::Camera()
: m_adapt_to_screen(true), m_width(state::window->getWidth()), m_height(state::window->getHeight()), m_projection(Projection::ePerspective)
: GraphNodeComponent("Camera"), m_adapt_to_screen(true), m_width(state::window->getWidth()), m_height(state::window->getHeight()), m_projection(Projection::ePerspective)
{
}
......@@ -23,22 +23,19 @@ namespace glare::core
}
void Camera::onGui()
{
if (ImGui::ComponentHeader("Camera", owner()->name().c_str(), id()))
{
ImGui::PushID(owner()->name().c_str());
if (ImGui::DragFloat("Focus Distance", &m_focus_distance, 0.05f, 0.05f, 10000.f))
messaging::Handler::getInstance().submit(tags::camera, 1);
if (ImGui::DragFloat("DOF Size", &m_dof_size, 0.05f, 0.05f, 10000.f))
messaging::Handler::getInstance().submit(tags::camera, 1);
if (ImGui::Button("Make Default"))
{
ImGui::PushID(owner()->name().c_str());
if (ImGui::DragFloat("Focus Distance", &m_focus_distance, 0.05f, 0.05f, 10000.f))
messaging::Handler::getInstance().submit(tags::camera, 1);
if (ImGui::DragFloat("DOF Size", &m_dof_size, 0.05f, 0.05f, 10000.f))
messaging::Handler::getInstance().submit(tags::camera, 1);
if (ImGui::Button("Make Default"))
{
core::state::camera = std::static_pointer_cast<Camera>(shared_from_this());
messaging::Handler::getInstance().submit(tags::camera, 1);
}
ImGui::PopID();
core::state::camera = std::static_pointer_cast<Camera>(shared_from_this());
messaging::Handler::getInstance().submit(tags::camera, 1);
}
ImGui::PopID();
}
float Camera::getFocusDistance() const
......
......@@ -11,7 +11,7 @@
namespace glare::core
{
LightComponent::LightComponent(color::rgba32f color, LightParameters data) : m_color(color), m_data(data)
LightComponent::LightComponent(color::rgba32f color, LightParameters data) : GraphNodeComponent("Light"), m_color(color), m_data(data)
{
}
......@@ -112,87 +112,83 @@ namespace glare::core
void LightComponent::onGui()
{
if (ImGui::ComponentHeader("Light", owner()->name().c_str(), id()))
{
bool changed = false;
ImGui::PushID(owner()->name().c_str());
bool changed = false;
ImGui::PushID(owner()->name().c_str());
ImGui::ColorButton(*reinterpret_cast<ImVec4*>(&m_color));
ImGui::SameLine();
changed |= ImGui::DragFloat3("Color", reinterpret_cast<float*>(&m_color), 0.01f, 0, 10000);
ImGui::ColorButton(*reinterpret_cast<ImVec4*>(&m_color));
ImGui::SameLine();
changed |= ImGui::DragFloat3("Color", reinterpret_cast<float*>(&m_color), 0.01f, 0, 10000);
static const auto attenuationItem = [this](Attenuation& attenuation) -> bool
{
ImGui::Title("Attenuation");
return ImGui::DragFloat("Constant", &(attenuation.constant), 0.01f, 0.f, 10000.f)
| ImGui::DragFloat("Linear", &(attenuation.linear), 0.01f, 0.f, 10000.f)
| ImGui::DragFloat("Quadratic", &(attenuation.quadratic), 0.01f, 0.f, 10000.f);
};
switch (m_data.light_type)
{
default:
case LightType::ePoint:
{
ImGui::Title("Point Light Settings");
changed |= ImGui::DragFloat("Radius", &(m_data.data.point.radius), 0.01f, 0.f, 10000.f);
changed |= attenuationItem(m_data.data.point.attenuation);
} break;
case LightType::eDirectional:
{
ImGui::Title("Directional Light Settings");
changed |= ImGui::DragFloat("Constant", &(m_data.data.directional.radius), 0.01f, 0.f, 10000.f);
} break;
case LightType::eSpot:
{
ImGui::Title("Spot Light Settings");
changed |= ImGui::DragFloat("Radius", &(m_data.data.spot.radius), 0.01f, 0.f, 10000.f);
static const auto attenuationItem = [this](Attenuation& attenuation) -> bool
{
ImGui::Title("Attenuation");
return ImGui::DragFloat("Constant", &(attenuation.constant), 0.01f, 0.f, 10000.f)
| ImGui::DragFloat("Linear", &(attenuation.linear), 0.01f, 0.f, 10000.f)
| ImGui::DragFloat("Quadratic", &(attenuation.quadratic), 0.01f, 0.f, 10000.f);
};
switch (m_data.light_type)
{
default:
case LightType::ePoint:
{
ImGui::Title("Point Light Settings");
changed |= ImGui::DragFloat("Radius", &(m_data.data.point.radius), 0.01f, 0.f, 10000.f);
changed |= attenuationItem(m_data.data.point.attenuation);
} break;
case LightType::eDirectional:
{
ImGui::Title("Directional Light Settings");
changed |= ImGui::DragFloat("Constant", &(m_data.data.directional.radius), 0.01f, 0.f, 10000.f);
} break;
case LightType::eSpot:
{
ImGui::Title("Spot Light Settings");
changed |= ImGui::DragFloat("Radius", &(m_data.data.spot.radius), 0.01f, 0.f, 10000.f);
float angle_deg = glm::degrees(m_data.data.spot.angle);
changed |= ImGui::DragFloat("Angle", &(angle_deg), 0.01f, 0.f, 10000.f);
m_data.data.spot.angle = glm::radians(angle_deg);
float angle_deg = glm::degrees(m_data.data.spot.angle);
changed |= ImGui::DragFloat("Angle", &(angle_deg), 0.01f, 0.f, 10000.f);
m_data.data.spot.angle = glm::radians(angle_deg);
changed |= ImGui::DragFloat("Falloff", &(m_data.data.spot.falloff), 0.01f, 0.f, 10000.f);
changed |= attenuationItem(m_data.data.spot.attenuation);
} break;
case LightType::eAmbient: break;
case LightType::eQuad:
{
ImGui::Title("Quad Light Settings");
changed |= ImGui::DragFloat("Falloff", &(m_data.data.spot.falloff), 0.01f, 0.f, 10000.f);
changed |= attenuationItem(m_data.data.spot.attenuation);
} break;
case LightType::eAmbient: break;
case LightType::eQuad:
{
ImGui::Title("Quad Light Settings");
changed |= ImGui::DragFloat2("Scale", reinterpret_cast<float*>(&(m_data.data.quad.scale)), 0.01f, 0.f, 10000.f);
changed |= attenuationItem(m_data.data.quad.attenuation);
} break;
}
changed |= ImGui::DragFloat2("Scale", reinterpret_cast<float*>(&(m_data.data.quad.scale)), 0.01f, 0.f, 10000.f);
changed |= attenuationItem(m_data.data.quad.attenuation);
} break;
}
if(ImGui::Button("Cange Type"))
{
ImGui::OpenPopup("light_change_type");
}
if (ImGui::Button("Cange Type"))
{
ImGui::OpenPopup("light_change_type");
}
if(ImGui::BeginPopup("light_change_type"))
{
if (ImGui::Button("Point", ImVec2(180, 24)))
m_data = LightParameters::makePointLight({ 1.f, 0.1f, 0.01f }, 1.f);
if (ImGui::Button("Directional", ImVec2(180, 24)))
m_data = LightParameters::makeDirectionalLight(1.f);
if (ImGui::Button("Spot", ImVec2(180, 24)))
m_data = LightParameters::makeSpotLight({ 1.f, 0.1f, 0.01f }, 1.f, glm::radians(30.f), 0.2f);
ImGui::Text("More types are not fully supported yet :(");
ImGui::EndPopup();
}
if (ImGui::BeginPopup("light_change_type"))
{
if (ImGui::Button("Point", ImVec2(180, 24)))
m_data = LightParameters::makePointLight({ 1.f, 0.1f, 0.01f }, 1.f);
if (ImGui::Button("Directional", ImVec2(180, 24)))
m_data = LightParameters::makeDirectionalLight(1.f);
if (ImGui::Button("Spot", ImVec2(180, 24)))
m_data = LightParameters::makeSpotLight({ 1.f, 0.1f, 0.01f }, 1.f, glm::radians(30.f), 0.2f);
ImGui::PopID();
ImGui::Text("More types are not fully supported yet :(");
// Light just has changed?
if (changed)
{
Log_Info << m_color.r << ", " << m_color.g << ", " << m_color.b;
messaging::Handler::getInstance().submit(tags::light, LightUpdate{ m_id, this });
}
ImGui::EndPopup();
}
ImGui::PopID();
// Light just has changed?
if (changed)
{
Log_Info << m_color.r << ", " << m_color.g << ", " << m_color.b;
messaging::Handler::getInstance().submit(tags::light, LightUpdate{ m_id, this });
}
}
......
......@@ -11,7 +11,7 @@ namespace glare::core
{
Skybox::Skybox()
: m_handle(std::move(gl::TextureTarget::eCubeMap))
: GraphNodeComponent("Skybox"), m_handle(std::move(gl::TextureTarget::eCubeMap))
{
}
......
......@@ -7,6 +7,7 @@
namespace glare::core
{
BatchRenderer::BatchRenderer()
: GraphNodeComponent("Batch Renderer")
{
static auto default_shader_program = std::make_shared<core::Program>(std::vector<std::shared_ptr<core::Shader>>{
std::make_shared<core::Shader>(gl::ShaderType::eVertex, files::shader("simple/simple.vert")),
......
......@@ -39,7 +39,7 @@ namespace ImGui {
bool Combo(const char* label, int* current_item, const std::vector<std::string>& items, int height_in_items = -1);
void Title(const char* label);
void TitledDescription(const char* label, const char* description);
void BeginNamedGroup(const char* id);
void EndNamedGroup();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment