X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FEquipMenu.cpp;h=8e509660ee302a81b50e457712dfbb3c60581fd0;hb=5d1a76ae7725af998c6ee46adfe492c68ee1d34f;hp=c60ea30a92795cb56fc85861b5ca95f03bd7f8ab;hpb=590f468d34edb704de415d05d51f087da106a547;p=l2e.git diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp index c60ea30..8e50966 100644 --- a/src/menu/EquipMenu.cpp +++ b/src/menu/EquipMenu.cpp @@ -1,10 +1,3 @@ -/* - * EquipMenu.cpp - * - * Created on: Nov 18, 2012 - * Author: holy - */ - #include "EquipMenu.h" #include "HeroStatus.h" @@ -26,7 +19,7 @@ using common::Hero; using common::Inventory; using common::Item; using common::Stats; -using geometry::Vector; +using math::Vector; using graphics::Font; using graphics::Frame; @@ -72,6 +65,12 @@ void EquipMenu::OnResize(int width, int height) { void EquipMenu::HandleEvents(const Input &input) { + if (input.JustPressed(Input::SHOULDER_LEFT)) { + PreviousHero(); + } + if (input.JustPressed(Input::SHOULDER_RIGHT)) { + NextHero(); + } if (actionMenu.IsActive()) { if (input.JustPressed(Input::PAD_UP)) { actionMenu.PreviousRow(); @@ -87,7 +86,7 @@ void EquipMenu::HandleEvents(const Input &input) { equipmentMenu.SetActive(); break; case CHOICE_STRONGEST: - // TODO + // TODO: implement "equip strongest" when items' stat effects are done break; case CHOICE_REMOVE: actionMenu.SetSelected(); @@ -148,7 +147,9 @@ void EquipMenu::HandleEvents(const Input &input) { inventoryMenu.NextRow(); } if (input.JustPressed(Input::ACTION_A)) { - // TODO: equip selected item + EquipSelected(); + inventoryMenu.SetInactive(); + equipmentMenu.SetActive(); } else if (input.JustPressed(Input::ACTION_B)) { inventoryMenu.SetInactive(); equipmentMenu.SetActive(); @@ -156,7 +157,7 @@ void EquipMenu::HandleEvents(const Input &input) { } } -void EquipMenu::UpdateWorld(float deltaT) { +void EquipMenu::UpdateWorld(Uint32 deltaT) { } @@ -262,11 +263,17 @@ void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector &offs void EquipMenu::NextHero() { cursor = (cursor + 1) % parent->Game().state->partySize; LoadEquipment(); + if (InventoryVisible()) { + LoadInventory(); + } } void EquipMenu::PreviousHero() { cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize; LoadEquipment(); + if (InventoryVisible()) { + LoadInventory(); + } } Hero &EquipMenu::GetHero() { @@ -285,7 +292,7 @@ void EquipMenu::LoadEquipment() { const Item *item(GetHero().Equipment(Hero::EquipSlot(i))); equipmentMenu.Add(item->Name(), item, true, item->MenuIcon()); } else { - equipmentMenu.Add(parent->Res().noEquipmentText, 0, false); + equipmentMenu.Add(parent->Res().noEquipmentText, 0); } } } @@ -337,4 +344,30 @@ void EquipMenu::LoadInventory() { } } +void EquipMenu::EquipSelected() { + Inventory &inv = parent->Game().state->inventory; + Hero &hero = GetHero(); + const Hero::EquipSlot slot = Hero::EquipSlot(equipmentMenu.SelectedIndex()); + + const Item *selected = inventoryMenu.Selected(); + const Item *equipped = equipmentMenu.Selected(); + + if (!hero.CanEquip(*selected)) { + // TODO: error noise and blur + return; + } + + inv.Remove(selected, 1); + if (!inv.Add(equipped, 1)) { + // roll back + inv.Add(selected, 1); + // TODO: error noise, blur, message? + return; + } + + hero.SetEquipment(slot, selected); + LoadEquipment(); + LoadInventory(); +} + }