diff options
Diffstat (limited to 'pacman-c++/client.cpp')
| -rw-r--r-- | pacman-c++/client.cpp | 179 |
1 files changed, 0 insertions, 179 deletions
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 @@ | |||
| 1 | #include "client.h" | ||
| 2 | #include "clicklabel.h" | ||
| 3 | #include "audio.h" | ||
| 4 | #include "util.h" | ||
| 5 | #include "pacman.pb.h" | ||
| 6 | |||
| 7 | Client::Client() | ||
| 8 | : m_ambientMuted(false) | ||
| 9 | { | ||
| 10 | m_settings = new QSettings(qApp->organizationName(), qApp->applicationName(), this); | ||
| 11 | createMenu(); | ||
| 12 | m_mainWidget = new MainWidget(this); | ||
| 13 | m_mainWidget->setAmbientMuted(m_ambientMuted); | ||
| 14 | setCentralWidget(m_mainWidget); | ||
| 15 | } | ||
| 16 | |||
| 17 | void Client::createMenu() | ||
| 18 | { | ||
| 19 | QMenu *fileMenu = menuBar()->addMenu("File"); | ||
| 20 | |||
| 21 | bool sound = AudioManager::self()->isWorking(); | ||
| 22 | bool muted = !sound || m_settings->value("muted", false).toBool(); | ||
| 23 | AudioManager::self()->setMuted(muted); | ||
| 24 | |||
| 25 | /* toggle sound: corner icon */ | ||
| 26 | ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this); | ||
| 27 | toggleSound->setToolTip("Toggle Sound"); | ||
| 28 | toggleSound->setFixedWidth(20); | ||
| 29 | toggleSound->setFixedHeight(16); | ||
| 30 | toggleSound->setAlignment(Qt::AlignBottom); | ||
| 31 | toggleSound->setPixmap(soundIcon(!muted)); | ||
| 32 | if (sound) | ||
| 33 | { | ||
| 34 | connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); | ||
| 35 | connect(AudioManager::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool))); | ||
| 36 | } | ||
| 37 | menuBar()->setCornerWidget(toggleSound); | ||
| 38 | |||
| 39 | /* toggle sound: menu */ | ||
| 40 | QAction *toggleSoundAction = new QAction("&Sound", this); | ||
| 41 | toggleSoundAction->setToolTip("Toggle Sound"); | ||
| 42 | toggleSoundAction->setCheckable(true); | ||
| 43 | toggleSoundAction->setChecked(!muted); | ||
| 44 | toggleSoundAction->setDisabled(!sound); | ||
| 45 | fileMenu->addAction(toggleSoundAction); | ||
| 46 | if (sound) | ||
| 47 | { | ||
| 48 | connect(toggleSoundAction, SIGNAL(triggered()), this, SLOT(toggleSound())); | ||
| 49 | connect(this, SIGNAL(setMuteActionsChecked(bool)), toggleSoundAction, SLOT(setChecked(bool))); | ||
| 50 | } | ||
| 51 | |||
| 52 | /* toggle ambient sound: menu */ | ||
| 53 | m_ambientMuted = muted || m_settings->value("ambientMuted", false).toBool(); | ||
| 54 | QAction *toggleAmbientAction = new QAction("&Ambient Sound", this); | ||
| 55 | toggleAmbientAction->setToolTip("Toggle Ambient Sound"); | ||
| 56 | toggleAmbientAction->setCheckable(true); | ||
| 57 | toggleAmbientAction->setChecked(!m_ambientMuted); | ||
| 58 | toggleAmbientAction->setDisabled(!sound); | ||
| 59 | fileMenu->addAction(toggleAmbientAction); | ||
| 60 | if (sound) | ||
| 61 | { | ||
| 62 | connect(toggleAmbientAction, SIGNAL(triggered(bool)), this, SLOT(enableAmbientSound(bool))); | ||
| 63 | connect(this, SIGNAL(setMuteActionsChecked(bool)), toggleAmbientAction, SLOT(setEnabled(bool))); | ||
| 64 | } | ||
| 65 | |||
| 66 | /* exit entry */ | ||
| 67 | fileMenu->addSeparator(); | ||
| 68 | QAction *quitAction = new QAction("E&xit", this); | ||
| 69 | quitAction->setIcon(QIcon::fromTheme(QLatin1String("application-exit"))); | ||
| 70 | fileMenu->addAction(quitAction); | ||
| 71 | connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); | ||
| 72 | |||
| 73 | |||
| 74 | QAction *aboutAction= menuBar()->addAction("Ab&out"); | ||
| 75 | connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout())); | ||
| 76 | } | ||
| 77 | |||
| 78 | void Client::toggleSound() | ||
| 79 | { | ||
| 80 | if (!AudioManager::self()->isWorking()) | ||
| 81 | return; | ||
| 82 | bool muted = !AudioManager::self()->isMuted(); | ||
| 83 | AudioManager::self()->setMuted(muted); | ||
| 84 | /* mute ambient sound again if explicitly muted */ | ||
| 85 | if (!muted && m_ambientMuted) | ||
| 86 | m_mainWidget->setAmbientMuted(true); | ||
| 87 | } | ||
| 88 | |||
| 89 | void Client::mutedChanged(bool muted) | ||
| 90 | { | ||
| 91 | ClickLabel *tmp = qobject_cast<ClickLabel *>(menuBar()->cornerWidget()); | ||
| 92 | tmp->setPixmap(soundIcon(!muted)); | ||
| 93 | m_settings->setValue("muted", muted); | ||
| 94 | emit setMuteActionsChecked(!muted); | ||
| 95 | } | ||
| 96 | |||
| 97 | void Client::enableAmbientSound(bool enabled) | ||
| 98 | { | ||
| 99 | if (!AudioManager::self()->isWorking()) | ||
| 100 | return; | ||
| 101 | m_ambientMuted = !enabled; | ||
| 102 | m_mainWidget->setAmbientMuted(m_ambientMuted); | ||
| 103 | m_settings->setValue("ambientMuted", m_ambientMuted); | ||
| 104 | } | ||
| 105 | |||
| 106 | QPixmap Client::soundIcon(bool enabled) const | ||
| 107 | { | ||
| 108 | QImage img(enabled ? ":/soundon" : ":/soundoff"); | ||
| 109 | img.setColor(1, menuBar()->palette().color( | ||
| 110 | enabled ? QPalette::Active : QPalette::Disabled, | ||
| 111 | QPalette::ButtonText).rgba()); | ||
| 112 | return QPixmap::fromImage(img); | ||
| 113 | } | ||
| 114 | |||
| 115 | void Client::showAbout() | ||
| 116 | { | ||
| 117 | QDialog *about = new QDialog(this); | ||
| 118 | about->setWindowTitle("About Pacman"); | ||
| 119 | about->setWindowFlags(about->windowFlags() & ~Qt::WindowContextHelpButtonHint); | ||
| 120 | |||
| 121 | QGridLayout *layout = new QGridLayout(about); | ||
| 122 | layout->setSizeConstraint(QLayout::SetFixedSize); | ||
| 123 | |||
| 124 | QString actoricons; | ||
| 125 | for(int i = 0; Color::order[i] != Color::none; ++i) | ||
| 126 | actoricons += QString("<img src=\":/actor%1icon\"/>").arg(i + 1); | ||
| 127 | |||
| 128 | const QString text = QString( | ||
| 129 | "<h3>Multiplayer Pacman %1</h3>" | ||
| 130 | "Authors: H. Demel, B. Mallinger, M. Mausz, M. Racz<br/>" | ||
| 131 | "<br/>" | ||
| 132 | "Gameplay based on <a href=\"http://en.wikipedia.org/wiki/Pac-Man\">Pacman</a>" | ||
| 133 | ", © <a href=\"http://www.namco.co.jp/\">Namco</a> 1980<br/>" | ||
| 134 | "<br/>" | ||
| 135 | "Developed using Qt %2 (%3 bit)<br/>") | ||
| 136 | .arg(actoricons, QLatin1String(QT_VERSION_STR), QString::number(QSysInfo::WordSize)); | ||
| 137 | |||
| 138 | QLabel *label = new QLabel(text); | ||
| 139 | label->setWordWrap(true); | ||
| 140 | label->setOpenExternalLinks(true); | ||
| 141 | label->setTextInteractionFlags(Qt::TextBrowserInteraction); | ||
| 142 | |||
| 143 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); | ||
| 144 | QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close); | ||
| 145 | buttonBox->addButton(closeButton, QDialogButtonBox::ButtonRole(QDialogButtonBox::RejectRole | QDialogButtonBox::AcceptRole)); | ||
| 146 | connect(buttonBox , SIGNAL(rejected()), about, SLOT(reject())); | ||
| 147 | |||
| 148 | layout->addWidget(label, 0, 1, 4, 4); | ||
| 149 | layout->addWidget(buttonBox, 4, 0, 1, 5); | ||
| 150 | about->show(); | ||
| 151 | } | ||
| 152 | |||
| 153 | bool Constants::server = false; | ||
| 154 | |||
| 155 | int main(int argc, char **argv) | ||
| 156 | { | ||
| 157 | /* Verify that the version of the library that we linked against is | ||
| 158 | * compatible with the version of the headers we compiled against. | ||
| 159 | */ | ||
| 160 | GOOGLE_PROTOBUF_VERIFY_VERSION; | ||
| 161 | |||
| 162 | QApplication app(argc, argv, true); | ||
| 163 | app.setOrganizationName("TU Wien FOOP"); | ||
| 164 | app.setApplicationName("Pacman Client"); | ||
| 165 | app.setWindowIcon(QIcon(":/appicon")); | ||
| 166 | |||
| 167 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | ||
| 168 | |||
| 169 | Client client; | ||
| 170 | client.show(); | ||
| 171 | client.setWindowTitle(app.applicationName()); | ||
| 172 | |||
| 173 | int ret = app.exec(); | ||
| 174 | |||
| 175 | /* Delete all global objects allocated by libprotobuf */ | ||
| 176 | google::protobuf::ShutdownProtobufLibrary(); | ||
| 177 | |||
| 178 | return ret; | ||
| 179 | } | ||
