]> git.localhorst.tv Git - l2e.git/commitdiff
added spell menu dummy
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 18 Nov 2012 16:00:55 +0000 (17:00 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 18 Nov 2012 16:21:22 +0000 (17:21 +0100)
src/main.cpp
src/menu/PartyMenu.cpp
src/menu/PartyMenu.h
src/menu/Resources.cpp
src/menu/Resources.h
src/menu/SpellMenu.cpp [new file with mode: 0644]
src/menu/SpellMenu.h [new file with mode: 0644]
src/menu/fwd.h

index b47a473d50d3f395d92eaad5507127982a774092..acdc0ad7e3dd457e2afb7d937079a26f491d9702 100644 (file)
@@ -395,6 +395,22 @@ int main(int argc, char **argv) {
                inventoryMenuProperties.delimiter = ':';
                menuResources.inventoryMenuProperties = &inventoryMenuProperties;
 
+               graphics::MenuProperties spellMenuProperties;
+               spellMenuProperties.cols = 2;
+               spellMenuProperties.rows = 6;
+               spellMenuProperties.charsPerEntry = 8;
+               spellMenuProperties.rowGap = 8;
+               spellMenuProperties.colGap = 48;
+               spellMenuProperties.cursor = &menuCursor;
+               spellMenuProperties.selectedCursor = &menuActiveCursor;
+               spellMenuProperties.font = &menuFont;
+               // TODO: disabled font
+               spellMenuProperties.disabledFont = &menuFont;
+               spellMenuProperties.iconSpace = 0;
+               spellMenuProperties.charsPerNumber = 2;
+               spellMenuProperties.delimiter = ':';
+               menuResources.spellMenuProperties = &spellMenuProperties;
+
                InitScreen screen(width, height);
 
                app::State *state(0);
index 07b7770859c1bfbb0812f810178f44534b9db0a3..993fad5abc00f0293175ffc635213461da0b79a6 100644 (file)
@@ -11,6 +11,7 @@
 #include "InventoryMenu.h"
 #include "Resources.h"
 #include "SelectHero.h"
+#include "SpellMenu.h"
 #include "StatusMenu.h"
 #include "../app/Application.h"
 #include "../app/Input.h"
@@ -98,6 +99,7 @@ void PartyMenu::HandleEvents(const Input &input) {
                                Ctrl().PushState(new InventoryMenu(this));
                                break;
                        case MENU_ITEM_SPELL:
+                               Ctrl().PushState(new SelectHero(this, this, this, OnSpellSelect));
                                break;
                        case MENU_ITEM_CAPSULE:
                                break;
@@ -206,4 +208,10 @@ void PartyMenu::OnStatusSelect(void *ref, int index) {
                        new StatusMenu(self, index));
 }
 
+void PartyMenu::OnSpellSelect(void *ref, int index) {
+       PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
+       self->Ctrl().ChangeState(
+                       new SpellMenu(self, index));
+}
+
 }
index fa1b92f908ac79f4cb45f04783543c661f582550..91c25ba549d14a92fdbd3250cce4b3d5722f7c48 100644 (file)
@@ -48,6 +48,7 @@ public:
        const HeroStatus &GetHeroStatus(int index) const { return status[index]; }
 
        static void OnStatusSelect(void *, int);
+       static void OnSpellSelect(void *, int);
 
 private:
        virtual void OnEnterState(SDL_Surface *screen);
index 28f5cb6fedb991d962a151862b0041516c6170f1..0e256acc3b89411760be48177b598444ea670376 100644 (file)
@@ -62,7 +62,9 @@ Resources::Resources()
 , itemMenuSortText(0)
 , itemMenuDropText(0)
 
-, inventoryMenuProperties(0) {
+, inventoryMenuProperties(0)
+
+, spellMenuProperties(0) {
 
 }
 
index 05ceaf3fa04b7ed785b6758679a57485a095d645..df69225748c5819217d4d7b97782aa2bd30deb59 100644 (file)
@@ -69,6 +69,8 @@ struct Resources {
 
        graphics::MenuProperties *inventoryMenuProperties;
 
+       graphics::MenuProperties *spellMenuProperties;
+
        Resources();
 
 };
diff --git a/src/menu/SpellMenu.cpp b/src/menu/SpellMenu.cpp
new file mode 100644 (file)
index 0000000..0f34d06
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * SpellMenu.cpp
+ *
+ *  Created on: Nov 18, 2012
+ *      Author: holy
+ */
+
+#include "SpellMenu.h"
+
+#include "HeroStatus.h"
+#include "PartyMenu.h"
+#include "Resources.h"
+#include "../app/Input.h"
+#include "../common/GameConfig.h"
+#include "../common/GameState.h"
+#include "../common/Hero.h"
+#include "../common/Spell.h"
+#include "../graphics/Font.h"
+#include "../graphics/Frame.h"
+
+#include <SDL.h>
+#include <vector>
+
+using app::Input;
+using common::Hero;
+using common::Spell;
+using geometry::Vector;
+using graphics::Font;
+using graphics::Frame;
+using std::vector;
+
+namespace menu {
+
+SpellMenu::SpellMenu(PartyMenu *parent, int cursor)
+: parent(parent)
+, highlight(0)
+, cursor(cursor)
+, actionMenu(*parent->Res().itemMenuProperties)
+, spellMenu(*parent->Res().spellMenuProperties) {
+       actionMenu.Add(parent->Res().itemMenuUseText, CHOICE_USE);
+       actionMenu.Add(parent->Res().itemMenuSortText, CHOICE_SORT);
+}
+
+
+void SpellMenu::OnEnterState(SDL_Surface *) {
+       const HeroStatus &status(parent->GetHeroStatus(0));
+       highlight = SDL_CreateRGBSurface(0, status.Width(), status.Height(), 32, 0xFF000000, 0xFF0000, 0xFF00, 0);
+       SDL_FillRect(highlight, 0, SDL_MapRGB(highlight->format, 0xFF, 0xFF, 0xFF));
+       SDL_SetAlpha(highlight, SDL_SRCALPHA|SDL_RLEACCEL, 0x20);
+
+       actionMenu.SetSelected();
+       LoadSpells();
+}
+
+void SpellMenu::LoadSpells() {
+       spellMenu.Clear();
+       // TODO: set to max spells once implementation is changed
+       spellMenu.Reserve(GetHero().Spells().size());
+       for (vector<const Spell *>::const_iterator
+                       i = GetHero().Spells().begin(), end = GetHero().Spells().end();
+                       i != end; ++i) {
+               const Spell *spell = *i;
+               spellMenu.Add(spell->Name(), spell, spell->CanUseOnStatusScreen(), 0, spell->Cost());
+       }
+}
+
+const Hero &SpellMenu::GetHero() const {
+       return *parent->Game().state->party[cursor];
+}
+
+void SpellMenu::OnExitState(SDL_Surface *) {
+       SDL_FreeSurface(highlight);
+}
+
+void SpellMenu::OnResumeState(SDL_Surface *) {
+
+}
+
+void SpellMenu::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void SpellMenu::OnResize(int width, int height) {
+
+}
+
+
+void SpellMenu::HandleEvents(const Input &input) {
+       if (actionMenu.IsActive()) {
+               if (input.JustPressed(Input::PAD_LEFT)) {
+                       actionMenu.PreviousItem();
+               }
+               if (input.JustPressed(Input::PAD_RIGHT)) {
+                       actionMenu.NextItem();
+               }
+       } else {
+               if (input.JustPressed(Input::PAD_UP)) {
+                       spellMenu.PreviousRow();
+               }
+               if (input.JustPressed(Input::PAD_RIGHT)) {
+                       spellMenu.NextItem();
+               }
+               if (input.JustPressed(Input::PAD_DOWN)) {
+                       spellMenu.NextRow();
+               }
+               if (input.JustPressed(Input::PAD_LEFT)) {
+                       spellMenu.PreviousItem();
+               }
+       }
+
+       if (input.JustPressed(Input::ACTION_A)) {
+               if (actionMenu.IsActive()) {
+                       if (actionMenu.Selected() == CHOICE_SORT) {
+                               // TODO: sort spells
+                               LoadSpells();
+                       } else {
+                               actionMenu.SetSelected();
+                               spellMenu.SetActive();
+                       }
+               } else if (spellMenu.IsActive()) {
+                       spellMenu.SetDualSelection();
+               } else if (spellMenu.SelectedIndex() == spellMenu.SecondaryIndex()) {
+                       if (spellMenu.Selected()->CanUseOnStatusScreen()) {
+                               // TODO: use spell
+                       }
+               } else {
+                       // TODO: swap spells
+                       spellMenu.SwapSelected();
+                       spellMenu.SetActive();
+               }
+       }
+
+       if (input.JustPressed(Input::ACTION_B)) {
+               if (actionMenu.IsActive()) {
+                       Ctrl().PopState();
+               } else if (spellMenu.IsActive()) {
+                       actionMenu.SetActive();
+                       spellMenu.SetInactive();
+               } else {
+                       spellMenu.SetActive();
+               }
+       }
+}
+
+void SpellMenu::UpdateWorld(float deltaT) {
+
+}
+
+void SpellMenu::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> spellsOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8);
+
+       parent->RenderBackground(screen);
+       RenderHighlight(screen, offset);
+       parent->RenderHeros(screen, offset);
+       RenderMenu(screen, menuOffset + offset);
+       RenderSpells(screen, spellsOffset + offset);
+}
+
+int SpellMenu::Width() const {
+       return parent->Width();
+}
+
+int SpellMenu::Height() const {
+       return parent->Height();
+}
+
+void SpellMenu::RenderHighlight(SDL_Surface *screen, const Vector<int> &offset) const {
+       if (cursor < 0) return;
+       Vector<int> statusOffset(parent->StatusOffset(cursor));
+       statusOffset -= Vector<int>(0, parent->Res().normalFont->CharHeight() / 8);
+       SDL_Rect rect;
+       rect.x = statusOffset.X();
+       rect.y = statusOffset.Y();
+       SDL_BlitSurface(highlight, 0, screen, &rect);
+}
+
+void SpellMenu::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() + 9 * font.CharWidth(), offset.Y());
+       const Vector<int> menuOffset(menuFrameOffset.X() + 3 * font.CharWidth(), menuFrameOffset.Y() + font.CharHeight());
+
+       frame.Draw(screen, offset, 9 * font.CharWidth(), 3 * font.CharHeight());
+       font.DrawString(parent->Res().mainMenuSpellText, screen, labelOffset + offset);
+       frame.Draw(screen, menuFrameOffset, 21 * font.CharWidth(), 3 * font.CharHeight());
+       actionMenu.Draw(screen, menuOffset);
+}
+
+void SpellMenu::RenderSpells(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());
+       spellMenu.Draw(screen, offset + menuOffset);
+}
+
+}
diff --git a/src/menu/SpellMenu.h b/src/menu/SpellMenu.h
new file mode 100644 (file)
index 0000000..c9c62a7
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * SpellMenu.h
+ *
+ *  Created on: Nov 18, 2012
+ *      Author: holy
+ */
+
+#ifndef MENU_SPELLMENU_H_
+#define MENU_SPELLMENU_H_
+
+#include "fwd.h"
+#include "../app/State.h"
+#include "../common/fwd.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Menu.h"
+
+namespace menu {
+
+class SpellMenu
+: public app::State {
+
+public:
+       SpellMenu(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);
+
+       const common::Hero &GetHero() const;
+
+       void LoadSpells();
+
+       void RenderHighlight(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+       void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+       void RenderSpells(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+
+private:
+       PartyMenu *parent;
+       SDL_Surface *highlight;
+       int cursor;
+       enum Choice {
+               CHOICE_USE,
+               CHOICE_SORT,
+       };
+       graphics::Menu<Choice> actionMenu;
+       graphics::Menu<const common::Spell *> spellMenu;
+
+};
+
+}
+
+#endif /* MENU_SPELLMENU_H_ */
index 5e08e00a0dfba3d1d5827b10b8c2e218b15db2ab..0f88e193ef4a83bfc07673cee731953179582f11 100644 (file)
@@ -16,6 +16,7 @@ class InventoryMenu;
 class PartyMenu;
 struct Resources;
 class SelectHero;
+class SpellMenu;
 class StatusMenu;
 
 }