4 * Created on: Aug 6, 2012
10 #include "AttackChoice.h"
11 #include "BattleState.h"
13 #include "Resources.h"
14 #include "../geometry/Vector.h"
15 #include "../graphics/Font.h"
16 #include "../graphics/Frame.h"
17 #include "../graphics/Gauge.h"
18 #include "../graphics/Sprite.h"
20 using geometry::Vector;
21 using graphics::Frame;
25 const graphics::Sprite *HeroTag::HeroSprite() const {
26 return battle->HeroAt(index).Sprite();
29 void HeroTag::Render(SDL_Surface *screen, int width, int height, Vector<int> position, bool active) const {
30 const Resources &r(battle->Res());
33 const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame);
34 Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
35 Vector<int> alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0);
36 frame->Draw(screen, position, width, height);
38 const Hero &hero(battle->HeroAt(index));
41 // NOTE: assuming frame border is unit size until charsets are impemented
42 int gaugeX(((index % 2) ? 10 : 6) * r.heroTagFont->CharWidth());
43 // 4 units reserved for hero, gaugeX already includes frame offset
44 int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * r.heroTagFont->CharWidth());
45 // health gauge, second line
46 Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + r.heroTagFont->CharHeight());
47 r.healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
48 // mana gauge, third line
49 Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
50 r.manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
51 // ikari gauge, fourth line
52 Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
53 r.ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
56 int labelX(((index % 2) ? 5 : 1) * r.heroTagFont->CharWidth());
58 Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
59 r.heroTagLabels->Draw(screen, position + levelLabelOffset, r.levelLabelCol, r.levelLabelRow);
61 Vector<int> healthLabelOffset(labelX, frameOffset.Y() + r.heroTagFont->CharHeight());
62 r.heroTagLabels->Draw(screen, position + healthLabelOffset, r.healthLabelCol, r.healthLabelRow);
64 Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
65 r.heroTagLabels->Draw(screen, position + manaLabelOffset, r.manaLabelCol, r.manaLabelRow);
67 Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
68 r.heroTagLabels->Draw(screen, position + moveLabelOffset, r.moveLabelCol, r.moveLabelRow);
70 Vector<int> ikariLabelOffset(labelX + 3 * r.heroTagFont->CharWidth(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
71 r.heroTagLabels->Draw(screen, position + ikariLabelOffset, r.ikariLabelCol, r.ikariLabelRow);
75 Vector<int> levelNumberOffset(gaugeX + r.heroTagLabels->Width(), levelLabelOffset.Y());
76 r.heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
78 Vector<int> healthNumberOffset(labelX + r.heroTagLabels->Width(), healthLabelOffset.Y());
79 r.heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
81 Vector<int> manaNumberOffset(labelX + r.heroTagLabels->Width(), manaLabelOffset.Y());
82 r.heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
85 r.normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
88 if (battle->HeroAt(index).GetAttackChoice().GetType() != AttackChoice::UNDECIDED) {
89 Vector<int> attackIconOffset(labelX + r.heroTagLabels->Width(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
90 r.attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->HeroAt(index).GetAttackChoice().GetType());
94 HeroSprite()->DrawCenter(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2);
97 Vector<int> HeroTag::HeroOffset() const {
99 ((index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth()) + HeroSprite()->Width() / 2,
100 battle->Res().normalFont->CharWidth() + HeroSprite()->Height() / 2);