]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectSpell.cpp
fix bug in select attack type state that caused the tag positioning to go nuts
[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                 if (battle->GetSpellMenu().SelectedIsEnabled()) {
53                         battle->SetAttackType(AttackChoice::MAGIC);
54                         battle->NextHero();
55                         ctrl->PopState();
56                 }
57         }
58         if (input.JustPressed(Input::ACTION_B)) {
59                 ctrl->PopState(); // return control to parent
60         }
61         if (input.JustPressed(Input::PAD_UP)) {
62                 battle->GetSpellMenu().PreviousRow();
63         }
64         if (input.JustPressed(Input::PAD_RIGHT)) {
65                 battle->GetSpellMenu().NextItem();
66         }
67         if (input.JustPressed(Input::PAD_DOWN)) {
68                 battle->GetSpellMenu().NextRow();
69         }
70         if (input.JustPressed(Input::PAD_LEFT)) {
71                 battle->GetSpellMenu().PreviousItem();
72         }
73 }
74
75 void SelectSpell::UpdateWorld(float deltaT) {
76
77 }
78
79 void SelectSpell::Render(SDL_Surface *screen) {
80         parent->Render(screen);
81         Vector<int> offset(battle->CalculateScreenOffset(screen));
82         RenderFrame(screen, offset);
83         RenderHeadline(screen, offset);
84         RenderMenu(screen, offset);
85 }
86
87 void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
88         const Frame *frame(battle->Res().selectFrame);
89         Point<int> position(frame->BorderWidth(), frame->BorderHeight());
90         int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
91         int height(battle->Res().normalFont->CharHeight() * 13);
92         frame->Draw(screen, position + offset, width, height);
93 }
94
95 void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
96         const Resources &res(battle->Res());
97         Point<int> position(
98                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
99                         2 * res.selectFrame->BorderHeight());
100         res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
101 }
102
103 void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
104         const Resources &res(battle->Res());
105         Point<int> position(
106                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
107                         2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
108         battle->GetSpellMenu().Draw(screen, position + offset);
109 }
110
111 }