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);
89 parent->RenderBackground(screen);
90 parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
91 RenderStatus(screen, offset + parent->StatusOffset(0));
92 RenderStats(screen, offset + statsOffset);
93 RenderEquipment(screen, offset + equipOffset);
96 int StatusMenu::Width() const {
97 return parent->Width();
100 int StatusMenu::Height() const {
101 return parent->Height();
104 void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
105 parent->GetHeroStatus(cursor).Render(screen, offset);
108 void StatusMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
109 const Stats &stats(parent->Game().state->party[cursor]->GetStats());
110 Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
112 Vector<int> position(offset);
113 RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
115 position += lineBreak;
116 RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
118 position += lineBreak;
119 RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
121 position += lineBreak;
122 RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
124 position += lineBreak;
125 RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
127 position += lineBreak;
128 RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
130 position += lineBreak;
131 RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
134 void StatusMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
135 const Font &font(*parent->Res().statusFont);
136 const Vector<int> numberOffset(4 * font.CharWidth(), 0);
138 font.DrawString(label, screen, position, 3);
139 font.DrawNumber(number, screen, position + numberOffset, 3);
142 void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector<int> &offset) const {
143 const Hero &hero(*parent->Game().state->party[cursor]);
144 Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
146 Vector<int> position(offset);
147 RenderEquipmentLine(hero.Weapon(), screen, position);
149 position += lineBreak;
150 RenderEquipmentLine(hero.Armor(), screen, position);
152 position += lineBreak;
153 RenderEquipmentLine(hero.Shield(), screen, position);
155 position += lineBreak;
156 RenderEquipmentLine(hero.Helmet(), screen, position);
158 position += lineBreak;
159 RenderEquipmentLine(hero.Ring(), screen, position);
161 position += lineBreak;
162 RenderEquipmentLine(hero.Jewel(), screen, position);
165 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
166 const Font &font(*parent->Res().statusFont);
167 const Vector<int> textOffset(font.CharWidth(), 0);
169 if (item->MenuIcon()) {
170 item->MenuIcon()->Draw(screen, position);
172 font.DrawString(item->Name(), screen, position + textOffset);
174 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
179 void StatusMenu::NextHero() {
180 cursor = (cursor + 1) % parent->Game().state->partySize;
183 void StatusMenu::PreviousHero() {
184 cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;