X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FHeroStatus.cpp;fp=src%2Fmenu%2FHeroStatus.cpp;h=e84327ebddb8e8718724e90e6169c614d8aa7601;hb=57a75f13e98f4b5d311c2d3b9d9ff637120c5ee2;hp=0000000000000000000000000000000000000000;hpb=e4f678d8cce5408590178bc873fde1754c037d0d;p=l2e.git 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); +} + +}