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 for (int i = 0; i < Hero::EQUIP_COUNT; ++i) {
182 RenderEquipmentLine(hero.Equipment(Hero::EquipSlot(i)), screen, position);
183 position += lineBreak;
187 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
188 const Font &font(*parent->Res().statusFont);
189 const Vector<int> textOffset(font.CharWidth(), 0);
191 if (item->MenuIcon()) {
192 item->MenuIcon()->Draw(screen, position);
194 font.DrawString(item->Name(), screen, position + textOffset);
196 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
200 void StatusMenu::RenderExperience(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
201 const Font &font(*parent->Res().statusFont);
202 font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10);
204 Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
205 font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7);
208 void StatusMenu::RenderNextLevel(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
209 const Font &font(*parent->Res().statusFont);
210 font.DrawStringRight(parent->Res().nextLevelLabel, screen, offset, 10);
212 Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
213 font.DrawNumberRight(GetHero().NextLevel(), screen, numberOffset, 7);
216 void StatusMenu::RenderIkari(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
217 const Font &font(*parent->Res().statusFont);
218 font.DrawString(parent->Res().ipLabel, screen, offset, 5);
220 Vector<int> numberOffset(offset.X() + 5 * font.CharWidth(), offset.Y());
221 font.DrawNumber(GetHero().RelativeIP(100), screen, numberOffset, 3);
223 Vector<int> percentOffset(offset.X() + 8 * font.CharWidth(), offset.Y());
224 font.DrawChar('%', screen, percentOffset);
227 void StatusMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
228 const Font &font(*parent->Res().normalFont);
229 const Frame &frame(*parent->Res().statusFrame);
231 Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
232 frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
233 font.DrawString(parent->Res().mainMenuStatusText, screen, offset + labelOffset);
235 Vector<int> menuFrameOffset(10 * font.CharWidth(), 0);
236 Vector<int> menuOffset(13 * font.CharWidth(), font.CharHeight());
237 frame.Draw(screen, offset + menuFrameOffset, 20 * font.CharWidth(), 3 * font.CharHeight());
238 menu.Draw(screen, offset + menuOffset);
242 void StatusMenu::NextHero() {
243 cursor = (cursor + 1) % parent->Game().state->partySize;
246 void StatusMenu::PreviousHero() {
247 cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
250 const Hero &StatusMenu::GetHero() const {
251 return *parent->Game().state->party[cursor];