From 080e308d5e32355d742450f10dc9abbef7fbe221 Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 11 Oct 2026 20:46:20 +0200 Subject: [PATCH] feat(editor): picking a drive or its side in the Switch mode panel changes the drive of the selected switch at once, no drive takes it away, each as one undo step; self-test command drivechoice; Polish translation --- application/editormode.h | 1 + application/editormodeselftest.cpp | 13 +++++++++++++ application/editormodetrack.cpp | 18 +++++++++++++++++- lang/editor_pl.po | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/application/editormode.h b/application/editormode.h index d8089832..07480eeb 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -1408,6 +1408,7 @@ class editor_mode : public application_mode, private editor_track::observer std::vector standing_templates(std::function const &Accept) const; bool find_switch_drive(TTrack const &Switch, standing_template &Drive, int &Family, int &Index); bool replace_switch_drive(TTrack &Switch, int Family, bool Flip); + void apply_switch_drive_choice(TTrack &Switch); bool switch_drive_spot(TTrack const &Switch, glm::dvec3 &Location, double &Yaw, glm::dvec2 &Tilt, bool &Rightswitch) const; void switch_drive_captured(TTrack const &Track); void switch_drives_committed(std::vector const &Tracks); diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index eecd34a8..ee138139 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -405,6 +405,19 @@ void editor_mode::selftest_step() m_switch.drive_side = side; WriteLog("SELFTEST switchdrive: " + (index >= 0 && index < static_cast(m_switch.drives.size()) ? m_switch.drives[index].name : std::string{"none"})); } + else if (command == "drivechoice") + { + int index{-1}, side{0}; + words >> index >> side; + scan_switch_drives(); + m_switch.drive = index; + m_switch.drive_side = side; + m_switch.status.clear(); + auto *track{selected_track()}; + if (track != nullptr && track->eType == tt_Switch && false == track->m_editorremoved) + apply_switch_drive_choice(*track); + WriteLog("SELFTEST drivechoice: " + (track != nullptr ? track->name() : std::string{"no switch"}) + ", " + m_switch.status); + } else if (command == "drives") { std::string name; diff --git a/application/editormodetrack.cpp b/application/editormodetrack.cpp index 9eee716e..d05c9d41 100644 --- a/application/editormodetrack.cpp +++ b/application/editormodetrack.cpp @@ -6814,6 +6814,20 @@ bool editor_mode::find_switch_drive(TTrack const &Switch, standing_template &Dri return true; } +void editor_mode::apply_switch_drive_choice(TTrack &Switch) +{ + if (m_switch.drive >= 0) + { + place_switch_drive(Switch); + return; + } + standing_template found; + int family{-1}; + int variant{0}; + if (find_switch_drive(Switch, found, family, variant) && remove_templates({found.instance}) > 0) + m_switch.status = format(STR_C("Switch %s without a drive now"), Switch.name().c_str()); +} + bool editor_mode::flip_switch_drive(TTrack &Switch) { return replace_switch_drive(Switch, -1, true); @@ -7562,7 +7576,9 @@ void editor_mode::render_switch_ui() ImGui::InputTextWithHint(STR_C("Name##switchname"), switch_name_for_new().c_str(), tool.name, sizeof(tool.name)); ImGui::PopItemWidth(); item_tooltip("Name of the next switch, its drive events are named after it; empty: the next free z1, z2...; a number at the end goes up with each switch"); - render_switch_drive_choice(); + if (render_switch_drive_choice()) + if (auto *track{selected_track()}; track != nullptr && track->eType == tt_Switch && false == track->m_editorremoved) + apply_switch_drive_choice(*track); if (false == tool.status.empty()) ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", tool.status.c_str()); if (ImGui::SmallButton(STR_C("Collect from the scenery"))) diff --git a/lang/editor_pl.po b/lang/editor_pl.po index d2b44bda..48a303ad 100644 --- a/lang/editor_pl.po +++ b/lang/editor_pl.po @@ -5452,3 +5452,6 @@ msgstr "Zwrotnica %s: napęd %s, teraz po prawej" msgid "Switch %s: the drive %s, on the left now" msgstr "Zwrotnica %s: napęd %s, teraz po lewej" +msgid "Switch %s without a drive now" +msgstr "Zwrotnica %s jest teraz bez napędu" +