void ShipInfoPanel::DrawShipStats(const Rectangle &bounds) { // Check that the specified area is big enough. if(bounds.Width() < WIDTH) return; // Colors to draw with. Color dim = *GameData::Colors().Get("medium"); Color bright = *GameData::Colors().Get("bright"); const Ship &ship = **shipIt; const Font &font = FontSet::Get(14); // Table attributes. Table table; table.AddColumn(0, Table::LEFT); table.AddColumn(WIDTH - 20, Table::RIGHT); table.SetUnderline(0, WIDTH - 20); table.DrawAt(bounds.TopLeft() + Point(10., 8.)); // Draw the ship information. table.Draw("ship:", dim); table.Draw(font.TruncateMiddle(ship.Name(), WIDTH - 50), bright); table.Draw("model:", dim); table.Draw(ship.ModelName(), bright); info.DrawAttributes(table.GetRowBounds().TopLeft() - Point(10., 10.)); }
void ShipInfoPanel::DrawCargo(const Rectangle &bounds) { Color dim = *GameData::Colors().Get("medium"); Color bright = *GameData::Colors().Get("bright"); Color backColor = *GameData::Colors().Get("faint"); const Ship &ship = **shipIt; // Cargo list. const CargoHold &cargo = (player.Cargo().Used() ? player.Cargo() : ship.Cargo()); Table table; table.AddColumn(0, Table::LEFT); table.AddColumn(WIDTH - 20, Table::RIGHT); table.SetUnderline(-5, WIDTH - 15); table.DrawAt(bounds.TopLeft() + Point(10., 8.)); double endY = bounds.Bottom() - 30. * (cargo.Passengers() != 0); bool hasSpace = (table.GetRowBounds().Bottom() < endY); if((cargo.CommoditiesSize() || cargo.HasOutfits() || cargo.MissionCargoSize()) && hasSpace) { table.Draw("Cargo", bright); table.Advance(); hasSpace = (table.GetRowBounds().Bottom() < endY); } if(cargo.CommoditiesSize() && hasSpace) { for(const auto &it : cargo.Commodities()) { if(!it.second) continue; commodityZones.emplace_back(table.GetCenterPoint(), table.GetRowSize(), it.first); if(it.first == selectedCommodity) table.DrawHighlight(backColor); table.Draw(it.first, dim); table.Draw(to_string(it.second), bright); // Truncate the list if there is not enough space. if(table.GetRowBounds().Bottom() >= endY) { hasSpace = false; break; } } table.DrawGap(10.); } if(cargo.HasOutfits() && hasSpace) { for(const auto &it : cargo.Outfits()) { if(!it.second) continue; plunderZones.emplace_back(table.GetCenterPoint(), table.GetRowSize(), it.first); if(it.first == selectedPlunder) table.DrawHighlight(backColor); // For outfits, show how many of them you have and their total mass. bool isSingular = (it.second == 1 || it.first->Get("installable") < 0.); string name = (isSingular ? it.first->Name() : it.first->PluralName()); if(!isSingular) name += " (" + to_string(it.second) + "x)"; table.Draw(name, dim); double mass = it.first->Mass() * it.second; table.Draw(Format::Number(mass), bright); // Truncate the list if there is not enough space. if(table.GetRowBounds().Bottom() >= endY) { hasSpace = false; break; } } table.DrawGap(10.); } if(cargo.HasMissionCargo() && hasSpace) { for(const auto &it : cargo.MissionCargo()) { // Capitalize the name of the cargo. table.Draw(Format::Capitalize(it.first->Cargo()), dim); table.Draw(to_string(it.second), bright); // Truncate the list if there is not enough space. if(table.GetRowBounds().Bottom() >= endY) break; } table.DrawGap(10.); } if(cargo.Passengers() && endY >= bounds.Top()) { table.DrawAt(Point(bounds.Left(), endY) + Point(10., 8.)); table.Draw("passengers:", dim); table.Draw(to_string(cargo.Passengers()), bright); } }
void ShipInfoPanel::DrawOutfits(const Rectangle &bounds, Rectangle &cargoBounds) { // Check that the specified area is big enough. if(bounds.Width() < WIDTH) return; // Colors to draw with. Color dim = *GameData::Colors().Get("medium"); Color bright = *GameData::Colors().Get("bright"); const Ship &ship = **shipIt; // Table attributes. Table table; table.AddColumn(0, Table::LEFT); table.AddColumn(WIDTH - 20, Table::RIGHT); table.SetUnderline(0, WIDTH - 20); Point start = bounds.TopLeft() + Point(10., 8.); table.DrawAt(start); // Draw the outfits in the same order used in the outfitter. for(const string &category : Outfit::CATEGORIES) { auto it = outfits.find(category); if(it == outfits.end()) continue; // Skip to the next column if there is not space for this category label // plus at least one outfit. if(table.GetRowBounds().Bottom() + 40. > bounds.Bottom()) { start += Point(WIDTH, 0.); if(start.X() + WIDTH - 20 > bounds.Right()) break; table.DrawAt(start); } // Draw the category label. table.Draw(category, bright); table.Advance(); for(const Outfit *outfit : it->second) { // Check if we've gone below the bottom of the bounds. if(table.GetRowBounds().Bottom() > bounds.Bottom()) { start += Point(WIDTH, 0.); if(start.X() + WIDTH - 20 > bounds.Right()) break; table.DrawAt(start); table.Draw(category, bright); table.Advance(); } // Draw the outfit name and count. table.Draw(outfit->Name(), dim); string number = to_string(ship.OutfitCount(outfit)); table.Draw(number, bright); } // Add an extra gap in between categories. table.DrawGap(10.); } // Check if this information spilled over into the cargo column. if(table.GetPoint().X() >= cargoBounds.Left()) { double startY = table.GetRowBounds().Top() - 8.; cargoBounds = Rectangle::WithCorners( Point(cargoBounds.Left(), startY), Point(cargoBounds.Right(), max(startY, cargoBounds.Bottom()))); } }