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 void SelectIkari::OnEnterState(SDL_Surface *screen) {
25 void SelectIkari::OnExitState(SDL_Surface *screen) {
29 void SelectIkari::OnResumeState(SDL_Surface *screen) {
30 if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
31 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::IKARI);
32 battle->ActiveHero().GetAttackChoice().SetItem(battle->ActiveHero().IkariMenu().Selected());
37 void SelectIkari::OnPauseState(SDL_Surface *screen) {
42 void SelectIkari::OnResize(int width, int height) {
47 void SelectIkari::HandleEvents(const Input &input) {
48 if (input.JustPressed(Input::ACTION_A)) {
49 if (battle->ActiveHero().IkariMenu().SelectedIsEnabled() && battle->ActiveHero().IkariMenu().Selected()->HasIkari()) {
50 AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
51 const Ikari *ikari(battle->ActiveHero().IkariMenu().Selected()->GetIkari());
52 ac.Selection().Reset();
53 if (ikari->GetTargetingMode().TargetsAlly()) {
54 ac.Selection().SelectHeroes();
56 ac.Selection().SelectMonsters();
58 if (ikari->GetTargetingMode().TargetsAll()) {
59 ac.SetType(AttackChoice::IKARI);
60 ac.SetItem(battle->ActiveHero().IkariMenu().Selected());
64 if (ikari->GetTargetingMode().TargetsSingle()) {
65 ac.Selection().SetSingle();
67 ac.Selection().SetMultiple();
69 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
73 if (input.JustPressed(Input::ACTION_B)) {
74 Ctrl().PopState(); // return control to parent
76 if (input.JustPressed(Input::PAD_UP)) {
77 battle->ActiveHero().IkariMenu().PreviousRow();
79 if (input.JustPressed(Input::PAD_RIGHT)) {
80 battle->ActiveHero().IkariMenu().NextItem();
82 if (input.JustPressed(Input::PAD_DOWN)) {
83 battle->ActiveHero().IkariMenu().NextRow();
85 if (input.JustPressed(Input::PAD_LEFT)) {
86 battle->ActiveHero().IkariMenu().PreviousItem();
90 void SelectIkari::UpdateWorld(Uint32 deltaT) {
94 void SelectIkari::Render(SDL_Surface *screen) {
95 parent->Render(screen);
96 Vector<int> offset(battle->CalculateScreenOffset(screen));
97 RenderFrame(screen, offset);
98 RenderHeadline(screen, offset);
99 RenderMenu(screen, offset);
102 void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
103 const Frame *frame(battle->Res().selectFrame);
104 Vector<int> position(frame->BorderSize());
105 int width(battle->Width() - 2 * frame->BorderWidth());
106 int height(battle->Res().normalFont->CharHeight() * 13);
107 frame->Draw(screen, position + offset, width, height);
110 void SelectIkari::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
111 const Resources &res(battle->Res());
112 Vector<int> position(
113 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
114 2 * res.selectFrame->BorderHeight());
115 res.normalFont->DrawString(res.ikariMenuHeadline, screen, position + offset);
118 void SelectIkari::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
119 const Resources &res(battle->Res());
120 Vector<int> position(
121 2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
122 2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
123 battle->ActiveHero().IkariMenu().Draw(screen, position + offset);