]> git.localhorst.tv Git - l2e.git/blob - src/battle/HeroTag.cpp
7c8769af048986f2d7f8dcd57ee0cc8415c85cb7
[l2e.git] / src / battle / HeroTag.cpp
1 #include "HeroTag.h"
2
3 #include "AttackChoice.h"
4 #include "BattleState.h"
5 #include "Hero.h"
6 #include "Resources.h"
7 #include "../geometry/Vector.h"
8 #include "../graphics/Font.h"
9 #include "../graphics/Frame.h"
10 #include "../graphics/Gauge.h"
11 #include "../graphics/Sprite.h"
12
13 using geometry::Vector;
14 using graphics::Frame;
15
16 namespace battle {
17
18 const graphics::Sprite *HeroTag::HeroSprite() const {
19         return battle->HeroAt(index).Sprite();
20 }
21
22 void HeroTag::Render(SDL_Surface *screen, int width, int height, const Vector<int> &position, bool active) const {
23         const Resources &r(battle->Res());
24
25         // frame
26         const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame);
27         Vector<int> frameOffset(frame->BorderSize());
28         Vector<int> alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0);
29         frame->Draw(screen, position, width, height);
30
31         const Hero &hero(battle->HeroAt(index));
32
33         // gauges
34         // NOTE: assuming frame border is unit size until charsets are impemented
35         int gaugeX(((index % 2) ? 10 : 6) * r.heroTagFont->CharWidth());
36         // 4 units reserved for hero, gaugeX already includes frame offset
37         int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * r.heroTagFont->CharWidth());
38         // health gauge, second line
39         Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + r.heroTagFont->CharHeight());
40         r.healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
41         // mana gauge, third line
42         Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
43         r.manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
44         // ikari gauge, fourth line
45         Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
46         r.ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
47
48         // labels
49         int labelX(((index % 2) ? 5 : 1) * r.heroTagFont->CharWidth());
50         // level
51         Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
52         r.heroTagLabels->Draw(screen, position + levelLabelOffset, r.levelLabelCol, r.levelLabelRow);
53         // hp
54         Vector<int> healthLabelOffset(labelX, frameOffset.Y() + r.heroTagFont->CharHeight());
55         r.heroTagLabels->Draw(screen, position + healthLabelOffset, r.healthLabelCol, r.healthLabelRow);
56         // mp
57         Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
58         r.heroTagLabels->Draw(screen, position + manaLabelOffset, r.manaLabelCol, r.manaLabelRow);
59         // cm
60         Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
61         r.heroTagLabels->Draw(screen, position + moveLabelOffset, r.moveLabelCol, r.moveLabelRow);
62         // ip
63         Vector<int> ikariLabelOffset(labelX + 3 * r.heroTagFont->CharWidth(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
64         r.heroTagLabels->Draw(screen, position + ikariLabelOffset, r.ikariLabelCol, r.ikariLabelRow);
65
66         // numbers
67         // level
68         Vector<int> levelNumberOffset(gaugeX + r.heroTagLabels->Width(), levelLabelOffset.Y());
69         r.heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
70         // health
71         Vector<int> healthNumberOffset(labelX + r.heroTagLabels->Width(), healthLabelOffset.Y());
72         r.heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
73         //mana
74         Vector<int> manaNumberOffset(labelX + r.heroTagLabels->Width(), manaLabelOffset.Y());
75         r.heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
76
77         // name
78         r.normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
79
80         // attack icon
81         if (battle->HeroAt(index).GetAttackChoice().GetType() != AttackChoice::UNDECIDED) {
82                 Vector<int> attackIconOffset(labelX + r.heroTagLabels->Width(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
83                 r.attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->HeroAt(index).GetAttackChoice().GetType());
84         }
85
86         // hero
87         HeroSprite()->DrawCenter(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2);
88 }
89
90 Vector<int> HeroTag::HeroOffset() const {
91         return Vector<int>(
92                         ((index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth()) + HeroSprite()->Width() / 2,
93                         battle->Res().normalFont->CharWidth() + HeroSprite()->Height() / 2);
94 }
95
96 }