18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 07:24:57 +01:00

fix(editor): Fields: the edits of a field stick, the natural slopes stay when the formations are laid again, no holes far off or by a missing chunk

The copy of the field the widgets edit is kept while one of them is held, so a drag ends with what it was dragged to. Laying
the formations again keeps the natural shape of the slopes of each. The surfaces of the fields are made as far as the chunks
are drawn, so their holes never show without them; a field over ground with no chunk is made of what has ground, and waits
only for chunks which are in the files but not loaded yet. Outline it again puts the points on the ground and the cut changes
that field. The holes of the fields are marked (254) and giving one back closes only its own, the holes cut by hand stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ
This commit is contained in:
Claude
2026-11-11 11:43:16 +01:00
parent ff5c7467ed
commit db8ea9081f
6 changed files with 136 additions and 27 deletions

View File

@@ -614,6 +614,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri
terrain_waves m_waves;
heightmap::modifier::natural_shape m_natural{0.8, 15.0, 0.15, 0.3, 0.08};
int m_patch_selected{-1}; // field chosen in the list
heightmap::surface_patch m_patch_edit; // its copy the widgets edit, kept while one of them is held
int m_patch_edited{-1}; // which field m_patch_edit is of
std::string m_patch_reoutline; // the field whose outline was put back to be drawn again: cutting out changes it
void render_fields_ui();
void cut_out_field();
void render_waves_options();

View File

@@ -202,6 +202,36 @@ void editor_mode::cut_out_field()
for (auto const &point : m_paint_outline)
patch.outline.emplace_back(point.x, point.z);
auto patches{m_streamer.patches()};
// the outline of a field put back to be drawn again: that field gets it, the rest of it as it was
auto const again{std::find_if(patches.begin(), patches.end(), [this](heightmap::surface_patch const &Other) { return Other.name == m_patch_reoutline; })};
m_patch_reoutline.clear();
if (again != patches.end())
{
auto const old{*again};
auto const index{static_cast<std::size_t>(again - patches.begin())};
auto outline{std::move(patch.outline)};
patch = old;
patch.outline = std::move(outline);
terrain_history_step();
if (m_waves.on && apply_waves(patch.outline))
forget_ground();
auto const name{patch.name};
patches[index] = patch;
if (false == patch.paint)
{
m_streamer.cut_field(old.outline, false);
m_streamer.cut_field(patch.outline, true);
m_streamer.patches(std::move(patches));
forget_ground();
}
else
repaint_patches(std::move(patches), {index}, {old});
terrain_history_step();
m_patch_selected = static_cast<int>(index);
m_paint_outline.clear();
m_terrain_status = format(STR_C("%s outlined again, Ctrl+Z puts it back"), name.c_str());
return;
}
// a name not taken yet
for (int number = static_cast<int>(patches.size()) + 1;; ++number)
{
@@ -221,7 +251,7 @@ void editor_mode::cut_out_field()
if (separate)
{
// the ground cut away under it, the field drawn over the hole with the heights the terrain has there
m_streamer.cut(outline, true);
m_streamer.cut_field(outline, true);
m_streamer.patches(std::move(patches));
forget_ground();
}
@@ -780,7 +810,14 @@ void editor_mode::render_patches_list()
}
if (m_patch_selected < 0 || m_patch_selected >= static_cast<int>(patches.size()))
return;
auto patch{patches[m_patch_selected]};
// the copy edited is kept from frame to frame while a widget is held, so a drag ends with the values dragged to; taken
// anew from the list otherwise (another field chosen, an undo)
if (false == ImGui::IsAnyItemActive() || m_patch_edited != m_patch_selected)
{
m_patch_edit = patches[m_patch_selected];
m_patch_edited = m_patch_selected;
}
auto &patch{m_patch_edit};
bool changed{false};
char buffer[256];
std::snprintf(buffer, sizeof(buffer), "%s", patch.material.c_str());
@@ -836,7 +873,7 @@ void editor_mode::render_patches_list()
patch.noise = std::max(0.0f, patch.noise);
patch.noise_scale = std::max(0.5f, patch.noise_scale);
auto all{patches};
all[m_patch_selected] = std::move(patch);
all[m_patch_selected] = patch;
repaint_patches(std::move(all), {static_cast<std::size_t>(m_patch_selected)});
return;
}
@@ -845,17 +882,21 @@ void editor_mode::render_patches_list()
m_paint_outline.clear();
for (auto const &point : patch.outline)
{
// on the ground: a field following the terrain has no heights of its own
double height{0.0};
patch.height(point.x, point.y, height);
if (false == m_streamer.height_at(point.x, point.y, height))
patch.height(point.x, point.y, height);
m_paint_outline.emplace_back(point.x, height, point.y);
}
// cutting it out again changes this field, not a new one
m_patch_reoutline = patch.name;
}
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("Puts the outline of the field back as the outline being drawn"));
ImGui::SetTooltip("%s", STR_C("Puts the outline of the field back as the outline being drawn; cut out again, it changes this field"));
ImGui::SameLine();
if (ImGui::Button(STR_C("Give back to the terrain##patch")))
{
auto const gone = patch;
auto const gone = patches[m_patch_selected];
auto all{patches};
all.erase(all.begin() + m_patch_selected);
m_patch_selected = -1;
@@ -866,7 +907,7 @@ void editor_mode::render_patches_list()
m_terrain_status = STR_C("Surface removed, the ground under it has the first material of the palette again");
return;
}
m_streamer.cut(gone.outline, false);
m_streamer.cut_field(gone.outline, false);
m_streamer.patches(std::move(all));
forget_ground();
m_terrain_status = STR_C("Surface removed, the hole under it closed");

View File

@@ -934,6 +934,14 @@ std::size_t editor_mode::nmt_shape_tracks(std::vector<TTrack *> const *Only)
for (auto const &name : gone)
m_streamer.remove_modifier(name);
}
// the natural shape of the slopes made for a formation stays with it when it's laid again
for (auto &modifier : laid)
for (auto const &old : m_streamer.modifiers())
if (old.name == modifier.name)
{
modifier.natural = old.natural;
break;
}
auto const count{laid.size()};
m_streamer.modifiers(std::move(laid));
forget_ground();