From 7880063f5c6b58d8487e7052dd2211f645f84e9c Mon Sep 17 00:00:00 2001 From: maciejbaur Date: Wed, 28 Sep 2022 22:13:54 +0200 Subject: [PATCH] (commands) add radioenable and radiodisable commands --- Train.cpp | 21 +++++++++++++++++++-- Train.h | 2 ++ command.cpp | 2 ++ command.h | 2 ++ driverkeyboardinput.cpp | 2 ++ drivermouseinput.cpp | 6 ++++++ vr/openvr_imp.cpp | 6 ++++++ 7 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Train.cpp b/Train.cpp index db1a7540..f59e9f1d 100644 --- a/Train.cpp +++ b/Train.cpp @@ -426,6 +426,8 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = { { user_command::hornhighactivate, &TTrain::OnCommand_hornhighactivate }, { user_command::whistleactivate, &TTrain::OnCommand_whistleactivate }, { user_command::radiotoggle, &TTrain::OnCommand_radiotoggle }, + { user_command::radioenable, &TTrain::OnCommand_radioenable }, + { user_command::radiodisable, &TTrain::OnCommand_radiodisable }, { user_command::radiochannelincrease, &TTrain::OnCommand_radiochannelincrease }, { user_command::radiochanneldecrease, &TTrain::OnCommand_radiochanneldecrease }, { user_command::radiostopsend, &TTrain::OnCommand_radiostopsend }, @@ -6395,7 +6397,6 @@ void TTrain::OnCommand_whistleactivate( TTrain *Train, command_data const &Comma } void TTrain::OnCommand_radiotoggle( TTrain *Train, command_data const &Command ) { - if( Command.action != GLFW_PRESS ) { return; } // NOTE: we ignore the lack of 3d model to allow system reset after receiving radio-stop signal @@ -6407,10 +6408,26 @@ void TTrain::OnCommand_radiotoggle( TTrain *Train, command_data const &Command ) // only reacting to press, so the sound can loop uninterrupted if( false == Train->mvOccupied->Radio ) { // turn on - Train->mvOccupied->Radio = true; + OnCommand_radioenable(Train, Command); } else { // turn off + OnCommand_radiodisable(Train, Command); + } +} + +void TTrain::OnCommand_radioenable( TTrain *Train, command_data const &Command ) { + if( Command.action != GLFW_PRESS ) { return; } + + if( false == Train->mvOccupied->Radio ) { + Train->mvOccupied->Radio = true; + } +} + +void TTrain::OnCommand_radiodisable( TTrain *Train, command_data const &Command ) { + if( Command.action != GLFW_PRESS ) { return; } + + if(Train->mvOccupied->Radio ) { Train->mvOccupied->Radio = false; } } diff --git a/Train.h b/Train.h index 31f6c23c..407f6590 100644 --- a/Train.h +++ b/Train.h @@ -448,6 +448,8 @@ class TTrain { static void OnCommand_hornhighactivate( TTrain *Train, command_data const &Command ); static void OnCommand_whistleactivate( TTrain *Train, command_data const &Command ); static void OnCommand_radiotoggle( TTrain *Train, command_data const &Command ); + static void OnCommand_radioenable( TTrain *Train, command_data const &Command ); + static void OnCommand_radiodisable( TTrain *Train, command_data const &Command ); static void OnCommand_radiochannelincrease( TTrain *Train, command_data const &Command ); static void OnCommand_radiochanneldecrease( TTrain *Train, command_data const &Command ); static void OnCommand_radiostopsend( TTrain *Train, command_data const &Command ); diff --git a/command.cpp b/command.cpp index bd980d41..f9e59b06 100644 --- a/command.cpp +++ b/command.cpp @@ -136,6 +136,8 @@ commanddescription_sequence Commands_descriptions = { { "hornhighactivate", command_target::vehicle, command_mode::oneoff }, { "whistleactivate", command_target::vehicle, command_mode::oneoff }, { "radiotoggle", command_target::vehicle, command_mode::oneoff }, + { "radioenable", command_target::vehicle, command_mode::oneoff }, + { "radiodisable", command_target::vehicle, command_mode::oneoff }, { "radiochannelincrease", command_target::vehicle, command_mode::oneoff }, { "radiochanneldecrease", command_target::vehicle, command_mode::oneoff }, { "radiostopsend", command_target::vehicle, command_mode::oneoff }, diff --git a/command.h b/command.h index 2c0dff21..61810e37 100644 --- a/command.h +++ b/command.h @@ -129,6 +129,8 @@ enum class user_command { hornhighactivate, whistleactivate, radiotoggle, + radioenable, + radiodisable, radiochannelincrease, radiochanneldecrease, radiostopsend, diff --git a/driverkeyboardinput.cpp b/driverkeyboardinput.cpp index 0fe8736b..7ed2580d 100644 --- a/driverkeyboardinput.cpp +++ b/driverkeyboardinput.cpp @@ -137,6 +137,8 @@ driverkeyboard_input::default_bindings() { { user_command::hornhighactivate, GLFW_KEY_S }, { user_command::whistleactivate, GLFW_KEY_Z }, { user_command::radiotoggle, GLFW_KEY_R | keymodifier::control }, + // radioenable + // radiodisable { user_command::radiochannelincrease, GLFW_KEY_EQUAL }, { user_command::radiochanneldecrease, GLFW_KEY_MINUS }, { user_command::radiostopsend, GLFW_KEY_PAUSE | keymodifier::shift | keymodifier::control }, diff --git a/drivermouseinput.cpp b/drivermouseinput.cpp index eba971da..c611321c 100644 --- a/drivermouseinput.cpp +++ b/drivermouseinput.cpp @@ -776,6 +776,12 @@ drivermouse_input::default_bindings() { { "radio_sw:", { user_command::radiotoggle, user_command::none } }, + { "radioon_sw:", { + user_command::radioenable, + user_command::none } }, + { "radiooff_sw:", { + user_command::radiodisable, + user_command::none } }, { "radiochannel_sw:", { user_command::radiochannelincrease, user_command::radiochanneldecrease } }, diff --git a/vr/openvr_imp.cpp b/vr/openvr_imp.cpp index 00fdc20f..3edbc6c9 100644 --- a/vr/openvr_imp.cpp +++ b/vr/openvr_imp.cpp @@ -657,6 +657,12 @@ std::unordered_map vr_openvr::m_buttonb { "radio_sw:", { user_command::radiotoggle, user_command::none } }, + { "radioon_sw:", { + user_command::radioenable, + user_command::none } }, + { "radiooff_sw:", { + user_command::radiodisable, + user_command::none } }, { "radiochannel_sw:", { user_command::radiochannelincrease, user_command::radiochanneldecrease } },