]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectItem.cpp
removed useless comments
[l2e.git] / src / battle / states / SelectItem.cpp
1 #include "SelectItem.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/Item.h"
9 #include "../../graphics/Frame.h"
10 #include "../../math/Vector.h"
11
12 using app::Application;
13 using app::Input;
14 using common::Item;
15 using math::Vector;
16 using graphics::Frame;
17
18 namespace battle {
19
20 void SelectItem::OnEnterState(SDL_Surface *screen) {
21
22 }
23
24 void SelectItem::OnExitState(SDL_Surface *screen) {
25
26 }
27
28 void SelectItem::OnResumeState(SDL_Surface *screen) {
29         if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
30                 battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::ITEM);
31                 battle->ActiveHero().GetAttackChoice().SetItem(battle->ItemMenu().Selected());
32                 Ctrl().PopState();
33         }
34 }
35
36 void SelectItem::OnPauseState(SDL_Surface *screen) {
37
38 }
39
40
41 void SelectItem::OnResize(int width, int height) {
42
43 }
44
45
46 void SelectItem::HandleEvents(const Input &input) {
47         if (input.JustPressed(Input::ACTION_A)) {
48                 if (battle->ItemMenu().SelectedIsEnabled()) {
49                         AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
50                         const Item *item(battle->ItemMenu().Selected());
51                         ac.Selection().Reset();
52                         if (item->GetTargetingMode().TargetsAlly()) {
53                                 ac.Selection().SelectHeroes();
54                         } else {
55                                 ac.Selection().SelectMonsters();
56                         }
57                         if (item->GetTargetingMode().TargetsAll()) {
58                                 ac.SetType(AttackChoice::ITEM);
59                                 ac.SetItem(item);
60                                 battle->NextHero();
61                                 Ctrl().PopState();
62                         } else {
63                                 if (item->GetTargetingMode().TargetsSingle()) {
64                                         ac.Selection().SetSingle();
65                                 } else {
66                                         ac.Selection().SetMultiple();
67                                 }
68                                 Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().itemTargetCursor));
69                         }
70                 }
71         }
72         if (input.JustPressed(Input::ACTION_B)) {
73                 Ctrl().PopState(); // return control to parent
74         }
75         if (input.JustPressed(Input::PAD_UP)) {
76                 battle->ItemMenu().PreviousRow();
77         }
78         if (input.JustPressed(Input::PAD_RIGHT)) {
79                 battle->ItemMenu().NextItem();
80         }
81         if (input.JustPressed(Input::PAD_DOWN)) {
82                 battle->ItemMenu().NextRow();
83         }
84         if (input.JustPressed(Input::PAD_LEFT)) {
85                 battle->ItemMenu().PreviousItem();
86         }
87 }
88
89 void SelectItem::UpdateWorld(Uint32 deltaT) {
90
91 }
92
93 void SelectItem::Render(SDL_Surface *screen) {
94         parent->Render(screen);
95         Vector<int> offset(battle->CalculateScreenOffset(screen));
96         RenderFrame(screen, offset);
97         RenderHeadline(screen, offset);
98         RenderMenu(screen, offset);
99 }
100
101 void SelectItem::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
102         const Frame *frame(battle->Res().selectFrame);
103         Vector<int> position(frame->BorderSize());
104         int width(battle->Width() - 2 * frame->BorderWidth());
105         int height(battle->Res().normalFont->CharHeight() * 13);
106         frame->Draw(screen, position + offset, width, height);
107 }
108
109 void SelectItem::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
110         const Resources &res(battle->Res());
111         Vector<int> position(
112                         2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
113                         2 * res.selectFrame->BorderHeight());
114         res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
115 }
116
117 void SelectItem::RenderMenu(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() + 2 * res.normalFont->CharHeight());
122         battle->ItemMenu().Draw(screen, position + offset);
123 }
124
125 }