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"
20 #include "../../math/Vector.h"
24 using app::Application;
31 void SelectAttackType::OnEnterState(SDL_Surface *screen) {
35 void SelectAttackType::OnExitState(SDL_Surface *screen) {
39 void SelectAttackType::OnResumeState(SDL_Surface *screen) {
40 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
41 battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
44 if (battle->AttackSelectionDone()) {
50 void SelectAttackType::OnPauseState(SDL_Surface *screen) {
55 void SelectAttackType::OnResize(int width, int height) {
60 void SelectAttackType::HandleEvents(const Input &input) {
61 if (input.IsDown(Input::PAD_UP)) {
62 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
63 } else if (input.IsDown(Input::PAD_RIGHT)) {
64 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
65 } else if (input.IsDown(Input::PAD_DOWN)) {
66 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
67 } else if (input.IsDown(Input::PAD_LEFT)) {
68 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
70 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
73 Hero &hero(battle->ActiveHero());
74 AttackChoice &ac(hero.GetAttackChoice());
75 if (input.JustPressed(Input::ACTION_A)) {
76 switch (battle->GetAttackTypeMenu().Selected()) {
77 case AttackChoice::SWORD:
78 if (hero.HasWeapon()) {
79 if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
80 ac.SetType(AttackChoice::SWORD);
84 ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
87 ac.Selection().SetSingle();
89 ac.Selection().Reset();
90 Ctrl().PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
92 case AttackChoice::MAGIC:
93 if (battle->ActiveHero().CanUseMagic()) {
94 Ctrl().PushState(new SelectSpell(battle, this));
97 case AttackChoice::DEFEND:
98 ac.SetType(AttackChoice::DEFEND);
101 case AttackChoice::IKARI:
102 Ctrl().PushState(new SelectIkari(battle, this));
104 case AttackChoice::ITEM:
105 Ctrl().PushState(new SelectItem(battle, this));
108 throw std::logic_error("selected invalid attack type");
110 } else if (input.JustPressed(Input::ACTION_B)) {
112 battle->PreviousHero();
113 if (battle->BeforeFirstHero()) {
114 Ctrl().ChangeState(new SelectMoveAction(battle));
116 battle->ActiveHero().GetAttackChoice().Reset();
120 if (battle->AttackSelectionDone()) {
125 void SelectAttackType::UpdateWorld(Uint32 deltaT) {
129 void SelectAttackType::Render(SDL_Surface *screen) {
130 Vector<int> offset(battle->CalculateScreenOffset(screen));
131 battle->RenderBackground(screen, offset);
132 battle->RenderMonsters(screen, offset);
133 battle->RenderHeroTags(screen, offset);
134 RenderMenu(screen, offset);
137 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
138 Vector<int> position(
139 (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
140 battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
141 battle->GetAttackTypeMenu().Render(screen, position + offset);