Tools can now be added and placed in any order

This commit is contained in:
dwg
2024-09-11 14:17:20 +02:00
parent d29a6e9ce4
commit 4cd90f7473
19 changed files with 64 additions and 42 deletions

View File

@@ -283,7 +283,7 @@ void MapView::set_editing_mode(editing_mode mode)
void MapView::setToolPropertyWidgetVisibility(editing_mode mode) void MapView::setToolPropertyWidgetVisibility(editing_mode mode)
{ {
_tool_panel_dock->setCurrentIndex(static_cast<int>(mode)); _tool_panel_dock->setCurrentTool(mode);
switch (mode) switch (mode)
{ {

View File

@@ -47,7 +47,7 @@ namespace Noggit
void AreaTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void AreaTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_areaTool = new Noggit::Ui::zone_id_browser(mapView()); _areaTool = new Noggit::Ui::zone_id_browser(mapView());
toolPanel->registerTool(name(), _areaTool); toolPanel->registerTool(this, _areaTool);
_areaTool->setMapID(mapView()->getWorld()->getMapID()); _areaTool->setMapID(mapView()->getWorld()->getMapID());
QObject::connect(_areaTool, &Noggit::Ui::zone_id_browser::selected QObject::connect(_areaTool, &Noggit::Ui::zone_id_browser::selected
@@ -119,4 +119,4 @@ namespace Noggit
_areaTool->changeRadius(params.relative_movement.dx() / XSENS); _areaTool->changeRadius(params.relative_movement.dx() / XSENS);
} }
} }
} }

View File

@@ -38,6 +38,6 @@ namespace Noggit
void ChunkTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void ChunkTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_chunkManipulator = new Noggit::Ui::Tools::ChunkManipulator::ChunkManipulatorPanel(mapView(), mapView()); _chunkManipulator = new Noggit::Ui::Tools::ChunkManipulator::ChunkManipulatorPanel(mapView(), mapView());
toolPanel->registerTool(name(), _chunkManipulator); toolPanel->registerTool(this, _chunkManipulator);
} }
} }

View File

@@ -77,7 +77,7 @@ namespace Noggit
void FlattenBlurTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void FlattenBlurTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_flattenTool = new Noggit::Ui::flatten_blur_tool(mapView()); _flattenTool = new Noggit::Ui::flatten_blur_tool(mapView());
toolPanel->registerTool(name(), _flattenTool); toolPanel->registerTool(this, _flattenTool);
} }
void FlattenBlurTool::postUiSetup() void FlattenBlurTool::postUiSetup()

View File

@@ -55,7 +55,7 @@ namespace Noggit
void HoleTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void HoleTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_holeTool = new Noggit::Ui::hole_tool(mapView()); _holeTool = new Noggit::Ui::hole_tool(mapView());
toolPanel->registerTool(name(), _holeTool); toolPanel->registerTool(this, _holeTool);
} }
ToolDrawParameters HoleTool::drawParameters() const ToolDrawParameters HoleTool::drawParameters() const
@@ -110,4 +110,4 @@ namespace Noggit
_holeTool->changeRadius(params.relative_movement.dx() / XSENS); _holeTool->changeRadius(params.relative_movement.dx() / XSENS);
} }
} }
} }

View File

@@ -32,7 +32,7 @@ namespace Noggit
void ImpassTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void ImpassTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
// Dummy, because the toolbar requires a widget for every tool // Dummy, because the toolbar requires a widget for every tool
toolPanel->registerTool(name(), new QWidget{mapView()}); toolPanel->registerTool(this, new QWidget{mapView()});
} }
void ImpassTool::onSelected() void ImpassTool::onSelected()
@@ -68,4 +68,4 @@ namespace Noggit
mapView()->getWorld()->mapIndex.setFlag(false, mapView()->cursorPosition(), 0x2); mapView()->getWorld()->mapIndex.setFlag(false, mapView()->cursorPosition(), 0x2);
} }
} }
} }

View File

@@ -38,7 +38,7 @@ namespace Noggit
void LightTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void LightTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_lightEditor = new Noggit::Ui::Tools::LightEditor(mapView(), mapView()); _lightEditor = new Noggit::Ui::Tools::LightEditor(mapView(), mapView());
toolPanel->registerTool(name(), _lightEditor); toolPanel->registerTool(this, _lightEditor);
} }
void LightTool::onTick(float deltaTime, TickParameters const& params) void LightTool::onTick(float deltaTime, TickParameters const& params)
@@ -46,4 +46,4 @@ namespace Noggit
if (mapView()->timeSpeed() > 0.0f) if (mapView()->timeSpeed() > 0.0f)
_lightEditor->UpdateWorldTime(); _lightEditor->UpdateWorldTime();
} }
} }

View File

