CPP_SRCS += \
../src/menu/HeroStatus.cpp \
../src/menu/PartyMenu.cpp \
-../src/menu/Resources.cpp
+../src/menu/Resources.cpp \
+../src/menu/SelectHero.cpp \
+../src/menu/StatusMenu.cpp
OBJS += \
./src/menu/HeroStatus.o \
./src/menu/PartyMenu.o \
-./src/menu/Resources.o
+./src/menu/Resources.o \
+./src/menu/SelectHero.o \
+./src/menu/StatusMenu.o
CPP_DEPS += \
./src/menu/HeroStatus.d \
./src/menu/PartyMenu.d \
-./src/menu/Resources.d
+./src/menu/Resources.d \
+./src/menu/SelectHero.d \
+./src/menu/StatusMenu.d
# Each subdirectory must supply rules for building sources it contributes
CPP_SRCS += \
../src/menu/HeroStatus.cpp \
../src/menu/PartyMenu.cpp \
-../src/menu/Resources.cpp
+../src/menu/Resources.cpp \
+../src/menu/SelectHero.cpp \
+../src/menu/StatusMenu.cpp
OBJS += \
./src/menu/HeroStatus.o \
./src/menu/PartyMenu.o \
-./src/menu/Resources.o
+./src/menu/Resources.o \
+./src/menu/SelectHero.o \
+./src/menu/StatusMenu.o
CPP_DEPS += \
./src/menu/HeroStatus.d \
./src/menu/PartyMenu.d \
-./src/menu/Resources.d
+./src/menu/Resources.d \
+./src/menu/SelectHero.d \
+./src/menu/StatusMenu.d
# Each subdirectory must supply rules for building sources it contributes
namespace common {
GameState::GameState()
-: money(0)
+: partySize(1)
+, money(0)
, time(0) {
party[0] = heroes;
party[1] = 0;
Hero heroes[7];
Hero *party[4];
+ int partySize;
Inventory inventory;
gameState.party[1] = &gameState.heroes[1];
gameState.party[2] = &gameState.heroes[2];
gameState.party[3] = &gameState.heroes[3];
+ gameState.partySize = 4;
GameConfig gameConfig;
gameConfig.state = &gameState;
menuResources.mainMenuTimeText = "TIME";
menuResources.mainMenuGoldText = "GOLD";
+ graphics::Sprite heroCursor(IMG_Load("test-data/hero-cursor.png"), 64, 16);
+ menuResources.heroCursor = &heroCursor;
+ menuResources.heroCursorBlinkTime = 532;
+
InitScreen screen(width, height);
app::State *state(0);
int Width() const;
int Height() const;
geometry::Vector<int> Size() const { return geometry::Vector<int>(Width(), Height()); }
+ const geometry::Vector<int> &Position() const { return position; }
void Render(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
#include "PartyMenu.h"
#include "Resources.h"
+#include "SelectHero.h"
+#include "StatusMenu.h"
#include "../app/Application.h"
#include "../app/Input.h"
#include "../common/GameConfig.h"
} else if (input.JustPressed(Input::PAD_LEFT)) {
mainMenu.PreviousItem();
}
+
+ if (input.JustPressed(Input::ACTION_A)) {
+ switch (mainMenu.Selected()) {
+ case MENU_ITEM_ITEM:
+ break;
+ case MENU_ITEM_SPELL:
+ break;
+ case MENU_ITEM_CAPSULE:
+ break;
+ case MENU_ITEM_EQUIP:
+ break;
+ case MENU_ITEM_STATUS:
+ Ctrl().PushState(new SelectHero(this, OnStatusSelect));
+ break;
+ case MENU_ITEM_CHANGE:
+ break;
+ case MENU_ITEM_CONFIG:
+ break;
+ case MENU_ITEM_SCENARIO:
+ break;
+ default:
+ break;
+ }
+ }
}
void PartyMenu::UpdateWorld(float deltaT) {
}
void PartyMenu::Render(SDL_Surface *screen) {
- Res().menubg->Render(screen, Vector<int>(), Vector<int>(screen->w, screen->h));
- RenderHeros(screen, Vector<int>(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight()));
+ RenderBackground(screen);
+ RenderHeros(screen, StatusOffset());
RenderMenu(screen, Vector<int>(8 * Res().normalFont->CharWidth(), 13 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
RenderInfo(screen, Vector<int>(14 * Res().normalFont->CharWidth(), 21 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
}
+Vector<int> PartyMenu::StatusOffset() const {
+ return Vector<int>(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight());
+}
+
+void PartyMenu::RenderBackground(SDL_Surface *screen) const {
+ Res().menubg->Render(screen, Vector<int>(), Vector<int>(screen->w, screen->h));
+}
+
void PartyMenu::RenderHeros(SDL_Surface *screen, const Vector<int> &offset) const {
for (int i(0); i < 4; ++i) {
status[i].Render(screen, offset);
return *game->menuResources;
}
+void PartyMenu::OnStatusSelect(PartyMenu *self, int index) {
+ self->Ctrl().ChangeState(new StatusMenu(self));
+}
+
}
virtual void Render(SDL_Surface *);
public:
+ common::GameConfig &Game() { return *game; }
+ const common::GameConfig &Game() const { return *game; }
Resources &Res();
const Resources &Res() const;
+public:
+ void RenderBackground(SDL_Surface *screen) const;
+ void RenderHeros(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderInfo(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+
+ geometry::Vector<int> StatusOffset() const;
+ const HeroStatus &GetHeroStatus(int index) const { return status[index]; }
+
+ static void OnStatusSelect(PartyMenu *, int);
+
private:
virtual void OnEnterState(SDL_Surface *screen);
virtual void OnExitState(SDL_Surface *screen);
virtual void OnResize(int width, int height);
- void RenderHeros(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderInfo(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+private:
+ enum MenuItem {
+ MENU_ITEM_ITEM,
+ MENU_ITEM_SPELL,
+ MENU_ITEM_CAPSULE,
+ MENU_ITEM_EQUIP,
+ MENU_ITEM_STATUS,
+ MENU_ITEM_CHANGE,
+ MENU_ITEM_CONFIG,
+ MENU_ITEM_SCENARIO,
+ };
private:
HeroStatus status[4];
namespace menu {
Resources::Resources()
-: menubg(0) {
+: menubg(0)
+, normalFont(0)
+, statusFont(0)
+
+, statusLabels(0)
+, statusFrame(0)
+
+, mainMenuProperties(0)
+, mainMenuItemText(0)
+, mainMenuSpellText(0)
+, mainMenuCapsuleText(0)
+, mainMenuEquipmentText(0)
+, mainMenuStatusText(0)
+, mainMenuChangeText(0)
+, mainMenuConfigText(0)
+, mainMenuScenarioText(0)
+
+, mainMenuTimeText(0)
+, mainMenuGoldText(0)
+
+, heroCursor(0)
+, heroCursorBlinkTime(0) {
}
const char *mainMenuTimeText;
const char *mainMenuGoldText;
+ graphics::Sprite *heroCursor;
+ int heroCursorBlinkTime;
+
Resources();
};
--- /dev/null
+/*
+ * SelectHero.cpp
+ *
+ * Created on: Oct 22, 2012
+ * Author: holy
+ */
+
+#include "SelectHero.h"
+
+#include "HeroStatus.h"
+#include "PartyMenu.h"
+#include "Resources.h"
+#include "../app/Application.h"
+#include "../app/Input.h"
+#include "../common/GameConfig.h"
+#include "../common/GameState.h"
+#include "../common/Hero.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Sprite.h"
+
+using app::Input;
+using geometry::Vector;
+
+namespace menu {
+
+SelectHero::SelectHero(PartyMenu *parent, Callback cb, int cursor)
+: parent(parent)
+, callback(cb)
+, cursor(cursor) {
+
+}
+
+
+void SelectHero::OnEnterState(SDL_Surface *) {
+ cursorBlink = GraphicsTimers().StartInterval(Res().heroCursorBlinkTime);
+}
+
+void SelectHero::OnExitState(SDL_Surface *) {
+
+}
+
+void SelectHero::OnResumeState(SDL_Surface *) {
+
+}
+
+void SelectHero::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void SelectHero::OnResize(int width, int height) {
+
+}
+
+
+void SelectHero::HandleEvents(const Input &input) {
+ if (input.JustPressed(Input::ACTION_A)) {
+ callback(parent, cursor);
+ }
+ if (input.JustPressed(Input::ACTION_B)) {
+ Ctrl().PopState();
+ }
+
+ if (input.JustPressed(Input::PAD_UP)) {
+ SelectUp();
+ } else if (input.JustPressed(Input::PAD_RIGHT)) {
+ SelectRight();
+ } else if (input.JustPressed(Input::PAD_DOWN)) {
+ SelectDown();
+ } else if (input.JustPressed(Input::PAD_LEFT)) {
+ SelectLeft();
+ }
+}
+
+void SelectHero::SelectUp() {
+ cursor = (cursor + 2) % parent->Game().state->partySize;
+ cursorBlink.Restart();
+}
+
+void SelectHero::SelectRight() {
+ cursor = (cursor + 1) % parent->Game().state->partySize;
+ cursorBlink.Restart();
+}
+
+void SelectHero::SelectDown() {
+ cursor = (cursor + 2) % parent->Game().state->partySize;
+ cursorBlink.Restart();
+}
+
+void SelectHero::SelectLeft() {
+ cursor = (cursor + 3) % parent->Game().state->partySize;
+ cursorBlink.Restart();
+}
+
+
+common::GameConfig &SelectHero::Game() {
+ return parent->Game();
+}
+
+const common::GameConfig &SelectHero::Game() const {
+ return parent->Game();
+}
+
+Resources &SelectHero::Res() {
+ return parent->Res();
+}
+
+const Resources &SelectHero::Res() const {
+ return parent->Res();
+}
+
+
+void SelectHero::UpdateWorld(float deltaT) {
+
+}
+
+
+void SelectHero::Render(SDL_Surface *screen) {
+ parent->Render(screen);
+ if (cursorBlink.Iteration() % 2 == 0) {
+ RenderCursor(screen);
+ }
+}
+
+void SelectHero::RenderCursor(SDL_Surface *screen) const {
+ const HeroStatus &status(parent->GetHeroStatus(cursor));
+ Vector<int> position(
+ 0, Game().state->party[cursor]->BattleSprite()->Height());
+ position += status.Position() + parent->StatusOffset();
+ Res().heroCursor->Draw(screen, position);
+}
+
+}
--- /dev/null
+/*
+ * SelectHero.h
+ *
+ * Created on: Oct 22, 2012
+ * Author: holy
+ */
+
+#ifndef MENU_SELECTHERO_H_
+#define MENU_SELECTHERO_H_
+
+#include "fwd.h"
+#include "../app/State.h"
+#include "../app/Timer.h"
+#include "../common/fwd.h"
+
+#include <SDL.h>
+
+namespace menu {
+
+class SelectHero
+: public app::State {
+
+public:
+ typedef void (*Callback)(PartyMenu *, int selection);
+
+public:
+ explicit SelectHero(PartyMenu *parent, Callback, int initialHero = 0);
+
+public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+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);
+
+private:
+ common::GameConfig &Game();
+ const common::GameConfig &Game() const;
+ Resources &Res();
+ const Resources &Res() const;
+
+ void SelectUp();
+ void SelectRight();
+ void SelectDown();
+ void SelectLeft();
+
+ void RenderCursor(SDL_Surface *screen) const;
+
+private:
+ PartyMenu *parent;
+ Callback callback;
+ app::Timer<Uint32> cursorBlink;
+ int cursor;
+
+};
+
+}
+
+#endif /* MENU_SELECTHERO_H_ */
--- /dev/null
+/*
+ * StatusMenu.cpp
+ *
+ * Created on: Oct 22, 2012
+ * Author: holy
+ */
+
+#include "StatusMenu.h"
+
+#include "PartyMenu.h"
+#include "../app/Application.h"
+#include "../app/Input.h"
+
+using app::Input;
+
+namespace menu {
+
+StatusMenu::StatusMenu(PartyMenu *parent)
+: parent(parent) {
+
+}
+
+
+void StatusMenu::OnEnterState(SDL_Surface *) {
+
+}
+
+void StatusMenu::OnExitState(SDL_Surface *) {
+
+}
+
+void StatusMenu::OnResumeState(SDL_Surface *) {
+
+}
+
+void StatusMenu::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void StatusMenu::OnResize(int width, int height) {
+
+}
+
+
+void StatusMenu::HandleEvents(const Input &input) {
+ if (input.JustPressed(Input::ACTION_B)) {
+ Ctrl().PopState();
+ }
+}
+
+void StatusMenu::UpdateWorld(float deltaT) {
+
+}
+
+void StatusMenu::Render(SDL_Surface *screen) {
+ parent->RenderBackground(screen);
+}
+
+}
--- /dev/null
+/*
+ * StatusMenu.h
+ *
+ * Created on: Oct 22, 2012
+ * Author: holy
+ */
+
+#ifndef MENU_STATUSMENU_H_
+#define MENU_STATUSMENU_H_
+
+#include "fwd.h"
+#include "../app/State.h"
+
+namespace menu {
+
+class StatusMenu
+: public app::State {
+
+public:
+ explicit StatusMenu(PartyMenu *parent);
+
+public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+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);
+
+private:
+ PartyMenu *parent;
+
+};
+
+}
+
+#endif /* MENU_STATUSMENU_H_ */
class HeroStatus;
class PartyMenu;
struct Resources;
+class SelectHero;
+class StatusMenu;
}