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 "../graphics/Font.h"
24 using geometry::Vector;
29 StatusMenu::StatusMenu(PartyMenu *parent, int cursor)
36 void StatusMenu::OnEnterState(SDL_Surface *) {
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::ACTION_B)) {
63 if (input.JustPressed(Input::SHOULDER_RIGHT)) {
66 if (input.JustPressed(Input::SHOULDER_LEFT)) {
71 void StatusMenu::UpdateWorld(float deltaT) {
75 void StatusMenu::Render(SDL_Surface *screen) {
76 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
77 Vector<int> shoulderNavOffset(
78 5 * parent->Res().statusFont->CharWidth(),
79 parent->Res().statusFont->CharHeight());
80 Vector<int> statsOffset(
81 17 * parent->Res().statusFont->CharWidth(),
82 4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
84 parent->RenderBackground(screen);
85 parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
86 RenderStatus(screen, offset + parent->StatusOffset(0));
87 RenderEquipment(screen, offset + statsOffset);
90 int StatusMenu::Width() const {
91 return parent->Width();
94 int StatusMenu::Height() const {
95 return parent->Height();
98 void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
99 parent->GetHeroStatus(cursor).Render(screen, offset);
102 void StatusMenu::RenderEquipment(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
103 const Hero &hero(*parent->Game().state->party[cursor]);
104 Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
106 Vector<int> position(offset);
107 RenderEquipmentLine(hero.Weapon(), screen, position);
109 position += lineBreak;
110 RenderEquipmentLine(hero.Armor(), screen, position);
112 position += lineBreak;
113 RenderEquipmentLine(hero.Shield(), screen, position);
115 position += lineBreak;
116 RenderEquipmentLine(hero.Helmet(), screen, position);
118 position += lineBreak;
119 RenderEquipmentLine(hero.Ring(), screen, position);
121 position += lineBreak;
122 RenderEquipmentLine(hero.Jewel(), screen, position);
125 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
126 const Font &font(*parent->Res().statusFont);
127 const Vector<int> textOffset(font.CharWidth(), 0);
129 if (item->MenuIcon()) {
130 item->MenuIcon()->Draw(screen, position);
132 font.DrawString(item->Name(), screen, position + textOffset);
134 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
139 void StatusMenu::NextHero() {
140 cursor = (cursor + 1) % parent->Game().state->partySize;
143 void StatusMenu::PreviousHero() {
144 cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;