From ce48af53646cd9e7ec762fc1ac176b3aa620b11d Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 5 May 2011 00:57:07 +0200 Subject: - refactorized the whole project and made a few subprojects - replaced tcp with enet - added connect dialog - some smaller bugfixes --- pacman-c++/client.cpp | 179 -------------------------------------------------- 1 file changed, 179 deletions(-) delete mode 100644 pacman-c++/client.cpp (limited to 'pacman-c++/client.cpp') diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp deleted file mode 100644 index 581778e..0000000 --- a/pacman-c++/client.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include "client.h" -#include "clicklabel.h" -#include "audio.h" -#include "util.h" -#include "pacman.pb.h" - -Client::Client() - : m_ambientMuted(false) -{ - m_settings = new QSettings(qApp->organizationName(), qApp->applicationName(), this); - createMenu(); - m_mainWidget = new MainWidget(this); - m_mainWidget->setAmbientMuted(m_ambientMuted); - setCentralWidget(m_mainWidget); -} - -void Client::createMenu() -{ - QMenu *fileMenu = menuBar()->addMenu("File"); - - bool sound = AudioManager::self()->isWorking(); - bool muted = !sound || m_settings->value("muted", false).toBool(); - AudioManager::self()->setMuted(muted); - - /* toggle sound: corner icon */ - ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this); - toggleSound->setToolTip("Toggle Sound"); - toggleSound->setFixedWidth(20); - toggleSound->setFixedHeight(16); - toggleSound->setAlignment(Qt::AlignBottom); - toggleSound->setPixmap(soundIcon(!muted)); - if (sound) - { - connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); - connect(AudioManager::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool))); - } - menuBar()->setCornerWidget(toggleSound); - - /* toggle sound: menu */ - QAction *toggleSoundAction = new QAction("&Sound", this); - toggleSoundAction->setToolTip("Toggle Sound"); - toggleSoundAction->setCheckable(true); - toggleSoundAction->setChecked(!muted); - toggleSoundAction->setDisabled(!sound); - fileMenu->addAction(toggleSoundAction); - if (sound) - { - connect(toggleSoundAction, SIGNAL(triggered()), this, SLOT(toggleSound())); - connect(this, SIGNAL(setMuteActionsChecked(bool)), toggleSoundAction, SLOT(setChecked(bool))); - } - - /* toggle ambient sound: menu */ - m_ambientMuted = muted || m_settings->value("ambientMuted", false).toBool(); - QAction *toggleAmbientAction = new QAction("&Ambient Sound", this); - toggleAmbientAction->setToolTip("Toggle Ambient Sound"); - toggleAmbientAction->setCheckable(true); - toggleAmbientAction->setChecked(!m_ambientMuted); - toggleAmbientAction->setDisabled(!sound); - fileMenu->addAction(toggleAmbientAction); - if (sound) - { - connect(toggleAmbientAction, SIGNAL(triggered(bool)), this, SLOT(enableAmbientSound(bool))); - connect(this, SIGNAL(setMuteActionsChecked(bool)), toggleAmbientAction, SLOT(setEnabled(bool))); - } - - /* exit entry */ - fileMenu->addSeparator(); - QAction *quitAction = new QAction("E&xit", this); - quitAction->setIcon(QIcon::fromTheme(QLatin1String("application-exit"))); - fileMenu->addAction(quitAction); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - - - QAction *aboutAction= menuBar()->addAction("Ab&out"); - connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout())); -} - -void Client::toggleSound() -{ - if (!AudioManager::self()->isWorking()) - return; - bool muted = !AudioManager::self()->isMuted(); - AudioManager::self()->setMuted(muted); - /* mute ambient sound again if explicitly muted */ - if (!muted && m_ambientMuted) - m_mainWidget->setAmbientMuted(true); -} - -void Client::mutedChanged(bool muted) -{ - ClickLabel *tmp = qobject_cast(menuBar()->cornerWidget()); - tmp->setPixmap(soundIcon(!muted)); - m_settings->setValue("muted", muted); - emit setMuteActionsChecked(!muted); -} - -void Client::enableAmbientSound(bool enabled) -{ - if (!AudioManager::self()->isWorking()) - return; - m_ambientMuted = !enabled; - m_mainWidget->setAmbientMuted(m_ambientMuted); - m_settings->setValue("ambientMuted", m_ambientMuted); -} - -QPixmap Client::soundIcon(bool enabled) const -{ - QImage img(enabled ? ":/soundon" : ":/soundoff"); - img.setColor(1, menuBar()->palette().color( - enabled ? QPalette::Active : QPalette::Disabled, - QPalette::ButtonText).rgba()); - return QPixmap::fromImage(img); -} - -void Client::showAbout() -{ - QDialog *about = new QDialog(this); - about->setWindowTitle("About Pacman"); - about->setWindowFlags(about->windowFlags() & ~Qt::WindowContextHelpButtonHint); - - QGridLayout *layout = new QGridLayout(about); - layout->setSizeConstraint(QLayout::SetFixedSize); - - QString actoricons; - for(int i = 0; Color::order[i] != Color::none; ++i) - actoricons += QString("").arg(i + 1); - - const QString text = QString( - "

Multiplayer Pacman %1

" - "Authors: H. Demel, B. Mallinger, M. Mausz, M. Racz
" - "
" - "Gameplay based on Pacman" - ", © Namco 1980
" - "
" - "Developed using Qt %2 (%3 bit)
") - .arg(actoricons, QLatin1String(QT_VERSION_STR), QString::number(QSysInfo::WordSize)); - - QLabel *label = new QLabel(text); - label->setWordWrap(true); - label->setOpenExternalLinks(true); - label->setTextInteractionFlags(Qt::TextBrowserInteraction); - - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); - QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close); - buttonBox->addButton(closeButton, QDialogButtonBox::ButtonRole(QDialogButtonBox::RejectRole | QDialogButtonBox::AcceptRole)); - connect(buttonBox , SIGNAL(rejected()), about, SLOT(reject())); - - layout->addWidget(label, 0, 1, 4, 4); - layout->addWidget(buttonBox, 4, 0, 1, 5); - about->show(); -} - -bool Constants::server = false; - -int main(int argc, char **argv) -{ - /* Verify that the version of the library that we linked against is - * compatible with the version of the headers we compiled against. - */ - GOOGLE_PROTOBUF_VERIFY_VERSION; - - QApplication app(argc, argv, true); - app.setOrganizationName("TU Wien FOOP"); - app.setApplicationName("Pacman Client"); - app.setWindowIcon(QIcon(":/appicon")); - - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); - - Client client; - client.show(); - client.setWindowTitle(app.applicationName()); - - int ret = app.exec(); - - /* Delete all global objects allocated by libprotobuf */ - google::protobuf::ShutdownProtobufLibrary(); - - return ret; -} -- cgit v1.2.3