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