Swap texture on chunk even if texture set is full

This commit is contained in:
EIntemporel
2022-07-01 19:51:13 +02:00
parent 1b56fc73e6
commit 61de6ffd9d
10 changed files with 32 additions and 9 deletions

View File

@@ -1285,9 +1285,9 @@ bool MapChunk::stampTexture(glm::vec3 const& pos, Brush *brush, float strength,
return texture_set->stampTexture(xbase, zbase, pos.x, pos.z, brush, strength, pressure, std::move (texture), img, paint); return texture_set->stampTexture(xbase, zbase, pos.x, pos.z, brush, strength, pressure, std::move (texture), img, paint);
} }
bool MapChunk::replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture) bool MapChunk::replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture, bool entire_chunk)
{ {
return texture_set->replace_texture(xbase, zbase, pos.x, pos.z, radius, old_texture, std::move (new_texture)); return texture_set->replace_texture(xbase, zbase, pos.x, pos.z, radius, old_texture, std::move (new_texture), entire_chunk);
} }
bool MapChunk::canPaintTexture(scoped_blp_texture_reference texture) bool MapChunk::canPaintTexture(scoped_blp_texture_reference texture)

View File

@@ -157,7 +157,7 @@ public:
//! \todo implement Action stack for these //! \todo implement Action stack for these
bool paintTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture); bool paintTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture);
bool stampTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture, QImage* img, bool paint); bool stampTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture, QImage* img, bool paint);
bool replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture); bool replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture, bool entire_chunk = false);
bool canPaintTexture(scoped_blp_texture_reference texture); bool canPaintTexture(scoped_blp_texture_reference texture);
int addTexture(scoped_blp_texture_reference texture); int addTexture(scoped_blp_texture_reference texture);
void switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture); void switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture);

View File

@@ -1190,7 +1190,7 @@ bool World::sprayTexture(glm::vec3 const& pos, Brush *brush, float strength, flo
return succ; return succ;
} }
bool World::replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture) bool World::replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture, bool entire_chunk)
{ {
ZoneScoped; ZoneScoped;
return for_all_chunks_in_range return for_all_chunks_in_range
@@ -1198,7 +1198,7 @@ bool World::replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_textur
, [&](MapChunk* chunk) , [&](MapChunk* chunk)
{ {
NOGGIT_CUR_ACTION->registerChunkTextureChange(chunk); NOGGIT_CUR_ACTION->registerChunkTextureChange(chunk);
return chunk->replaceTexture(pos, radius, old_texture, new_texture); return chunk->replaceTexture(pos, radius, old_texture, new_texture, entire_chunk);
} }
); );
} }

View File

@@ -208,7 +208,7 @@ public:
bool paintTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture); bool paintTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture);
bool stampTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture, QImage* img, bool paint); bool stampTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture, QImage* img, bool paint);
bool sprayTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, float spraySize, float sprayPressure, scoped_blp_texture_reference texture); bool sprayTexture(glm::vec3 const& pos, Brush *brush, float strength, float pressure, float spraySize, float sprayPressure, scoped_blp_texture_reference texture);
bool replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture); bool replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture, bool entire_chunk = false);
void eraseTextures(glm::vec3 const& pos); void eraseTextures(glm::vec3 const& pos);
void overwriteTextureAtCurrentChunk(glm::vec3 const& pos, scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture); void overwriteTextureAtCurrentChunk(glm::vec3 const& pos, scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture);

View File

@@ -1663,4 +1663,4 @@ bool WorldRender::saveMinimap(TileIndex const& tile_idx, MinimapRenderSettings*
pixel_buffer.release(); pixel_buffer.release();
return true; return true;
} }

View File

