-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptionsMenuState.cpp
More file actions
162 lines (142 loc) · 5.07 KB
/
OptionsMenuState.cpp
File metadata and controls
162 lines (142 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "OptionsMenuState.h"
OptionsMenuState::OptionsMenuState():State()
{
std::cout << "Konstruktor OptionsMenuState!" << std::endl;
}
void OptionsMenuState::Init()
{
music = new Button(GameEngine::getInstance()->getSteering(),
sf::Vector2f((float)(GameEngine::SCREEN_WIDTH/2 -50.0),
(float)(GameEngine::SCREEN_HEIGHT/2 - 100.0)),
sf::Vector2f(100.0,50.0),
sf::Color(125,125,125),
"Muzyka");
sounds = new Button(GameEngine::getInstance()->getSteering(),
sf::Vector2f((float)(GameEngine::SCREEN_WIDTH/2 -50.0),
(float)GameEngine::SCREEN_HEIGHT/2),
sf::Vector2f(100.0,50.0),
sf::Color(125,125,125),
"Dzwieki");
mainMenu = new Button(GameEngine::getInstance()->getSteering(),
sf::Vector2f((float)(GameEngine::SCREEN_WIDTH/2 -50.0),
(float)(GameEngine::SCREEN_HEIGHT/2 + 200)),
sf::Vector2f(100.0,50.0),
sf::Color(125,125,125),
"Powrot");
musicTextBox = new TextBox(sf::Vector2f((float)(GameEngine::SCREEN_WIDTH/2 +100 ),
(float)( GameEngine::SCREEN_HEIGHT/2 - 100.0 ) ),
sf::Vector2f((float)(50),(float)(50)) );
soundTextBox = new TextBox(sf::Vector2f((float)(GameEngine::SCREEN_WIDTH/2 +100 ),
(float)(GameEngine::SCREEN_HEIGHT/2 )),
sf::Vector2f((float)(50),(float)(50)) );
fullscreen = new Button(GameEngine::getInstance()->getSteering(),
sf::Vector2f((float)(GameEngine::SCREEN_WIDTH/2 -50.0),
(float)(GameEngine::SCREEN_HEIGHT/2 + 100)),
sf::Vector2f(100.0,50.0),
sf::Color(125,125,125),
"Fullscreen");
fullscreenTextBox = new TextBox(sf::Vector2f((float)(GameEngine::SCREEN_WIDTH/2 +100 ),
(float)(GameEngine::SCREEN_HEIGHT/2 + 100 )),
sf::Vector2f((float)(50),(float)(50)) );
musicTextBox->SetText( GameEngine::getInstance()->getMusic().GetStatus() == sf::Sound::Playing ? "Tak" : "Nie" );
musicTextBox->SetTextPosition( sf::Vector2f( musicTextBox->GetTextBoxPosition().x + 10 ,musicTextBox->GetTextBoxPosition().y + 15 ) );
soundTextBox->SetText( GameEngine::getInstance()->Sounds() ? "Tak" : "Nie" );
soundTextBox->SetTextPosition( sf::Vector2f( soundTextBox->GetTextBoxPosition().x + 10 ,soundTextBox->GetTextBoxPosition().y + 15 ) );
fullscreenTextBox->SetText( GameEngine::getInstance()->IsFullscreen() ? "Tak" : "Nie" );
fullscreenTextBox->SetTextPosition( sf::Vector2f( fullscreenTextBox->GetTextBoxPosition().x + 10 ,fullscreenTextBox->GetTextBoxPosition().y + 15 ) );
title.SetImage(ImageManager::getInstance()->loadImage("Data/Textures/title.png"));
title.SetCenter(0, 0);
title.SetPosition(105,50);
info.SetText("alpha version");
info.SetScale(0.5, 0.5);
info.SetPosition(560, 140);
init = 1;
}
void OptionsMenuState::UpdateSystem()
{
}
void OptionsMenuState::Display()
{
GameEngine::getInstance()->SetDefaultView();
sounds->Display(&GameEngine::getInstance()->getWindow());
music->Display(&GameEngine::getInstance()->getWindow());
mainMenu->Display(&GameEngine::getInstance()->getWindow());
musicTextBox->Display(&GameEngine::getInstance()->getWindow());
soundTextBox->Display(&GameEngine::getInstance()->getWindow());
fullscreen->Display(&GameEngine::getInstance()->getWindow());
fullscreenTextBox->Display(&GameEngine::getInstance()->getWindow());
GameEngine::getInstance()->getWindow().Draw(title);
GameEngine::getInstance()->getWindow().Draw(info);
}
void OptionsMenuState::EventHandling()
{
GameEngine::getInstance()->SetDefaultView();
music->GetEvent();
sounds->GetEvent();
mainMenu->GetEvent();
fullscreen->GetEvent();
if ( mainMenu->pressed )
{
GameEngine::getInstance()->ChangeState(MAINMENU);
}
if ( music->singlePressed )
{
if ( GameEngine::getInstance()->getMusic().GetStatus() == sf::Sound::Playing )
{
GameEngine::getInstance()->getMusic().Stop();
musicTextBox->SetText( "Nie" );
}
else if ( GameEngine::getInstance()->getMusic().GetStatus() == sf::Sound::Stopped )
{
GameEngine::getInstance()->getMusic().Play();
musicTextBox->SetText( "Tak" );
}
}
if ( sounds->singlePressed )
{
std::string temp = soundTextBox->GetText().GetText();
if( temp == "Nie" )
{
GameEngine::getInstance()->SetSounds(true);
soundTextBox->SetText("Tak");
}
else
{
GameEngine::getInstance()->SetSounds(false);
soundTextBox->SetText("Nie");
}
}
if ( fullscreen->singlePressed )
{
std::string temp = fullscreenTextBox->GetText().GetText();
if( temp == "Nie" )
{
GameEngine::getInstance()->SetFullscreen(true);
fullscreenTextBox->SetText("Tak");
}
else
{
GameEngine::getInstance()->SetFullscreen(false);
fullscreenTextBox->SetText("Nie");
}
}
}
void OptionsMenuState::GetEvents()
{
sf::Event event = GameEngine::getInstance()->getEvent();
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
{
GameEngine::getInstance()->ChangeState(MAINMENU);
}
}
void OptionsMenuState::Cleanup()
{
delete sounds;
delete music;
delete mainMenu;
delete musicTextBox;
delete soundTextBox;
delete fullscreen;
delete fullscreenTextBox;
init = 0;
}