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) {
17 OnResize(screen->w, screen->h);
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) {
34 Vector<int> offset(battle->ScreenOffset());
35 cursorOffset = Vector<int>(cursorIcon->Width() / -2, cursorIcon->Height()) + offset;
36 // offset the indicator by 1/8th to the right and top
37 indicatorOffset = cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8);
39 monsterPositions.clear();
40 monsterPositions.reserve(battle->MaxMonsters());
41 for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
42 monsterPositions.push_back(battle->MonsterAt(i).Position());
45 heroPositions.clear();
46 heroPositions.reserve(battle->NumHeroes());
47 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
48 heroPositions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
53 void SelectTarget::HandleEvents(const Input &input) {
54 if (input.JustPressed(Input::ACTION_A)) {
55 if (selection->CurrentIsSelected()) {
56 Ctrl().PopState(); // return control to parent
59 if (selection->SelectSingle()) {
60 Ctrl().PopState(); // return control to parent
64 if (input.JustPressed(Input::ACTION_B)) {
65 if (selection->CurrentIsSelected()) {
66 selection->Unselect();
68 selection->UnselectAll();
69 Ctrl().PopState(); // return control to parent
73 if (input.JustPressed(Input::PAD_UP)) {
76 if (input.JustPressed(Input::PAD_RIGHT)) {
77 selection->MoveRight();
79 if (input.JustPressed(Input::PAD_DOWN)) {
80 selection->MoveDown();
82 if (input.JustPressed(Input::PAD_LEFT)) {
83 selection->MoveLeft();
87 void SelectTarget::UpdateWorld(Uint32 deltaT) {
91 void SelectTarget::Render(SDL_Surface *screen) {
92 parent->Render(screen);
93 RenderCursors(screen);
96 void SelectTarget::RenderCursors(SDL_Surface *screen) {
97 vector<Vector<int> > &positions = selection->TargetsMonsters()
102 for (vector<Vector<int> >::size_type i(0), end(positions.size());
104 if (selection->IsSelected(i)) {
105 cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset);
109 flipFlop = !flipFlop;
110 cursorIcon->DrawTopRight(screen, positions[selection->Current()] + cursorOffset);