@@ -817,6 +817,7 @@ bool TextureSet::replace_texture( float xbase
, float radius , float radius
, scoped_blp_texture_reference const& texture_to_replace , scoped_blp_texture_reference const& texture_to_replace
, scoped_blp_texture_reference replacement_texture , scoped_blp_texture_reference replacement_texture
, bool entire_chunk
) )
{ {
float dist = misc::getShortestDist(x, z, xbase, zbase, CHUNKSIZE); float dist = misc::getShortestDist(x, z, xbase, zbase, CHUNKSIZE);
@@ -826,6 +827,14 @@ bool TextureSet::replace_texture( float xbase
return false; return false;
} }
if (entire_chunk)
{
replace_texture(texture_to_replace, std::move (replacement_texture));
_chunk->registerChunkUpdate(ChunkUpdateFlags::ALPHAMAP);
_need_lod_texture_map_update = true;
return true;
}
// if the chunk is fully inside the brush, just swap the 2 textures // if the chunk is fully inside the brush, just swap the 2 textures
if (misc::square_is_in_circle(x, z, radius, xbase, zbase, CHUNKSIZE)) if (misc::square_is_in_circle(x, z, radius, xbase, zbase, CHUNKSIZE))
{ {
@@ -1368,4 +1377,4 @@ std::array<std::uint16_t, 8> TextureSet::lod_texture_map()
} }
return _doodadMapping; return _doodadMapping;
} }

View File

@@ -55,6 +55,7 @@ public:
, float radius , float radius
, scoped_blp_texture_reference const& texture_to_replace , scoped_blp_texture_reference const& texture_to_replace
, scoped_blp_texture_reference replacement_texture , scoped_blp_texture_reference replacement_texture
, bool entire_chunk = false
); );
bool canPaintTexture(scoped_blp_texture_reference const& texture); bool canPaintTexture(scoped_blp_texture_reference const& texture);

View File

@@ -51,6 +51,11 @@ namespace Noggit
auto brush_layout (new QFormLayout(brush_content)); auto brush_layout (new QFormLayout(brush_content));
_brush_mode_group->setLayout(brush_layout); _brush_mode_group->setLayout(brush_layout);
_swap_entire_chunk = new QCheckBox(brush_content);
_swap_entire_chunk->setText(tr("Entire chunk"));
_swap_entire_chunk->setCheckState(Qt::CheckState::Unchecked);
brush_layout->addRow(_swap_entire_chunk);
_radius_spin = new QDoubleSpinBox(brush_content); _radius_spin = new QDoubleSpinBox(brush_content);
_radius_spin->setRange (0.f, 100.f); _radius_spin->setRange (0.f, 100.f);
_radius_spin->setDecimals (2); _radius_spin->setDecimals (2);

View File

@@ -6,6 +6,7 @@
#include <QtWidgets/QDoubleSpinBox> #include <QtWidgets/QDoubleSpinBox>
#include <QtWidgets/QGroupBox> #include <QtWidgets/QGroupBox>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QSlider> #include <QtWidgets/QSlider>
#include <QtWidgets/QWidget> #include <QtWidgets/QWidget>
#include <optional> #include <optional>
@@ -35,6 +36,11 @@ namespace Noggit
return _radius; return _radius;
} }
bool entireChunk() const
{
return _swap_entire_chunk->isChecked();
}
void change_radius(float change); void change_radius(float change);
bool brush_mode() const bool brush_mode() const
@@ -60,6 +66,7 @@ namespace Noggit
QGroupBox* _brush_mode_group; QGroupBox* _brush_mode_group;
QSlider* _radius_slider; QSlider* _radius_slider;
QCheckBox* _swap_entire_chunk;
QDoubleSpinBox* _radius_spin; QDoubleSpinBox* _radius_spin;
World* _world; World* _world;
}; };

View File

@@ -514,7 +514,8 @@ namespace Noggit
{ {
if (_texture_switcher->brush_mode()) if (_texture_switcher->brush_mode())
{ {
world->replaceTexture(pos, _texture_switcher->radius(), to_swap.value(), texture); std::cout << _texture_switcher->radius() << std::endl;
world->replaceTexture(pos, _texture_switcher->radius(), to_swap.value(), texture, _texture_switcher->entireChunk());
} }
else else
{ {