Uint16 Value() const { return value; }
- bool CanEquipWeapon() const { return equipability & EQUIPPABLE_WEAPON; }
- bool CanEquipArmor() const { return equipability & EQUIPPABLE_ARMOR; }
- bool CanEquipShield() const { return equipability & EQUIPPABLE_SHIELD; }
- bool CanEquipHelmet() const { return equipability & EQUIPPABLE_HELMET; }
- bool CanEquipRing() const { return equipability & EQUIPPABLE_RING; }
- bool CanEquipJewel() const { return equipability & EQUIPPABLE_JEWEL; }
+ bool EquipableAt(Hero::EquipSlot slot) const { return equipability & (1 << slot); }
int HeroMask() const { return heroMask; }
static void Construct(void *);
private:
- enum Equipable {
- EQUIPPABLE_NONE = 0,
- EQUIPPABLE_WEAPON = 1 << Hero::EQUIP_WEAPON,
- EQUIPPABLE_ARMOR = 1 << Hero::EQUIP_ARMOR,
- EQUIPPABLE_SHIELD = 1 << Hero::EQUIP_SHIELD,
- EQUIPPABLE_HELMET = 1 << Hero::EQUIP_HELMET,
- EQUIPPABLE_RING = 1 << Hero::EQUIP_RING,
- EQUIPPABLE_JEWEL = 1 << Hero::EQUIP_JEWEL,
- };
enum Property {
PROPERTY_HAS_EFFECT_STATUS = 1,
PROPERTY_HAS_EFFECT_BATTLE = 2,
void EquipMenu::OnEnterState(SDL_Surface *) {
equipmentMenu.SetInactive();
+ inventoryMenu.SetInactive();
}
void EquipMenu::OnExitState(SDL_Surface *) {
if (input.JustPressed(Input::ACTION_A)) {
switch (actionMenu.Selected()) {
case CHOICE_EQUIP:
+ LoadEquipment();
actionMenu.SetSelected();
equipmentMenu.SetActive();
break;
} else if (equipmentMenu.IsActive()) {
if (input.JustPressed(Input::PAD_UP)) {
equipmentMenu.PreviousRow();
+ if (InventoryVisible()) {
+ LoadInventory();
+ }
}
if (input.JustPressed(Input::PAD_DOWN)) {
equipmentMenu.NextRow();
+ if (InventoryVisible()) {
+ LoadInventory();
+ }
}
if (input.JustPressed(Input::ACTION_B)) {
equipmentMenu.SetInactive();
} else if (input.JustPressed(Input::ACTION_A)) {
switch (actionMenu.Selected()) {
case CHOICE_EQUIP:
- // TODO
+ equipmentMenu.SetSelected();
+ inventoryMenu.SetActive();
break;
case CHOICE_STRONGEST:
case CHOICE_REMOVE_ALL:
break;
}
}
+ } else {
+ if (input.JustPressed(Input::PAD_UP)) {
+ inventoryMenu.PreviousRow();
+ }
+ if (input.JustPressed(Input::PAD_DOWN)) {
+ inventoryMenu.NextRow();
+ }
+ if (input.JustPressed(Input::ACTION_A)) {
+ // TODO: equip selected item
+ } else if (input.JustPressed(Input::ACTION_B)) {
+ inventoryMenu.SetInactive();
+ equipmentMenu.SetActive();
+ }
}
}
Vector<int> equipOffset(
17 * parent->Res().statusFont->CharWidth(),
4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
- Vector<int> menuOffset(
- 15 * parent->Res().statusFont->CharWidth(),
- 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
parent->RenderBackground(screen);
parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
RenderStatus(screen, offset + parent->StatusOffset(0));
RenderStats(screen, offset + statsOffset);
RenderEquipmentMenu(screen, offset + equipOffset);
- RenderActionMenu(screen, offset + menuOffset);
+ if (InventoryVisible()) {
+ Vector<int> inventoryOffset(
+ parent->Res().statusFont->CharWidth(),
+ 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+ RenderInventoryMenu(screen, offset + inventoryOffset);
+ } else {
+ Vector<int> menuOffset(
+ 15 * parent->Res().statusFont->CharWidth(),
+ 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+ RenderActionMenu(screen, offset + menuOffset);
+ }
}
int EquipMenu::Width() const {
}
void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+ const Font &font(*parent->Res().normalFont);
+ const Frame &frame(*parent->Res().statusFrame);
+ const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
+ frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
+ inventoryMenu.Draw(screen, offset + menuOffset);
}
LoadEquipment();
}
+
+bool EquipMenu::InventoryVisible() const {
+ return !actionMenu.IsActive() && actionMenu.Selected() == CHOICE_EQUIP;
+}
+
+void EquipMenu::LoadInventory() {
+ const Inventory &inv = parent->Game().state->inventory;
+ const Hero &hero = GetHero();
+ const Hero::EquipSlot slot = Hero::EquipSlot(equipmentMenu.SelectedIndex());
+
+ inventoryMenu.Clear();
+ for (int i = 0; i < inv.MaxItems(); ++i) {
+ const Item *item = inv.ItemAt(i);
+ if (item && item->EquipableAt(slot)) {
+ inventoryMenu.Add(item->Name(), item, hero.CanEquip(*item),
+ item->MenuIcon(), inv.ItemCountAt(i));
+ }
+ }
+}
+
}