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 "../../common/Item.h"
23 using app::Application;
26 using geometry::Vector;
30 void SelectAttackType::OnEnterState(SDL_Surface *screen) {
34 void SelectAttackType::OnExitState(SDL_Surface *screen) {
38 void SelectAttackType::OnResumeState(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::OnPauseState(SDL_Surface *screen) {
54 void SelectAttackType::OnResize(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 Hero &hero(battle->ActiveHero());
73 AttackChoice &ac(hero.GetAttackChoice());
74 if (input.JustPressed(Input::ACTION_A)) {
75 switch (battle->GetAttackTypeMenu().Selected()) {
76 case AttackChoice::SWORD:
77 if (hero.HasWeapon()) {
78 if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
79 ac.SetType(AttackChoice::SWORD);
83 ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
86 ac.Selection().SetSingle();
88 ac.Selection().Reset();
89 Ctrl().PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
91 case AttackChoice::MAGIC:
92 if (battle->ActiveHero().CanUseMagic()) {
93 Ctrl().PushState(new SelectSpell(battle, this));
96 case AttackChoice::DEFEND:
97 ac.SetType(AttackChoice::DEFEND);
100 case AttackChoice::IKARI:
101 Ctrl().PushState(new SelectIkari(battle, this));
103 case AttackChoice::ITEM:
104 Ctrl().PushState(new SelectItem(battle, this));
107 throw std::logic_error("selected invalid attack type");
109 } else if (input.JustPressed(Input::ACTION_B)) {
111 battle->PreviousHero();
112 if (battle->BeforeFirstHero()) {
113 Ctrl().ChangeState(new SelectMoveAction(battle));
115 battle->ActiveHero().GetAttackChoice().Reset();
119 if (battle->AttackSelectionDone()) {
124 void SelectAttackType::UpdateWorld(float deltaT) {
128 void SelectAttackType::Render(SDL_Surface *screen) {
129 Vector<int> offset(battle->CalculateScreenOffset(screen));
130 battle->RenderBackground(screen, offset);
131 battle->RenderMonsters(screen, offset);
132 battle->RenderHeroTags(screen, offset);
133 RenderMenu(screen, offset);
136 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
137 Vector<int> position(
138 (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
139 battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
140 battle->GetAttackTypeMenu().Render(screen, position + offset);