]> git.localhorst.tv Git - l2e.git/blob - src/menu/ConfigMenu.cpp
added basic config menu
[l2e.git] / src / menu / ConfigMenu.cpp
1 /*
2  * ConfigMenu.cpp
3  *
4  *  Created on: Nov 29, 2012
5  *      Author: holy
6  */
7
8 #include "ConfigMenu.h"
9
10 #include "PartyMenu.h"
11 #include "Resources.h"
12 #include "../common/GameConfig.h"
13 #include "../common/GameState.h"
14 #include "../graphics/Font.h"
15 #include "../graphics/Frame.h"
16
17 using app::Input;
18 using geometry::Vector;
19 using graphics::Font;
20 using graphics::Frame;
21
22 namespace menu {
23
24 ConfigMenu::ConfigMenu(PartyMenu *parent)
25 : parent(parent)
26 , configMenu(*parent->Res().configMenuProperties) {
27         configMenu.Add(parent->Res().configMessageSpeedLabel, 0);
28         configMenu.Add(parent->Res().configBattleCursorLabel, 1);
29         configMenu.Add(parent->Res().configStatusCursorLabel, 2);
30         configMenu.Add(parent->Res().configMusicLabel, 3);
31 }
32
33
34 void ConfigMenu::OnEnterState(SDL_Surface *) {
35
36 }
37
38 void ConfigMenu::OnExitState(SDL_Surface *) {
39
40 }
41
42 void ConfigMenu::OnResumeState(SDL_Surface *) {
43
44 }
45
46 void ConfigMenu::OnPauseState(SDL_Surface *) {
47
48 }
49
50
51 void ConfigMenu::OnResize(int width, int height) {
52
53 }
54
55
56 int ConfigMenu::Width() const {
57         return parent->Width();
58 }
59
60 int ConfigMenu::Height() const {
61         return parent->Height();
62 }
63
64
65 void ConfigMenu::HandleEvents(const Input &input) {
66         if (input.JustPressed(Input::ACTION_B)) {
67                 Ctrl().PopState();
68         }
69         if (input.JustPressed(Input::PAD_DOWN)) {
70                 configMenu.NextRow();
71         }
72         if (input.JustPressed(Input::PAD_UP)) {
73                 configMenu.PreviousRow();
74         }
75 }
76
77 void ConfigMenu::UpdateWorld(float deltaT) {
78
79 }
80
81 void ConfigMenu::Render(SDL_Surface *screen) {
82         const Font &font(*parent->Res().normalFont);
83         const Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
84         const Vector<int> headlineOffset(
85                         font.CharWidth(), 2 * font.CharHeight() - font.CharHeight() / 8);
86         const Vector<int> menuOffset(
87                         font.CharWidth(), 5 * font.CharHeight() - font.CharHeight() / 8);
88
89         parent->RenderBackground(screen);
90         RenderHeadline(screen, offset + headlineOffset);
91         RenderMenu(screen, offset + menuOffset);
92 }
93
94 void ConfigMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
95         const Font &font(*parent->Res().normalFont);
96         const Frame &frame(*parent->Res().statusFrame);
97         const Vector<int> textOffset(
98                         2 * font.CharWidth(), font.CharHeight());
99
100         frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
101         font.DrawString(parent->Res().mainMenuConfigText, screen, offset + textOffset, 6);
102 }
103
104 void ConfigMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
105         const Font &font(*parent->Res().normalFont);
106         const Frame &frame(*parent->Res().statusFrame);
107         const Vector<int> menuOffset(
108                         3 * font.CharWidth(), 2 * font.CharHeight());
109
110         frame.Draw(screen, offset, 30 * font.CharWidth(), 14 * font.CharHeight());
111         configMenu.Draw(screen, offset + menuOffset);
112 }
113
114 }