]> git.localhorst.tv Git - l2e.git/commitdiff
added prototype for battle's hero tags
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 6 Aug 2012 16:48:23 +0000 (18:48 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 6 Aug 2012 16:48:23 +0000 (18:48 +0200)
A hero tag is the panel in the attack selection screen containing
information about the hero's stats.

Debug/src/battle/subdir.mk
Release/src/battle/subdir.mk
src/battle/AttackTypeMenu.cpp
src/battle/AttackTypeMenu.h
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/HeroTag.cpp [new file with mode: 0644]
src/battle/HeroTag.h [new file with mode: 0644]

index d0073bc4a97075a97a3eca051c07dabc04bd2ce4..0ef38a1b92aefccd8627c8a6907311e2479db677 100644 (file)
@@ -7,6 +7,7 @@ CPP_SRCS += \
 ../src/battle/AttackTypeMenu.cpp \
 ../src/battle/BattleState.cpp \
 ../src/battle/Hero.cpp \
+../src/battle/HeroTag.cpp \
 ../src/battle/Monster.cpp \
 ../src/battle/PartyLayout.cpp 
 
@@ -14,6 +15,7 @@ OBJS += \
 ./src/battle/AttackTypeMenu.o \
 ./src/battle/BattleState.o \
 ./src/battle/Hero.o \
+./src/battle/HeroTag.o \
 ./src/battle/Monster.o \
 ./src/battle/PartyLayout.o 
 
@@ -21,6 +23,7 @@ CPP_DEPS += \
 ./src/battle/AttackTypeMenu.d \
 ./src/battle/BattleState.d \
 ./src/battle/Hero.d \
+./src/battle/HeroTag.d \
 ./src/battle/Monster.d \
 ./src/battle/PartyLayout.d 
 
index d1c5b2fb7e712b2bc02ca25e3584b9d7af66bb0e..e59a859652022563eaf1b08ba2749c3c254adf33 100644 (file)
@@ -7,6 +7,7 @@ CPP_SRCS += \
 ../src/battle/AttackTypeMenu.cpp \
 ../src/battle/BattleState.cpp \
 ../src/battle/Hero.cpp \
+../src/battle/HeroTag.cpp \
 ../src/battle/Monster.cpp \
 ../src/battle/PartyLayout.cpp 
 
@@ -14,6 +15,7 @@ OBJS += \
 ./src/battle/AttackTypeMenu.o \
 ./src/battle/BattleState.o \
 ./src/battle/Hero.o \
+./src/battle/HeroTag.o \
 ./src/battle/Monster.o \
 ./src/battle/PartyLayout.o 
 
@@ -21,6 +23,7 @@ CPP_DEPS += \
 ./src/battle/AttackTypeMenu.d \
 ./src/battle/BattleState.d \
 ./src/battle/Hero.d \
+./src/battle/HeroTag.d \
 ./src/battle/Monster.d \
 ./src/battle/PartyLayout.d 
 
index 2a23a09bb7597415b1b44bc9f8080e8f5ba0255f..b881d8b6f5ee57d5a95e515109bf5e132d9c3148 100644 (file)
@@ -32,18 +32,18 @@ void AttackTypeMenu::ReadInput(const Input &input) {
        }
 }
 
-void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Point<int> &center) {
-       Vector<int> swordOffset(icons->Width() / -2, icons->Height() / -2);
-       Vector<int> magicOffset(swordOffset.X(), swordOffset.Y() - icons->Height());
-       Vector<int> defendOffset(swordOffset.X() + icons->Width(), swordOffset.Y());
-       Vector<int> ikariOffset(swordOffset.X(), swordOffset.Y() + icons->Height());
-       Vector<int> itemOffset(swordOffset.X() - icons->Width(), swordOffset.Y());
-
-       icons->Draw(screen, center + swordOffset, SWORD, (selected == SWORD) ? 1 : 0);
-       icons->Draw(screen, center + magicOffset, MAGIC, (selected == MAGIC) ? 1 : 0);
-       icons->Draw(screen, center + defendOffset, DEFEND, (selected == DEFEND) ? 1 : 0);
-       icons->Draw(screen, center + ikariOffset, IKARI, (selected == IKARI) ? 1 : 0);
-       icons->Draw(screen, center + itemOffset, ITEM, (selected == ITEM) ? 1 : 0);
+void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Point<int> &position) {
+       Vector<int> swordOffset(IconWidth(), IconHeight());
+       Vector<int> magicOffset(IconWidth(), 0);
+       Vector<int> defendOffset(2 * IconWidth(), IconHeight());
+       Vector<int> ikariOffset(IconWidth(), 2 * IconHeight());
+       Vector<int> itemOffset(0, IconHeight());
+
+       icons->Draw(screen, position + swordOffset, SWORD, (selected == SWORD) ? 1 : 0);
+       icons->Draw(screen, position + magicOffset, MAGIC, (selected == MAGIC) ? 1 : 0);
+       icons->Draw(screen, position + defendOffset, DEFEND, (selected == DEFEND) ? 1 : 0);
+       icons->Draw(screen, position + ikariOffset, IKARI, (selected == IKARI) ? 1 : 0);
+       icons->Draw(screen, position + itemOffset, ITEM, (selected == ITEM) ? 1 : 0);
 }
 
 }
index b63ec97e53e55109c6abb2f4ec3f2f3378dd5fc9..08caf7f4160c3e93e4bed77eb4425770af317518 100644 (file)
@@ -9,9 +9,9 @@
 #define BATTLE_ATTACKTYPEMENU_H_
 
 namespace app { class Input; }
