]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectTarget.cpp
introduced a small delay after flip if the screen is not a hardware surface
[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::OnEnterState(SDL_Surface *screen) {
23
24 }
25
26 void SelectTarget::OnExitState(SDL_Surface *screen) {
27
28 }
29
30 void SelectTarget::OnResumeState(SDL_Surface *screen) {
31
32 }
33
34 void SelectTarget::OnPauseState(SDL_Surface *screen) {
35
36 }
37
38
39 void SelectTarget::OnResize(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         Vector<int> cursorOffset(cursorIcon->Width() / -2, cursorIcon->Height());
90         // offset the indicator by 1/8th to the right and top
91         Vector<int> indicatorOffset(cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8));
92         vector<Vector<int> > positions;
93         if (selection->TargetsMonsters()) {
94                 for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
95                         positions.push_back(battle->MonsterAt(i).Position());
96                 }
97         } else {
98                 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
99                         positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
100                 }
101         }
102         if (flipFlop) {
103                 for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
104                         if (selection->IsSelected(i)) {
105                                 cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset + offset);
106                         }
107                 }
108         }
109         flipFlop = !flipFlop;
110         cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);
111 }
112
113 }