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