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->ActiveHeroAttackChoice().Selection().HasSelected()) {
40 battle->ActiveHeroAttackChoice().SetType(AttackChoice::IKARI);
41 battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
46 void SelectIkari::PauseState(Application &ctrl, SDL_Surface *screen) {
51 void SelectIkari::Resize(int width, int height) {
56 void SelectIkari::HandleEvents(const Input &input) {
57 if (input.JustPressed(Input::ACTION_A)) {
58 if (battle->GetIkariMenu().SelectedIsEnabled() && battle->GetIkariMenu().Selected()->HasIkari()) {
59 const Ikari *ikari(battle->GetIkariMenu().Selected()->GetIkari());
60 battle->ActiveHeroAttackChoice().Selection().Reset();
61 if (ikari->GetTargetingMode().TargetsAlly()) {
62 battle->ActiveHeroAttackChoice().Selection().SelectHeroes();
64 battle->ActiveHeroAttackChoice().Selection().SelectEnemies();
66 if (ikari->GetTargetingMode().TargetsAll()) {
67 battle->ActiveHeroAttackChoice().SetType(AttackChoice::MAGIC);
68 // TODO: remove item from inventory
69 battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
73 if (ikari->GetTargetingMode().TargetsSingle()) {
74 battle->ActiveHeroAttackChoice().Selection().SetSingle();
76 battle->ActiveHeroAttackChoice().Selection().SetMultiple();
78 ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
82 if (input.JustPressed(Input::ACTION_B)) {
83 ctrl->PopState(); // return control to parent
85 if (input.JustPressed(Input::PAD_UP)) {
86 battle->GetIkariMenu().PreviousRow();
88 if (input.JustPressed(Input::PAD_RIGHT)) {
89 battle->GetIkariMenu().NextItem();
91 if (input.JustPressed(Input::PAD_DOWN)) {
92 battle->GetIkariMenu().NextRow();
94 if (input.JustPressed(Input::PAD_LEFT)) {
95 battle->GetIkariMenu().PreviousItem();
99 void SelectIkari::UpdateWorld(float deltaT) {
103 void SelectIkari::Render(SDL_Surface *screen) {
104 parent->Render(screen);
105 Vector<int> offset(battle->CalculateScreenOffset(screen));
106 RenderFrame(screen, offset);
107 RenderHeadline(screen, offset);
108 RenderMenu(screen, offset);
111 void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
112 const Frame *frame(battle->Res().selectFrame);
113 Point<int> position(frame->BorderWidth(), frame->BorderHeight());
114 int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
115 int height(battle->Res().normalFont->CharHeight() * 13);
116 frame->Draw(screen, position + offset, width, height);
119 void SelectIkari::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
120 const Resources &res(battle->Res());
122 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
123 2 * res.selectFrame->BorderHeight());
124 res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
127 void SelectIkari::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
128 const Resources &res(battle->Res());
130 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
131 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
132 battle->GetIkariMenu().Draw(screen, position + offset);