CPP_SRCS += \
../src/menu/ChangeHero.cpp \
../src/menu/HeroStatus.cpp \
+../src/menu/InventoryMenu.cpp \
../src/menu/PartyMenu.cpp \
../src/menu/Resources.cpp \
../src/menu/SelectHero.cpp \
OBJS += \
./src/menu/ChangeHero.o \
./src/menu/HeroStatus.o \
+./src/menu/InventoryMenu.o \
./src/menu/PartyMenu.o \
./src/menu/Resources.o \
./src/menu/SelectHero.o \
CPP_DEPS += \
./src/menu/ChangeHero.d \
./src/menu/HeroStatus.d \
+./src/menu/InventoryMenu.d \
./src/menu/PartyMenu.d \
./src/menu/Resources.d \
./src/menu/SelectHero.d \
CPP_SRCS += \
../src/menu/ChangeHero.cpp \
../src/menu/HeroStatus.cpp \
+../src/menu/InventoryMenu.cpp \
../src/menu/PartyMenu.cpp \
../src/menu/Resources.cpp \
../src/menu/SelectHero.cpp \
OBJS += \
./src/menu/ChangeHero.o \
./src/menu/HeroStatus.o \
+./src/menu/InventoryMenu.o \
./src/menu/PartyMenu.o \
./src/menu/Resources.o \
./src/menu/SelectHero.o \
CPP_DEPS += \
./src/menu/ChangeHero.d \
./src/menu/HeroStatus.d \
+./src/menu/InventoryMenu.d \
./src/menu/PartyMenu.d \
./src/menu/Resources.d \
./src/menu/SelectHero.d \
MenuProperties()
: font(0), disabledFont(0), cursor(0)
- , charsPerEntry(0), rows(0), rowGap(0)
- , iconSpace(0), cols(0), colGap(0)
+ , charsPerEntry(0), rows(1), rowGap(0)
+ , iconSpace(0), cols(1), colGap(0)
, charsPerNumber(0), charsPerAdditionalText(0)
, additionalTextGap(0), delimiter(':')
, wrapX(false), wrapY(false) { }
geometry::Vector<int> iconOffset(
(i % cols) * (ColWidth() + colGap),
(i / cols) * RowHeight());
+
+ // Third column hack!
+ // This fixes the position of the "DROP" item in the inventory menu.
+ if (i % cols == 2) {
+ iconOffset += geometry::Vector<int>(font->CharWidth(), 0);
+ }
+
if (entries[start + i].icon) {
entries[start + i].icon->Draw(dest, position + iconOffset);
}
if (charsPerNumber) {
usedFont->DrawChar(delimiter, dest, position + textOffset);
textOffset += geometry::Vector<int>(usedFont->CharWidth(), 0);
- usedFont->DrawNumber(entries[start + i].number, dest, position + textOffset);
+ usedFont->DrawNumber(entries[start + i].number, dest, position + textOffset, charsPerNumber);
}
}
geometry::Vector<int> cursorOffset(
menuResources.nextLabel = "NEXT";
menuResources.returnLabel = "RETURN";
+ graphics::MenuProperties itemMenuProperties;
+ itemMenuProperties.cols = 3;
+ itemMenuProperties.rows = 1;
+ itemMenuProperties.charsPerEntry = 5;
+ itemMenuProperties.rowGap = 8;
+ itemMenuProperties.colGap = 16;
+ itemMenuProperties.cursor = &menuCursor;
+ itemMenuProperties.font = &menuFont;
+ itemMenuProperties.wrapX = true;
+ itemMenuProperties.wrapY = true;
+ menuResources.itemMenuProperties = &itemMenuProperties;
+ menuResources.itemMenuUseText = "USE";
+ menuResources.itemMenuSortText = "SORT";
+ menuResources.itemMenuDropText = "DROP";
+
+ graphics::MenuProperties inventoryMenuProperties;
+ inventoryMenuProperties.cols = 1;
+ inventoryMenuProperties.rows = 6;
+ inventoryMenuProperties.charsPerEntry = 13;
+ inventoryMenuProperties.rowGap = 8;
+ inventoryMenuProperties.cursor = &menuCursor;
+ inventoryMenuProperties.font = &menuFont;
+ // TODO: disabled font
+ inventoryMenuProperties.disabledFont = &menuFont;
+ inventoryMenuProperties.iconSpace = 16;
+ inventoryMenuProperties.charsPerNumber = 2;
+ inventoryMenuProperties.delimiter = ':';
+ menuResources.inventoryMenuProperties = &inventoryMenuProperties;
+
InitScreen screen(width, height);
app::State *state(0);
--- /dev/null
+/*
+ * 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);
+}
+
+}
--- /dev/null
+/*
+ * InventoryMenu.h
+ *
+ * Created on: Nov 4, 2012
+ * Author: holy
+ */
+
+#ifndef MENU_INVENTORYMENU_H_
+#define MENU_INVENTORYMENU_H_
+
+#include "fwd.h"
+#include "../app/State.h"
+#include "../common/fwd.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Menu.h"
+
+namespace menu {
+
+class InventoryMenu
+: public app::State {
+
+public:
+ explicit InventoryMenu(PartyMenu *parent);
+
+public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+ int Width() const;
+ int Height() const;
+
+private:
+ virtual void OnEnterState(SDL_Surface *screen);
+ virtual void OnExitState(SDL_Surface *screen);
+ virtual void OnResumeState(SDL_Surface *screen);
+ virtual void OnPauseState(SDL_Surface *screen);
+
+ virtual void OnResize(int width, int height);
+
+ void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderInventory(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+
+private:
+ PartyMenu *parent;
+ graphics::Menu<int> menu;
+ graphics::Menu<const common::Item *> itemMenu;
+
+};
+
+}
+
+#endif /* MENU_INVENTORYMENU_H_ */
#include "PartyMenu.h"
#include "ChangeHero.h"
+#include "InventoryMenu.h"
#include "Resources.h"
#include "SelectHero.h"
#include "StatusMenu.h"
if (input.JustPressed(Input::ACTION_A)) {
switch (mainMenu.Selected()) {
case MENU_ITEM_ITEM:
+ Ctrl().PushState(new InventoryMenu(this));
break;
case MENU_ITEM_SPELL:
break;
, statusMenuProperties(0)
, nextLabel(0)
-, returnLabel(0) {
+, returnLabel(0)
+
+, itemMenuProperties(0)
+, itemMenuUseText(0)
+, itemMenuSortText(0)
+, itemMenuDropText(0)
+
+, inventoryMenuProperties(0) {
}
const char *nextLabel;
const char *returnLabel;
+ graphics::MenuProperties *itemMenuProperties;
+ const char *itemMenuUseText;
+ const char *itemMenuSortText;
+ const char *itemMenuDropText;
+
+ graphics::MenuProperties *inventoryMenuProperties;
+
Resources();
};
class ChangeHero;
class HeroStatus;
+class InventoryMenu;
class PartyMenu;
struct Resources;
class SelectHero;