X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FHeroTag.cpp;h=6212f36a5c87bdadf3b3832df02bef94909ae2e2;hb=62c0a1d0ac98eb51418e4daa59e80b6cc97b522f;hp=33c42db72de3f0b7d270eaace92d9c1f5ad1b47c;hpb=ca31ddeab37eebaa2de5e5b1c94974fac06d418b;p=l2e.git diff --git a/src/battle/HeroTag.cpp b/src/battle/HeroTag.cpp index 33c42db..6212f36 100644 --- a/src/battle/HeroTag.cpp +++ b/src/battle/HeroTag.cpp @@ -7,7 +7,10 @@ #include "HeroTag.h" +#include "AttackChoice.h" +#include "BattleState.h" #include "Hero.h" +#include "Resources.h" #include "../geometry/operators.h" #include "../geometry/Vector.h" #include "../graphics/Font.h" @@ -17,71 +20,84 @@ using geometry::Point; using geometry::Vector; +using graphics::Frame; namespace battle { +const graphics::Sprite *HeroTag::HeroSprite() const { + return battle->HeroAt(index).Sprite(); +} + void HeroTag::Render(SDL_Surface *screen, int width, int height, Point position, bool active) const { // frame - Vector frameOffset; - if (active) { - activeFrame->Draw(screen, position, width, height); - frameOffset = Vector(activeFrame->BorderWidth(), activeFrame->BorderHeight()); - } else { - frame->Draw(screen, position, width, height); - frameOffset = Vector(frame->BorderWidth(), frame->BorderHeight()); - } + const Frame *frame(active ? battle->Res().activeHeroTagFrame : battle->Res().heroTagFrame); + Vector frameOffset(frame->BorderWidth(), frame->BorderHeight()); + Vector alignOffset((index % 2) ? 4 * battle->Res().heroTagFont->CharWidth() : 0, 0); + frame->Draw(screen, position, width, height); - int yOffset((height - hero->Sprite()->Height()) / 2); + const Hero &hero(battle->HeroAt(index)); // gauges // NOTE: assuming frame border is unit size until charsets are impemented - int gaugeX((align == LEFT ? 10 : 6) * font->CharWidth()); + int gaugeX(((index % 2) ? 10 : 6) * battle->Res().heroTagFont->CharWidth()); // 4 units reserved for hero, gaugeX already includes frame offset - int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * font->CharWidth()); + int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * battle->Res().heroTagFont->CharWidth()); // health gauge, second line - Vector healthGaugeOffset(gaugeX, frameOffset.Y() + font->CharHeight()); - healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth)); + Vector healthGaugeOffset(gaugeX, frameOffset.Y() + battle->Res().heroTagFont->CharHeight()); + battle->Res().healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255)); // mana gauge, third line - Vector manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * font->CharHeight()); - manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth)); + Vector manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * battle->Res().heroTagFont->CharHeight()); + battle->Res().manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255)); // ikari gauge, fourth line - Vector ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * font->CharHeight()); - ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth)); + Vector ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight()); + battle->Res().ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255)); // labels - int labelX((align == LEFT ? 5 : 1) * font->CharWidth()); + int labelX(((index % 2) ? 5 : 1) * battle->Res().heroTagFont->CharWidth()); // level Vector levelLabelOffset(gaugeX, frameOffset.Y()); - sprites->Draw(screen, position + levelLabelOffset, 0, 0); + battle->Res().heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0); // hp - Vector healthLabelOffset(labelX, frameOffset.Y() + font->CharHeight()); - sprites->Draw(screen, position + healthLabelOffset, 0, 1); + Vector healthLabelOffset(labelX, frameOffset.Y() + battle->Res().heroTagFont->CharHeight()); + battle->Res().heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1); // mp - Vector manaLabelOffset(labelX, frameOffset.Y() + 2 * font->CharHeight()); - sprites->Draw(screen, position + manaLabelOffset, 0, 2); + Vector manaLabelOffset(labelX, frameOffset.Y() + 2 * battle->Res().heroTagFont->CharHeight()); + battle->Res().heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2); // cm - Vector moveLabelOffset(labelX, frameOffset.Y() + 3 * font->CharHeight()); - sprites->Draw(screen, position + moveLabelOffset, 0, 3); + Vector moveLabelOffset(labelX, frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight()); + battle->Res().heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3); // ip - Vector ikariLabelOffset(labelX + 3 * font->CharWidth(), frameOffset.Y() + 3 * font->CharHeight()); - sprites->Draw(screen, position + ikariLabelOffset, 0, 4); + Vector ikariLabelOffset(labelX + 3 * battle->Res().heroTagFont->CharWidth(), frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight()); + battle->Res().heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4); // numbers // level - Vector levelNumberOffset(gaugeX + sprites->Width(), levelLabelOffset.Y()); - font->DrawNumber(hero->Level(), screen, position + levelNumberOffset, 2); + Vector levelNumberOffset(gaugeX + battle->Res().heroTagLabels->Width(), levelLabelOffset.Y()); + battle->Res().heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2); // health - Vector healthNumberOffset(labelX + sprites->Width(), healthLabelOffset.Y()); - font->DrawNumber(hero->Health(), screen, position + healthNumberOffset, 3); + Vector healthNumberOffset(labelX + battle->Res().heroTagLabels->Width(), healthLabelOffset.Y()); + battle->Res().heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3); //mana - Vector manaNumberOffset(labelX + sprites->Width(), manaLabelOffset.Y()); - font->DrawNumber(hero->Mana(), screen, position + manaNumberOffset, 3); + Vector manaNumberOffset(labelX + battle->Res().heroTagLabels->Width(), manaLabelOffset.Y()); + battle->Res().heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3); + + // name + battle->Res().normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5); + + // attack icon + if (battle->AttackChoiceAt(index).GetType() != AttackChoice::UNDECIDED) { + Vector attackIconOffset(labelX + battle->Res().heroTagLabels->Width(), frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight()); + battle->Res().attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->AttackChoiceAt(index).GetType()); + } // hero - Vector heroOffset( - (align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset, - yOffset); - hero->Sprite()->Draw(screen, position + heroOffset, 0, hero->Health() > 0 ? 0 : 2); + HeroSprite()->Draw(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2); +} + +Vector HeroTag::HeroOffset() const { + return Vector( + (index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth(), + battle->Res().normalFont->CharWidth()); } }