Skip to content

Commit 1bdb2e8

Browse files
committed
T-Panel/Stats: fixed values being cut off.
1 parent 5d78bc0 commit 1bdb2e8

File tree

3 files changed

+71
-88
lines changed

3 files changed

+71
-88
lines changed

source/main/gfx/GfxActor.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -3334,10 +3334,6 @@ void RoR::GfxActor::UpdateWingMeshes()
33343334
}
33353335
}
33363336

3337-
int RoR::GfxActor::FetchNumBeams () const { return m_actor->ar_num_beams; }
3338-
int RoR::GfxActor::FetchNumNodes () const { return m_actor->ar_num_nodes; }
3339-
int RoR::GfxActor::FetchNumWheelNodes () const { return m_actor->getWheelNodeCount(); }
3340-
33413337
int RoR::GfxActor::countBeaconProps() const
33423338
{
33433339
int count = 0;

source/main/gfx/GfxActor.h

-3
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ class GfxActor
140140
ActorPtr GetActor(); // Watch out for multithreading with this!
141141
Ogre::TexturePtr GetHelpTex() { return m_help_tex; }
142142
Ogre::MaterialPtr GetHelpMat() { return m_help_mat; }
143-
int FetchNumBeams() const ;
144-
int FetchNumNodes() const ;
145-
int FetchNumWheelNodes() const ;
146143
bool HasDriverSeatProp() const { return m_driverseat_prop_index != -1; }
147144
void CalcPropAnimation(PropAnim& anim, float& cstate, int& div, float dt);
148145
std::vector<Prop>& getProps() { return m_props; }

source/main/gui/panels/GUI_VehicleInfoTPanel.cpp

+71-81
Original file line numberDiff line numberDiff line change
@@ -325,61 +325,74 @@ void VehicleInfoTPanel::DrawVehicleCommandsUI(RoR::GfxActor* actorx)
325325
}
326326
}
327327

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+
328359
void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
329360
{
330361
GUIManager::GuiTheme& theme = App::GetGuiManager()->GetTheme();
362+
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 0));
331363

332364
if (m_stat_health < 1.0f)
333365
{
334366
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));
338368
}
339369
else if (m_stat_health >= 1.0f) //When this condition is true, it means that health is at 0% which means 100% of destruction.
340370
{
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%");
344372
}
345373

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));
351376

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));
356379

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));
361382

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));
366385

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));
371388

372389
ImGui::NewLine();
373390

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));
379394

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));
383396

384397
ImGui::NewLine();
385398

@@ -394,32 +407,20 @@ void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
394407
const float cur_rpm = actorx->GetSimDataBuffer().simbuf_engine_rpm;
395408
const float wheel_speed = actorx->GetSimDataBuffer().simbuf_wheel_speed;
396409

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);
401412

402-
ImGui::TextColored(theme.value_blue_text_color,"%s", _LC("SimActorStats", "Input shaft RPM: "));
403-
ImGui::SameLine();
404413
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);
406415

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)));
410417

411418
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)));
415420

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));
419422

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));
423424

424425
float velocityKPH = wheel_speed * 3.6f;
425426
float velocityMPH = wheel_speed * 2.23693629f;
@@ -436,40 +437,31 @@ void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
436437
carSpeedKPH = carSpeedMPH = 0.0f;
437438
}
438439

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)));
442441

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)));
446443
}
447444
else // Aircraft or boat
448445
{
449446
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)));
453448

454449
if (actorx->GetSimDataBuffer().simbuf_driveable == AIRPLANE)
455450
{
456451
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)));
460453

461454
int engine_num = 1; // UI; count from 1
462455
for (AeroEngineSB& ae: actorx->GetSimDataBuffer().simbuf_aeroengines)
463456
{
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
467459
{
468-
ImGui::Text("%.2f RPM", ae.simbuf_ae_rpm);
460+
DrawStatsLine(label.c_str(), fmt::format("{:.2f} RPM", ae.simbuf_ae_rpm));
469461
}
470462
else // Turbojet
471463
{
472-
ImGui::Text("%.2f", ae.simbuf_ae_rpm);
464+
DrawStatsLine(label.c_str(), fmt::format("{:.2f}", ae.simbuf_ae_rpm));
473465
}
474466
++engine_num;
475467
}
@@ -479,9 +471,8 @@ void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
479471
int engine_num = 1; // UI; count from 1
480472
for (ScrewpropSB& screw: actorx->GetSimDataBuffer().simbuf_screwprops)
481473
{
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));
485476
++engine_num;
486477
}
487478
}
@@ -491,17 +482,16 @@ void VehicleInfoTPanel::DrawVehicleStatsUI(RoR::GfxActor* actorx)
491482

492483
const float speedKPH = actorx->GetSimDataBuffer().simbuf_top_speed * 3.6f;
493484
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)));
497486

498487
ImGui::NewLine();
499488

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));
504493

494+
ImGui::PopStyleVar(); // ItemSpacing
505495
}
506496

507497
void VehicleInfoTPanel::DrawVehicleDiagUI(RoR::GfxActor* actorx)

0 commit comments

Comments
 (0)