]> git.localhorst.tv Git - l2e.git/blob - src/menu/PartyMenu.cpp
added party main menu 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 "../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"
19
20 using app::Input;
21 using common::GameConfig;
22 using geometry::Vector;
23
24 namespace menu {
25
26 PartyMenu::PartyMenu(GameConfig *game)
27 : game(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);
32         }
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()));
36
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);
45 }
46
47 PartyMenu::~PartyMenu() {
48
49 }
50
51
52 void PartyMenu::OnEnterState(SDL_Surface *) {
53
54 }
55
56 void PartyMenu::OnExitState(SDL_Surface *) {
57
58 }
59
60 void PartyMenu::OnResumeState(SDL_Surface *) {
61
62 }
63
64 void PartyMenu::OnPauseState(SDL_Surface *) {
65
66 }
67
68
69 void PartyMenu::OnResize(int width, int height) {
70
71 }
72
73
74 void PartyMenu::HandleEvents(const Input &input) {
75         if (input.JustPressed(Input::ACTION_B)) {
76                 Ctrl().PopState();
77                 return;
78         }
79
80         if (input.JustPressed(Input::PAD_UP)) {
81                 mainMenu.PreviousRow();
82         } else if (input.JustPressed(Input::PAD_RIGHT)) {
83                 mainMenu.NextItem();
84         } else if (input.JustPressed(Input::PAD_DOWN)) {
85                 mainMenu.NextRow();
86         } else if (input.JustPressed(Input::PAD_LEFT)) {
87                 mainMenu.PreviousItem();
88         }
89 }
90
91 void PartyMenu::UpdateWorld(float deltaT) {
92
93 }
94
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));
100 }
101
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);
105         }
106 }
107
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);
110
111         Res().statusFrame->Draw(screen, offset, 23 * Res().normalFont->CharWidth(), 8 * Res().normalFont->CharHeight());
112         mainMenu.Draw(screen, offset + menuOffset);
113 }
114
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());
117
118         Vector<int> timeLabelOffset(2 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
119         Res().normalFont->DrawString(Res().mainMenuTimeText, screen, offset + timeLabelOffset);
120
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);
123
124         Vector<int> timeSeparatorOffset(hoursOffset.X() + 4 * Res().normalFont->CharWidth(), hoursOffset.Y());
125         Res().normalFont->DrawChar(':', screen, offset + timeSeparatorOffset);
126
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);
131         }
132
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);
135
136         Vector<int> goldOffset(goldLabelOffset.X() + 6 * Res().normalFont->CharWidth(), goldLabelOffset.Y());
137         Res().normalFont->DrawNumber(game->state->money, screen, offset + goldOffset, 7);
138 }
139
140
141 Resources &PartyMenu::Res() {
142         return *game->menuResources;
143 }
144
145 const Resources &PartyMenu::Res() const {
146         return *game->menuResources;
147 }
148
149 }