18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 16:14:58 +01:00

feat(ui): repair the broken coupler next to the camera from the driving aid

This commit is contained in:
2026-11-11 02:52:00 +01:00
parent 8e97277bcb
commit aba8687678
8 changed files with 125 additions and 3 deletions

View File

@@ -40,6 +40,24 @@ http://mozilla.org/MPL/2.0/.
#include <format>
namespace {
// how close to a broken coupler the camera has to be for the driving aid to offer its repair [m]
constexpr float coupler_repair_radius { 5.f };
// the broken coupler nearest to the camera, within reach: the vehicle and its end, or no vehicle
std::pair<TDynamicObject const *, int> broken_coupler_nearby( glm::dvec3 const &Camera ) {
auto const *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Camera, coupler_repair_radius, false, true ) ) };
if( vehicle == nullptr || vehicle->MoverParameters == nullptr ) { return { nullptr, end::front }; }
auto const front { glm::distance( vehicle->CouplerPosition( end::front ), Camera ) };
auto const rear { glm::distance( vehicle->CouplerPosition( end::rear ), Camera ) };
auto const nearest { front <= rear ? end::front : end::rear };
if( std::min( front, rear ) > coupler_repair_radius || false == vehicle->MoverParameters->Couplers[ nearest ].broken ) { return { nullptr, end::front }; }
return { vehicle, nearest };
}
} // namespace
void
drivingaid_panel::update() {
@@ -47,6 +65,8 @@ drivingaid_panel::update() {
text_lines.clear();
std::tie( m_brokenvehicle, m_brokenend ) = broken_coupler_nearby( Global.pCamera.Pos );
auto const *train { simulation::Train };
auto const *controlled { ( train ? train->Dynamic() : nullptr ) };
@@ -223,6 +243,12 @@ drivingaid_panel::render_contents() {
}
}
// only the coupler the camera is next to, and the one of the vehicle it was coupled with
if( m_brokenvehicle != nullptr && ImGui::Button( STR_C( "Repair coupler" ) ) ) {
command_relay commandrelay;
commandrelay.post( user_command::repaircoupler, m_brokenend, 0.0, GLFW_PRESS, 0, glm::vec3( 0.0f ), &m_brokenvehicle->name() );
}
ui_panel::render_contents();
}
@@ -1628,8 +1654,8 @@ debug_panel::update_section_coupler( std::vector<text_line> &Output ) {
Output.emplace_back(
std::format( "Stretch: {:.1f} mm, stop: {}, overloaded for {:.1f} s", state.elongation * 1000.0, coupler_stop_name( state.stop ), coupler.stretch_duration ),
Global.UITextColor );
if( TestFlag( mover.DamageFlag, dtrain_coupling ) ) {
Output.emplace_back( "Coupler broken", glm::vec4( 1.f, 0.25f, 0.25f, 1.f ) );
if( coupler.broken ) {
Output.emplace_back( "Coupler broken (repair it in the driving aid, F1)", glm::vec4( 1.f, 0.25f, 0.25f, 1.f ) );
}
}