diff --git a/src/noggit/ui/tools/ViewToolbar/Ui/ViewToolbar.cpp b/src/noggit/ui/tools/ViewToolbar/Ui/ViewToolbar.cpp index 4e31ed16..b07c4f56 100755 --- a/src/noggit/ui/tools/ViewToolbar/Ui/ViewToolbar.cpp +++ b/src/noggit/ui/tools/ViewToolbar/Ui/ViewToolbar.cpp @@ -33,7 +33,13 @@ ViewToolbar::ViewToolbar(MapView* mapView) mapView->getWorld()->renderer()->markTerrainParamsUniformBlockDirty(); }); - SliderAction* climb_value = new SliderAction(tr("Configure climb maximum value")); + SliderAction* climb_value = new SliderAction(tr("Configure climb maximum value"), 0, 1570, 856, tr("degrees"), + std::function() = [&](int v) { + float radian = float(v) / 1000.f; + float degrees = radian * (180.0 / 3.141592653589793238463); + return int(degrees); + }); + connect(climb_value->slider(), &QSlider::valueChanged, [mapView](int value) { float radian = float(value) / 1000.0f; @@ -239,6 +245,32 @@ ViewToolbar::ViewToolbar(MapView* mapView, editing_mode mode) _object_secondary_tool.push_back(_up_toolbar); _object_secondary_tool.push_back(_down_toolbar); } + + { + /* + * LIGHT SECONDARY TOOL + */ + + SubToolBarAction* _toolbar = new SubToolBarAction(); + + { + IconAction* _icon = new IconAction(FontNoggitIcon{ FontNoggit::TOOL_STAMP }); + CheckBoxAction* _draw_only_inside = new CheckBoxAction(tr("Draw current only")); + CheckBoxAction* _draw_wireframe = new CheckBoxAction(tr("Draw wireframe")); + SliderAction* _alpha_value = new SliderAction(tr("Alpha"), 0, 100, 30, "", + std::function() = [&](float v) { + return v / 100.f; + }); + + _toolbar->ADD_ACTION(_icon); + _toolbar->ADD_ACTION(_draw_only_inside); sphere_light_inside_index = 1; + _toolbar->ADD_ACTION(_draw_wireframe); sphere_light_wireframe_index = 2; + _toolbar->ADD_ACTION(_alpha_value); sphere_light_alpha_index = 3; + _toolbar->SETUP_WIDGET(false); + } + + _light_secondary_tool.push_back(_toolbar); + } } void ViewToolbar::setCurrentMode(MapView* mapView, editing_mode mode) @@ -270,6 +302,14 @@ void ViewToolbar::setCurrentMode(MapView* mapView, editing_mode mode) //setupWidget(_object_secondary_tool, true); //mapView->getLeftSecondaryToolbar()->show(); } + break; + case editing_mode::light: + if (_light_secondary_tool.size() > 0) + { + setupWidget(_light_secondary_tool, true); + mapView->getLeftSecondaryToolbar()->show(); + } + break; default: break; } @@ -335,3 +375,21 @@ void ViewToolbar::nextFlattenMode(MapView* mapView) _raise_option->setChecked(true); _lower_option->setChecked(true); } + +bool ViewToolbar::drawOnlyInsideSphereLight() +{ + return static_cast(_light_secondary_tool[0])->GET(sphere_light_inside_index)->checkbox()->isChecked() && current_mode == editing_mode::light; +} + +bool ViewToolbar::drawWireframeSphereLight() +{ + return static_cast(_light_secondary_tool[0])->GET(sphere_light_wireframe_index)->checkbox()->isChecked() && current_mode == editing_mode::light; +} + +float ViewToolbar::getAlphaSphereLight() +{ + auto toolbar = static_cast(_light_secondary_tool[0]); + auto slider = toolbar->GET(sphere_light_alpha_index)->slider(); + + return float(slider->value()) / 100.f; +} \ No newline at end of file diff --git a/src/noggit/ui/tools/ViewToolbar/Ui/ViewToolbar.hpp b/src/noggit/ui/tools/ViewToolbar/Ui/ViewToolbar.hpp index 8c97998f..5a531318 100755 --- a/src/noggit/ui/tools/ViewToolbar/Ui/ViewToolbar.hpp +++ b/src/noggit/ui/tools/ViewToolbar/Ui/ViewToolbar.hpp @@ -30,12 +30,18 @@ namespace Noggit QVector _climb_secondary_tool; /*secondary left tool*/ - bool showUnpaintableChunk(); + QVector _flatten_secondary_tool; void nextFlattenMode(MapView* mapView); - QVector _flatten_secondary_tool; QVector _texture_secondary_tool; + bool showUnpaintableChunk(); + QVector _object_secondary_tool; + + QVector _light_secondary_tool; + bool drawOnlyInsideSphereLight(); + bool drawWireframeSphereLight(); + float getAlphaSphereLight(); private: QActionGroup _tool_group; @@ -44,6 +50,9 @@ namespace Noggit int raise_index = -1; int lower_index = -1; int unpaintable_chunk_index = -1; + int sphere_light_inside_index = -1; + int sphere_light_wireframe_index = -1; + int sphere_light_alpha_index = -1; void setupWidget(QVector _to_setup, bool ignoreSeparator = false); void add_tool_icon(MapView* mapView, @@ -58,27 +67,29 @@ namespace Noggit class SliderAction : public QWidgetAction { public: - SliderAction (const QString &title) + template + SliderAction (const QString &title, int min, int max, int value, const QString& prec, + std::function func) : QWidgetAction(NULL) { + static_assert (std::is_arithmetic::value, "SliderAction - T must be numeric"); + QWidget* _widget = new QWidget(NULL); QHBoxLayout* _layout = new QHBoxLayout(); _layout->setSpacing(3); _layout->setMargin(0); QLabel* _label = new QLabel(title); - QLabel* _display = new QLabel(tr("49 degrees")); + QLabel* _display = new QLabel(QString::number(func(static_cast(value)), 'f', 2) + tr(" %1").arg(prec)); _slider = new QSlider(NULL); _slider->setOrientation(Qt::Horizontal); - _slider->setMinimum(0); - _slider->setMaximum(1570); - _slider->setValue(856); + _slider->setMinimum(min); + _slider->setMaximum(max); + _slider->setValue(value); - connect(_slider, &QSlider::valueChanged, [_display](int value) + connect(_slider, &QSlider::valueChanged, [_display, prec, func](int value) { - float radian = float(value) / 1000.f; - float degrees = radian * (180.0/3.141592653589793238463); - _display->setText(QString::number(int(degrees)) + tr(" degrees")); + _display->setText(QString::number(func(static_cast(value)), 'f', 2) + tr(" %1").arg(prec)); }); _layout->addWidget(_label);