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 "../../math/Vector.h"
16 using app::Application;
23 void SelectTarget::OnEnterState(SDL_Surface *screen) {
27 void SelectTarget::OnExitState(SDL_Surface *screen) {
31 void SelectTarget::OnResumeState(SDL_Surface *screen) {
35 void SelectTarget::OnPauseState(SDL_Surface *screen) {
40 void SelectTarget::OnResize(int width, int height) {
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
51 if (selection->SelectSingle()) {
52 Ctrl().PopState(); // return control to parent
56 if (input.JustPressed(Input::ACTION_B)) {
57 if (selection->CurrentIsSelected()) {
58 selection->Unselect();
60 selection->UnselectAll();
61 Ctrl().PopState(); // return control to parent
65 if (input.JustPressed(Input::PAD_UP)) {
68 if (input.JustPressed(Input::PAD_RIGHT)) {
69 selection->MoveRight();
71 if (input.JustPressed(Input::PAD_DOWN)) {
72 selection->MoveDown();
74 if (input.JustPressed(Input::PAD_LEFT)) {
75 selection->MoveLeft();
79 void SelectTarget::UpdateWorld(Uint32 deltaT) {
83 void SelectTarget::Render(SDL_Surface *screen) {
84 Vector<int> offset(battle->CalculateScreenOffset(screen));
85 parent->Render(screen);
86 RenderCursors(screen, offset);
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());
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);