4 * Created on: Oct 21, 2012
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"
23 using common::GameConfig;
24 using geometry::Vector;
28 PartyMenu::PartyMenu(GameConfig *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);
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()));
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()) {
98 case MENU_ITEM_CAPSULE:
100 case MENU_ITEM_EQUIP:
102 case MENU_ITEM_STATUS:
103 Ctrl().PushState(new SelectHero(this, OnStatusSelect));
105 case MENU_ITEM_CHANGE:
107 case MENU_ITEM_CONFIG:
109 case MENU_ITEM_SCENARIO:
117 void PartyMenu::UpdateWorld(float deltaT) {
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));
128 Vector<int> PartyMenu::StatusOffset() const {
129 return Vector<int>(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight());
132 void PartyMenu::RenderBackground(SDL_Surface *screen) const {
133 Res().menubg->Render(screen, Vector<int>(), Vector<int>(screen->w, screen->h));
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);
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);
145 Res().statusFrame->Draw(screen, offset, 23 * Res().normalFont->CharWidth(), 8 * Res().normalFont->CharHeight());
146 mainMenu.Draw(screen, offset + menuOffset);
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());
152 Vector<int> timeLabelOffset(2 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
153 Res().normalFont->DrawString(Res().mainMenuTimeText, screen, offset + timeLabelOffset);
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);
158 Vector<int> timeSeparatorOffset(hoursOffset.X() + 4 * Res().normalFont->CharWidth(), hoursOffset.Y());
159 Res().normalFont->DrawChar(':', screen, offset + timeSeparatorOffset);
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);
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);
170 Vector<int> goldOffset(goldLabelOffset.X() + 6 * Res().normalFont->CharWidth(), goldLabelOffset.Y());
171 Res().normalFont->DrawNumber(game->state->money, screen, offset + goldOffset, 7);
175 Resources &PartyMenu::Res() {
176 return *game->menuResources;
179 const Resources &PartyMenu::Res() const {
180 return *game->menuResources;
183 void PartyMenu::OnStatusSelect(PartyMenu *self, int index) {
184 self->Ctrl().ChangeState(new StatusMenu(self));