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