]> git.localhorst.tv Git - l2e.git/blob - src/menu/StatusMenu.cpp
removed lazy fwd headers
[l2e.git] / src / menu / StatusMenu.cpp
1 #include "StatusMenu.h"
2
3 #include "HeroStatus.h"
4 #include "PartyMenu.h"
5 #include "Resources.h"
6 #include "../app/Application.h"
7 #include "../app/Input.h"
8 #include "../common/GameConfig.h"
9 #include "../common/GameState.h"
10 #include "../common/Hero.h"
11 #include "../common/Item.h"
12 #include "../common/Stats.h"
13 #include "../graphics/Font.h"
14 #include "../graphics/Frame.h"
15 #include "../math/Vector.h"
16
17 using app::Input;
18 using common::Hero;
19 using common::Item;
20 using common::Stats;
21 using math::Vector;
22 using graphics::Font;
23 using graphics::Frame;
24
25 namespace menu {
26
27 StatusMenu::StatusMenu(PartyMenu *parent, int cursor)
28 : parent(parent)
29 , cursor(cursor)
30 , menu(*parent->Res().statusMenuProperties) {
31         menu.Add(parent->Res().nextLabel, 0);
32         menu.Add(parent->Res().returnLabel, 1);
33 }
34
35
36 void StatusMenu::OnEnterState(SDL_Surface *) {
37
38 }
39
40 void StatusMenu::OnExitState(SDL_Surface *) {
41
42 }
43
44 void StatusMenu::OnResumeState(SDL_Surface *) {
45
46 }
47
48 void StatusMenu::OnPauseState(SDL_Surface *) {
49
50 }
51
52
53 void StatusMenu::OnResize(int width, int height) {
54
55 }
56
57
58 void StatusMenu::HandleEvents(const Input &input) {
59         if (input.JustPressed(Input::SHOULDER_RIGHT)) {
60                 NextHero();
61         }
62         if (input.JustPressed(Input::SHOULDER_LEFT)) {
63                 PreviousHero();
64         }
65
66         if (input.JustPressed(Input::PAD_LEFT)) {
67                 menu.PreviousItem();
68         }
69         if (input.JustPressed(Input::PAD_RIGHT)) {
70                 menu.NextItem();
71         }
72
73         if (input.JustPressed(Input::ACTION_A)) {
74                 if (menu.Selected() == 0) {
75                         NextHero();
76                 } else if (menu.Selected() == 1) {
77                         Ctrl().PopState();
78                 }
79         }
80         if (input.JustPressed(Input::ACTION_B)) {
81                 Ctrl().PopState();
82         }
83 }
84
85 void StatusMenu::UpdateWorld(Uint32 deltaT) {
86
87 }
88
89 void StatusMenu::Render(SDL_Surface *screen) {
90         Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
91         Vector<int> shoulderNavOffset(
92                         5 * parent->Res().statusFont->CharWidth(),
93                         parent->Res().statusFont->CharHeight());
94         Vector<int> statsOffset(
95                         4 * parent->Res().statusFont->CharWidth(),
96                         8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
97         Vector<int> equipOffset(
98                         17 * parent->Res().statusFont->CharWidth(),
99                         4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
100         Vector<int> experienceOffset(
101                         11 * parent->Res().statusFont->CharWidth(),
102                         17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
103         Vector<int> nextLevelOffset(
104                         11 * parent->Res().statusFont->CharWidth(),
105                         20 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
106         Vector<int> ikariOffset(
107                         17 * parent->Res().statusFont->CharWidth(),
108                         17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
109         Vector<int> menuOffset(
110                         parent->Res().statusFont->CharWidth(),
111                         23 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
112
113         parent->RenderBackground(screen);
114         parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
115         RenderStatus(screen, offset + parent->StatusOffset(0));
116         RenderStats(screen, offset + statsOffset);
117         RenderEquipment(screen, offset + equipOffset);
118         RenderExperience(screen, experienceOffset);
119         RenderNextLevel(screen, nextLevelOffset);
120         RenderIkari(screen, ikariOffset);
121         RenderMenu(screen, menuOffset);
122 }
123
124 int StatusMenu::Width() const {
125         return parent->Width();
126 }
127
128 int StatusMenu::Height() const {
129         return parent->Height();
130 }
131
132 void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
133         parent->GetHeroStatus(cursor).Render(screen, offset);
134 }
135
136 void StatusMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
137         const Stats &stats(GetHero().GetStats());
138         Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
139
140         Vector<int> position(offset);
141         RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
142
143         position += lineBreak;
144         RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
145
146         position += lineBreak;
147         RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
148
149         position += lineBreak;
150         RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
151
152         position += lineBreak;
153         RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
154
155         position += lineBreak;
156         RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
157
158         position += lineBreak;
159         RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
160 }
161
162 void StatusMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
163         const Font &font(*parent->Res().statusFont);
164         const Vector<int> numberOffset(4 * font.CharWidth(), 0);
165
166         font.DrawString(label, screen, position, 3);
167         font.DrawNumber(number, screen, position + numberOffset, 3);
168 }
169
170 void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector<int> &offset) const {
171         const Hero &hero(GetHero());
172         Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
173
174         Vector<int> position(offset);
175         for (int i = 0; i < Hero::EQUIP_COUNT; ++i) {
176                 RenderEquipmentLine(hero.Equipment(Hero::EquipSlot(i)), screen, position);
177                 position += lineBreak;
178         }
179 }
180
181 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
182         const Font &font(*parent->Res().statusFont);
183         const Vector<int> textOffset(font.CharWidth(), 0);
184         if (item) {
185                 if (item->MenuIcon()) {
186                         item->MenuIcon()->Draw(screen, position);
187                 }
188                 font.DrawString(item->Name(), screen, position + textOffset);
189         } else {
190                 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
191         }
192 }
193
194 void StatusMenu::RenderExperience(SDL_Surface *screen, const math::Vector<int> &offset) const {
195         const Font &font(*parent->Res().statusFont);
196         font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10);
197
198         Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
199         font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7);
200 }
201
202 void StatusMenu::RenderNextLevel(SDL_Surface *screen, const math::Vector<int> &offset) const {
203         const Font &font(*parent->Res().statusFont);
204         font.DrawStringRight(parent->Res().nextLevelLabel, screen, offset, 10);
205
206         Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
207         font.DrawNumberRight(GetHero().NextLevel(), screen, numberOffset, 7);
208 }
209
210 void StatusMenu::RenderIkari(SDL_Surface *screen, const math::Vector<int> &offset) const {
211         const Font &font(*parent->Res().statusFont);
212         font.DrawString(parent->Res().ipLabel, screen, offset, 5);
213
214         Vector<int> numberOffset(offset.X() + 5 * font.CharWidth(), offset.Y());
215         font.DrawNumber(GetHero().RelativeIP(100), screen, numberOffset, 3);
216
217         Vector<int> percentOffset(offset.X() + 8 * font.CharWidth(), offset.Y());
218         font.DrawChar('%', screen, percentOffset);
219 }
220
221 void StatusMenu::RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const {
222         const Font &font(*parent->Res().normalFont);
223         const Frame &frame(*parent->Res().statusFrame);
224
225         Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
226         frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
227         font.DrawString(parent->Res().mainMenuStatusText, screen, offset + labelOffset);
228
229         Vector<int> menuFrameOffset(10 * font.CharWidth(), 0);
230         Vector<int> menuOffset(13 * font.CharWidth(), font.CharHeight());
231         frame.Draw(screen, offset + menuFrameOffset, 20 * font.CharWidth(), 3 * font.CharHeight());
232         menu.Draw(screen, offset + menuOffset);
233 }
234
235
236 void StatusMenu::NextHero() {
237         cursor = (cursor + 1) % parent->Game().state->partySize;
238 }
239
240 void StatusMenu::PreviousHero() {
241         cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
242 }
243
244 const Hero &StatusMenu::GetHero() const {
245         return *parent->Game().state->party[cursor];
246 }
247
248 }