From 317100aa5878503dad034a1e1eb734d1e952f842 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 23 Oct 2012 23:04:27 +0200 Subject: [PATCH] added hero's stats in status screen --- src/main.cpp | 8 ++++++++ src/menu/Resources.cpp | 10 +++++++++- src/menu/Resources.h | 8 ++++++++ src/menu/StatusMenu.cpp | 44 +++++++++++++++++++++++++++++++++++++++-- src/menu/StatusMenu.h | 2 ++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 93727fd..1587d60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -328,6 +328,14 @@ int main(int argc, char **argv) { graphics::Sprite shoulderNav(IMG_Load("test-data/shoulder-nav.png"), 160, 16); menuResources.shoulderNav = &shoulderNav; + menuResources.atpLabel = "ATP"; + menuResources.dfpLabel = "DFP"; + menuResources.strLabel = "STR"; + menuResources.aglLabel = "AGL"; + menuResources.intLabel = "INT"; + menuResources.gutLabel = "GUT"; + menuResources.mgrLabel = "MGR"; + InitScreen screen(width, height); app::State *state(0); diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 166fbf7..79e5951 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -35,7 +35,15 @@ Resources::Resources() , noEquipmentText(0) -, shoulderNav(0) { +, shoulderNav(0) + +, atpLabel(0) +, dfpLabel(0) +, strLabel(0) +, aglLabel(0) +, intLabel(0) +, gutLabel(0) +, mgrLabel(0) { } diff --git a/src/menu/Resources.h b/src/menu/Resources.h index eb61816..0b3b435 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -42,6 +42,14 @@ struct Resources { graphics::Sprite *shoulderNav; + const char *atpLabel; + const char *dfpLabel; + const char *strLabel; + const char *aglLabel; + const char *intLabel; + const char *gutLabel; + const char *mgrLabel; + Resources(); }; diff --git a/src/menu/StatusMenu.cpp b/src/menu/StatusMenu.cpp index e46a1dd..c56e796 100644 --- a/src/menu/StatusMenu.cpp +++ b/src/menu/StatusMenu.cpp @@ -16,11 +16,13 @@ #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; @@ -78,13 +80,17 @@ void StatusMenu::Render(SDL_Surface *screen) { 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); parent->RenderBackground(screen); parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset); RenderStatus(screen, offset + parent->StatusOffset(0)); - RenderEquipment(screen, offset + statsOffset); + RenderStats(screen, offset + statsOffset); + RenderEquipment(screen, offset + equipOffset); } int StatusMenu::Width() const { @@ -99,7 +105,41 @@ void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector &offset) co parent->GetHeroStatus(cursor).Render(screen, offset); } -void StatusMenu::RenderEquipment(SDL_Surface *screen, const geometry::Vector &offset) const { +void StatusMenu::RenderStats(SDL_Surface *screen, const Vector &offset) const { + const Stats &stats(parent->Game().state->party[cursor]->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(*parent->Game().state->party[cursor]); Vector lineBreak(0, 2 * parent->Res().statusFont->CharHeight()); diff --git a/src/menu/StatusMenu.h b/src/menu/StatusMenu.h index 4330b99..61082d4 100644 --- a/src/menu/StatusMenu.h +++ b/src/menu/StatusMenu.h @@ -42,6 +42,8 @@ private: void PreviousHero(); void RenderStatus(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderStats(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const geometry::Vector &position) const; void RenderEquipment(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderEquipmentLine(const common::Item *, SDL_Surface *screen, const geometry::Vector &position) const; -- 2.39.2