From 839f005b7b4cca495f9c56dc64b5148fcf7fab05 Mon Sep 17 00:00:00 2001 From: Marukyu Date: Thu, 5 May 2016 13:03:43 +0200 Subject: [PATCH] Added selector for draw/erase mode to object tool This allows multiple objects to be stacked and individual objects to be removed from a stack. --- src/Client/Editor/Tools/ObjectTool.cpp | 4 +- src/Client/Editor/Tools/ObjectTool.hpp | 2 +- .../Editor/Tools/Panels/ObjectToolPanel.cpp | 56 +++++++++++++++++-- .../Editor/Tools/Panels/ObjectToolPanel.hpp | 15 +++++ 4 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/Client/Editor/Tools/ObjectTool.cpp b/src/Client/Editor/Tools/ObjectTool.cpp index d406ed1..6512b9d 100644 --- a/src/Client/Editor/Tools/ObjectTool.cpp +++ b/src/Client/Editor/Tools/ObjectTool.cpp @@ -7,8 +7,6 @@ ObjectTool::ObjectTool(std::vector objectTypes) : objectTypes(objectTypes) { - primaryBrush.setObjectMode(Brush::ObjectMode::ReplaceAll); - secondaryBrush.setObjectMode(Brush::ObjectMode::EraseAll); } ObjectTool::~ObjectTool() @@ -78,10 +76,12 @@ gui2::Ptr ObjectTool::getSettingsPanel() const const Brush& ObjectTool::getPrimaryBrush() const { primaryBrush.setObject(settingsPanel->getSelectedObject()); + primaryBrush.setObjectMode(settingsPanel->getPrimaryMode()); return primaryBrush; } const Brush& ObjectTool::getSecondaryBrush() const { + secondaryBrush.setObjectMode(settingsPanel->getSecondaryMode()); return secondaryBrush; } diff --git a/src/Client/Editor/Tools/ObjectTool.hpp b/src/Client/Editor/Tools/ObjectTool.hpp index b7cf0c7..0dd6134 100644 --- a/src/Client/Editor/Tools/ObjectTool.hpp +++ b/src/Client/Editor/Tools/ObjectTool.hpp @@ -28,7 +28,7 @@ class ObjectTool : public BrushTool std::vector objectTypes; mutable Brush primaryBrush; - Brush secondaryBrush; + mutable Brush secondaryBrush; gui2::Ptr settingsPanel; }; diff --git a/src/Client/Editor/Tools/Panels/ObjectToolPanel.cpp b/src/Client/Editor/Tools/Panels/ObjectToolPanel.cpp index eddce60..64cff40 100644 --- a/src/Client/Editor/Tools/Panels/ObjectToolPanel.cpp +++ b/src/Client/Editor/Tools/Panels/ObjectToolPanel.cpp @@ -1,8 +1,12 @@ #include #include +#include #include +#include +#include #include #include +#include gui2::Ptr ObjectToolPanel::make(std::vector objects, const ObjectAppearanceManager & objectAppearance) @@ -27,17 +31,61 @@ const Object& ObjectToolPanel::getSelectedObject() const return selectedObject; } +static const std::vector BRUSH_MODE_NAMES = { + "Ignore", + "Add", + "Replace all", + "Place on empty", + "Replace front", + "Place/replace front", + "Erase all", + "Erase front" +}; + +Brush::ObjectMode ObjectToolPanel::getPrimaryMode() const +{ + return static_cast(primaryModeMenu->getSelection()); +} + +Brush::ObjectMode ObjectToolPanel::getSecondaryMode() const +{ + return static_cast(secondaryModeMenu->getSelection()); +} + void ObjectToolPanel::init() { gui2::Container::init(); - + ObjectMapperFactory mapperFactory(*objectAppearance); - + + auto modePanel = gui2::GridPanel::make(2, 2); + modePanel->setMargin(1.f); + + primaryModeMenu = gui2::Dropdown::make(); + primaryModeMenu->setModel(std::make_shared(BRUSH_MODE_NAMES)); + primaryModeMenu->setSelection(static_cast(Brush::ObjectMode::ReplaceAll)); + primaryModeMenu->setVerticalFlip(true); + + secondaryModeMenu = gui2::Dropdown::make(); + secondaryModeMenu->setModel(std::make_shared(BRUSH_MODE_NAMES)); + secondaryModeMenu->setSelection(static_cast(Brush::ObjectMode::EraseAll)); + secondaryModeMenu->setVerticalFlip(true); + + modePanel->add(gui2::Text::make("Left click:")); + modePanel->add(gui2::Text::make("Right click:")); + modePanel->add(primaryModeMenu); + modePanel->add(secondaryModeMenu); + panel = SelectionPanel::make(); panel->setTexture(objectAppearance->getTexture()); - auto grid = gui2::GridPanel::make(panel); - add(grid); panel->setMapper(mapperFactory.generateObjectMapper(this->objects), this->objects.size()); + + auto borderPanel = gui2::BorderPanel::make(); + + borderPanel->add(panel, gui2::BorderPanel::Center); + borderPanel->add(modePanel, gui2::BorderPanel::Bottom, 50); + + add(borderPanel); } void ObjectToolPanel::onProcessContainer(gui2::WidgetEvents& events) diff --git a/src/Client/Editor/Tools/Panels/ObjectToolPanel.hpp b/src/Client/Editor/Tools/Panels/ObjectToolPanel.hpp index 2e29db7..d842c91 100644 --- a/src/Client/Editor/Tools/Panels/ObjectToolPanel.hpp +++ b/src/Client/Editor/Tools/Panels/ObjectToolPanel.hpp @@ -4,7 +4,9 @@ #include #include #include +#include #include +#include #include #include @@ -26,6 +28,16 @@ class ObjectToolPanel : public gui2::Container */ const Object & getSelectedObject() const; + /** + * Returns the current left click brush mode. + */ + Brush::ObjectMode getPrimaryMode() const; + + /** + * Returns the current right click brush mode. + */ + Brush::ObjectMode getSecondaryMode() const; + protected: virtual void init() override; @@ -38,6 +50,9 @@ class ObjectToolPanel : public gui2::Container std::vector objects; Object selectedObject; + + gui2::Ptr primaryModeMenu; + gui2::Ptr secondaryModeMenu; gui2::Ptr panel; };