Skip to content

Commit 862478c

Browse files
committed
testing pictorial loadouts, using icons instead of text
1 parent 4aa2081 commit 862478c

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

Source/GUI/GUIListPanel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ void GUIListPanel::BuildDrawBitmap() {
337337
I->m_pBitmap->DrawTrans(m_DrawBitmap, ((thirdWidth / 2) - (bitmapWidth / 2)) - itemX + 2, bitmapY, 0);
338338
} else {
339339
// No text, just bitmap, so give it more room
340-
I->m_pBitmap->DrawTrans(m_DrawBitmap, ((thirdWidth / 2) - (bitmapWidth / 2)) - itemX + 4, bitmapY, 0);
340+
I->m_pBitmap->DrawTrans(m_DrawBitmap, ((thirdWidth) - (bitmapWidth / 2)) - itemX + 4, bitmapY, 0);
341341
}
342342
}
343343

Source/Menus/BuyMenuGUI.cpp

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ void BuyMenuGUI::AddObjectsToItemList(std::vector<std::list<Entity*>>& moduleLis
21592159
void BuyMenuGUI::AddPresetsToItemList() {
21602160
m_SelectedLoadoutIndex = -1;
21612161

2162-
GUIBitmap* pItemBitmap = 0;
2162+
AllegroBitmap* pItemBitmap = 0;
21632163
std::string loadoutLabel;
21642164
float loadoutCost;
21652165
const Actor* pPassenger = 0;
@@ -2172,37 +2172,56 @@ void BuyMenuGUI::AddPresetsToItemList() {
21722172
pItemBitmap = 0;
21732173
pPassenger = 0;
21742174

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;
21902217
}
21912218

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);
21972221
}
21982222

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());
22042223
// 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);
22062225
}
22072226
}
22082227

0 commit comments

Comments
 (0)