]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectSpell.cpp
added rough implementation of a Menu
[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 using app::Application;
20 using app::Input;
21 using geometry::Point;
22 using geometry::Vector;
23 using graphics::Frame;
24
25 namespace battle {
26
27 void SelectSpell::EnterState(Application &c, SDL_Surface *screen) {
28         ctrl = &c;
29 }
30
31 void SelectSpell::ExitState(Application &c, SDL_Surface *screen) {
32         ctrl = 0;
33 }
34
35 void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) {
36
37 }
38
39 void SelectSpell::PauseState(Application &ctrl, SDL_Surface *screen) {
40
41 }
42
43
44 void SelectSpell::Resize(int width, int height) {
45
46 }
47
48
49 void SelectSpell::HandleInput(const Input &input) {
50         if (input.JustPressed(Input::ACTION_A)) {
51                 // TODO: switch to target select
52                 battle->NextHero();
53                 ctrl->PopState();
54         }
55         if (input.JustPressed(Input::ACTION_B)) {
56                 ctrl->PopState(); // return control to parent
57         }
58 }
59
60 void SelectSpell::UpdateWorld(float deltaT) {
61
62 }
63
64 void SelectSpell::Render(SDL_Surface *screen) {
65         parent->Render(screen);
66         Vector<int> offset(battle->CalculateScreenOffset(screen));
67         RenderFrame(screen, offset);
68         RenderMenu(screen, offset);
69 }
70
71 void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
72         const Frame *frame(battle->Res().selectFrame);
73         Point<int> position(frame->BorderWidth(), frame->BorderHeight());
74         int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
75         // TODO: replace with font height
76         int height(frame->BorderHeight() * 13);
77         frame->Draw(screen, position + offset, width, height);
78 }
79
80 void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
81         Point<int> position(2 * battle->Res().selectFrame->BorderWidth(), 2 * battle->Res().selectFrame->BorderHeight());
82         battle->GetSpellMenu().Draw(screen, position + offset);
83 }
84
85 }