From: Daniel Karbach Date: Sun, 21 Oct 2012 17:09:39 +0000 (+0200) Subject: added hero status tags in party menu X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=57a75f13e98f4b5d311c2d3b9d9ff637120c5ee2;p=l2e.git added hero status tags in party menu --- 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 8a1532b..93e82cb 100644 Binary files a/test-data/normal-font.png and b/test-data/normal-font.png differ diff --git a/test-data/status-labels.png b/test-data/status-labels.png new file mode 100644 index 0000000..93fcebc Binary files /dev/null and b/test-data/status-labels.png differ