From: Daniel Karbach Date: Sun, 18 Nov 2012 16:00:55 +0000 (+0100) Subject: added spell menu dummy X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=670dd3c61cba875345b6755d41f479cff8d964c4;p=l2e.git added spell menu dummy --- diff --git a/src/main.cpp b/src/main.cpp index b47a473..acdc0ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 07b7770..993fad5 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -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(ref)); + self->Ctrl().ChangeState( + new SpellMenu(self, index)); +} + } diff --git a/src/menu/PartyMenu.h b/src/menu/PartyMenu.h index fa1b92f..91c25ba 100644 --- a/src/menu/PartyMenu.h +++ b/src/menu/PartyMenu.h @@ -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); diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 28f5cb6..0e256ac 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -62,7 +62,9 @@ Resources::Resources() , itemMenuSortText(0) , itemMenuDropText(0) -, inventoryMenuProperties(0) { +, inventoryMenuProperties(0) + +, spellMenuProperties(0) { } diff --git a/src/menu/Resources.h b/src/menu/Resources.h index 05ceaf3..df69225 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -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 index 0000000..0f34d06 --- /dev/null +++ b/src/menu/SpellMenu.cpp @@ -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 +#include + +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_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 offset((screen->w - Width()) / 2, (screen->h - Height()) / 2); + Vector menuOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8); + Vector 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 &offset) const { + if (cursor < 0) return; + Vector statusOffset(parent->StatusOffset(cursor)); + statusOffset -= Vector(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 &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + + const Vector labelOffset(2 * font.CharWidth(), font.CharHeight()); + const Vector menuFrameOffset(offset.X() + 9 * font.CharWidth(), offset.Y()); + const Vector 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 &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + const Vector 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 index 0000000..c9c62a7 --- /dev/null +++ b/src/menu/SpellMenu.h @@ -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 &offset) const; + void RenderMenu(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderSpells(SDL_Surface *screen, const geometry::Vector &offset) const; + +private: + PartyMenu *parent; + SDL_Surface *highlight; + int cursor; + enum Choice { + CHOICE_USE, + CHOICE_SORT, + }; + graphics::Menu actionMenu; + graphics::Menu spellMenu; + +}; + +} + +#endif /* MENU_SPELLMENU_H_ */ diff --git a/src/menu/fwd.h b/src/menu/fwd.h index 5e08e00..0f88e19 100644 --- a/src/menu/fwd.h +++ b/src/menu/fwd.h @@ -16,6 +16,7 @@ class InventoryMenu; class PartyMenu; struct Resources; class SelectHero; +class SpellMenu; class StatusMenu; }