]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectTarget.cpp
removed invalid TODO from spell selection
[l2e.git] / src / battle / states / SelectTarget.cpp
1 /*
2  * SelectTarget.cpp
3  *
4  *  Created on: Aug 9, 2012
5  *      Author: holy
6  */
7
8 #include "SelectTarget.h"
9
10 #include "SelectAttackType.h"
11 #include "../BattleState.h"
12 #include "../../app/Application.h"
13 #include "../../app/Input.h"
14
15 using app::Application;
16 using app::Input;
17 using geometry::Vector;
18 using std::vector;
19
20 namespace battle {
21
22 void SelectTarget::EnterState(Application &c, SDL_Surface *screen) {
23         ctrl = &c;
24 }
25
26 void SelectTarget::ExitState(Application &c, SDL_Surface *screen) {
27         ctrl = 0;
28 }
29
30 void SelectTarget::ResumeState(Application &ctrl, SDL_Surface *screen) {
31
32 }
33
34 void SelectTarget::PauseState(Application &ctrl, SDL_Surface *screen) {
35
36 }
37
38
39 void SelectTarget::Resize(int width, int height) {
40
41 }
42
43
44 void SelectTarget::HandleEvents(const Input &input) {
45         if (input.JustPressed(Input::ACTION_A)) {
46                 if (selection->CurrentIsSelected()) {
47                         ctrl->PopState(); // return control to parent
48                 } else {
49                         selection->Select();
50                         if (selection->SelectSingle()) {
51                                 ctrl->PopState(); // return control to parent
52                         }
53                 }
54         }
55         if (input.JustPressed(Input::ACTION_B)) {
56                 if (selection->CurrentIsSelected()) {
57                         selection->Unselect();
58                 } else {
59                         selection->UnselectAll();
60                         ctrl->PopState(); // return control to parent
61                 }
62         }
63
64         if (input.JustPressed(Input::PAD_UP)) {
65                 selection->MoveUp();
66         }
67         if (input.JustPressed(Input::PAD_RIGHT)) {
68                 selection->MoveRight();
69         }
70         if (input.JustPressed(Input::PAD_DOWN)) {
71                 selection->MoveDown();
72         }
73         if (input.JustPressed(Input::PAD_LEFT)) {
74                 selection->MoveLeft();
75         }
76 }
77
78 void SelectTarget::UpdateWorld(float deltaT) {
79
80 }
81
82 void SelectTarget::Render(SDL_Surface *screen) {
83         Vector<int> offset(battle->CalculateScreenOffset(screen));
84         parent->Render(screen);
85         RenderCursors(screen, offset);
86 }
87
88 void SelectTarget::RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset) {
89         // TODO: this should be related to the enemy's width
90         Vector<int> cursorOffset(cursorIcon->Width() / -2, cursorIcon->Height());
91         // offset the indicator by 1/8th to the right and top
92         Vector<int> indicatorOffset(cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8));
93         vector<Vector<int> > positions;
94         if (selection->TargetsMonsters()) {
95                 for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
96                         positions.push_back(battle->MonsterAt(i).Position());
97                 }
98         } else {
99                 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
100                         positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
101                 }
102         }
103         if (flipFlop) {
104                 for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
105                         if (selection->IsSelected(i)) {
106                                 cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset + offset);
107                         }
108                 }
109         }
110         flipFlop = !flipFlop;
111         cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);
112 }
113
114 }