]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectSpell.cpp
b1053d00eedf071cc2f52112b00b55a156a70482
[l2e.git] / src / battle / states / SelectSpell.cpp
1 #include "SelectSpell.h"
2
3 #include "SelectAttackType.h"
4 #include "SelectMoveAction.h"
5 #include "SelectTarget.h"
6 #include "../BattleState.h"
7 #include "../../app/Application.h"
8 #include "../../app/Input.h"
9 #include "../../common/Spell.h"
10 #include "../../graphics/Frame.h"
11 #include "../../math/Vector.h"
12
13 using app::Application;
14 using app::Input;
15 using common::Spell;
16 using math::Vector;
17 using graphics::Frame;
18
19 namespace battle {
20
21 void SelectSpell::OnEnterState(SDL_Surface *screen) {
22
23 }
24
25 void SelectSpell::OnExitState(SDL_Surface *screen) {
26
27 }
28
29 void SelectSpell::OnResumeState(SDL_Surface *screen) {
30         if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
31                 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::MAGIC);
32                 battle->ActiveHero().GetAttackChoice().SetSpell(battle->ActiveHero().SpellMenu().Selected());
33                 Ctrl().PopState();
34         }
35 }
36
37 void SelectSpell::OnPauseState(SDL_Surface *screen) {
38
39 }
40
41
42 void SelectSpell::OnResize(int width, int height) {
43
44 }
45
46
47 void SelectSpell::HandleEvents(const Input &input) {
48         if (input.JustPressed(Input::ACTION_A)) {
49                 if (battle->ActiveHero().SpellMenu().SelectedIsEnabled()) {
50                         AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
51                         const Spell *spell(battle->ActiveHero().SpellMenu().Selected());
52                         ac.Selection().Reset();
53                         if (spell->GetTargetingMode().TargetsAlly()) {
54                                 ac.Selection().SelectHeroes();
55                         } else {
56                                 ac.Selection().SelectMonsters();
57                         }
58                         if (spell->GetTargetingMode().TargetsAll()) {
59                                 ac.SetType(AttackChoice::MAGIC);
60                                 ac.SetSpell(spell);
61                                 battle->NextHero();
62                                 Ctrl().PopState();
63                         } else {
64                                 if (spell->GetTargetingMode().TargetsSingle()) {
65                                         ac.Selection().SetSingle();
66                                 } else {
67                                         ac.Selection().SetMultiple();
68                                 }
69                                 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().magicTargetCursor));
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().SpellMenu().PreviousRow();
78         }
79         if (input.JustPressed(Input::PAD_RIGHT)) {
80                 battle->ActiveHero().SpellMenu().NextItem();
81         }
82         if (input.JustPressed(Input::PAD_DOWN)) {
83                 battle->ActiveHero().SpellMenu().NextRow();
84         }
85         if (input.JustPressed(Input::PAD_LEFT)) {
86                 battle->ActiveHero().SpellMenu().PreviousItem();
87         }
88 }
89
90 void SelectSpell::UpdateWorld(Uint32 deltaT) {
91
92 }
93
94 void SelectSpell::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 SelectSpell::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 SelectSpell::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.spellMenuHeadline, screen, position + offset);
116 }
117
118 void SelectSpell::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().SpellMenu().Draw(screen, position + offset);
124 }
125
126 }