]> git.localhorst.tv Git - l2e.git/blob - src/battle/HeroTag.cpp
write hero's name on tag
[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 "Hero.h"
11 #include "Resources.h"
12 #include "../geometry/operators.h"
13 #include "../geometry/Vector.h"
14 #include "../graphics/Font.h"
15 #include "../graphics/Frame.h"
16 #include "../graphics/Gauge.h"
17 #include "../graphics/Sprite.h"
18
19 using geometry::Point;
20 using geometry::Vector;
21 using graphics::Frame;
22
23 namespace battle {
24
25 void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
26         // frame
27         const Frame *frame(active ? res->activeHeroTagFrame : res->heroTagFrame);
28         Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
29         Vector<int> alignOffset(align == LEFT ? 4 * res->heroTagFont->CharWidth() : 0, 0);
30         frame->Draw(screen, position, width, height);
31
32         int yOffset((height - hero->Sprite()->Height()) / 2);
33
34         // gauges
35         // NOTE: assuming frame border is unit size until charsets are impemented
36         int gaugeX((align == LEFT ? 10 : 6) * res->heroTagFont->CharWidth());
37         // 4 units reserved for hero, gaugeX already includes frame offset
38         int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * res->heroTagFont->CharWidth());
39         // health gauge, second line
40         Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + res->heroTagFont->CharHeight());
41         res->healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth));
42         // mana gauge, third line
43         Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
44         res->manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth));
45         // ikari gauge, fourth line
46         Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
47         res->ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth));
48
49         // labels
50         int labelX((align == LEFT ? 5 : 1) * res->heroTagFont->CharWidth());
51         // level
52         Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
53         res->heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0);
54         // hp
55         Vector<int> healthLabelOffset(labelX, frameOffset.Y() + res->heroTagFont->CharHeight());
56         res->heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1);
57         // mp
58         Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
59         res->heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2);
60         // cm
61         Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
62         res->heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3);
63         // ip
64         Vector<int> ikariLabelOffset(labelX + 3 * res->heroTagFont->CharWidth(), frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
65         res->heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4);
66
67         // numbers
68         // level
69         Vector<int> levelNumberOffset(gaugeX + res->heroTagLabels->Width(), levelLabelOffset.Y());
70         res->heroTagFont->DrawNumber(hero->Level(), screen, position + levelNumberOffset, 2);
71         // health
72         Vector<int> healthNumberOffset(labelX + res->heroTagLabels->Width(), healthLabelOffset.Y());
73         res->heroTagFont->DrawNumber(hero->Health(), screen, position + healthNumberOffset, 3);
74         //mana
75         Vector<int> manaNumberOffset(labelX + res->heroTagLabels->Width(), manaLabelOffset.Y());
76         res->heroTagFont->DrawNumber(hero->Mana(), screen, position + manaNumberOffset, 3);
77
78         // name
79         res->normalFont->DrawString(hero->Name(), screen, position + frameOffset + alignOffset, 5);
80
81         // hero
82         Vector<int> heroOffset(
83                         (align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset,
84                         yOffset);
85         hero->Sprite()->Draw(screen, position + heroOffset, 0, hero->Health() > 0 ? 0 : 2);
86 }
87
88 }