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