X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FStatusMenu.cpp;h=b0377033b50f1920258332595586325382a368c3;hb=b9448180c2cf0ecc75865e57d83db63d4fe3e8a5;hp=efc807feed4e9e14787a49e3acad8b967aacdb7c;hpb=bba1ac05e8c1854dc61bd737d228d9bc18bbb6ad;p=l2e.git diff --git a/src/menu/StatusMenu.cpp b/src/menu/StatusMenu.cpp index efc807f..b037703 100644 --- a/src/menu/StatusMenu.cpp +++ b/src/menu/StatusMenu.cpp @@ -7,16 +7,30 @@ #include "StatusMenu.h" +#include "HeroStatus.h" #include "PartyMenu.h" +#include "Resources.h" #include "../app/Application.h" #include "../app/Input.h" +#include "../common/GameConfig.h" +#include "../common/GameState.h" +#include "../common/Hero.h" +#include "../common/Item.h" +#include "../common/Stats.h" +#include "../graphics/Font.h" using app::Input; +using common::Hero; +using common::Item; +using common::Stats; +using geometry::Vector; +using graphics::Font; namespace menu { -StatusMenu::StatusMenu(PartyMenu *parent) -: parent(parent) { +StatusMenu::StatusMenu(PartyMenu *parent, int cursor) +: parent(parent) +, cursor(cursor) { } @@ -47,6 +61,13 @@ void StatusMenu::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_B)) { Ctrl().PopState(); } + + if (input.JustPressed(Input::SHOULDER_RIGHT)) { + NextHero(); + } + if (input.JustPressed(Input::SHOULDER_LEFT)) { + PreviousHero(); + } } void StatusMenu::UpdateWorld(float deltaT) { @@ -54,7 +75,156 @@ void StatusMenu::UpdateWorld(float deltaT) { } void StatusMenu::Render(SDL_Surface *screen) { + Vector offset((screen->w - Width()) / 2, (screen->h - Height()) / 2); + Vector shoulderNavOffset( + 5 * parent->Res().statusFont->CharWidth(), + parent->Res().statusFont->CharHeight()); + Vector statsOffset( + 4 * parent->Res().statusFont->CharWidth(), + 8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + Vector equipOffset( + 17 * parent->Res().statusFont->CharWidth(), + 4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + Vector experienceOffset( + 11 * parent->Res().statusFont->CharWidth(), + 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + Vector nextLevelOffset( + 11 * parent->Res().statusFont->CharWidth(), + 19 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + Vector ikariOffset( + 17 * parent->Res().statusFont->CharWidth(), + 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + parent->RenderBackground(screen); + parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset); + RenderStatus(screen, offset + parent->StatusOffset(0)); + RenderStats(screen, offset + statsOffset); + RenderEquipment(screen, offset + equipOffset); + RenderExperience(screen, experienceOffset); + RenderNextLevel(screen, nextLevelOffset); + RenderIkari(screen, ikariOffset); +} + +int StatusMenu::Width() const { + return parent->Width(); +} + +int StatusMenu::Height() const { + return parent->Height(); +} + +void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector &offset) const { + parent->GetHeroStatus(cursor).Render(screen, offset); +} + +void StatusMenu::RenderStats(SDL_Surface *screen, const Vector &offset) const { + const Stats &stats(GetHero().GetStats()); + Vector lineBreak(0, parent->Res().statusFont->CharHeight()); + + Vector position(offset); + RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position); + + position += lineBreak; + RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position); + + position += lineBreak; + RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position); + + position += lineBreak; + RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position); + + position += lineBreak; + RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position); + + position += lineBreak; + RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position); + + position += lineBreak; + RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position); +} + +void StatusMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector &position) const { + const Font &font(*parent->Res().statusFont); + const Vector numberOffset(4 * font.CharWidth(), 0); + + font.DrawString(label, screen, position, 3); + font.DrawNumber(number, screen, position + numberOffset, 3); +} + +void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector &offset) const { + const Hero &hero(GetHero()); + Vector lineBreak(0, 2 * parent->Res().statusFont->CharHeight()); + + Vector position(offset); + RenderEquipmentLine(hero.Weapon(), screen, position); + + position += lineBreak; + RenderEquipmentLine(hero.Armor(), screen, position); + + position += lineBreak; + RenderEquipmentLine(hero.Shield(), screen, position); + + position += lineBreak; + RenderEquipmentLine(hero.Helmet(), screen, position); + + position += lineBreak; + RenderEquipmentLine(hero.Ring(), screen, position); + + position += lineBreak; + RenderEquipmentLine(hero.Jewel(), screen, position); +} + +void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector &position) const { + const Font &font(*parent->Res().statusFont); + const Vector textOffset(font.CharWidth(), 0); + if (item) { + if (item->MenuIcon()) { + item->MenuIcon()->Draw(screen, position); + } + font.DrawString(item->Name(), screen, position + textOffset); + } else { + font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset); + } +} + +void StatusMenu::RenderExperience(SDL_Surface *screen, const geometry::Vector &offset) const { + const Font &font(*parent->Res().statusFont); + font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10); + + Vector numberOffset(offset.X(), offset.Y() + font.CharHeight()); + font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7); +} + +void StatusMenu::RenderNextLevel(SDL_Surface *screen, const geometry::Vector &offset) const { + const Font &font(*parent->Res().statusFont); + font.DrawStringRight(parent->Res().nextLevelLabel, screen, offset, 10); + + Vector numberOffset(offset.X(), offset.Y() + font.CharHeight()); + font.DrawNumberRight(GetHero().NextLevel(), screen, numberOffset, 7); +} + +void StatusMenu::RenderIkari(SDL_Surface *screen, const geometry::Vector &offset) const { + const Font &font(*parent->Res().statusFont); + font.DrawString(parent->Res().ipLabel, screen, offset, 5); + + Vector numberOffset(offset.X() + 5 * font.CharWidth(), offset.Y()); + font.DrawNumber(GetHero().RelativeIP(100), screen, numberOffset, 3); + + Vector percentOffset(offset.X() + 8 * font.CharWidth(), offset.Y()); + font.DrawChar('%', screen, percentOffset); +} + + +void StatusMenu::NextHero() { + cursor = (cursor + 1) % parent->Game().state->partySize; +} + +void StatusMenu::PreviousHero() { + cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize; +} + +const Hero &StatusMenu::GetHero() const { + return *parent->Game().state->party[cursor]; } }