]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/HeroTag.cpp
removed stupid file headers that eclipse put in
[l2e.git] / src / battle / HeroTag.cpp
index 851e88ed07f10d32e4da792364efc0ede7426cd4..7c8769af048986f2d7f8dcd57ee0cc8415c85cb7 100644 (file)
@@ -1,57 +1,96 @@
-/*
- * HeroTag.cpp
- *
- *  Created on: Aug 6, 2012
- *      Author: holy
- */
-
 #include "HeroTag.h"
 
+#include "AttackChoice.h"
+#include "BattleState.h"
 #include "Hero.h"
-#include "../geometry/operators.h"
+#include "Resources.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 {
+const graphics::Sprite *HeroTag::HeroSprite() const {
+       return battle->HeroAt(index).Sprite();
+}
+
+void HeroTag::Render(SDL_Surface *screen, int width, int height, const Vector<int> &position, bool active) const {
+       const Resources &r(battle->Res());
+
        // frame
-       Vector<int> frameOffset;
-       if (active) {
-               activeFrame->Draw(screen, position, width, height);
-               frameOffset = Vector<int>(activeFrame->BorderWidth(), activeFrame->BorderHeight());
-       } else {
-               frame->Draw(screen, position, width, height);
-               frameOffset = Vector<int>(frame->BorderWidth(), frame->BorderHeight());
-       }
+       const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame);
+       Vector<int> frameOffset(frame->BorderSize());
+       Vector<int> alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0);
+       frame->Draw(screen, position, width, height);
 
-       int yOffset((height - hero->Sprite()->Height()) / 2);
+       const Hero &hero(battle->HeroAt(index));
 
        // gauges
        // NOTE: assuming frame border is unit size until charsets are impemented
-       int gaugeX((align == LEFT ? 10 : 6) * frameOffset.X());
+       int gaugeX(((index % 2) ? 10 : 6) * r.heroTagFont->CharWidth());
        // 4 units reserved for hero, gaugeX already includes frame offset
-       int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * frameOffset.X());
+       int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * r.heroTagFont->CharWidth());
        // health gauge, second line
-       Vector<int> healthGaugeOffset(gaugeX, 2 * frameOffset.Y());
-       healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(256));
+       Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + r.heroTagFont->CharHeight());
+       r.healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
        // mana gauge, third line
-       Vector<int> manaGaugeOffset(gaugeX, 3 * frameOffset.Y());
-       manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(256));
+       Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
+       r.manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
        // ikari gauge, fourth line
-       Vector<int> ikariGaugeOffset(gaugeX, 4 * frameOffset.Y());
-       ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(256));
+       Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
+       r.ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
+
+       // labels
+       int labelX(((index % 2) ? 5 : 1) * r.heroTagFont->CharWidth());
+       // level
+       Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
+       r.heroTagLabels->Draw(screen, position + levelLabelOffset, r.levelLabelCol, r.levelLabelRow);
+       // hp
+       Vector<int> healthLabelOffset(labelX, frameOffset.Y() + r.heroTagFont->CharHeight());
+       r.heroTagLabels->Draw(screen, position + healthLabelOffset, r.healthLabelCol, r.healthLabelRow);
+       // mp
+       Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
+       r.heroTagLabels->Draw(screen, position + manaLabelOffset, r.manaLabelCol, r.manaLabelRow);
+       // cm
+       Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
+       r.heroTagLabels->Draw(screen, position + moveLabelOffset, r.moveLabelCol, r.moveLabelRow);
+       // ip
+       Vector<int> ikariLabelOffset(labelX + 3 * r.heroTagFont->CharWidth(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
+       r.heroTagLabels->Draw(screen, position + ikariLabelOffset, r.ikariLabelCol, r.ikariLabelRow);
+
+       // numbers
+       // level
+       Vector<int> levelNumberOffset(gaugeX + r.heroTagLabels->Width(), levelLabelOffset.Y());
+       r.heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
+       // health
+       Vector<int> healthNumberOffset(labelX + r.heroTagLabels->Width(), healthLabelOffset.Y());
+       r.heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
+       //mana
+       Vector<int> manaNumberOffset(labelX + r.heroTagLabels->Width(), manaLabelOffset.Y());
+       r.heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
+
+       // name
+       r.normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
+
+       // attack icon
+       if (battle->HeroAt(index).GetAttackChoice().GetType() != AttackChoice::UNDECIDED) {
+               Vector<int> attackIconOffset(labelX + r.heroTagLabels->Width(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
+               r.attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->HeroAt(index).GetAttackChoice().GetType());
+       }
 
        // hero
-       Vector<int> heroOffset(
-                       (align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset,
-                       yOffset);
-       hero->Sprite()->Draw(screen, position + heroOffset, 0, hero->Health() > 0 ? 0 : 2);
+       HeroSprite()->DrawCenter(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2);
+}
+
+Vector<int> HeroTag::HeroOffset() const {
+       return Vector<int>(
+                       ((index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth()) + HeroSprite()->Width() / 2,
+                       battle->Res().normalFont->CharWidth() + HeroSprite()->Height() / 2);
 }
 
 }