1 #include "SelectIkari.h"
3 #include "SelectAttackType.h"
4 #include "SelectTarget.h"
5 #include "../BattleState.h"
6 #include "../../app/Application.h"
7 #include "../../app/Input.h"
8 #include "../../common/Ikari.h"
9 #include "../../common/Item.h"
10 #include "../../graphics/Frame.h"
11 #include "../../math/Vector.h"
13 using app::Application;
17 using graphics::Frame;
21 SelectIkari::SelectIkari(Battle *battle, SelectAttackType *parent)
28 void SelectIkari::OnEnterState(SDL_Surface *screen) {
29 OnResize(screen->w, screen->h);
32 void SelectIkari::OnExitState(SDL_Surface *screen) {
36 void SelectIkari::OnResumeState(SDL_Surface *screen) {
37 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
38 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::IKARI);
39 battle->ActiveHero().GetAttackChoice().SetItem(battle->ActiveHero().IkariMenu().Selected());
44 void SelectIkari::OnPauseState(SDL_Surface *screen) {
49 void SelectIkari::OnResize(int width, int height) {
50 const Vector<int> offset = parent->ScreenOffset();
52 const Resources &res = parent->Res();
53 const Frame &frame = *res.selectFrame;
55 framePosition = offset + frame.BorderSize();
56 frameSize = Vector<int>(
57 parent->Width() - 2 * frame.BorderWidth(),
58 res.normalFont->CharHeight() * 13);
60 headlinePosition = offset + Vector<int>(
61 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
62 2 * frame.BorderHeight());
64 menuPosition = offset + Vector<int>(
65 2 * frame.BorderWidth() + res.normalFont->CharWidth(),
66 2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
70 void SelectIkari::HandleEvents(const Input &input) {
71 if (input.JustPressed(Input::ACTION_A)) {
72 if (battle->ActiveHero().IkariMenu().SelectedIsEnabled() && battle->ActiveHero().IkariMenu().Selected()->HasIkari()) {
73 AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
74 const Ikari *ikari(battle->ActiveHero().IkariMenu().Selected()->GetIkari());
75 ac.Selection().Reset();
76 if (ikari->GetTargetingMode().TargetsAlly()) {
77 ac.Selection().SelectHeroes();
79 ac.Selection().SelectMonsters();
81 if (ikari->GetTargetingMode().TargetsAll()) {
82 ac.SetType(AttackChoice::IKARI);
83 ac.SetItem(battle->ActiveHero().IkariMenu().Selected());
87 if (ikari->GetTargetingMode().TargetsSingle()) {
88 ac.Selection().SetSingle();
90 ac.Selection().SetMultiple();
92 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? parent->Res().magicTargetCursor : parent->Res().weaponTargetCursor));
96 if (input.JustPressed(Input::ACTION_B)) {
97 Ctrl().PopState(); // return control to parent
99 if (input.JustPressed(Input::PAD_UP)) {
100 battle->ActiveHero().IkariMenu().PreviousRow();
102 if (input.JustPressed(Input::PAD_RIGHT)) {
103 battle->ActiveHero().IkariMenu().NextItem();
105 if (input.JustPressed(Input::PAD_DOWN)) {
106 battle->ActiveHero().IkariMenu().NextRow();
108 if (input.JustPressed(Input::PAD_LEFT)) {
109 battle->ActiveHero().IkariMenu().PreviousItem();
113 void SelectIkari::UpdateWorld(Uint32 deltaT) {
117 void SelectIkari::Render(SDL_Surface *screen) {
118 parent->Render(screen);
120 RenderHeadline(screen);
124 void SelectIkari::RenderFrame(SDL_Surface *screen) {
125 const Frame &frame = *parent->Res().selectFrame;
126 frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
129 void SelectIkari::RenderHeadline(SDL_Surface *screen) {
130 const Resources &res = parent->Res();
131 res.normalFont->DrawString(res.ikariMenuHeadline, screen, headlinePosition);
134 void SelectIkari::RenderMenu(SDL_Surface *screen) {
135 battle->ActiveHero().IkariMenu().Draw(screen, menuPosition);