Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Music #37

Open
wants to merge 9 commits into
base: developing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ find_package(Qt5 COMPONENTS
Network
WebSockets
REQUIRED
Multimedia
)

include_directories(Resources/Images/Buttons)
Expand Down Expand Up @@ -85,6 +86,7 @@ add_executable(client
src/Client/View/GameWidget/WaitingScreen/waiting_screen.cpp
src/Client/View/FinalScreen/final_screen.cpp
src/Client/View/NetworkProblemWidget/network_problem_widget.cpp
Resources/Sound/Sound.qrc
src/Client/Games/TerminalMinigameView/terminal_minigame_view.cpp
)

Expand All @@ -94,6 +96,7 @@ set(REQUIRED_QT_PARTS
Qt::Widgets
Qt::Network
Qt::WebSockets
Qt::Multimedia
)

foreach (executable server; client)
Expand Down
5 changes: 5 additions & 0 deletions Resources/Sound/Sound.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource>
<file>sound.wav</file>
</qresource>
</RCC>
Binary file added Resources/Sound/sound.wav
Binary file not shown.
81 changes: 75 additions & 6 deletions src/Client/View/MainMenu/client_main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

ClientMainMenu::ClientMainMenu(QWidget* parent) :
QWidget(parent),
setting_(new QSettings(this)),
background_(new BackgroundWidget(this)),
sound_on_(new QPushButton(this)),
background_layout_(new QGridLayout),
game_name_(new QLabel("SpaceGate", this)),
interface_layout_(new QGridLayout),
Expand All @@ -21,7 +23,9 @@ ClientMainMenu::ClientMainMenu(QWidget* parent) :
player_list_(new QListWidget(this)),
rooms_list_(new QListWidget(this)),
nothing_here_(new QLabel(this)),
interface_(new QWidget(this)) {
interface_(new QWidget(this)),
set_sound_(new QSpinBox(this)) {
set_sound_->setVisible(0);
QString family =
QFontDatabase::applicationFontFamilies(QFontDatabase::addApplicationFont(
"../Resources/Fonts/Paladins.otf")).at(0);
Expand All @@ -33,11 +37,12 @@ ClientMainMenu::ClientMainMenu(QWidget* parent) :
font_.setPointSize(105);
font_.setBold(true);
game_name_->setFont(font_);

sound_ = new QSoundEffect(this);
SetMouseTracking();
SetLayouts();
ShowStartWidget();
Connect();
SetSound();
}
void ClientMainMenu::SetCenterPos(QPoint pos) {
background_->SetCenterPos(pos);
Expand Down Expand Up @@ -139,14 +144,45 @@ void ClientMainMenu::Connect() {
&ClientMainMenu::BackToGameOption);
connect(exit_,
&QPushButton::clicked,
[this]() { emit Close(); });
[this]() { emit Close();});
connect(back_to_start_,
&QPushButton::clicked,
this,
&ClientMainMenu::BackToStart);
connect(settings_, &QPushButton::clicked, this, &ClientMainMenu::Settings);
connect(ready_status_,
&QPushButton::clicked, this, &ClientMainMenu::ReadyButtonPressEvent);
connect(set_sound_, QOverload<int>::of(&QSpinBox::valueChanged),
this, [&](int value){
if (value > 0) {
sound_on_->setText("Turn Off");
sound_->setMuted(0);
} else {
sound_on_->setText("Turn On");
sound_->setMuted(1);
}
sound_->setVolume(static_cast<double>(value) / 100);
setting_->setValue("sound_value", sound_->volume());
setting_->setValue("spin_box_value", value);
setting_->setValue("muted", sound_->isMuted());
});
connect(sound_on_, &QPushButton::clicked, this, [&](){
if (sound_->isMuted()) {
sound_->setMuted(0);
sound_on_->setText("Turn Off");
} else {
sound_->setMuted(1);
sound_on_->setText("Turn On");
}
setting_->setValue("muted", sound_->isMuted());
});
connect(sound_, &QSoundEffect::mutedChanged, this, [&](){
if (sound_->isMuted()) {
sound_on_->setText("Turn On");
} else {
sound_on_->setText("Turn Off");
}
});
}

