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) {
25 OnResize(screen->w, screen->h);
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) {
49 Vector<int> offset(battle->ScreenOffset());
51 (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
52 battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
53 menuOffset = offset + position;
57 void SelectAttackType::HandleEvents(const Input &input) {
58 if (input.IsDown(Input::PAD_UP)) {
59 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
60 } else if (input.IsDown(Input::PAD_RIGHT)) {
61 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
62 } else if (input.IsDown(Input::PAD_DOWN)) {
63 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
64 } else if (input.IsDown(Input::PAD_LEFT)) {
65 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
67 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
70 Hero &hero(battle->ActiveHero());
71 AttackChoice &ac(hero.GetAttackChoice());
72 if (input.JustPressed(Input::ACTION_A)) {
73 switch (battle->GetAttackTypeMenu().Selected()) {
74 case AttackChoice::SWORD:
75 if (hero.HasWeapon()) {
76 if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
77 ac.SetType(AttackChoice::SWORD);
81 ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
84 ac.Selection().SetSingle();
86 ac.Selection().Reset();
87 Ctrl().PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
89 case AttackChoice::MAGIC:
90 if (battle->ActiveHero().CanUseMagic()) {
91 Ctrl().PushState(new SelectSpell(battle, this));
94 case AttackChoice::DEFEND:
95 ac.SetType(AttackChoice::DEFEND);
98 case AttackChoice::IKARI:
99 Ctrl().PushState(new SelectIkari(battle, this));
101 case AttackChoice::ITEM:
102 Ctrl().PushState(new SelectItem(battle, this));
105 throw std::logic_error("selected invalid attack type");
107 } else if (input.JustPressed(Input::ACTION_B)) {
109 battle->PreviousHero();
110 if (battle->BeforeFirstHero()) {
111 Ctrl().ChangeState(new SelectMoveAction(battle));
113 battle->ActiveHero().GetAttackChoice().Reset();
117 if (battle->AttackSelectionDone()) {
122 void SelectAttackType::UpdateWorld(Uint32 deltaT) {
126 void SelectAttackType::Render(SDL_Surface *screen) {
127 battle->RenderBackground(screen);
128 battle->RenderMonsters(screen);
129 battle->RenderHeroTags(screen);
133 void SelectAttackType::RenderMenu(SDL_Surface *screen) {
134 battle->GetAttackTypeMenu().Render(screen, menuOffset);