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 "../../geometry/operators.h"
24 using app::Application;
27 using geometry::Point;
28 using geometry::Vector;
32 void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) {
36 void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
40 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
41 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
42 battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
45 if (battle->AttackSelectionDone()) {
51 void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
56 void SelectAttackType::Resize(int width, int height) {
61 void SelectAttackType::HandleEvents(const Input &input) {
62 if (input.IsDown(Input::PAD_UP)) {
63 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
64 } else if (input.IsDown(Input::PAD_RIGHT)) {
65 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
66 } else if (input.IsDown(Input::PAD_DOWN)) {
67 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
68 } else if (input.IsDown(Input::PAD_LEFT)) {
69 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
71 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
74 Hero &hero(battle->ActiveHero());
75 AttackChoice &ac(hero.GetAttackChoice());
76 if (input.JustPressed(Input::ACTION_A)) {
77 switch (battle->GetAttackTypeMenu().Selected()) {
78 case AttackChoice::SWORD:
79 if (hero.HasWeapon()) {
80 if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
81 ac.SetType(AttackChoice::SWORD);
85 ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
88 ac.Selection().SetSingle();
90 ac.Selection().Reset();
91 ctrl->PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
93 case AttackChoice::MAGIC:
94 if (battle->ActiveHero().CanUseMagic()) {
95 ctrl->PushState(new SelectSpell(battle, this));
98 case AttackChoice::DEFEND:
99 ac.SetType(AttackChoice::DEFEND);
102 case AttackChoice::IKARI:
103 ctrl->PushState(new SelectIkari(battle, this));
105 case AttackChoice::ITEM:
106 ctrl->PushState(new SelectItem(battle, this));
109 throw std::logic_error("selected invalid attack type");
111 } else if (input.JustPressed(Input::ACTION_B)) {
113 battle->PreviousHero();
114 if (battle->BeforeFirstHero()) {
115 ctrl->ChangeState(new SelectMoveAction(battle));
117 battle->ActiveHero().GetAttackChoice().Reset();
121 if (battle->AttackSelectionDone()) {
126 void SelectAttackType::UpdateWorld(float deltaT) {
130 void SelectAttackType::Render(SDL_Surface *screen) {
131 Vector<int> offset(battle->CalculateScreenOffset(screen));
132 battle->RenderBackground(screen, offset);
133 battle->RenderMonsters(screen, offset);
134 battle->RenderHeroTags(screen, offset);
135 RenderMenu(screen, offset);
138 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
140 (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
141 battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
142 battle->GetAttackTypeMenu().Render(screen, position + offset);