1 #include "SelectTarget.h"
3 #include "SelectAttackType.h"
4 #include "../BattleState.h"
5 #include "../../app/Application.h"
6 #include "../../app/Input.h"
7 #include "../../math/Vector.h"
9 using app::Application;
16 void SelectTarget::OnEnterState(SDL_Surface *screen) {
20 void SelectTarget::OnExitState(SDL_Surface *screen) {
24 void SelectTarget::OnResumeState(SDL_Surface *screen) {
28 void SelectTarget::OnPauseState(SDL_Surface *screen) {
33 void SelectTarget::OnResize(int width, int height) {
38 void SelectTarget::HandleEvents(const Input &input) {
39 if (input.JustPressed(Input::ACTION_A)) {
40 if (selection->CurrentIsSelected()) {
41 Ctrl().PopState(); // return control to parent
44 if (selection->SelectSingle()) {
45 Ctrl().PopState(); // return control to parent
49 if (input.JustPressed(Input::ACTION_B)) {
50 if (selection->CurrentIsSelected()) {
51 selection->Unselect();
53 selection->UnselectAll();
54 Ctrl().PopState(); // return control to parent
58 if (input.JustPressed(Input::PAD_UP)) {
61 if (input.JustPressed(Input::PAD_RIGHT)) {
62 selection->MoveRight();
64 if (input.JustPressed(Input::PAD_DOWN)) {
65 selection->MoveDown();
67 if (input.JustPressed(Input::PAD_LEFT)) {
68 selection->MoveLeft();
72 void SelectTarget::UpdateWorld(Uint32 deltaT) {
76 void SelectTarget::Render(SDL_Surface *screen) {
77 Vector<int> offset(battle->CalculateScreenOffset(screen));
78 parent->Render(screen);
79 RenderCursors(screen, offset);
82 void SelectTarget::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
83 Vector<int> cursorOffset(cursorIcon->Width() / -2, cursorIcon->Height());
84 // offset the indicator by 1/8th to the right and top
85 Vector<int> indicatorOffset(cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8));
86 vector<Vector<int> > positions;
87 if (selection->TargetsMonsters()) {
88 for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
89 positions.push_back(battle->MonsterAt(i).Position());
92 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
93 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
97 for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
98 if (selection->IsSelected(i)) {
99 cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset + offset);
103 flipFlop = !flipFlop;
104 cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);