implement radius based input for hole tool

This commit is contained in:
Skarn
2020-10-13 12:57:10 +03:00
parent dd3e1a5df9
commit 234aa4cbae
7 changed files with 38 additions and 12 deletions

View File

@@ -1038,7 +1038,7 @@ bool MapChunk::isHole(int i, int j)
return (holes & ((1 << ((j * 4) + i)))) != 0; return (holes & ((1 << ((j * 4) + i)))) != 0;
} }
void MapChunk::setHole(math::vector_3d const& pos, bool big, bool add) void MapChunk::setHole(math::vector_3d const& pos, float radius, bool big, bool add)
{ {
if (big) if (big)
{ {
@@ -1046,8 +1046,21 @@ void MapChunk::setHole(math::vector_3d const& pos, bool big, bool add)
} }
else else
{ {
int v = 1 << ((int)((pos.z - zbase) / MINICHUNKSIZE) * 4 + (int)((pos.x - xbase) / MINICHUNKSIZE)); for (int x = 0; x < 4; ++x)
holes = add ? (holes | v) : (holes & ~v); {
for (int y = 0; y < 4; ++y)
{
if (misc::getShortestDist(pos.x, pos.z, xbase + (MINICHUNKSIZE * x),
zbase + (MINICHUNKSIZE * y), MINICHUNKSIZE) <= radius)
{
int v = 1 << (y * 4 + x);
holes = add ? (holes | v) : (holes & ~v);
}
}
}
} }
initStrip(); initStrip();

View File

@@ -174,7 +174,7 @@ public:
//! \todo implement Action stack for these //! \todo implement Action stack for these
bool isHole(int i, int j); bool isHole(int i, int j);
void setHole(math::vector_3d const& pos, bool big, bool add); void setHole(math::vector_3d const& pos, float radius, bool big, bool add);
void setFlag(bool value, uint32_t); void setFlag(bool value, uint32_t);

View File

@@ -1840,11 +1840,11 @@ void MapView::tick (float dt)
// no undermap check here, else it's impossible to remove holes // no undermap check here, else it's impossible to remove holes
if (_mod_shift_down) if (_mod_shift_down)
{ {
_world->setHole(_cursor_pos, _mod_alt_down, false); _world->setHole(_cursor_pos, holeTool->brushRadius(),_mod_alt_down, false);
} }
else if (_mod_ctrl_down && !underMap) else if (_mod_ctrl_down && !underMap)
{ {
_world->setHole(_cursor_pos, _mod_alt_down, true); _world->setHole(_cursor_pos, holeTool->brushRadius(), _mod_alt_down, true);
} }
break; break;
case editing_mode::areaid: case editing_mode::areaid:
@@ -2362,6 +2362,9 @@ void MapView::draw_map()
case editing_mode::areaid: case editing_mode::areaid:
radius = ZoneIDBrowser->brushRadius(); radius = ZoneIDBrowser->brushRadius();
break; break;
case editing_mode::holes:
radius = holeTool->brushRadius();
break;
} }
//! \note Select terrain below mouse, if no item selected or the item is map. //! \note Select terrain below mouse, if no item selected or the item is map.
@@ -2723,6 +2726,9 @@ void MapView::mouseMoveEvent (QMouseEvent* event)
case editing_mode::areaid: case editing_mode::areaid:
ZoneIDBrowser->changeRadius(relative_movement.dx() / XSENS); ZoneIDBrowser->changeRadius(relative_movement.dx() / XSENS);
break; break;
case editing_mode::holes:
holeTool->changeRadius(relative_movement.dx() / XSENS);
break;
} }
} }

View File

@@ -1647,14 +1647,21 @@ void World::overwriteTextureAtCurrentChunk(math::vector_3d const& pos, scoped_bl
for_chunk_at(pos, [&](MapChunk* chunk) {chunk->switchTexture(oldTexture, std::move (newTexture));}); for_chunk_at(pos, [&](MapChunk* chunk) {chunk->switchTexture(oldTexture, std::move (newTexture));});
} }
void World::setHole(math::vector_3d const& pos, bool big, bool hole) void World::setHole(math::vector_3d const& pos, float radius, bool big, bool hole)
{ {
for_chunk_at(pos, [&](MapChunk* chunk) { chunk->setHole(pos, big, hole); }); for_all_chunks_in_range
( pos, radius
, [&](MapChunk* chunk)
{
chunk->setHole(pos, radius, big, hole);
return true;
}
);
} }
void World::setHoleADT(math::vector_3d const& pos, bool hole) void World::setHoleADT(math::vector_3d const& pos, bool hole)
{ {
for_all_chunks_on_tile(pos, [&](MapChunk* chunk) { chunk->setHole(pos, true, hole); }); for_all_chunks_on_tile(pos, [&](MapChunk* chunk) { chunk->setHole(pos, 1.0f, true, hole); });
} }

View File

@@ -231,7 +231,7 @@ public:
void removeTexDuplicateOnADT(math::vector_3d const& pos); void removeTexDuplicateOnADT(math::vector_3d const& pos);
void change_texture_flag(math::vector_3d const& pos, scoped_blp_texture_reference const& tex, std::size_t flag, bool add); void change_texture_flag(math::vector_3d const& pos, scoped_blp_texture_reference const& tex, std::size_t flag, bool add);
void setHole(math::vector_3d const& pos, bool big, bool hole); void setHole(math::vector_3d const& pos, float radius, bool big, bool hole);
void setHoleADT(math::vector_3d const& pos, bool hole); void setHoleADT(math::vector_3d const& pos, bool hole);
void addM2 ( std::string const& filename void addM2 ( std::string const& filename

View File

@@ -32,7 +32,7 @@ namespace noggit
layout->addRow ("Radius:", _radius_spin); layout->addRow ("Radius:", _radius_spin);
_radius_slider = new QSlider (Qt::Orientation::Horizontal, this); _radius_slider = new QSlider (Qt::Orientation::Horizontal, this);
_radius_slider->setRange (0, 100); _radius_slider->setRange (0, 250);
_radius_slider->setSliderPosition (_radius); _radius_slider->setSliderPosition (_radius);
layout->addRow (_radius_slider); layout->addRow (_radius_slider);

View File

@@ -20,7 +20,7 @@ namespace noggit
layout->addRow ("Radius:", _radius_spin); layout->addRow ("Radius:", _radius_spin);
_radius_slider = new QSlider (Qt::Orientation::Horizontal, this); _radius_slider = new QSlider (Qt::Orientation::Horizontal, this);
_radius_slider->setRange (0, 100); _radius_slider->setRange (0, 250);
_radius_slider->setSliderPosition (_radius); _radius_slider->setSliderPosition (_radius);
layout->addRow (_radius_slider); layout->addRow (_radius_slider);