@@ -1141,54 +1141,106 @@ void BuyMenuGUI::Update() {
1141
1141
GUIListPanel::Item* pItem = m_pShopList->GetItem (m_ListItemIndex);
1142
1142
std::string description = " " ;
1143
1143
1144
- if (pItem && pItem->m_pEntity ) {
1145
- description = ((pItem->m_pEntity ->GetDescription ().empty ()) ? " -No Information Found-" : pItem->m_pEntity ->GetDescription ()) + " \n " ;
1146
- const Entity* currentItem = pItem->m_pEntity ;
1147
- const ACraft* itemAsCraft = dynamic_cast <const ACraft*>(currentItem);
1148
- if (itemAsCraft) {
1149
- int craftMaxPassengers = itemAsCraft->GetMaxPassengers ();
1150
- float craftMaxMass = itemAsCraft->GetMaxInventoryMass ();
1151
- if (craftMaxMass == 0 ) {
1152
- description += " \n NO CARGO SPACE!" ;
1153
- } else if (craftMaxMass > 0 ) {
1154
- description += " \n Max Mass: " + RoundFloatToPrecision (craftMaxMass, craftMaxMass < 50 .0F ? 1 : 0 , 3 ) + " kg" ;
1155
- }
1156
- if (craftMaxPassengers >= 0 && craftMaxMass != 0 ) {
1157
- description += (craftMaxPassengers == 0 ) ? " \n NO PASSENGER SPACE!" : " \n Max Passengers: " + std::to_string (craftMaxPassengers);
1158
- }
1159
- } else {
1160
- // Items in the BuyMenu always have any remainder rounded up in their masses.
1161
- const Actor* itemAsActor = dynamic_cast <const Actor*>(currentItem);
1162
- if (itemAsActor) {
1163
- description += " \n Mass: " + (itemAsActor->GetMass () < 0 .1F ? " <0.1 kg" : RoundFloatToPrecision (itemAsActor->GetMass (), itemAsActor->GetMass () < 50 .0F ? 1 : 0 , 3 ) + " kg" );
1164
- int passengerSlotsTaken = itemAsActor->GetPassengerSlots ();
1165
- if (passengerSlotsTaken > 1 ) {
1166
- description += " \n Passenger Slots: " + std::to_string (passengerSlotsTaken);
1144
+ if (pItem) {
1145
+ if (pItem->m_pEntity ) {
1146
+ description = ((pItem->m_pEntity ->GetDescription ().empty ()) ? " -No Information Found-" : pItem->m_pEntity ->GetDescription ()) + " \n " ;
1147
+ const Entity* currentItem = pItem->m_pEntity ;
1148
+ const ACraft* itemAsCraft = dynamic_cast <const ACraft*>(currentItem);
1149
+ if (itemAsCraft) {
1150
+ int craftMaxPassengers = itemAsCraft->GetMaxPassengers ();
1151
+ float craftMaxMass = itemAsCraft->GetMaxInventoryMass ();
1152
+ if (craftMaxMass == 0 ) {
1153
+ description += " \n NO CARGO SPACE!" ;
1154
+ } else if (craftMaxMass > 0 ) {
1155
+ description += " \n Max Mass: " + RoundFloatToPrecision (craftMaxMass, craftMaxMass < 50 .0F ? 1 : 0 , 3 ) + " kg" ;
1156
+ }
1157
+ if (craftMaxPassengers >= 0 && craftMaxMass != 0 ) {
1158
+ description += (craftMaxPassengers == 0 ) ? " \n NO PASSENGER SPACE!" : " \n Max Passengers: " + std::to_string (craftMaxPassengers);
1167
1159
}
1168
1160
} else {
1169
- const MovableObject* itemAsMO = dynamic_cast <const MovableObject*>(currentItem);
1170
- if (itemAsMO) {
1171
- const MOSRotating* itemAsMOSRotating = dynamic_cast <const MOSRotating*>(currentItem);
1172
- float extraMass = 0 ;
1173
- if (itemAsMOSRotating) {
1174
- if (itemAsMOSRotating->NumberValueExists (" Grenade Count" )) {
1175
- description += " \n Grenade Count: " + RoundFloatToPrecision (itemAsMOSRotating->GetNumberValue (" Grenade Count" ), 0 , 2 );
1161
+ // Items in the BuyMenu always have any remainder rounded up in their masses.
1162
+ const Actor* itemAsActor = dynamic_cast <const Actor*>(currentItem);
1163
+ if (itemAsActor) {
1164
+ description += " \n Mass: " + (itemAsActor->GetMass () < 0 .1F ? " <0.1 kg" : RoundFloatToPrecision (itemAsActor->GetMass (), itemAsActor->GetMass () < 50 .0F ? 1 : 0 , 3 ) + " kg" );
1165
+ int passengerSlotsTaken = itemAsActor->GetPassengerSlots ();
1166
+ if (passengerSlotsTaken > 1 ) {
1167
+ description += " \n Passenger Slots: " + std::to_string (passengerSlotsTaken);
1168
+ }
1169
+ } else {
1170
+ const MovableObject* itemAsMO = dynamic_cast <const MovableObject*>(currentItem);
1171
+ if (itemAsMO) {
1172
+ const MOSRotating* itemAsMOSRotating = dynamic_cast <const MOSRotating*>(currentItem);
1173
+ float extraMass = 0 ;
1174
+ if (itemAsMOSRotating) {
1175
+ if (itemAsMOSRotating->NumberValueExists (" Grenade Count" )) {
1176
+ description += " \n Grenade Count: " + RoundFloatToPrecision (itemAsMOSRotating->GetNumberValue (" Grenade Count" ), 0 , 2 );
1177
+ }
1178
+ if (itemAsMOSRotating->NumberValueExists (" Replenish Delay" ) && itemAsMOSRotating->GetNumberValue (" Replenish Delay" ) > 0 ) {
1179
+ description += " \n Replenish Delay: " + RoundFloatToPrecision (itemAsMOSRotating->GetNumberValue (" Replenish Delay" ) / 1000 .0F , 3 , 2 ) + " seconds" ;
1180
+ }
1181
+ if (itemAsMOSRotating->NumberValueExists (" Belt Mass" )) {
1182
+ extraMass = itemAsMOSRotating->GetNumberValue (" Belt Mass" );
1183
+ }
1184
+ }
1185
+ description += " \n Mass: " + (itemAsMO->GetMass () + extraMass < 0 .1F ? " <0.1 kg" : RoundFloatToPrecision (itemAsMO->GetMass () + extraMass, itemAsMO->GetMass () + extraMass < 50 .0F ? 1 : 0 , 3 ) + " kg" );
1186
+ }
1187
+ }
1188
+ }
1189
+ } else if (pItem->m_ExtraIndex != -1 ) {
1190
+ if (m_MenuCategory == PRESETS) {
1191
+ // This is a loadout preset, so get the description from the preset
1192
+ // Add preset name at the begining to differentiate loadouts from user-defined presets
1193
+ Loadout& loadout = m_Loadouts[pItem->m_ExtraIndex ];
1194
+ if (loadout.GetPresetName () != " None" ) {
1195
+ description += loadout.GetPresetName () + " :\n " ;
1196
+ }
1197
+
1198
+ // Go through the cargo setup of each loadout and encode a meaningful label for the list item
1199
+ auto lastItr = loadout.GetCargoList ()->end ();
1200
+ --lastItr;
1201
+
1202
+ auto nextItr = loadout.GetCargoList ()->begin ();
1203
+
1204
+ bool actorSeen = false ;
1205
+ for (std::list<const SceneObject*>::iterator cItr = loadout.GetCargoList ()->begin (); cItr != loadout.GetCargoList ()->end (); ++cItr) {
1206
+ ++nextItr;
1207
+
1208
+ bool isActor = dynamic_cast <const Actor*>(*cItr) != nullptr ;
1209
+ actorSeen = actorSeen || isActor;
1210
+
1211
+ // Anything under an actor should be indented
1212
+ if (!isActor && actorSeen) {
1213
+ description += " \t\t " ;
1214
+ }
1215
+
1216
+ // Append the name of the current cargo thing to the label
1217
+ description += (*cItr)->GetPresetName ();
1218
+
1219
+ // If not the last one, add a separator to the label
1220
+ if (cItr != lastItr) {
1221
+ bool nextIsActor = dynamic_cast <const Actor*>(*nextItr) != nullptr ;
1222
+ if (isActor && !nextIsActor) {
1223
+ description += " :" ;
1176
1224
}
1177
- if (itemAsMOSRotating->NumberValueExists (" Replenish Delay" ) && itemAsMOSRotating->GetNumberValue (" Replenish Delay" ) > 0 ) {
1178
- description += " \n Replenish Delay: " + RoundFloatToPrecision (itemAsMOSRotating->GetNumberValue (" Replenish Delay" ) / 1000 .0F , 3 , 2 ) + " seconds" ;
1225
+
1226
+ if (actorSeen || nextIsActor) {
1227
+ description += " \n " ;
1228
+ } else {
1229
+ description += " , " ;
1179
1230
}
1180
- if (itemAsMOSRotating->NumberValueExists (" Belt Mass" )) {
1181
- extraMass = itemAsMOSRotating->GetNumberValue (" Belt Mass" );
1231
+
1232
+ if (nextIsActor) {
1233
+ // Extra space between each actor
1234
+ description += " \n " ;
1182
1235
}
1183
1236
}
1184
- description += " \n Mass: " + (itemAsMO->GetMass () + extraMass < 0 .1F ? " <0.1 kg" : RoundFloatToPrecision (itemAsMO->GetMass () + extraMass, itemAsMO->GetMass () + extraMass < 50 .0F ? 1 : 0 , 3 ) + " kg" );
1185
1237
}
1186
- }
1187
- }
1188
- } else if (pItem && pItem-> m_ExtraIndex >= 0 ) {
1189
- const DataModule* pModule = g_PresetMan. GetDataModule (pItem-> m_ExtraIndex );
1190
- if (pModule && !pModule-> GetDescription (). empty ()) {
1191
- description = pModule-> GetDescription ();
1238
+ } else {
1239
+ const DataModule* pModule = g_PresetMan. GetDataModule (pItem-> m_ExtraIndex );
1240
+ if (pModule && !pModule-> GetDescription (). empty () ) {
1241
+ description += pModule-> GetDescription ( );
1242
+ }
1243
+ }
1192
1244
}
1193
1245
}
1194
1246
@@ -2160,16 +2212,20 @@ void BuyMenuGUI::AddPresetsToItemList() {
2160
2212
m_SelectedLoadoutIndex = -1 ;
2161
2213
2162
2214
// Go through all the presets, making intelligible list items from then for the GUI item list
2163
- for (std::vector<Loadout>::iterator lItr = m_Loadouts.begin (); lItr != m_Loadouts.end (); ++lItr) {
2215
+ for (int i = 0 ; i < m_Loadouts.size (); ++i) {
2216
+ Loadout& loadout = m_Loadouts[i];
2217
+
2164
2218
AllegroBitmap* pItemBitmap = nullptr ;
2165
2219
float loadoutCost = 0 ;
2166
2220
2221
+ const int maxBitmapWidth = 100 ;
2222
+
2167
2223
int bitmapHeight = 0 ;
2168
2224
int bitmapWidth = 0 ;
2169
2225
2170
2226
int rowHeight = 0 ;
2171
2227
int rowWidth = 0 ;
2172
- for (const SceneObject* sceneObject : *(*lItr) .GetCargoList ()) {
2228
+ for (const SceneObject* sceneObject: *loadout .GetCargoList ()) {
2173
2229
if (dynamic_cast <const Actor*>(sceneObject)) {
2174
2230
// start a new row
2175
2231
bitmapHeight += rowHeight;
@@ -2178,6 +2234,10 @@ void BuyMenuGUI::AddPresetsToItemList() {
2178
2234
rowWidth = 0 ;
2179
2235
}
2180
2236
2237
+ if (rowWidth + sceneObject->GetGraphicalIcon ()->w > maxBitmapWidth) {
2238
+ continue ; // don't draw anything that would overflow the bitmap
2239
+ }
2240
+
2181
2241
rowHeight = std::max (rowHeight, sceneObject->GetGraphicalIcon ()->h );
2182
2242
rowWidth += sceneObject->GetGraphicalIcon ()->w ;
2183
2243
}
@@ -2194,26 +2254,30 @@ void BuyMenuGUI::AddPresetsToItemList() {
2194
2254
rowHeight = 0 ;
2195
2255
int heightOffset = 0 ;
2196
2256
int widthOffset = 0 ;
2197
- for (const SceneObject* sceneObject: *(*lItr) .GetCargoList ()) {
2257
+ for (const SceneObject* sceneObject: *loadout .GetCargoList ()) {
2198
2258
if (dynamic_cast <const Actor*>(sceneObject)) {
2199
2259
// start a new row
2200
2260
heightOffset += rowHeight;
2201
2261
rowHeight = 0 ;
2202
2262
widthOffset = 0 ;
2203
2263
}
2204
2264
2205
- draw_sprite_h_flip (pItemBitmap->GetBitmap (), sceneObject->GetGraphicalIcon (), widthOffset, heightOffset);
2265
+ if (widthOffset + sceneObject->GetGraphicalIcon ()->w > maxBitmapWidth) {
2266
+ continue ; // don't draw anything that would overflow the bitmap
2267
+ }
2268
+
2269
+ draw_sprite (pItemBitmap->GetBitmap (), sceneObject->GetGraphicalIcon (), widthOffset, heightOffset);
2206
2270
2207
2271
rowHeight = std::max (rowHeight, sceneObject->GetGraphicalIcon ()->h );
2208
2272
widthOffset += sceneObject->GetGraphicalIcon ()->w ;
2209
2273
}
2210
2274
2211
- for (const SceneObject* sceneObject: *(*lItr) .GetCargoList ()) {
2275
+ for (const SceneObject* sceneObject: *loadout .GetCargoList ()) {
2212
2276
loadoutCost += sceneObject->GetGoldValue (m_NativeTechModule, m_ForeignCostMult);
2213
2277
}
2214
2278
2215
2279
// Passing in ownership of the bitmap
2216
- m_pShopList->AddItem (" " , std::to_string (loadoutCost) , pItemBitmap, 0 );
2280
+ m_pShopList->AddItem (" " , std::to_string (( int )( loadoutCost + 0 . 5f )) , pItemBitmap, nullptr , i );
2217
2281
}
2218
2282
}
2219
2283
0 commit comments