void ClientMainMenu::ChooseRoomOption() {
Expand Down Expand Up @@ -192,6 +228,8 @@ void ClientMainMenu::RemoveAllWidgets() {
ready_status_->setVisible(false);
rooms_list_->setVisible(false);
nothing_here_->setVisible(false);
set_sound_->setVisible(false);
sound_on_->setVisible(false);

interface_layout_->removeWidget(create_room_);
interface_layout_->removeWidget(join_room_);
Expand Down Expand Up @@ -224,17 +262,36 @@ void ClientMainMenu::JoinRoom() {

void ClientMainMenu::Settings() {
RemoveAllWidgets();
set_sound_->setFixedSize(400, 100);
set_sound_->setSpecialValueText("Volume");
set_sound_->setFont(font_);
set_sound_->setStyleSheet("color : #88bcff; font-size: 10px; aligment : "
"Qt::AlignCenter");
set_sound_->setRange(0, 100);
set_sound_->setValue((setting_->value("spin_box_value")).toInt());
sound_->setMuted((setting_->value("muted").toBool()));
set_sound_->setVisible(true);

nothing_here_->setVisible(true);
back_to_start_->setVisible(true);

nothing_here_->setText("Nothing Here");
sound_on_->setVisible(true);
sound_on_->setFixedSize(400, 100);
sound_on_->setText("Turn Off");
sound_on_->setFont(font_);
sound_on_->setStyleSheet("color : #88bcff; font-size: 40px;");

nothing_here_->setText("Adjust Sound");
nothing_here_->setFont(font_);
nothing_here_->setStyleSheet("QLabel {color : #88bcff; font-size: 40px;}");
nothing_here_->setStyleSheet("color : #88bcff; font-size: 40px;");

interface_layout_->addWidget(nothing_here_, 1, 0, 1, 2,
Qt::AlignHCenter | Qt::AlignVCenter);
interface_layout_->addWidget(back_to_start_, 3, 0, 1, 2,
interface_layout_->addWidget(back_to_start_, 4, 0, 1, 2,
Qt::AlignHCenter | Qt::AlignVCenter);
interface_layout_->addWidget(set_sound_, 2, 0, 1, 2,
Qt::AlignHCenter | Qt::AlignVCenter);
interface_layout_->addWidget(sound_on_, 3, 0, 1, 2,
Qt::AlignHCenter | Qt::AlignVCenter);
}

Expand Down Expand Up @@ -386,3 +443,15 @@ void ClientMainMenu::BackToLobby() {
ShowRoomGuestInterface();
}
}
void ClientMainMenu::SetSound() {
sound_->setSource(QUrl::fromLocalFile(":sound.wav"));
auto volume = setting_->value("sound_value");
if (!volume.isNull()) {
sound_->setVolume(volume.toDouble());
} else {
sound_->setVolume(0.5);
}
sound_->setMuted((setting_->value("muted")).toBool());
sound_->setLoopCount(1000);
sound_->play();
}
11 changes: 11 additions & 0 deletions src/Client/View/MainMenu/client_main_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QFont>
#include "QSoundEffect"
#include "QSpinBox"
#include "QSettings"

class ClientMainMenu : public QWidget {
Q_OBJECT
Expand Down Expand Up @@ -42,6 +45,8 @@ class ClientMainMenu : public QWidget {
void JoinRoom();
void Settings();
void ReadyButtonPressEvent();
void SetSound();
void SoundValueChangedEvent();

private:
BackgroundWidget* background_;
Expand All @@ -62,13 +67,18 @@ class ClientMainMenu : public QWidget {
QLabel* nothing_here_;
QWidget* interface_;
QFont font_;
QSoundEffect* sound_;
QSpinBox* set_sound_;
QSettings* setting_;
QPushButton* sound_on_;

bool is_chief_{true};
static QColor StatusToColor(server_events::RoomUser::Status status);

void ShowRoomChiefInterface();
void ShowRoomGuestInterface();


signals:
void StartEffect(bool state);
void Close();
Expand All @@ -77,5 +87,6 @@ class ClientMainMenu : public QWidget {
void LeaveRoom();
void JoinRoomSignal(RoomId room_id);
void StartGame();
void SoundValueChanged();
};

2 changes: 2 additions & 0 deletions src/Client/View/client_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ClientView::ClientView() :
final_screen_(new FinalScreen(this)),
input_controller_(new InputController),
network_problem_widget_(new NetworkProblemWidget(this)) {
QSound sound(":sound.wav");
sound.play(":sound.wav");
AddWidgets();
stacked_widget_->setCurrentWidget(main_menu_);
setCentralWidget(stacked_widget_);
Expand Down
1 change: 1 addition & 0 deletions src/Client/View/client_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QWidget>
#include <QStackedWidget>
#include <QMainWindow>
#include "QSound"

class ClientView : public QMainWindow {
Q_OBJECT
Expand Down