]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/HeroTag.cpp
added attack choice icons
[l2e.git] / src / battle / HeroTag.cpp
index d67368ff9b98bf4d0d097e97c03633b0416993c1..96dedd9269e836037804c4d1a0c822375ca20763 100644 (file)
@@ -7,39 +7,89 @@
 
 #include "HeroTag.h"
 
+#include "AttackChoice.h"
 #include "Hero.h"
+#include "Resources.h"
 #include "../geometry/operators.h"
 #include "../geometry/Vector.h"
+#include "../graphics/Font.h"
+#include "../graphics/Frame.h"
+#include "../graphics/Gauge.h"
 #include "../graphics/Sprite.h"
 
 using geometry::Point;
 using geometry::Vector;
+using graphics::Frame;
 
 namespace battle {
 
 void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
-       SDL_Rect destRect;
-       destRect.x = position.X();
-       destRect.y = position.Y();
-       destRect.w = width;
-       destRect.h = height;
-
-       destRect.x += 1;
-       destRect.y += 1;
-       destRect.w -= 2;
-       destRect.h -= 2;
-       SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0xFF, active ? 0 : 0xFF, active ? 0 : 0xFF));
-
-       destRect.x += 1;
-       destRect.y += 1;
-       destRect.w -= 2;
-       destRect.h -= 2;
-       SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0, 0, 0));
+       // frame
+       const Frame *frame(active ? res->activeHeroTagFrame : res->heroTagFrame);
+       Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
+       Vector<int> alignOffset(align == LEFT ? 4 * res->heroTagFont->CharWidth() : 0, 0);
+       frame->Draw(screen, position, width, height);
 
+       int yOffset((height - hero->Sprite()->Height()) / 2);
+
+       // gauges
+       // NOTE: assuming frame border is unit size until charsets are impemented
+       int gaugeX((align == LEFT ? 10 : 6) * res->heroTagFont->CharWidth());
+       // 4 units reserved for hero, gaugeX already includes frame offset
+       int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * res->heroTagFont->CharWidth());
+       // health gauge, second line
+       Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + res->heroTagFont->CharHeight());
+       res->healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth));
+       // mana gauge, third line
+       Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
+       res->manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth));
+       // ikari gauge, fourth line
+       Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
+       res->ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth));
+
+       // labels
+       int labelX((align == LEFT ? 5 : 1) * res->heroTagFont->CharWidth());
+       // level
+       Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
+       res->heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0);
+       // hp
+       Vector<int> healthLabelOffset(labelX, frameOffset.Y() + res->heroTagFont->CharHeight());
+       res->heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1);
+       // mp
+       Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
+       res->heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2);
+       // cm
+       Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
+       res->heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3);
+       // ip
+       Vector<int> ikariLabelOffset(labelX + 3 * res->heroTagFont->CharWidth(), frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
+       res->heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4);
+
+       // numbers
+       // level
+       Vector<int> levelNumberOffset(gaugeX + res->heroTagLabels->Width(), levelLabelOffset.Y());
+       res->heroTagFont->DrawNumber(hero->Level(), screen, position + levelNumberOffset, 2);
+       // health
+       Vector<int> healthNumberOffset(labelX + res->heroTagLabels->Width(), healthLabelOffset.Y());
+       res->heroTagFont->DrawNumber(hero->Health(), screen, position + healthNumberOffset, 3);
+       //mana
+       Vector<int> manaNumberOffset(labelX + res->heroTagLabels->Width(), manaLabelOffset.Y());
+       res->heroTagFont->DrawNumber(hero->Mana(), screen, position + manaNumberOffset, 3);
+
+       // name
+       res->normalFont->DrawString(hero->Name(), screen, position + frameOffset + alignOffset, 5);
+
+       // attack icon
+       if (choice->GetType() != AttackChoice::UNDECIDED) {
+               Vector<int> attackIconOffset(labelX + res->heroTagLabels->Width(), frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
+               res->attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, choice->GetType());
+       }
+
+       // hero
        Vector<int> heroOffset(
-                       (align == LEFT) ? 3 : width - hero->Sprite()->Width() - 3,
-                       height - hero->Sprite()->Height() - 3);
-       hero->Sprite()->Draw(screen, position + heroOffset);
+                       (align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset,
+                       yOffset);
+       hero->Sprite()->Draw(screen, position + heroOffset, 0, hero->Health() > 0 ? 0 : 2);
 }
 
 }