3 #include "ChangeHero.h"
4 #include "ConfigMenu.h"
6 #include "InventoryMenu.h"
8 #include "ScenarioMenu.h"
9 #include "SelectHero.h"
10 #include "SpellMenu.h"
11 #include "StatusMenu.h"
12 #include "../app/Application.h"
13 #include "../app/Input.h"
14 #include "../common/GameConfig.h"
15 #include "../common/GameState.h"
16 #include "../geometry/Vector.h"
17 #include "../graphics/Font.h"
18 #include "../graphics/Frame.h"
19 #include "../graphics/Texture.h"
22 using common::GameConfig;
23 using geometry::Vector;
27 PartyMenu::PartyMenu(GameConfig *game)
29 , mainMenu(*game->menuResources->mainMenuProperties) {
30 for (int i(0); i < 4; ++i) {
31 status[i].SetHero(game->state->party, i);
32 status[i].SetResources(game->menuResources);
34 statusPositions[0] = Vector<int>(0, 0);
35 statusPositions[1] = Vector<int>(status[0].Width(), 0);
36 statusPositions[2] = Vector<int>(0, status[0].Height());
37 statusPositions[3] = Vector<int>(status[0].Width(), status[0].Height());
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);
49 PartyMenu::~PartyMenu() {
54 void PartyMenu::OnEnterState(SDL_Surface *) {
58 void PartyMenu::OnExitState(SDL_Surface *) {
62 void PartyMenu::OnResumeState(SDL_Surface *) {
66 void PartyMenu::OnPauseState(SDL_Surface *) {
71 void PartyMenu::OnResize(int width, int height) {
76 void PartyMenu::HandleEvents(const Input &input) {
77 if (input.JustPressed(Input::ACTION_B)) {
82 if (input.JustPressed(Input::PAD_UP)) {
83 mainMenu.PreviousRow();
84 } else if (input.JustPressed(Input::PAD_RIGHT)) {
86 } else if (input.JustPressed(Input::PAD_DOWN)) {
88 } else if (input.JustPressed(Input::PAD_LEFT)) {
89 mainMenu.PreviousItem();
92 if (input.JustPressed(Input::ACTION_A)) {
93 switch (mainMenu.Selected()) {
95 Ctrl().PushState(new InventoryMenu(this));
98 Ctrl().PushState(new SelectHero(this, this, this, OnSpellSelect));
100 case MENU_ITEM_CAPSULE:
102 case MENU_ITEM_EQUIP:
103 Ctrl().PushState(new SelectHero(this, this, this, OnEquipSelect));
105 case MENU_ITEM_STATUS:
106 Ctrl().PushState(new SelectHero(this, this, this, OnStatusSelect));
108 case MENU_ITEM_CHANGE:
109 Ctrl().PushState(new ChangeHero(this));
111 case MENU_ITEM_CONFIG:
112 Ctrl().PushState(new ConfigMenu(this));
114 case MENU_ITEM_SCENARIO:
115 Ctrl().PushState(new ScenarioMenu(this));
123 void PartyMenu::UpdateWorld(float deltaT) {
127 void PartyMenu::Render(SDL_Surface *screen) {
128 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
130 RenderBackground(screen);
131 RenderHeros(screen, offset);
132 RenderMenu(screen, offset + Vector<int>(8 * Res().normalFont->CharWidth(), 13 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
133 RenderInfo(screen, offset + Vector<int>(14 * Res().normalFont->CharWidth(), 21 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
136 int PartyMenu::Width() const {
137 return 2 * (status[0].Width() + Res().normalFont->CharWidth());
140 int PartyMenu::Height() const {
141 return 2 * Res().normalFont->CharHeight()
142 + 2 * status[0].Height()
143 + Res().normalFont->CharHeight()
144 + 8 * Res().normalFont->CharHeight()
145 + 5 * Res().normalFont->CharHeight()
146 + 2 * Res().normalFont->CharHeight();
149 void PartyMenu::RenderBackground(SDL_Surface *screen) const {
150 Res().menubg->Render(screen, Vector<int>(), Vector<int>(screen->w, screen->h));
153 void PartyMenu::RenderHeros(SDL_Surface *screen, const Vector<int> &offset) const {
154 for (int i(0); i < 4; ++i) {
155 status[i].Render(screen, offset + StatusOffset(i));
159 Vector<int> PartyMenu::StatusOffset(int index) const {
160 return statusPositions[index] + Vector<int>(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight());
163 void PartyMenu::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) const {
164 Vector<int> menuOffset(3 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
166 Res().statusFrame->Draw(screen, offset, 23 * Res().normalFont->CharWidth(), 8 * Res().normalFont->CharHeight());
167 mainMenu.Draw(screen, offset + menuOffset);
170 void PartyMenu::RenderInfo(SDL_Surface *screen, const Vector<int> &offset) const {
171 Res().statusFrame->Draw(screen, offset, 17 * Res().normalFont->CharWidth(), 5 * Res().normalFont->CharHeight());
173 Vector<int> timeLabelOffset(2 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
174 Res().normalFont->DrawString(Res().mainMenuTimeText, screen, offset + timeLabelOffset);
176 Vector<int> hoursOffset(timeLabelOffset.X() + 6 * Res().normalFont->CharWidth(), timeLabelOffset.Y());
177 Res().normalFont->DrawNumber(game->state->time / 60 / 60, screen, offset + hoursOffset, 4);
179 Vector<int> timeSeparatorOffset(hoursOffset.X() + 4 * Res().normalFont->CharWidth(), hoursOffset.Y());
180 Res().normalFont->DrawChar(':', screen, offset + timeSeparatorOffset);
182 Vector<int> minutesOffset(timeSeparatorOffset.X() + Res().normalFont->CharWidth(), timeSeparatorOffset.Y());
183 Res().normalFont->DrawNumber(game->state->time / 60, screen, offset + minutesOffset, 2);
184 if (game->state->time / 60 < 10) {
185 Res().normalFont->DrawChar('0', screen, offset + minutesOffset);
188 Vector<int> goldLabelOffset(2 * Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() * 3 / 4);
189 Res().normalFont->DrawString(Res().mainMenuGoldText, screen, offset + goldLabelOffset);
191 Vector<int> goldOffset(goldLabelOffset.X() + 6 * Res().normalFont->CharWidth(), goldLabelOffset.Y());
192 Res().normalFont->DrawNumber(game->state->money, screen, offset + goldOffset, 7);
196 Resources &PartyMenu::Res() {
197 return *game->menuResources;
200 const Resources &PartyMenu::Res() const {
201 return *game->menuResources;
204 void PartyMenu::OnEquipSelect(void *ref, int index) {
205 PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
206 self->Ctrl().ChangeState(
207 new EquipMenu(self, index));
210 void PartyMenu::OnSpellSelect(void *ref, int index) {
211 PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
212 self->Ctrl().ChangeState(
213 new SpellMenu(self, index));
216 void PartyMenu::OnStatusSelect(void *ref, int index) {
217 PartyMenu *self(reinterpret_cast<PartyMenu *>(ref));
218 self->Ctrl().ChangeState(
219 new StatusMenu(self, index));