]> git.localhorst.tv Git - l2e.git/blob - src/menu/SelectHero.cpp
added hero selection state + status stub
[l2e.git] / src / menu / SelectHero.cpp
1 /*
2  * SelectHero.cpp
3  *
4  *  Created on: Oct 22, 2012
5  *      Author: holy
6  */
7
8 #include "SelectHero.h"
9
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"
20
21 using app::Input;
22 using geometry::Vector;
23
24 namespace menu {
25
26 SelectHero::SelectHero(PartyMenu *parent, Callback cb, int cursor)
27 : parent(parent)
28 , callback(cb)
29 , cursor(cursor) {
30
31 }
32
33
34 void SelectHero::OnEnterState(SDL_Surface *) {
35         cursorBlink = GraphicsTimers().StartInterval(Res().heroCursorBlinkTime);
36 }
37
38 void SelectHero::OnExitState(SDL_Surface *) {
39
40 }
41
42 void SelectHero::OnResumeState(SDL_Surface *) {
43
44 }
45
46 void SelectHero::OnPauseState(SDL_Surface *) {
47
48 }
49
50
51 void SelectHero::OnResize(int width, int height) {
52
53 }
54
55
56 void SelectHero::HandleEvents(const Input &input) {
57         if (input.JustPressed(Input::ACTION_A)) {
58                 callback(parent, cursor);
59         }
60         if (input.JustPressed(Input::ACTION_B)) {
61                 Ctrl().PopState();
62         }
63
64         if (input.JustPressed(Input::PAD_UP)) {
65                 SelectUp();
66         } else if (input.JustPressed(Input::PAD_RIGHT)) {
67                 SelectRight();
68         } else if (input.JustPressed(Input::PAD_DOWN)) {
69                 SelectDown();
70         } else if (input.JustPressed(Input::PAD_LEFT)) {
71                 SelectLeft();
72         }
73 }
74
75 void SelectHero::SelectUp() {
76         cursor = (cursor + 2) % parent->Game().state->partySize;
77         cursorBlink.Restart();
78 }
79
80 void SelectHero::SelectRight() {
81         cursor = (cursor + 1) % parent->Game().state->partySize;
82         cursorBlink.Restart();
83 }
84
85 void SelectHero::SelectDown() {
86         cursor = (cursor + 2) % parent->Game().state->partySize;
87         cursorBlink.Restart();
88 }
89
90 void SelectHero::SelectLeft() {
91         cursor = (cursor + 3) % parent->Game().state->partySize;
92         cursorBlink.Restart();
93 }
94
95
96 common::GameConfig &SelectHero::Game() {
97         return parent->Game();
98 }
99
100 const common::GameConfig &SelectHero::Game() const {
101         return parent->Game();
102 }
103
104 Resources &SelectHero::Res() {
105         return parent->Res();
106 }
107
108 const Resources &SelectHero::Res() const {
109         return parent->Res();
110 }
111
112
113 void SelectHero::UpdateWorld(float deltaT) {
114
115 }
116
117
118 void SelectHero::Render(SDL_Surface *screen) {
119         parent->Render(screen);
120         if (cursorBlink.Iteration() % 2 == 0) {
121                 RenderCursor(screen);
122         }
123 }
124
125 void SelectHero::RenderCursor(SDL_Surface *screen) const {
126         const HeroStatus &status(parent->GetHeroStatus(cursor));
127         Vector<int> position(
128                         0, Game().state->party[cursor]->BattleSprite()->Height());
129         position += status.Position() + parent->StatusOffset();
130         Res().heroCursor->Draw(screen, position);
131 }
132
133 }