1 #include "SelectHero.h"
3 #include "HeroStatus.h"
6 #include "../app/Application.h"
7 #include "../app/Input.h"
8 #include "../common/GameConfig.h"
9 #include "../common/GameState.h"
10 #include "../common/Hero.h"
11 #include "../geometry/Vector.h"
12 #include "../graphics/Sprite.h"
15 using geometry::Vector;
19 SelectHero::SelectHero(app::State *parent, PartyMenu *pm, void *ref, Callback cb, int cursor)
29 void SelectHero::OnEnterState(SDL_Surface *) {
30 cursorBlink = GraphicsTimers().StartInterval(Res().heroCursorBlinkTime);
33 void SelectHero::OnExitState(SDL_Surface *) {
37 void SelectHero::OnResumeState(SDL_Surface *) {
41 void SelectHero::OnPauseState(SDL_Surface *) {
46 void SelectHero::OnResize(int width, int height) {
51 void SelectHero::HandleEvents(const Input &input) {
52 if (input.JustPressed(Input::ACTION_A)) {
53 callback(ref, cursor);
55 if (input.JustPressed(Input::ACTION_B)) {
59 if (input.JustPressed(Input::PAD_UP)) {
61 } else if (input.JustPressed(Input::PAD_RIGHT)) {
63 } else if (input.JustPressed(Input::PAD_DOWN)) {
65 } else if (input.JustPressed(Input::PAD_LEFT)) {
70 void SelectHero::SelectUp() {
71 cursor = (cursor + 2) % partyMenu->Game().state->partySize;
72 cursorBlink.Restart();
75 void SelectHero::SelectRight() {
76 cursor = (cursor + 1) % partyMenu->Game().state->partySize;
77 cursorBlink.Restart();
80 void SelectHero::SelectDown() {
81 cursor = (cursor + 2) % partyMenu->Game().state->partySize;
82 cursorBlink.Restart();
85 void SelectHero::SelectLeft() {
86 cursor = (cursor + 3) % partyMenu->Game().state->partySize;
87 cursorBlink.Restart();
91 common::GameConfig &SelectHero::Game() {
92 return partyMenu->Game();
95 const common::GameConfig &SelectHero::Game() const {
96 return partyMenu->Game();
99 Resources &SelectHero::Res() {
100 return partyMenu->Res();
103 const Resources &SelectHero::Res() const {
104 return partyMenu->Res();
108 void SelectHero::UpdateWorld(float deltaT) {
113 void SelectHero::Render(SDL_Surface *screen) {
114 parent->Render(screen);
115 if (cursorBlink.Iteration() % 2 == 0) {
116 RenderCursor(screen);
120 void SelectHero::RenderCursor(SDL_Surface *screen) const {
121 Vector<int> position(
122 0, Game().state->party[cursor]->BattleSprite()->Height());
123 position += partyMenu->StatusOffset(cursor);
124 Res().heroCursor->Draw(screen, position);