X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmenu%2FPartyMenu.cpp;h=bda633129211b3973d5e1d33034f6691c8d5efbd;hb=f2abfc21845c29024ce2478f95429801e91ef8e8;hp=5a68ca4fa5c3eac66b39055f18d28e861b29f2e6;hpb=aedf4ae020e3c811341df79ceae63ca56fb7ce83;p=l2e.git diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 5a68ca4..bda6331 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -7,7 +7,13 @@ #include "PartyMenu.h" +#include "ChangeHero.h" +#include "EquipMenu.h" +#include "InventoryMenu.h" #include "Resources.h" +#include "SelectHero.h" +#include "SpellMenu.h" +#include "StatusMenu.h" #include "../app/Application.h" #include "../app/Input.h" #include "../common/GameConfig.h" @@ -27,12 +33,13 @@ PartyMenu::PartyMenu(GameConfig *game) : game(game) , mainMenu(*game->menuResources->mainMenuProperties) { for (int i(0); i < 4; ++i) { - status[i].SetHero(game->state->party[i]); + status[i].SetHero(game->state->party, i); status[i].SetResources(game->menuResources); } - status[1].SetPosition(Vector(status[0].Width() + Res().normalFont->CharWidth(), 0)); - status[2].SetPosition(Vector(0, status[0].Height() + Res().normalFont->CharHeight())); - status[3].SetPosition(Vector(status[0].Width() + Res().normalFont->CharWidth(), status[0].Height() + Res().normalFont->CharHeight())); + statusPositions[0] = Vector(0, 0); + statusPositions[1] = Vector(status[0].Width(), 0); + statusPositions[2] = Vector(0, status[0].Height()); + statusPositions[3] = Vector(status[0].Width(), status[0].Height()); mainMenu.Add(Res().mainMenuItemText, 0); mainMenu.Add(Res().mainMenuStatusText, 4); @@ -86,6 +93,34 @@ void PartyMenu::HandleEvents(const Input &input) { } else if (input.JustPressed(Input::PAD_LEFT)) { mainMenu.PreviousItem(); } + + if (input.JustPressed(Input::ACTION_A)) { + switch (mainMenu.Selected()) { + case MENU_ITEM_ITEM: + Ctrl().PushState(new InventoryMenu(this)); + break; + case MENU_ITEM_SPELL: + Ctrl().PushState(new SelectHero(this, this, this, OnSpellSelect)); + break; + 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)); + break; + case MENU_ITEM_CHANGE: + Ctrl().PushState(new ChangeHero(this)); + break; + case MENU_ITEM_CONFIG: + break; + case MENU_ITEM_SCENARIO: + break; + default: + break; + } + } } void PartyMenu::UpdateWorld(float deltaT) { @@ -93,18 +128,41 @@ void PartyMenu::UpdateWorld(float deltaT) { } void PartyMenu::Render(SDL_Surface *screen) { + Vector offset((screen->w - Width()) / 2, (screen->h - Height()) / 2); + + RenderBackground(screen); + RenderHeros(screen, offset); + RenderMenu(screen, offset + Vector(8 * Res().normalFont->CharWidth(), 13 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8)); + RenderInfo(screen, offset + Vector(14 * Res().normalFont->CharWidth(), 21 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8)); +} + +int PartyMenu::Width() const { + return 2 * (status[0].Width() + Res().normalFont->CharWidth()); +} + +int PartyMenu::Height() const { + return 2 * Res().normalFont->CharHeight() + + 2 * status[0].Height() + + Res().normalFont->CharHeight() + + 8 * Res().normalFont->CharHeight() + + 5 * Res().normalFont->CharHeight() + + 2 * Res().normalFont->CharHeight(); +} + +void PartyMenu::RenderBackground(SDL_Surface *screen) const { Res().menubg->Render(screen, Vector(), Vector(screen->w, screen->h)); - RenderHeros(screen, Vector(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight())); - RenderMenu(screen, Vector(8 * Res().normalFont->CharWidth(), 13 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8)); - RenderInfo(screen, Vector(14 * Res().normalFont->CharWidth(), 21 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8)); } void PartyMenu::RenderHeros(SDL_Surface *screen, const Vector &offset) const { for (int i(0); i < 4; ++i) { - status[i].Render(screen, offset); + status[i].Render(screen, offset + StatusOffset(i)); } } +Vector PartyMenu::StatusOffset(int index) const { + return statusPositions[index] + Vector(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight()); +} + void PartyMenu::RenderMenu(SDL_Surface *screen, const Vector &offset) const { Vector menuOffset(3 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4); @@ -146,4 +204,22 @@ const Resources &PartyMenu::Res() const { return *game->menuResources; } +void PartyMenu::OnEquipSelect(void *ref, int index) { + PartyMenu *self(reinterpret_cast(ref)); + self->Ctrl().ChangeState( + new EquipMenu(self, index)); +} + +void PartyMenu::OnSpellSelect(void *ref, int index) { + PartyMenu *self(reinterpret_cast(ref)); + self->Ctrl().ChangeState( + new SpellMenu(self, index)); +} + +void PartyMenu::OnStatusSelect(void *ref, int index) { + PartyMenu *self(reinterpret_cast(ref)); + self->Ctrl().ChangeState( + new StatusMenu(self, index)); +} + }