]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectSpell.cpp
interpret user input in spell selection
[l2e.git] / src / battle / states / SelectSpell.cpp
1 /*
2  * SelectSpell.cpp
3  *
4  *  Created on: Aug 8, 2012
5  *      Author: holy
6  */
7
8 #include "SelectSpell.h"
9
10 #include "SelectAttackType.h"
11 #include "SelectMoveAction.h"
12 #include "../BattleState.h"
13 #include "../../app/Application.h"
14 #include "../../app/Input.h"
15 #include "../../geometry/operators.h"
16 #include "../../geometry/Point.h"
17 #include "../../graphics/Frame.h"
18
19 #include <iostream>
20
21 using app::Application;
22 using app::Input;
23 using geometry::Point;
24 using geometry::Vector;
25 using graphics::Frame;
26
27 namespace battle {
28
29 void SelectSpell::EnterState(Application &c, SDL_Surface *screen) {
30         ctrl = &c;
31 }
32
33 void SelectSpell::ExitState(Application &c, SDL_Surface *screen) {
34         ctrl = 0;
35 }
36
37 void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) {
38
39 }
40
41 void SelectSpell::PauseState(Application &ctrl, SDL_Surface *screen) {
42
43 }
44
45
46 void SelectSpell::Resize(int width, int height) {
47
48 }
49
50
51 void SelectSpell::HandleInput(const Input &input) {
52         if (input.JustPressed(Input::ACTION_A)) {
53                 // TODO: switch to target select
54                 if (battle->GetSpellMenu().SelectedIsEnabled()) {
55                         battle->NextHero();
56                         ctrl->PopState();
57                 }
58         }
59         if (input.JustPressed(Input::ACTION_B)) {
60                 ctrl->PopState(); // return control to parent
61         }
62         if (input.JustPressed(Input::PAD_UP)) {
63                 std::cout << "pressed up" << std::endl;
64                 battle->GetSpellMenu().PreviousRow();
65                 std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl;
66         }
67         if (input.JustPressed(Input::PAD_RIGHT)) {
68                 std::cout << "pressed right" << std::endl;
69                 battle->GetSpellMenu().NextItem();
70                 std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl;
71         }
72         if (input.JustPressed(Input::PAD_DOWN)) {
73                 std::cout << "pressed down" << std::endl;
74                 battle->GetSpellMenu().NextRow();
75                 std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl;
76         }
77         if (input.JustPressed(Input::PAD_LEFT)) {
78                 std::cout << "pressed left" << std::endl;
79                 battle->GetSpellMenu().PreviousItem();
80                 std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl;
81         }
82 }
83
84 void SelectSpell::UpdateWorld(float deltaT) {
85
86 }
87
88 void SelectSpell::Render(SDL_Surface *screen) {
89         parent->Render(screen);
90         Vector<int> offset(battle->CalculateScreenOffset(screen));
91         RenderFrame(screen, offset);
92         RenderHeadline(screen, offset);
93         RenderMenu(screen, offset);
94 }
95
96 void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
97         const Frame *frame(battle->Res().selectFrame);
98         Point<int> position(frame->BorderWidth(), frame->BorderHeight());
99         int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
100         // TODO: replace with font height
101         int height(frame->BorderHeight() * 13);
102         frame->Draw(screen, position + offset, width, height);
103 }
104
105 void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
106         const Resources &res(battle->Res());
107         Point<int> position(
108                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
109                         2 * res.selectFrame->BorderHeight());
110         res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
111 }
112
113 void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
114         const Resources &res(battle->Res());
115         Point<int> position(
116                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
117                         2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
118         battle->GetSpellMenu().Draw(screen, position + offset);
119 }
120
121 }