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 {
33 const Frame *frame(active ? battle->Res().activeHeroTagFrame : battle->Res().heroTagFrame);
34 Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
35 Vector<int> alignOffset((index % 2) ? 4 * battle->Res().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) * battle->Res().heroTagFont->CharWidth());
43 // 4 units reserved for hero, gaugeX already includes frame offset
44 int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * battle->Res().heroTagFont->CharWidth());
45 // health gauge, second line
46 Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + battle->Res().heroTagFont->CharHeight());
47 battle->Res().healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
48 // mana gauge, third line
49 Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * battle->Res().heroTagFont->CharHeight());
50 battle->Res().manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
51 // ikari gauge, fourth line
52 Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
53 battle->Res().ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
56 int labelX(((index % 2) ? 5 : 1) * battle->Res().heroTagFont->CharWidth());
58 Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
59 battle->Res().heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0);
61 Vector<int> healthLabelOffset(labelX, frameOffset.Y() + battle->Res().heroTagFont->CharHeight());
62 battle->Res().heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1);
64 Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * battle->Res().heroTagFont->CharHeight());
65 battle->Res().heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2);
67 Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
68 battle->Res().heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3);
70 Vector<int> ikariLabelOffset(labelX + 3 * battle->Res().heroTagFont->CharWidth(), frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
71 battle->Res().heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4);
75 Vector<int> levelNumberOffset(gaugeX + battle->Res().heroTagLabels->Width(), levelLabelOffset.Y());
76 battle->Res().heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
78 Vector<int> healthNumberOffset(labelX + battle->Res().heroTagLabels->Width(), healthLabelOffset.Y());
79 battle->Res().heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
81 Vector<int> manaNumberOffset(labelX + battle->Res().heroTagLabels->Width(), manaLabelOffset.Y());
82 battle->Res().heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
85 battle->Res().normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
88 if (battle->AttackChoiceAt(index).GetType() != AttackChoice::UNDECIDED) {
89 Vector<int> attackIconOffset(labelX + battle->Res().heroTagLabels->Width(), frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
90 battle->Res().attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->AttackChoiceAt(index).GetType());
94 HeroSprite()->Draw(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(),
100 battle->Res().normalFont->CharWidth());