void ObjectViewerView::Update() { if (Pi::KeyState(SDLK_EQUALS)) viewingDist *= 0.99f; if (Pi::KeyState(SDLK_MINUS)) viewingDist *= 1.01f; viewingDist = Clamp(viewingDist, 10.0f, 1e12f); char buf[128]; Body *body = Pi::player->GetNavTarget(); if(body && (body != lastTarget)) { // Reset view distance for new target. viewingDist = body->GetBoundingRadius() * 2.0f; lastTarget = body; if (body->IsType(Object::TERRAINBODY)) { TerrainBody *tbody = static_cast<TerrainBody*>(body); const SystemBody *sbody = tbody->GetSystemBody(); m_sbodyVolatileGas->SetText(stringf("%0{f.3}", sbody->m_volatileGas.ToFloat())); m_sbodyVolatileLiquid->SetText(stringf("%0{f.3}", sbody->m_volatileLiquid.ToFloat())); m_sbodyVolatileIces->SetText(stringf("%0{f.3}", sbody->m_volatileIces.ToFloat())); m_sbodyLife->SetText(stringf("%0{f.3}", sbody->m_life.ToFloat())); m_sbodyVolcanicity->SetText(stringf("%0{f.3}", sbody->m_volcanicity.ToFloat())); m_sbodyMetallicity->SetText(stringf("%0{f.3}", sbody->m_metallicity.ToFloat())); m_sbodySeed->SetText(stringf("%0{i}", int(sbody->seed))); m_sbodyMass->SetText(stringf("%0{f}", sbody->mass.ToFloat())); m_sbodyRadius->SetText(stringf("%0{f}", sbody->radius.ToFloat())); } } snprintf(buf, sizeof(buf), "View dist: %s Object: %s", format_distance(viewingDist).c_str(), (body ? body->GetLabel().c_str() : "<none>")); m_infoLabel->SetText(buf); if (body && body->IsType(Object::TERRAINBODY)) m_vbox->ShowAll(); else m_vbox->HideAll(); }
void SystemView::OnClickObject(SBody *b) { m_selectedObject = b; std::string desc; std::string data; desc += std::string(Lang::NAME); desc += ":\n"; data += b->name+"\n"; desc += std::string(Lang::DAY_LENGTH); desc += std::string(Lang::ROTATIONAL_PERIOD); desc += ":\n"; data += stringf(Lang::N_DAYS, formatarg("days", b->rotationPeriod.ToFloat())) + "\n"; desc += std::string(Lang::RADIUS); desc += ":\n"; data += format_distance(b->GetRadius())+"\n"; if (b->parent) { desc += std::string(Lang::SEMI_MAJOR_AXIS); desc += ":\n"; data += format_distance(b->orbit.semiMajorAxis)+"\n"; desc += std::string(Lang::ORBITAL_PERIOD); desc += ":\n"; data += stringf(Lang::N_DAYS, formatarg("days", b->orbit.period / (24*60*60))) + "\n"; } m_infoLabel->SetText(desc); m_infoText->SetText(data); if (Pi::KeyState(SDLK_LSHIFT) || Pi::KeyState(SDLK_RSHIFT)) { SystemPath path = m_system->GetPathOf(b); if (Pi::game->GetSpace()->GetStarSystem()->GetPath() == m_system->GetPath()) { Body* body = Pi::game->GetSpace()->FindBodyForPath(&path); if (body != 0) Pi::player->SetNavTarget(body); } } }
NumberLabel *NumberLabel::SetValue(double v) { m_value = v; switch (m_format) { case FORMAT_NUMBER_2DP: SetText(to_string(v, "f.2")); break; case FORMAT_INTEGER: SetText(to_string(Uint32(v+0.5), "u")); break; case FORMAT_PERCENT: SetText(stringf("%0{f.2}%%", v*100.0)); break; case FORMAT_PERCENT_INTEGER: SetText(stringf("%0{u}%%", Uint32(v*100.0+0.5))); break; case FORMAT_MASS_TONNES: SetText(stringf(Lang::NUMBER_TONNES, formatarg("mass", v))); break; case FORMAT_MONEY: SetText(format_money(Sint64(v*100))); break; case FORMAT_DISTANCE_M: SetText(format_distance(v, 3)); break; case FORMAT_DISTANCE_LY: SetText(stringf(Lang::NUMBER_LY, formatarg("distance", v))); break; default: case FORMAT_NUMBER: SetText(to_string(v, "f")); break; } return this; }
/* * Function: Distance * * Create a string representation of the given distance value. * * > string = Format.Distance(distance) * * Parameters: * * distance - a distance in metres * * Return: * * string - the string representation * * Availability: * * alpha 10 * * Status: * * stable */ static int l_format_distance(lua_State *l) { double t = luaL_checknumber(l, 1); lua_pushstring(l, format_distance(t).c_str()); return 1; }
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(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(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() == SystemBody::SUPERTYPE_STAR ? Lang::SOLAR : Lang::EARTH)))); _add_label_and_value(Lang::RADIUS, stringf(Lang::N_WHATEVER_RADII, formatarg("radius", b->radius.ToDouble()), formatarg("units", std::string(b->GetSuperType() == SystemBody::SUPERTYPE_STAR ? Lang::SOLAR : Lang::EARTH)))); if (b->type != SystemBody::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, format_distance(b->orbMin.ToDouble()*AU, 3)); _add_label_and_value(Lang::APOAPSIS_DISTANCE, format_distance(b->orbMax.ToDouble()*AU, 3)); _add_label_and_value(Lang::ECCENTRICITY, stringf("%0{f.2}", b->orbit.eccentricity)); if (b->type != SystemBody::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<SystemBody*>::iterator i = b->children.begin(); i != b->children.end(); ++i) { if ((*i)->type == SystemBody::TYPE_STARPORT_SURFACE) { nameList += (numSurfaceStarports ? ", " : "") + (*i)->name; numSurfaceStarports++; } } if (numSurfaceStarports) { _add_label_and_value(Lang::STARPORTS, nameList); } } m_infoBox->ShowAll(); m_infoBox->ResizeRequest(); }