4 * Created on: Oct 21, 2012
10 #include "Resources.h"
11 #include "../app/Application.h"
12 #include "../app/Input.h"
13 #include "../common/GameConfig.h"
14 #include "../common/GameState.h"
15 #include "../geometry/Vector.h"
16 #include "../graphics/Font.h"
17 #include "../graphics/Frame.h"
18 #include "../graphics/Texture.h"
21 using common::GameConfig;
22 using geometry::Vector;
26 PartyMenu::PartyMenu(GameConfig *game)
28 , mainMenu(*game->menuResources->mainMenuProperties) {
29 for (int i(0); i < 4; ++i) {
30 status[i].SetHero(game->state->party[i]);
31 status[i].SetResources(game->menuResources);
33 status[1].SetPosition(Vector<int>(status[0].Width() + Res().normalFont->CharWidth(), 0));
34 status[2].SetPosition(Vector<int>(0, status[0].Height() + Res().normalFont->CharHeight()));
35 status[3].SetPosition(Vector<int>(status[0].Width() + Res().normalFont->CharWidth(), status[0].Height() + Res().normalFont->CharHeight()));
37 mainMenu.Add(Res().mainMenuItemText, 0);
38 mainMenu.Add(Res().mainMenuStatusText, 4);
39 mainMenu.Add(Res().mainMenuSpellText, 1);
40 mainMenu.Add(Res().mainMenuChangeText, 5);
41 mainMenu.Add(Res().mainMenuCapsuleText, 2);
42 mainMenu.Add(Res().mainMenuConfigText, 6);
43 mainMenu.Add(Res().mainMenuEquipmentText, 3);
44 mainMenu.Add(Res().mainMenuScenarioText, 7);
47 PartyMenu::~PartyMenu() {
52 void PartyMenu::OnEnterState(SDL_Surface *) {
56 void PartyMenu::OnExitState(SDL_Surface *) {
60 void PartyMenu::OnResumeState(SDL_Surface *) {
64 void PartyMenu::OnPauseState(SDL_Surface *) {
69 void PartyMenu::OnResize(int width, int height) {
74 void PartyMenu::HandleEvents(const Input &input) {
75 if (input.JustPressed(Input::ACTION_B)) {
80 if (input.JustPressed(Input::PAD_UP)) {
81 mainMenu.PreviousRow();
82 } else if (input.JustPressed(Input::PAD_RIGHT)) {
84 } else if (input.JustPressed(Input::PAD_DOWN)) {
86 } else if (input.JustPressed(Input::PAD_LEFT)) {
87 mainMenu.PreviousItem();
91 void PartyMenu::UpdateWorld(float deltaT) {
95 void PartyMenu::Render(SDL_Surface *screen) {
96 Res().menubg->Render(screen, Vector<int>(), Vector<int>(screen->w, screen->h));
97 RenderHeros(screen, Vector<int>(Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight()));
98 RenderMenu(screen, Vector<int>(8 * Res().normalFont->CharWidth(), 13 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
99 RenderInfo(screen, Vector<int>(14 * Res().normalFont->CharWidth(), 21 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
102 void PartyMenu::RenderHeros(SDL_Surface *screen, const Vector<int> &offset) const {
103 for (int i(0); i < 4; ++i) {
104 status[i].Render(screen, offset);
108 void PartyMenu::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) const {
109 Vector<int> menuOffset(3 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
111 Res().statusFrame->Draw(screen, offset, 23 * Res().normalFont->CharWidth(), 8 * Res().normalFont->CharHeight());
112 mainMenu.Draw(screen, offset + menuOffset);
115 void PartyMenu::RenderInfo(SDL_Surface *screen, const Vector<int> &offset) const {
116 Res().statusFrame->Draw(screen, offset, 17 * Res().normalFont->CharWidth(), 5 * Res().normalFont->CharHeight());
118 Vector<int> timeLabelOffset(2 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
119 Res().normalFont->DrawString(Res().mainMenuTimeText, screen, offset + timeLabelOffset);
121 Vector<int> hoursOffset(timeLabelOffset.X() + 6 * Res().normalFont->CharWidth(), timeLabelOffset.Y());
122 Res().normalFont->DrawNumber(game->state->time / 60 / 60, screen, offset + hoursOffset, 4);
124 Vector<int> timeSeparatorOffset(hoursOffset.X() + 4 * Res().normalFont->CharWidth(), hoursOffset.Y());
125 Res().normalFont->DrawChar(':', screen, offset + timeSeparatorOffset);
127 Vector<int> minutesOffset(timeSeparatorOffset.X() + Res().normalFont->CharWidth(), timeSeparatorOffset.Y());
128 Res().normalFont->DrawNumber(game->state->time / 60, screen, offset + minutesOffset, 2);
129 if (game->state->time / 60 < 10) {
130 Res().normalFont->DrawChar('0', screen, offset + minutesOffset);
133 Vector<int> goldLabelOffset(2 * Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() * 3 / 4);
134 Res().normalFont->DrawString(Res().mainMenuGoldText, screen, offset + goldLabelOffset);
136 Vector<int> goldOffset(goldLabelOffset.X() + 6 * Res().normalFont->CharWidth(), goldLabelOffset.Y());
137 Res().normalFont->DrawNumber(game->state->money, screen, offset + goldOffset, 7);
141 Resources &PartyMenu::Res() {
142 return *game->menuResources;
145 const Resources &PartyMenu::Res() const {
146 return *game->menuResources;