4 * Created on: Oct 22, 2012
8 #include "StatusMenu.h"
10 #include "HeroStatus.h"
11 #include "PartyMenu.h"
12 #include "Resources.h"
13 #include "../app/Application.h"
14 #include "../app/Input.h"
15 #include "../common/GameConfig.h"
16 #include "../common/GameState.h"
17 #include "../common/Hero.h"
18 #include "../common/Item.h"
19 #include "../common/Stats.h"
20 #include "../graphics/Font.h"
21 #include "../graphics/Frame.h"
27 using geometry::Vector;
29 using graphics::Frame;
33 StatusMenu::StatusMenu(PartyMenu *parent, int cursor)
36 , menu(*parent->Res().statusMenuProperties) {
37 menu.Add(parent->Res().nextLabel, 0);
38 menu.Add(parent->Res().returnLabel, 1);
42 void StatusMenu::OnEnterState(SDL_Surface *) {
46 void StatusMenu::OnExitState(SDL_Surface *) {
50 void StatusMenu::OnResumeState(SDL_Surface *) {
54 void StatusMenu::OnPauseState(SDL_Surface *) {
59 void StatusMenu::OnResize(int width, int height) {
64 void StatusMenu::HandleEvents(const Input &input) {
65 if (input.JustPressed(Input::SHOULDER_RIGHT)) {
68 if (input.JustPressed(Input::SHOULDER_LEFT)) {
72 if (input.JustPressed(Input::PAD_LEFT)) {
75 if (input.JustPressed(Input::PAD_RIGHT)) {
79 if (input.JustPressed(Input::ACTION_A)) {
80 if (menu.Selected() == 0) {
82 } else if (menu.Selected() == 1) {
86 if (input.JustPressed(Input::ACTION_B)) {
91 void StatusMenu::UpdateWorld(float deltaT) {
95 void StatusMenu::Render(SDL_Surface *screen) {
96 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
97 Vector<int> shoulderNavOffset(
98 5 * parent->Res().statusFont->CharWidth(),
99 parent->Res().statusFont->CharHeight());
100 Vector<int> statsOffset(
101 4 * parent->Res().statusFont->CharWidth(),
102 8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
103 Vector<int> equipOffset(
104 17 * parent->Res().statusFont->CharWidth(),
105 4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
106 Vector<int> experienceOffset(
107 11 * parent->Res().statusFont->CharWidth(),
108 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
109 Vector<int> nextLevelOffset(
110 11 * parent->Res().statusFont->CharWidth(),
111 20 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
112 Vector<int> ikariOffset(
113 17 * parent->Res().statusFont->CharWidth(),
114 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
115 Vector<int> menuOffset(
116 parent->Res().statusFont->CharWidth(),
117 23 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
119 parent->RenderBackground(screen);
120 parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
121 RenderStatus(screen, offset + parent->StatusOffset(0));
122 RenderStats(screen, offset + statsOffset);
123 RenderEquipment(screen, offset + equipOffset);
124 RenderExperience(screen, experienceOffset);
125 RenderNextLevel(screen, nextLevelOffset);
126 RenderIkari(screen, ikariOffset);
127 RenderMenu(screen, menuOffset);
130 int StatusMenu::Width() const {
131 return parent->Width();
134 int StatusMenu::Height() const {
135 return parent->Height();
138 void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
139 parent->GetHeroStatus(cursor).Render(screen, offset);
142 void StatusMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
143 const Stats &stats(GetHero().GetStats());
144 Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
146 Vector<int> position(offset);
147 RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
149 position += lineBreak;
150 RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
152 position += lineBreak;
153 RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
155 position += lineBreak;
156 RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
158 position += lineBreak;
159 RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
161 position += lineBreak;
162 RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
164 position += lineBreak;
165 RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
168 void StatusMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
169 const Font &font(*parent->Res().statusFont);
170 const Vector<int> numberOffset(4 * font.CharWidth(), 0);
172 font.DrawString(label, screen, position, 3);
173 font.DrawNumber(number, screen, position + numberOffset, 3);
176 void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector<int> &offset) const {
177 const Hero &hero(GetHero());
178 Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
180 Vector<int> position(offset);
181 RenderEquipmentLine(hero.Weapon(), screen, position);
183 position += lineBreak;
184 RenderEquipmentLine(hero.Armor(), screen, position);
186 position += lineBreak;
187 RenderEquipmentLine(hero.Shield(), screen, position);
189 position += lineBreak;
190 RenderEquipmentLine(hero.Helmet(), screen, position);
192 position += lineBreak;
193 RenderEquipmentLine(hero.Ring(), screen, position);
195 position += lineBreak;
196 RenderEquipmentLine(hero.Jewel(), screen, position);
199 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
200 const Font &font(*parent->Res().statusFont);
201 const Vector<int> textOffset(font.CharWidth(), 0);
203 if (item->MenuIcon()) {
204 item->MenuIcon()->Draw(screen, position);
206 font.DrawString(item->Name(), screen, position + textOffset);
208 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
212 void StatusMenu::RenderExperience(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
213 const Font &font(*parent->Res().statusFont);
214 font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10);
216 Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
217 font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7);
220 void StatusMenu::RenderNextLevel(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
221 const Font &font(*parent->Res().statusFont);
222 font.DrawStringRight(parent->Res().nextLevelLabel, screen, offset, 10);
224 Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
225 font.DrawNumberRight(GetHero().NextLevel(), screen, numberOffset, 7);
228 void StatusMenu::RenderIkari(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
229 const Font &font(*parent->Res().statusFont);
230 font.DrawString(parent->Res().ipLabel, screen, offset, 5);
232 Vector<int> numberOffset(offset.X() + 5 * font.CharWidth(), offset.Y());
233 font.DrawNumber(GetHero().RelativeIP(100), screen, numberOffset, 3);
235 Vector<int> percentOffset(offset.X() + 8 * font.CharWidth(), offset.Y());
236 font.DrawChar('%', screen, percentOffset);
239 void StatusMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
240 const Font &font(*parent->Res().normalFont);
241 const Frame &frame(*parent->Res().statusFrame);
243 Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
244 frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
245 font.DrawString(parent->Res().mainMenuStatusText, screen, offset + labelOffset);
247 Vector<int> menuFrameOffset(10 * font.CharWidth(), 0);
248 Vector<int> menuOffset(13 * font.CharWidth(), font.CharHeight());
249 frame.Draw(screen, offset + menuFrameOffset, 20 * font.CharWidth(), 3 * font.CharHeight());
250 menu.Draw(screen, offset + menuOffset);
254 void StatusMenu::NextHero() {
255 cursor = (cursor + 1) % parent->Game().state->partySize;
258 void StatusMenu::PreviousHero() {
259 cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
262 const Hero &StatusMenu::GetHero() const {
263 return *parent->Game().state->party[cursor];