4 * Created on: Aug 7, 2012
8 #include "SelectAttackType.h"
10 #include "SelectIkari.h"
11 #include "SelectItem.h"
12 #include "SelectMoveAction.h"
13 #include "SelectSpell.h"
14 #include "SelectTarget.h"
15 #include "../AttackChoice.h"
16 #include "../BattleState.h"
17 #include "../../app/Application.h"
18 #include "../../app/Input.h"
19 #include "../../geometry/operators.h"
23 using app::Application;
25 using geometry::Point;
26 using geometry::Vector;
30 void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) {
34 void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
38 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
39 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
40 battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
43 if (battle->AttackSelectionDone()) {
49 void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
54 void SelectAttackType::Resize(int width, int height) {
59 void SelectAttackType::HandleEvents(const Input &input) {
60 if (input.IsDown(Input::PAD_UP)) {
61 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
62 } else if (input.IsDown(Input::PAD_RIGHT)) {
63 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
64 } else if (input.IsDown(Input::PAD_DOWN)) {
65 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
66 } else if (input.IsDown(Input::PAD_LEFT)) {
67 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
69 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
72 if (input.JustPressed(Input::ACTION_A)) {
73 switch (battle->GetAttackTypeMenu().Selected()) {
74 case AttackChoice::SWORD:
75 // TODO: detect single/multiple/all attack mode
76 battle->ActiveHero().GetAttackChoice().Selection().SetSingle();
77 battle->ActiveHero().GetAttackChoice().Selection().Reset();
78 ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHero().GetAttackChoice().Selection(), battle->Res().weaponTargetCursor));
80 case AttackChoice::MAGIC:
81 if (battle->ActiveHero().CanUseMagic()) {
82 ctrl->PushState(new SelectSpell(battle, this));
85 case AttackChoice::DEFEND:
86 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::DEFEND);
89 case AttackChoice::IKARI:
90 ctrl->PushState(new SelectIkari(battle, this));
92 case AttackChoice::ITEM:
93 ctrl->PushState(new SelectItem(battle, this));
96 throw std::logic_error("selected invalid attack type");
98 } else if (input.JustPressed(Input::ACTION_B)) {
99 battle->ActiveHero().GetAttackChoice().Reset();
100 battle->PreviousHero();
101 if (battle->BeforeFirstHero()) {
102 ctrl->ChangeState(new SelectMoveAction(battle));
104 battle->ActiveHero().GetAttackChoice().Reset();
108 if (battle->AttackSelectionDone()) {
113 void SelectAttackType::UpdateWorld(float deltaT) {
117 void SelectAttackType::Render(SDL_Surface *screen) {
118 Vector<int> offset(battle->CalculateScreenOffset(screen));
119 battle->RenderBackground(screen, offset);
120 battle->RenderMonsters(screen, offset);
121 battle->RenderHeroTags(screen, offset);
122 RenderMenu(screen, offset);
125 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
127 (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
128 battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
129 battle->GetAttackTypeMenu().Render(screen, position + offset);