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