# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/menu/ChangeHero.cpp \
../src/menu/HeroStatus.cpp \
../src/menu/PartyMenu.cpp \
../src/menu/Resources.cpp \
../src/menu/StatusMenu.cpp
OBJS += \
+./src/menu/ChangeHero.o \
./src/menu/HeroStatus.o \
./src/menu/PartyMenu.o \
./src/menu/Resources.o \
./src/menu/StatusMenu.o
CPP_DEPS += \
+./src/menu/ChangeHero.d \
./src/menu/HeroStatus.d \
./src/menu/PartyMenu.d \
./src/menu/Resources.d \
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/menu/ChangeHero.cpp \
../src/menu/HeroStatus.cpp \
../src/menu/PartyMenu.cpp \
../src/menu/Resources.cpp \
../src/menu/StatusMenu.cpp
OBJS += \
+./src/menu/ChangeHero.o \
./src/menu/HeroStatus.o \
./src/menu/PartyMenu.o \
./src/menu/Resources.o \
./src/menu/StatusMenu.o
CPP_DEPS += \
+./src/menu/ChangeHero.d \
./src/menu/HeroStatus.d \
./src/menu/PartyMenu.d \
./src/menu/Resources.d \
--- /dev/null
+/*
+ * ChangeHero.cpp
+ *
+ * Created on: Nov 4, 2012
+ * Author: holy
+ */
+
+#include "ChangeHero.h"
+
+#include "HeroStatus.h"
+#include "PartyMenu.h"
+#include "Resources.h"
+#include "SelectHero.h"
+#include "../app/Application.h"
+#include "../app/Input.h"
+#include "../common/GameConfig.h"
+#include "../common/GameState.h"
+
+#include <algorithm>
+
+using app::Input;
+using geometry::Vector;
+using std::swap;
+
+namespace menu {
+
+ChangeHero::ChangeHero(PartyMenu *parent)
+: parent(parent)
+, highlight(0)
+, selection(0) {
+
+}
+
+
+void ChangeHero::OnEnterState(SDL_Surface *) {
+ const HeroStatus &status(parent->GetHeroStatus(0));
+ highlight = SDL_CreateRGBSurface(0, status.Width(), status.Height(), 32, 0xFF000000, 0xFF0000, 0xFF00, 0);
+ SDL_FillRect(highlight, 0, SDL_MapRGB(highlight->format, 0xFF, 0xFF, 0xFF));
+ SDL_SetAlpha(highlight, SDL_SRCALPHA|SDL_RLEACCEL, 0x20);
+}
+
+void ChangeHero::OnExitState(SDL_Surface *) {
+ SDL_FreeSurface(highlight);
+}
+
+void ChangeHero::OnResumeState(SDL_Surface *) {
+ if (selection < 0) {
+ Ctrl().PopState();
+ } else {
+ selection = -1;
+ Ctrl().PushState(new SelectHero(this, parent, this, OnHeroSelected));
+ }
+}
+
+void ChangeHero::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void ChangeHero::OnResize(int width, int height) {
+
+}
+
+
+int ChangeHero::Width() const {
+ return parent->Width();
+}
+
+int ChangeHero::Height() const {
+ return parent->Height();
+}
+
+
+void ChangeHero::HandleEvents(const Input &input) {
+
+}
+
+void ChangeHero::UpdateWorld(float deltaT) {
+
+}
+
+void ChangeHero::Render(SDL_Surface *screen) {
+ Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
+
+ parent->RenderBackground(screen);
+ RenderHighlight(screen, offset);
+ parent->RenderHeros(screen, offset);
+ parent->RenderMenu(screen, offset + Vector<int>(8 * parent->Res().normalFont->CharWidth(), 13 * parent->Res().normalFont->CharHeight() + parent->Res().normalFont->CharHeight() / 8));
+ parent->RenderInfo(screen, offset + Vector<int>(14 * parent->Res().normalFont->CharWidth(), 21 * parent->Res().normalFont->CharHeight() + parent->Res().normalFont->CharHeight() / 8));
+}
+
+void ChangeHero::RenderHighlight(SDL_Surface *screen, const Vector<int> &offset) const {
+ if (selection < 0) return;
+ Vector<int> statusOffset(parent->StatusOffset(selection));
+ statusOffset -= Vector<int>(0, parent->Res().normalFont->CharHeight() / 8);
+ SDL_Rect rect;
+ rect.x = statusOffset.X();
+ rect.y = statusOffset.Y();
+ SDL_BlitSurface(highlight, 0, screen, &rect);
+}
+
+
+void ChangeHero::OnHeroSelected(void *ref, int index) {
+ ChangeHero *self(reinterpret_cast<ChangeHero *>(ref));
+ self->SelectedHero(index);
+}
+
+void ChangeHero::SelectedHero(int index) {
+ if (selection < 0) {
+ selection = index;
+ } else {
+ if (index != selection) {
+ swap(parent->Game().state->party[selection],
+ parent->Game().state->party[index]);
+ }
+ selection = -1;
+ }
+}
+
+}
--- /dev/null
+/*
+ * ChangeHero.h
+ *
+ * Created on: Nov 4, 2012
+ * Author: holy
+ */
+
+#ifndef MENU_CHANGEHERO_H_
+#define MENU_CHANGEHERO_H_
+
+#include "fwd.h"
+#include "../app/State.h"
+#include "../geometry/Vector.h"
+
+#include <SDL.h>
+
+namespace menu {
+
+class ChangeHero
+: public app::State {
+
+public:
+ explicit ChangeHero(PartyMenu *parent);
+
+public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+public:
+ int Width() const;
+ int Height() const;
+
+private:
+ virtual void OnEnterState(SDL_Surface *screen);
+ virtual void OnExitState(SDL_Surface *screen);
+ virtual void OnResumeState(SDL_Surface *screen);
+ virtual void OnPauseState(SDL_Surface *screen);
+
+ virtual void OnResize(int width, int height);
+
+ void SelectedHero(int index);
+
+ void RenderHighlight(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+
+ static void OnHeroSelected(void *, int);
+
+private:
+ PartyMenu *parent;
+ SDL_Surface *highlight;
+ int selection;
+
+};
+
+}
+
+#endif /* MENU_CHANGEHERO_H_ */
HeroStatus::HeroStatus()
: res(0)
+, party(0)
, hero(0) {
}
int HeroStatus::Width() const {
- return hero->BattleSprite()->Width() + res->statusFont->CharWidth() * 11;
+ return party[hero]->BattleSprite()->Width() + res->statusFont->CharWidth() * 11;
}
int HeroStatus::Height() const {
- return hero->BattleSprite()->Height() + res->statusFont->CharWidth();
+ return party[hero]->BattleSprite()->Height() + res->statusFont->CharWidth();
}
void HeroStatus::Render(SDL_Surface *screen, const Vector<int> &offset) const {
- if (!hero) return;
+ if (!party) return;
- hero->BattleSprite()->Draw(screen, offset, 0, 0);
+ party[hero]->BattleSprite()->Draw(screen, offset, 0, 0);
// for some reason, fonts are shifted by one pixel in the original
Vector<int> nameOffset(
- hero->BattleSprite()->Width(),
+ party[hero]->BattleSprite()->Width(),
res->statusFont->CharHeight() * 7 / 8);
nameOffset += offset;
- res->statusFont->DrawString(hero->Name(), screen, nameOffset, 5);
+ res->statusFont->DrawString(party[hero]->Name(), screen, nameOffset, 5);
Vector<int> levelLabelOffset(nameOffset.X() + 6 * res->statusFont->CharWidth(), nameOffset.Y());
res->statusLabels->Draw(screen, levelLabelOffset, 0, 0);
Vector<int> levelOffset(levelLabelOffset.X() + 2 * res->statusFont->CharWidth(), levelLabelOffset.Y());
- res->statusFont->DrawNumber(hero->Level(), screen, levelOffset, 2);
+ res->statusFont->DrawNumber(party[hero]->Level(), screen, levelOffset, 2);
Vector<int> healthLabelOffset(nameOffset.X(), nameOffset.Y() + res->statusFont->CharHeight());
res->statusLabels->Draw(screen, healthLabelOffset, 0, 1);
Vector<int> healthOffset(nameOffset.X() + 3 * res->statusFont->CharWidth(), nameOffset.Y() + res->statusFont->CharHeight());
- res->statusFont->DrawNumber(hero->Health(), screen, healthOffset, 3);
+ res->statusFont->DrawNumber(party[hero]->Health(), screen, healthOffset, 3);
Vector<int> healthSeparatorOffset(healthOffset.X() + 3 * res->statusFont->CharWidth(), healthOffset.Y());
res->statusFont->DrawChar('/', screen, healthSeparatorOffset);
Vector<int> maxHealthOffset(healthSeparatorOffset.X() + res->statusFont->CharWidth(), healthOffset.Y());
- res->statusFont->DrawNumber(hero->MaxHealth(), screen, maxHealthOffset, 3);
+ res->statusFont->DrawNumber(party[hero]->MaxHealth(), screen, maxHealthOffset, 3);
Vector<int> manaLabelOffset(healthLabelOffset.X(), healthLabelOffset.Y() + res->statusFont->CharHeight());
res->statusLabels->Draw(screen, manaLabelOffset, 0, 2);
Vector<int> manaOffset(healthOffset.X(), healthOffset.Y() + res->statusFont->CharHeight());
- res->statusFont->DrawNumber(hero->Mana(), screen, manaOffset, 3);
+ res->statusFont->DrawNumber(party[hero]->Mana(), screen, manaOffset, 3);
Vector<int> manaSeparatorOffset(healthSeparatorOffset.X(), manaOffset.Y());
res->statusFont->DrawChar('/', screen, manaSeparatorOffset);
Vector<int> maxManaOffset(maxHealthOffset.X(), manaOffset.Y());
- res->statusFont->DrawNumber(hero->MaxMana(), screen, maxManaOffset, 3);
+ res->statusFont->DrawNumber(party[hero]->MaxMana(), screen, maxManaOffset, 3);
}
}
public:
void SetResources(const Resources *r) { res = r; }
- void SetHero(const common::Hero *h) { hero = h; }
+ void SetHero(common::Hero **p, int h) { party = p; hero = h; }
int Width() const;
int Height() const;
private:
const Resources *res;
- const common::Hero *hero;
+ common::Hero **party;
+ int hero;
};
#include "PartyMenu.h"
+#include "ChangeHero.h"
#include "Resources.h"
#include "SelectHero.h"
#include "StatusMenu.h"
: game(game)
, mainMenu(*game->menuResources->mainMenuProperties) {
for (int i(0); i < 4; ++i) {
- status[i].SetHero(game->state->party[i]);
+ status[i].SetHero(game->state->party, i);
status[i].SetResources(game->menuResources);
}
statusPositions[0] = Vector<int>(0, 0);
case MENU_ITEM_EQUIP:
break;
case MENU_ITEM_STATUS:
- Ctrl().PushState(new SelectHero(this, OnStatusSelect));
+ Ctrl().PushState(new SelectHero(this, this, this, OnStatusSelect));
break;
case MENU_ITEM_CHANGE:
+ Ctrl().PushState(new ChangeHero(this));
break;
case MENU_ITEM_CONFIG:
break;
return *game->menuResources;
}
-void PartyMenu::OnStatusSelect(PartyMenu *self, int index) {
- self->Ctrl().ChangeState(new StatusMenu(self, index));
+void PartyMenu::OnStatusSelect(void *ref, int index) {
+ PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
+ self->Ctrl().ChangeState(
+ new StatusMenu(self, index));
}
}
geometry::Vector<int> StatusOffset(int index) const;
const HeroStatus &GetHeroStatus(int index) const { return status[index]; }
- static void OnStatusSelect(PartyMenu *, int);
+ static void OnStatusSelect(void *, int);
private:
virtual void OnEnterState(SDL_Surface *screen);
namespace menu {
-SelectHero::SelectHero(PartyMenu *parent, Callback cb, int cursor)
+SelectHero::SelectHero(app::State *parent, PartyMenu *pm, void *ref, Callback cb, int cursor)
: parent(parent)
+, partyMenu(pm)
+, ref(ref)
, callback(cb)
, cursor(cursor) {
void SelectHero::HandleEvents(const Input &input) {
if (input.JustPressed(Input::ACTION_A)) {
- callback(parent, cursor);
+ callback(ref, cursor);
}
if (input.JustPressed(Input::ACTION_B)) {
Ctrl().PopState();
}
void SelectHero::SelectUp() {
- cursor = (cursor + 2) % parent->Game().state->partySize;
+ cursor = (cursor + 2) % partyMenu->Game().state->partySize;
cursorBlink.Restart();
}
void SelectHero::SelectRight() {
- cursor = (cursor + 1) % parent->Game().state->partySize;
+ cursor = (cursor + 1) % partyMenu->Game().state->partySize;
cursorBlink.Restart();
}
void SelectHero::SelectDown() {
- cursor = (cursor + 2) % parent->Game().state->partySize;
+ cursor = (cursor + 2) % partyMenu->Game().state->partySize;
cursorBlink.Restart();
}
void SelectHero::SelectLeft() {
- cursor = (cursor + 3) % parent->Game().state->partySize;
+ cursor = (cursor + 3) % partyMenu->Game().state->partySize;
cursorBlink.Restart();
}
common::GameConfig &SelectHero::Game() {
- return parent->Game();
+ return partyMenu->Game();
}
const common::GameConfig &SelectHero::Game() const {
- return parent->Game();
+ return partyMenu->Game();
}
Resources &SelectHero::Res() {
- return parent->Res();
+ return partyMenu->Res();
}
const Resources &SelectHero::Res() const {
- return parent->Res();
+ return partyMenu->Res();
}
void SelectHero::RenderCursor(SDL_Surface *screen) const {
Vector<int> position(
0, Game().state->party[cursor]->BattleSprite()->Height());
- position += parent->StatusOffset(cursor);
+ position += partyMenu->StatusOffset(cursor);
Res().heroCursor->Draw(screen, position);
}
: public app::State {
public:
- typedef void (*Callback)(PartyMenu *, int selection);
+ typedef void (*Callback)(void *, int selection);
public:
- explicit SelectHero(PartyMenu *parent, Callback, int initialHero = 0);
+ SelectHero(app::State *parent, PartyMenu *partyMenu, void *ref, Callback, int initialHero = 0);
public:
virtual void HandleEvents(const app::Input &);
void RenderCursor(SDL_Surface *screen) const;
private:
- PartyMenu *parent;
+ app::State *parent;
+ PartyMenu *partyMenu;
+ void *ref;
Callback callback;
app::Timer<Uint32> cursorBlink;
int cursor;
namespace menu {
+class ChangeHero;
class HeroStatus;
class PartyMenu;
struct Resources;