4 * Created on: Nov 18, 2012
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 EquipMenu::EquipMenu(PartyMenu *parent, int cursor)
36 , actionMenu(*parent->Res().equipmentActionMenuProperties)
37 , equipmentMenu(*parent->Res().equipmentMenuProperties)
38 , inventoryMenu(*parent->Res().inventoryMenuProperties) {
39 actionMenu.Add(parent->Res().equipMenuEquipLabel, CHOICE_EQUIP);
40 actionMenu.Add(parent->Res().equipMenuStrongestLabel, CHOICE_STRONGEST);
41 actionMenu.Add(parent->Res().equipMenuRemoveLabel, CHOICE_REMOVE);
42 actionMenu.Add(parent->Res().equipMenuRemoveAllLabel, CHOICE_REMOVE_ALL);
43 actionMenu.Add(parent->Res().equipMenuDropLabel, CHOICE_DROP);
49 void EquipMenu::OnEnterState(SDL_Surface *) {
50 equipmentMenu.SetInactive();
53 void EquipMenu::OnExitState(SDL_Surface *) {
57 void EquipMenu::OnResumeState(SDL_Surface *) {
61 void EquipMenu::OnPauseState(SDL_Surface *) {
66 void EquipMenu::OnResize(int width, int height) {
71 void EquipMenu::HandleEvents(const Input &input) {
75 void EquipMenu::UpdateWorld(float deltaT) {
79 void EquipMenu::Render(SDL_Surface *screen) {
80 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
81 Vector<int> shoulderNavOffset(
82 5 * parent->Res().statusFont->CharWidth(),
83 parent->Res().statusFont->CharHeight());
84 Vector<int> statsOffset(
85 4 * parent->Res().statusFont->CharWidth(),
86 8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
87 Vector<int> equipOffset(
88 17 * parent->Res().statusFont->CharWidth(),
89 4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
91 parent->RenderBackground(screen);
92 parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
93 RenderStatus(screen, offset + parent->StatusOffset(0));
94 RenderStats(screen, offset + statsOffset);
95 RenderEquipmentMenu(screen, equipOffset);
98 int EquipMenu::Width() const {
99 return parent->Width();
102 int EquipMenu::Height() const {
103 return parent->Height();
106 void EquipMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
107 parent->GetHeroStatus(cursor).Render(screen, offset);
110 void EquipMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
111 const Stats &stats(GetHero().GetStats());
112 Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
114 Vector<int> position(offset);
115 RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
117 position += lineBreak;
118 RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
120 position += lineBreak;
121 RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
123 position += lineBreak;
124 RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
126 position += lineBreak;
127 RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
129 position += lineBreak;
130 RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
132 position += lineBreak;
133 RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
136 void EquipMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
137 const Font &font(*parent->Res().statusFont);
138 const Vector<int> numberOffset(4 * font.CharWidth(), 0);
140 font.DrawString(label, screen, position, 3);
141 font.DrawNumber(number, screen, position + numberOffset, 3);
144 void EquipMenu::RenderEquipmentMenu(SDL_Surface *screen, const Vector<int> &offset) const {
145 equipmentMenu.Draw(screen, offset);
148 void EquipMenu::RenderActionMenu(SDL_Surface *screen, const Vector<int> &offset) const {
152 void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector<int> &offset) const {
157 void EquipMenu::NextHero() {
158 cursor = (cursor + 1) % parent->Game().state->partySize;
162 void EquipMenu::PreviousHero() {
163 cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
167 const Hero &EquipMenu::GetHero() const {
168 return *parent->Game().state->party[cursor];
171 void EquipMenu::LoadEquipment() {
172 equipmentMenu.Clear();
173 equipmentMenu.Add(GetHero().Weapon()->Name(), GetHero().Weapon(), true, GetHero().Weapon()->MenuIcon());
174 equipmentMenu.Add(GetHero().Armor()->Name(), GetHero().Armor(), true, GetHero().Armor()->MenuIcon());
175 equipmentMenu.Add(GetHero().Shield()->Name(), GetHero().Shield(), true, GetHero().Shield()->MenuIcon());
176 equipmentMenu.Add(GetHero().Helmet()->Name(), GetHero().Helmet(), true, GetHero().Helmet()->MenuIcon());
177 equipmentMenu.Add(GetHero().Ring()->Name(), GetHero().Ring(), true, GetHero().Ring()->MenuIcon());
178 equipmentMenu.Add(GetHero().Jewel()->Name(), GetHero().Jewel(), true, GetHero().Jewel()->MenuIcon());