New functions in scene editor

This commit is contained in:
Jano211
2025-02-10 23:10:51 +01:00
committed by Hirek
parent 9aad41c0ba
commit ecebc70814
5 changed files with 146 additions and 12 deletions

View File

@@ -206,7 +206,7 @@ editor_mode::on_key( int const Key, int const Scancode, int const Action, int co
m_node = nullptr;
m_dragging = false;
Application.set_cursor( GLFW_CURSOR_NORMAL );
//Application.set_cursor( GLFW_CURSOR_NORMAL );
static_cast<editor_ui*>( m_userinterface.get() )->set_node(nullptr);
simulation::State.delete_model(model);
@@ -318,10 +318,14 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
if( Action == GLFW_PRESS ) {
// left button press
auto const mode = static_cast<editor_ui*>( m_userinterface.get() )->mode();
auto const rotation_mode = static_cast<editor_ui*>( m_userinterface.get() )->rot_mode();
auto const fixed_rotation_value =
static_cast<editor_ui *>(m_userinterface.get())->rot_val();
m_node = nullptr;
GfxRenderer->Pick_Node_Callback([this, mode,Action,Button](scene::basic_node *node) {
GfxRenderer->Pick_Node_Callback([this, mode, rotation_mode, fixed_rotation_value,
Action, Button](scene::basic_node *node) {
editor_ui *ui = static_cast<editor_ui *>(m_userinterface.get());
if (mode == nodebank_panel::MODIFY) {
@@ -329,10 +333,10 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
return;
m_node = node;
if( m_node )
Application.set_cursor( GLFW_CURSOR_DISABLED );
else
m_dragging = false;
//if( m_node )
//Application.set_cursor( GLFW_CURSOR_DISABLED );
//else
//m_dragging = false;
ui->set_node(m_node);
}
else if (mode == nodebank_panel::COPY) {
@@ -360,8 +364,24 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
if (!m_dragging)
return;
m_node = cloned;
Application.set_cursor( GLFW_CURSOR_DISABLED );
m_node = cloned;
if (rotation_mode == functions_panel::RANDOM)
{
auto const rotation{glm::vec3{0, LocalRandom(0.0, 360.0), 0}};
m_editor.rotate(m_node, rotation, 1);
}
else if (rotation_mode == functions_panel::FIXED)
{
auto const rotation{glm::vec3{0, fixed_rotation_value, 0}};
m_editor.rotate(m_node, rotation, 0);
}
//Application.set_cursor( GLFW_CURSOR_DISABLED );
ui->set_node( m_node );
}
});
@@ -370,8 +390,8 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
}
else {
// left button release
if( m_node )
Application.set_cursor( GLFW_CURSOR_NORMAL );
//if( m_node )
//Application.set_cursor( GLFW_CURSOR_NORMAL );
m_dragging = false;
// prime history stack for another snapshot
m_takesnapshot = true;

View File

@@ -21,6 +21,7 @@ editor_ui::editor_ui() {
add_external_panel( &m_itempropertiespanel );
add_external_panel( &m_nodebankpanel );
add_external_panel( &m_functionspanel );
}
// updates state of UI elements
@@ -41,6 +42,7 @@ editor_ui::update() {
ui_layer::update();
m_itempropertiespanel.update( m_node );
m_functionspanel.update( m_node );
}
void
@@ -63,3 +65,17 @@ nodebank_panel::edit_mode
editor_ui::mode() {
return m_nodebankpanel.mode;
}
functions_panel::rotation_mode
editor_ui::rot_mode() {
return m_functionspanel.rot_mode;
}
float
editor_ui::rot_val() {
return m_functionspanel.rot_value;
}
bool
editor_ui::rot_from_last()
{
return m_functionspanel.rot_from_last;
}

View File

@@ -31,6 +31,12 @@ public:
set_node( scene::basic_node * Node );
void
add_node_template(const std::string &desc);
float
rot_val();
bool
rot_from_last();
functions_panel::rotation_mode
rot_mode();
const std::string *
get_active_node_template();
nodebank_panel::edit_mode
@@ -39,6 +45,7 @@ public:
private:
// members
itemproperties_panel m_itempropertiespanel { "Node Properties", true };
functions_panel m_functionspanel { "Functions", true };
nodebank_panel m_nodebankpanel{ "Node Bank", true };
scene::basic_node * m_node { nullptr }; // currently bound scene node, if any
};

View File

@@ -420,8 +420,6 @@ nodebank_panel::render() {
ImGui::SameLine();
ImGui::RadioButton("Insert from bank", (int*)&mode, ADD);
ImGui::SameLine();
ImGui::RadioButton("Brush", (int*)&mode, BRUSH);
ImGui::SameLine();
ImGui::RadioButton( "Copy to bank", (int*)&mode, COPY );
ImGui::SameLine();
if (ImGui::Button("Reload Nodebank"))
@@ -493,3 +491,64 @@ nodebank_panel::generate_node_label( std::string Input ) const {
model :
model + " (" + texture + ")" );
}
void functions_panel::update(scene::basic_node const *Node)
{
m_node = Node;
if (false == is_open)
{
return;
}
text_lines.clear();
m_grouplines.clear();
std::string textline;
// scenario inspector
auto const *node{Node};
auto const &camera{Global.pCamera};
}
void
functions_panel::render() {
if( false == is_open ) { return; }
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
| ( size.x > 0 ? ImGuiWindowFlags_NoResize : 0 );
if( size.x > 0 ) {
ImGui::SetNextWindowSize( ImVec2S( size.x, size.y ) );
}
if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2( size_max.x, size_max.y ) );
}
auto const panelname { (
title.empty() ?
m_name :
title )
+ "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), nullptr, flags ) ) {
// header section
ImGui::RadioButton("Random rotation", (int *)&rot_mode, RANDOM);
ImGui::RadioButton("Fixed rotation", (int *)&rot_mode, FIXED);
if(rot_mode == FIXED){
//ImGui::Checkbox("Get rotation from last object", &rot_from_last);
ImGui::SliderFloat("Rotation Value", &rot_value, 0.0f, 360.0f, "%.1f");
};
ImGui::RadioButton("Default rotation", (int *)&rot_mode, DEFAULT);
for( auto const &line : text_lines ) {
ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), line.data.c_str() );
}
}
ImGui::End();
}

View File

@@ -73,3 +73,35 @@ private:
char m_nodesearch[ 128 ];
std::shared_ptr<std::string> m_selectedtemplate;
};
class functions_panel : public ui_panel
{
public:
enum rotation_mode
{
RANDOM,
FIXED,
DEFAULT
};
rotation_mode rot_mode = DEFAULT;
float rot_value = 0.0f;
bool rot_from_last = false;
functions_panel(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen) {}
void update(scene::basic_node const *Node);
void render() override;
private:
// methods
// members
scene::basic_node const *m_node{nullptr}; // scene node bound to the panel
scene::group_handle m_grouphandle{null_handle}; // scene group bound to the panel
std::string m_groupprefix;
std::vector<text_line> m_grouplines;
};