1 #include "CapsuleChangeMenu.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"
13 #include "../graphics/Texture.h"
16 using common::Capsule;
17 using common::Inventory;
19 using geometry::Vector;
21 using graphics::Frame;
25 CapsuleChangeMenu::CapsuleChangeMenu(CapsuleMenu *parent)
31 void CapsuleChangeMenu::OnEnterState(SDL_Surface *) {
35 void CapsuleChangeMenu::OnExitState(SDL_Surface *) {
39 void CapsuleChangeMenu::OnResumeState(SDL_Surface *) {
43 void CapsuleChangeMenu::OnPauseState(SDL_Surface *) {
48 void CapsuleChangeMenu::OnResize(int width, int height) {
53 void CapsuleChangeMenu::HandleEvents(const Input &input) {
54 if (input.JustPressed(Input::ACTION_B)) {
59 void CapsuleChangeMenu::UpdateWorld(float deltaT) {
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(
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(
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(
81 24 * font.CharHeight() - font.CharHeight() / 8);
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);
91 void CapsuleChangeMenu::RenderClasses(SDL_Surface *screen, const Vector<int> &offset) const {
92 Vector<int> cursor(offset);
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();
101 parent->Res().capsuleSelectTopLeft->Draw(screen, cursor);
102 cursor.Y() += parent->Res().capsuleSelectTopLeft->Height();
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();
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(
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);
123 cursor.Y() += parent->Res().capsuleSelectLadder->Height();
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);
129 cursor.X() += parent->Res().capsuleSelectLadder->Width();
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);
144 int CapsuleChangeMenu::Width() const {
145 return parent->Width();
148 int CapsuleChangeMenu::Height() const {
149 return parent->Height();
152 const Capsule &CapsuleChangeMenu::GetCapsule() const {
153 return parent->GetCapsule();