@@ -44,7 +44,7 @@ namespace Noggit
{ {
auto mv = mapView(); auto mv = mapView();
_minimapTool = new Noggit::Ui::MinimapCreator(mv, mv->getWorld(), mv); _minimapTool = new Noggit::Ui::MinimapCreator(mv, mv->getWorld(), mv);
toolPanel->registerTool(name(), _minimapTool); toolPanel->registerTool(this, _minimapTool);
QObject::connect(_minimapTool, &Ui::MinimapCreator::onSave, [=] { QObject::connect(_minimapTool, &Ui::MinimapCreator::onSave, [=] {
saving_minimap = true; saving_minimap = true;
@@ -296,4 +296,4 @@ namespace Noggit
// Save minimap creator model filters // Save minimap creator model filters
_minimapTool->saveFiltersToJSON(); _minimapTool->saveFiltersToJSON();
} }
} }

View File

@@ -75,7 +75,7 @@ namespace Noggit
, &_move_model_snap_to_objects , &_move_model_snap_to_objects
, mv , mv
); );
toolPanel->registerTool(name(), _objectEditor); toolPanel->registerTool(this, _objectEditor);
/* Additional tools */ /* Additional tools */
@@ -965,4 +965,4 @@ namespace Noggit
{ {
_objectEditor->rotationEditor->updateValues(mapView()->getWorld()); _objectEditor->rotationEditor->updateValues(mapView()->getWorld());
} }
} }

View File

@@ -72,7 +72,7 @@ namespace Noggit
void RaiseLowerTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void RaiseLowerTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_terrainTool = new Noggit::Ui::TerrainTool{ mapView(), mapView() }; _terrainTool = new Noggit::Ui::TerrainTool{ mapView(), mapView() };
toolPanel->registerTool(name(), _terrainTool); toolPanel->registerTool(this, _terrainTool);
QObject::connect(_terrainTool QObject::connect(_terrainTool
, &Noggit::Ui::TerrainTool::updateVertices , &Noggit::Ui::TerrainTool::updateVertices
@@ -251,4 +251,4 @@ namespace Noggit
image_mask_selector->setRotation(uid(gen)); image_mask_selector->setRotation(uid(gen));
} }
} }

View File

@@ -39,7 +39,7 @@ namespace Noggit
void ScriptingTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void ScriptingTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_scriptingTool = new Noggit::Scripting::scripting_tool(mapView(), mapView(), mapView()->settings()); _scriptingTool = new Noggit::Scripting::scripting_tool(mapView(), mapView(), mapView()->settings());
toolPanel->registerTool(name(), _scriptingTool); toolPanel->registerTool(this, _scriptingTool);
} }
ToolDrawParameters ScriptingTool::drawParameters() const ToolDrawParameters ScriptingTool::drawParameters() const
@@ -67,4 +67,4 @@ namespace Noggit
} }
} }
} }
} }

View File

@@ -40,7 +40,7 @@ namespace Noggit
void StampTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void StampTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_stampTool = new Noggit::Ui::Tools::BrushStack(mapView(), mapView()); _stampTool = new Noggit::Ui::Tools::BrushStack(mapView(), mapView());
toolPanel->registerTool(name(), _stampTool); toolPanel->registerTool(this, _stampTool);
QObject::connect(mapView(), &MapView::trySetBrushTexture, [=](QImage* brush, QWidget* sender) { QObject::connect(mapView(), &MapView::trySetBrushTexture, [=](QImage* brush, QWidget* sender) {
auto mv = mapView(); auto mv = mapView();
@@ -174,4 +174,4 @@ namespace Noggit
_stampTool->changeRotation(uid(gen)); _stampTool->changeRotation(uid(gen));
} }
} }

View File

@@ -123,7 +123,7 @@ namespace Noggit
auto mv = mapView(); auto mv = mapView();
/* Tool */ /* Tool */
_texturingTool = new Ui::texturing_tool(&mv->getCamera()->position, mv, &_show_texture_palette_small_window, mv); _texturingTool = new Ui::texturing_tool(&mv->getCamera()->position, mv, &_show_texture_palette_small_window, mv);
toolPanel->registerTool(name(), _texturingTool); toolPanel->registerTool(this, _texturingTool);
// Connects // Connects
QObject::connect(_texturingTool->texture_swap_tool()->texture_display() QObject::connect(_texturingTool->texture_swap_tool()->texture_display()
@@ -581,4 +581,4 @@ namespace Noggit
image_mask_selector->setRotation(uid(gen)); image_mask_selector->setRotation(uid(gen));
} }
} }

View File

@@ -44,7 +44,7 @@ namespace Noggit
void VertexPainterTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void VertexPainterTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_shaderTool = new Noggit::Ui::ShaderTool(mapView(), mapView()); _shaderTool = new Noggit::Ui::ShaderTool(mapView(), mapView());
toolPanel->registerTool(name(), _shaderTool); toolPanel->registerTool(this, _shaderTool);
} }
ToolDrawParameters VertexPainterTool::drawParameters() const ToolDrawParameters VertexPainterTool::drawParameters() const
@@ -159,4 +159,4 @@ namespace Noggit
} }
} }
} }
} }

View File

