]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectIkari.cpp
relocate scripts
[l2e.git] / src / battle / states / SelectIkari.cpp
1 #include "SelectIkari.h"
2
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"
12
13 using app::Application;
14 using app::Input;
15 using common::Ikari;
16 using math::Vector;
17 using graphics::Frame;
18
19 namespace battle {
20
21 SelectIkari::SelectIkari(Battle *battle, SelectAttackType *parent)
22 : battle(battle)
23 , parent(parent) {
24
25 }
26
27
28 void SelectIkari::OnEnterState(SDL_Surface *screen) {
29         OnResize(screen->w, screen->h);
30 }
31
32 void SelectIkari::OnExitState(SDL_Surface *screen) {
33
34 }
35
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());
40                 Ctrl().PopState();
41         }
42 }
43
44 void SelectIkari::OnPauseState(SDL_Surface *screen) {
45
46 }
47
48
49 void SelectIkari::OnResize(int width, int height) {
50         const Vector<int> offset = parent->ScreenOffset();
51
52         const Resources &res = parent->Res();
53         const Frame &frame = *res.selectFrame;
54
55         framePosition = offset + frame.BorderSize();
56         frameSize = Vector<int>(
57                         parent->Width() - 2 * frame.BorderWidth(),
58                         res.normalFont->CharHeight() * 13);
59
60         headlinePosition = offset + Vector<int>(
61                         2 * frame.BorderWidth() + res.normalFont->CharWidth(),
62                         2 * frame.BorderHeight());
63
64         menuPosition = offset + Vector<int>(
65                         2 * frame.BorderWidth() + res.normalFont->CharWidth(),
66                         2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
67 }
68
69
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();
78                         } else {
79                                 ac.Selection().SelectMonsters();
80                         }
81                         if (ikari->GetTargetingMode().TargetsAll()) {
82                                 ac.SetType(AttackChoice::IKARI);
83                                 ac.SetItem(battle->ActiveHero().IkariMenu().Selected());
84                                 battle->NextHero();
85                                 Ctrl().PopState();
86                         } else {
87                                 if (ikari->GetTargetingMode().TargetsSingle()) {
88                                         ac.Selection().SetSingle();
89                                 } else {
90                                         ac.Selection().SetMultiple();
91                                 }
92                                 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? parent->Res().magicTargetCursor : parent->Res().weaponTargetCursor));
93                         }
94                 }
95         }
96         if (input.JustPressed(Input::ACTION_B)) {
97                 Ctrl().PopState(); // return control to parent
98         }
99         if (input.JustPressed(Input::PAD_UP)) {
100                 battle->ActiveHero().IkariMenu().PreviousRow();
101         }
102         if (input.JustPressed(Input::PAD_RIGHT)) {
103                 battle->ActiveHero().IkariMenu().NextItem();
104         }
105         if (input.JustPressed(Input::PAD_DOWN)) {
106                 battle->ActiveHero().IkariMenu().NextRow();
107         }
108         if (input.JustPressed(Input::PAD_LEFT)) {
109                 battle->ActiveHero().IkariMenu().PreviousItem();
110         }
111 }
112
113 void SelectIkari::UpdateWorld(Uint32 deltaT) {
114
115 }
116
117 void SelectIkari::Render(SDL_Surface *screen) {
118         parent->Render(screen);
119         RenderFrame(screen);
120         RenderHeadline(screen);
121         RenderMenu(screen);
122 }
123
124 void SelectIkari::RenderFrame(SDL_Surface *screen) {
125         const Frame &frame = *parent->Res().selectFrame;
126         frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
127 }
128
129 void SelectIkari::RenderHeadline(SDL_Surface *screen) {
130         const Resources &res = parent->Res();
131         res.normalFont->DrawString(res.ikariMenuHeadline, screen, headlinePosition);
132 }
133
134 void SelectIkari::RenderMenu(SDL_Surface *screen) {
135         battle->ActiveHero().IkariMenu().Draw(screen, menuPosition);
136 }
137
138 }