void SystemInfoView::OnBodyViewed(SystemBody *b) { std::string desc, data; m_infoBox->DeleteAllChildren(); Gui::Fixed *outer = new Gui::Fixed(600, 200); m_infoBox->PackStart(outer); Gui::VBox *col1 = new Gui::VBox(); Gui::VBox *col2 = new Gui::VBox(); outer->Add(col1, 0, 0); outer->Add(col2, 300, 0); #define _add_label_and_value(label, value) { \ Gui::Label *l = (new Gui::Label(label))->Color(255,255,0); \ col1->PackEnd(l); \ l = (new Gui::Label(value))->Color(255,255,0); \ col2->PackEnd(l); \ } bool multiple = (b->GetSuperType() == SystemBody::SUPERTYPE_STAR && b->GetParent() && b->GetParent()->GetType() == SystemBody::TYPE_GRAVPOINT && b->GetParent()->GetParent()); { Gui::Label *l = new Gui::Label(b->GetName() + ": " + b->GetAstroDescription() + (multiple ? (std::string(" (")+b->GetParent()->GetName() + ")") : "")); l->Color(255,255,0); m_infoBox->PackStart(l); } _add_label_and_value(Lang::MASS, stringf(Lang::N_WHATEVER_MASSES, formatarg("mass", b->GetMassAsFixed().ToDouble()), formatarg("units", std::string(b->GetSuperType() == SystemBody::SUPERTYPE_STAR ? Lang::SOLAR : Lang::EARTH)))); _add_label_and_value(Lang::RADIUS, stringf(Lang::N_WHATEVER_RADII, formatarg("radius", b->GetRadiusAsFixed().ToDouble()), formatarg("units", std::string(b->GetSuperType() == SystemBody::SUPERTYPE_STAR ? Lang::SOLAR : Lang::EARTH)), formatarg("radkm", b->GetRadius() / 1000.0))); if (b->GetSuperType() == SystemBody::SUPERTYPE_STAR) { _add_label_and_value(Lang::EQUATORIAL_RADIUS_TO_POLAR_RADIUS_RATIO, stringf("%0{f.3}", b->GetAspectRatio())); } if (b->GetType() != SystemBody::TYPE_STARPORT_ORBITAL) { _add_label_and_value(Lang::SURFACE_TEMPERATURE, stringf(Lang::N_CELSIUS, formatarg("temperature", b->GetAverageTemp()-273))); _add_label_and_value(Lang::SURFACE_GRAVITY, stringf("%0{f.3} m/s^2", b->CalcSurfaceGravity())); } if (b->GetParent()) { float days = float(b->GetOrbit().Period()) / float(60*60*24); if (days > 1000) { data = stringf(Lang::N_YEARS, formatarg("years", days/365)); } else { data = stringf(Lang::N_DAYS, formatarg("days", b->GetOrbit().Period() / (60*60*24))); } if (multiple) { float pdays = float(b->GetParent()->GetOrbit().Period()) /float(60*60*24); data += " (" + (pdays > 1000 ? stringf(Lang::N_YEARS, formatarg("years", pdays/365)) : stringf(Lang::N_DAYS, formatarg("days", b->GetParent()->GetOrbit().Period() / (60*60*24)))) + ")"; } _add_label_and_value(Lang::ORBITAL_PERIOD, data); _add_label_and_value(Lang::PERIAPSIS_DISTANCE, format_distance(b->GetOrbMin()*AU, 3) + (multiple ? (std::string(" (") + format_distance(b->GetParent()->GetOrbMin()*AU, 3)+ ")") : "")); _add_label_and_value(Lang::APOAPSIS_DISTANCE, format_distance(b->GetOrbMax()*AU, 3) + (multiple ? (std::string(" (") + format_distance(b->GetParent()->GetOrbMax()*AU, 3)+ ")") : "")); _add_label_and_value(Lang::ECCENTRICITY, stringf("%0{f.2}", b->GetOrbit().GetEccentricity()) + (multiple ? (std::string(" (") + stringf("%0{f.2}", b->GetParent()->GetOrbit().GetEccentricity()) + ")") : "")); if (b->GetType() != SystemBody::TYPE_STARPORT_ORBITAL) { _add_label_and_value(Lang::AXIAL_TILT, stringf(Lang::N_DEGREES, formatarg("angle", b->GetAxialTilt() * (180.0/M_PI)))); if (b->IsRotating()) { _add_label_and_value( std::string(Lang::DAY_LENGTH)+std::string(Lang::ROTATIONAL_PERIOD), stringf(Lang::N_EARTH_DAYS, formatarg("days", b->GetRotationPeriodInDays()))); } } int numSurfaceStarports = 0; std::string nameList; for (const SystemBody* kid : b->GetChildren()) { if (kid->GetType() == SystemBody::TYPE_STARPORT_SURFACE) { nameList += (numSurfaceStarports ? ", " : "") + kid->GetName(); numSurfaceStarports++; } } if (numSurfaceStarports) { _add_label_and_value(Lang::STARPORTS, nameList); } } m_infoBox->ShowAll(); m_infoBox->ResizeRequest(); }
void SystemInfoView::OnBodyViewed(SBody *b) { std::string desc, data; m_infoBox->DeleteAllChildren(); Gui::Fixed *outer = new Gui::Fixed(600, 200); m_infoBox->PackStart(outer); Gui::VBox *col1 = new Gui::VBox(); Gui::VBox *col2 = new Gui::VBox(); outer->Add(col1, 0, 0); outer->Add(col2, 300, 0); #define _add_label_and_value(label, value) { \ Gui::Label *l = (new Gui::Label(label))->Color(1.0f,1.0f,0.0f); \ col1->PackEnd(l); \ l = (new Gui::Label(value))->Color(1.0f,1.0f,0.0f); \ col2->PackEnd(l); \ } { Gui::Label *l = new Gui::Label(b->name + ": " + b->GetAstroDescription()); l->Color(1,1,0); m_infoBox->PackStart(l); } _add_label_and_value(Lang::MASS, stringf(Lang::N_WHATEVER_MASSES, formatarg("mass", b->mass.ToDouble()), formatarg("units", std::string(b->GetSuperType() == SBody::SUPERTYPE_STAR ? Lang::SOLAR : Lang::EARTH)))); if (b->type != SBody::TYPE_STARPORT_ORBITAL) { _add_label_and_value(Lang::SURFACE_TEMPERATURE, stringf(Lang::N_CELSIUS, formatarg("temperature", b->averageTemp-273))); _add_label_and_value(Lang::SURFACE_GRAVITY, stringf("%0{f.3} m/s^2", b->CalcSurfaceGravity())); } if (b->parent) { float days = float(b->orbit.period) / float(60*60*24); if (days > 1000) { data = stringf(Lang::N_YEARS, formatarg("years", days/365)); } else { data = stringf(Lang::N_DAYS, formatarg("days", b->orbit.period / (60*60*24))); } _add_label_and_value(Lang::ORBITAL_PERIOD, data); _add_label_and_value(Lang::PERIAPSIS_DISTANCE, stringf("%0{f.3} AU", b->orbMin.ToDouble())); _add_label_and_value(Lang::APOAPSIS_DISTANCE, stringf("%0{f.3} AU", b->orbMax.ToDouble())); _add_label_and_value(Lang::ECCENTRICITY, stringf("%0{f.2}", b->orbit.eccentricity)); if (b->type != SBody::TYPE_STARPORT_ORBITAL) { _add_label_and_value(Lang::AXIAL_TILT, stringf(Lang::N_DEGREES, formatarg("angle", b->axialTilt.ToDouble() * (180.0/M_PI)))); if (b->rotationPeriod != 0) { _add_label_and_value( std::string(Lang::DAY_LENGTH)+std::string(Lang::ROTATIONAL_PERIOD), stringf(Lang::N_EARTH_DAYS, formatarg("days", b->rotationPeriod.ToDouble()))); } } int numSurfaceStarports = 0; std::string nameList; for (std::vector<SBody*>::iterator i = b->children.begin(); i != b->children.end(); ++i) { if ((*i)->type == SBody::TYPE_STARPORT_SURFACE) { nameList += (numSurfaceStarports ? ", " : "") + (*i)->name; numSurfaceStarports++; } } if (numSurfaceStarports) { _add_label_and_value(Lang::STARPORTS, nameList); } } m_infoBox->ShowAll(); m_infoBox->ResizeRequest(); }