]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectSpell.cpp
introduced a small delay after flip if the screen is not a hardware surface
[l2e.git] / src / battle / states / SelectSpell.cpp
1 /*
2  * SelectSpell.cpp
3  *
4  *  Created on: Aug 8, 2012
5  *      Author: holy
6  */
7
8 #include "SelectSpell.h"
9
10 #include "SelectAttackType.h"
11 #include "SelectMoveAction.h"
12 #include "SelectTarget.h"
13 #include "../BattleState.h"
14 #include "../../app/Application.h"
15 #include "../../app/Input.h"
16 #include "../../common/Spell.h"
17 #include "../../graphics/Frame.h"
18
19 using app::Application;
20 using app::Input;
21 using common::Spell;
22 using geometry::Vector;
23 using graphics::Frame;
24
25 namespace battle {
26
27 void SelectSpell::OnEnterState(SDL_Surface *screen) {
28
29 }
30
31 void SelectSpell::OnExitState(SDL_Surface *screen) {
32
33 }
34
35 void SelectSpell::OnResumeState(SDL_Surface *screen) {
36         if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
37                 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::MAGIC);
38                 battle->ActiveHero().GetAttackChoice().SetSpell(battle->ActiveHero().SpellMenu().Selected());
39                 Ctrl().PopState();
40         }
41 }
42
43 void SelectSpell::OnPauseState(SDL_Surface *screen) {
44
45 }
46
47
48 void SelectSpell::OnResize(int width, int height) {
49
50 }
51
52
53 void SelectSpell::HandleEvents(const Input &input) {
54         if (input.JustPressed(Input::ACTION_A)) {
55                 if (battle->ActiveHero().SpellMenu().SelectedIsEnabled()) {
56                         AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
57                         const Spell *spell(battle->ActiveHero().SpellMenu().Selected());
58                         ac.Selection().Reset();
59                         if (spell->GetTargetingMode().TargetsAlly()) {
60                                 ac.Selection().SelectHeroes();
61                         } else {
62                                 ac.Selection().SelectMonsters();
63                         }
64                         if (spell->GetTargetingMode().TargetsAll()) {
65                                 ac.SetType(AttackChoice::MAGIC);
66                                 ac.SetSpell(spell);
67                                 battle->NextHero();
68                                 Ctrl().PopState();
69                         } else {
70                                 if (spell->GetTargetingMode().TargetsSingle()) {
71                                         ac.Selection().SetSingle();
72                                 } else {
73                                         ac.Selection().SetMultiple();
74                                 }
75                                 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().magicTargetCursor));
76                         }
77                 }
78         }
79         if (input.JustPressed(Input::ACTION_B)) {
80                 Ctrl().PopState(); // return control to parent
81         }
82         if (input.JustPressed(Input::PAD_UP)) {
83                 battle->ActiveHero().SpellMenu().PreviousRow();
84         }
85         if (input.JustPressed(Input::PAD_RIGHT)) {
86                 battle->ActiveHero().SpellMenu().NextItem();
87         }
88         if (input.JustPressed(Input::PAD_DOWN)) {
89                 battle->ActiveHero().SpellMenu().NextRow();
90         }
91         if (input.JustPressed(Input::PAD_LEFT)) {
92                 battle->ActiveHero().SpellMenu().PreviousItem();
93         }
94 }
95
96 void SelectSpell::UpdateWorld(float deltaT) {
97
98 }
99
100 void SelectSpell::Render(SDL_Surface *screen) {
101         parent->Render(screen);
102         Vector<int> offset(battle->CalculateScreenOffset(screen));
103         RenderFrame(screen, offset);
104         RenderHeadline(screen, offset);
105         RenderMenu(screen, offset);
106 }
107
108 void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
109         const Frame *frame(battle->Res().selectFrame);
110         Vector<int> position(frame->BorderSize());
111         int width(battle->Width() - 2 * frame->BorderWidth());
112         int height(battle->Res().normalFont->CharHeight() * 13);
113         frame->Draw(screen, position + offset, width, height);
114 }
115
116 void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
117         const Resources &res(battle->Res());
118         Vector<int> position(
119                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
120                         2 * res.selectFrame->BorderHeight());
121         res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
122 }
123
124 void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
125         const Resources &res(battle->Res());
126         Vector<int> position(
127                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
128                         2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
129         battle->ActiveHero().SpellMenu().Draw(screen, position + offset);
130 }
131
132 }