Update ViewToolbar - LightEditor option sub tools

This commit is contained in:
EIntemporel
2022-11-14 23:23:22 +01:00
parent 9f8c8a5207
commit 23c3c65daf
2 changed files with 81 additions and 12 deletions

View File

@@ -33,7 +33,13 @@ ViewToolbar::ViewToolbar(MapView* mapView)
mapView->getWorld()->renderer()->markTerrainParamsUniformBlockDirty(); 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(int v)>() = [&](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) connect(climb_value->slider(), &QSlider::valueChanged, [mapView](int value)
{ {
float radian = float(value) / 1000.0f; 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(_up_toolbar);
_object_secondary_tool.push_back(_down_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(float v)>() = [&](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) 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); //setupWidget(_object_secondary_tool, true);
//mapView->getLeftSecondaryToolbar()->show(); //mapView->getLeftSecondaryToolbar()->show();
} }
break;
case editing_mode::light:
if (_light_secondary_tool.size() > 0)
{
setupWidget(_light_secondary_tool, true);
mapView->getLeftSecondaryToolbar()->show();
}
break;
default: default:
break; break;
} }
@@ -335,3 +375,21 @@ void ViewToolbar::nextFlattenMode(MapView* mapView)
_raise_option->setChecked(true); _raise_option->setChecked(true);
_lower_option->setChecked(true); _lower_option->setChecked(true);
} }
bool ViewToolbar::drawOnlyInsideSphereLight()
{
return static_cast<SubToolBarAction*>(_light_secondary_tool[0])->GET<CheckBoxAction*>(sphere_light_inside_index)->checkbox()->isChecked() && current_mode == editing_mode::light;
}
bool ViewToolbar::drawWireframeSphereLight()
{
return static_cast<SubToolBarAction*>(_light_secondary_tool[0])->GET<CheckBoxAction*>(sphere_light_wireframe_index)->checkbox()->isChecked() && current_mode == editing_mode::light;
}
float ViewToolbar::getAlphaSphereLight()
{
auto toolbar = static_cast<SubToolBarAction*>(_light_secondary_tool[0]);
auto slider = toolbar->GET<SliderAction*>(sphere_light_alpha_index)->slider();
return float(slider->value()) / 100.f;
}

View File

@@ -30,12 +30,18 @@ namespace Noggit
QVector<QWidgetAction*> _climb_secondary_tool; QVector<QWidgetAction*> _climb_secondary_tool;
/*secondary left tool*/ /*secondary left tool*/
bool showUnpaintableChunk(); QVector<QWidgetAction*> _flatten_secondary_tool;
void nextFlattenMode(MapView* mapView); void nextFlattenMode(MapView* mapView);
QVector<QWidgetAction*> _flatten_secondary_tool;
QVector<QWidgetAction*> _texture_secondary_tool; QVector<QWidgetAction*> _texture_secondary_tool;
bool showUnpaintableChunk();
QVector<QWidgetAction*> _object_secondary_tool; QVector<QWidgetAction*> _object_secondary_tool;
QVector<QWidgetAction*> _light_secondary_tool;
bool drawOnlyInsideSphereLight();
bool drawWireframeSphereLight();
float getAlphaSphereLight();
private: private:
QActionGroup _tool_group; QActionGroup _tool_group;
@@ -44,6 +50,9 @@ namespace Noggit
int raise_index = -1; int raise_index = -1;
int lower_index = -1; int lower_index = -1;
int unpaintable_chunk_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<QWidgetAction*> _to_setup, bool ignoreSeparator = false); void setupWidget(QVector<QWidgetAction*> _to_setup, bool ignoreSeparator = false);
void add_tool_icon(MapView* mapView, void add_tool_icon(MapView* mapView,
@@ -58,27 +67,29 @@ namespace Noggit
class SliderAction : public QWidgetAction class SliderAction : public QWidgetAction
{ {
public: public:
SliderAction (const QString &title) template <typename T>
SliderAction (const QString &title, int min, int max, int value, const QString& prec,
std::function<T(T v)> func)
: QWidgetAction(NULL) : QWidgetAction(NULL)
{ {
static_assert (std::is_arithmetic<T>::value, "<T>SliderAction - T must be numeric");
QWidget* _widget = new QWidget(NULL); QWidget* _widget = new QWidget(NULL);
QHBoxLayout* _layout = new QHBoxLayout(); QHBoxLayout* _layout = new QHBoxLayout();
_layout->setSpacing(3); _layout->setSpacing(3);
_layout->setMargin(0); _layout->setMargin(0);
QLabel* _label = new QLabel(title); QLabel* _label = new QLabel(title);
QLabel* _display = new QLabel(tr("49 degrees")); QLabel* _display = new QLabel(QString::number(func(static_cast<T>(value)), 'f', 2) + tr(" %1").arg(prec));
_slider = new QSlider(NULL); _slider = new QSlider(NULL);
_slider->setOrientation(Qt::Horizontal); _slider->setOrientation(Qt::Horizontal);
_slider->setMinimum(0); _slider->setMinimum(min);
_slider->setMaximum(1570); _slider->setMaximum(max);
_slider->setValue(856); _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; _display->setText(QString::number(func(static_cast<T>(value)), 'f', 2) + tr(" %1").arg(prec));
float degrees = radian * (180.0/3.141592653589793238463);
_display->setText(QString::number(int(degrees)) + tr(" degrees"));
}); });
_layout->addWidget(_label); _layout->addWidget(_label);