]> git.localhorst.tv Git - l2e.git/commitdiff
started implementation of equipment menu
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 20 Nov 2012 19:22:38 +0000 (20:22 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 20 Nov 2012 19:22:38 +0000 (20:22 +0100)
src/main.cpp
src/menu/EquipMenu.cpp [new file with mode: 0644]
src/menu/EquipMenu.h [new file with mode: 0644]
src/menu/PartyMenu.cpp
src/menu/PartyMenu.h
src/menu/Resources.cpp
src/menu/Resources.h
src/menu/fwd.h

index acdc0ad7e3dd457e2afb7d937079a26f491d9702..df5ab7a9d3de930e8abe127ecb7074e9e1b9ffdc 100644 (file)
@@ -411,6 +411,28 @@ int main(int argc, char **argv) {
                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);
diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp
new file mode 100644 (file)
index 0000000..da24f77
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * 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());
+}
+
+}
diff --git a/src/menu/EquipMenu.h b/src/menu/EquipMenu.h
new file mode 100644 (file)
index 0000000..39380dc
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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_ */
index 993fad5abc00f0293175ffc635213461da0b79a6..bda633129211b3973d5e1d33034f6691c8d5efbd 100644 (file)
@@ -8,6 +8,7 @@
 #include "PartyMenu.h"
 
 #include "ChangeHero.h"
+#include "EquipMenu.h"
 #include "InventoryMenu.h"
 #include "Resources.h"
 #include "SelectHero.h"
@@ -104,6 +105,7 @@ void PartyMenu::HandleEvents(const Input &input) {
                        case MENU_ITEM_CAPSULE:
                                break;
                        case MENU_ITEM_EQUIP:
+                               Ctrl().PushState(new SelectHero(this, this, this, OnEquipSelect));
                                break;
                        case MENU_ITEM_STATUS:
                                Ctrl().PushState(new SelectHero(this, this, this, OnStatusSelect));
@@ -202,10 +204,10 @@ const Resources &PartyMenu::Res() const {
        return *game->menuResources;
 }
 
-void PartyMenu::OnStatusSelect(void *ref, int index) {
+void PartyMenu::OnEquipSelect(void *ref, int index) {
        PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
        self->Ctrl().ChangeState(
-                       new StatusMenu(self, index));
+                       new EquipMenu(self, index));
 }
 
 void PartyMenu::OnSpellSelect(void *ref, int index) {
@@ -214,4 +216,10 @@ void PartyMenu::OnSpellSelect(void *ref, int index) {
                        new SpellMenu(self, index));
 }
 
+void PartyMenu::OnStatusSelect(void *ref, int index) {
+       PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
+       self->Ctrl().ChangeState(
+                       new StatusMenu(self, index));
+}
+
 }
index 91c25ba549d14a92fdbd3250cce4b3d5722f7c48..f915d30e4a45d2cc3950a7f7fe43ac81f0ef7211 100644 (file)
@@ -47,8 +47,9 @@ public:
        geometry::Vector<int> StatusOffset(int index) const;
        const HeroStatus &GetHeroStatus(int index) const { return status[index]; }
 
-       static void OnStatusSelect(void *, int);
+       static void OnEquipSelect(void *, int);
        static void OnSpellSelect(void *, int);
+       static void OnStatusSelect(void *, int);
 
 private:
        virtual void OnEnterState(SDL_Surface *screen);
index 0e256acc3b89411760be48177b598444ea670376..8b36b252f007524a7461e0f2b32d9450ade402d9 100644 (file)
@@ -64,7 +64,15 @@ Resources::Resources()
 
 , inventoryMenuProperties(0)
 
-, spellMenuProperties(0) {
+, spellMenuProperties(0)
+
+, equipmentActionMenuProperties(0)
+, equipmentMenuProperties(0)
+, equipMenuEquipLabel(0)
+, equipMenuStrongestLabel(0)
+, equipMenuRemoveLabel(0)
+, equipMenuRemoveAllLabel(0)
+, equipMenuDropLabel(0) {
 
 }
 
index df69225748c5819217d4d7b97782aa2bd30deb59..acc99ad3a6bbcc076c5ee9dbf569a47691c7ee35 100644 (file)
@@ -71,6 +71,14 @@ struct Resources {
 
        graphics::MenuProperties *spellMenuProperties;
 
+       graphics::MenuProperties *equipmentActionMenuProperties;
+       graphics::MenuProperties *equipmentMenuProperties;
+       const char *equipMenuEquipLabel;
+       const char *equipMenuStrongestLabel;
+       const char *equipMenuRemoveLabel;
+       const char *equipMenuRemoveAllLabel;
+       const char *equipMenuDropLabel;
+
        Resources();
 
 };
index 0f88e193ef4a83bfc07673cee731953179582f11..40d0163bc8d7941a1e883ab6284bf4bdb0b06e41 100644 (file)
@@ -11,6 +11,7 @@
 namespace menu {
 
 class ChangeHero;
+class EquipMenu;
 class HeroStatus;
 class InventoryMenu;
 class PartyMenu;