]> git.localhorst.tv Git - l2e.git/blob - src/menu/StatusMenu.cpp
f155c160b1fb71ab85d5a16a2be42956a7398b41
[l2e.git] / src / menu / StatusMenu.cpp
1 /*
2  * StatusMenu.cpp
3  *
4  *  Created on: Oct 22, 2012
5  *      Author: holy
6  */
7
8 #include "StatusMenu.h"
9
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
22 using app::Input;
23 using common::Hero;
24 using common::Item;
25 using common::Stats;
26 using geometry::Vector;
27 using graphics::Font;
28
29 namespace menu {
30
31 StatusMenu::StatusMenu(PartyMenu *parent, int cursor)
32 : parent(parent)
33 , cursor(cursor) {
34
35 }
36
37
38 void StatusMenu::OnEnterState(SDL_Surface *) {
39
40 }
41
42 void StatusMenu::OnExitState(SDL_Surface *) {
43
44 }
45
46 void StatusMenu::OnResumeState(SDL_Surface *) {
47
48 }
49
50 void StatusMenu::OnPauseState(SDL_Surface *) {
51
52 }
53
54
55 void StatusMenu::OnResize(int width, int height) {
56
57 }
58
59
60 void StatusMenu::HandleEvents(const Input &input) {
61         if (input.JustPressed(Input::ACTION_B)) {
62                 Ctrl().PopState();
63         }
64
65         if (input.JustPressed(Input::SHOULDER_RIGHT)) {
66                 NextHero();
67         }
68         if (input.JustPressed(Input::SHOULDER_LEFT)) {
69                 PreviousHero();
70         }
71 }
72
73 void StatusMenu::UpdateWorld(float deltaT) {
74
75 }
76
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
92         parent->RenderBackground(screen);
93         parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
94         RenderStatus(screen, offset + parent->StatusOffset(0));
95         RenderStats(screen, offset + statsOffset);
96         RenderEquipment(screen, offset + equipOffset);
97         RenderExperience(screen, experienceOffset);
98 }
99
100 int StatusMenu::Width() const {
101         return parent->Width();
102 }
103
104 int StatusMenu::Height() const {
105         return parent->Height();
106 }
107
108 void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
109         parent->GetHeroStatus(cursor).Render(screen, offset);
110 }
111
112 void StatusMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
113         const Stats &stats(GetHero().GetStats());
114         Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
115
116         Vector<int> position(offset);
117         RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
118
119         position += lineBreak;
120         RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
121
122         position += lineBreak;
123         RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
124
125         position += lineBreak;
126         RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
127
128         position += lineBreak;
129         RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
130
131         position += lineBreak;
132         RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
133
134         position += lineBreak;
135         RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
136 }
137
138 void StatusMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
139         const Font &font(*parent->Res().statusFont);
140         const Vector<int> numberOffset(4 * font.CharWidth(), 0);
141
142         font.DrawString(label, screen, position, 3);
143         font.DrawNumber(number, screen, position + numberOffset, 3);
144 }
145
146 void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector<int> &offset) const {
147         const Hero &hero(GetHero());
148         Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
149
150         Vector<int> position(offset);
151         RenderEquipmentLine(hero.Weapon(), screen, position);
152
153         position += lineBreak;
154         RenderEquipmentLine(hero.Armor(), screen, position);
155
156         position += lineBreak;
157         RenderEquipmentLine(hero.Shield(), screen, position);
158
159         position += lineBreak;
160         RenderEquipmentLine(hero.Helmet(), screen, position);
161
162         position += lineBreak;
163         RenderEquipmentLine(hero.Ring(), screen, position);
164
165         position += lineBreak;
166         RenderEquipmentLine(hero.Jewel(), screen, position);
167 }
168
169 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
170         const Font &font(*parent->Res().statusFont);
171         const Vector<int> textOffset(font.CharWidth(), 0);
172         if (item) {
173                 if (item->MenuIcon()) {
174                         item->MenuIcon()->Draw(screen, position);
175                 }
176                 font.DrawString(item->Name(), screen, position + textOffset);
177         } else {
178                 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
179         }
180 }
181
182 void StatusMenu::RenderExperience(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
183         const Font &font(*parent->Res().statusFont);
184         font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10);
185
186         Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
187         font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7);
188 }
189
190
191 void StatusMenu::NextHero() {
192         cursor = (cursor + 1) % parent->Game().state->partySize;
193 }
194
195 void StatusMenu::PreviousHero() {
196         cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
197 }
198
199 const Hero &StatusMenu::GetHero() const {
200         return *parent->Game().state->party[cursor];
201 }
202
203 }