From 010a336797f1419945bed60560cc61fb492793f4 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 6 Aug 2012 18:48:23 +0200 Subject: [PATCH] added prototype for battle's hero tags A hero tag is the panel in the attack selection screen containing information about the hero's stats. --- Debug/src/battle/subdir.mk | 3 +++ Release/src/battle/subdir.mk | 3 +++ src/battle/AttackTypeMenu.cpp | 24 ++++++++++---------- src/battle/AttackTypeMenu.h | 9 ++++++-- src/battle/BattleState.cpp | 29 +++++++++++++++++++++++- src/battle/BattleState.h | 4 ++++ src/battle/HeroTag.cpp | 34 ++++++++++++++++++++++++++++ src/battle/HeroTag.h | 42 +++++++++++++++++++++++++++++++++++ 8 files changed, 133 insertions(+), 15 deletions(-) create mode 100644 src/battle/HeroTag.cpp create mode 100644 src/battle/HeroTag.h diff --git a/Debug/src/battle/subdir.mk b/Debug/src/battle/subdir.mk index d0073bc..0ef38a1 100644 --- a/Debug/src/battle/subdir.mk +++ b/Debug/src/battle/subdir.mk @@ -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 diff --git a/Release/src/battle/subdir.mk b/Release/src/battle/subdir.mk index d1c5b2f..e59a859 100644 --- a/Release/src/battle/subdir.mk +++ b/Release/src/battle/subdir.mk @@ -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 diff --git a/src/battle/AttackTypeMenu.cpp b/src/battle/AttackTypeMenu.cpp index 2a23a09..b881d8b 100644 --- a/src/battle/AttackTypeMenu.cpp +++ b/src/battle/AttackTypeMenu.cpp @@ -32,18 +32,18 @@ void AttackTypeMenu::ReadInput(const Input &input) { } } -void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Point ¢er) { - Vector swordOffset(icons->Width() / -2, icons->Height() / -2); - Vector magicOffset(swordOffset.X(), swordOffset.Y() - icons->Height()); - Vector defendOffset(swordOffset.X() + icons->Width(), swordOffset.Y()); - Vector ikariOffset(swordOffset.X(), swordOffset.Y() + icons->Height()); - Vector 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 &position) { + Vector swordOffset(IconWidth(), IconHeight()); + Vector magicOffset(IconWidth(), 0); + Vector defendOffset(2 * IconWidth(), IconHeight()); + Vector ikariOffset(IconWidth(), 2 * IconHeight()); + Vector 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); } } diff --git a/src/battle/AttackTypeMenu.h b/src/battle/AttackTypeMenu.h index b63ec97..08caf7f 100644 --- a/src/battle/AttackTypeMenu.h +++ b/src/battle/AttackTypeMenu.h @@ -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 @@ -35,7 +35,12 @@ public: public: void ReadInput(const app::Input &); Icon Selected() const { return selected; } - void Render(SDL_Surface *screen, const geometry::Point ¢er); + void Render(SDL_Surface *screen, const geometry::Point &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; diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index b11f52c..758d9d8 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -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::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(background->w / 2, background->h * 3 / 4)); + RenderHeroTags(screen, offset); + RenderAttackTypeMenu(screen, offset); } void BattleState::RenderBackground(SDL_Surface *screen, const Vector &offset) { @@ -96,4 +100,27 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector &offset) { } } +void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector &offset) { + int uiHeight(background->h / 2), uiOffset(uiHeight); + int tagHeight((uiHeight - attackTypeMenu.IconHeight()) / 2); + int tagWidth((background->w - attackTypeMenu.IconWidth()) / 2); + + Point tagPosition[4]; + tagPosition[0] = Point(0, uiOffset); + tagPosition[1] = Point(tagWidth + attackTypeMenu.IconWidth(), uiOffset); + tagPosition[2] = Point(0, uiOffset + tagHeight + attackTypeMenu.IconHeight()); + tagPosition[3] = Point(tagWidth + attackTypeMenu.IconWidth(), uiOffset + tagHeight + attackTypeMenu.IconHeight()); + + for (vector::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 &offset) { + Point position( + (background->w - attackTypeMenu.Width()) / 2, + (background->h * 3 / 4) - (attackTypeMenu.Height() / 2)); + attackTypeMenu.Render(screen, position + offset); +} + } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 9e504ed..8fa7d95 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -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 &offset); void RenderMonsters(SDL_Surface *screen, const geometry::Vector &offset); void RenderHeroes(SDL_Surface *screen, const geometry::Vector &offset); + void RenderHeroTags(SDL_Surface *screen, const geometry::Vector &offset); + void RenderAttackTypeMenu(SDL_Surface *screen, const geometry::Vector &offset); private: SDL_Surface *background; @@ -64,6 +67,7 @@ private: std::vector > heroesPositions; std::vector monsters; std::vector heroes; + std::vector heroTags; }; diff --git a/src/battle/HeroTag.cpp b/src/battle/HeroTag.cpp new file mode 100644 index 0000000..2461e4d --- /dev/null +++ b/src/battle/HeroTag.cpp @@ -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 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 index 0000000..e0d3a5a --- /dev/null +++ b/src/battle/HeroTag.h @@ -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 + +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 position) const; + +private: + const Hero *hero; + Alignment align; + +}; + +} + +#endif /* BATTLE_HEROTAG_H_ */ -- 2.39.2