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