void BattleState::OnResize(int w, int h) {
-
+ offset = Vector<int>(
+ (w - background->w) / 2,
+ (h - background->h) / 2);
}
smallHeroTagPositions[2] = Vector<int>(xOffset + tagWidth, yOffset);
smallHeroTagPositions[3] = Vector<int>(xOffset + 3 * tagWidth, yOffset);
+ OnResize(screen->w, screen->h);
+
itemMenu = *res->itemMenuProperties;
LoadInventory();
ClearAllAttacks();
void BattleState::Render(SDL_Surface *screen) {
assert(screen);
- Vector<int> offset(CalculateScreenOffset(screen));
- RenderBackground(screen, offset);
- RenderMonsters(screen, offset);
+ RenderBackground(screen);
+ RenderMonsters(screen);
}
-void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderBackground(SDL_Surface *screen) {
assert(screen);
// black for now
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
SDL_BlitSurface(background, 0, screen, &destRect);
}
-void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderMonsters(SDL_Surface *screen) {
assert(screen);
for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
if (MonsterPositionOccupied(i)) {
}
}
-void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderHeroes(SDL_Surface *screen) {
assert(screen);
for (int i(0); i < numHeroes; ++i) {
if (heroes[i].GetAnimation().Running()) {
}
}
-void BattleState::RenderCapsule(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderCapsule(SDL_Surface *screen) {
if (!capsule.Active() || capsule.Health() <= 0) return;
if (capsule.GetAnimation().Running()) {
capsule.GetAnimation().DrawCenter(screen, capsule.Position() + offset);
}
}
-void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderHeroTags(SDL_Surface *screen) {
assert(screen);
int tagHeight(attackTypeMenu.Height());
int tagWidth(attackTypeMenu.Width() * 2 + attackTypeMenu.Width() / 2);
}
}
-void BattleState::RenderSmallHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderSmallHeroTags(SDL_Surface *screen) {
assert(screen);
int tagHeight(res->normalFont->CharHeight() * 4 + res->smallHeroTagFrame->BorderHeight() * 2);
int tagWidth(res->normalFont->CharWidth() * 6 + res->smallHeroTagFrame->BorderWidth() * 2);
bool Defeat() const;
public:
- math::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
- return math::Vector<int>(
- (screen->w - background->w) / 2,
- (screen->h - background->h) / 2);
- }
+ const math::Vector<int> &ScreenOffset() const { return offset; }
int Width() const { return background->w; }
int Height() const { return background->h; }
math::Vector<int> Size() const { return math::Vector<int>(Width(), Height()); }
- void RenderBackground(SDL_Surface *screen, const math::Vector<int> &offset);
- void RenderMonsters(SDL_Surface *screen, const math::Vector<int> &offset);
- void RenderHeroes(SDL_Surface *screen, const math::Vector<int> &offset);
- void RenderCapsule(SDL_Surface *screen, const math::Vector<int> &offset);
- void RenderHeroTags(SDL_Surface *screen, const math::Vector<int> &offset);
- void RenderSmallHeroTags(SDL_Surface *screen, const math::Vector<int> &offset);
+ void RenderBackground(SDL_Surface *screen);
+ void RenderMonsters(SDL_Surface *screen);
+ void RenderHeroes(SDL_Surface *screen);
+ void RenderCapsule(SDL_Surface *screen);
+ void RenderHeroTags(SDL_Surface *screen);
+ void RenderSmallHeroTags(SDL_Surface *screen);
private:
virtual void OnEnterState(SDL_Surface *screen);
SmallHeroTag smallHeroTags[4];
math::Vector<int> heroTagPositions[4];
math::Vector<int> smallHeroTagPositions[4];
+
+ math::Vector<int> offset;
+
Capsule capsule;
int numHeroes;
int activeHero;
battle->CalculateAttackOrder();
numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 ? battle->MaxMonsters() : battle->NumHeroes() + 1);
numberPosition.reserve(numberAnimation.size());
+ OnResize(screen->w, screen->h);
}
void PerformAttacks::OnExitState(SDL_Surface *screen) {
void PerformAttacks::OnResize(int width, int height) {
-
+ const Resources &res = battle->Res();
+ framePosition = battle->ScreenOffset();
+ frameSize = Vector<int>(
+ battle->Width(),
+ res.titleFrame->BorderHeight() * 2 + res.titleFont->CharHeight());
}
}
}
- if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(850);
+ if (titleBarText) {
+ titleBarTimer = GraphicsTimers().StartCountdown(850);
+ textPosition = battle->ScreenOffset() + Vector<int>(
+ (battle->Width() - std::strlen(titleBarText) * battle->Res().titleFont->CharWidth()) / 2,
+ battle->Res().titleFrame->BorderHeight());
+ }
if (moveAnimation.Valid()) {
moveAnimation.Start(*this);
if (battle->CurrentAttack().IsMonster()) {
if (ts.IsBad(i)) {
numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
numberPosition.push_back(
- battle->MonsterAt(i).Position());
+ battle->MonsterAt(i).Position() + battle->ScreenOffset());
} else if (ts.IsGood(i)) {
numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
numberPosition.push_back(
- battle->MonsterAt(i).Position());
+ battle->MonsterAt(i).Position() + battle->ScreenOffset());
}
}
} else {
if (ts.IsBad(i)) {
numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
numberPosition.push_back(
- battle->HeroAt(i).Position());
+ battle->HeroAt(i).Position() + battle->ScreenOffset());
} else if (ts.IsGood(i)) {
numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
numberPosition.push_back(
- battle->HeroAt(i).Position());
+ battle->HeroAt(i).Position() + battle->ScreenOffset());
}
}
}
}
void PerformAttacks::Render(SDL_Surface *screen) {
- Vector<int> offset(battle->CalculateScreenOffset(screen));
- battle->RenderBackground(screen, offset);
- battle->RenderMonsters(screen, offset);
- battle->RenderHeroes(screen, offset);
- battle->RenderCapsule(screen, offset);
- battle->RenderSmallHeroTags(screen, offset);
- RenderTitleBar(screen, offset);
- RenderNumbers(screen, offset);
- RenderTargetAnimation(screen, offset);
+ battle->RenderBackground(screen);
+ battle->RenderMonsters(screen);
+ battle->RenderHeroes(screen);
+ battle->RenderCapsule(screen);
+ battle->RenderSmallHeroTags(screen);
+ RenderTitleBar(screen);
+ RenderNumbers(screen);
+ RenderTargetAnimation(screen);
}
-void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) const {
+void PerformAttacks::RenderTitleBar(SDL_Surface *screen) const {
if (!titleBarText || !titleBarTimer.Running()) return;
- int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
- battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height);
+ battle->Res().titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y());
- Vector<int> textPosition(
- (battle->Width() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2,
- battle->Res().titleFrame->BorderHeight());
- battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset);
+ battle->Res().titleFont->DrawString(titleBarText, screen, textPosition);
}
-void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector<int> &offset) const {
+void PerformAttacks::RenderNumbers(SDL_Surface *screen) const {
for (vector<NumberAnimation>::size_type i(0), end(numberAnimation.size()); i < end; ++i) {
if (numberAnimation[i].Running()) {
Vector<int> align(numberAnimation[i].Width() / -2, numberAnimation[i].Height() * -3 / 4);
- numberAnimation[i].Draw(screen, numberPosition[i] + align + offset);
+ numberAnimation[i].Draw(screen, numberPosition[i] + align);
}
}
}
-void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const math::Vector<int> &offset) const {
+void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen) const {
if (!targetAnimation.Valid() || !targetAnimation.Running()) return;
const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
if (ts.TargetsHeroes()) {
for (vector<Vector<int> >::size_type i(0), end(battle->NumHeroes()); i < end; ++i) {
if (ts.IsSelected(i)) {
- targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + offset);
+ targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + battle->ScreenOffset());
}
}
} else {
for (vector<Vector<int> >::size_type i(0), end(battle->MaxMonsters()); i < end; ++i) {
if (ts.IsSelected(i)) {
- targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + offset);
+ targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + battle->ScreenOffset());
}
}
}
private:
void AddNumberAnimations(const TargetSelection &);
- void RenderTitleBar(SDL_Surface *screen, const math::Vector<int> &offset) const;
- void RenderNumbers(SDL_Surface *screen, const math::Vector<int> &offset) const;
- void RenderTargetAnimation(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderTitleBar(SDL_Surface *screen) const;
+ void RenderNumbers(SDL_Surface *screen) const;
+ void RenderTargetAnimation(SDL_Surface *screen) const;
private:
BattleState *battle;
app::Timer<Uint32> targetAnimationTimer;
std::vector<NumberAnimation> numberAnimation;
std::vector<math::Vector<int> > numberPosition;
+ math::Vector<int> framePosition;
+ math::Vector<int> frameSize;
+ math::Vector<int> textPosition;
int cursor;
};
namespace battle {
void RunState::OnEnterState(SDL_Surface *screen) {
-
+ OnResize(screen->w, screen->h);
}
void RunState::OnExitState(SDL_Surface *screen) {
void RunState::OnResize(int width, int height) {
+ framePosition = battle->ScreenOffset();
+ frameSize = Vector<int> (
+ battle->Width(),
+ battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
+ textPosition = Vector<int>(
+ (battle->Width() - std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth()) / 2,
+ battle->Res().titleFrame->BorderHeight());
}
}
void RunState::Render(SDL_Surface *screen) {
- Vector<int> offset(battle->CalculateScreenOffset(screen));
- battle->RenderBackground(screen, offset);
- battle->RenderMonsters(screen, offset);
- battle->RenderHeroes(screen, offset);
- battle->RenderSmallHeroTags(screen, offset);
- RenderTitleBar(screen, offset);
+ battle->RenderBackground(screen);
+ battle->RenderMonsters(screen);
+ battle->RenderHeroes(screen);
+ battle->RenderSmallHeroTags(screen);
+ RenderTitleBar(screen);
}
-void RunState::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
- int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
- battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height);
-
- Vector<int> textPosition(
- (battle->Width() - (std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth())) / 2,
- battle->Res().titleFrame->BorderHeight());
- battle->Res().titleFont->DrawString(battle->Res().escapeText, screen, textPosition + offset);
+void RunState::RenderTitleBar(SDL_Surface *screen) {
+const Resources &res = battle->Res();
+ res.titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y());
+ res.titleFont->DrawString(res.escapeText, screen, textPosition);
}
}
namespace battle {
class BattleState;
}
-namespace math {
- template<class>
- class Vector;
-}
#include "../../app/State.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderTitleBar(SDL_Surface *screen, const math::Vector<int> &offset);
+ void RenderTitleBar(SDL_Surface *screen);
private:
BattleState *battle;
app::Timer<Uint32> timer;
+ math::Vector<int> framePosition;
+ math::Vector<int> frameSize;
+ math::Vector<int> textPosition;
};
namespace battle {
void SelectAttackType::OnEnterState(SDL_Surface *screen) {
-
+ OnResize(screen->w, screen->h);
}
void SelectAttackType::OnExitState(SDL_Surface *screen) {
void SelectAttackType::OnResize(int width, int height) {
-
+ Vector<int> offset(battle->ScreenOffset());
+ Vector<int> position(
+ (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
+ battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
+ menuOffset = offset + position;
}
}
void SelectAttackType::Render(SDL_Surface *screen) {
- Vector<int> offset(battle->CalculateScreenOffset(screen));
- battle->RenderBackground(screen, offset);
- battle->RenderMonsters(screen, offset);
- battle->RenderHeroTags(screen, offset);
- RenderMenu(screen, offset);
+ battle->RenderBackground(screen);
+ battle->RenderMonsters(screen);
+ battle->RenderHeroTags(screen);
+ RenderMenu(screen);
}
-void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
- Vector<int> position(
- (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
- battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
- battle->GetAttackTypeMenu().Render(screen, position + offset);
+void SelectAttackType::RenderMenu(SDL_Surface *screen) {
+ battle->GetAttackTypeMenu().Render(screen, menuOffset);
}
}
namespace battle {
class BattleState;
}
-namespace math {
- template<class>
- class Vector;
-}
#include "../../app/State.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset);
+ void RenderMenu(SDL_Surface *screen);
private:
BattleState *battle;
+ math::Vector<int> menuOffset;
};
namespace battle {
void SelectIkari::OnEnterState(SDL_Surface *screen) {
-
+ OnResize(screen->w, screen->h);
}
void SelectIkari::OnExitState(SDL_Surface *screen) {
void SelectIkari::OnResize(int width, int height) {
+ const Vector<int> offset = battle->ScreenOffset();
+
+ const Resources &res = battle->Res();
+ const Frame &frame = *res.selectFrame;
+
+ framePosition = offset + frame.BorderSize();
+ frameSize = Vector<int>(
+ battle->Width() - 2 * frame.BorderWidth(),
+ res.normalFont->CharHeight() * 13);
+
+ headlinePosition = offset + Vector<int>(
+ 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+ 2 * frame.BorderHeight());
+ menuPosition = offset + Vector<int>(
+ 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+ 2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
}
void SelectIkari::Render(SDL_Surface *screen) {
parent->Render(screen);
- Vector<int> offset(battle->CalculateScreenOffset(screen));
- RenderFrame(screen, offset);
- RenderHeadline(screen, offset);
- RenderMenu(screen, offset);
+ RenderFrame(screen);
+ RenderHeadline(screen);
+ RenderMenu(screen);
}
-void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
- const Frame *frame(battle->Res().selectFrame);
- Vector<int> position(frame->BorderSize());
- int width(battle->Width() - 2 * frame->BorderWidth());
- int height(battle->Res().normalFont->CharHeight() * 13);
- frame->Draw(screen, position + offset, width, height);
+void SelectIkari::RenderFrame(SDL_Surface *screen) {
+ const Frame &frame = *battle->Res().selectFrame;
+ frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
}
-void SelectIkari::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
- const Resources &res(battle->Res());
- Vector<int> position(
- 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
- 2 * res.selectFrame->BorderHeight());
- res.normalFont->DrawString(res.ikariMenuHeadline, screen, position + offset);
+void SelectIkari::RenderHeadline(SDL_Surface *screen) {
+ const Resources &res = battle->Res();
+ res.normalFont->DrawString(res.ikariMenuHeadline, screen, headlinePosition);
}
-void SelectIkari::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
- const Resources &res(battle->Res());
- Vector<int> position(
- 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
- 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
- battle->ActiveHero().IkariMenu().Draw(screen, position + offset);
+void SelectIkari::RenderMenu(SDL_Surface *screen) {
+ battle->ActiveHero().IkariMenu().Draw(screen, menuPosition);
}
}
class BattleState;
class SelectAttackType;
}
-namespace math {
- template<class>
- class Vector;
-}
#include "../../app/State.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderFrame(SDL_Surface *, const math::Vector<int> &offset);
- void RenderHeadline(SDL_Surface *, const math::Vector<int> &offset);
- void RenderMenu(SDL_Surface *, const math::Vector<int> &offset);
+ void RenderFrame(SDL_Surface *);
+ void RenderHeadline(SDL_Surface *);
+ void RenderMenu(SDL_Surface *);
private:
BattleState *battle;
SelectAttackType *parent;
+ math::Vector<int> framePosition;
+ math::Vector<int> frameSize;
+ math::Vector<int> headlinePosition;
+ math::Vector<int> menuPosition;
};
namespace battle {
void SelectItem::OnEnterState(SDL_Surface *screen) {
-
+ OnResize(screen->w, screen->h);
}
void SelectItem::OnExitState(SDL_Surface *screen) {
void SelectItem::OnResize(int width, int height) {
+ const Vector<int> offset = battle->ScreenOffset();
+
+ const Resources &res = battle->Res();
+ const Frame &frame = *res.selectFrame;
+
+ framePosition = offset + frame.BorderSize();
+ frameSize = Vector<int>(
+ battle->Width() - 2 * frame.BorderWidth(),
+ res.normalFont->CharHeight() * 13);
+
+ headlinePosition = offset + Vector<int>(
+ 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+ 2 * frame.BorderHeight());
+ menuPosition = offset + Vector<int>(
+ 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+ 2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
}
void SelectItem::Render(SDL_Surface *screen) {
parent->Render(screen);
- Vector<int> offset(battle->CalculateScreenOffset(screen));
- RenderFrame(screen, offset);
- RenderHeadline(screen, offset);
- RenderMenu(screen, offset);
+ RenderFrame(screen);
+ RenderHeadline(screen);
+ RenderMenu(screen);
}
-void SelectItem::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
- const Frame *frame(battle->Res().selectFrame);
- Vector<int> position(frame->BorderSize());
- int width(battle->Width() - 2 * frame->BorderWidth());
- int height(battle->Res().normalFont->CharHeight() * 13);
- frame->Draw(screen, position + offset, width, height);
+void SelectItem::RenderFrame(SDL_Surface *screen) {
+ const Frame &frame = *battle->Res().selectFrame;
+ frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
}
-void SelectItem::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
- const Resources &res(battle->Res());
- Vector<int> position(
- 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
- 2 * res.selectFrame->BorderHeight());
- res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
+void SelectItem::RenderHeadline(SDL_Surface *screen) {
+ const Resources &res = battle->Res();
+ res.normalFont->DrawString(res.itemMenuHeadline, screen, headlinePosition);
}
-void SelectItem::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
- const Resources &res(battle->Res());
- Vector<int> position(
- 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
- 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
- battle->ItemMenu().Draw(screen, position + offset);
+void SelectItem::RenderMenu(SDL_Surface *screen) {
+ battle->ItemMenu().Draw(screen, menuPosition);
}
}
class BattleState;
class SelectAttackType;
}
-namespace math {
- template<class>
- class Vector;
-}
#include "../../app/State.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderFrame(SDL_Surface *, const math::Vector<int> &offset);
- void RenderHeadline(SDL_Surface *, const math::Vector<int> &offset);
- void RenderMenu(SDL_Surface *, const math::Vector<int> &offset);
+ void RenderFrame(SDL_Surface *);
+ void RenderHeadline(SDL_Surface *);
+ void RenderMenu(SDL_Surface *);
private:
BattleState *battle;
SelectAttackType *parent;
+ math::Vector<int> framePosition;
+ math::Vector<int> frameSize;
+ math::Vector<int> headlinePosition;
+ math::Vector<int> menuPosition;
};
namespace battle {
void SelectMoveAction::OnEnterState(SDL_Surface *screen) {
-
+ OnResize(screen->w, screen->h);
}
void SelectMoveAction::OnExitState(SDL_Surface *screen) {
void SelectMoveAction::OnResize(int width, int height) {
-
+ position = battle->ScreenOffset() + Vector<int>(
+ (battle->Width() - battle->GetMoveMenu().Width()) / 2,
+ battle->Height() - battle->GetMoveMenu().Height() - battle->GetMoveMenu().Height() / 2);
}
}
void SelectMoveAction::Render(SDL_Surface *screen) {
- Vector<int> offset(battle->CalculateScreenOffset(screen));
- battle->RenderBackground(screen, offset);
- battle->RenderMonsters(screen, offset);
- battle->RenderHeroTags(screen, offset);
- RenderMenu(screen, offset);
+ battle->RenderBackground(screen);
+ battle->RenderMonsters(screen);
+ battle->RenderHeroTags(screen);
+ RenderMenu(screen);
}
-void SelectMoveAction::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
- Vector<int> position(
- (battle->Width() - battle->GetMoveMenu().Width()) / 2,
- battle->Height() - battle->GetMoveMenu().Height() - battle->GetMoveMenu().Height() / 2);
- battle->GetMoveMenu().Render(screen, position + offset);
+void SelectMoveAction::RenderMenu(SDL_Surface *screen) {
+ battle->GetMoveMenu().Render(screen, position);
}
}
namespace battle {
class BattleState;
}
-namespace math {
- template<class>
- class Vector;
-}
#include "../../app/State.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset);
+ void RenderMenu(SDL_Surface *screen);
private:
BattleState *battle;
+ math::Vector<int> position;
};
namespace battle {
void SelectSpell::OnEnterState(SDL_Surface *screen) {
-
+ OnResize(screen->w, screen->h);
}
void SelectSpell::OnExitState(SDL_Surface *screen) {
void SelectSpell::OnResize(int width, int height) {
+ const Vector<int> offset = battle->ScreenOffset();
+
+ const Resources &res = battle->Res();
+ const Frame &frame = *res.selectFrame;
+
+ framePosition = offset + frame.BorderSize();
+ frameSize = Vector<int>(
+ battle->Width() - 2 * frame.BorderWidth(),
+ res.normalFont->CharHeight() * 13);
+
+ headlinePosition = offset + Vector<int>(
+ 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+ 2 * frame.BorderHeight());
+ menuPosition = offset + Vector<int>(
+ 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+ 2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
}
void SelectSpell::Render(SDL_Surface *screen) {
parent->Render(screen);
- Vector<int> offset(battle->CalculateScreenOffset(screen));
- RenderFrame(screen, offset);
- RenderHeadline(screen, offset);
- RenderMenu(screen, offset);
+ RenderFrame(screen);
+ RenderHeadline(screen);
+ RenderMenu(screen);
}
-void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
- const Frame *frame(battle->Res().selectFrame);
- Vector<int> position(frame->BorderSize());
- int width(battle->Width() - 2 * frame->BorderWidth());
- int height(battle->Res().normalFont->CharHeight() * 13);
- frame->Draw(screen, position + offset, width, height);
+void SelectSpell::RenderFrame(SDL_Surface *screen) {
+ const Frame &frame = *battle->Res().selectFrame;
+ frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
}
-void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
- const Resources &res(battle->Res());
- Vector<int> position(
- 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
- 2 * res.selectFrame->BorderHeight());
- res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
+void SelectSpell::RenderHeadline(SDL_Surface *screen) {
+ const Resources &res = battle->Res();
+ res.normalFont->DrawString(res.spellMenuHeadline, screen, headlinePosition);
}
-void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
- const Resources &res(battle->Res());
- Vector<int> position(
- 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
- 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
- battle->ActiveHero().SpellMenu().Draw(screen, position + offset);
+void SelectSpell::RenderMenu(SDL_Surface *screen) {
+ battle->ActiveHero().SpellMenu().Draw(screen, menuPosition);
}
}
class BattleState;
class SelectAttackType;
}
-namespace math {
- template<class>
- class Vector;
-}
#include "../../app/State.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderFrame(SDL_Surface *, const math::Vector<int> &offset);
- void RenderHeadline(SDL_Surface *, const math::Vector<int> &offset);
- void RenderMenu(SDL_Surface *, const math::Vector<int> &offset);
+ void RenderFrame(SDL_Surface *);
+ void RenderHeadline(SDL_Surface *);
+ void RenderMenu(SDL_Surface *);
private:
BattleState *battle;
SelectAttackType *parent;
+ math::Vector<int> framePosition;
+ math::Vector<int> frameSize;
+ math::Vector<int> headlinePosition;
+ math::Vector<int> menuPosition;
};
namespace battle {
void SelectTarget::OnEnterState(SDL_Surface *screen) {
-
+ OnResize(screen->w, screen->h);
}
void SelectTarget::OnExitState(SDL_Surface *screen) {
void SelectTarget::OnResize(int width, int height) {
+ Vector<int> offset(battle->ScreenOffset());
+ cursorOffset = Vector<int>(cursorIcon->Width() / -2, cursorIcon->Height()) + offset;
+ // offset the indicator by 1/8th to the right and top
+ indicatorOffset = cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8);
+ monsterPositions.clear();
+ monsterPositions.reserve(battle->MaxMonsters());
+ for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
+ monsterPositions.push_back(battle->MonsterAt(i).Position());
+ }
+
+ heroPositions.clear();
+ heroPositions.reserve(battle->NumHeroes());
+ for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
+ heroPositions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
+ }
}
}
void SelectTarget::Render(SDL_Surface *screen) {
- Vector<int> offset(battle->CalculateScreenOffset(screen));
parent->Render(screen);
- RenderCursors(screen, offset);
+ RenderCursors(screen);
}
-void SelectTarget::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
- Vector<int> cursorOffset(cursorIcon->Width() / -2, cursorIcon->Height());
- // offset the indicator by 1/8th to the right and top
- Vector<int> indicatorOffset(cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8));
- vector<Vector<int> > positions;
- if (selection->TargetsMonsters()) {
- for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
- positions.push_back(battle->MonsterAt(i).Position());
- }
- } else {
- for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
- positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
- }
- }
+void SelectTarget::RenderCursors(SDL_Surface *screen) {
+ vector<Vector<int> > &positions = selection->TargetsMonsters()
+ ? monsterPositions
+ : heroPositions;
+
if (flipFlop) {
- for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
+ for (vector<Vector<int> >::size_type i(0), end(positions.size());
+ i != end; ++i) {
if (selection->IsSelected(i)) {
- cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset + offset);
+ cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset);
}
}
}
flipFlop = !flipFlop;
- cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);
+ cursorIcon->DrawTopRight(screen, positions[selection->Current()] + cursorOffset);
}
}
class SelectAttackType;
class TargetSelection;
}
-namespace math {
- template<class>
- class Vector;
-}
namespace graphics {
class Sprite;
}
#include "../../app/State.h"
+#include "../../math/Vector.h"
+
+#include <vector>
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset);
+ void RenderCursors(SDL_Surface *screen);
private:
BattleState *battle;
SelectAttackType *parent;
TargetSelection *selection;
const graphics::Sprite *cursorIcon;
+ std::vector<math::Vector<int> > monsterPositions;
+ std::vector<math::Vector<int> > heroPositions;
+ math::Vector<int> cursorOffset;
+ math::Vector<int> indicatorOffset;
bool flipFlop;
};
namespace battle {
void SwapHeroes::OnEnterState(SDL_Surface *screen) {
-
+ OnResize(screen->w, screen->h);
}
void SwapHeroes::OnExitState(SDL_Surface *screen) {
void SwapHeroes::OnResize(int width, int height) {
+ Vector<int> offset(battle->ScreenOffset());
+ // offset the cursor by 1/8th to the left and bottom
+ cursorOffset = Vector<int>(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
+ indicatorOffset = Vector<int>(0, 0);
+ positions.clear();
+ positions.reserve(battle->NumHeroes());
+ for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
+ Vector<int> positionCorrection(
+ battle->Res().swapCursor->Width() / 2,
+ battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
+ // indicator offsets are inverted for heroes
+ positionCorrection -= cursorOffset;
+ positions.push_back(battle->HeroTagPositionAt(i)
+ + battle->HeroTagAt(i).HeroOffset()
+ + positionCorrection
+ + offset);
+ }
}
}
void SwapHeroes::Render(SDL_Surface *screen) {
- Vector<int> offset(battle->CalculateScreenOffset(screen));
parent->Render(screen);
- RenderCursors(screen, offset);
+ RenderCursors(screen);
}
-void SwapHeroes::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
- // offset the cursor by 1/8th to the left and bottom
- Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
- Vector<int> indicatorOffset(0, 0);
- vector<Vector<int> > positions;
- for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
- Vector<int> positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
- // indicator offsets are inverted for heroes
- positionCorrection -= cursorOffset;
- positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection);
- }
+void SwapHeroes::RenderCursors(SDL_Surface *screen) {
if (flipFlop) {
- for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
+ for (vector<Vector<int> >::size_type i(0), end(positions.size());
+ i != end; ++i) {
if (selected == int(i)) {
- battle->Res().swapCursor->DrawTopRight(screen, positions[i] + offset);
+ battle->Res().swapCursor->DrawTopRight(screen, positions[i]);
}
}
}
flipFlop = !flipFlop;
- battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset);
+ battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + cursorOffset);
}
}
class BattleState;
class SelectMoveAction;
}
-namespace math {
- template<class>
- class Vector;
-}
#include "../../app/State.h"
+#include "../../math/Vector.h"
+
+#include <vector>
namespace battle {
void MoveLeft();
private:
- void RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset);
+ void RenderCursors(SDL_Surface *screen);
private:
BattleState *battle;
SelectMoveAction *parent;
+ std::vector<math::Vector<int> > positions;
+ math::Vector<int> cursorOffset;
+ math::Vector<int> indicatorOffset;
int cursor;
int selected;
bool flipFlop;