]> git.localhorst.tv Git - l2e.git/blob - src/menu/StatusMenu.cpp
e46a1dd1fbc9d2f11d36d4399286af0cc6a8e200
[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 "../graphics/Font.h"
20
21 using app::Input;
22 using common::Hero;
23 using common::Item;
24 using geometry::Vector;
25 using graphics::Font;
26
27 namespace menu {
28
29 StatusMenu::StatusMenu(PartyMenu *parent, int cursor)
30 : parent(parent)
31 , cursor(cursor) {
32
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::ACTION_B)) {
60                 Ctrl().PopState();
61         }
62
63         if (input.JustPressed(Input::SHOULDER_RIGHT)) {
64                 NextHero();
65         }
66         if (input.JustPressed(Input::SHOULDER_LEFT)) {
67                 PreviousHero();
68         }
69 }
70
71 void StatusMenu::UpdateWorld(float deltaT) {
72
73 }
74
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);
83
84         parent->RenderBackground(screen);
85         parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
86         RenderStatus(screen, offset + parent->StatusOffset(0));
87         RenderEquipment(screen, offset + statsOffset);
88 }
89
90 int StatusMenu::Width() const {
91         return parent->Width();
92 }
93
94 int StatusMenu::Height() const {
95         return parent->Height();
96 }
97
98 void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
99         parent->GetHeroStatus(cursor).Render(screen, offset);
100 }
101
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());
105
106         Vector<int> position(offset);
107         RenderEquipmentLine(hero.Weapon(), screen, position);
108
109         position += lineBreak;
110         RenderEquipmentLine(hero.Armor(), screen, position);
111
112         position += lineBreak;
113         RenderEquipmentLine(hero.Shield(), screen, position);
114
115         position += lineBreak;
116         RenderEquipmentLine(hero.Helmet(), screen, position);
117
118         position += lineBreak;
119         RenderEquipmentLine(hero.Ring(), screen, position);
120
121         position += lineBreak;
122         RenderEquipmentLine(hero.Jewel(), screen, position);
123 }
124
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);
128         if (item) {
129                 if (item->MenuIcon()) {
130                         item->MenuIcon()->Draw(screen, position);
131                 }
132                 font.DrawString(item->Name(), screen, position + textOffset);
133         } else {
134                 font.DrawString(parent->Res().noEquipmentText, screen, position + textOffset);
135         }
136 }
137
138
139 void StatusMenu::NextHero() {
140         cursor = (cursor + 1) % parent->Game().state->partySize;
141 }
142
143 void StatusMenu::PreviousHero() {
144         cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
145 }
146
147 }