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 SelectSpell::SelectSpell(Battle *battle, SelectAttackType *parent)
28 void SelectSpell::OnEnterState(SDL_Surface *screen) {
29 OnResize(screen->w, screen->h);
32 void SelectSpell::OnExitState(SDL_Surface *screen) {
36 void SelectSpell::OnResumeState(SDL_Surface *screen) {
37 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
38 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::MAGIC);
39 battle->ActiveHero().GetAttackChoice().SetSpell(battle->ActiveHero().SpellMenu().Selected());
44 void SelectSpell::OnPauseState(SDL_Surface *screen) {
49 void SelectSpell::OnResize(int width, int height) {
50 const Vector<int> offset = parent->ScreenOffset();
52 const Resources &res = parent->Res();
53 const Frame &frame = *res.selectFrame;
55 framePosition = offset + frame.BorderSize();
56 frameSize = Vector<int>(
57 parent->Width() - 2 * frame.BorderWidth(),
58 res.normalFont->CharHeight() * 13);
60 headlinePosition = offset + Vector<int>(
61 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
62 2 * frame.BorderHeight());
64 menuPosition = offset + Vector<int>(
65 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
66 2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
70 void SelectSpell::HandleEvents(const Input &input) {
71 if (input.JustPressed(Input::ACTION_A)) {
72 if (battle->ActiveHero().SpellMenu().SelectedIsEnabled()) {
73 AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
74 const Spell *spell(battle->ActiveHero().SpellMenu().Selected());
75 ac.Selection().Reset();
76 if (spell->GetTargetingMode().TargetsAlly()) {
77 ac.Selection().SelectHeroes();
79 ac.Selection().SelectMonsters();
81 if (spell->GetTargetingMode().TargetsAll()) {
82 ac.SetType(AttackChoice::MAGIC);
87 if (spell->GetTargetingMode().TargetsSingle()) {
88 ac.Selection().SetSingle();
90 ac.Selection().SetMultiple();
92 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), parent->Res().magicTargetCursor));
96 if (input.JustPressed(Input::ACTION_B)) {
97 Ctrl().PopState(); // return control to parent
99 if (input.JustPressed(Input::PAD_UP)) {
100 battle->ActiveHero().SpellMenu().PreviousRow();
102 if (input.JustPressed(Input::PAD_RIGHT)) {
103 battle->ActiveHero().SpellMenu().NextItem();
105 if (input.JustPressed(Input::PAD_DOWN)) {
106 battle->ActiveHero().SpellMenu().NextRow();
108 if (input.JustPressed(Input::PAD_LEFT)) {
109 battle->ActiveHero().SpellMenu().PreviousItem();
113 void SelectSpell::UpdateWorld(Uint32 deltaT) {
117 void SelectSpell::Render(SDL_Surface *screen) {
118 parent->Render(screen);
120 RenderHeadline(screen);
124 void SelectSpell::RenderFrame(SDL_Surface *screen) {
125 const Frame &frame = *parent->Res().selectFrame;
126 frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
129 void SelectSpell::RenderHeadline(SDL_Surface *screen) {
130 const Resources &res = parent->Res();
131 res.normalFont->DrawString(res.spellMenuHeadline, screen, headlinePosition);
134 void SelectSpell::RenderMenu(SDL_Surface *screen) {
135 battle->ActiveHero().SpellMenu().Draw(screen, menuPosition);