From: Daniel Karbach Date: Tue, 27 Nov 2012 12:33:45 +0000 (+0100) Subject: added inventory menu to EquipMenu X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=590f468d34edb704de415d05d51f087da106a547;p=l2e.git added inventory menu to EquipMenu --- diff --git a/src/common/Item.h b/src/common/Item.h index 06c0f83..df361fe 100644 --- a/src/common/Item.h +++ b/src/common/Item.h @@ -54,12 +54,7 @@ public: 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; } @@ -91,15 +86,6 @@ public: 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, diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp index df924b1..c60ea30 100644 --- a/src/menu/EquipMenu.cpp +++ b/src/menu/EquipMenu.cpp @@ -50,6 +50,7 @@ EquipMenu::EquipMenu(PartyMenu *parent, int cursor) void EquipMenu::OnEnterState(SDL_Surface *) { equipmentMenu.SetInactive(); + inventoryMenu.SetInactive(); } void EquipMenu::OnExitState(SDL_Surface *) { @@ -81,6 +82,7 @@ void EquipMenu::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { switch (actionMenu.Selected()) { case CHOICE_EQUIP: + LoadEquipment(); actionMenu.SetSelected(); equipmentMenu.SetActive(); break; @@ -105,9 +107,15 @@ void EquipMenu::HandleEvents(const Input &input) { } 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(); @@ -115,7 +123,8 @@ void EquipMenu::HandleEvents(const Input &input) { } 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: @@ -131,6 +140,19 @@ void EquipMenu::HandleEvents(const Input &input) { 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(); + } } } @@ -149,16 +171,23 @@ void EquipMenu::Render(SDL_Surface *screen) { Vector equipOffset( 17 * parent->Res().statusFont->CharWidth(), 4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); - Vector 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 inventoryOffset( + parent->Res().statusFont->CharWidth(), + 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + RenderInventoryMenu(screen, offset + inventoryOffset); + } else { + Vector menuOffset( + 15 * parent->Res().statusFont->CharWidth(), + 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + RenderActionMenu(screen, offset + menuOffset); + } } int EquipMenu::Width() const { @@ -221,7 +250,12 @@ void EquipMenu::RenderActionMenu(SDL_Surface *screen, const Vector &offset) } void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + const Vector menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4); + frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight()); + inventoryMenu.Draw(screen, offset + menuOffset); } @@ -283,4 +317,24 @@ void EquipMenu::DropItem() { 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)); + } + } +} + } diff --git a/src/menu/EquipMenu.h b/src/menu/EquipMenu.h index 2ec66ae..24e9789 100644 --- a/src/menu/EquipMenu.h +++ b/src/menu/EquipMenu.h @@ -50,6 +50,9 @@ private: void RemoveItem(); void DropItem(); + bool InventoryVisible() const; + void LoadInventory(); + void RenderStatus(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderStats(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const geometry::Vector &position) const;