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) {
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) {
47 void SelectSpell::HandleEvents(const Input &input) {
48 if (input.JustPressed(Input::ACTION_A)) {
49 if (battle->ActiveHero().SpellMenu().SelectedIsEnabled()) {
50 AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
51 const Spell *spell(battle->ActiveHero().SpellMenu().Selected());
52 ac.Selection().Reset();
53 if (spell->GetTargetingMode().TargetsAlly()) {
54 ac.Selection().SelectHeroes();
56 ac.Selection().SelectMonsters();
58 if (spell->GetTargetingMode().TargetsAll()) {
59 ac.SetType(AttackChoice::MAGIC);
64 if (spell->GetTargetingMode().TargetsSingle()) {
65 ac.Selection().SetSingle();
67 ac.Selection().SetMultiple();
69 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().magicTargetCursor));
73 if (input.JustPressed(Input::ACTION_B)) {
74 Ctrl().PopState(); // return control to parent
76 if (input.JustPressed(Input::PAD_UP)) {
77 battle->ActiveHero().SpellMenu().PreviousRow();
79 if (input.JustPressed(Input::PAD_RIGHT)) {
80 battle->ActiveHero().SpellMenu().NextItem();
82 if (input.JustPressed(Input::PAD_DOWN)) {
83 battle->ActiveHero().SpellMenu().NextRow();
85 if (input.JustPressed(Input::PAD_LEFT)) {
86 battle->ActiveHero().SpellMenu().PreviousItem();
90 void SelectSpell::UpdateWorld(Uint32 deltaT) {
94 void SelectSpell::Render(SDL_Surface *screen) {
95 parent->Render(screen);
96 Vector<int> offset(battle->CalculateScreenOffset(screen));
97 RenderFrame(screen, offset);
98 RenderHeadline(screen, offset);
99 RenderMenu(screen, offset);
102 void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
103 const Frame *frame(battle->Res().selectFrame);
104 Vector<int> position(frame->BorderSize());
105 int width(battle->Width() - 2 * frame->BorderWidth());
106 int height(battle->Res().normalFont->CharHeight() * 13);
107 frame->Draw(screen, position + offset, width, height);
110 void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
111 const Resources &res(battle->Res());
112 Vector<int> position(
113 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
114 2 * res.selectFrame->BorderHeight());
115 res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
118 void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
119 const Resources &res(battle->Res());
120 Vector<int> position(
121 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
122 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
123 battle->ActiveHero().SpellMenu().Draw(screen, position + offset);