]> git.localhorst.tv Git - l2e.git/blob - src/menu/EquipMenu.cpp
da24f771f10723d342f00ea97fddf1f8fda58181
[l2e.git] / src / menu / EquipMenu.cpp
1 /*
2  * EquipMenu.cpp
3  *
4  *  Created on: Nov 18, 2012
5  *      Author: holy
6  */
7
8 #include "EquipMenu.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 EquipMenu::EquipMenu(PartyMenu *parent, int cursor)
34 : parent(parent)
35 , cursor(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);
44
45         LoadEquipment();
46 }
47
48
49 void EquipMenu::OnEnterState(SDL_Surface *) {
50         equipmentMenu.SetInactive();
51 }
52
53 void EquipMenu::OnExitState(SDL_Surface *) {
54
55 }
56
57 void EquipMenu::OnResumeState(SDL_Surface *) {
58
59 }
60
61 void EquipMenu::OnPauseState(SDL_Surface *) {
62
63 }
64
65
66 void EquipMenu::OnResize(int width, int height) {
67
68 }
69
70
71 void EquipMenu::HandleEvents(const Input &input) {
72
73 }
74
75 void EquipMenu::UpdateWorld(float deltaT) {
76
77 }
78
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);
90
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);
96 }
97
98 int EquipMenu::Width() const {
99         return parent->Width();
100 }
101
102 int EquipMenu::Height() const {
103         return parent->Height();
104 }
105
106 void EquipMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
107         parent->GetHeroStatus(cursor).Render(screen, offset);
108 }
109
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());
113
114         Vector<int> position(offset);
115         RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
116
117         position += lineBreak;
118         RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
119
120         position += lineBreak;
121         RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
122
123         position += lineBreak;
124         RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
125
126         position += lineBreak;
127         RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
128
129         position += lineBreak;
130         RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
131
132         position += lineBreak;
133         RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
134 }
135
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);
139
140         font.DrawString(label, screen, position, 3);
141         font.DrawNumber(number, screen, position + numberOffset, 3);
142 }
143
144 void EquipMenu::RenderEquipmentMenu(SDL_Surface *screen, const Vector<int> &offset) const {
145         equipmentMenu.Draw(screen, offset);
146 }
147
148 void EquipMenu::RenderActionMenu(SDL_Surface *screen, const Vector<int> &offset) const {
149
150 }
151
152 void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector<int> &offset) const {
153
154 }
155
156
157 void EquipMenu::NextHero() {
158         cursor = (cursor + 1) % parent->Game().state->partySize;
159         LoadEquipment();
160 }
161
162 void EquipMenu::PreviousHero() {
163         cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
164         LoadEquipment();
165 }
166
167 const Hero &EquipMenu::GetHero() const {
168         return *parent->Game().state->party[cursor];
169 }
170
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());
179 }
180
181 }