]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectIkari.cpp
removed useless comments
[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 void SelectIkari::OnEnterState(SDL_Surface *screen) {
22
23 }
24
25 void SelectIkari::OnExitState(SDL_Surface *screen) {
26
27 }
28
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());
33                 Ctrl().PopState();
34         }
35 }
36
37 void SelectIkari::OnPauseState(SDL_Surface *screen) {
38
39 }
40
41
42 void SelectIkari::OnResize(int width, int height) {
43
44 }
45
46
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();
55                         } else {
56                                 ac.Selection().SelectMonsters();
57                         }
58                         if (ikari->GetTargetingMode().TargetsAll()) {
59                                 ac.SetType(AttackChoice::IKARI);
60                                 ac.SetItem(battle->ActiveHero().IkariMenu().Selected());
61                                 battle->NextHero();
62                                 Ctrl().PopState();
63                         } else {
64                                 if (ikari->GetTargetingMode().TargetsSingle()) {
65                                         ac.Selection().SetSingle();
66                                 } else {
67                                         ac.Selection().SetMultiple();
68                                 }
69                                 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
70                         }
71                 }
72         }
73         if (input.JustPressed(Input::ACTION_B)) {
74                 Ctrl().PopState(); // return control to parent
75         }
76         if (input.JustPressed(Input::PAD_UP)) {
77                 battle->ActiveHero().IkariMenu().PreviousRow();
78         }
79         if (input.JustPressed(Input::PAD_RIGHT)) {
80                 battle->ActiveHero().IkariMenu().NextItem();
81         }
82         if (input.JustPressed(Input::PAD_DOWN)) {
83                 battle->ActiveHero().IkariMenu().NextRow();
84         }
85         if (input.JustPressed(Input::PAD_LEFT)) {
86                 battle->ActiveHero().IkariMenu().PreviousItem();
87         }
88 }
89
90 void SelectIkari::UpdateWorld(Uint32 deltaT) {
91
92 }
93
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);
100 }
101
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);
108 }
109
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);
116 }
117
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);
124 }
125
126 }