diff --git a/src/noggit/MapView.cpp b/src/noggit/MapView.cpp index a705b2da1..1d742e1a9 100644 --- a/src/noggit/MapView.cpp +++ b/src/noggit/MapView.cpp @@ -81,7 +81,7 @@ void MapView::set_editing_mode (editing_mode mode) objectEditor->modelImport->hide(); objectEditor->rotationEditor->hide(); TexturePalette->hide(); - TexturePicker->hide(); + texturingTool->texture_picker->hide(); _texture_palette_dock->hide(); _world->reset_selection(); @@ -123,6 +123,7 @@ void MapView::setToolPropertyWidgetVisibility(editing_mode mode) break; case editing_mode::paint: _texturing_dock->setVisible(!ui_hidden); + _current_tool = texturingTool; break; case editing_mode::areaid: _areaid_editor_dock->setVisible(!ui_hidden); @@ -373,11 +374,10 @@ void MapView::createGUI() _keybindings->hide(); connect(this, &QObject::destroyed, _keybindings, &QObject::deleteLater); - TexturePicker = new noggit::ui::texture_picker(texturingTool->_current_texture, this); - TexturePicker->hide(); - connect(this, &QObject::destroyed, TexturePicker, &QObject::deleteLater); + texturingTool->texture_picker->hide(); + connect(this, &QObject::destroyed, texturingTool->texture_picker, &QObject::deleteLater); - connect( TexturePicker + connect( texturingTool->texture_picker , &noggit::ui::texture_picker::set_texture , [=] (scoped_blp_texture_reference texture) { @@ -386,20 +386,20 @@ void MapView::createGUI() noggit::ui::selected_texture::set(std::move(texture)); } ); - connect(TexturePicker, &noggit::ui::texture_picker::shift_left + connect(texturingTool->texture_picker, &noggit::ui::texture_picker::shift_left , [=] { makeCurrent(); opengl::context::scoped_setter const _(::gl, context()); - TexturePicker->shiftSelectedTextureLeft(); + texturingTool->texture_picker->shiftSelectedTextureLeft(); } ); - connect(TexturePicker, &noggit::ui::texture_picker::shift_right + connect(texturingTool->texture_picker, &noggit::ui::texture_picker::shift_right , [=] { makeCurrent(); opengl::context::scoped_setter const _(::gl, context()); - TexturePicker->shiftSelectedTextureRight(); + texturingTool->texture_picker->shiftSelectedTextureRight(); } ); @@ -768,7 +768,7 @@ void MapView::createGUI() QWidget* widget_list[] = { TexturePalette, - TexturePicker, + texturingTool->texture_picker, guidetailInfos, _cursor_switcher.get(), _keybindings, @@ -1426,7 +1426,7 @@ void MapView::on_exit_prompt() objectEditor->modelImport->hide(); objectEditor->rotationEditor->hide(); guidetailInfos->hide(); - TexturePicker->hide(); + texturingTool->texture_picker->hide(); TexturePalette->hide(); } @@ -1818,7 +1818,7 @@ MapView::~MapView() // when the uid fix fail the UI isn't created if (!_uid_fix_failed) { - delete TexturePicker; // explicitly delete this here to avoid opengl context related crash + delete texturingTool->texture_picker; // explicitly delete this here to avoid opengl context related crash delete objectEditor; delete texturingTool; } @@ -1939,29 +1939,6 @@ void MapView::tick (float dt) switch (terrainMode) { - case editing_mode::paint: - if (_mod_shift_down && _mod_ctrl_down && _mod_alt_down) - { - // clear chunk texture - if (!underMap) - { - _world->eraseTextures(_cursor_pos); - } - } - else if (_mod_ctrl_down && !ui_hidden) - { - // Pick texture - TexturePicker->getTextures(selection); - } - else if (_mod_shift_down && !!noggit::ui::selected_texture::get()) - { - if ((_display_mode == display_mode::in_3D && !underMap) || _display_mode == display_mode::in_2D) - { - texturingTool->paint(_world.get(), _cursor_pos, dt, *noggit::ui::selected_texture::get()); - } - } - break; - case editing_mode::holes: // no undermap check here, else it's impossible to remove holes if (_mod_shift_down) @@ -2793,35 +2770,6 @@ void MapView::mouseMoveEvent (QMouseEvent* event) _minimap->update(); } - - if (rightMouse && _mod_alt_down) - { - if (terrainMode == editing_mode::paint) - { - texturingTool->change_hardness(relative_movement.dx() / 300.0f); - } - } - - if (leftMouse && _mod_alt_down) - { - switch (terrainMode) - { - case editing_mode::paint: - texturingTool->change_radius(relative_movement.dx() / XSENS); - break; - } - } - - if (leftMouse && _mod_space_down) - { - switch (terrainMode) - { - case editing_mode::paint: - texturingTool->change_pressure(relative_movement.dx() / 300.0f); - break; - } - } - if (_display_mode == display_mode::in_2D && leftMouse && _mod_alt_down && _mod_shift_down) { strafing = ((relative_movement.dx() / XSENS) / -1) * 5.0f; @@ -2917,34 +2865,6 @@ void MapView::wheelEvent (QWheelEvent* event) makeCurrent(); opengl::context::scoped_setter const _ (::gl, context()); - auto&& delta_for_range - ( [&] (float range) - { - //! \note / 8.f for degrees, / 40.f for smoothness - return (_mod_ctrl_down ? 0.01f : 0.1f) - * range - // alt = horizontal delta - * (_mod_alt_down ? event->angleDelta().x() : event->angleDelta().y()) - / 320.f - ; - } - ); - - if (terrainMode == editing_mode::paint) - { - if (_mod_space_down) - { - texturingTool->change_brush_level (delta_for_range (255.f)); - } - else if (_mod_alt_down) - { - texturingTool->change_spray_size (delta_for_range (39.f)); - } - else if (_mod_shift_down) - { - texturingTool->change_spray_pressure (delta_for_range (10.f)); - } - } if (_current_tool) { _current_tool->wheel_event(event); diff --git a/src/noggit/MapView.h b/src/noggit/MapView.h index 8c580ee5c..bea34b983 100644 --- a/src/noggit/MapView.h +++ b/src/noggit/MapView.h @@ -314,7 +314,6 @@ public slots: noggit::ui::zone_id_browser* ZoneIDBrowser; noggit::ui::texture_palette_small* _texture_palette_small; QDockWidget* _areaid_editor_dock; - noggit::ui::texture_picker* TexturePicker; noggit::ui::water* guiWater; QDockWidget* _water_editor_dock; noggit::ui::object_editor* objectEditor; diff --git a/src/noggit/ui/TexturePicker.cpp b/src/noggit/ui/TexturePicker.cpp index 50218f77a..ef85fa7c7 100644 --- a/src/noggit/ui/TexturePicker.cpp +++ b/src/noggit/ui/TexturePicker.cpp @@ -76,13 +76,12 @@ namespace noggit } - void texture_picker::getTextures(selection_type lSelection) + void texture_picker::getTextures(MapChunk* chunk) { show(); - if (lSelection.which() == eEntry_MapChunk) + if (chunk) { - MapChunk* chunk = boost::get (lSelection).chunk; _chunk = chunk; update(false); } diff --git a/src/noggit/ui/TexturePicker.h b/src/noggit/ui/TexturePicker.h index 4439053b3..618b80efd 100644 --- a/src/noggit/ui/TexturePicker.h +++ b/src/noggit/ui/TexturePicker.h @@ -23,7 +23,7 @@ namespace noggit public: texture_picker (current_texture*, QWidget* parent = nullptr); - void getTextures(selection_type lSelection); + void getTextures(MapChunk* chunk); void setTexture(size_t id, current_texture*); void shiftSelectedTextureLeft(); void shiftSelectedTextureRight(); diff --git a/src/noggit/ui/texturing_tool.cpp b/src/noggit/ui/texturing_tool.cpp index 5273feb9a..0f24e2675 100644 --- a/src/noggit/ui/texturing_tool.cpp +++ b/src/noggit/ui/texturing_tool.cpp @@ -8,7 +8,10 @@ #include #include #include +#include #include +#include + #include #include @@ -24,7 +27,7 @@ namespace noggit , bool_toggle_property* show_quick_palette , QWidget* parent ) - : QWidget(parent) + : noggit_tool(parent) , _brush_level(255) , _radius(15.f) , _hardness(0.5f) @@ -45,6 +48,8 @@ namespace noggit layout->addRow (_current_texture); layout->setAlignment(_current_texture, Qt::AlignHCenter); + texture_picker = new ui::texture_picker(_current_texture); + auto tabs (new QTabWidget(this)); auto tool_widget (new QWidget (this)); @@ -420,9 +425,66 @@ namespace noggit } } - void texturing_tool::change_tex_flag(World* world, math::vector_3d const& pos, bool add, scoped_blp_texture_reference texture) + + void texturing_tool::tick(float dt, math::vector_3d const& cursor_pos, bool cursor_under_map, World* world) + { + if (_left_mouse_button && !cursor_under_map) + { + if (_mod_shift_down && _mod_ctrl_down && _mod_alt_down) + { + // clear chunk textures + world->eraseTextures(cursor_pos); + } + else if (_mod_ctrl_down) + { + // Pick texture + texture_picker->getTextures(world->get_chunk_at(cursor_pos)); + } + else if (_mod_shift_down && !!noggit::ui::selected_texture::get()) + { + paint(world, cursor_pos, dt, *noggit::ui::selected_texture::get()); + } + } + } + + void texturing_tool::mouse_move_event(QLineF const& relative_movement) + { + if (_right_mouse_button && _mod_alt_down) + { + change_hardness(relative_movement.dx() / (mouse_sensibility * 50.f)); + } + else if (_left_mouse_button) + { + if (_mod_alt_down) + { + change_radius(relative_movement.dx() / mouse_sensibility); + } + else if (_mod_space_down) + { + change_pressure(relative_movement.dx() / (mouse_sensibility * 50.f)); + } + } + } + + void texturing_tool::wheel_event(QWheelEvent* event) { + if (_mod_space_down) + { + change_brush_level(scroll_wheel_delta_for_range(event, 255.f)); + } + else if (_mod_alt_down) + { + change_spray_size(scroll_wheel_delta_for_range(event, 39.f)); + } + else if (_mod_shift_down) + { + change_spray_pressure(scroll_wheel_delta_for_range(event, 10.f)); + } + } + + void texturing_tool::change_tex_flag(World* world, math::vector_3d const& pos, bool add, scoped_blp_texture_reference texture) + { std::size_t flag = 0; flag |= FLAG_ANIMATE; diff --git a/src/noggit/ui/texturing_tool.hpp b/src/noggit/ui/texturing_tool.hpp index ccb91a1ce..1d77bfb8b 100644 --- a/src/noggit/ui/texturing_tool.hpp +++ b/src/noggit/ui/texturing_tool.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,7 @@ namespace noggit { class checkbox; class current_texture; + class texture_picker; class texture_swapper; enum class texturing_mode @@ -32,7 +34,7 @@ namespace noggit anim }; - class texturing_tool : public QWidget + class texturing_tool : public noggit_tool { public: texturing_tool ( const math::vector_3d* camera_pos @@ -71,11 +73,16 @@ namespace noggit } current_texture* _current_texture; + texture_picker* texture_picker; texture_swapper* const texture_swap_tool() { return _texture_switcher; } QSize sizeHint() const override; + virtual void tick(float dt, math::vector_3d const& cursor_pos, bool cursor_under_map, World* world) override; + virtual void mouse_move_event(QLineF const& relative_movement) override; + virtual void wheel_event(QWheelEvent* event) override; + private: void change_tex_flag(World* world, math::vector_3d const& pos, bool add, scoped_blp_texture_reference texture);