-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.cpp
More file actions
101 lines (90 loc) · 2.51 KB
/
Settings.cpp
File metadata and controls
101 lines (90 loc) · 2.51 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
#include "Settings.h"
Settings::Settings(MyWindow * window) : Panel(window)
{
//Init
if (!volume.loadFromFile("images/settings/volume.png")) {};
if (!music.loadFromFile("images/settings/music.png")) {};
if (!vsync.loadFromFile("images/settings/vsync.png")) {};
pbVolume = new MyProgressBar("images/settings/vol_bar.png");
back = new MyButton("images/settings/back.png", "images/settings/back_s.png");
_volume = sf::Sprite(volume);
_music = sf::Sprite(music);
_vsync = sf::Sprite(vsync);
cbMusic = new MyCheckbox();
cbVsync = new MyCheckbox();
//Init positions
_volume.setPosition(255, 255);
_music.setPosition(255,367);
_vsync.setPosition(255,479);
pbVolume->setPositionBar(820,273);
pbVolume->setPosition(986, 259);
cbMusic->setPosition(960,371);
cbVsync->setPosition(960,481);
back->setPosition(23, 28);
//Config sync
pbVolume->setPercentage(getWindow()->getConfig()->getVolume());
cbMusic->setChecked(getWindow()->getConfig()->isMusicOn());
cbVsync->setChecked(getWindow()->getConfig()->isVsyncOn());
}
Settings::~Settings()
{
delete pbVolume;
delete cbMusic;
delete cbVsync;
delete back;
}
void Settings::init()
{
back->setVolume(getWindow()->getConfig()->getVolume());
getWindow()->clear();
getWindow()->draw(getBackground());
getWindow()->draw(_volume);
getWindow()->draw(_music);
getWindow()->draw(_vsync);
getWindow()->draw(pbVolume->getSpriteBar());
getWindow()->draw(pbVolume->getSprite());
getWindow()->draw(cbMusic->getSprite());
getWindow()->draw(cbVsync->getSprite());
getWindow()->draw(back->getSprite());
}
int Settings::keyPressedOnce(sf::Keyboard::Key key)
{
switch (key) {
case(sf::Keyboard::Key::Escape): return Panel::PANEL_MENU; break;
}
return -1;
}
int Settings::keyPressed(int key)
{
return -1;
}
int Settings::mouseMove(int x, int y) {
if (back->isSelected(x, y)) {
back->changeTexture();
}
return -1;
}
int Settings::mouseClicked(int x, int y, sf::Mouse::Button button)
{
if (button == sf::Mouse::Button::Left) {
if (pbVolume->setPercentage(x, y)) {
getWindow()->getConfig()->setVolume(pbVolume->getPercentage());
}
else if (cbMusic->setChecked(x, y)) {
cbMusic->setChecked(!cbMusic->isChecked());
getWindow()->getConfig()->setMusic(cbMusic->isChecked());
}
else if (cbVsync->setChecked(x, y)) {
cbVsync->setChecked(!cbVsync->isChecked());
getWindow()->getConfig()->setVsync(cbVsync->isChecked());
}
else if (back->isSelected(x, y)) {
return Panel::PANEL_MENU;
}
}
return -1;
}
int Settings::getType() const
{
return Panel::PANEL_SETTINGS;
}