1 #include "CapsuleMenu.h"
3 #include "CapsuleChangeMenu.h"
4 #include "CapsuleFeedMenu.h"
5 #include "CapsuleNameMenu.h"
8 #include "../app/Application.h"
9 #include "../app/Input.h"
10 #include "../common/GameConfig.h"
11 #include "../common/GameState.h"
12 #include "../common/Spell.h"
13 #include "../common/Stats.h"
14 #include "../graphics/Font.h"
15 #include "../graphics/Frame.h"
16 #include "../graphics/Texture.h"
19 using common::Capsule;
21 using geometry::Vector;
23 using graphics::Frame;
27 CapsuleMenu::CapsuleMenu(PartyMenu *parent)
29 , menu(*Res().capsuleMenuProperties) {
30 menu.Add(Res().capsuleFeedLabel, CHOICE_FEED);
31 menu.Add(Res().capsuleChangeLabel, CHOICE_CHANGE);
32 menu.Add(Res().capsuleNameLabel, CHOICE_NAME);
36 void CapsuleMenu::OnEnterState(SDL_Surface *) {
40 void CapsuleMenu::OnExitState(SDL_Surface *) {
44 void CapsuleMenu::OnResumeState(SDL_Surface *) {
48 void CapsuleMenu::OnPauseState(SDL_Surface *) {
53 void CapsuleMenu::OnResize(int width, int height) {
58 void CapsuleMenu::HandleEvents(const Input &input) {
59 if (input.JustPressed(Input::PAD_LEFT)) {
62 if (input.JustPressed(Input::PAD_RIGHT)) {
66 if (input.JustPressed(Input::ACTION_A)) {
67 switch (menu.Selected()) {
69 Ctrl().PushState(new CapsuleFeedMenu(this));
73 Ctrl().PushState(new CapsuleChangeMenu(this));
77 Ctrl().PushState(new CapsuleNameMenu(this));
81 } else if (input.JustPressed(Input::ACTION_B)) {
86 void CapsuleMenu::UpdateWorld(float deltaT) {
90 void CapsuleMenu::Render(SDL_Surface *screen) {
91 const Font &font(*Res().statusFont);
92 const Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
93 const Vector<int> capsuleOffset(
95 12 * font.CharHeight());
96 const Vector<int> infoOffset(
97 12 * font.CharWidth(),
98 2 * font.CharHeight() - font.CharHeight() / 8);
99 // TODO: wheel offset: top left, center, or center bottom?
100 const Vector<int> wheelOffset(
101 6 * font.CharWidth(),
102 19 * font.CharHeight() - font.CharHeight() / 8);
103 const Vector<int> statsOffset(
104 12 * font.CharWidth(),
105 15 * font.CharHeight() - font.CharHeight() / 8);
106 const Vector<int> menuOffset(
108 24 * font.CharHeight() - font.CharHeight() / 8);
110 RenderBackground(screen);
111 RenderCapsule(screen, offset + capsuleOffset);
112 RenderInfo(screen, offset + infoOffset);
113 RenderWheel(screen, offset + wheelOffset);
114 RenderStats(screen, offset + statsOffset);
115 RenderMenu(screen, offset + menuOffset);
118 void CapsuleMenu::RenderBackground(SDL_Surface *screen) const {
119 Res().capsulebg->Render(screen, Vector<int>(), Vector<int>(screen->w, screen->h));
122 void CapsuleMenu::RenderCapsule(SDL_Surface *screen, const Vector<int> &offset) const {
123 GetCapsule().BattleSprite()->DrawCenterBottom(screen, offset);
126 void CapsuleMenu::RenderInfo(SDL_Surface *screen, const Vector<int> &offset) const {
127 const Capsule &capsule(GetCapsule());
128 const Font &font(*Res().statusFont);
129 const Vector<int> delimiterOffset(5 * font.CharWidth(), 0);
130 const Vector<int> valueOffset(6 * font.CharWidth(), 0);
131 const Vector<int> lineBreak(0, font.CharHeight() + font.CharHeight() / 2);
132 Vector<int> lineHead(offset);
134 font.DrawString(Res().capsuleNameLabel, screen, lineHead, 5);
135 font.DrawChar(':', screen, lineHead + delimiterOffset);
136 font.DrawString(capsule.Name(), screen, lineHead + valueOffset);
138 lineHead += lineBreak;
139 font.DrawString(Res().capsuleClassLabel, screen, lineHead, 5);
140 font.DrawChar(':', screen, lineHead + delimiterOffset);
141 font.DrawString(capsule.ClassName(), screen, lineHead + valueOffset);
143 lineHead += lineBreak;
144 font.DrawString(Res().capsuleAlignmentLabel, screen, lineHead, 5);
145 font.DrawChar(':', screen, lineHead + delimiterOffset);
146 font.DrawString(capsule.Alignment(), screen, lineHead + valueOffset);
148 lineHead += lineBreak;
149 font.DrawString(Res().capsuleTribeLabel, screen, lineHead, 5);
150 font.DrawChar(':', screen, lineHead + delimiterOffset);
151 font.DrawString(capsule.Tribe(), screen, lineHead + valueOffset);
153 lineHead += lineBreak;
154 font.DrawString(Res().capsuleAttack1Label, screen, lineHead, 5);
155 font.DrawChar(':', screen, lineHead + delimiterOffset);
156 if (capsule.Attack1()) {
157 font.DrawString(capsule.Attack1()->Name(), screen, lineHead + valueOffset);
159 font.DrawString(Res().capsuleNoAttackText, screen, lineHead + valueOffset);
162 lineHead += lineBreak;
163 font.DrawString(Res().capsuleAttack1Label, screen, lineHead, 5);
164 font.DrawChar(':', screen, lineHead + delimiterOffset);
165 if (capsule.Attack2()) {
166 font.DrawString(capsule.Attack2()->Name(), screen, lineHead + valueOffset);
168 font.DrawString(Res().capsuleNoAttackText, screen, lineHead + valueOffset);
171 lineHead += lineBreak;
172 font.DrawString(Res().capsuleAttack1Label, screen, lineHead, 5);
173 font.DrawChar(':', screen, lineHead + delimiterOffset);
174 if (capsule.Attack3()) {
175 font.DrawString(capsule.Attack3()->Name(), screen, lineHead + valueOffset);
177 font.DrawString(Res().capsuleNoAttackText, screen, lineHead + valueOffset);
181 void CapsuleMenu::RenderWheel(SDL_Surface *screen, const Vector<int> &offset) const {
182 Res().capsuleAlignmentWheel->DrawCenter(screen, offset);
183 Res().capsuleAlignmentCursor->DrawCenter(screen, offset + Game().state->capsule->AlignmentOffset());
186 void CapsuleMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
187 const Capsule &capsule(GetCapsule());
188 Stats stats(capsule.GetStats());
189 const Font &font(*Res().statusFont);
190 const Vector<int> lineBreak(0, font.CharHeight());
191 Vector<int> lineHead(offset);
193 RenderStatsLine(screen, lineHead, Res().hpLabel, capsule.MaxHealth());
194 lineHead += lineBreak;
195 RenderStatsLine(screen, lineHead, Res().atpLabel, stats.Attack());
196 lineHead += lineBreak;
197 RenderStatsLine(screen, lineHead, Res().dfpLabel, stats.Defense());
198 lineHead += lineBreak;
199 RenderStatsLine(screen, lineHead, Res().strLabel, stats.Strength());
200 lineHead += lineBreak;
201 RenderStatsLine(screen, lineHead, Res().aglLabel, stats.Agility());
202 lineHead += lineBreak;
203 RenderStatsLine(screen, lineHead, Res().intLabel, stats.Intelligence());
204 lineHead += lineBreak;
205 RenderStatsLine(screen, lineHead, Res().gutLabel, stats.Gut());
206 lineHead += lineBreak;
207 RenderStatsLine(screen, lineHead, Res().mgrLabel, stats.MagicResistance());
209 lineHead = offset + Vector<int>(18 * font.CharWidth(), 0);
210 font.DrawStringRight(Res().levelLabel, screen, lineHead);
211 lineHead += lineBreak;
212 font.DrawNumberRight(capsule.Level(), screen, lineHead);
213 lineHead += 2 * lineBreak;
214 font.DrawStringRight(Res().experienceLabel, screen, lineHead);
215 lineHead += lineBreak;
216 font.DrawNumberRight(capsule.Experience(), screen, lineHead);
217 lineHead += 2 * lineBreak;
218 font.DrawStringRight(Res().nextLevelLabel, screen, lineHead);
219 lineHead += lineBreak;
220 font.DrawNumberRight(capsule.NextLevel(), screen, lineHead);
223 void CapsuleMenu::RenderStatsLine(SDL_Surface *screen, const geometry::Vector<int> &offset, const char *name, int value) const {
224 const Font &font(*Res().statusFont);
225 const Vector<int> numberOffset(4 * font.CharWidth(), 0);
227 font.DrawString(name, screen, offset, 4);
228 font.DrawNumber(value, screen, offset + numberOffset, 3);
231 void CapsuleMenu::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) const {
232 const Font &font(*Res().normalFont);
233 const Frame &frame(*Res().statusFrame);
234 const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight());
236 frame.Draw(screen, offset, 30 * font.CharWidth(), 3 * font.CharHeight());
237 menu.Draw(screen, offset + menuOffset);
241 common::GameConfig &CapsuleMenu::Game() {
242 return parent->Game();
245 const common::GameConfig &CapsuleMenu::Game() const {
246 return parent->Game();
249 Resources &CapsuleMenu::Res() {
250 return parent->Res();
253 const Resources &CapsuleMenu::Res() const {
254 return parent->Res();
258 int CapsuleMenu::Width() const {
259 return parent->Width();
262 int CapsuleMenu::Height() const {
263 return parent->Height();
266 Capsule &CapsuleMenu::GetCapsule() {
267 return *Game().state->capsule;
270 const Capsule &CapsuleMenu::GetCapsule() const {
271 return *Game().state->capsule;