spellMenuProperties.delimiter = ':';
menuResources.spellMenuProperties = &spellMenuProperties;
+ graphics::MenuProperties equipmentActionMenuProperties;
+ equipmentActionMenuProperties.cols = 1;
+ equipmentActionMenuProperties.rows = 5;
+ equipmentActionMenuProperties.charsPerEntry = 10;
+ equipmentActionMenuProperties.rowGap = 8;
+ equipmentActionMenuProperties.cursor = &menuCursor;
+ equipmentActionMenuProperties.selectedCursor = &menuActiveCursor;
+ equipmentActionMenuProperties.font = &menuFont;
+ equipmentActionMenuProperties.iconSpace = 0;
+ menuResources.equipmentActionMenuProperties = &equipmentActionMenuProperties;
+
+ graphics::MenuProperties equipmentMenuProperties;
+ equipmentMenuProperties.cols = 1;
+ equipmentMenuProperties.rows = 5;
+ equipmentMenuProperties.charsPerEntry = 12;
+ equipmentMenuProperties.rowGap = 16;
+ equipmentMenuProperties.cursor = &menuCursor;
+ equipmentMenuProperties.selectedCursor = &menuActiveCursor;
+ equipmentMenuProperties.font = menuResources.statusFont;
+ equipmentMenuProperties.iconSpace = 16;
+ menuResources.equipmentMenuProperties = &equipmentMenuProperties;
+
InitScreen screen(width, height);
app::State *state(0);
--- /dev/null
+/*
+ * EquipMenu.cpp
+ *
+ * Created on: Nov 18, 2012
+ * Author: holy
+ */
+
+#include "EquipMenu.h"
+
+#include "HeroStatus.h"
+#include "PartyMenu.h"
+#include "Resources.h"
+#include "../app/Application.h"
+#include "../app/Input.h"
+#include "../common/GameConfig.h"
+#include "../common/GameState.h"
+#include "../common/Hero.h"
+#include "../common/Item.h"
+#include "../common/Stats.h"
+#include "../graphics/Font.h"
+#include "../graphics/Frame.h"
+
+using app::Input;
+using common::Hero;
+using common::Item;
+using common::Stats;
+using geometry::Vector;
+using graphics::Font;
+using graphics::Frame;
+
+namespace menu {
+
+EquipMenu::EquipMenu(PartyMenu *parent, int cursor)
+: parent(parent)
+, cursor(cursor)
+, actionMenu(*parent->Res().equipmentActionMenuProperties)
+, equipmentMenu(*parent->Res().equipmentMenuProperties)
+, inventoryMenu(*parent->Res().inventoryMenuProperties) {
+ actionMenu.Add(parent->Res().equipMenuEquipLabel, CHOICE_EQUIP);
+ actionMenu.Add(parent->Res().equipMenuStrongestLabel, CHOICE_STRONGEST);
+ actionMenu.Add(parent->Res().equipMenuRemoveLabel, CHOICE_REMOVE);
+ actionMenu.Add(parent->Res().equipMenuRemoveAllLabel, CHOICE_REMOVE_ALL);
+ actionMenu.Add(parent->Res().equipMenuDropLabel, CHOICE_DROP);
+
+ LoadEquipment();
+}
+
+
+void EquipMenu::OnEnterState(SDL_Surface *) {
+ equipmentMenu.SetInactive();
+}
+
+void EquipMenu::OnExitState(SDL_Surface *) {
+
+}
+
+void EquipMenu::OnResumeState(SDL_Surface *) {
+
+}
+
+void EquipMenu::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void EquipMenu::OnResize(int width, int height) {
+
+}
+
+
+void EquipMenu::HandleEvents(const Input &input) {
+
+}
+
+void EquipMenu::UpdateWorld(float deltaT) {
+
+}
+
+void EquipMenu::Render(SDL_Surface *screen) {
+ Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
+ Vector<int> shoulderNavOffset(
+ 5 * parent->Res().statusFont->CharWidth(),
+ parent->Res().statusFont->CharHeight());
+ Vector<int> statsOffset(
+ 4 * parent->Res().statusFont->CharWidth(),
+ 8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+ Vector<int> equipOffset(
+ 17 * parent->Res().statusFont->CharWidth(),
+ 4 * 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, equipOffset);
+}
+
+int EquipMenu::Width() const {
+ return parent->Width();
+}
+
+int EquipMenu::Height() const {
+ return parent->Height();
+}
+
+void EquipMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
+ parent->GetHeroStatus(cursor).Render(screen, offset);
+}
+
+void EquipMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
+ const Stats &stats(GetHero().GetStats());
+ Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
+
+ Vector<int> position(offset);
+ RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
+
+ position += lineBreak;
+ RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
+
+ position += lineBreak;
+ RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
+
+ position += lineBreak;
+ RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
+
+ position += lineBreak;
+ RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
+
+ position += lineBreak;
+ RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
+
+ position += lineBreak;
+ RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
+}
+
+void EquipMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
+ const Font &font(*parent->Res().statusFont);
+ const Vector<int> numberOffset(4 * font.CharWidth(), 0);
+
+ font.DrawString(label, screen, position, 3);
+ font.DrawNumber(number, screen, position + numberOffset, 3);
+}
+
+void EquipMenu::RenderEquipmentMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+ equipmentMenu.Draw(screen, offset);
+}
+
+void EquipMenu::RenderActionMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+
+}
+
+void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+
+}
+
+
+void EquipMenu::NextHero() {
+ cursor = (cursor + 1) % parent->Game().state->partySize;
+ LoadEquipment();
+}
+
+void EquipMenu::PreviousHero() {
+ cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
+ LoadEquipment();
+}
+
+const Hero &EquipMenu::GetHero() const {
+ return *parent->Game().state->party[cursor];
+}
+
+void EquipMenu::LoadEquipment() {
+ equipmentMenu.Clear();
+ equipmentMenu.Add(GetHero().Weapon()->Name(), GetHero().Weapon(), true, GetHero().Weapon()->MenuIcon());
+ equipmentMenu.Add(GetHero().Armor()->Name(), GetHero().Armor(), true, GetHero().Armor()->MenuIcon());
+ equipmentMenu.Add(GetHero().Shield()->Name(), GetHero().Shield(), true, GetHero().Shield()->MenuIcon());
+ equipmentMenu.Add(GetHero().Helmet()->Name(), GetHero().Helmet(), true, GetHero().Helmet()->MenuIcon());
+ equipmentMenu.Add(GetHero().Ring()->Name(), GetHero().Ring(), true, GetHero().Ring()->MenuIcon());
+ equipmentMenu.Add(GetHero().Jewel()->Name(), GetHero().Jewel(), true, GetHero().Jewel()->MenuIcon());
+}
+
+}
--- /dev/null
+/*
+ * EquipMenu.h
+ *
+ * Created on: Nov 18, 2012
+ * Author: holy
+ */
+
+#ifndef MENU_EQUIPMENU_H_
+#define MENU_EQUIPMENU_H_
+
+#include "fwd.h"
+#include "../app/State.h"
+#include "../common/fwd.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Menu.h"
+
+namespace menu {
+
+class EquipMenu
+: public app::State {
+
+public:
+ EquipMenu(PartyMenu *parent, int heroIndex);
+
+public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+public:
+ 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 NextHero();
+ void PreviousHero();
+
+ const common::Hero &GetHero() const;
+
+ void LoadEquipment();
+
+ void RenderStatus(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderStats(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const geometry::Vector<int> &position) const;
+ void RenderEquipmentMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderActionMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderInventoryMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+
+private:
+ PartyMenu *parent;
+ int cursor;
+ enum Choice {
+ CHOICE_EQUIP,
+ CHOICE_STRONGEST,
+ CHOICE_REMOVE,
+ CHOICE_REMOVE_ALL,
+ CHOICE_DROP,
+ };
+ graphics::Menu<Choice> actionMenu;
+ graphics::Menu<const common::Item *> equipmentMenu;
+ graphics::Menu<const common::Item *> inventoryMenu;
+
+};
+
+}
+
+#endif /* MENU_EQUIPMENU_H_ */