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(PartyMenu *parent, Callback cb, int cursor)
34 void SelectHero::OnEnterState(SDL_Surface *) {
35 cursorBlink = GraphicsTimers().StartInterval(Res().heroCursorBlinkTime);
38 void SelectHero::OnExitState(SDL_Surface *) {
42 void SelectHero::OnResumeState(SDL_Surface *) {
46 void SelectHero::OnPauseState(SDL_Surface *) {
51 void SelectHero::OnResize(int width, int height) {
56 void SelectHero::HandleEvents(const Input &input) {
57 if (input.JustPressed(Input::ACTION_A)) {
58 callback(parent, cursor);
60 if (input.JustPressed(Input::ACTION_B)) {
64 if (input.JustPressed(Input::PAD_UP)) {
66 } else if (input.JustPressed(Input::PAD_RIGHT)) {
68 } else if (input.JustPressed(Input::PAD_DOWN)) {
70 } else if (input.JustPressed(Input::PAD_LEFT)) {
75 void SelectHero::SelectUp() {
76 cursor = (cursor + 2) % parent->Game().state->partySize;
77 cursorBlink.Restart();
80 void SelectHero::SelectRight() {
81 cursor = (cursor + 1) % parent->Game().state->partySize;
82 cursorBlink.Restart();
85 void SelectHero::SelectDown() {
86 cursor = (cursor + 2) % parent->Game().state->partySize;
87 cursorBlink.Restart();
90 void SelectHero::SelectLeft() {
91 cursor = (cursor + 3) % parent->Game().state->partySize;
92 cursorBlink.Restart();
96 common::GameConfig &SelectHero::Game() {
97 return parent->Game();
100 const common::GameConfig &SelectHero::Game() const {
101 return parent->Game();
104 Resources &SelectHero::Res() {
105 return parent->Res();
108 const Resources &SelectHero::Res() const {
109 return parent->Res();
113 void SelectHero::UpdateWorld(float deltaT) {
118 void SelectHero::Render(SDL_Surface *screen) {
119 parent->Render(screen);
120 if (cursorBlink.Iteration() % 2 == 0) {
121 RenderCursor(screen);
125 void SelectHero::RenderCursor(SDL_Surface *screen) const {
126 Vector<int> position(
127 0, Game().state->party[cursor]->BattleSprite()->Height());
128 position += parent->StatusOffset(cursor);
129 Res().heroCursor->Draw(screen, position);