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"
15 using app::Application;
17 using geometry::Vector;
22 void SelectTarget::EnterState(Application &c, SDL_Surface *screen) {
26 void SelectTarget::ExitState(Application &c, SDL_Surface *screen) {
30 void SelectTarget::ResumeState(Application &ctrl, SDL_Surface *screen) {
34 void SelectTarget::PauseState(Application &ctrl, SDL_Surface *screen) {
39 void SelectTarget::Resize(int width, int height) {
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
50 if (selection->SelectSingle()) {
51 ctrl->PopState(); // return control to parent
55 if (input.JustPressed(Input::ACTION_B)) {
56 if (selection->CurrentIsSelected()) {
57 selection->Unselect();
59 selection->UnselectAll();
60 ctrl->PopState(); // return control to parent
64 if (input.JustPressed(Input::PAD_UP)) {
67 if (input.JustPressed(Input::PAD_RIGHT)) {
68 selection->MoveRight();
70 if (input.JustPressed(Input::PAD_DOWN)) {
71 selection->MoveDown();
73 if (input.JustPressed(Input::PAD_LEFT)) {
74 selection->MoveLeft();
78 void SelectTarget::UpdateWorld(float deltaT) {
82 void SelectTarget::Render(SDL_Surface *screen) {
83 Vector<int> offset(battle->CalculateScreenOffset(screen));
84 parent->Render(screen);
85 RenderCursors(screen, offset);
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());
99 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
100 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
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);
110 flipFlop = !flipFlop;
111 cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);