]> git.localhorst.tv Git - l2e.git/blob - src/battle/HeroTag.cpp
f94581b698a957b04e30e9625f385f5689a787d4
[l2e.git] / src / battle / HeroTag.cpp
1 /*
2  * HeroTag.cpp
3  *
4  *  Created on: Aug 6, 2012
5  *      Author: holy
6  */
7
8 #include "HeroTag.h"
9
10 #include "AttackChoice.h"
11 #include "BattleState.h"
12 #include "Hero.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"
19
20 using geometry::Vector;
21 using graphics::Frame;
22
23 namespace battle {
24
25 const graphics::Sprite *HeroTag::HeroSprite() const {
26         return battle->HeroAt(index).Sprite();
27 }
28
29 void HeroTag::Render(SDL_Surface *screen, int width, int height, const Vector<int> &position, bool active) const {
30         const Resources &r(battle->Res());
31
32         // frame
33         const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame);
34         Vector<int> frameOffset(frame->BorderSize());
35         Vector<int> alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0);
36         frame->Draw(screen, position, width, height);
37
38         const Hero &hero(battle->HeroAt(index));
39
40         // gauges
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));
54
55         // labels
56         int labelX(((index % 2) ? 5 : 1) * r.heroTagFont->CharWidth());
57         // level
58         Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
59         r.heroTagLabels->Draw(screen, position + levelLabelOffset, r.levelLabelCol, r.levelLabelRow);
60         // hp
61         Vector<int> healthLabelOffset(labelX, frameOffset.Y() + r.heroTagFont->CharHeight());
62         r.heroTagLabels->Draw(screen, position + healthLabelOffset, r.healthLabelCol, r.healthLabelRow);
63         // mp
64         Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
65         r.heroTagLabels->Draw(screen, position + manaLabelOffset, r.manaLabelCol, r.manaLabelRow);
66         // cm
67         Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
68         r.heroTagLabels->Draw(screen, position + moveLabelOffset, r.moveLabelCol, r.moveLabelRow);
69         // ip
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);
72
73         // numbers
74         // level
75         Vector<int> levelNumberOffset(gaugeX + r.heroTagLabels->Width(), levelLabelOffset.Y());
76         r.heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
77         // health
78         Vector<int> healthNumberOffset(labelX + r.heroTagLabels->Width(), healthLabelOffset.Y());
79         r.heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
80         //mana
81         Vector<int> manaNumberOffset(labelX + r.heroTagLabels->Width(), manaLabelOffset.Y());
82         r.heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
83
84         // name
85         r.normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
86
87         // attack icon
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());
91         }
92
93         // hero
94         HeroSprite()->DrawCenter(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2);
95 }
96
97 Vector<int> HeroTag::HeroOffset() const {
98         return Vector<int>(
99                         ((index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth()) + HeroSprite()->Width() / 2,
100                         battle->Res().normalFont->CharWidth() + HeroSprite()->Height() / 2);
101 }
102
103 }