]> git.localhorst.tv Git - l2e.git/blob - src/menu/SelectHero.cpp
12690dbeabe22998d678664b359e3e4b84a52e0c
[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(app::State *parent, PartyMenu *pm, void *ref, Callback cb, int cursor)
27 : parent(parent)
28 , partyMenu(pm)
29 , ref(ref)
30 , callback(cb)
31 , cursor(cursor) {
32
33 }
34
35
36 void SelectHero::OnEnterState(SDL_Surface *) {
37         cursorBlink = GraphicsTimers().StartInterval(Res().heroCursorBlinkTime);
38 }
39
40 void SelectHero::OnExitState(SDL_Surface *) {
41
42 }
43
44 void SelectHero::OnResumeState(SDL_Surface *) {
45
46 }
47
48 void SelectHero::OnPauseState(SDL_Surface *) {
49
50 }
51
52
53 void SelectHero::OnResize(int width, int height) {
54
55 }
56
57
58 void SelectHero::HandleEvents(const Input &input) {
59         if (input.JustPressed(Input::ACTION_A)) {
60                 callback(ref, cursor);
61         }
62         if (input.JustPressed(Input::ACTION_B)) {
63                 Ctrl().PopState();
64         }
65
66         if (input.JustPressed(Input::PAD_UP)) {
67                 SelectUp();
68         } else if (input.JustPressed(Input::PAD_RIGHT)) {
69                 SelectRight();
70         } else if (input.JustPressed(Input::PAD_DOWN)) {
71                 SelectDown();
72         } else if (input.JustPressed(Input::PAD_LEFT)) {
73                 SelectLeft();
74         }
75 }
76
77 void SelectHero::SelectUp() {
78         cursor = (cursor + 2) % partyMenu->Game().state->partySize;
79         cursorBlink.Restart();
80 }
81
82 void SelectHero::SelectRight() {
83         cursor = (cursor + 1) % partyMenu->Game().state->partySize;
84         cursorBlink.Restart();
85 }
86
87 void SelectHero::SelectDown() {
88         cursor = (cursor + 2) % partyMenu->Game().state->partySize;
89         cursorBlink.Restart();
90 }
91
92 void SelectHero::SelectLeft() {
93         cursor = (cursor + 3) % partyMenu->Game().state->partySize;
94         cursorBlink.Restart();
95 }
96
97
98 common::GameConfig &SelectHero::Game() {
99         return partyMenu->Game();
100 }
101
102 const common::GameConfig &SelectHero::Game() const {
103         return partyMenu->Game();
104 }
105
106 Resources &SelectHero::Res() {
107         return partyMenu->Res();
108 }
109
110 const Resources &SelectHero::Res() const {
111         return partyMenu->Res();
112 }
113
114
115 void SelectHero::UpdateWorld(float deltaT) {
116
117 }
118
119
120 void SelectHero::Render(SDL_Surface *screen) {
121         parent->Render(screen);
122         if (cursorBlink.Iteration() % 2 == 0) {
123                 RenderCursor(screen);
124         }
125 }
126
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);
132 }
133
134 }