diff --git a/Driver.cpp b/Driver.cpp index 0560d0df..637ce102 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -1708,20 +1708,20 @@ std::array orderbuffer; std::string TController::OrderCurrent() const { // pobranie aktualnego rozkazu celem wyƛwietlenia auto const order { OrderCurrentGet() }; - if( order & Change_direction ) { - return locale::strings[ locale::string::driver_scenario_changedirection ]; + if( order & Change_direction ) { + return STR(driver_scenario_changedirection); } switch( OrderList[ OrderPos ] ) { - case Wait_for_orders: { return locale::strings[ locale::string::driver_scenario_waitfororders ]; } - case Prepare_engine: { return locale::strings[ locale::string::driver_scenario_prepareengine ]; } - case Release_engine: { return locale::strings[ locale::string::driver_scenario_releaseengine ]; } - case Change_direction: { return locale::strings[ locale::string::driver_scenario_changedirection ]; } - case Connect: { return locale::strings[ locale::string::driver_scenario_connect ]; } + case Wait_for_orders: { return STR(driver_scenario_waitfororders); } + case Prepare_engine: { return STR(driver_scenario_prepareengine); } + case Release_engine: { return STR(driver_scenario_releaseengine); } + case Change_direction: { return STR(driver_scenario_changedirection); } + case Connect: { return STR(driver_scenario_connect); } case Disconnect: { if( iVehicleCount < 0 ) { // done with uncoupling, order should update shortly - return locale::strings[ locale::string::driver_scenario_waitfororders ]; + return STR(driver_scenario_waitfororders); } // try to provide some task details auto const count { iVehicleCount }; @@ -1730,25 +1730,25 @@ std::string TController::OrderCurrent() const std::snprintf( orderbuffer.data(), orderbuffer.size(), ( iVehicleCount < 5 ? - locale::strings[ locale::string::driver_scenario_fewvehicles ].c_str() : // 2-4 - locale::strings[ locale::string::driver_scenario_somevehicles ].c_str() ), // 5+ + STR_C(driver_scenario_fewvehicles) : // 2-4 + STR_C(driver_scenario_somevehicles) ), // 5+ count ); } auto const countstring { ( - count == 0 ? locale::strings[ locale::string::driver_scenario_allvehicles ] : - count == 1 ? locale::strings[ locale::string::driver_scenario_onevehicle ] : + count == 0 ? STR(driver_scenario_allvehicles) : + count == 1 ? STR(driver_scenario_onevehicle) : orderbuffer.data() ) }; std::snprintf( orderbuffer.data(), orderbuffer.size(), - locale::strings[ locale::string::driver_scenario_disconnect ].c_str(), + STR_C(driver_scenario_disconnect), countstring.c_str() ); return orderbuffer.data(); } - case Shunt: { return locale::strings[ locale::string::driver_scenario_shunt ]; } - case Loose_shunt: { return locale::strings[ locale::string::driver_scenario_looseshunt ]; } - case Obey_train: { return locale::strings[ locale::string::driver_scenario_obeytrain ]; } - case Bank: { return locale::strings[ locale::string::driver_scenario_bank ]; } + case Shunt: { return STR(driver_scenario_shunt); } + case Loose_shunt: { return STR(driver_scenario_looseshunt); } + case Obey_train: { return STR(driver_scenario_obeytrain); } + case Bank: { return STR(driver_scenario_bank); } default: { return{}; } } }; diff --git a/application.cpp b/application.cpp index 41f6d63f..08f56d4d 100644 --- a/application.cpp +++ b/application.cpp @@ -622,7 +622,7 @@ eu07_application::init_settings( int Argc, char *Argv[] ) { int eu07_application::init_locale() { - locale::init(); + Translations.init(); return 0; } diff --git a/driveruilayer.cpp b/driveruilayer.cpp index 73f8d1c7..bf8cfba2 100644 --- a/driveruilayer.cpp +++ b/driveruilayer.cpp @@ -37,17 +37,17 @@ driver_ui::driver_ui() { add_external_panel( &m_cameraviewpanel ); m_logpanel.is_open = false; - m_aidpanel.title = locale::strings[ locale::string::driver_aid_header ]; + m_aidpanel.title = STR(driver_aid_header); - m_scenariopanel.title = locale::strings[ locale::string::driver_scenario_header ]; + m_scenariopanel.title = STR(driver_scenario_header); m_scenariopanel.size_min = { 435, 85 }; m_scenariopanel.size_max = { Global.iWindowWidth * 0.95, Global.iWindowHeight * 0.95 }; - m_timetablepanel.title = locale::strings[ locale::string::driver_timetable_header ]; + m_timetablepanel.title = STR(driver_timetable_header); m_timetablepanel.size_min = { 435, 110 }; m_timetablepanel.size_max = { 435, Global.iWindowHeight * 0.95 }; - m_transcriptspanel.title = locale::strings[ locale::string::driver_transcripts_header ]; + m_transcriptspanel.title = STR(driver_transcripts_header); m_transcriptspanel.size_min = { 435, 85 }; m_transcriptspanel.size_max = { Global.iWindowWidth * 0.95, Global.iWindowHeight * 0.95 }; } @@ -55,10 +55,10 @@ driver_ui::driver_ui() { void driver_ui::render_menu_contents() { ui_layer::render_menu_contents(); - if (ImGui::BeginMenu(locale::strings[locale::string::ui_mode_windows].c_str())) + if (ImGui::BeginMenu(STR_C(ui_mode_windows))) { ImGui::MenuItem(m_aidpanel.title.c_str(), "F1", &m_aidpanel.is_open); - ImGui::MenuItem(locale::strings[locale::string::driver_timetable_name].c_str(), "F2", &m_timetablepanel.is_open); + ImGui::MenuItem(STR_C(driver_timetable_name), "F2", &m_timetablepanel.is_open); ImGui::MenuItem(m_debugpanel.name().c_str(), "F12", &m_debugpanel.is_open); ImGui::MenuItem(m_mappanel.name().c_str(), "Tab", &m_mappanel.is_open); ImGui::MenuItem(m_vehiclelist.name().c_str(), nullptr, &m_vehiclelist.is_open); @@ -192,7 +192,7 @@ driver_ui::update() { if( ( train != nullptr ) && ( false == FreeFlyModeFlag ) ) { if( false == DebugModeFlag ) { // in regular mode show control functions, for defined controls - set_tooltip( locale::label_cab_control( train->GetLabel( GfxRenderer.get_picked_control() ) ) ); + set_tooltip( Translations.label_cab_control( train->GetLabel( GfxRenderer.get_picked_control() ) ) ); } else { // in debug mode show names of submodels, to help with cab setup and/or debugging @@ -228,18 +228,18 @@ driver_ui::set_cursor( bool const Visible ) { void driver_ui::render_() { // pause/quit modal - auto const popupheader { locale::strings[ locale::string::driver_pause_header ].c_str() }; + auto const popupheader { STR_C(driver_pause_header) }; if (m_paused && !m_pause_modal_opened) { m_pause_modal_opened = true; ImGui::OpenPopup(popupheader); } if( ImGui::BeginPopupModal( popupheader, &m_pause_modal_opened, ImGuiWindowFlags_AlwaysAutoResize ) ) { - auto const popupwidth{ locale::strings[ locale::string::driver_pause_header ].size() * 7 }; - if( ImGui::Button( locale::strings[ locale::string::driver_pause_resume ].c_str(), ImVec2( popupwidth, 0 ) ) ) { + auto const popupwidth{ STR(driver_pause_header).size() * 7 }; + if( ImGui::Button( STR_C(driver_pause_resume), ImVec2( popupwidth, 0 ) ) ) { m_relay.post(user_command::pausetoggle, 0.0, 0.0, GLFW_PRESS, 0); } - if( ImGui::Button( locale::strings[ locale::string::driver_pause_quit ].c_str(), ImVec2( popupwidth, 0 ) ) ) { + if( ImGui::Button( STR_C(driver_pause_quit), ImVec2( popupwidth, 0 ) ) ) { m_relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0); } if (!m_paused) diff --git a/driveruipanels.cpp b/driveruipanels.cpp index 54908f35..a3f6ed67 100644 --- a/driveruipanels.cpp +++ b/driveruipanels.cpp @@ -53,7 +53,7 @@ drivingaid_panel::update() { if( std::abs( grade ) >= 0.25 ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_aid_grade ].c_str(), + STR_C(driver_aid_grade), grade ); gradetext = m_buffer.data(); } @@ -64,7 +64,7 @@ drivingaid_panel::update() { if( nextspeedlimit != speedlimit ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_aid_nextlimit ].c_str(), + STR_C(driver_aid_nextlimit), nextspeedlimit, driver->ActualProximityDist * 0.001 ); nextspeedlimittext = m_buffer.data(); @@ -72,7 +72,7 @@ drivingaid_panel::update() { // current speed and limit std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_aid_speedlimit ].c_str(), + STR_C(driver_aid_speedlimit), static_cast( std::floor( mover->Vel ) ), speedlimit, nextspeedlimittext.c_str(), @@ -82,7 +82,7 @@ drivingaid_panel::update() { // base data and optional bits put together std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_aid_throttle ].c_str(), + STR_C(driver_aid_throttle), driver->Controlling()->MainCtrlPos, driver->Controlling()->ScndCtrlPos, ( mover->ActiveDir > 0 ? 'D' : mover->ActiveDir < 0 ? 'R' : 'N' ), @@ -96,14 +96,14 @@ drivingaid_panel::update() { if( is_expanded ) { std::snprintf ( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_aid_pressures ].c_str(), + STR_C(driver_aid_pressures), mover->BrakePress * 100, mover->PipePress * 100 ); expandedtext = m_buffer.data(); } std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_aid_brakes ].c_str(), + STR_C(driver_aid_brakes), mover->fBrakeCtrlPos, mover->LocalBrakePosA * LocalBrakePosNo, ( mover->SlippingWheels ? '!' : ' ' ), @@ -119,7 +119,7 @@ drivingaid_panel::update() { if( stoptime > 0 ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_aid_loadinginprogress ].c_str(), + STR_C(driver_aid_loadinginprogress), stoptime ); expandedtext = m_buffer.data(); } @@ -128,7 +128,7 @@ drivingaid_panel::update() { if( trackblockdistance <= 75.0 ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_aid_vehicleahead ].c_str(), + STR_C(driver_aid_vehicleahead), trackblockdistance ); expandedtext = m_buffer.data(); } @@ -136,11 +136,11 @@ drivingaid_panel::update() { } std::string textline = ( mover->SecuritySystem.is_vigilance_blinking() ? - locale::strings[ locale::string::driver_aid_alerter ] : + STR(driver_aid_alerter) : " " ); textline += ( mover->SecuritySystem.is_cabsignal_blinking() ? - locale::strings[ locale::string::driver_aid_shp ] : + STR(driver_aid_shp) : " " ); text_lines.emplace_back( textline + " " + expandedtext, Global.UITextColor ); @@ -169,7 +169,7 @@ scenario_panel::update() { if( owner == nullptr ) { return; } std::string textline = - locale::strings[ locale::string::driver_scenario_currenttask ] + "\n " + STR(driver_scenario_currenttask) + "\n " + owner->OrderCurrent(); text_lines.emplace_back( textline, Global.UITextColor ); @@ -205,7 +205,7 @@ scenario_panel::render() { m_nearest->Mechanik : m_nearest->ctOwner ) }; if( owner != nullptr ) { - auto const assignmentheader { locale::strings[ locale::string::driver_scenario_assignment ] }; + auto const assignmentheader { STR(driver_scenario_assignment) }; if( ( false == owner->assignment().empty() ) && ( true == ImGui::CollapsingHeader( assignmentheader.c_str() ) ) ) { ImGui::TextWrapped( "%s", owner->assignment().c_str() ); @@ -236,9 +236,9 @@ timetable_panel::update() { { // current time std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_timetable_header ].c_str(), + STR_C(driver_timetable_header), 37, 37, - locale::strings[ locale::string::driver_timetable_name ].c_str(), + STR_C(driver_timetable_name), time.wHour, time.wMinute, time.wSecond ); @@ -300,7 +300,7 @@ timetable_panel::update() { } std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::driver_timetable_consistdata ].c_str(), + STR_C(driver_timetable_consistdata), static_cast( table->LocLoad ), static_cast( consistmass / 1000 ), static_cast( consistlength ) ); @@ -311,7 +311,7 @@ timetable_panel::update() { if( 0 == table->StationCount ) { // only bother if there's stations to list - text_lines.emplace_back( locale::strings[ locale::string::driver_timetable_notimetable ], Global.UITextColor ); + text_lines.emplace_back( STR(driver_timetable_notimetable), Global.UITextColor ); } else { @@ -554,9 +554,9 @@ debug_panel::update_section_vehicle( std::vector &Output ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::debug_vehicle_nameloadstatuscouplers ].c_str(), + STR_C(debug_vehicle_nameloadstatuscouplers), mover.Name.c_str(), - std::string( isowned ? locale::strings[ locale::string::debug_vehicle_owned ].c_str() + vehicle.ctOwner->OwnerName() : "" ).c_str(), + std::string( isowned ? STR(debug_vehicle_owned) + vehicle.ctOwner->OwnerName() : "" ).c_str(), mover.LoadAmount, mover.LoadType.name.c_str(), mover.EngineDescription( 0 ).c_str(), @@ -569,7 +569,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::debug_vehicle_devicespower ].c_str(), + STR_C(debug_vehicle_devicespower), // devices ( mover.Battery ? 'B' : '.' ), ( mover.Mains ? 'M' : '.' ), @@ -585,8 +585,8 @@ debug_panel::update_section_vehicle( std::vector &Output ) { ( mover.ConvOvldFlag ? '!' : '.' ), ( mover.CompressorFlag ? 'C' : ( false == mover.CompressorAllowLocal ? '-' : ( ( mover.CompressorAllow || mover.CompressorStart == start_t::automatic ) ? 'c' : '.' ) ) ), ( mover.CompressorGovernorLock ? '!' : '.' ), - std::string( isplayervehicle ? locale::strings[ locale::string::debug_vehicle_radio ] + ( mover.Radio ? std::to_string( m_input.train->RadioChannel() ) : "-" ) : "" ).c_str(), - std::string( isdieselenginepowered ? locale::strings[ locale::string::debug_vehicle_oilpressure ] + to_string( mover.OilPump.pressure, 2 ) : "" ).c_str(), + std::string( isplayervehicle ? STR(debug_vehicle_radio) + ( mover.Radio ? std::to_string( m_input.train->RadioChannel() ) : "-" ) : "" ).c_str(), + std::string( isdieselenginepowered ? STR(debug_vehicle_oilpressure) + to_string( mover.OilPump.pressure, 2 ) : "" ).c_str(), // power transfers mover.Couplers[ end::front ].power_high.voltage, mover.Couplers[ end::front ].power_high.current, @@ -600,11 +600,11 @@ debug_panel::update_section_vehicle( std::vector &Output ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::debug_vehicle_controllersenginerevolutions ].c_str(), + STR_C(debug_vehicle_controllersenginerevolutions), // controllers mover.MainCtrlPos, mover.MainCtrlActualPos, - std::string( isdieselinshuntmode ? to_string( mover.AnPos, 2 ) + locale::strings[ locale::string::debug_vehicle_shuntmode ] : std::to_string( mover.ScndCtrlPos ) + "(" + std::to_string( mover.ScndCtrlActualPos ) + ")" ).c_str(), + std::string( isdieselinshuntmode ? to_string( mover.AnPos, 2 ) + STR(debug_vehicle_shuntmode) : std::to_string( mover.ScndCtrlPos ) + "(" + std::to_string( mover.ScndCtrlActualPos ) + ")" ).c_str(), // engine mover.EnginePower, std::abs( mover.TrainType == dt_EZT ? mover.ShowCurrent( 0 ) : mover.Im ), @@ -622,7 +622,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) { if( isdieselenginepowered ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::debug_vehicle_temperatures ].c_str(), + STR_C(debug_vehicle_temperatures), mover.dizel_heat.Ts, mover.dizel_heat.To, mover.dizel_heat.temperatura1, @@ -635,7 +635,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::debug_vehicle_brakespressures ].c_str(), + STR_C(debug_vehicle_brakespressures), // brakes mover.fBrakeCtrlPos, mover.LocalBrakePosA, @@ -661,7 +661,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) { if( mover.EnginePowerSource.SourceType == TPowerSource::CurrentCollector ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::debug_vehicle_pantograph ].c_str(), + STR_C(debug_vehicle_pantograph), mover.PantPress, ( mover.bPantKurek3 ? '-' : '|' ) ); textline += m_buffer.data(); @@ -677,7 +677,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) { std::snprintf( m_buffer.data(), m_buffer.size(), - locale::strings[ locale::string::debug_vehicle_forcesaccelerationvelocityposition ].c_str(), + STR_C(debug_vehicle_forcesaccelerationvelocityposition), // forces mover.Ft * 0.001f * ( mover.ActiveCab ? mover.ActiveCab : vehicle.ctOwner ? vehicle.ctOwner->Controlling()->ActiveCab : 1 ) + 0.001f, mover.Fb * 0.001f, @@ -702,7 +702,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) { std::string debug_panel::update_vehicle_coupler( int const Side ) { // NOTE: mover and vehicle are guaranteed to be valid by the caller - std::string couplerstatus { locale::strings[ locale::string::debug_vehicle_none ] }; + std::string couplerstatus { STR(debug_vehicle_none) }; auto const *connected { m_input.vehicle->MoverParameters->Neighbours[ Side ].vehicle }; diff --git a/editoruilayer.cpp b/editoruilayer.cpp index c8fdc07e..f37f549f 100644 --- a/editoruilayer.cpp +++ b/editoruilayer.cpp @@ -74,7 +74,7 @@ const std::string *editor_ui::get_active_node_template() { void editor_ui::render_menu_contents() { ui_layer::render_menu_contents(); - if (ImGui::BeginMenu(locale::strings[locale::string::ui_mode_windows].c_str())) + if (ImGui::BeginMenu(STR_C(ui_mode_windows))) { ImGui::MenuItem(m_nodebankpanel.title.c_str(), nullptr, &m_nodebankpanel.is_open); ImGui::EndMenu(); diff --git a/keyboardinput.h b/keyboardinput.h index ec6ab9ff..6ce3239e 100644 --- a/keyboardinput.h +++ b/keyboardinput.h @@ -25,13 +25,6 @@ extern bool key_shift; class keyboard_input { public: // types - /* - struct binding_setup { - - user_command command; - int binding; - };*/ - using bindingsetup_sequence = std::map; enum keymodifier : int { diff --git a/scenarioloadermode.cpp b/scenarioloadermode.cpp index 15e2b443..ecce7a8d 100644 --- a/scenarioloadermode.cpp +++ b/scenarioloadermode.cpp @@ -83,7 +83,7 @@ scenarioloader_mode::enter() { m_userinterface->set_background( "logo" ); Application.set_title( Global.AppName + " (" + Global.SceneryFile + ")" ); m_userinterface->set_progress(); - m_userinterface->set_progress(locale::strings[locale::string::ui_loading_scenery]); + m_userinterface->set_progress(STR(ui_loading_scenery)); GfxRenderer.Render(); } diff --git a/translation.cpp b/translation.cpp index 366a1330..1460e809 100644 --- a/translation.cpp +++ b/translation.cpp @@ -576,8 +576,7 @@ void locale::init() return; } - while (stream.eof()) - parse_translation(stream); + while (parse_translation(stream)); WriteLog("translation: " + std::to_string(lang_mapping.size()) + " strings loaded"); } @@ -587,7 +586,7 @@ const std::string& locale::lookup_s(const std::string &msg, bool constant) if (constant) { auto it = pointer_cache.find(&msg); if (it != pointer_cache.end()) - return *(it->second); + return *((const std::string*)(it->second)); } auto it = lang_mapping.find(msg); @@ -602,25 +601,27 @@ const std::string& locale::lookup_s(const std::string &msg, bool constant) return msg; } -const char* locale::lookup(const char *msg, bool constant) +const char* locale::lookup_c(const char *msg, bool constant) { if (constant) { - auto it = pointer_cache.find(&msg); + auto it = pointer_cache.find(msg); if (it != pointer_cache.end()) - return it->second->c_str(); + return (const char*)(it->second); } auto it = lang_mapping.find(std::string(msg)); if (it != lang_mapping.end()) { if (constant) - pointer_cache.emplace(&msg, &(it->second)); + pointer_cache.emplace(msg, it->second.c_str()); return it->second.c_str(); } + if (constant) + pointer_cache.emplace(msg, msg); return msg; } -void locale::parse_translation(std::istream &stream) +bool locale::parse_translation(std::istream &stream) { std::string line; @@ -649,11 +650,17 @@ void locale::parse_translation(std::istream &stream) msgctxt += parse_c_literal(line); } else { - if (!msgid.empty() && !msgstr.empty()) - lang_mapping.emplace(msgctxt + "\x1d" + msgid, msgstr); - return; + if (!msgid.empty() && !msgstr.empty()) { + if (!msgctxt.empty()) + lang_mapping.emplace(msgctxt + "\x1d" + msgid, msgstr); + else + lang_mapping.emplace(msgid, msgstr); + } + return true; } } + + return false; } std::string locale::parse_c_literal(const std::string &str) @@ -665,7 +672,7 @@ std::string locale::parse_c_literal(const std::string &str) bool escape = false; char c; - while ((c = stream.get()) != stream.eof()) { + while ((c = stream.get()) != std::char_traits::eof()) { if (!escape && c == '"') active = !active; else if (active && !escape && c == '\\') @@ -826,3 +833,5 @@ std::string locale::label_cab_control(std::string const &Label) lookup_s(it->second) : "" ); } + +locale Translations; diff --git a/translation.h b/translation.h index b6d70793..fb1262c6 100644 --- a/translation.h +++ b/translation.h @@ -226,20 +226,23 @@ http://mozilla.org/MPL/2.0/. class locale { public: - static void init(); - static std::string label_cab_control(const std::string &Label); + void init(); + std::string label_cab_control(const std::string &Label); - static const char* lookup(const char *msg, bool constant = true); - static const std::string& lookup_s(const std::string &msg, bool constant = true); + const char* lookup_c(const char *msg, bool constant = false); + const std::string& lookup_s(const std::string &msg, bool constant = false); private: - static void parse_translation(std::istream &stream); - static std::string parse_c_literal(const std::string &str); + bool parse_translation(std::istream &stream); + std::string parse_c_literal(const std::string &str); - static std::unordered_map lang_mapping; - static std::unordered_map pointer_cache; + std::unordered_map lang_mapping; + std::unordered_map pointer_cache; }; -#define LOC_STR(x) locale::lookup_s(#x) -#define LOC_STR_C(x) locale::lookup(#x) +extern locale Translations; +#define STR(x) Translations.lookup_s(#x, true) +#define STR_C(x) Translations.lookup_c(#x, true) +#define STRC(x, c) Translations.lookup_s(c "\x1d" #x, true) +#define STRC_C(x, c) Translations.lookup_c(c "\x1d" #x, true) diff --git a/uilayer.cpp b/uilayer.cpp index 327ff2bd..596d5a0a 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -77,7 +77,7 @@ void ui_panel::register_popup(std::unique_ptr &&popup) void ui_expandable_panel::render_contents() { - ImGui::Checkbox(LOC_STR(ui_expand), &is_expanded); + ImGui::Checkbox(STR_C(ui_expand), &is_expanded); ui_panel::render_contents(); } @@ -269,14 +269,14 @@ void ui_layer::render_quit_widget() return; ImGui::SetNextWindowSize(ImVec2(0, 0)); - ImGui::Begin(LOC_STR(ui_quit), &m_quit_active, ImGuiWindowFlags_NoResize); - ImGui::TextUnformatted(LOC_STR(ui_quit_simulation_q)); - if (ImGui::Button(LOC_STR(ui_yes))) { + ImGui::Begin(STR_C(ui_quit), &m_quit_active, ImGuiWindowFlags_NoResize); + ImGui::TextUnformatted(STR_C(ui_quit_simulation_q)); + if (ImGui::Button(STR_C(ui_yes))) { command_relay relay; relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0); } ImGui::SameLine(); - if (ImGui::Button(LOC_STR(ui_no))) + if (ImGui::Button(STR_C(ui_no))) m_quit_active = false; ImGui::End(); } @@ -334,7 +334,7 @@ void ui_layer::render_progress() ImGui::SetNextWindowPos(ImVec2(50, 50)); ImGui::SetNextWindowSize(ImVec2(0, 0)); - ImGui::Begin(LOC_STR(ui_loading), nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); + ImGui::Begin(STR_C(ui_loading), nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); if (!m_progresstext.empty()) ImGui::ProgressBar(m_progress, ImVec2(300, 0), m_progresstext.c_str()); else @@ -366,29 +366,29 @@ void ui_layer::render_tooltip() void ui_layer::render_menu_contents() { - if (ImGui::BeginMenu(LOC_STR(ui_general))) + if (ImGui::BeginMenu(STR_C(ui_general))) { - ImGui::MenuItem(LOC_STR(ui_debug_mode), nullptr, &DebugModeFlag); - ImGui::MenuItem(LOC_STR(ui_quit), "F10", &m_quit_active); + ImGui::MenuItem(STR_C(ui_debug_mode), nullptr, &DebugModeFlag); + ImGui::MenuItem(STR_C(ui_quit), "F10", &m_quit_active); ImGui::EndMenu(); } - if (ImGui::BeginMenu(LOC_STR(ui_tools))) + if (ImGui::BeginMenu(STR_C(ui_tools))) { static bool log = Global.iWriteLogEnabled & 1; - ImGui::MenuItem(LOC_STR(ui_logging_to_log), nullptr, &log); + ImGui::MenuItem(STR_C(ui_logging_to_log), nullptr, &log); if (log) Global.iWriteLogEnabled |= 1; else Global.iWriteLogEnabled &= ~1; - if (ImGui::MenuItem(LOC_STR(ui_screenshot), "PrtScr")) + if (ImGui::MenuItem(STR_C(ui_screenshot), "PrtScr")) Application.queue_screenshot(); ImGui::EndMenu(); } - if (ImGui::BeginMenu(LOC_STR(ui_windows))) + if (ImGui::BeginMenu(STR_C(ui_windows))) { - ImGui::MenuItem(LOC_STR(ui_log), "F9", &m_logpanel.is_open); + ImGui::MenuItem(STR_C(ui_log), "F9", &m_logpanel.is_open); if (DebugModeFlag) { ImGui::MenuItem("ImGui Demo", nullptr, &m_imgui_demo); ImGui::MenuItem("Headlight config", nullptr, &GfxRenderer.debug_ui_active); diff --git a/widgets/cameraview.cpp b/widgets/cameraview.cpp index 38d20614..54f7b4ca 100644 --- a/widgets/cameraview.cpp +++ b/widgets/cameraview.cpp @@ -4,7 +4,7 @@ #include "Logs.h" ui::cameraview_panel::cameraview_panel() - : ui_panel(LOC_STR(cameraview_window), false) + : ui_panel(STR_C(cameraview_window), false) { size_min = { -2, -2 }; } diff --git a/widgets/map.cpp b/widgets/map.cpp index 00f1fd8c..3ea417af 100644 --- a/widgets/map.cpp +++ b/widgets/map.cpp @@ -8,7 +8,7 @@ #include "Driver.h" #include "AnimModel.h" -ui::map_panel::map_panel() : ui_panel(LOC_STR(ui_map), false) +ui::map_panel::map_panel() : ui_panel(STR_C(ui_map), false) { size_min = {200, 200}; size_max = {fb_size, fb_size}; @@ -445,13 +445,13 @@ void ui::launcher_window::render_content() { ImGui::TextUnformatted(m_switch->name.c_str()); - const std::string &open_label = locale::strings[ + const std::string &open_label = STR( m_switch->type == map::launcher::track_switch - ? locale::string::map_straight : locale::string::map_open]; + ? locale::string::map_straight : locale::string::map_open); - const std::string &close_label = locale::strings[ + const std::string &close_label = STR( m_switch->type == map::launcher::track_switch - ? locale::string::map_divert : locale::string::map_close]; + ? locale::string::map_divert : locale::string::map_close); if (ImGui::Button(open_label.c_str())) { @@ -495,7 +495,7 @@ void ui::obstacle_insert_window::render_content() return; } - ImGui::TextUnformatted(LOC_STR(map_obstacle_insert)); + ImGui::TextUnformatted(STR_C(map_obstacle_insert)); for (auto const &entry : m_obstacles) { if (ImGui::Button(entry.first.c_str())) @@ -526,7 +526,7 @@ ui::obstacle_remove_window::obstacle_remove_window(ui_panel &panel, std::shared_ void ui::obstacle_remove_window::render_content() { - if (ImGui::Button(LOC_STR(map_obstacle_remove))) { + if (ImGui::Button(STR_C(map_obstacle_remove))) { m_relay.post(user_command::deletemodel, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(), &m_obstacle->model_name); auto &entries = map::Objects.entries; diff --git a/widgets/time.cpp b/widgets/time.cpp index 920fc2a3..17557eea 100644 --- a/widgets/time.cpp +++ b/widgets/time.cpp @@ -3,20 +3,20 @@ #include "simulationtime.h" #include "Globals.h" -ui::time_panel::time_panel() : ui_panel(LOC_STR(time_window), false) +ui::time_panel::time_panel() : ui_panel(STR_C(time_window), false) { size.x = 450; } void ui::time_panel::render_contents() { - ImGui::SliderFloat(LOC_STR(time_time), &time, 0.0f, 24.0f, "%.1f"); - ImGui::SliderInt(LOC_STR(time_yearday), &yearday, 1, 365); - ImGui::SliderFloat(LOC_STR(time_visibility), &fog, 50.0f, 3000.0f, "%.0f"); - ImGui::SliderFloat(LOC_STR(time_weather), &overcast, 0.0f, 2.0f, "%.1f"); - ImGui::SliderFloat(LOC_STR(time_temperature), &temperature, -20.0f, 40.0f, "%.0f"); + ImGui::SliderFloat(STR_C(time_time), &time, 0.0f, 24.0f, "%.1f"); + ImGui::SliderInt(STR_C(time_yearday), &yearday, 1, 365); + ImGui::SliderFloat(STR_C(time_visibility), &fog, 50.0f, 3000.0f, "%.0f"); + ImGui::SliderFloat(STR_C(time_weather), &overcast, 0.0f, 2.0f, "%.1f"); + ImGui::SliderFloat(STR_C(time_temperature), &temperature, -20.0f, 40.0f, "%.0f"); - if (ImGui::Button(LOC_STR(time_apply))) + if (ImGui::Button(STR_C(time_apply))) { m_relay.post(user_command::setdatetime, (double)yearday, time, 1, 0); m_relay.post(user_command::setweather, fog, overcast, 1, 0); diff --git a/widgets/vehiclelist.cpp b/widgets/vehiclelist.cpp index 170a92b6..0964ffff 100644 --- a/widgets/vehiclelist.cpp +++ b/widgets/vehiclelist.cpp @@ -5,7 +5,7 @@ #include "widgets/vehicleparams.h" ui::vehiclelist_panel::vehiclelist_panel(ui_layer &parent) - : ui_panel(LOC_STR(vehiclelist_window), false), m_parent(parent) + : ui_panel(STR_C(vehiclelist_window), false), m_parent(parent) { } diff --git a/widgets/vehicleparams.cpp b/widgets/vehicleparams.cpp index 570a73fb..4899683c 100644 --- a/widgets/vehicleparams.cpp +++ b/widgets/vehicleparams.cpp @@ -6,7 +6,7 @@ #include "Train.h" ui::vehicleparams_panel::vehicleparams_panel(const std::string &vehicle) - : ui_panel(std::string(locale::strings[locale::string::vehicleparams_window]) + ": " + vehicle, false), m_vehicle_name(vehicle) + : ui_panel(std::string(STR(vehicleparams_window)) + ": " + vehicle, false), m_vehicle_name(vehicle) { } @@ -53,7 +53,7 @@ void ui::vehicleparams_panel::render_contents() std::snprintf( buffer.data(), buffer.size(), - locale::strings[ locale::string::debug_vehicle_devicespower ].c_str(), + STR_C(debug_vehicle_devicespower), // devices ( mover.Battery ? 'B' : '.' ), ( mover.Mains ? 'M' : '.' ), @@ -70,7 +70,7 @@ void ui::vehicleparams_panel::render_contents() ( mover.CompressorFlag ? 'C' : ( false == mover.CompressorAllowLocal ? '-' : ( ( mover.CompressorAllow || mover.CompressorStart == start_t::automatic ) ? 'c' : '.' ) ) ), ( mover.CompressorGovernorLock ? '!' : '.' ), "", - std::string( isdieselenginepowered ? locale::strings[ locale::string::debug_vehicle_oilpressure ] + to_string( mover.OilPump.pressure, 2 ) : "" ).c_str(), + std::string( isdieselenginepowered ? STR(debug_vehicle_oilpressure) + to_string( mover.OilPump.pressure, 2 ) : "" ).c_str(), // power transfers mover.Couplers[ end::front ].power_high.voltage, mover.Couplers[ end::front ].power_high.current, @@ -84,11 +84,11 @@ void ui::vehicleparams_panel::render_contents() std::snprintf( buffer.data(), buffer.size(), - locale::strings[ locale::string::debug_vehicle_controllersenginerevolutions ].c_str(), + STR_C(debug_vehicle_controllersenginerevolutions), // controllers mover.MainCtrlPos, mover.MainCtrlActualPos, - std::string( isdieselinshuntmode ? to_string( mover.AnPos, 2 ) + locale::strings[ locale::string::debug_vehicle_shuntmode ] : std::to_string( mover.ScndCtrlPos ) + "(" + std::to_string( mover.ScndCtrlActualPos ) + ")" ).c_str(), + std::string( isdieselinshuntmode ? to_string( mover.AnPos, 2 ) + STR(debug_vehicle_shuntmode) : std::to_string( mover.ScndCtrlPos ) + "(" + std::to_string( mover.ScndCtrlActualPos ) + ")" ).c_str(), // engine mover.EnginePower, std::abs( mover.TrainType == dt_EZT ? mover.ShowCurrent( 0 ) : mover.Im ), @@ -106,7 +106,7 @@ void ui::vehicleparams_panel::render_contents() if( isdieselenginepowered ) { std::snprintf( buffer.data(), buffer.size(), - locale::strings[ locale::string::debug_vehicle_temperatures ].c_str(), + STR_C(debug_vehicle_temperatures), mover.dizel_heat.Ts, mover.dizel_heat.To, mover.dizel_heat.temperatura1, @@ -132,7 +132,7 @@ void ui::vehicleparams_panel::render_contents() std::snprintf( buffer.data(), buffer.size(), - locale::strings[ locale::string::debug_vehicle_brakespressures ].c_str(), + STR_C(debug_vehicle_brakespressures), // brakes mover.fBrakeCtrlPos, mover.LocalBrakePosA, @@ -158,7 +158,7 @@ void ui::vehicleparams_panel::render_contents() if( mover.EnginePowerSource.SourceType == TPowerSource::CurrentCollector ) { std::snprintf( buffer.data(), buffer.size(), - locale::strings[ locale::string::debug_vehicle_pantograph ].c_str(), + STR_C(debug_vehicle_pantograph), mover.PantPress, ( mover.bPantKurek3 ? '-' : '|' ) ); ImGui::TextUnformatted(buffer.data()); @@ -166,7 +166,7 @@ void ui::vehicleparams_panel::render_contents() std::snprintf( buffer.data(), buffer.size(), - locale::strings[ locale::string::debug_vehicle_forcesaccelerationvelocityposition ].c_str(), + STR_C(debug_vehicle_forcesaccelerationvelocityposition), // forces mover.Ft * 0.001f * ( mover.ActiveCab ? mover.ActiveCab : vehicle.ctOwner ? vehicle.ctOwner->Controlling()->ActiveCab : 1 ) + 0.001f, mover.Fb * 0.001f, @@ -186,40 +186,40 @@ void ui::vehicleparams_panel::render_contents() ImGui::TextUnformatted(buffer.data()); - if (ImGui::Button(LOC_STR(vehicleparams_radiostop))) + if (ImGui::Button(STR_C(vehicleparams_radiostop))) m_relay.post(user_command::radiostop, 0.0, 0.0, GLFW_PRESS, 0, vehicle_ptr->GetPosition()); ImGui::SameLine(); - if (ImGui::Button(LOC_STR(vehicleparams_reset))) + if (ImGui::Button(STR_C(vehicleparams_reset))) m_relay.post(user_command::resetconsist, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); ImGui::SameLine(); - if (ImGui::Button(LOC_STR(vehicleparams_resetposition))) { + if (ImGui::Button(STR_C(vehicleparams_resetposition))) { std::string payload = vehicle_ptr->name() + '%' + vehicle_ptr->initial_track->name(); m_relay.post(user_command::consistteleport, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &payload); m_relay.post(user_command::resetconsist, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); } - if (ImGui::Button(LOC_STR(vehicleparams_resetpipe))) + if (ImGui::Button(STR_C(vehicleparams_resetpipe))) m_relay.post(user_command::fillcompressor, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); ImGui::SameLine(); - if (ImGui::Button(LOC_STR(vehicleparams_rupturepipe))) + if (ImGui::Button(STR_C(vehicleparams_rupturepipe))) m_relay.post(user_command::pullalarmchain, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); ImGui::SameLine(); - ImGui::Button(LOC_STR(cab_releaser_bt)); + ImGui::Button(STR_C(cab_releaser_bt)); if (ImGui::IsItemClicked()) m_relay.post(user_command::consistreleaser, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); if (ImGui::IsItemDeactivated()) m_relay.post(user_command::consistreleaser, 0.0, 0.0, GLFW_RELEASE, 0, glm::vec3(0.0f), &vehicle_ptr->name()); if (vehicle_ptr->MoverParameters->V < 0.01) { - if (ImGui::Button(LOC_STR(vehicleparams_move500f))) + if (ImGui::Button(STR_C(vehicleparams_move500f))) m_relay.post(user_command::dynamicmove, 500.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); ImGui::SameLine(); - if (ImGui::Button(LOC_STR(vehicleparams_move500b))) + if (ImGui::Button(STR_C(vehicleparams_move500b))) m_relay.post(user_command::dynamicmove, -500.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); } }