+/*
+ * InventoryMenu.cpp
+ *
+ * Created on: Nov 4, 2012
+ * Author: holy
+ */
+
+#include "InventoryMenu.h"
+
+#include "PartyMenu.h"
+#include "Resources.h"
+#include "../app/Input.h"
+#include "../common/GameConfig.h"
+#include "../common/GameState.h"
+#include "../common/Inventory.h"
+#include "../common/Item.h"
+#include "../graphics/Font.h"
+#include "../graphics/Frame.h"
+
+using app::Input;
+using common::Inventory;
+using common::Item;
+using geometry::Vector;
+using graphics::Font;
+using graphics::Frame;
+
+namespace menu {
+
+InventoryMenu::InventoryMenu(PartyMenu *parent)
+: parent(parent)
+, menu(*parent->Res().itemMenuProperties)
+, itemMenu(*parent->Res().inventoryMenuProperties) {
+ menu.Add(parent->Res().itemMenuUseText, 0);
+ menu.Add(parent->Res().itemMenuSortText, 1);
+ menu.Add(parent->Res().itemMenuDropText, 2);
+}
+
+
+void InventoryMenu::OnEnterState(SDL_Surface *) {
+ const Inventory &inv(parent->Game().state->inventory);
+ itemMenu.Clear();
+ itemMenu.Reserve(inv.MaxItems());
+ for (int i(0); i < inv.MaxItems(); ++i) {
+ const Item *item(inv.ItemAt(i));
+ if (item) {
+ itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i));
+ } else {
+ itemMenu.AddEmptyEntry();
+ }
+ }
+}
+
+void InventoryMenu::OnExitState(SDL_Surface *) {
+
+}
+
+void InventoryMenu::OnResumeState(SDL_Surface *) {
+
+}
+
+void InventoryMenu::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void InventoryMenu::OnResize(int width, int height) {
+
+}
+
+
+void InventoryMenu::HandleEvents(const Input &input) {
+ if (input.JustPressed(Input::PAD_LEFT)) {
+ menu.PreviousItem();
+ }
+ if (input.JustPressed(Input::PAD_RIGHT)) {
+ menu.NextItem();
+ }
+
+ if (input.JustPressed(Input::PAD_UP)) {
+ itemMenu.PreviousItem();
+ }
+ if (input.JustPressed(Input::PAD_DOWN)) {
+ itemMenu.NextItem();
+ }
+}
+
+void InventoryMenu::UpdateWorld(float deltaT) {
+
+}
+
+
+void InventoryMenu::Render(SDL_Surface *screen) {
+ const Font &font(*parent->Res().normalFont);
+ Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
+ Vector<int> menuOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8);
+ Vector<int> inventoryOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8);
+
+ parent->RenderBackground(screen);
+ parent->RenderHeros(screen, offset);
+ RenderMenu(screen, menuOffset + offset);
+ RenderInventory(screen, inventoryOffset + offset);
+}
+
+int InventoryMenu::Width() const {
+ return parent->Width();
+}
+
+int InventoryMenu::Height() const {
+ return parent->Height();
+}
+
+void InventoryMenu::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+ const Font &font(*parent->Res().normalFont);
+ const Frame &frame(*parent->Res().statusFrame);
+
+ const Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
+ const Vector<int> menuFrameOffset(offset.X() + 8 * font.CharWidth(), offset.Y());
+ const Vector<int> menuOffset(menuFrameOffset.X() + 3 * font.CharWidth(), menuFrameOffset.Y() + font.CharHeight());
+
+ frame.Draw(screen, offset, 8 * font.CharWidth(), 3 * font.CharHeight());
+ font.DrawString(parent->Res().mainMenuItemText, screen, labelOffset + offset);
+ frame.Draw(screen, menuFrameOffset, 22 * font.CharWidth(), 3 * font.CharHeight());
+ menu.Draw(screen, menuOffset);
+}
+
+void InventoryMenu::RenderInventory(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());
+ itemMenu.Draw(screen, offset + menuOffset);
+}
+
+}