Skip to content

Commit

Permalink
Merge pull request #1437 from ayrtondenner/issue-1429-add-store-space…
Browse files Browse the repository at this point in the history
…-item-info

Add store space item info
  • Loading branch information
FilmBoy84 committed May 10, 2024
2 parents 5c9f30f + f56ee59 commit 774386a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 73 deletions.
73 changes: 34 additions & 39 deletions game/ui/general/aequipmentsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,29 @@ void AEquipmentSheet::clear()
}

void AEquipmentSheet::displayImplementation(sp<AEquipment> item, const AEquipmentType &itemType,
bool researched)
const bool researched)
{
if (!researched)
{
displayAlien(item, itemType);
return;
}
const auto itemName = researched
? itemType.name
: (itemType.bioStorage ? tr("Alien Organism") : tr("Alien Artifact"));

const auto selectedImage =
researched && item ? item->getEquipmentImage() : itemType.equipscreen_sprite;

form->findControlTyped<Label>("ITEM_NAME")->setText(itemType.name);
form->findControlTyped<Graphic>("SELECTED_IMAGE")
->setImage(item ? item->getEquipmentImage() : itemType.equipscreen_sprite);
form->findControlTyped<Label>("ITEM_NAME")->setText(itemName);
form->findControlTyped<Graphic>("SELECTED_IMAGE")->setImage(selectedImage);

// when possible, the actual item's weight takes precedence
form->findControlTyped<Label>("LABEL_1_L")->setText(tr("Weight"));
form->findControlTyped<Label>("LABEL_1_R")
->setText(format("%d", item ? item->getWeight() : itemType.weight));

form->findControlTyped<Label>("LABEL_2_L")->setText(tr("Storage"));
form->findControlTyped<Label>("LABEL_2_R")->setText(format("%d", itemType.store_space));

if (!researched)
return;

switch (itemType.type)
{
case AEquipmentType::Type::Grenade:
Expand Down Expand Up @@ -99,23 +105,23 @@ void AEquipmentSheet::displayImplementation(sp<AEquipment> item, const AEquipmen
void AEquipmentSheet::displayGrenade(sp<AEquipment> item [[maybe_unused]],
const AEquipmentType &itemType)
{
form->findControlTyped<Label>("LABEL_2_C")->setText(itemType.damage_type->name);
form->findControlTyped<Label>("LABEL_3_C")->setText(itemType.damage_type->name);

form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Power"));
form->findControlTyped<Label>("LABEL_3_R")->setText(format("%d", itemType.damage));
form->findControlTyped<Label>("LABEL_4_L")->setText(tr("Power"));
form->findControlTyped<Label>("LABEL_4_R")->setText(format("%d", itemType.damage));
}

void AEquipmentSheet::displayAmmo(sp<AEquipment> item, const AEquipmentType &itemType)
{
form->findControlTyped<Label>("LABEL_2_L")->setText(tr("Accuracy"));
form->findControlTyped<Label>("LABEL_2_R")->setText(format("%d", itemType.accuracy));
form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Accuracy"));
form->findControlTyped<Label>("LABEL_3_R")->setText(format("%d", itemType.accuracy));

form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Fire rate"));
form->findControlTyped<Label>("LABEL_3_R")
form->findControlTyped<Label>("LABEL_4_L")->setText(tr("Fire rate"));
form->findControlTyped<Label>("LABEL_4_R")
->setText(format("%.2f", itemType.getRoundsPerSecond()));

form->findControlTyped<Label>("LABEL_4_L")->setText(tr("Range"));
form->findControlTyped<Label>("LABEL_4_R")->setText(format("%d", itemType.getRangeInTiles()));
form->findControlTyped<Label>("LABEL_5_L")->setText(tr("Range"));
form->findControlTyped<Label>("LABEL_5_R")->setText(format("%d", itemType.getRangeInTiles()));

form->findControlTyped<Label>("LABEL_6_C")->setText(tr("Ammo Type:"));
form->findControlTyped<Label>("LABEL_7_C")->setText(itemType.damage_type->name);
Expand Down Expand Up @@ -143,21 +149,21 @@ void AEquipmentSheet::displayWeapon(sp<AEquipment> item [[maybe_unused]],
}

auto &ammoType = *itemType.ammo_types.begin();
form->findControlTyped<Label>("LABEL_2_L")->setText(tr("Accuracy"));
form->findControlTyped<Label>("LABEL_2_R")->setText(format("%d", ammoType->accuracy));
form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Accuracy"));
form->findControlTyped<Label>("LABEL_3_R")->setText(format("%d", ammoType->accuracy));

form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Fire rate"));
form->findControlTyped<Label>("LABEL_3_R")
form->findControlTyped<Label>("LABEL_4_L")->setText(tr("Fire rate"));
form->findControlTyped<Label>("LABEL_4_R")
->setText(format("%.2f", ammoType->getRoundsPerSecond()));

form->findControlTyped<Label>("LABEL_4_L")->setText(tr("Range"));
form->findControlTyped<Label>("LABEL_4_R")->setText(format("%d", ammoType->getRangeInTiles()));
form->findControlTyped<Label>("LABEL_5_L")->setText(tr("Range"));
form->findControlTyped<Label>("LABEL_5_R")->setText(format("%d", ammoType->getRangeInTiles()));

form->findControlTyped<Label>("LABEL_5_C")->setText(tr("Ammo types:"));
form->findControlTyped<Label>("LABEL_6_C")->setText(tr("Ammo types:"));
int ammoNum = 1;
for (auto &ammo : itemType.ammo_types)
{
form->findControlTyped<Label>(format("LABEL_%d_C", 5 + ammoNum))->setText(ammo->name);
form->findControlTyped<Label>(format("LABEL_%d_C", 6 + ammoNum))->setText(ammo->name);
if (++ammoNum >= 4)
{
break;
Expand All @@ -167,8 +173,8 @@ void AEquipmentSheet::displayWeapon(sp<AEquipment> item [[maybe_unused]],

void AEquipmentSheet::displayArmor(sp<AEquipment> item, const AEquipmentType &itemType)
{
form->findControlTyped<Label>("LABEL_2_L")->setText(tr("Protection"));
form->findControlTyped<Label>("LABEL_2_R")
form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Protection"));
form->findControlTyped<Label>("LABEL_3_R")
->setText(item ? format("%d / %d", item->armor, itemType.armor)
: format("%d", itemType.armor));
}
Expand All @@ -178,15 +184,4 @@ void AEquipmentSheet::displayOther(sp<AEquipment> item [[maybe_unused]],
{
}

void AEquipmentSheet::displayAlien(sp<AEquipment> item, const AEquipmentType &itemType)
{
form->findControlTyped<Label>("ITEM_NAME")
->setText(itemType.bioStorage ? tr("Alien Organism") : tr("Alien Artifact"));
form->findControlTyped<Graphic>("SELECTED_IMAGE")->setImage(itemType.equipscreen_sprite);

form->findControlTyped<Label>("LABEL_1_L")->setText(tr("Weight"));
form->findControlTyped<Label>("LABEL_1_R")
->setText(format("%d", item ? item->getWeight() : itemType.weight));
}

}; // namespace OpenApoc
3 changes: 1 addition & 2 deletions game/ui/general/aequipmentsheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ class AEquipmentSheet

private:
void displayImplementation(sp<AEquipment> item, const AEquipmentType &itemType,
bool researched);
const bool researched);
void displayGrenade(sp<AEquipment> item, const AEquipmentType &itemType);
void displayWeapon(sp<AEquipment> item, const AEquipmentType &itemType);
void displayAmmo(sp<AEquipment> item, const AEquipmentType &itemType);
void displayArmor(sp<AEquipment> item, const AEquipmentType &itemType);
void displayOther(sp<AEquipment> item, const AEquipmentType &itemType);
void displayAlien(sp<AEquipment> item, const AEquipmentType &itemType);
sp<Form> form;
};

Expand Down
56 changes: 26 additions & 30 deletions game/ui/general/vehiclesheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ void VehicleSheet::display(sp<VEquipment> item)
void VehicleSheet::display(sp<VEquipmentType> itemType, bool researched)
{
clear();
if (researched)
{
displayEquipImplementation(nullptr, itemType);
}
else
{
displayAlien(itemType);
}
displayEquipImplementation(nullptr, itemType, researched);
}

void VehicleSheet::clear()
Expand Down Expand Up @@ -128,15 +121,26 @@ void VehicleSheet::displayImplementation(sp<Vehicle> vehicle, sp<VehicleType> ve
}
}

void VehicleSheet::displayEquipImplementation(sp<VEquipment> item, sp<VEquipmentType> type)
void VehicleSheet::displayEquipImplementation(sp<VEquipment> item, sp<VEquipmentType> type,
const bool isResearched)
{
form->findControlTyped<TextEdit>("TEXT_VEHICLE_NAME")->setText("");
form->findControlTyped<Label>("ITEM_NAME")->setText(item ? item->type->name : type->name);
form->findControlTyped<Graphic>("SELECTED_IMAGE")->setImage(type->equipscreen_sprite);

form->findControlTyped<Label>("LABEL_1_L")->setText(tr("Weight"));
form->findControlTyped<Label>("LABEL_1_R")->setText(format("%d", type->weight));

form->findControlTyped<Label>("LABEL_2_L")->setText(tr("Storage"));
form->findControlTyped<Label>("LABEL_2_R")->setText(format("%d", type->store_space));

if (!isResearched)
{
form->findControlTyped<Label>("ITEM_NAME")->setText(tr("Alien Artifact"));
return;
}

form->findControlTyped<TextEdit>("TEXT_VEHICLE_NAME")->setText("");
form->findControlTyped<Label>("ITEM_NAME")->setText(item ? item->type->name : type->name);

// Draw equipment stats
switch (type->type)
{
Expand All @@ -157,20 +161,20 @@ void VehicleSheet::displayEquipImplementation(sp<VEquipment> item, sp<VEquipment

void VehicleSheet::displayEngine(sp<VEquipment> item [[maybe_unused]], sp<VEquipmentType> type)
{
form->findControlTyped<Label>("LABEL_2_L")->setText(tr("Top Speed"));
form->findControlTyped<Label>("LABEL_2_R")->setText(format("%d", type->top_speed));
form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Power"));
form->findControlTyped<Label>("LABEL_3_R")->setText(format("%d", type->power));
form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Top Speed"));
form->findControlTyped<Label>("LABEL_3_R")->setText(format("%d", type->top_speed));
form->findControlTyped<Label>("LABEL_4_L")->setText(tr("Power"));
form->findControlTyped<Label>("LABEL_4_R")->setText(format("%d", type->power));
}

void VehicleSheet::displayWeapon(sp<VEquipment> item, sp<VEquipmentType> type)
{
form->findControlTyped<Label>("LABEL_2_L")->setText(tr("Damage"));
form->findControlTyped<Label>("LABEL_2_R")->setText(format("%d", type->damage));
form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Range"));
form->findControlTyped<Label>("LABEL_3_R")->setText(format("%d", type->getRangeInTiles()));
form->findControlTyped<Label>("LABEL_4_L")->setText(tr("Accuracy"));
form->findControlTyped<Label>("LABEL_4_R")->setText(format("%d%%", type->accuracy));
form->findControlTyped<Label>("LABEL_3_L")->setText(tr("Damage"));
form->findControlTyped<Label>("LABEL_3_R")->setText(format("%d", type->damage));
form->findControlTyped<Label>("LABEL_4_L")->setText(tr("Range"));
form->findControlTyped<Label>("LABEL_4_R")->setText(format("%d", type->getRangeInTiles()));
form->findControlTyped<Label>("LABEL_5_L")->setText(tr("Accuracy"));
form->findControlTyped<Label>("LABEL_5_R")->setText(format("%d%%", type->accuracy));

// Only show rounds if non-zero (IE not infinite ammo)
if (type->max_ammo != 0)
Expand All @@ -184,7 +188,7 @@ void VehicleSheet::displayWeapon(sp<VEquipment> item, sp<VEquipmentType> type)

void VehicleSheet::displayGeneral(sp<VEquipment> item [[maybe_unused]], sp<VEquipmentType> type)
{
int statsCount = 2;
int statsCount = 3;
if (type->accuracy_modifier)
{
form->findControlTyped<Label>(format("LABEL_%d_L", statsCount))->setText(tr("Accuracy"));
Expand Down Expand Up @@ -240,12 +244,4 @@ void VehicleSheet::displayGeneral(sp<VEquipment> item [[maybe_unused]], sp<VEqui
}
}

void VehicleSheet::displayAlien(sp<VEquipmentType> type)
{
form->findControlTyped<Label>("ITEM_NAME")->setText(tr("Alien Artifact"));
form->findControlTyped<Graphic>("SELECTED_IMAGE")->setImage(type->equipscreen_sprite);
form->findControlTyped<Label>("LABEL_1_L")->setText(tr("Weight"));
form->findControlTyped<Label>("LABEL_1_R")->setText(format("%d", type->weight));
}

}; // namespace OpenApoc
4 changes: 2 additions & 2 deletions game/ui/general/vehiclesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class VehicleSheet
private:
void displayImplementation(sp<Vehicle> vehicle, sp<VehicleType> vehicleType);

void displayEquipImplementation(sp<VEquipment> item, sp<VEquipmentType> itemType);
void displayEquipImplementation(sp<VEquipment> item, sp<VEquipmentType> itemType,
const bool isResearched = true);
void displayEngine(sp<VEquipment> item, sp<VEquipmentType> type);
void displayWeapon(sp<VEquipment> item, sp<VEquipmentType> type);
void displayGeneral(sp<VEquipment> item, sp<VEquipmentType> type);
void displayAlien(sp<VEquipmentType> type);

sp<Form> form;
};
Expand Down

0 comments on commit 774386a

Please sign in to comment.