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