4 * Created on: Aug 8, 2012
8 #include "SelectSpell.h"
10 #include "SelectAttackType.h"
11 #include "SelectMoveAction.h"
12 #include "../BattleState.h"
13 #include "../../app/Application.h"
14 #include "../../app/Input.h"
15 #include "../../geometry/operators.h"
16 #include "../../geometry/Point.h"
17 #include "../../graphics/Frame.h"
19 using app::Application;
21 using geometry::Point;
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) {
39 void SelectSpell::PauseState(Application &ctrl, SDL_Surface *screen) {
44 void SelectSpell::Resize(int width, int height) {
49 void SelectSpell::HandleInput(const Input &input) {
50 if (input.JustPressed(Input::ACTION_A)) {
51 // TODO: switch to target select
55 if (input.JustPressed(Input::ACTION_B)) {
56 ctrl->PopState(); // return control to parent
60 void SelectSpell::UpdateWorld(float deltaT) {
64 void SelectSpell::Render(SDL_Surface *screen) {
65 parent->Render(screen);
66 Vector<int> offset(battle->CalculateScreenOffset(screen));
67 RenderFrame(screen, offset);
68 RenderHeadline(screen, offset);
69 RenderMenu(screen, offset);
72 void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
73 const Frame *frame(battle->Res().selectFrame);
74 Point<int> position(frame->BorderWidth(), frame->BorderHeight());
75 int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
76 // TODO: replace with font height
77 int height(frame->BorderHeight() * 13);
78 frame->Draw(screen, position + offset, width, height);
81 void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
82 const Resources &res(battle->Res());
84 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
85 2 * res.selectFrame->BorderHeight());
86 res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
89 void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
90 const Resources &res(battle->Res());
92 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
93 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
94 battle->GetSpellMenu().Draw(screen, position + offset);