]> git.localhorst.tv Git - l2e.git/blob - src/menu/EquipMenu.cpp
added action menu to equipment menu
[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         Vector<int> menuOffset(
91                         15 * parent->Res().statusFont->CharWidth(),
92                         17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
93
94         parent->RenderBackground(screen);
95         parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
96         RenderStatus(screen, offset + parent->StatusOffset(0));
97         RenderStats(screen, offset + statsOffset);
98         RenderEquipmentMenu(screen, offset + equipOffset);
99         RenderActionMenu(screen, offset + menuOffset);
100 }
101
102 int EquipMenu::Width() const {
103         return parent->Width();
104 }
105
106 int EquipMenu::Height() const {
107         return parent->Height();
108 }
109
110 void EquipMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
111         parent->GetHeroStatus(cursor).Render(screen, offset);
112 }
113
114 void EquipMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
115         const Stats &stats(GetHero().GetStats());
116         Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
117
118         Vector<int> position(offset);
119         RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
120
121         position += lineBreak;
122         RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
123
124         position += lineBreak;
125         RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
126
127         position += lineBreak;
128         RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
129
130         position += lineBreak;
131         RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
132
133         position += lineBreak;
134         RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
135
136         position += lineBreak;
137         RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
138 }
139
140 void EquipMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
141         const Font &font(*parent->Res().statusFont);
142         const Vector<int> numberOffset(4 * font.CharWidth(), 0);
143
144         font.DrawString(label, screen, position, 3);
145         font.DrawNumber(number, screen, position + numberOffset, 3);
146 }
147
148 void EquipMenu::RenderEquipmentMenu(SDL_Surface *screen, const Vector<int> &offset) const {
149         equipmentMenu.Draw(screen, offset);
150 }
151
152 void EquipMenu::RenderActionMenu(SDL_Surface *screen, const Vector<int> &offset) const {
153         const Font &font(*parent->Res().statusFont);
154         const Frame &frame(*parent->Res().statusFrame);
155         const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 2);
156
157         frame.Draw(screen, offset, 15 * font.CharWidth(), 10 * font.CharHeight());
158         actionMenu.Draw(screen, offset + menuOffset);
159 }
160
161 void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector<int> &offset) const {
162
163 }
164
165
166 void EquipMenu::NextHero() {
167         cursor = (cursor + 1) % parent->Game().state->partySize;
168         LoadEquipment();
169 }
170
171 void EquipMenu::PreviousHero() {
172         cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
173         LoadEquipment();
174 }
175
176 const Hero &EquipMenu::GetHero() const {
177         return *parent->Game().state->party[cursor];
178 }
179
180 void EquipMenu::LoadEquipment() {
181         equipmentMenu.Clear();
182         equipmentMenu.Add(GetHero().Weapon()->Name(), GetHero().Weapon(), true, GetHero().Weapon()->MenuIcon());
183         equipmentMenu.Add(GetHero().Armor()->Name(), GetHero().Armor(), true, GetHero().Armor()->MenuIcon());
184         equipmentMenu.Add(GetHero().Shield()->Name(), GetHero().Shield(), true, GetHero().Shield()->MenuIcon());
185         equipmentMenu.Add(GetHero().Helmet()->Name(), GetHero().Helmet(), true, GetHero().Helmet()->MenuIcon());
186         equipmentMenu.Add(GetHero().Ring()->Name(), GetHero().Ring(), true, GetHero().Ring()->MenuIcon());
187         equipmentMenu.Add(GetHero().Jewel()->Name(), GetHero().Jewel(), true, GetHero().Jewel()->MenuIcon());
188 }
189
190 }