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