-namespace graphics { class Sprite; }
 
 #include "../geometry/Point.h"
+#include "../graphics/Sprite.h"
 
 #include <SDL.h>
 
@@ -35,7 +35,12 @@ public:
 public:
        void ReadInput(const app::Input &);
        Icon Selected() const { return selected; }
-       void Render(SDL_Surface *screen, const geometry::Point<int> &center);
+       void Render(SDL_Surface *screen, const geometry::Point<int> &position);
+
+       int Width() const { return 3 * IconWidth(); }
+       int Height() const { return 3 * IconHeight(); }
+       int IconWidth() const { return icons->Width(); }
+       int IconHeight() const { return icons->Height(); }
 
 private:
        const graphics::Sprite *icons;
index b11f52cc90b4950f73fd76641cc1699420d17bb3..758d9d8224a097d2b0cdd731dfc00dac17117b59 100644 (file)
@@ -47,6 +47,9 @@ void BattleState::Resize(int w, int h) {
 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
        heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
+       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
+               heroTags.push_back(HeroTag(&heroes[i], HeroTag::Alignment((i + 1) % 2)));
+       }
 }
 
 void BattleState::ExitState() {
@@ -70,7 +73,8 @@ void BattleState::Render(SDL_Surface *screen) {
        RenderBackground(screen, offset);
        RenderMonsters(screen, offset);
 //     RenderHeroes(screen, offset);
-       attackTypeMenu.Render(screen, Point<int>(background->w / 2, background->h * 3 / 4));
+       RenderHeroTags(screen, offset);
+       RenderAttackTypeMenu(screen, offset);
 }
 
 void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offset) {
@@ -96,4 +100,27 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
        }
 }
 
+void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
+       int uiHeight(background->h / 2), uiOffset(uiHeight);
+       int tagHeight((uiHeight - attackTypeMenu.IconHeight()) / 2);
+       int tagWidth((background->w - attackTypeMenu.IconWidth()) / 2);
+
+       Point<int> tagPosition[4];
+       tagPosition[0] = Point<int>(0, uiOffset);
+       tagPosition[1] = Point<int>(tagWidth + attackTypeMenu.IconWidth(), uiOffset);
+       tagPosition[2] = Point<int>(0, uiOffset + tagHeight + attackTypeMenu.IconHeight());
+       tagPosition[3] = Point<int>(tagWidth + attackTypeMenu.IconWidth(), uiOffset + tagHeight + attackTypeMenu.IconHeight());
+
+       for (vector<HeroTag>::size_type i(0), end(heroTags.size()); i < end; ++i) {
+               heroTags[i].Render(screen, tagWidth, tagHeight, tagPosition[i] + offset);
+       }
+}
+
+void BattleState::RenderAttackTypeMenu(SDL_Surface *screen, const Vector<int> &offset) {
+       Point<int> position(
+                       (background->w - attackTypeMenu.Width()) / 2,
+                       (background->h * 3 / 4) - (attackTypeMenu.Height() / 2));
+       attackTypeMenu.Render(screen, position + offset);
+}
+
 }
index 9e504ed8c13b04db85168aa5bf7acd2cb672a4e4..8fa7d951ac393bcf5dd5917cc36d2b34f44bbce5 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "AttackTypeMenu.h"
 #include "Hero.h"
+#include "HeroTag.h"
 #include "Monster.h"
 #include "../app/State.h"
 #include "../geometry/Point.h"
@@ -54,6 +55,8 @@ private:
        void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
+       void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
+       void RenderAttackTypeMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
        SDL_Surface *background;
@@ -64,6 +67,7 @@ private:
        std::vector<geometry::Point<int> > heroesPositions;
        std::vector<Monster> monsters;
        std::vector<Hero> heroes;
+       std::vector<HeroTag> heroTags;
 
 };
 
diff --git a/src/battle/HeroTag.cpp b/src/battle/HeroTag.cpp
new file mode 100644 (file)
index 0000000..2461e4d
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * HeroTag.cpp
+ *
+ *  Created on: Aug 6, 2012
+ *      Author: holy
+ */
+
+#include "HeroTag.h"
+
+using geometry::Point;
+
+namespace battle {
+
+void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position) 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, 0xFF, 0xFF));
+
+       destRect.x += 1;
+       destRect.y += 1;
+       destRect.w -= 2;
+       destRect.h -= 2;
+       SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0, 0, 0));
+}
+
+}
diff --git a/src/battle/HeroTag.h b/src/battle/HeroTag.h
new file mode 100644 (file)
index 0000000..e0d3a5a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * HeroTag.h
+ *
+ *  Created on: Aug 6, 2012
+ *      Author: holy
+ */
+
+#ifndef BATTLE_HEROTAG_H_
+#define BATTLE_HEROTAG_H_
+
+#include "../geometry/Point.h"
+
+#include <SDL.h>
+
+namespace battle {
+
+class Hero;
+
+class HeroTag {
+
+public:
+       enum Alignment {
+               LEFT,
+               RIGHT
+       };
+
+public:
+       HeroTag(const Hero *hero, Alignment align) : hero(hero), align(align) { }
+       ~HeroTag() { }
+
+public:
+       void Render(SDL_Surface *screen, int width, int height, geometry::Point<int> position) const;
+
+private:
+       const Hero *hero;
+       Alignment align;
+
+};
+
+}
+
+#endif /* BATTLE_HEROTAG_H_ */