4 * Created on: Oct 22, 2012
8 #include "SelectHero.h"
10 #include "HeroStatus.h"
11 #include "PartyMenu.h"
12 #include "Resources.h"
13 #include "../app/Application.h"
14 #include "../app/Input.h"
15 #include "../common/GameConfig.h"
16 #include "../common/GameState.h"
17 #include "../common/Hero.h"
18 #include "../geometry/Vector.h"
19 #include "../graphics/Sprite.h"
22 using geometry::Vector;
26 SelectHero::SelectHero(app::State *parent, PartyMenu *pm, void *ref, Callback cb, int cursor)
36 void SelectHero::OnEnterState(SDL_Surface *) {
37 cursorBlink = GraphicsTimers().StartInterval(Res().heroCursorBlinkTime);
40 void SelectHero::OnExitState(SDL_Surface *) {
44 void SelectHero::OnResumeState(SDL_Surface *) {
48 void SelectHero::OnPauseState(SDL_Surface *) {
53 void SelectHero::OnResize(int width, int height) {
58 void SelectHero::HandleEvents(const Input &input) {
59 if (input.JustPressed(Input::ACTION_A)) {
60 callback(ref, cursor);
62 if (input.JustPressed(Input::ACTION_B)) {
66 if (input.JustPressed(Input::PAD_UP)) {
68 } else if (input.JustPressed(Input::PAD_RIGHT)) {
70 } else if (input.JustPressed(Input::PAD_DOWN)) {
72 } else if (input.JustPressed(Input::PAD_LEFT)) {
77 void SelectHero::SelectUp() {
78 cursor = (cursor + 2) % partyMenu->Game().state->partySize;
79 cursorBlink.Restart();
82 void SelectHero::SelectRight() {
83 cursor = (cursor + 1) % partyMenu->Game().state->partySize;
84 cursorBlink.Restart();
87 void SelectHero::SelectDown() {
88 cursor = (cursor + 2) % partyMenu->Game().state->partySize;
89 cursorBlink.Restart();
92 void SelectHero::SelectLeft() {
93 cursor = (cursor + 3) % partyMenu->Game().state->partySize;
94 cursorBlink.Restart();
98 common::GameConfig &SelectHero::Game() {
99 return partyMenu->Game();
102 const common::GameConfig &SelectHero::Game() const {
103 return partyMenu->Game();
106 Resources &SelectHero::Res() {
107 return partyMenu->Res();
110 const Resources &SelectHero::Res() const {
111 return partyMenu->Res();
115 void SelectHero::UpdateWorld(float deltaT) {
120 void SelectHero::Render(SDL_Surface *screen) {
121 parent->Render(screen);
122 if (cursorBlink.Iteration() % 2 == 0) {
123 RenderCursor(screen);
127 void SelectHero::RenderCursor(SDL_Surface *screen) const {
128 Vector<int> position(
129 0, Game().state->party[cursor]->BattleSprite()->Height());
130 position += partyMenu->StatusOffset(cursor);
131 Res().heroCursor->Draw(screen, position);