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"
26 using geometry::Vector;
31 StatusMenu::StatusMenu(PartyMenu *parent, int cursor)
38 void StatusMenu::OnEnterState(SDL_Surface *) {
42 void StatusMenu::OnExitState(SDL_Surface *) {
46 void StatusMenu::OnResumeState(SDL_Surface *) {
50 void StatusMenu::OnPauseState(SDL_Surface *) {
55 void StatusMenu::OnResize(int width, int height) {
60 void StatusMenu::HandleEvents(const Input &input) {
61 if (input.JustPressed(Input::ACTION_B)) {
65 if (input.JustPressed(Input::SHOULDER_RIGHT)) {
68 if (input.JustPressed(Input::SHOULDER_LEFT)) {
73 void StatusMenu::UpdateWorld(float deltaT) {
77 void StatusMenu::Render(SDL_Surface *screen) {
78 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
79 Vector<int> shoulderNavOffset(
80 5 * parent->Res().statusFont->CharWidth(),
81 parent->Res().statusFont->CharHeight());
82 Vector<int> statsOffset(
83 4 * parent->Res().statusFont->CharWidth(),
84 8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
85 Vector<int> equipOffset(
86 17 * parent->Res().statusFont->CharWidth(),
87 4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
88 Vector<int> experienceOffset(
89 11 * parent->Res().statusFont->CharWidth(),
90 17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
91 Vector<int> nextLevelOffset(
92 11 * parent->Res().statusFont->CharWidth(),
93 19 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
95 parent->RenderBackground(screen);
96 parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
97 RenderStatus(screen, offset + parent->StatusOffset(0));
98 RenderStats(screen, offset + statsOffset);
99 RenderEquipment(screen, offset + equipOffset);
100 RenderExperience(screen, experienceOffset);
101 RenderNextLevel(screen, nextLevelOffset);
104 int StatusMenu::Width() const {
105 return parent->Width();
108 int StatusMenu::Height() const {
109 return parent->Height();
112 void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
113 parent->GetHeroStatus(cursor).Render(screen, offset);
116 void StatusMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
117 const Stats &stats(GetHero().GetStats());
118 Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
120 Vector<int> position(offset);
121 RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
123 position += lineBreak;
124 RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
126 position += lineBreak;
127 RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
129 position += lineBreak;
130 RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
132 position += lineBreak;
133 RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
135 position += lineBreak;
136 RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
138 position += lineBreak;
139 RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
142 void StatusMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
143 const Font &font(*parent->Res().statusFont);
144 const Vector<int> numberOffset(4 * font.CharWidth(), 0);
146 font.DrawString(label, screen, position, 3);
147 font.DrawNumber(number, screen, position + numberOffset, 3);
150 void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector<int> &offset) const {
151 const Hero &hero(GetHero());
152 Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
154 Vector<int> position(offset);
155 RenderEquipmentLine(hero.Weapon(), screen, position);
157 position += lineBreak;
158 RenderEquipmentLine(hero.Armor(), screen, position);
160 position += lineBreak;
161 RenderEquipmentLine(hero.Shield(), screen, position);
163 position += lineBreak;
164 RenderEquipmentLine(hero.Helmet(), screen, position);
166 position += lineBreak;
167 RenderEquipmentLine(hero.Ring(), screen, position);
169 position += lineBreak;
170 RenderEquipmentLine(hero.Jewel(), screen, position);
173 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
174 const Font &font(*parent->Res().statusFont);
175 const Vector<int> textOffset(font.CharWidth(), 0);
177 if (item->MenuIcon()) {
178 item->MenuIcon()->Draw(screen, position);
180 font.DrawString(item->Name(), screen, position + textOffset);
182 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
186 void StatusMenu::RenderExperience(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
187 const Font &font(*parent->Res().statusFont);
188 font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10);
190 Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
191 font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7);
194 void StatusMenu::RenderNextLevel(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
195 const Font &font(*parent->Res().statusFont);
196 font.DrawStringRight(parent->Res().nextLevelLabel, screen, offset, 10);
198 Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
199 font.DrawNumberRight(GetHero().NextLevel(), screen, numberOffset, 7);
203 void StatusMenu::NextHero() {
204 cursor = (cursor + 1) % parent->Game().state->partySize;
207 void StatusMenu::PreviousHero() {
208 cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
211 const Hero &StatusMenu::GetHero() const {
212 return *parent->Game().state->party[cursor];