Skip to content

Commit

Permalink
noggit: ui: texturing_tool: inherit noggit_tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Adspartan committed Nov 12, 2024
1 parent 2e4c50d commit da4ef3a
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 100 deletions.
104 changes: 12 additions & 92 deletions src/noggit/MapView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
}
);

Expand Down Expand Up @@ -768,7 +768,7 @@ void MapView::createGUI()
QWidget* widget_list[] =
{
TexturePalette,
TexturePicker,
texturingTool->texture_picker,
guidetailInfos,
_cursor_switcher.get(),
_keybindings,
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/noggit/MapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/noggit/ui/TexturePicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<selected_chunk_type> (lSelection).chunk;
_chunk = chunk;
update(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/noggit/ui/TexturePicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
66 changes: 64 additions & 2 deletions src/noggit/ui/texturing_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#include <noggit/ui/checkbox.hpp>
#include <noggit/ui/CurrentTexture.h>
#include <noggit/ui/slider_spinbox.hpp>
#include <noggit/ui/TexturePicker.h>
#include <noggit/ui/texture_swapper.hpp>
#include <noggit/ui/TexturingGUI.h>

#include <util/qt/overload.hpp>

#include <QtWidgets/QFormLayout>
Expand All @@ -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)
Expand All @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/noggit/ui/texturing_tool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <noggit/float_property.hpp>
#include <noggit/TextureManager.h>
#include <noggit/unsigned_int_property.hpp>
#include <noggit/ui/noggit_tool.hpp>

#include <QtWidgets/QCheckBox>
#include <QtWidgets/QDial>
Expand All @@ -23,6 +24,7 @@ namespace noggit
{
class checkbox;
class current_texture;
class texture_picker;
class texture_swapper;

enum class texturing_mode
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit da4ef3a

Please sign in to comment.