From: Daniel Karbach Date: Tue, 23 Oct 2012 20:31:37 +0000 (+0200) Subject: added equipment in stats screen X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=243cb7d922fe888be8d18241de138ad5949de430;p=l2e.git added equipment in stats screen --- diff --git a/src/main.cpp b/src/main.cpp index 7cb7bd2..93727fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -323,6 +323,11 @@ int main(int argc, char **argv) { menuResources.heroCursor = &heroCursor; menuResources.heroCursorBlinkTime = 532; + menuResources.noEquipmentText = "No equip"; + + graphics::Sprite shoulderNav(IMG_Load("test-data/shoulder-nav.png"), 160, 16); + menuResources.shoulderNav = &shoulderNav; + InitScreen screen(width, height); app::State *state(0); diff --git a/src/menu/HeroStatus.cpp b/src/menu/HeroStatus.cpp index 6f8b341..2d038b1 100644 --- a/src/menu/HeroStatus.cpp +++ b/src/menu/HeroStatus.cpp @@ -28,24 +28,24 @@ HeroStatus::~HeroStatus() { int HeroStatus::Width() const { - return hero->BattleSprite()->Width() + res->statusFont->CharWidth() * 10; + return hero->BattleSprite()->Width() + res->statusFont->CharWidth() * 11; } int HeroStatus::Height() const { - return hero->BattleSprite()->Height(); + return hero->BattleSprite()->Height() + res->statusFont->CharWidth(); } void HeroStatus::Render(SDL_Surface *screen, const Vector &offset) const { if (!hero) return; - hero->BattleSprite()->Draw(screen, position + offset, 0, 0); + hero->BattleSprite()->Draw(screen, offset, 0, 0); // for some reason, fonts are shifted by one pixel in the original Vector nameOffset( hero->BattleSprite()->Width(), res->statusFont->CharHeight() * 7 / 8); - nameOffset += position + offset; + nameOffset += offset; res->statusFont->DrawString(hero->Name(), screen, nameOffset, 5); Vector levelLabelOffset(nameOffset.X() + 6 * res->statusFont->CharWidth(), nameOffset.Y()); diff --git a/src/menu/HeroStatus.h b/src/menu/HeroStatus.h index 12fe62f..2888b15 100644 --- a/src/menu/HeroStatus.h +++ b/src/menu/HeroStatus.h @@ -25,19 +25,16 @@ public: public: void SetResources(const Resources *r) { res = r; } void SetHero(const common::Hero *h) { hero = h; } - void SetPosition(const geometry::Vector &p) { position = p; } int Width() const; int Height() const; geometry::Vector Size() const { return geometry::Vector(Width(), Height()); } - const geometry::Vector &Position() const { return position; } void Render(SDL_Surface *screen, const geometry::Vector &offset) const; private: const Resources *res; const common::Hero *hero; - geometry::Vector position; }; diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 85d19d2..79b2be0 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -32,9 +32,10 @@ PartyMenu::PartyMenu(GameConfig *game) 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); @@ -119,14 +120,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)); +} + +int PartyMenu::Width() const { + return 2 * (status[0].Width() + Res().normalFont->CharWidth()); } -Vector PartyMenu::StatusOffset() const { - return Vector(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight()); +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 +147,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); @@ -181,7 +197,7 @@ const Resources &PartyMenu::Res() const { } void PartyMenu::OnStatusSelect(PartyMenu *self, int index) { - self->Ctrl().ChangeState(new StatusMenu(self)); + self->Ctrl().ChangeState(new StatusMenu(self, index)); } } diff --git a/src/menu/PartyMenu.h b/src/menu/PartyMenu.h index a55b2c1..d7edf31 100644 --- a/src/menu/PartyMenu.h +++ b/src/menu/PartyMenu.h @@ -35,13 +35,16 @@ public: Resources &Res(); const Resources &Res() const; + int Width() const; + int Height() const; + public: void RenderBackground(SDL_Surface *screen) const; void RenderHeros(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderMenu(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderInfo(SDL_Surface *screen, const geometry::Vector &offset) const; - geometry::Vector StatusOffset() const; + geometry::Vector StatusOffset(int index) const; const HeroStatus &GetHeroStatus(int index) const { return status[index]; } static void OnStatusSelect(PartyMenu *, int); @@ -68,6 +71,7 @@ private: private: HeroStatus status[4]; + geometry::Vector statusPositions[4]; common::GameConfig *game; graphics::Menu mainMenu; diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 79342b2..166fbf7 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -31,7 +31,11 @@ Resources::Resources() , mainMenuGoldText(0) , heroCursor(0) -, heroCursorBlinkTime(0) { +, heroCursorBlinkTime(0) + +, noEquipmentText(0) + +, shoulderNav(0) { } diff --git a/src/menu/Resources.h b/src/menu/Resources.h index e5241c3..eb61816 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -38,6 +38,10 @@ struct Resources { graphics::Sprite *heroCursor; int heroCursorBlinkTime; + const char *noEquipmentText; + + graphics::Sprite *shoulderNav; + Resources(); }; diff --git a/src/menu/SelectHero.cpp b/src/menu/SelectHero.cpp index 723414f..74e6f88 100644 --- a/src/menu/SelectHero.cpp +++ b/src/menu/SelectHero.cpp @@ -123,10 +123,9 @@ void SelectHero::Render(SDL_Surface *screen) { } void SelectHero::RenderCursor(SDL_Surface *screen) const { - const HeroStatus &status(parent->GetHeroStatus(cursor)); Vector position( 0, Game().state->party[cursor]->BattleSprite()->Height()); - position += status.Position() + parent->StatusOffset(); + position += parent->StatusOffset(cursor); Res().heroCursor->Draw(screen, position); } diff --git a/src/menu/StatusMenu.cpp b/src/menu/StatusMenu.cpp index efc807f..e46a1dd 100644 --- a/src/menu/StatusMenu.cpp +++ b/src/menu/StatusMenu.cpp @@ -7,16 +7,28 @@ #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 "../graphics/Font.h" using app::Input; +using common::Hero; +using common::Item; +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 +59,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 +73,75 @@ 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( + 17 * parent->Res().statusFont->CharWidth(), + 4 * 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)); + RenderEquipment(screen, offset + statsOffset); +} + +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::RenderEquipment(SDL_Surface *screen, const geometry::Vector &offset) const { + const Hero &hero(*parent->Game().state->party[cursor]); + 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::NextHero() { + cursor = (cursor + 1) % parent->Game().state->partySize; +} + +void StatusMenu::PreviousHero() { + cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize; } } diff --git a/src/menu/StatusMenu.h b/src/menu/StatusMenu.h index 465c7c4..4330b99 100644 --- a/src/menu/StatusMenu.h +++ b/src/menu/StatusMenu.h @@ -10,6 +10,8 @@ #include "fwd.h" #include "../app/State.h" +#include "../common/fwd.h" +#include "../geometry/Vector.h" namespace menu { @@ -17,13 +19,17 @@ class StatusMenu : public app::State { public: - explicit StatusMenu(PartyMenu *parent); + StatusMenu(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); @@ -32,8 +38,16 @@ private: virtual void OnResize(int width, int height); + void NextHero(); + void PreviousHero(); + + void RenderStatus(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderEquipment(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderEquipmentLine(const common::Item *, SDL_Surface *screen, const geometry::Vector &position) const; + private: PartyMenu *parent; + int cursor; }; diff --git a/test-data/shoulder-nav.png b/test-data/shoulder-nav.png new file mode 100644 index 0000000..54edbe6 Binary files /dev/null and b/test-data/shoulder-nav.png differ