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