X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FPartyMenu.cpp;h=f3176b3f70981aa4fe66c942b3d4ea4bd9d6aa8c;hb=6dff93b1a6e9b727dbe26747456f4b23efca86da;hp=85d19d2064456b74e44e63ce988253672b952ead;hpb=bba1ac05e8c1854dc61bd737d228d9bc18bbb6ad;p=l2e.git diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 85d19d2..f3176b3 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -1,14 +1,14 @@ -/* - * PartyMenu.cpp - * - * Created on: Oct 21, 2012 - * Author: holy - */ - #include "PartyMenu.h" +#include "CapsuleMenu.h" +#include "ChangeHero.h" +#include "ConfigMenu.h" +#include "EquipMenu.h" +#include "InventoryMenu.h" #include "Resources.h" +#include "ScenarioMenu.h" #include "SelectHero.h" +#include "SpellMenu.h" #include "StatusMenu.h" #include "../app/Application.h" #include "../app/Input.h" @@ -29,18 +29,19 @@ 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); mainMenu.Add(Res().mainMenuSpellText, 1); mainMenu.Add(Res().mainMenuChangeText, 5); - mainMenu.Add(Res().mainMenuCapsuleText, 2); + mainMenu.Add(Res().mainMenuCapsuleText, 2, game->state->capsule); mainMenu.Add(Res().mainMenuConfigText, 6); mainMenu.Add(Res().mainMenuEquipmentText, 3); mainMenu.Add(Res().mainMenuScenarioText, 7); @@ -92,21 +93,32 @@ void PartyMenu::HandleEvents(const Input &input) { 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: + if (game->state->capsule) { + Ctrl().PushState(new CapsuleMenu(this)); + } else { + // noise and blur + } break; case MENU_ITEM_EQUIP: + Ctrl().PushState(new SelectHero(this, this, this, OnEquipSelect)); break; case MENU_ITEM_STATUS: - Ctrl().PushState(new SelectHero(this, OnStatusSelect)); + Ctrl().PushState(new SelectHero(this, this, this, OnStatusSelect)); break; case MENU_ITEM_CHANGE: + Ctrl().PushState(new ChangeHero(this)); break; case MENU_ITEM_CONFIG: + Ctrl().PushState(new ConfigMenu(this)); break; case MENU_ITEM_SCENARIO: + Ctrl().PushState(new ScenarioMenu(this)); break; default: break; @@ -119,14 +131,25 @@ 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, StatusOffset()); - 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)); + 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)); } -Vector PartyMenu::StatusOffset() const { - return Vector(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight()); +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 { @@ -135,10 +158,14 @@ void PartyMenu::RenderBackground(SDL_Surface *screen) const { 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); @@ -180,8 +207,22 @@ const Resources &PartyMenu::Res() const { return *game->menuResources; } -void PartyMenu::OnStatusSelect(PartyMenu *self, int index) { - self->Ctrl().ChangeState(new StatusMenu(self)); +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)); } }