]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectTarget.cpp
c685dab8947108aa78b83d0a794fdac07da6fba9
[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 #include "../../math/Vector.h"
15
16 using app::Application;
17 using app::Input;
18 using math::Vector;
19 using std::vector;
20
21 namespace battle {
22
23 void SelectTarget::OnEnterState(SDL_Surface *screen) {
24
25 }
26
27 void SelectTarget::OnExitState(SDL_Surface *screen) {
28
29 }
30
31 void SelectTarget::OnResumeState(SDL_Surface *screen) {
32
33 }
34
35 void SelectTarget::OnPauseState(SDL_Surface *screen) {
36
37 }
38
39
40 void SelectTarget::OnResize(int width, int height) {
41
42 }
43
44
45 void SelectTarget::HandleEvents(const Input &input) {
46         if (input.JustPressed(Input::ACTION_A)) {
47                 if (selection->CurrentIsSelected()) {
48                         Ctrl().PopState(); // return control to parent
49                 } else {
50                         selection->Select();
51                         if (selection->SelectSingle()) {
52                                 Ctrl().PopState(); // return control to parent
53                         }
54                 }
55         }
56         if (input.JustPressed(Input::ACTION_B)) {
57                 if (selection->CurrentIsSelected()) {
58                         selection->Unselect();
59                 } else {
60                         selection->UnselectAll();
61                         Ctrl().PopState(); // return control to parent
62                 }
63         }
64
65         if (input.JustPressed(Input::PAD_UP)) {
66                 selection->MoveUp();
67         }
68         if (input.JustPressed(Input::PAD_RIGHT)) {
69                 selection->MoveRight();
70         }
71         if (input.JustPressed(Input::PAD_DOWN)) {
72                 selection->MoveDown();
73         }
74         if (input.JustPressed(Input::PAD_LEFT)) {
75                 selection->MoveLeft();
76         }
77 }
78
79 void SelectTarget::UpdateWorld(Uint32 deltaT) {
80
81 }
82
83 void SelectTarget::Render(SDL_Surface *screen) {
84         Vector<int> offset(battle->CalculateScreenOffset(screen));
85         parent->Render(screen);
86         RenderCursors(screen, offset);
87 }
88
89 void SelectTarget::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
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 }