@@ -2159,7 +2159,7 @@ void BuyMenuGUI::AddObjectsToItemList(std::vector<std::list<Entity*>>& moduleLis
2159
2159
void BuyMenuGUI::AddPresetsToItemList () {
2160
2160
m_SelectedLoadoutIndex = -1 ;
2161
2161
2162
- GUIBitmap * pItemBitmap = 0 ;
2162
+ AllegroBitmap * pItemBitmap = 0 ;
2163
2163
std::string loadoutLabel;
2164
2164
float loadoutCost;
2165
2165
const Actor* pPassenger = 0 ;
@@ -2172,37 +2172,56 @@ void BuyMenuGUI::AddPresetsToItemList() {
2172
2172
pItemBitmap = 0 ;
2173
2173
pPassenger = 0 ;
2174
2174
2175
- // Add preset name at the begining to differentiate loadouts from user-defined presets
2176
- if ((*lItr).GetPresetName () != " None" )
2177
- loadoutLabel = (*lItr).GetPresetName () + " :\n " ;
2178
-
2179
- // Go through the cargo setup of each loadout and encode a meaningful label for the list item
2180
- for (std::list<const SceneObject*>::iterator cItr = (*lItr).GetCargoList ()->begin (); cItr != (*lItr).GetCargoList ()->end (); ++cItr) {
2181
- // If not the first one, add a comma separator to the label
2182
- if (cItr != (*lItr).GetCargoList ()->begin ())
2183
- loadoutLabel += " , " ;
2184
- // Append the name of the current cargo thing to the label
2185
- loadoutLabel += (*cItr)->GetPresetName ();
2186
- // Adjust price for foreignness of the items to this player
2187
- loadoutCost += (*cItr)->GetGoldValue (m_NativeTechModule, m_ForeignCostMult);
2188
- if (!pPassenger)
2189
- pPassenger = dynamic_cast <const Actor*>(*cItr);
2175
+ int bitmapHeight = 0 ;
2176
+ int bitmapWidth = 0 ;
2177
+
2178
+ int rowHeight = 0 ;
2179
+ int rowWidth = 0 ;
2180
+ for (const SceneObject* sceneObject : *(*lItr).GetCargoList ()) {
2181
+ if (dynamic_cast <const Actor*>(sceneObject)) {
2182
+ // start a new row
2183
+ bitmapHeight += rowHeight;
2184
+ bitmapWidth = std::max (bitmapWidth, rowWidth);
2185
+ rowHeight = 0 ;
2186
+ rowWidth = 0 ;
2187
+ }
2188
+
2189
+ rowHeight = std::max (rowHeight, sceneObject->GetGraphicalIcon ()->h );
2190
+ rowWidth += sceneObject->GetGraphicalIcon ()->w ;
2191
+ }
2192
+
2193
+ // and once more for the last row
2194
+ bitmapHeight += rowHeight;
2195
+ bitmapWidth = std::max (bitmapWidth, rowWidth);
2196
+
2197
+ // Generate our bitmap of all the cargo items in the loadout
2198
+ pItemBitmap = new AllegroBitmap ();
2199
+ pItemBitmap->Create (bitmapWidth, bitmapHeight);
2200
+
2201
+ // Now actually draw the stuff in the appropriate places
2202
+ rowHeight = 0 ;
2203
+ int heightOffset = 0 ;
2204
+ int widthOffset = 0 ;
2205
+ for (const SceneObject* sceneObject: *(*lItr).GetCargoList ()) {
2206
+ if (dynamic_cast <const Actor*>(sceneObject)) {
2207
+ // start a new row
2208
+ heightOffset += rowHeight;
2209
+ rowHeight = 0 ;
2210
+ widthOffset = 0 ;
2211
+ }
2212
+
2213
+ draw_sprite_h_flip (pItemBitmap->GetBitmap (), sceneObject->GetGraphicalIcon (), widthOffset, heightOffset);
2214
+
2215
+ rowHeight = std::max (rowHeight, sceneObject->GetGraphicalIcon ()->h );
2216
+ widthOffset += sceneObject->GetGraphicalIcon ()->w ;
2190
2217
}
2191
2218
2192
- // Add the ship's cost, if there is one defined
2193
- if ((*lItr).GetDeliveryCraft ()) {
2194
- loadoutLabel += " via " + (*lItr).GetDeliveryCraft ()->GetPresetName ();
2195
- // Adjust price for foreignness of the ship to this player
2196
- loadoutCost += (*lItr).GetDeliveryCraft ()->GetGoldValue (m_NativeTechModule, m_ForeignCostMult);
2219
+ for (const SceneObject* sceneObject: *(*lItr).GetCargoList ()) {
2220
+ loadoutCost += sceneObject->GetGoldValue (m_NativeTechModule, m_ForeignCostMult);
2197
2221
}
2198
2222
2199
- // Make the cost label
2200
- std::snprintf (costString, sizeof (costString), " %.0f" , loadoutCost);
2201
- // Get a good icon and wrap it, while not passing ownership into the AllegroBitmap
2202
- // We're trying to pick the icon of the first passenger, or the first item if there's no passengers in the loadout
2203
- pItemBitmap = new AllegroBitmap (pPassenger ? const_cast <Actor*>(pPassenger)->GetGraphicalIcon () : const_cast <SceneObject*>((*lItr).GetCargoList ()->front ())->GetGraphicalIcon ());
2204
2223
// Passing in ownership of the bitmap, but not of the pSpriteObj
2205
- m_pShopList->AddItem (loadoutLabel , costString, pItemBitmap, 0 );
2224
+ m_pShopList->AddItem (" " , costString, pItemBitmap);
2206
2225
}
2207
2226
}
2208
2227
0 commit comments