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->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
40 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::IKARI);
41 battle->ActiveHero().GetAttackChoice().SetItem(battle->ActiveHero().IkariMenu().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->ActiveHero().IkariMenu().SelectedIsEnabled() && battle->ActiveHero().IkariMenu().Selected()->HasIkari()) {
59 AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
60 const Ikari *ikari(battle->ActiveHero().IkariMenu().Selected()->GetIkari());
61 ac.Selection().Reset();
62 if (ikari->GetTargetingMode().TargetsAlly()) {
63 ac.Selection().SelectHeroes();
65 ac.Selection().SelectMonsters();
67 if (ikari->GetTargetingMode().TargetsAll()) {
68 ac.SetType(AttackChoice::MAGIC);
69 // TODO: remove item from inventory
70 ac.SetItem(battle->ActiveHero().IkariMenu().Selected());
74 if (ikari->GetTargetingMode().TargetsSingle()) {
75 ac.Selection().SetSingle();
77 ac.Selection().SetMultiple();
79 ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
83 if (input.JustPressed(Input::ACTION_B)) {
84 ctrl->PopState(); // return control to parent
86 if (input.JustPressed(Input::PAD_UP)) {
87 battle->ActiveHero().IkariMenu().PreviousRow();
89 if (input.JustPressed(Input::PAD_RIGHT)) {
90 battle->ActiveHero().IkariMenu().NextItem();
92 if (input.JustPressed(Input::PAD_DOWN)) {
93 battle->ActiveHero().IkariMenu().NextRow();
95 if (input.JustPressed(Input::PAD_LEFT)) {
96 battle->ActiveHero().IkariMenu().PreviousItem();
100 void SelectIkari::UpdateWorld(float deltaT) {
104 void SelectIkari::Render(SDL_Surface *screen) {
105 parent->Render(screen);
106 Vector<int> offset(battle->CalculateScreenOffset(screen));
107 RenderFrame(screen, offset);
108 RenderHeadline(screen, offset);
109 RenderMenu(screen, offset);
112 void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
113 const Frame *frame(battle->Res().selectFrame);
114 Point<int> position(frame->BorderWidth(), frame->BorderHeight());
115 int width(battle->Width() - 2 * frame->BorderWidth());
116 int height(battle->Res().normalFont->CharHeight() * 13);
117 frame->Draw(screen, position + offset, width, height);
120 void SelectIkari::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
121 const Resources &res(battle->Res());
123 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
124 2 * res.selectFrame->BorderHeight());
125 res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
128 void SelectIkari::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
129 const Resources &res(battle->Res());
131 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
132 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
133 battle->ActiveHero().IkariMenu().Draw(screen, position + offset);