1 #include "CapsuleNameMenu.h"
3 #include "CapsuleMenu.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"
17 using common::Capsule;
18 using common::Inventory;
20 using geometry::Vector;
22 using graphics::Frame;
26 CapsuleNameMenu::CapsuleNameMenu(CapsuleMenu *parent)
29 std::strncpy(buffer, GetCapsule().Name(), 6);
34 void CapsuleNameMenu::OnEnterState(SDL_Surface *) {
38 void CapsuleNameMenu::OnExitState(SDL_Surface *) {
42 void CapsuleNameMenu::OnResumeState(SDL_Surface *) {
46 void CapsuleNameMenu::OnPauseState(SDL_Surface *) {
51 void CapsuleNameMenu::OnResize(int width, int height) {
56 void CapsuleNameMenu::HandleEvents(const Input &input) {
57 if (input.JustPressed(Input::START)) {
62 void CapsuleNameMenu::UpdateWorld(float deltaT) {
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(
71 4 * font.CharHeight() - font.CharHeight() / 8);
72 const Vector<int> alphaOffset(
74 7 * font.CharHeight() - font.CharHeight() / 8);
76 parent->RenderBackground(screen);
77 RenderName(screen, offset + nameOffset);
78 RenderAlphabet(screen, offset + alphaOffset);
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());
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);
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);
98 frame.Draw(screen, offset, 24 * font.CharWidth(), 17 * font.CharHeight());
102 int CapsuleNameMenu::Width() const {
103 return parent->Width();
106 int CapsuleNameMenu::Height() const {
107 return parent->Height();
110 const Capsule &CapsuleNameMenu::GetCapsule() const {
111 return parent->GetCapsule();