]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectIkari.cpp
53d2cbd462dc479578861f5a5a48d8966f101e5e
[l2e.git] / src / battle / states / SelectIkari.cpp
1 /*
2  * SelectIkari.cpp
3  *
4  *  Created on: Aug 9, 2012
5  *      Author: holy
6  */
7
8 #include "SelectIkari.h"
9
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"
18 #include "../../math/Vector.h"
19
20 using app::Application;
21 using app::Input;
22 using common::Ikari;
23 using math::Vector;
24 using graphics::Frame;
25
26 namespace battle {
27
28 void SelectIkari::OnEnterState(SDL_Surface *screen) {
29
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
51 }
52
53
54 void SelectIkari::HandleEvents(const Input &input) {
55         if (input.JustPressed(Input::ACTION_A)) {
56                 if (battle->ActiveHero().IkariMenu().SelectedIsEnabled() && battle->ActiveHero().IkariMenu().Selected()->HasIkari()) {
57                         AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
58                         const Ikari *ikari(battle->ActiveHero().IkariMenu().Selected()->GetIkari());
59                         ac.Selection().Reset();
60                         if (ikari->GetTargetingMode().TargetsAlly()) {
61                                 ac.Selection().SelectHeroes();
62                         } else {
63                                 ac.Selection().SelectMonsters();
64                         }
65                         if (ikari->GetTargetingMode().TargetsAll()) {
66                                 ac.SetType(AttackChoice::IKARI);
67                                 ac.SetItem(battle->ActiveHero().IkariMenu().Selected());
68                                 battle->NextHero();
69                                 Ctrl().PopState();
70                         } else {
71                                 if (ikari->GetTargetingMode().TargetsSingle()) {
72                                         ac.Selection().SetSingle();
73                                 } else {
74                                         ac.Selection().SetMultiple();
75                                 }
76                                 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
77                         }
78                 }
79         }
80         if (input.JustPressed(Input::ACTION_B)) {
81                 Ctrl().PopState(); // return control to parent
82         }
83         if (input.JustPressed(Input::PAD_UP)) {
84                 battle->ActiveHero().IkariMenu().PreviousRow();
85         }
86         if (input.JustPressed(Input::PAD_RIGHT)) {
87                 battle->ActiveHero().IkariMenu().NextItem();
88         }
89         if (input.JustPressed(Input::PAD_DOWN)) {
90                 battle->ActiveHero().IkariMenu().NextRow();
91         }
92         if (input.JustPressed(Input::PAD_LEFT)) {
93                 battle->ActiveHero().IkariMenu().PreviousItem();
94         }
95 }
96
97 void SelectIkari::UpdateWorld(Uint32 deltaT) {
98
99 }
100
101 void SelectIkari::Render(SDL_Surface *screen) {
102         parent->Render(screen);
103         Vector<int> offset(battle->CalculateScreenOffset(screen));
104         RenderFrame(screen, offset);
105         RenderHeadline(screen, offset);
106         RenderMenu(screen, offset);
107 }
108
109 void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
110         const Frame *frame(battle->Res().selectFrame);
111         Vector<int> position(frame->BorderSize());
112         int width(battle->Width() - 2 * frame->BorderWidth());
113         int height(battle->Res().normalFont->CharHeight() * 13);
114         frame->Draw(screen, position + offset, width, height);
115 }
116
117 void SelectIkari::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
118         const Resources &res(battle->Res());
119         Vector<int> position(
120                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
121                         2 * res.selectFrame->BorderHeight());
122         res.normalFont->DrawString(res.ikariMenuHeadline, screen, position + offset);
123 }
124
125 void SelectIkari::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
126         const Resources &res(battle->Res());
127         Vector<int> position(
128                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
129                         2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
130         battle->ActiveHero().IkariMenu().Draw(screen, position + offset);
131 }
132
133 }