From 57a75f13e98f4b5d311c2d3b9d9ff637120c5ee2 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 21 Oct 2012 19:09:39 +0200 Subject: [PATCH] added hero status tags in party menu --- Debug/src/menu/subdir.mk | 3 ++ Release/src/menu/subdir.mk | 3 ++ src/common/Hero.h | 1 + src/main.cpp | 5 +++ src/menu/HeroStatus.cpp | 82 ++++++++++++++++++++++++++++++++++++ src/menu/HeroStatus.h | 45 ++++++++++++++++++++ src/menu/PartyMenu.cpp | 17 +++++++- src/menu/PartyMenu.h | 9 +++- src/menu/Resources.h | 4 ++ src/menu/fwd.h | 1 + test-data/normal-font.png | Bin 1258 -> 1409 bytes test-data/status-labels.png | Bin 0 -> 283 bytes 12 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 src/menu/HeroStatus.cpp create mode 100644 src/menu/HeroStatus.h create mode 100644 test-data/status-labels.png diff --git a/Debug/src/menu/subdir.mk b/Debug/src/menu/subdir.mk index cdf7f21..15d3746 100644 --- a/Debug/src/menu/subdir.mk +++ b/Debug/src/menu/subdir.mk @@ -4,14 +4,17 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/menu/HeroStatus.cpp \ ../src/menu/PartyMenu.cpp \ ../src/menu/Resources.cpp OBJS += \ +./src/menu/HeroStatus.o \ ./src/menu/PartyMenu.o \ ./src/menu/Resources.o CPP_DEPS += \ +./src/menu/HeroStatus.d \ ./src/menu/PartyMenu.d \ ./src/menu/Resources.d diff --git a/Release/src/menu/subdir.mk b/Release/src/menu/subdir.mk index a289eae..a0ea3ff 100644 --- a/Release/src/menu/subdir.mk +++ b/Release/src/menu/subdir.mk @@ -4,14 +4,17 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/menu/HeroStatus.cpp \ ../src/menu/PartyMenu.cpp \ ../src/menu/Resources.cpp OBJS += \ +./src/menu/HeroStatus.o \ ./src/menu/PartyMenu.o \ ./src/menu/Resources.o CPP_DEPS += \ +./src/menu/HeroStatus.d \ ./src/menu/PartyMenu.d \ ./src/menu/Resources.d diff --git a/src/common/Hero.h b/src/common/Hero.h index ca4651c..b12e8f5 100644 --- a/src/common/Hero.h +++ b/src/common/Hero.h @@ -72,6 +72,7 @@ public: const std::vector &Spells() const { return spells; } graphics::Sprite *BattleSprite() { return battleSprite; } + const graphics::Sprite *BattleSprite() const { return battleSprite; } graphics::Animation *MeleeAnimation() { return meleeAnimation; } graphics::Animation *AttackAnimation() { return attackAnimation; } graphics::Animation *SpellAnimation() { return spellAnimation; } diff --git a/src/main.cpp b/src/main.cpp index 73b4274..b06b5c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -279,6 +279,11 @@ int main(int argc, char **argv) { menubg.SetSize(Vector(64, 64)); menuResources.menubg = &menubg; + menuResources.normalFont = gameConfig.battleResources->normalFont; + + graphics::Sprite statusLabels(IMG_Load("test-data/status-labels.png"), 32, 16); + menuResources.statusLabels = &statusLabels; + InitScreen screen(width, height); app::State *state(0); diff --git a/src/menu/HeroStatus.cpp b/src/menu/HeroStatus.cpp new file mode 100644 index 0000000..e84327e --- /dev/null +++ b/src/menu/HeroStatus.cpp @@ -0,0 +1,82 @@ +/* + * HeroStatus.cpp + * + * Created on: Oct 21, 2012 + * Author: holy + */ + +#include "HeroStatus.h" + +#include "Resources.h" +#include "../common/Hero.h" +#include "../graphics/Font.h" +#include "../graphics/Sprite.h" + +using geometry::Vector; + +namespace menu { + +HeroStatus::HeroStatus() +: res(0) +, hero(0) { + +} + +HeroStatus::~HeroStatus() { + +} + + +int HeroStatus::Width() const { + return hero->BattleSprite()->Width() + res->normalFont->CharWidth() * 10; +} + +int HeroStatus::Height() const { + return hero->BattleSprite()->Height(); +} + + +void HeroStatus::Render(SDL_Surface *screen, const Vector &offset) const { + if (!hero) return; + + hero->BattleSprite()->Draw(screen, position + offset, 0, 0); + + // for some reason, fonts are shifted by one pixel in the original + Vector nameOffset( + hero->BattleSprite()->Width(), + res->normalFont->CharHeight() * 7 / 8); + nameOffset += position + offset; + res->normalFont->DrawString(hero->Name(), screen, nameOffset, 5); + + Vector levelLabelOffset(nameOffset.X() + 6 * res->normalFont->CharWidth(), nameOffset.Y()); + res->statusLabels->Draw(screen, levelLabelOffset, 0, 0); + + Vector levelOffset(levelLabelOffset.X() + 2 * res->normalFont->CharWidth(), levelLabelOffset.Y()); + res->normalFont->DrawNumber(hero->Level(), screen, levelOffset, 2); + + Vector healthLabelOffset(nameOffset.X(), nameOffset.Y() + res->normalFont->CharHeight()); + res->statusLabels->Draw(screen, healthLabelOffset, 0, 1); + + Vector healthOffset(nameOffset.X() + 3 * res->normalFont->CharWidth(), nameOffset.Y() + res->normalFont->CharHeight()); + res->normalFont->DrawNumber(hero->Health(), screen, healthOffset, 3); + + Vector healthSeparatorOffset(healthOffset.X() + 3 * res->normalFont->CharWidth(), healthOffset.Y()); + res->normalFont->DrawChar('/', screen, healthSeparatorOffset); + + Vector maxHealthOffset(healthSeparatorOffset.X() + res->normalFont->CharWidth(), healthOffset.Y()); + res->normalFont->DrawNumber(hero->MaxHealth(), screen, maxHealthOffset, 3); + + Vector manaLabelOffset(healthLabelOffset.X(), healthLabelOffset.Y() + res->normalFont->CharHeight()); + res->statusLabels->Draw(screen, manaLabelOffset, 0, 2); + + Vector manaOffset(healthOffset.X(), healthOffset.Y() + res->normalFont->CharHeight()); + res->normalFont->DrawNumber(hero->Mana(), screen, manaOffset, 3); + + Vector manaSeparatorOffset(healthSeparatorOffset.X(), manaOffset.Y()); + res->normalFont->DrawChar('/', screen, manaSeparatorOffset); + + Vector maxManaOffset(maxHealthOffset.X(), manaOffset.Y()); + res->normalFont->DrawNumber(hero->MaxMana(), screen, maxManaOffset, 3); +} + +} diff --git a/src/menu/HeroStatus.h b/src/menu/HeroStatus.h new file mode 100644 index 0000000..1b88da2 --- /dev/null +++ b/src/menu/HeroStatus.h @@ -0,0 +1,45 @@ +/* + * HeroStatus.h + * + * Created on: Oct 21, 2012 + * Author: holy + */ + +#ifndef MENU_HEROSTATUS_H_ +#define MENU_HEROSTATUS_H_ + +#include "fwd.h" +#include "../common/fwd.h" +#include "../geometry/Vector.h" + +#include + +namespace menu { + +class HeroStatus { + +public: + HeroStatus(); + ~HeroStatus(); + +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()); } + + void Render(SDL_Surface *screen, const geometry::Vector &offset) const; + +private: + const Resources *res; + const common::Hero *hero; + geometry::Vector position; + +}; + +} + +#endif /* MENU_HEROSTATUS_H_ */ diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 1243df9..f230358 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -11,7 +11,9 @@ #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/Texture.h" using app::Input; @@ -22,7 +24,13 @@ namespace menu { PartyMenu::PartyMenu(GameConfig *game) : game(game) { - + for (int i(0); i < 4; ++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())); } PartyMenu::~PartyMenu() { @@ -65,6 +73,13 @@ void PartyMenu::UpdateWorld(float deltaT) { void PartyMenu::Render(SDL_Surface *screen) { Res().menubg->Render(screen, Vector(), Vector(screen->w, screen->h)); + RenderHeros(screen, Vector()); +} + +void PartyMenu::RenderHeros(SDL_Surface *screen, const geometry::Vector &offset) const { + for (int i(0); i < 4; ++i) { + status[i].Render(screen, offset); + } } diff --git a/src/menu/PartyMenu.h b/src/menu/PartyMenu.h index ee84239..2172bfc 100644 --- a/src/menu/PartyMenu.h +++ b/src/menu/PartyMenu.h @@ -8,9 +8,11 @@ #ifndef MENU_PARTYMENU_H_ #define MENU_PARTYMENU_H_ -#include "Resources.h" +#include "fwd.h" +#include "HeroStatus.h" #include "../app/State.h" -#include "../common/GameConfig.h" +#include "../common/fwd.h" +#include "../geometry/Vector.h" namespace menu { @@ -38,7 +40,10 @@ private: virtual void OnResize(int width, int height); + void RenderHeros(SDL_Surface *screen, const geometry::Vector &offset) const; + private: + HeroStatus status[4]; common::GameConfig *game; }; diff --git a/src/menu/Resources.h b/src/menu/Resources.h index 8969eb8..bc6f204 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -16,6 +16,10 @@ struct Resources { graphics::Texture *menubg; + graphics::Font *normalFont; + + graphics::Sprite *statusLabels; + Resources(); }; diff --git a/src/menu/fwd.h b/src/menu/fwd.h index 642eae3..8885525 100644 --- a/src/menu/fwd.h +++ b/src/menu/fwd.h @@ -10,6 +10,7 @@ namespace menu { +class HeroStatus; class PartyMenu; struct Resources; diff --git a/test-data/normal-font.png b/test-data/normal-font.png index 8a1532b71e4b679183ffd0079da7f2890df107b4..93e82cb0cf5023a0b9f084120f5b5b21403609d2 100644 GIT binary patch delta 1391 zcmW+$eKga182=8F#=T38bPILdPD?3rbj$0A>#d_mBO;N=ODivV8(UX(qcX3Pa}v?2 zYi$(6^0sct&7y0u-F}X^-Lqz94YOu8{qB#?Ip2St=X{^%d_K?Td1lsMH7>QGp#A*4 zJwvl0c`dUX=YYHMVbqn!p4w5my)1MGA+{{^>>U1Q4DA7ii|I3@85C_RBFx&D++fE( zKA4flmVQ+@Mz)T-aWhE6l%SyUKMtiUwOuv=^uWz=%!M@ldq)~WF*K}pKa1JrCZ5BYRY-0Y(b1^`fycRZjbB43>zk)I=-@krGWRn7Tl$?(_+|_0t*hTtn)QcvB>sxgki6iWd z0`*{4%DGFVe;8~ycj^hA@9{$Hv*q>TRtx~>mV(JgB2iR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Ce*wNuF002ovPDHLkV1m$< BUjG09 diff --git a/test-data/status-labels.png b/test-data/status-labels.png new file mode 100644 index 0000000000000000000000000000000000000000..93fcebc3ba10f9ae11769c3ff1dfe0df7fc9081e GIT binary patch literal 283 zcmV+$0p$LPP)K9}QSqXlWxU7@h#@`HXTN-4Vk(kVw3gIp6B)6ii3v zPwXv79L_tSJ0TfvZP$MJ6yx3lUR8VJVWyy18Adx}O+ktf?;`rvF0iza7ZJ`qa9QRz z4$u2(mAjUo{%%3y@a_Sr#OgrQuKjR#fv&{M@$cUQx^izPEI*hjD82LQMQ>cLW1N?; hrCLk{3RJOJLlltU~`ynp}z002ovPDHLkV1lm!ct8LE literal 0 HcmV?d00001 -- 2.39.2