1 #include "StatusMenu.h"
3 #include "HeroStatus.h"
6 #include "../app/Application.h"
7 #include "../app/Input.h"
8 #include "../common/GameConfig.h"
9 #include "../common/GameState.h"
10 #include "../common/Hero.h"
11 #include "../common/Item.h"
12 #include "../common/Stats.h"
13 #include "../graphics/Font.h"
14 #include "../graphics/Frame.h"
15 #include "../math/Vector.h"
23 using graphics::Frame;
27 StatusMenu::StatusMenu(PartyMenu *parent, int cursor)
30 , menu(*parent->Res().statusMenuProperties) {
31 menu.Add(parent->Res().nextLabel, 0);
32 menu.Add(parent->Res().returnLabel, 1);
36 void StatusMenu::OnEnterState(SDL_Surface *) {
37 menu.StartAnimation(Ctrl());
40 void StatusMenu::OnExitState(SDL_Surface *) {
44 void StatusMenu::OnResumeState(SDL_Surface *) {
48 void StatusMenu::OnPauseState(SDL_Surface *) {
53 void StatusMenu::OnResize(int width, int height) {
58 void StatusMenu::HandleEvents(const Input &input) {
59 if (input.JustPressed(Input::SHOULDER_RIGHT)) {
62 if (input.JustPressed(Input::SHOULDER_LEFT)) {
66 if (input.JustPressed(Input::PAD_LEFT)) {
69 if (input.JustPressed(Input::PAD_RIGHT)) {
73 if (input.JustPressed(Input::ACTION_A)) {
74 if (menu.Selected() == 0) {
76 } else if (menu.Selected() == 1) {
80 if (input.JustPressed(Input::ACTION_B)) {
85 void StatusMenu::UpdateWorld(Uint32 deltaT) {
89 void StatusMenu::Render(SDL_Surface *screen) {
90 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
91 Vector<int> shoulderNavOffset(
92 5 * parent->Res().statusFont->CharWidth(),
93 parent->Res().statusFont->CharHeight());
94 Vector<int> statsOffset(
95 4 * parent->Res().statusFont->CharWidth(),
96 8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
97 Vector<int> equipOffset(
98 17 * parent->Res().statusFont->CharWidth(),
99 4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
100 Vector<int> experienceOffset(
101 11 * parent->Res().statusFont->CharWidth(),
102 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
103 Vector<int> nextLevelOffset(
104 11 * parent->Res().statusFont->CharWidth(),
105 20 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
106 Vector<int> ikariOffset(
107 17 * parent->Res().statusFont->CharWidth(),
108 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
109 Vector<int> menuOffset(
110 parent->Res().statusFont->CharWidth(),
111 23 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
113 parent->RenderBackground(screen);
114 parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
115 RenderStatus(screen, offset + parent->StatusOffset(0));
116 RenderStats(screen, offset + statsOffset);
117 RenderEquipment(screen, offset + equipOffset);
118 RenderExperience(screen, experienceOffset);
119 RenderNextLevel(screen, nextLevelOffset);
120 RenderIkari(screen, ikariOffset);
121 RenderMenu(screen, menuOffset);
124 int StatusMenu::Width() const {
125 return parent->Width();
128 int StatusMenu::Height() const {
129 return parent->Height();
132 void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
133 parent->GetHeroStatus(cursor).Render(screen, offset);
136 void StatusMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
137 const Stats &stats(GetHero().GetStats());
138 Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
140 Vector<int> position(offset);
141 RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
143 position += lineBreak;
144 RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
146 position += lineBreak;
147 RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
149 position += lineBreak;
150 RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
152 position += lineBreak;
153 RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
155 position += lineBreak;
156 RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
158 position += lineBreak;
159 RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
162 void StatusMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
163 const Font &font(*parent->Res().statusFont);
164 const Vector<int> numberOffset(4 * font.CharWidth(), 0);
166 font.DrawString(label, screen, position, 3);
167 font.DrawNumber(number, screen, position + numberOffset, 3);
170 void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector<int> &offset) const {
171 const Hero &hero(GetHero());
172 Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
174 Vector<int> position(offset);
175 for (int i = 0; i < Hero::EQUIP_COUNT; ++i) {
176 RenderEquipmentLine(hero.Equipment(Hero::EquipSlot(i)), screen, position);
177 position += lineBreak;
181 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
182 const Font &font(*parent->Res().statusFont);
183 const Vector<int> textOffset(font.CharWidth(), 0);
185 if (item->MenuIcon()) {
186 item->MenuIcon()->Draw(screen, position);
188 font.DrawString(item->Name(), screen, position + textOffset);
190 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
194 void StatusMenu::RenderExperience(SDL_Surface *screen, const math::Vector<int> &offset) const {
195 const Font &font(*parent->Res().statusFont);
196 font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10);
198 Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
199 font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7);
202 void StatusMenu::RenderNextLevel(SDL_Surface *screen, const math::Vector<int> &offset) const {
203 const Font &font(*parent->Res().statusFont);
204 font.DrawStringRight(parent->Res().nextLevelLabel, screen, offset, 10);
206 Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
207 font.DrawNumberRight(GetHero().NextLevel(), screen, numberOffset, 7);
210 void StatusMenu::RenderIkari(SDL_Surface *screen, const math::Vector<int> &offset) const {
211 const Font &font(*parent->Res().statusFont);
212 font.DrawString(parent->Res().ipLabel, screen, offset, 5);
214 Vector<int> numberOffset(offset.X() + 5 * font.CharWidth(), offset.Y());
215 font.DrawNumber(GetHero().RelativeIP(100), screen, numberOffset, 3);
217 Vector<int> percentOffset(offset.X() + 8 * font.CharWidth(), offset.Y());
218 font.DrawChar('%', screen, percentOffset);
221 void StatusMenu::RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const {
222 const Font &font(*parent->Res().normalFont);
223 const Frame &frame(*parent->Res().statusFrame);
225 Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
226 frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
227 font.DrawString(parent->Res().mainMenuStatusText, screen, offset + labelOffset);
229 Vector<int> menuFrameOffset(10 * font.CharWidth(), 0);
230 Vector<int> menuOffset(13 * font.CharWidth(), font.CharHeight());
231 frame.Draw(screen, offset + menuFrameOffset, 20 * font.CharWidth(), 3 * font.CharHeight());
232 menu.Draw(screen, offset + menuOffset);
236 void StatusMenu::NextHero() {
237 cursor = (cursor + 1) % parent->Game().state->partySize;
240 void StatusMenu::PreviousHero() {
241 cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
244 const Hero &StatusMenu::GetHero() const {
245 return *parent->Game().state->party[cursor];