17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-18 06:49:18 +02:00

Editor: keep the terrain palette rotation/repeat values when the slider is released

This commit is contained in:
2026-10-10 18:19:10 +02:00
parent 7b9eaf1ccb
commit dab227d16d
2 changed files with 16 additions and 6 deletions

View File

@@ -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<std::uint16_t>(m_terrain_layer), size);
m_streamer.layer_size(static_cast<std::uint16_t>(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<std::uint16_t>(m_terrain_layer), rotation);
m_streamer.layer_rotation(static_cast<std::uint16_t>(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."));

View File

@@ -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<glm::dvec3> 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