4 * Created on: Aug 9, 2012
8 #include "SelectItem.h"
10 #include "SelectAttackType.h"
11 #include "../BattleState.h"
12 #include "../../app/Application.h"
13 #include "../../app/Input.h"
14 #include "../../geometry/Point.h"
15 #include "../../geometry/operators.h"
16 #include "../../graphics/Frame.h"
18 using app::Application;
20 using geometry::Point;
21 using geometry::Vector;
22 using graphics::Frame;
26 void SelectItem::EnterState(Application &c, SDL_Surface *screen) {
30 void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
34 void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
38 void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) {
43 void SelectItem::Resize(int width, int height) {
48 void SelectItem::HandleInput(const Input &input) {
49 if (input.JustPressed(Input::ACTION_A)) {
50 // TODO: switch to target select
51 if (battle->GetItemMenu().SelectedIsEnabled()) {
56 if (input.JustPressed(Input::ACTION_B)) {
57 ctrl->PopState(); // return control to parent
59 if (input.JustPressed(Input::PAD_UP)) {
60 battle->GetItemMenu().PreviousRow();
62 if (input.JustPressed(Input::PAD_RIGHT)) {
63 battle->GetItemMenu().NextItem();
65 if (input.JustPressed(Input::PAD_DOWN)) {
66 battle->GetItemMenu().NextRow();
68 if (input.JustPressed(Input::PAD_LEFT)) {
69 battle->GetItemMenu().PreviousItem();
73 void SelectItem::UpdateWorld(float deltaT) {
77 void SelectItem::Render(SDL_Surface *screen) {
78 parent->Render(screen);
79 Vector<int> offset(battle->CalculateScreenOffset(screen));
80 RenderFrame(screen, offset);
81 RenderHeadline(screen, offset);
82 RenderMenu(screen, offset);
85 void SelectItem::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
86 const Frame *frame(battle->Res().selectFrame);
87 Point<int> position(frame->BorderWidth(), frame->BorderHeight());
88 int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
89 int height(battle->Res().normalFont->CharHeight() * 13);
90 frame->Draw(screen, position + offset, width, height);
93 void SelectItem::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
94 const Resources &res(battle->Res());
96 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
97 2 * res.selectFrame->BorderHeight());
98 res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
101 void SelectItem::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
102 const Resources &res(battle->Res());
104 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
105 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
106 battle->GetItemMenu().Draw(screen, position + offset);