]> git.localhorst.tv Git - l2e.git/blob - CapsuleChangeMenu.cpp
cac2056aecab713fe075f0c5fb3205010cb0b996
[l2e.git] / CapsuleChangeMenu.cpp
1 #include "CapsuleChangeMenu.h"
2
3 #include "CapsuleMenu.h"
4 #include "Resources.h"
5 #include "../app/Application.h"
6 #include "../app/Input.h"
7 #include "../common/Inventory.h"
8 #include "../common/Item.h"
9 #include "../common/GameConfig.h"
10 #include "../common/GameState.h"
11 #include "../graphics/Font.h"
12 #include "../graphics/Frame.h"
13 #include "../graphics/Texture.h"
14
15 using app::Input;
16 using common::Capsule;
17 using common::Inventory;
18 using common::Item;
19 using geometry::Vector;
20 using graphics::Font;
21 using graphics::Frame;
22
23 namespace menu {
24
25 CapsuleChangeMenu::CapsuleChangeMenu(CapsuleMenu *parent)
26 : parent(parent) {
27
28 }
29
30
31 void CapsuleChangeMenu::OnEnterState(SDL_Surface *) {
32
33 }
34
35 void CapsuleChangeMenu::OnExitState(SDL_Surface *) {
36
37 }
38
39 void CapsuleChangeMenu::OnResumeState(SDL_Surface *) {
40
41 }
42
43 void CapsuleChangeMenu::OnPauseState(SDL_Surface *) {
44
45 }
46
47
48 void CapsuleChangeMenu::OnResize(int width, int height) {
49
50 }
51
52
53 void CapsuleChangeMenu::HandleEvents(const Input &input) {
54         if (input.JustPressed(Input::ACTION_B)) {
55                 Ctrl().PopState();
56         }
57 }
58
59 void CapsuleChangeMenu::UpdateWorld(float deltaT) {
60
61 }
62
63 void CapsuleChangeMenu::Render(SDL_Surface *screen) {
64         const Font &font(*parent->Res().statusFont);
65         const Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
66         const Vector<int> capsuleOffset(
67                         6 * font.CharWidth(),
68                         12 * font.CharHeight());
69         const Vector<int> infoOffset(
70                         12 * font.CharWidth(),
71                         2 * font.CharHeight() - font.CharHeight() / 8);
72         // TODO: wheel offset: top left, center, or center bottom?
73         const Vector<int> wheelOffset(
74                         6 * font.CharWidth(),
75                         19 * font.CharHeight() - font.CharHeight() / 8);
76         const Vector<int> classesOffset(
77                         12 * font.CharWidth(),
78                         13 * font.CharHeight() - font.CharHeight() / 8);
79         const Vector<int> menuOffset(
80                         font.CharWidth(),
81                         24 * font.CharHeight() - font.CharHeight() / 8);
82
83         parent->RenderBackground(screen);
84         parent->RenderCapsule(screen, offset + capsuleOffset);
85         parent->RenderInfo(screen, offset + infoOffset);
86         parent->RenderWheel(screen, offset + wheelOffset);
87         RenderClasses(screen, offset + classesOffset);
88         parent->RenderMenu(screen, offset + menuOffset);
89 }
90
91 void CapsuleChangeMenu::RenderClasses(SDL_Surface *screen, const Vector<int> &offset) const {
92         Vector<int> cursor(offset);
93
94         int numClasses = 0;
95         for (int i = 0; i < parent->Game().state->NumCapsules(); ++i) {
96                 if (numClasses < parent->Game().state->capsules[i].NumClasses()) {
97                         numClasses = parent->Game().state->capsules[i].NumClasses();
98                 }
99         }
100
101         parent->Res().capsuleSelectTopLeft->Draw(screen, cursor);
102         cursor.Y() += parent->Res().capsuleSelectTopLeft->Height();
103         Vector<int> target(
104                         cursor.X() + parent->Res().capsuleSelectTopLeft->Width(),
105                         cursor.Y() + numClasses * parent->Res().capsuleSelectLadder->Height());
106         parent->Res().capsuleSelectLeftRepeat->Render(screen, cursor, target);
107         cursor.Y() = target.Y();
108         parent->Res().capsuleSelectBottomLeft->Draw(screen, cursor);
109         cursor.X() += parent->Res().capsuleSelectTopLeft->Width();
110
111         for (int i = 0; i < parent->Game().state->NumCapsules(); ++i) {
112                 cursor.Y() = offset.Y();
113                 parent->Res().capsuleSelectTopRepeat->Draw(screen, cursor);
114                 cursor.Y() += parent->Res().capsuleSelectTopRepeat->Height();
115                 for (int j = numClasses - 1; j >= 0; --j) {
116                         parent->Res().capsuleSelectLadder->Draw(
117                                         screen, cursor,
118                                         j < parent->Game().state->capsules[i].MaxClass(), j);
119                         if (&parent->Game().state->capsules[i] == parent->Game().state->capsule
120                                         && parent->Game().state->capsules[i].CurrentClass() == j) {
121                                 parent->Res().capsuleSelectCursor->Draw(screen, cursor);
122                         }
123                         cursor.Y() += parent->Res().capsuleSelectLadder->Height();
124                 }
125                 parent->Res().capsuleSelectBottomRepeat->Draw(screen, cursor);
126                 if (parent->Game().state->capsules[i].AlignmentSprite()) {
127                         parent->Game().state->capsules[i].AlignmentSprite()->Draw(screen, cursor);
128                 }
129                 cursor.X() += parent->Res().capsuleSelectLadder->Width();
130         }
131
132         cursor.Y() = offset.Y();
133         parent->Res().capsuleSelectTopRight->Draw(screen, cursor);
134         cursor.Y() += parent->Res().capsuleSelectTopRight->Height();
135         target = Vector<int>(
136                         cursor.X() + parent->Res().capsuleSelectTopRight->Width(),
137                         cursor.Y() + numClasses * parent->Res().capsuleSelectLadder->Height());
138         parent->Res().capsuleSelectRightRepeat->Render(screen, cursor, target);
139         cursor.Y() = target.Y();
140         parent->Res().capsuleSelectBottomRight->Draw(screen, cursor);
141 }
142
143
144 int CapsuleChangeMenu::Width() const {
145         return parent->Width();
146 }
147
148 int CapsuleChangeMenu::Height() const {
149         return parent->Height();
150 }
151
152 const Capsule &CapsuleChangeMenu::GetCapsule() const {
153         return parent->GetCapsule();
154 }
155
156 }