]> git.localhorst.tv Git - l2e.git/blob - src/menu/PartyMenu.cpp
started implementation of equipment menu
[l2e.git] / src / menu / PartyMenu.cpp
1 /*
2  * PartyMenu.cpp
3  *
4  *  Created on: Oct 21, 2012
5  *      Author: holy
6  */
7
8 #include "PartyMenu.h"
9
10 #include "ChangeHero.h"
11 #include "EquipMenu.h"
12 #include "InventoryMenu.h"
13 #include "Resources.h"
14 #include "SelectHero.h"
15 #include "SpellMenu.h"
16 #include "StatusMenu.h"
17 #include "../app/Application.h"
18 #include "../app/Input.h"
19 #include "../common/GameConfig.h"
20 #include "../common/GameState.h"
21 #include "../geometry/Vector.h"
22 #include "../graphics/Font.h"
23 #include "../graphics/Frame.h"
24 #include "../graphics/Texture.h"
25
26 using app::Input;
27 using common::GameConfig;
28 using geometry::Vector;
29
30 namespace menu {
31
32 PartyMenu::PartyMenu(GameConfig *game)
33 : game(game)
34 , mainMenu(*game->menuResources->mainMenuProperties) {
35         for (int i(0); i < 4; ++i) {
36                 status[i].SetHero(game->state->party, i);
37                 status[i].SetResources(game->menuResources);
38         }
39         statusPositions[0] = Vector<int>(0, 0);
40         statusPositions[1] = Vector<int>(status[0].Width(), 0);
41         statusPositions[2] = Vector<int>(0, status[0].Height());
42         statusPositions[3] = Vector<int>(status[0].Width(), status[0].Height());
43
44         mainMenu.Add(Res().mainMenuItemText, 0);
45         mainMenu.Add(Res().mainMenuStatusText, 4);
46         mainMenu.Add(Res().mainMenuSpellText, 1);
47         mainMenu.Add(Res().mainMenuChangeText, 5);
48         mainMenu.Add(Res().mainMenuCapsuleText, 2);
49         mainMenu.Add(Res().mainMenuConfigText, 6);
50         mainMenu.Add(Res().mainMenuEquipmentText, 3);
51         mainMenu.Add(Res().mainMenuScenarioText, 7);
52 }
53
54 PartyMenu::~PartyMenu() {
55
56 }
57
58
59 void PartyMenu::OnEnterState(SDL_Surface *) {
60
61 }
62
63 void PartyMenu::OnExitState(SDL_Surface *) {
64
65 }
66
67 void PartyMenu::OnResumeState(SDL_Surface *) {
68
69 }
70
71 void PartyMenu::OnPauseState(SDL_Surface *) {
72
73 }
74
75
76 void PartyMenu::OnResize(int width, int height) {
77
78 }
79
80
81 void PartyMenu::HandleEvents(const Input &input) {
82         if (input.JustPressed(Input::ACTION_B)) {
83                 Ctrl().PopState();
84                 return;
85         }
86
87         if (input.JustPressed(Input::PAD_UP)) {
88                 mainMenu.PreviousRow();
89         } else if (input.JustPressed(Input::PAD_RIGHT)) {
90                 mainMenu.NextItem();
91         } else if (input.JustPressed(Input::PAD_DOWN)) {
92                 mainMenu.NextRow();
93         } else if (input.JustPressed(Input::PAD_LEFT)) {
94                 mainMenu.PreviousItem();
95         }
96
97         if (input.JustPressed(Input::ACTION_A)) {
98                 switch (mainMenu.Selected()) {
99                         case MENU_ITEM_ITEM:
100                                 Ctrl().PushState(new InventoryMenu(this));
101                                 break;
102                         case MENU_ITEM_SPELL:
103                                 Ctrl().PushState(new SelectHero(this, this, this, OnSpellSelect));
104                                 break;
105                         case MENU_ITEM_CAPSULE:
106                                 break;
107                         case MENU_ITEM_EQUIP:
108                                 Ctrl().PushState(new SelectHero(this, this, this, OnEquipSelect));
109                                 break;
110                         case MENU_ITEM_STATUS:
111                                 Ctrl().PushState(new SelectHero(this, this, this, OnStatusSelect));
112                                 break;
113                         case MENU_ITEM_CHANGE:
114                                 Ctrl().PushState(new ChangeHero(this));
115                                 break;
116                         case MENU_ITEM_CONFIG:
117                                 break;
118                         case MENU_ITEM_SCENARIO:
119                                 break;
120                         default:
121                                 break;
122                 }
123         }
124 }
125
126 void PartyMenu::UpdateWorld(float deltaT) {
127
128 }
129
130 void PartyMenu::Render(SDL_Surface *screen) {
131         Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
132
133         RenderBackground(screen);
134         RenderHeros(screen, offset);
135         RenderMenu(screen, offset + Vector<int>(8 * Res().normalFont->CharWidth(), 13 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
136         RenderInfo(screen, offset + Vector<int>(14 * Res().normalFont->CharWidth(), 21 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
137 }
138
139 int PartyMenu::Width() const {
140         return 2 * (status[0].Width() + Res().normalFont->CharWidth());
141 }
142
143 int PartyMenu::Height() const {
144         return 2 * Res().normalFont->CharHeight()
145                         + 2 * status[0].Height()
146                         + Res().normalFont->CharHeight()
147                         + 8 * Res().normalFont->CharHeight()
148                         + 5 * Res().normalFont->CharHeight()
149                         + 2 * Res().normalFont->CharHeight();
150 }
151
152 void PartyMenu::RenderBackground(SDL_Surface *screen) const {
153         Res().menubg->Render(screen, Vector<int>(), Vector<int>(screen->w, screen->h));
154 }
155
156 void PartyMenu::RenderHeros(SDL_Surface *screen, const Vector<int> &offset) const {
157         for (int i(0); i < 4; ++i) {
158                 status[i].Render(screen, offset + StatusOffset(i));
159         }
160 }
161
162 Vector<int> PartyMenu::StatusOffset(int index) const {
163         return statusPositions[index] + Vector<int>(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight());
164 }
165
166 void PartyMenu::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) const {
167         Vector<int> menuOffset(3 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
168
169         Res().statusFrame->Draw(screen, offset, 23 * Res().normalFont->CharWidth(), 8 * Res().normalFont->CharHeight());
170         mainMenu.Draw(screen, offset + menuOffset);
171 }
172
173 void PartyMenu::RenderInfo(SDL_Surface *screen, const Vector<int> &offset) const {
174         Res().statusFrame->Draw(screen, offset, 17 * Res().normalFont->CharWidth(), 5 * Res().normalFont->CharHeight());
175
176         Vector<int> timeLabelOffset(2 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
177         Res().normalFont->DrawString(Res().mainMenuTimeText, screen, offset + timeLabelOffset);
178
179         Vector<int> hoursOffset(timeLabelOffset.X() + 6 * Res().normalFont->CharWidth(), timeLabelOffset.Y());
180         Res().normalFont->DrawNumber(game->state->time / 60 / 60, screen, offset + hoursOffset, 4);
181
182         Vector<int> timeSeparatorOffset(hoursOffset.X() + 4 * Res().normalFont->CharWidth(), hoursOffset.Y());
183         Res().normalFont->DrawChar(':', screen, offset + timeSeparatorOffset);
184
185         Vector<int> minutesOffset(timeSeparatorOffset.X() + Res().normalFont->CharWidth(), timeSeparatorOffset.Y());
186         Res().normalFont->DrawNumber(game->state->time / 60, screen, offset + minutesOffset, 2);
187         if (game->state->time / 60 < 10) {
188                 Res().normalFont->DrawChar('0', screen, offset + minutesOffset);
189         }
190
191         Vector<int> goldLabelOffset(2 * Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() * 3 / 4);
192         Res().normalFont->DrawString(Res().mainMenuGoldText, screen, offset + goldLabelOffset);
193
194         Vector<int> goldOffset(goldLabelOffset.X() + 6 * Res().normalFont->CharWidth(), goldLabelOffset.Y());
195         Res().normalFont->DrawNumber(game->state->money, screen, offset + goldOffset, 7);
196 }
197
198
199 Resources &PartyMenu::Res() {
200         return *game->menuResources;
201 }
202
203 const Resources &PartyMenu::Res() const {
204         return *game->menuResources;
205 }
206
207 void PartyMenu::OnEquipSelect(void *ref, int index) {
208         PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
209         self->Ctrl().ChangeState(
210                         new EquipMenu(self, index));
211 }
212
213 void PartyMenu::OnSpellSelect(void *ref, int index) {
214         PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
215         self->Ctrl().ChangeState(
216                         new SpellMenu(self, index));
217 }
218
219 void PartyMenu::OnStatusSelect(void *ref, int index) {
220         PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
221         self->Ctrl().ChangeState(
222                         new StatusMenu(self, index));
223 }
224
225 }