4 * Created on: Aug 9, 2012
8 #include "SelectTarget.h"
10 #include "SelectAttackType.h"
11 #include "../BattleState.h"
12 #include "../../app/Application.h"
13 #include "../../app/Input.h"
14 #include "../../geometry/operators.h"
15 #include "../../geometry/Point.h"
17 using app::Application;
19 using geometry::Point;
20 using geometry::Vector;
25 void SelectTarget::EnterState(Application &c, SDL_Surface *screen) {
29 void SelectTarget::ExitState(Application &c, SDL_Surface *screen) {
33 void SelectTarget::ResumeState(Application &ctrl, SDL_Surface *screen) {
37 void SelectTarget::PauseState(Application &ctrl, SDL_Surface *screen) {
42 void SelectTarget::Resize(int width, int height) {
47 void SelectTarget::HandleInput(const Input &input) {
48 if (input.JustPressed(Input::ACTION_A)) {
49 if (selection->CurrentIsSelected()) {
50 ctrl->PopState(); // return control to parent
53 if (selection->SelectSingle()) {
54 ctrl->PopState(); // return control to parent
58 if (input.JustPressed(Input::ACTION_B)) {
59 if (selection->CurrentIsSelected()) {
60 selection->Unselect();
62 selection->UnselectAll();
63 ctrl->PopState(); // return control to parent
67 if (input.JustPressed(Input::PAD_UP)) {
70 if (input.JustPressed(Input::PAD_RIGHT)) {
71 selection->MoveRight();
73 if (input.JustPressed(Input::PAD_DOWN)) {
74 selection->MoveDown();
76 if (input.JustPressed(Input::PAD_LEFT)) {
77 selection->MoveLeft();
81 void SelectTarget::UpdateWorld(float deltaT) {
85 void SelectTarget::Render(SDL_Surface *screen) {
86 Vector<int> offset(battle->CalculateScreenOffset(screen));
87 parent->Render(screen);
88 RenderCursors(screen, offset);
91 void SelectTarget::RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset) {
92 // TODO: this should be related to the enemy's width
93 Vector<int> cursorOffset(0, 0);
94 Vector<int> indicatorOffset(0, 0);
95 vector<Point<int> > positions;
96 if (selection->TargetsEnemies()) {
97 for (vector<Point<int> >::const_iterator i(battle->MonsterPositions().begin()), end(battle->MonsterPositions().end()); i != end; ++i) {
98 positions.push_back(*i);
101 for (vector<Hero>::size_type i(0), end(battle->Heroes().size()); i < end; ++i) {
102 Vector<int> positionCorrection(cursorIcon->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - cursorIcon->Height() / 2);
103 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection);
107 for (vector<Point<int> >::size_type i(0); i < positions.size(); ++i) {
108 if (selection->IsSelected(i)) {
109 cursorIcon->DrawTopRight(screen, positions[i] + offset);
113 flipFlop = !flipFlop;
114 cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);