@@ -52,7 +52,7 @@ namespace Noggit
void WaterTool::setupUi(Ui::Tools::ToolPanel* toolPanel) void WaterTool::setupUi(Ui::Tools::ToolPanel* toolPanel)
{ {
_guiWater = new Noggit::Ui::water(&_displayedWaterLayer, &_displayAllWaterLayers, mapView()); _guiWater = new Noggit::Ui::water(&_displayedWaterLayer, &_displayAllWaterLayers, mapView());
toolPanel->registerTool(name(), _guiWater); toolPanel->registerTool(this, _guiWater);
auto mv = mapView(); auto mv = mapView();
@@ -162,4 +162,4 @@ namespace Noggit
_guiWater->change_height(delta_for_range(40.f)); _guiWater->change_height(delta_for_range(40.f));
} }
} }
} }

View File

@@ -29,11 +29,16 @@ namespace Noggit
}); });
action->setActionGroup(&_tool_group); action->setActionGroup(&_tool_group);
action->setCheckable(true); action->setCheckable(true);
_tool_actions[mode] = action;
} }
void toolbar::check_tool(editing_mode mode) void toolbar::check_tool(editing_mode mode)
{ {
_tool_group.actions()[static_cast<std::size_t> (mode)]->setChecked(true); if (auto itr = _tool_actions.find(mode); itr != _tool_actions.end())
{
itr->second->setChecked(true);
}
} }
} }
} }

View File

@@ -10,6 +10,8 @@
#include <noggit/tool_enums.hpp> #include <noggit/tool_enums.hpp>
#include <noggit/ui/FontNoggit.hpp> #include <noggit/ui/FontNoggit.hpp>
#include <unordered_map>
namespace Noggit namespace Noggit
{ {
class Tool; class Tool;
@@ -27,6 +29,8 @@ namespace Noggit
std::function<void (editing_mode)> _set_editing_mode; std::function<void (editing_mode)> _set_editing_mode;
QActionGroup _tool_group; QActionGroup _tool_group;
std::unordered_map<editing_mode, QAction*> _tool_actions;
void add_tool_icon(editing_mode mode, const QString& name, const FontNoggit::Icons& icon); void add_tool_icon(editing_mode mode, const QString& name, const FontNoggit::Icons& icon);
}; };
} }

View File

@@ -1,12 +1,14 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3). // This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/Tool.hpp>
#include "ToolPanel.hpp" #include "ToolPanel.hpp"
#include <QScrollBar> #include <QScrollBar>
using namespace Noggit::Ui::Tools; using namespace Noggit::Ui::Tools;
ToolPanel::ToolPanel(QWidget* parent) ToolPanel::ToolPanel(QWidget* parent)
: QDockWidget(parent) : QDockWidget(parent)
{ {
auto body = new QWidget(this); auto body = new QWidget(this);
_ui.setupUi(body); _ui.setupUi(body);
@@ -16,18 +18,25 @@ ToolPanel::ToolPanel(QWidget* parent)
setFixedWidth(250 + 15); setFixedWidth(250 + 15);
} }
void ToolPanel::setCurrentIndex(int index) void ToolPanel::setCurrentTool(editing_mode mode)
{ {
for (auto& widget : _widgets) for (auto&& [tool, widget] : _tools)
widget->setVisible(false); {
if (tool->editingMode() == mode)
{
widget->setVisible(true);
}
else
{
widget->setVisible(false);
}
}
_widgets.at(index)->setVisible(true);
_ui.scrollAreaWidgetContents->adjustSize(); _ui.scrollAreaWidgetContents->adjustSize();
} }
void ToolPanel::registerTool(QString const& title, QWidget* widget) void ToolPanel::registerTool(Tool* tool, QWidget* widget)
{ {
_widgets.push_back(widget);
_ui.scrollAreaWidgetContents->layout()->addWidget(widget); _ui.scrollAreaWidgetContents->layout()->addWidget(widget);
_titles.emplace_back(title); _tools.emplace_back(std::make_pair(tool, widget));
} }

View File

@@ -3,14 +3,19 @@
#ifndef NOGGIT_TOOLPANEL_HPP #ifndef NOGGIT_TOOLPANEL_HPP
#define NOGGIT_TOOLPANEL_HPP #define NOGGIT_TOOLPANEL_HPP
#include <noggit/tool_enums.hpp>
#include <QWidget> #include <QWidget>
#include <QDockWidget> #include <QDockWidget>
#include <ui_ToolPanelScroll.h> #include <ui_ToolPanelScroll.h>
#include <vector> #include <vector>
#include <utility>
namespace Noggit namespace Noggit
{ {
class Tool;
namespace Ui::Tools namespace Ui::Tools
{ {
class ToolPanel : public QDockWidget class ToolPanel : public QDockWidget
@@ -20,13 +25,12 @@ namespace Noggit
public: public:
explicit ToolPanel(QWidget* parent = nullptr); explicit ToolPanel(QWidget* parent = nullptr);
void setCurrentIndex(int index); void setCurrentTool(editing_mode mode);
void registerTool(QString const& title, QWidget* widget); void registerTool(Tool* tool, QWidget* widget);
private: private:
::Ui::toolPanel _ui; ::Ui::toolPanel _ui;
std::vector<QString> _titles; std::vector<std::pair<Tool*, QWidget*>> _tools;
std::vector<QWidget*> _widgets;
}; };
} }