From b6097d8d9c4f8c3b57255f32173545b14b57f624 Mon Sep 17 00:00:00 2001 From: T1ti Date: Fri, 22 Jul 2022 07:22:54 +0200 Subject: [PATCH] New button to remove texture from ADT --- src/noggit/MapChunk.cpp | 11 +++++++++++ src/noggit/MapChunk.h | 1 + src/noggit/World.cpp | 15 +++++++++++++++ src/noggit/World.h | 1 + src/noggit/ui/texture_swapper.cpp | 11 +++++++++++ 5 files changed, 39 insertions(+) diff --git a/src/noggit/MapChunk.cpp b/src/noggit/MapChunk.cpp index a22b4a60..ff2c2377 100755 --- a/src/noggit/MapChunk.cpp +++ b/src/noggit/MapChunk.cpp @@ -1259,6 +1259,17 @@ void MapChunk::eraseTextures() texture_set->eraseTextures(); } +void MapChunk::eraseTexture(scoped_blp_texture_reference const& tex) +{ + + int textureindex = texture_set->get_texture_index_or_add(tex, 0); + + if (textureindex != -1) + { + texture_set->eraseTexture(textureindex); + } +} + void MapChunk::change_texture_flag(scoped_blp_texture_reference const& tex, std::size_t flag, bool add) { texture_set->change_texture_flag(tex, flag, add); diff --git a/src/noggit/MapChunk.h b/src/noggit/MapChunk.h index 2989f1c9..a0217023 100755 --- a/src/noggit/MapChunk.h +++ b/src/noggit/MapChunk.h @@ -162,6 +162,7 @@ public: int addTexture(scoped_blp_texture_reference texture); void switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture); void eraseTextures(); + void eraseTexture(scoped_blp_texture_reference const& tex); void change_texture_flag(scoped_blp_texture_reference const& tex, std::size_t flag, bool add); void clear_shadows(); diff --git a/src/noggit/World.cpp b/src/noggit/World.cpp index 95d17945..f97d3b1e 100755 --- a/src/noggit/World.cpp +++ b/src/noggit/World.cpp @@ -2031,6 +2031,21 @@ void World::swapTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex) } } +void World::removeTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex) +{ + ZoneScoped; + if (!!Noggit::Ui::selected_texture::get()) + { + for_all_chunks_on_tile(pos, [&](MapChunk* chunk) + { + NOGGIT_CUR_ACTION->registerChunkTextureChange(chunk); + // chunk->switchTexture(tex, *Noggit::Ui::selected_texture::get()); + chunk->eraseTexture(tex); + }); + } +} + + void World::removeTexDuplicateOnADT(glm::vec3 const& pos) { ZoneScoped; diff --git a/src/noggit/World.h b/src/noggit/World.h index ce59dfb6..4047c0c1 100755 --- a/src/noggit/World.h +++ b/src/noggit/World.h @@ -216,6 +216,7 @@ public: void clear_shadows(glm::vec3 const& pos); void clearTextures(glm::vec3 const& pos); void swapTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex); + void removeTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex); void removeTexDuplicateOnADT(glm::vec3 const& pos); void change_texture_flag(glm::vec3 const& pos, scoped_blp_texture_reference const& tex, std::size_t flag, bool add); diff --git a/src/noggit/ui/texture_swapper.cpp b/src/noggit/ui/texture_swapper.cpp index 9cf29c71..ff806c27 100755 --- a/src/noggit/ui/texture_swapper.cpp +++ b/src/noggit/ui/texture_swapper.cpp @@ -36,11 +36,13 @@ namespace Noggit QPushButton* select = new QPushButton("Select", this); QPushButton* swap_adt = new QPushButton("Swap ADT", this); + QPushButton* remove_text_adt = new QPushButton("Remove this texture from ADT", this); layout->addRow(new QLabel("Texture to swap")); layout->addRow(_texture_to_swap_display); layout->addRow(select); layout->addRow(swap_adt); + layout->addRow(remove_text_adt); _brush_mode_group = new QGroupBox("Brush mode", this); _brush_mode_group->setCheckable(true); @@ -82,6 +84,15 @@ namespace Noggit } }); + connect(remove_text_adt, &QPushButton::clicked, [this, camera_pos, map_view]() { + if (_texture_to_swap) + { + ActionManager::instance()->beginAction(map_view, ActionFlags::eCHUNKS_TEXTURE); + _world->removeTexture(*camera_pos, _texture_to_swap.value()); + ActionManager::instance()->endAction(); + } + }); + connect ( _radius_spin, qOverload (&QDoubleSpinBox::valueChanged) , [&](double v) {