]> git.localhorst.tv Git - l2e.git/blob - src/menu/CapsuleNameMenu.cpp
14acd461fa2e491b8ec86686bb5c26b960d1a668
[l2e.git] / src / menu / CapsuleNameMenu.cpp
1 #include "CapsuleNameMenu.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
14 #include <cstring>
15
16 using app::Input;
17 using common::Capsule;
18 using common::Inventory;
19 using common::Item;
20 using geometry::Vector;
21 using graphics::Font;
22 using graphics::Frame;
23
24 namespace menu {
25
26 CapsuleNameMenu::CapsuleNameMenu(CapsuleMenu *parent)
27 : parent(parent)
28 , cursor(5) {
29         std::strncpy(buffer, GetCapsule().Name(), 6);
30         buffer[5] = '\0';
31 }
32
33
34 void CapsuleNameMenu::OnEnterState(SDL_Surface *) {
35
36 }
37
38 void CapsuleNameMenu::OnExitState(SDL_Surface *) {
39
40 }
41
42 void CapsuleNameMenu::OnResumeState(SDL_Surface *) {
43
44 }
45
46 void CapsuleNameMenu::OnPauseState(SDL_Surface *) {
47
48 }
49
50
51 void CapsuleNameMenu::OnResize(int width, int height) {
52
53 }
54
55
56 void CapsuleNameMenu::HandleEvents(const Input &input) {
57         if (input.JustPressed(Input::START)) {
58                 Ctrl().PopState();
59         }
60 }
61
62 void CapsuleNameMenu::UpdateWorld(float deltaT) {
63
64 }
65
66 void CapsuleNameMenu::Render(SDL_Surface *screen) {
67         const Font &font(*parent->Res().statusFont);
68         const Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
69         const Vector<int> nameOffset(
70                         4 * font.CharWidth(),
71                         4 * font.CharHeight() - font.CharHeight() / 8);
72         const Vector<int> alphaOffset(
73                         4 * font.CharWidth(),
74                         7 * font.CharHeight() - font.CharHeight() / 8);
75
76         parent->RenderBackground(screen);
77         RenderName(screen, offset + nameOffset);
78         RenderAlphabet(screen, offset + alphaOffset);
79 }
80
81 void CapsuleNameMenu::RenderName(SDL_Surface *screen, const Vector<int> &offset) const {
82         const Font &font(*parent->Res().normalFont);
83         const Frame &frame(*parent->Res().statusFrame);
84         const Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
85         const Vector<int> namebgOffset(8 * font.CharWidth(), 0);
86         const Vector<int> nameOffset(13 * font.CharWidth(), font.CharHeight());
87
88         frame.Draw(screen, offset, 8 * font.CharWidth(), 3 * font.CharHeight());
89         font.DrawString(parent->Res().capsuleNameLabel, screen, offset + labelOffset, 5);
90         frame.Draw(screen, offset + namebgOffset, 16 * font.CharWidth(), 3 * font.CharHeight());
91         font.DrawString(buffer, screen, offset + nameOffset, 5);
92 }
93
94 void CapsuleNameMenu::RenderAlphabet(SDL_Surface *screen, const Vector<int> &offset) const {
95         const Font &font(*parent->Res().normalFont);
96         const Frame &frame(*parent->Res().statusFrame);
97
98         frame.Draw(screen, offset, 24 * font.CharWidth(), 17 * font.CharHeight());
99 }
100
101
102 int CapsuleNameMenu::Width() const {
103         return parent->Width();
104 }
105
106 int CapsuleNameMenu::Height() const {
107         return parent->Height();
108 }
109
110 const Capsule &CapsuleNameMenu::GetCapsule() const {
111         return parent->GetCapsule();
112 }
113
114 }