4 * Created on: Aug 9, 2012
8 #include "SelectIkari.h"
10 #include "SelectAttackType.h"
11 #include "SelectTarget.h"
12 #include "../BattleState.h"
13 #include "../../app/Application.h"
14 #include "../../app/Input.h"
15 #include "../../common/Ikari.h"
16 #include "../../common/Item.h"
17 #include "../../geometry/Point.h"
18 #include "../../geometry/operators.h"
19 #include "../../graphics/Frame.h"
21 using app::Application;
24 using geometry::Point;
25 using geometry::Vector;
26 using graphics::Frame;
30 void SelectIkari::EnterState(Application &c, SDL_Surface *screen) {
34 void SelectIkari::ExitState(Application &c, SDL_Surface *screen) {
38 void SelectIkari::ResumeState(Application &ctrl, SDL_Surface *screen) {
39 if (battle->ActiveHeroTargets().HasSelected()) {
44 void SelectIkari::PauseState(Application &ctrl, SDL_Surface *screen) {
49 void SelectIkari::Resize(int width, int height) {
54 void SelectIkari::HandleEvents(const Input &input) {
55 if (input.JustPressed(Input::ACTION_A)) {
56 if (battle->GetIkariMenu().SelectedIsEnabled() && battle->GetIkariMenu().Selected()->HasIkari()) {
57 const Ikari *ikari(battle->GetIkariMenu().Selected()->GetIkari());
58 battle->ActiveHeroTargets().Reset();
59 if (ikari->GetTargetingMode().TargetsAlly()) {
60 battle->ActiveHeroTargets().SelectHeroes();
62 battle->ActiveHeroTargets().SelectEnemies();
64 if (ikari->GetTargetingMode().TargetsAll()) {
65 battle->SetAttackType(AttackChoice::MAGIC);
66 // TODO: remove item from inventory
67 battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
71 if (ikari->GetTargetingMode().TargetsSingle()) {
72 battle->ActiveHeroTargets().SetSingle();
74 battle->ActiveHeroTargets().SetMultiple();
76 ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
80 if (input.JustPressed(Input::ACTION_B)) {
81 ctrl->PopState(); // return control to parent
83 if (input.JustPressed(Input::PAD_UP)) {
84 battle->GetIkariMenu().PreviousRow();
86 if (input.JustPressed(Input::PAD_RIGHT)) {
87 battle->GetIkariMenu().NextItem();
89 if (input.JustPressed(Input::PAD_DOWN)) {
90 battle->GetIkariMenu().NextRow();
92 if (input.JustPressed(Input::PAD_LEFT)) {
93 battle->GetIkariMenu().PreviousItem();
97 void SelectIkari::UpdateWorld(float deltaT) {
101 void SelectIkari::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 SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
110 const Frame *frame(battle->Res().selectFrame);
111 Point<int> position(frame->BorderWidth(), frame->BorderHeight());
112 int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
113 int height(battle->Res().normalFont->CharHeight() * 13);
114 frame->Draw(screen, position + offset, width, height);
117 void SelectIkari::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
118 const Resources &res(battle->Res());
120 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
121 2 * res.selectFrame->BorderHeight());
122 res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
125 void SelectIkari::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
126 const Resources &res(battle->Res());
128 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
129 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
130 battle->GetIkariMenu().Draw(screen, position + offset);