X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FPartyMenu.cpp;h=20a2a8ee567dd74b37734699f1577a71d42ca6d9;hb=cc3d698b8c1ad09d7a3f9e3f28bc84e0ac1735ea;hp=f230358b1de4c1e1c6fdd20ab61c6efb51ffb0ca;hpb=57a75f13e98f4b5d311c2d3b9d9ff637120c5ee2;p=l2e.git diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index f230358..20a2a8e 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -1,19 +1,21 @@ -/* - * PartyMenu.cpp - * - * Created on: Oct 21, 2012 - * Author: holy - */ - #include "PartyMenu.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" #include "../common/GameConfig.h" #include "../common/GameState.h" #include "../geometry/Vector.h" #include "../graphics/Font.h" +#include "../graphics/Frame.h" #include "../graphics/Texture.h" using app::Input; @@ -23,14 +25,25 @@ using geometry::Vector; namespace menu { PartyMenu::PartyMenu(GameConfig *game) -: game(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().mainMenuConfigText, 6); + mainMenu.Add(Res().mainMenuEquipmentText, 3); + mainMenu.Add(Res().mainMenuScenarioText, 7); } PartyMenu::~PartyMenu() { @@ -65,6 +78,46 @@ void PartyMenu::HandleEvents(const Input &input) { Ctrl().PopState(); return; } + + if (input.JustPressed(Input::PAD_UP)) { + mainMenu.PreviousRow(); + } else if (input.JustPressed(Input::PAD_RIGHT)) { + mainMenu.NextItem(); + } else if (input.JustPressed(Input::PAD_DOWN)) { + mainMenu.NextRow(); + } 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: + Ctrl().PushState(new ConfigMenu(this)); + break; + case MENU_ITEM_SCENARIO: + Ctrl().PushState(new ScenarioMenu(this)); + break; + default: + break; + } + } } void PartyMenu::UpdateWorld(float deltaT) { @@ -72,14 +125,71 @@ 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()); } -void PartyMenu::RenderHeros(SDL_Surface *screen, const geometry::Vector &offset) 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); + + Res().statusFrame->Draw(screen, offset, 23 * Res().normalFont->CharWidth(), 8 * Res().normalFont->CharHeight()); + mainMenu.Draw(screen, offset + menuOffset); +} + +void PartyMenu::RenderInfo(SDL_Surface *screen, const Vector &offset) const { + Res().statusFrame->Draw(screen, offset, 17 * Res().normalFont->CharWidth(), 5 * Res().normalFont->CharHeight()); + + Vector timeLabelOffset(2 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4); + Res().normalFont->DrawString(Res().mainMenuTimeText, screen, offset + timeLabelOffset); + + Vector hoursOffset(timeLabelOffset.X() + 6 * Res().normalFont->CharWidth(), timeLabelOffset.Y()); + Res().normalFont->DrawNumber(game->state->time / 60 / 60, screen, offset + hoursOffset, 4); + + Vector timeSeparatorOffset(hoursOffset.X() + 4 * Res().normalFont->CharWidth(), hoursOffset.Y()); + Res().normalFont->DrawChar(':', screen, offset + timeSeparatorOffset); + + Vector minutesOffset(timeSeparatorOffset.X() + Res().normalFont->CharWidth(), timeSeparatorOffset.Y()); + Res().normalFont->DrawNumber(game->state->time / 60, screen, offset + minutesOffset, 2); + if (game->state->time / 60 < 10) { + Res().normalFont->DrawChar('0', screen, offset + minutesOffset); } + + Vector goldLabelOffset(2 * Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() * 3 / 4); + Res().normalFont->DrawString(Res().mainMenuGoldText, screen, offset + goldLabelOffset); + + Vector goldOffset(goldLabelOffset.X() + 6 * Res().normalFont->CharWidth(), goldLabelOffset.Y()); + Res().normalFont->DrawNumber(game->state->money, screen, offset + goldOffset, 7); } @@ -91,4 +201,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)); +} + }