4 * Created on: Aug 6, 2012
10 #include "AttackChoice.h"
11 #include "BattleState.h"
13 #include "Resources.h"
14 #include "../geometry/operators.h"
15 #include "../geometry/Vector.h"
16 #include "../graphics/Font.h"
17 #include "../graphics/Frame.h"
18 #include "../graphics/Gauge.h"
19 #include "../graphics/Sprite.h"
21 using geometry::Point;
22 using geometry::Vector;
23 using graphics::Frame;
27 const graphics::Sprite *HeroTag::HeroSprite() const {
28 return battle->HeroAt(index).Sprite();
31 void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
32 const Resources &r(battle->Res());
35 const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame);
36 Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
37 Vector<int> alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0);
38 frame->Draw(screen, position, width, height);
40 const Hero &hero(battle->HeroAt(index));
43 // NOTE: assuming frame border is unit size until charsets are impemented
44 int gaugeX(((index % 2) ? 10 : 6) * r.heroTagFont->CharWidth());
45 // 4 units reserved for hero, gaugeX already includes frame offset
46 int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * r.heroTagFont->CharWidth());
47 // health gauge, second line
48 Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + r.heroTagFont->CharHeight());
49 r.healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
50 // mana gauge, third line
51 Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
52 r.manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
53 // ikari gauge, fourth line
54 Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
55 r.ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
58 int labelX(((index % 2) ? 5 : 1) * r.heroTagFont->CharWidth());
60 Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
61 r.heroTagLabels->Draw(screen, position + levelLabelOffset, r.levelLabelCol, r.levelLabelRow);
63 Vector<int> healthLabelOffset(labelX, frameOffset.Y() + r.heroTagFont->CharHeight());
64 r.heroTagLabels->Draw(screen, position + healthLabelOffset, r.healthLabelCol, r.healthLabelRow);
66 Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
67 r.heroTagLabels->Draw(screen, position + manaLabelOffset, r.manaLabelCol, r.manaLabelRow);
69 Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
70 r.heroTagLabels->Draw(screen, position + moveLabelOffset, r.moveLabelCol, r.moveLabelRow);
72 Vector<int> ikariLabelOffset(labelX + 3 * r.heroTagFont->CharWidth(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
73 r.heroTagLabels->Draw(screen, position + ikariLabelOffset, r.ikariLabelCol, r.ikariLabelRow);
77 Vector<int> levelNumberOffset(gaugeX + r.heroTagLabels->Width(), levelLabelOffset.Y());
78 r.heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
80 Vector<int> healthNumberOffset(labelX + r.heroTagLabels->Width(), healthLabelOffset.Y());
81 r.heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
83 Vector<int> manaNumberOffset(labelX + r.heroTagLabels->Width(), manaLabelOffset.Y());
84 r.heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
87 r.normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
90 if (battle->AttackChoiceAt(index).GetType() != AttackChoice::UNDECIDED) {
91 Vector<int> attackIconOffset(labelX + r.heroTagLabels->Width(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
92 r.attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->AttackChoiceAt(index).GetType());
96 HeroSprite()->Draw(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2);
99 Vector<int> HeroTag::HeroOffset() const {
101 (index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth(),
102 battle->Res().normalFont->CharWidth());