4 * Created on: Aug 8, 2012
8 #include "SelectSpell.h"
10 #include "SelectAttackType.h"
11 #include "SelectMoveAction.h"
12 #include "SelectTarget.h"
13 #include "../BattleState.h"
14 #include "../../app/Application.h"
15 #include "../../app/Input.h"
16 #include "../../common/Spell.h"
17 #include "../../graphics/Frame.h"
19 using app::Application;
22 using geometry::Vector;
23 using graphics::Frame;
27 void SelectSpell::EnterState(Application &c, SDL_Surface *screen) {
31 void SelectSpell::ExitState(Application &c, SDL_Surface *screen) {
35 void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) {
36 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
37 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::MAGIC);
38 battle->ActiveHero().GetAttackChoice().SetSpell(battle->ActiveHero().SpellMenu().Selected());
43 void SelectSpell::PauseState(Application &ctrl, SDL_Surface *screen) {
48 void SelectSpell::Resize(int width, int height) {
53 void SelectSpell::HandleEvents(const Input &input) {
54 if (input.JustPressed(Input::ACTION_A)) {
55 if (battle->ActiveHero().SpellMenu().SelectedIsEnabled()) {
56 AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
57 const Spell *spell(battle->ActiveHero().SpellMenu().Selected());
58 ac.Selection().Reset();
59 if (spell->GetTargetingMode().TargetsAlly()) {
60 ac.Selection().SelectHeroes();
62 ac.Selection().SelectMonsters();
64 if (spell->GetTargetingMode().TargetsAll()) {
65 ac.SetType(AttackChoice::MAGIC);
66 // TODO: remove item from inventory
71 if (spell->GetTargetingMode().TargetsSingle()) {
72 ac.Selection().SetSingle();
74 ac.Selection().SetMultiple();
76 ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().magicTargetCursor));
80 if (input.JustPressed(Input::ACTION_B)) {
81 ctrl->PopState(); // return control to parent
83 if (input.JustPressed(Input::PAD_UP)) {
84 battle->ActiveHero().SpellMenu().PreviousRow();
86 if (input.JustPressed(Input::PAD_RIGHT)) {
87 battle->ActiveHero().SpellMenu().NextItem();
89 if (input.JustPressed(Input::PAD_DOWN)) {
90 battle->ActiveHero().SpellMenu().NextRow();
92 if (input.JustPressed(Input::PAD_LEFT)) {
93 battle->ActiveHero().SpellMenu().PreviousItem();
97 void SelectSpell::UpdateWorld(float deltaT) {
101 void SelectSpell::Render(SDL_Surface *screen) {
102 parent->Render(screen);
103 Vector<int> offset(battle->CalculateScreenOffset(screen));
104 RenderFrame(screen, offset);
105 RenderHeadline(screen, offset);
106 RenderMenu(screen, offset);
109 void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
110 const Frame *frame(battle->Res().selectFrame);
111 Vector<int> position(frame->BorderSize());
112 int width(battle->Width() - 2 * frame->BorderWidth());
113 int height(battle->Res().normalFont->CharHeight() * 13);
114 frame->Draw(screen, position + offset, width, height);
117 void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
118 const Resources &res(battle->Res());
119 Vector<int> position(
120 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
121 2 * res.selectFrame->BorderHeight());
122 res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
125 void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
126 const Resources &res(battle->Res());
127 Vector<int> position(
128 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
129 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
130 battle->ActiveHero().SpellMenu().Draw(screen, position + offset);