+/*
+ * SelectItem.cpp
+ *
+ * Created on: Aug 9, 2012
+ * Author: holy
+ */
+
+#include "SelectItem.h"
+
+#include "SelectAttackType.h"
+#include "../BattleState.h"
+#include "../../app/Application.h"
+#include "../../app/Input.h"
+#include "../../geometry/Point.h"
+#include "../../geometry/operators.h"
+#include "../../graphics/Frame.h"
+
+using app::Application;
+using app::Input;
+using geometry::Point;
+using geometry::Vector;
+using graphics::Frame;
+
+namespace battle {
+
+void SelectItem::EnterState(Application &c, SDL_Surface *screen) {
+ ctrl = &c;
+}
+
+void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
+ ctrl = 0;
+}
+
+void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+
+void SelectItem::Resize(int width, int height) {
+
+}
+
+
+void SelectItem::HandleInput(const Input &input) {
+ if (input.JustPressed(Input::ACTION_A)) {
+ // TODO: switch to target select
+ if (battle->GetItemMenu().SelectedIsEnabled()) {
+ battle->NextHero();
+ ctrl->PopState();
+ }
+ }
+ if (input.JustPressed(Input::ACTION_B)) {
+ ctrl->PopState(); // return control to parent
+ }
+ if (input.JustPressed(Input::PAD_UP)) {
+ battle->GetItemMenu().PreviousRow();
+ }
+ if (input.JustPressed(Input::PAD_RIGHT)) {
+ battle->GetItemMenu().NextItem();
+ }
+ if (input.JustPressed(Input::PAD_DOWN)) {
+ battle->GetItemMenu().NextRow();
+ }
+ if (input.JustPressed(Input::PAD_LEFT)) {
+ battle->GetItemMenu().PreviousItem();
+ }
+}
+
+void SelectItem::UpdateWorld(float deltaT) {
+
+}
+
+void SelectItem::Render(SDL_Surface *screen) {
+ parent->Render(screen);
+ Vector<int> offset(battle->CalculateScreenOffset(screen));
+ RenderFrame(screen, offset);
+ RenderHeadline(screen, offset);
+ RenderMenu(screen, offset);
+}
+
+void SelectItem::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
+ const Frame *frame(battle->Res().selectFrame);
+ Point<int> position(frame->BorderWidth(), frame->BorderHeight());
+ int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
+ int height(battle->Res().normalFont->CharHeight() * 13);
+ frame->Draw(screen, position + offset, width, height);
+}
+
+void SelectItem::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
+ const Resources &res(battle->Res());
+ Point<int> position(
+ 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
+ 2 * res.selectFrame->BorderHeight());
+ res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
+}
+
+void SelectItem::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
+ const Resources &res(battle->Res());
+ Point<int> position(
+ 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
+ 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
+ battle->GetItemMenu().Draw(screen, position + offset);
+}
+
+}