1 #include "SelectSpell.h"
3 #include "SelectAttackType.h"
4 #include "SelectMoveAction.h"
5 #include "SelectTarget.h"
6 #include "../BattleState.h"
7 #include "../../app/Application.h"
8 #include "../../app/Input.h"
9 #include "../../common/Spell.h"
10 #include "../../graphics/Frame.h"
11 #include "../../math/Vector.h"
13 using app::Application;
17 using graphics::Frame;
21 void SelectSpell::OnEnterState(SDL_Surface *screen) {
22 OnResize(screen->w, screen->h);
25 void SelectSpell::OnExitState(SDL_Surface *screen) {
29 void SelectSpell::OnResumeState(SDL_Surface *screen) {
30 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
31 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::MAGIC);
32 battle->ActiveHero().GetAttackChoice().SetSpell(battle->ActiveHero().SpellMenu().Selected());
37 void SelectSpell::OnPauseState(SDL_Surface *screen) {
42 void SelectSpell::OnResize(int width, int height) {
43 const Vector<int> offset = battle->ScreenOffset();
45 const Resources &res = battle->Res();
46 const Frame &frame = *res.selectFrame;
48 framePosition = offset + frame.BorderSize();
49 frameSize = Vector<int>(
50 battle->Width() - 2 * frame.BorderWidth(),
51 res.normalFont->CharHeight() * 13);
53 headlinePosition = offset + Vector<int>(
54 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
55 2 * frame.BorderHeight());
57 menuPosition = offset + Vector<int>(
58 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
59 2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
63 void SelectSpell::HandleEvents(const Input &input) {
64 if (input.JustPressed(Input::ACTION_A)) {
65 if (battle->ActiveHero().SpellMenu().SelectedIsEnabled()) {
66 AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
67 const Spell *spell(battle->ActiveHero().SpellMenu().Selected());
68 ac.Selection().Reset();
69 if (spell->GetTargetingMode().TargetsAlly()) {
70 ac.Selection().SelectHeroes();
72 ac.Selection().SelectMonsters();
74 if (spell->GetTargetingMode().TargetsAll()) {
75 ac.SetType(AttackChoice::MAGIC);
80 if (spell->GetTargetingMode().TargetsSingle()) {
81 ac.Selection().SetSingle();
83 ac.Selection().SetMultiple();
85 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().magicTargetCursor));
89 if (input.JustPressed(Input::ACTION_B)) {
90 Ctrl().PopState(); // return control to parent
92 if (input.JustPressed(Input::PAD_UP)) {
93 battle->ActiveHero().SpellMenu().PreviousRow();
95 if (input.JustPressed(Input::PAD_RIGHT)) {
96 battle->ActiveHero().SpellMenu().NextItem();
98 if (input.JustPressed(Input::PAD_DOWN)) {
99 battle->ActiveHero().SpellMenu().NextRow();
101 if (input.JustPressed(Input::PAD_LEFT)) {
102 battle->ActiveHero().SpellMenu().PreviousItem();
106 void SelectSpell::UpdateWorld(Uint32 deltaT) {
110 void SelectSpell::Render(SDL_Surface *screen) {
111 parent->Render(screen);
113 RenderHeadline(screen);
117 void SelectSpell::RenderFrame(SDL_Surface *screen) {
118 const Frame &frame = *battle->Res().selectFrame;
119 frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
122 void SelectSpell::RenderHeadline(SDL_Surface *screen) {
123 const Resources &res = battle->Res();
124 res.normalFont->DrawString(res.spellMenuHeadline, screen, headlinePosition);
127 void SelectSpell::RenderMenu(SDL_Surface *screen) {
128 battle->ActiveHero().SpellMenu().Draw(screen, menuPosition);