From 0e68f5e8d79cfba89228a7d3f2ce3821252d496e Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 5 Mar 2015 18:47:00 +0000 Subject: [PATCH] Add Clone NodeBox --- src/MenuState.hpp | 1 + src/Node.cpp | 12 ++++++++++++ src/Node.hpp | 1 + src/modes/NBEditor.cpp | 14 +++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/MenuState.hpp b/src/MenuState.hpp index 75bbfea..810d117 100644 --- a/src/MenuState.hpp +++ b/src/MenuState.hpp @@ -38,6 +38,7 @@ enum GUI_ID // Tools GUI_PROJ_NEW_BOX, GUI_PROJ_DELETE_BOX, + GUI_PROJ_CLONE, GUI_PROJ_IMAGE_IM, // Help diff --git a/src/Node.cpp b/src/Node.cpp index 0964bfe..c681a30 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -88,6 +88,18 @@ void Node::deleteNodebox(int id) _selected = boxes.size() - 1; } +void Node::cloneNodebox(int id) +{ + NodeBox *nb = GetNodeBox(id); + if (!nb) + return; + + NodeBox *new_nb = addNodeBox(); + new_nb->one = nb->one; + new_nb->two = nb->two; + new_nb->buildNode(state, position, device, images); +} + void Node::setTexture(CubeSide face, Media::Image *image) { if (image) { diff --git a/src/Node.hpp b/src/Node.hpp index 3642765..14e8b2d 100644 --- a/src/Node.hpp +++ b/src/Node.hpp @@ -23,6 +23,7 @@ class Node NodeBox* GetNodeBox(int id); NodeBox* addNodeBox(); void deleteNodebox(int id); + void cloneNodebox(int id); void select(int id) { _selected = id; } // Node bulk updaters diff --git a/src/modes/NBEditor.cpp b/src/modes/NBEditor.cpp index ca8bb34..7af30c4 100644 --- a/src/modes/NBEditor.cpp +++ b/src/modes/NBEditor.cpp @@ -68,10 +68,13 @@ void NBEditor::load() lb->setVisible(false); IGUIButton* b1 = guienv->addButton(rect(0, 100, 50, 125), lb, GUI_PROJ_NEW_BOX, L"+", L"Add a node box"); - IGUIButton* b2 = guienv->addButton(rect(60, 100, 110,125), + IGUIButton* b2 = guienv->addButton(rect(60, 100, 110, 125), lb, GUI_PROJ_DELETE_BOX, L"-", L"Delete node box"); + IGUIButton* b3 = guienv->addButton(rect(120, 100, 170, 125), + lb, GUI_PROJ_CLONE, L"Clone", L"Duplicate node box"); b1->setNotClipped(true); b2->setNotClipped(true); + b3->setNotClipped(true); } @@ -447,6 +450,15 @@ bool NBEditor::OnEvent(const irr::SEvent &event) { } break; } + case GUI_PROJ_CLONE: { + Node* node = state->project->GetCurrentNode(); + IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX); + if (node && node->GetNodeBox(lb->getSelected())){ + node->cloneNodebox(lb->getSelected()); + load_ui(); + } + break; + } case ENB_GUI_PROP_REVERT: fillProperties(); break;