Skip to content

Commit 08488ae

Browse files
committed
Show description, and improvements to rendering
1 parent 2f5893b commit 08488ae

File tree

1 file changed

+111
-47
lines changed

1 file changed

+111
-47
lines changed

Source/Menus/BuyMenuGUI.cpp

Lines changed: 111 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,54 +1141,106 @@ void BuyMenuGUI::Update() {
11411141
GUIListPanel::Item* pItem = m_pShopList->GetItem(m_ListItemIndex);
11421142
std::string description = "";
11431143

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 += "\nNO CARGO SPACE!";
1153-
} else if (craftMaxMass > 0) {
1154-
description += "\nMax Mass: " + RoundFloatToPrecision(craftMaxMass, craftMaxMass < 50.0F ? 1 : 0, 3) + " kg";
1155-
}
1156-
if (craftMaxPassengers >= 0 && craftMaxMass != 0) {
1157-
description += (craftMaxPassengers == 0) ? "\nNO PASSENGER SPACE!" : "\nMax 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 += "\nMass: " + (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 += "\nPassenger 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 += "\nNO CARGO SPACE!";
1154+
} else if (craftMaxMass > 0) {
1155+
description += "\nMax Mass: " + RoundFloatToPrecision(craftMaxMass, craftMaxMass < 50.0F ? 1 : 0, 3) + " kg";
1156+
}
1157+
if (craftMaxPassengers >= 0 && craftMaxMass != 0) {
1158+
description += (craftMaxPassengers == 0) ? "\nNO PASSENGER SPACE!" : "\nMax Passengers: " + std::to_string(craftMaxPassengers);
11671159
}
11681160
} 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 += "\nGrenade 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 += "\nMass: " + (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 += "\nPassenger 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 += "\nGrenade Count: " + RoundFloatToPrecision(itemAsMOSRotating->GetNumberValue("Grenade Count"), 0, 2);
1177+
}
1178+
if (itemAsMOSRotating->NumberValueExists("Replenish Delay") && itemAsMOSRotating->GetNumberValue("Replenish Delay") > 0) {
1179+
description += "\nReplenish 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 += "\nMass: " + (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 += ":";
11761224
}
1177-
if (itemAsMOSRotating->NumberValueExists("Replenish Delay") && itemAsMOSRotating->GetNumberValue("Replenish Delay") > 0) {
1178-
description += "\nReplenish Delay: " + RoundFloatToPrecision(itemAsMOSRotating->GetNumberValue("Replenish Delay") / 1000.0F, 3, 2) + " seconds";
1225+
1226+
if (actorSeen || nextIsActor) {
1227+
description += "\n";
1228+
} else {
1229+
description += ", ";
11791230
}
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";
11821235
}
11831236
}
1184-
description += "\nMass: " + (itemAsMO->GetMass() + extraMass < 0.1F ? "<0.1 kg" : RoundFloatToPrecision(itemAsMO->GetMass() + extraMass, itemAsMO->GetMass() + extraMass < 50.0F ? 1 : 0, 3) + " kg");
11851237
}
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+
}
11921244
}
11931245
}
11941246

@@ -2160,16 +2212,20 @@ void BuyMenuGUI::AddPresetsToItemList() {
21602212
m_SelectedLoadoutIndex = -1;
21612213

21622214
// 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+
21642218
AllegroBitmap* pItemBitmap = nullptr;
21652219
float loadoutCost = 0;
21662220

2221+
const int maxBitmapWidth = 100;
2222+
21672223
int bitmapHeight = 0;
21682224
int bitmapWidth = 0;
21692225

21702226
int rowHeight = 0;
21712227
int rowWidth = 0;
2172-
for (const SceneObject* sceneObject : *(*lItr).GetCargoList()) {
2228+
for (const SceneObject* sceneObject: *loadout.GetCargoList()) {
21732229
if (dynamic_cast<const Actor*>(sceneObject)) {
21742230
// start a new row
21752231
bitmapHeight += rowHeight;
@@ -2178,6 +2234,10 @@ void BuyMenuGUI::AddPresetsToItemList() {
21782234
rowWidth = 0;
21792235
}
21802236

2237+
if (rowWidth + sceneObject->GetGraphicalIcon()->w > maxBitmapWidth) {
2238+
continue; // don't draw anything that would overflow the bitmap
2239+
}
2240+
21812241
rowHeight = std::max(rowHeight, sceneObject->GetGraphicalIcon()->h);
21822242
rowWidth += sceneObject->GetGraphicalIcon()->w;
21832243
}
@@ -2194,26 +2254,30 @@ void BuyMenuGUI::AddPresetsToItemList() {
21942254
rowHeight = 0;
21952255
int heightOffset = 0;
21962256
int widthOffset = 0;
2197-
for (const SceneObject* sceneObject: *(*lItr).GetCargoList()) {
2257+
for (const SceneObject* sceneObject: *loadout.GetCargoList()) {
21982258
if (dynamic_cast<const Actor*>(sceneObject)) {
21992259
// start a new row
22002260
heightOffset += rowHeight;
22012261
rowHeight = 0;
22022262
widthOffset = 0;
22032263
}
22042264

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);
22062270

22072271
rowHeight = std::max(rowHeight, sceneObject->GetGraphicalIcon()->h);
22082272
widthOffset += sceneObject->GetGraphicalIcon()->w;
22092273
}
22102274

2211-
for (const SceneObject* sceneObject: *(*lItr).GetCargoList()) {
2275+
for (const SceneObject* sceneObject: *loadout.GetCargoList()) {
22122276
loadoutCost += sceneObject->GetGoldValue(m_NativeTechModule, m_ForeignCostMult);
22132277
}
22142278

22152279
// 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);
22172281
}
22182282
}
22192283

0 commit comments

Comments
 (0)