-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.cpp
153 lines (130 loc) · 5.07 KB
/
options.cpp
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
#include "options.h"
#include "ui_options.h"
#include <iostream>
int Options::voiceLevel = 100;
Options::Options(QWidget *parent) :
QDialog(parent),
ui(new Ui::Options)
{
this->setFixedSize(350,300);
ui->setupUi(this);
setUpConnections();
}
void Options::setUpConnections()
{
//game items properties
connect(ui->ball_size_slider,&QSlider::valueChanged,
[this](const int &val)->void{ui->ball_size_edit->setText(QString::number(val/10.0));});
connect(ui->ball_speed_slider,&QSlider::valueChanged,
[this](const int &val)->void{ui->ball_speed_edit->setText(QString::number(val/10.0));});
connect(ui->player_size_slider,&QSlider::valueChanged,
[this](const int &val)->void{ui->player_size_edit->setText(QString::number(val/10.0));});
connect(ui->player_speed_slider,&QSlider::valueChanged,
[this](const int &val)->void{ui->player_speed_edit->setText(QString::number(val/10.0));});
//sounds
connect(ui->sound_slider, &QSlider::valueChanged,
[this](const int &val)->void{
if(val==0)
ui->mute_check_box->setChecked(true);
else
{
ui->mute_check_box->setChecked(false);
voiceLevel = val;
}
ui->sound_edit->setText(QString::number(val));
}
);
connect(ui->mute_check_box, &QCheckBox::stateChanged,
[this]()->void{
if(ui->mute_check_box->isChecked())
ui->sound_slider->setValue(0);
else
ui->sound_slider->setValue(voiceLevel);
}
);
//game control
connect(ui->endless_check_box, &QCheckBox::stateChanged,
[this]()->void{
if(ui->endless_check_box->isChecked())
ui->score_to_win_spin_box->setEnabled(false);
else
ui->score_to_win_spin_box->setEnabled(true);
}
);
connect(ui->mouse_mode_radio_button, &QRadioButton::clicked,
[this](const bool &val)->void{
if(val == false)
{
ui->keyboard_mode_radio_button->setChecked(val);
ui->mouse_mode_radio_button->setChecked(!val);
}
else
{
ui->keyboard_mode_radio_button->setChecked(!val);
ui->mouse_mode_radio_button->setChecked(val);
}
}
);
connect(ui->keyboard_mode_radio_button, &QRadioButton::clicked,
[this](const bool &val)->void{
if(val == false)
{
ui->keyboard_mode_radio_button->setChecked(!val);
ui->mouse_mode_radio_button->setChecked(val);
}
else
{
ui->keyboard_mode_radio_button->setChecked(val);
ui->mouse_mode_radio_button->setChecked(!val);
}
}
);
}
int Options::getVoiceLevel()
{
return voiceLevel;
}
double Options::getBallSize() const
{
return ui->ball_size_edit->text().toDouble();
}
double Options::getBallSpeed() const
{
return ui->ball_speed_edit->text().toDouble();
}
double Options::getPlayerSize() const
{
return ui->player_size_edit->text().toDouble();
}
double Options::getPlayerSpeed() const
{
return ui->player_speed_edit->text().toDouble();
}
int Options::getSound() const
{
return ui->sound_edit->text().toInt();
}
bool Options::getMouseMode() const
{
return ui->mouse_mode_radio_button->isChecked();
}
bool Options::getKeyboardMode() const
{
return ui->keyboard_mode_radio_button->isChecked();
}
bool Options::getEndlessGame() const
{
return ui->endless_check_box->isChecked();
}
unsigned int Options::getScoreToWin() const
{
return ui->score_to_win_spin_box->value();
}
void Options::setVolume(int volume)
{
ui->sound_slider->setValue(volume);
}
Options::~Options()
{
delete ui;
}