@@ -325,61 +325,74 @@ void VehicleInfoTPanel::DrawVehicleCommandsUI(RoR::GfxActor* actorx)
325
325
}
326
326
}
327
327
328
+ void DrawStatsLineColored (const char * name, const std::string& value, ImVec4 value_color)
329
+ {
330
+ GUIManager::GuiTheme& theme = App::GetGuiManager ()->GetTheme ();
331
+ ImGui::TextColored (theme.value_blue_text_color , " %s" , name);
332
+ // If the value is too long, move it to next line
333
+ ImVec2 label_size = ImGui::CalcTextSize (name);
334
+ ImVec2 value_size = ImGui::CalcTextSize (value.c_str ());
335
+ float cursor_x_desired = - ImGui::CalcTextSize (value.c_str ()).x ;
336
+ if (label_size.x + value_size.x + ImGui::GetStyle ().ItemSpacing .x < ImGui::GetWindowContentRegionWidth ())
337
+ {
338
+ ImGui::SameLine ();
339
+ }
340
+ ImGui::SetCursorPosX (ImGui::GetWindowContentRegionWidth () - value_size.x );
341
+ ImGui::TextColored (value_color, " %s" , value.c_str ());
342
+ }
343
+
344
+ void DrawStatsLine (const char * name, const std::string& value)
345
+ {
346
+ DrawStatsLineColored (name, value, ImGui::GetStyle ().Colors [ImGuiCol_Text]);
347
+ }
348
+
349
+ void DrawStatsBullet (const char * name, const std::string& value)
350
+ {
351
+ GUIManager::GuiTheme& theme = App::GetGuiManager ()->GetTheme ();
352
+ ImGui::PushStyleColor (ImGuiCol_Text, theme.value_blue_text_color );
353
+ ImGui::Bullet ();
354
+ ImGui::PopStyleColor (); // Text
355
+ ImGui::SameLine ();
356
+ DrawStatsLineColored (name, value, ImGui::GetStyle ().Colors [ImGuiCol_Text]);
357
+ }
358
+
328
359
void VehicleInfoTPanel::DrawVehicleStatsUI (RoR::GfxActor* actorx)
329
360
{
330
361
GUIManager::GuiTheme& theme = App::GetGuiManager ()->GetTheme ();
362
+ ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2 (ImGui::GetStyle ().ItemSpacing .x , 0 ));
331
363
332
364
if (m_stat_health < 1 .0f )
333
365
{
334
366
const float value = static_cast <float >( Round ((1 .0f - m_stat_health) * 100 .0f , 2 ) );
335
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Vehicle health: " ));
336
- ImGui::SameLine ();
337
- ImGui::Text (" %.2f%%" , value);
367
+ DrawStatsLine (_LC (" SimActorStats" , " Vehicle health: " ), fmt::format (" {:.2f}%" , value));
338
368
}
339
369
else if (m_stat_health >= 1 .0f ) // When this condition is true, it means that health is at 0% which means 100% of destruction.
340
370
{
341
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Vehicle destruction: " ));
342
- ImGui::SameLine ();
343
- ImGui::Text (" 100%%" );
371
+ DrawStatsLine (_LC (" SimActorStats" , " Vehicle destruction: " ), " 100%" );
344
372
}
345
373
346
- const int num_beams_i = actorx->FetchNumBeams ();
347
- const float num_beams_f = static_cast <float >(num_beams_i);
348
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Beam count: " ));
349
- ImGui::SameLine ();
350
- ImGui::Text (" %d" , num_beams_i);
374
+ const int num_beams = actorx->GetActor ()->ar_num_beams ;
375
+ DrawStatsLine (_LC (" SimActorStats" , " Beam count: " ), fmt::format (" {}" , num_beams));
351
376
352
- const float broken_pct = static_cast <float >( Round ((float )m_stat_broken_beams / num_beams_f, 2 ) * 100 .0f );
353
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Broken beams count: " ));
354
- ImGui::SameLine ();
355
- ImGui::Text (" %d (%.0f%%)" , m_stat_broken_beams, broken_pct);
377
+ const float broken_pct = static_cast <float >( Round ((float )m_stat_broken_beams / (float )num_beams, 2 ) * 100 .0f );
378
+ DrawStatsLine (_LC (" SimActorStats" , " Broken beams count: " ), fmt::format (" {} ({:.0f}%)" , m_stat_broken_beams, broken_pct));
356
379
357
- const float deform_pct = static_cast <float >( Round ((float )m_stat_deformed_beams / num_beams_f * 100 .0f ) );
358
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Deformed beams count: " ));
359
- ImGui::SameLine ();
360
- ImGui::Text (" %d (%.0f%%)" , m_stat_deformed_beams, deform_pct);
380
+ const float deform_pct = static_cast <float >( Round ((float )m_stat_deformed_beams / (float )num_beams * 100 .0f ) );
381
+ DrawStatsLine (_LC (" SimActorStats" , " Deformed beams count: " ), fmt::format (" {} ({:.0f}%)" , m_stat_deformed_beams, deform_pct));
361
382
362
- const float avg_deform = static_cast <float >( Round ((float )m_stat_avg_deform / num_beams_f, 4 ) * 100 .0f );
363
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Average deformation: " ));
364
- ImGui::SameLine ();
365
- ImGui::Text (" %.2f" , avg_deform);
383
+ const float avg_deform = static_cast <float >( Round ((float )m_stat_avg_deform / (float )num_beams, 4 ) * 100 .0f );
384
+ DrawStatsLine (_LC (" SimActorStats" , " Average deformation: " ), fmt::format (" {:.2f}" , avg_deform));
366
385
367
- const float avg_stress = 1 .f - (float )m_stat_beam_stress / num_beams_f;
368
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Average stress: " ));
369
- ImGui::SameLine ();
370
- ImGui::Text (" %+08.0f" , avg_stress);
386
+ const float avg_stress = 1 .f - (float )m_stat_beam_stress / (float )num_beams;
387
+ DrawStatsLine (_LC (" SimActorStats" , " Average stress: " ), fmt::format (" {:+08.0f}" , avg_stress));
371
388
372
389
ImGui::NewLine ();
373
390
374
- const int num_nodes = actorx->FetchNumNodes ();
375
- const int num_wheelnodes = actorx->FetchNumWheelNodes ();
376
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Node count: " ));
377
- ImGui::SameLine ();
378
- ImGui::Text (" %d (%s%d)" , num_nodes, " wheels: " , num_wheelnodes);
391
+ const int num_nodes = actorx->GetActor ()->ar_num_nodes ;
392
+ const int num_wheelnodes = actorx->GetActor ()->getWheelNodeCount ();
393
+ DrawStatsLine (_LC (" SimActorStats" , " Node count: " ), fmt::format (" {} (wheels: {})" , num_nodes, num_wheelnodes));
379
394
380
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Total mass: " ));
381
- ImGui::SameLine ();
382
- ImGui::Text (" %8.2f Kg (%.2f tons)" , m_stat_mass_Kg, m_stat_mass_Kg / 1000 .0f );
395
+ DrawStatsLine (_LC (" SimActorStats" , " Total mass: " ), fmt::format (" {:8.2f} Kg {:.2f} tons)" , m_stat_mass_Kg, m_stat_mass_Kg / 1000 .0f ));
383
396
384
397
ImGui::NewLine ();
385
398
@@ -394,32 +407,20 @@ void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
394
407
const float cur_rpm = actorx->GetSimDataBuffer ().simbuf_engine_rpm ;
395
408
const float wheel_speed = actorx->GetSimDataBuffer ().simbuf_wheel_speed ;
396
409
397
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Engine RPM: " ));
398
- ImGui::SameLine ();
399
- ImVec4 rpm_color = (cur_rpm > max_rpm) ? theme.value_red_text_color : ImGui::GetStyle ().Colors [ImGuiCol_Text];
400
- ImGui::TextColored (rpm_color, " %.2f / %.2f" , cur_rpm, max_rpm);
410
+ const ImVec4 rpm_color = (cur_rpm > max_rpm) ? theme.value_red_text_color : ImGui::GetStyle ().Colors [ImGuiCol_Text];
411
+ DrawStatsLineColored (_LC (" SimActorStats" , " Engine RPM: " ), fmt::format (" {:.2f} / {:.2f}" , cur_rpm, max_rpm), rpm_color);
401
412
402
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Input shaft RPM: " ));
403
- ImGui::SameLine ();
404
413
const float inputshaft_rpm = Round (std::max (0 .0f , actorx->GetSimDataBuffer ().simbuf_inputshaft_rpm ));
405
- ImGui::TextColored (rpm_color , " % .0f" , inputshaft_rpm);
414
+ DrawStatsLineColored ( _LC ( " SimActorStats " , " Input shaft RPM: " ), fmt::format ( " {: .0f} " , inputshaft_rpm), rpm_color );
406
415
407
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Current torque: " ));
408
- ImGui::SameLine ();
409
- ImGui::Text (" %.0f Nm" , Round (torque));
416
+ DrawStatsLine (_LC (" SimActorStats" , " Current torque: " ), fmt::format (" {:.0f} Nm" , Round (torque)));
410
417
411
418
const float currentKw = (((cur_rpm * (torque + ((turbo_psi * 6.8 ) * torque) / 100 ) * ( PI / 30 )) / 1000 ));
412
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Current power: " ));
413
- ImGui::SameLine ();
414
- ImGui::Text (" %.0fhp (%.0fKw)" , static_cast <float >(Round (currentKw *1.34102209 )), static_cast <float >(Round (currentKw)));
419
+ DrawStatsLine (_LC (" SimActorStats" , " Current power: " ), fmt::format (" {:.0f}hp ({:.0f}Kw)" , Round (currentKw *1.34102209 ), Round (currentKw)));
415
420
416
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Current gear: " ));
417
- ImGui::SameLine ();
418
- ImGui::Text (" %d" , actorx->GetSimDataBuffer ().simbuf_gear );
421
+ DrawStatsLine (_LC (" SimActorStats" , " Current gear: " ), fmt::format (" {}" , actorx->GetSimDataBuffer ().simbuf_gear ));
419
422
420
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Drive ratio: " ));
421
- ImGui::SameLine ();
422
- ImGui::Text (" %.2f:1" , actorx->GetSimDataBuffer ().simbuf_drive_ratio );
423
+ DrawStatsLine (_LC (" SimActorStats" , " Drive ratio: " ), fmt::format (" {:.2f}:1" , actorx->GetSimDataBuffer ().simbuf_drive_ratio ));
423
424
424
425
float velocityKPH = wheel_speed * 3 .6f ;
425
426
float velocityMPH = wheel_speed * 2 .23693629f ;
@@ -436,40 +437,31 @@ void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
436
437
carSpeedKPH = carSpeedMPH = 0 .0f ;
437
438
}
438
439
439
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Wheel speed: " ));
440
- ImGui::SameLine ();
441
- ImGui::Text (" %.0fKm/h (%.0f mph)" , Round (velocityKPH), Round (velocityMPH));
440
+ DrawStatsLine (_LC (" SimActorStats" , " Wheel speed: " ), fmt::format (" {:.0f}Km/h ({:.0f} mph)" , Round (velocityKPH), Round (velocityMPH)));
442
441
443
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Vehicle speed: " ));
444
- ImGui::SameLine ();
445
- ImGui::Text (" %.0fKm/h (%.0f mph)" , Round (carSpeedKPH), Round (carSpeedMPH));
442
+ DrawStatsLine (_LC (" SimActorStats" , " Vehicle speed: " ), fmt::format (" {:.0f}Km/h ({:.0f} mph)" , Round (carSpeedKPH), Round (carSpeedMPH)));
446
443
}
447
444
else // Aircraft or boat
448
445
{
449
446
float speedKN = n0_velo_len * 1 .94384449f ;
450
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Current speed: " ));
451
- ImGui::SameLine ();
452
- ImGui::Text (" %.0f kn (%.0f Km/h; %.0f mph)" , Round (speedKN), Round (speedKN * 1.852 ), Round (speedKN * 1.151 ));
447
+ DrawStatsLine (_LC (" SimActorStats" , " Current speed: " ), fmt::format (" {:.0f} kn ({:.0f} Km/h; {:.0f} mph)" , Round (speedKN), Round (speedKN * 1.852 ), Round (speedKN * 1.151 )));
453
448
454
449
if (actorx->GetSimDataBuffer ().simbuf_driveable == AIRPLANE)
455
450
{
456
451
const float altitude = actorx->GetSimNodeBuffer ()[0 ].AbsPosition .y / 30.48 * 100 ;
457
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Altitude: " ));
458
- ImGui::SameLine ();
459
- ImGui::Text (" %.0f feet (%.0f meters)" , Round (altitude), Round (altitude * 0.30480 ));
452
+ DrawStatsLine (_LC (" SimActorStats" , " Altitude: " ), fmt::format (" {:.0f} feet ({:.0f} meters)" , Round (altitude), Round (altitude * 0.30480 )));
460
453
461
454
int engine_num = 1 ; // UI; count from 1
462
455
for (AeroEngineSB& ae: actorx->GetSimDataBuffer ().simbuf_aeroengines )
463
456
{
464
- ImGui::TextColored (theme.value_blue_text_color , " %s #%d:" , _LC (" SimActorStats" , " Engine " ), engine_num);
465
- ImGui::SameLine ();
466
- if (ae.simbuf_ae_type == AeroEngineType::AE_XPROP)
457
+ std::string label = fmt::format (" {} #{}:" , _LC (" SimActorStats" , " Engine " ), engine_num);
458
+ if (ae.simbuf_ae_type == AeroEngineType::AE_XPROP) // Turboprop/pistonprop
467
459
{
468
- ImGui::Text ( " % .2f RPM" , ae.simbuf_ae_rpm );
460
+ DrawStatsLine (label. c_str (), fmt::format ( " {: .2f} RPM" , ae.simbuf_ae_rpm ) );
469
461
}
470
462
else // Turbojet
471
463
{
472
- ImGui::Text ( " % .2f" , ae.simbuf_ae_rpm );
464
+ DrawStatsLine (label. c_str (), fmt::format ( " {: .2f} " , ae.simbuf_ae_rpm ) );
473
465
}
474
466
++engine_num;
475
467
}
@@ -479,9 +471,8 @@ void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
479
471
int engine_num = 1 ; // UI; count from 1
480
472
for (ScrewpropSB& screw: actorx->GetSimDataBuffer ().simbuf_screwprops )
481
473
{
482
- ImGui::TextColored (theme.value_blue_text_color , " %s #%d:" , _LC (" SimActorStats" , " Engine " ), engine_num);
483
- ImGui::SameLine ();
484
- ImGui::Text (" %f%" , screw.simbuf_sp_throttle );
474
+ std::string label = fmt::format (" {} #{}:" , _LC (" SimActorStats" , " Engine " ), engine_num);
475
+ DrawStatsLine (label.c_str (), fmt::format (" {:.2f}" , screw.simbuf_sp_throttle ));
485
476
++engine_num;
486
477
}
487
478
}
@@ -491,17 +482,16 @@ void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
491
482
492
483
const float speedKPH = actorx->GetSimDataBuffer ().simbuf_top_speed * 3 .6f ;
493
484
const float speedMPH = actorx->GetSimDataBuffer ().simbuf_top_speed * 2 .23693629f ;
494
- ImGui::TextColored (theme.value_blue_text_color ," %s" , _LC (" SimActorStats" , " Top speed: " ));
495
- ImGui::SameLine ();
496
- ImGui::Text (" %.0f km/h (%.0f mph)" , Round (speedKPH), Round (speedMPH));
485
+ DrawStatsLine (_LC (" SimActorStats" , " Top speed: " ), fmt::format (" {:.0f} km/h ({:.0f} mph)" , Round (speedKPH), Round (speedMPH)));
497
486
498
487
ImGui::NewLine ();
499
488
500
- ImGui::TextColored (theme. value_blue_text_color , " %s " , _LC (" SimActorStats" , " G-Forces:" ));
501
- ImGui::Text ( " Vertical: % 6.2fg (%1.2fg )" , m_stat_gcur_x, m_stat_gmax_x);
502
- ImGui::Text ( " Sagittal: % 6.2fg (%1.2fg )" , m_stat_gcur_y, m_stat_gmax_y);
503
- ImGui::Text ( " Lateral: % 6.2fg (%1.2fg )" , m_stat_gcur_z, m_stat_gmax_z);
489
+ DrawStatsLine ( _LC (" SimActorStats" , " G-Forces:" ), " " );
490
+ DrawStatsBullet ( " Vertical: " , fmt::format ( " {: 6.2f}g ({:1.2f}g )" , m_stat_gcur_x, m_stat_gmax_x) );
491
+ DrawStatsBullet ( " Sagittal: " , fmt::format ( " {: 6.2f}g ({:1.2f}g )" , m_stat_gcur_y, m_stat_gmax_y) );
492
+ DrawStatsBullet ( " Lateral: " , fmt::format ( " {: 6.2f}g ({:1.2f}g )" , m_stat_gcur_z, m_stat_gmax_z) );
504
493
494
+ ImGui::PopStyleVar (); // ItemSpacing
505
495
}
506
496
507
497
void VehicleInfoTPanel::DrawVehicleDiagUI (RoR::GfxActor* actorx)
0 commit comments