1 #include "SelectAttackType.h"
3 #include "SelectIkari.h"
4 #include "SelectItem.h"
5 #include "SelectMoveAction.h"
6 #include "SelectSpell.h"
7 #include "SelectTarget.h"
8 #include "../AttackChoice.h"
9 #include "../BattleState.h"
10 #include "../../app/Application.h"
11 #include "../../app/Input.h"
12 #include "../../common/Item.h"
13 #include "../../math/Vector.h"
17 using app::Application;
24 void SelectAttackType::OnEnterState(SDL_Surface *screen) {
28 void SelectAttackType::OnExitState(SDL_Surface *screen) {
32 void SelectAttackType::OnResumeState(SDL_Surface *screen) {
33 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
34 battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
37 if (battle->AttackSelectionDone()) {
43 void SelectAttackType::OnPauseState(SDL_Surface *screen) {
48 void SelectAttackType::OnResize(int width, int height) {
53 void SelectAttackType::HandleEvents(const Input &input) {
54 if (input.IsDown(Input::PAD_UP)) {
55 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
56 } else if (input.IsDown(Input::PAD_RIGHT)) {
57 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
58 } else if (input.IsDown(Input::PAD_DOWN)) {
59 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
60 } else if (input.IsDown(Input::PAD_LEFT)) {
61 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
63 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
66 Hero &hero(battle->ActiveHero());
67 AttackChoice &ac(hero.GetAttackChoice());
68 if (input.JustPressed(Input::ACTION_A)) {
69 switch (battle->GetAttackTypeMenu().Selected()) {
70 case AttackChoice::SWORD:
71 if (hero.HasWeapon()) {
72 if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
73 ac.SetType(AttackChoice::SWORD);
77 ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
80 ac.Selection().SetSingle();
82 ac.Selection().Reset();
83 Ctrl().PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
85 case AttackChoice::MAGIC:
86 if (battle->ActiveHero().CanUseMagic()) {
87 Ctrl().PushState(new SelectSpell(battle, this));
90 case AttackChoice::DEFEND:
91 ac.SetType(AttackChoice::DEFEND);
94 case AttackChoice::IKARI:
95 Ctrl().PushState(new SelectIkari(battle, this));
97 case AttackChoice::ITEM:
98 Ctrl().PushState(new SelectItem(battle, this));
101 throw std::logic_error("selected invalid attack type");
103 } else if (input.JustPressed(Input::ACTION_B)) {
105 battle->PreviousHero();
106 if (battle->BeforeFirstHero()) {
107 Ctrl().ChangeState(new SelectMoveAction(battle));
109 battle->ActiveHero().GetAttackChoice().Reset();
113 if (battle->AttackSelectionDone()) {
118 void SelectAttackType::UpdateWorld(Uint32 deltaT) {
122 void SelectAttackType::Render(SDL_Surface *screen) {
123 Vector<int> offset(battle->CalculateScreenOffset(screen));
124 battle->RenderBackground(screen, offset);
125 battle->RenderMonsters(screen, offset);
126 battle->RenderHeroTags(screen, offset);
127 RenderMenu(screen, offset);
130 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
131 Vector<int> position(
132 (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
133 battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
134 battle->GetAttackTypeMenu().Render(screen, position + offset);