From dab227d16db080b37828923cea1b226e928630cf Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Sat, 10 Oct 2026 18:19:10 +0200 Subject: [PATCH] Editor: keep the terrain palette rotation/repeat values when the slider is released --- application/editormode.cpp | 18 ++++++++++++------ application/editormode.h | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/application/editormode.cpp b/application/editormode.cpp index 2b70bafa..32f991c5 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -1762,18 +1762,24 @@ void editor_mode::render_terrain_ui() } if (false == layers.empty()) { - auto size{layers[m_terrain_layer].size}; + // the values are kept while dragged and given to the palette once the dragging ends; + // read back from the palette every frame, the release would hand it the old value + if (false == m_terrain_layer_size_dragged) + m_terrain_layer_size = layers[m_terrain_layer].size; ImGui::SetNextItemWidth(120.0f); - ImGui::DragFloat(STR_C("Repeats every (m)"), &size, 0.1f, 0.0f, 200.0f, "%.1f"); + ImGui::DragFloat(STR_C("Repeats every (m)"), &m_terrain_layer_size, 0.1f, 0.0f, 200.0f, "%.1f"); + m_terrain_layer_size_dragged = ImGui::IsItemActive(); if (ImGui::IsItemDeactivatedAfterEdit()) - m_streamer.layer_size(static_cast(m_terrain_layer), size); + m_streamer.layer_size(static_cast(m_terrain_layer), m_terrain_layer_size); if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", STR_C("Metres the textures of the chosen material repeat at; 0: as the material gives it, or 8 m")); - auto rotation{layers[m_terrain_layer].rotation}; + if (false == m_terrain_layer_rotation_dragged) + m_terrain_layer_rotation = layers[m_terrain_layer].rotation; ImGui::SetNextItemWidth(120.0f); - ImGui::SliderFloat(STR_C("Turned by (deg)"), &rotation, -180.0f, 180.0f, "%.0f"); + ImGui::SliderFloat(STR_C("Turned by (deg)"), &m_terrain_layer_rotation, -180.0f, 180.0f, "%.0f"); + m_terrain_layer_rotation_dragged = ImGui::IsItemActive(); if (ImGui::IsItemDeactivatedAfterEdit()) - m_streamer.layer_rotation(static_cast(m_terrain_layer), rotation); + m_streamer.layer_rotation(static_cast(m_terrain_layer), m_terrain_layer_rotation); if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", STR_C("Angle the textures of the chosen material are turned by, on every chunk painted with it.\n" "Ctrl+click to type it. To have the material turned in one place only, fill it there with an angle of its own.")); diff --git a/application/editormode.h b/application/editormode.h index 03a53312..c7dbd391 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -432,6 +432,10 @@ class editor_mode : public application_mode, private editor_track::observer int m_terrain_layer{0}; // entry of the palette painted char m_terrain_material[128]{"grass"}; // material added to the palette float m_terrain_material_size{0.0f}; // metres its textures repeat at, 0: given by the material + float m_terrain_layer_size{0.0f}; // repeat of the chosen palette entry, while it's dragged + bool m_terrain_layer_size_dragged{false}; + float m_terrain_layer_rotation{0.0f}; // angle of the chosen palette entry, while it's dragged + bool m_terrain_layer_rotation_dragged{false}; std::vector m_water_points; // outline of a body of water being drawn float m_water_level{0.0f}; bool m_water_level_edited{false}; // the level was given by hand, the points clicked don't change it