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 "../../graphics/Frame.h"
19 using app::Application;
22 using geometry::Vector;
23 using graphics::Frame;
27 void SelectIkari::EnterState(Application &c, SDL_Surface *screen) {
31 void SelectIkari::ExitState(Application &c, SDL_Surface *screen) {
35 void SelectIkari::ResumeState(Application &ctrl, SDL_Surface *screen) {
36 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
37 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::IKARI);
38 battle->ActiveHero().GetAttackChoice().SetItem(battle->ActiveHero().IkariMenu().Selected());
43 void SelectIkari::PauseState(Application &ctrl, SDL_Surface *screen) {
48 void SelectIkari::Resize(int width, int height) {
53 void SelectIkari::HandleEvents(const Input &input) {
54 if (input.JustPressed(Input::ACTION_A)) {
55 if (battle->ActiveHero().IkariMenu().SelectedIsEnabled() && battle->ActiveHero().IkariMenu().Selected()->HasIkari()) {
56 AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
57 const Ikari *ikari(battle->ActiveHero().IkariMenu().Selected()->GetIkari());
58 ac.Selection().Reset();
59 if (ikari->GetTargetingMode().TargetsAlly()) {
60 ac.Selection().SelectHeroes();
62 ac.Selection().SelectMonsters();
64 if (ikari->GetTargetingMode().TargetsAll()) {
65 ac.SetType(AttackChoice::IKARI);
66 ac.SetItem(battle->ActiveHero().IkariMenu().Selected());
70 if (ikari->GetTargetingMode().TargetsSingle()) {
71 ac.Selection().SetSingle();
73 ac.Selection().SetMultiple();
75 ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
79 if (input.JustPressed(Input::ACTION_B)) {
80 ctrl->PopState(); // return control to parent
82 if (input.JustPressed(Input::PAD_UP)) {
83 battle->ActiveHero().IkariMenu().PreviousRow();
85 if (input.JustPressed(Input::PAD_RIGHT)) {
86 battle->ActiveHero().IkariMenu().NextItem();
88 if (input.JustPressed(Input::PAD_DOWN)) {
89 battle->ActiveHero().IkariMenu().NextRow();
91 if (input.JustPressed(Input::PAD_LEFT)) {
92 battle->ActiveHero().IkariMenu().PreviousItem();
96 void SelectIkari::UpdateWorld(float deltaT) {
100 void SelectIkari::Render(SDL_Surface *screen) {
101 parent->Render(screen);
102 Vector<int> offset(battle->CalculateScreenOffset(screen));
103 RenderFrame(screen, offset);
104 RenderHeadline(screen, offset);
105 RenderMenu(screen, offset);
108 void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
109 const Frame *frame(battle->Res().selectFrame);
110 Vector<int> position(frame->BorderSize());
111 int width(battle->Width() - 2 * frame->BorderWidth());
112 int height(battle->Res().normalFont->CharHeight() * 13);
113 frame->Draw(screen, position + offset, width, height);
116 void SelectIkari::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
117 const Resources &res(battle->Res());
118 Vector<int> position(
119 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
120 2 * res.selectFrame->BorderHeight());
121 res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
124 void SelectIkari::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
125 const Resources &res(battle->Res());
126 Vector<int> position(
127 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
128 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
129 battle->ActiveHero().IkariMenu().Draw(screen, position + offset);