diff options
| author | totycro <totycro@unknown-horizons.org> | 2011-04-09 15:11:35 +0200 |
|---|---|---|
| committer | totycro <totycro@unknown-horizons.org> | 2011-04-09 15:11:35 +0200 |
| commit | 13199a5212e210206b8d6b938f7c1683760cf226 (patch) | |
| tree | cba982d54d62081589d31f188796b65fc51b703d | |
| parent | 979c3b4528da1608404d6e163211280fee5da9c5 (diff) | |
| parent | 827a9b10539af4a8c4cff70fa345254668d294c7 (diff) | |
| download | foop-13199a5212e210206b8d6b938f7c1683760cf226.tar.gz foop-13199a5212e210206b8d6b938f7c1683760cf226.tar.bz2 foop-13199a5212e210206b8d6b938f7c1683760cf226.zip | |
Merge branch 'master' of git.manuel.mausz.at:/foop
Conflicts:
pacman-c++/sceneholder.cpp
pacman-c++/util.h
| -rw-r--r-- | pacman-c++/actor.cpp | 6 | ||||
| -rw-r--r-- | pacman-c++/audioplayer.cpp | 12 | ||||
| -rw-r--r-- | pacman-c++/audioplayer.h | 5 | ||||
| -rw-r--r-- | pacman-c++/clicklabel.cpp | 12 | ||||
| -rw-r--r-- | pacman-c++/clicklabel.h | 21 | ||||
| -rw-r--r-- | pacman-c++/client.cpp | 29 | ||||
| -rw-r--r-- | pacman-c++/client.h | 3 | ||||
| -rw-r--r-- | pacman-c++/pacman.pro | 2 | ||||
| -rw-r--r-- | pacman-c++/pacman.qrc | 2 | ||||
| -rw-r--r-- | pacman-c++/pics/soundoff.xpm | 15 | ||||
| -rw-r--r-- | pacman-c++/pics/soundon.xpm | 15 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.h | 2 |
12 files changed, 117 insertions, 7 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 445d63d..011fbeb 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -81,7 +81,7 @@ QSequentialAnimationGroup *Actor::setupEatingAnimation(Actor::Movement direction | |||
| 81 | fadeout->setEndValue(false); | 81 | fadeout->setEndValue(false); |
| 82 | 82 | ||
| 83 | QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving); | 83 | QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving); |
| 84 | move->setDuration(Constants::tick); | 84 | move->setDuration(Constants::tick - 50); |
| 85 | move->setEndValue(QPoint(0, 0)); | 85 | move->setEndValue(QPoint(0, 0)); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| @@ -106,8 +106,8 @@ bool Actor::isLocal() | |||
| 106 | void Actor::move(Actor::Movement direction) | 106 | void Actor::move(Actor::Movement direction) |
| 107 | { | 107 | { |
| 108 | //TODO: remove? | 108 | //TODO: remove? |
| 109 | if (isMoving()) | 109 | //if (isMoving()) |
| 110 | return; | 110 | // return; |
| 111 | 111 | ||
| 112 | /* stop current animation */ | 112 | /* stop current animation */ |
| 113 | if (direction != m_direction) | 113 | if (direction != m_direction) |
diff --git a/pacman-c++/audioplayer.cpp b/pacman-c++/audioplayer.cpp index 424d3cf..5507bb3 100644 --- a/pacman-c++/audioplayer.cpp +++ b/pacman-c++/audioplayer.cpp | |||
| @@ -52,6 +52,11 @@ AudioPlayer *AudioPlayer::self() | |||
| 52 | return m_instance; | 52 | return m_instance; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | bool AudioPlayer::isWorking() const | ||
| 56 | { | ||
| 57 | return m_working; | ||
| 58 | } | ||
| 59 | |||
| 55 | void AudioPlayer::stop() | 60 | void AudioPlayer::stop() |
| 56 | { | 61 | { |
| 57 | m_player->stop(); | 62 | m_player->stop(); |
| @@ -62,6 +67,11 @@ void AudioPlayer::setMuted(bool mute) | |||
| 62 | m_output->setMuted(mute); | 67 | m_output->setMuted(mute); |
| 63 | } | 68 | } |
| 64 | 69 | ||
| 70 | bool AudioPlayer::isMuted() const | ||
| 71 | { | ||
| 72 | return m_output->isMuted(); | ||
| 73 | } | ||
| 74 | |||
| 65 | void AudioPlayer::play(AudioPlayer::Sound sound) | 75 | void AudioPlayer::play(AudioPlayer::Sound sound) |
| 66 | { | 76 | { |
| 67 | if (!m_working) | 77 | if (!m_working) |
| @@ -86,7 +96,7 @@ void AudioPlayer::enqueue(AudioPlayer::Sound sound) | |||
| 86 | m_player->enqueue(Phonon::MediaSource(m_sounds[sound])); | 96 | m_player->enqueue(Phonon::MediaSource(m_sounds[sound])); |
| 87 | } | 97 | } |
| 88 | 98 | ||
| 89 | void AudioPlayer::clearQueue() | 99 | void AudioPlayer::clearQueue() const |
| 90 | { | 100 | { |
| 91 | if (!m_working) | 101 | if (!m_working) |
| 92 | return; | 102 | return; |
diff --git a/pacman-c++/audioplayer.h b/pacman-c++/audioplayer.h index dd0c25a..567ccb1 100644 --- a/pacman-c++/audioplayer.h +++ b/pacman-c++/audioplayer.h | |||
| @@ -28,13 +28,14 @@ public: | |||
| 28 | public: | 28 | public: |
| 29 | AudioPlayer(); | 29 | AudioPlayer(); |
| 30 | static AudioPlayer *self(); | 30 | static AudioPlayer *self(); |
| 31 | bool isWorking(); | 31 | bool isWorking() const; |
| 32 | void stop(); | 32 | void stop(); |
| 33 | void setMuted(bool mute = true); | 33 | void setMuted(bool mute = true); |
| 34 | bool isMuted() const; | ||
| 34 | void play(Sound sound); | 35 | void play(Sound sound); |
| 35 | void clear(); | 36 | void clear(); |
| 36 | void enqueue(Sound sound); | 37 | void enqueue(Sound sound); |
| 37 | void clearQueue(); | 38 | void clearQueue() const; |
| 38 | Phonon::State state(); | 39 | Phonon::State state(); |
| 39 | 40 | ||
| 40 | signals: | 41 | signals: |
diff --git a/pacman-c++/clicklabel.cpp b/pacman-c++/clicklabel.cpp new file mode 100644 index 0000000..87b06b8 --- /dev/null +++ b/pacman-c++/clicklabel.cpp | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #include "clicklabel.h" | ||
| 2 | |||
| 3 | ClickLabel::ClickLabel(const QString &text, QWidget *parent, Qt::WindowFlags f) | ||
| 4 | : QLabel(text, parent, f) | ||
| 5 | { | ||
| 6 | } | ||
| 7 | |||
| 8 | void ClickLabel::mouseReleaseEvent(QMouseEvent * /* event */) | ||
| 9 | { | ||
| 10 | emit clicked(); | ||
| 11 | } | ||
| 12 | |||
diff --git a/pacman-c++/clicklabel.h b/pacman-c++/clicklabel.h new file mode 100644 index 0000000..494b1ee --- /dev/null +++ b/pacman-c++/clicklabel.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #ifndef CLICKLABEL_H | ||
| 2 | #define CLICKLABEL_H | ||
| 3 | |||
| 4 | #include <QLabel> | ||
| 5 | |||
| 6 | class ClickLabel | ||
| 7 | : public QLabel | ||
| 8 | { | ||
| 9 | Q_OBJECT | ||
| 10 | |||
| 11 | public: | ||
| 12 | ClickLabel(const QString &text, QWidget *parent = 0, Qt::WindowFlags f = 0); | ||
| 13 | |||
| 14 | signals: | ||
| 15 | void clicked(); | ||
| 16 | |||
| 17 | protected: | ||
| 18 | void mouseReleaseEvent(QMouseEvent *event); | ||
| 19 | }; | ||
| 20 | |||
| 21 | #endif // CLICKLABEL_H | ||
diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp index e4978f7..7827591 100644 --- a/pacman-c++/client.cpp +++ b/pacman-c++/client.cpp | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #include "client.h" | 1 | #include "client.h" |
| 2 | #include "audioplayer.h" | 2 | #include "audioplayer.h" |
| 3 | #include "clicklabel.h" | ||
| 3 | 4 | ||
| 4 | Client::Client() | 5 | Client::Client() |
| 5 | { | 6 | { |
| @@ -9,10 +10,38 @@ Client::Client() | |||
| 9 | QMenu *fileMenu = menuBar()->addMenu("File"); | 10 | QMenu *fileMenu = menuBar()->addMenu("File"); |
| 10 | fileMenu->addAction(quitAction); | 11 | fileMenu->addAction(quitAction); |
| 11 | 12 | ||
| 13 | ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this); | ||
| 14 | toggleSound->setFixedWidth(20); | ||
| 15 | toggleSound->setFixedHeight(16); | ||
| 16 | toggleSound->setAlignment(Qt::AlignBottom); | ||
| 17 | bool sound = AudioPlayer::self()->isWorking(); | ||
| 18 | QImage img(sound ? ":/soundon" : ":/soundoff"); | ||
| 19 | img.setColor(1, menuBar()->palette().color(sound ? QPalette::Active : QPalette::Disabled, | ||
| 20 | QPalette::ButtonText).rgba()); | ||
| 21 | toggleSound->setPixmap(QPixmap::fromImage(img)); | ||
| 22 | if (sound) | ||
| 23 | connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); | ||
| 24 | |||
| 25 | menuBar()->setCornerWidget(toggleSound); | ||
| 26 | |||
| 12 | m_mainWidget = new MainWidget(); | 27 | m_mainWidget = new MainWidget(); |
| 13 | setCentralWidget(m_mainWidget); | 28 | setCentralWidget(m_mainWidget); |
| 14 | } | 29 | } |
| 15 | 30 | ||
| 31 | void Client::toggleSound() const | ||
| 32 | { | ||
| 33 | if (!AudioPlayer::self()->isWorking()) | ||
| 34 | return; | ||
| 35 | |||
| 36 | bool muted = AudioPlayer::self()->isMuted(); | ||
| 37 | QImage img(muted ? ":/soundon" : ":/soundoff"); | ||
| 38 | img.setColor(1, menuBar()->palette().color(muted ? QPalette::Active : QPalette::Disabled, | ||
| 39 | QPalette::ButtonText).rgba()); | ||
| 40 | ClickLabel *tmp = qobject_cast<ClickLabel *>(menuBar()->cornerWidget()); | ||
| 41 | tmp->setPixmap(QPixmap::fromImage(img)); | ||
| 42 | AudioPlayer::self()->setMuted(!muted); | ||
| 43 | } | ||
| 44 | |||
| 16 | int main(int argc, char ** argv) | 45 | int main(int argc, char ** argv) |
| 17 | { | 46 | { |
| 18 | QApplication app(argc, argv); | 47 | QApplication app(argc, argv); |
diff --git a/pacman-c++/client.h b/pacman-c++/client.h index 476b972..56f3602 100644 --- a/pacman-c++/client.h +++ b/pacman-c++/client.h | |||
| @@ -11,6 +11,9 @@ class Client | |||
| 11 | public: | 11 | public: |
| 12 | Client(); | 12 | Client(); |
| 13 | 13 | ||
| 14 | public slots: | ||
| 15 | void toggleSound() const; | ||
| 16 | |||
| 14 | private: | 17 | private: |
| 15 | MainWidget *m_mainWidget; | 18 | MainWidget *m_mainWidget; |
| 16 | }; | 19 | }; |
diff --git a/pacman-c++/pacman.pro b/pacman-c++/pacman.pro index a1dddf6..dd08568 100644 --- a/pacman-c++/pacman.pro +++ b/pacman-c++/pacman.pro | |||
| @@ -8,6 +8,7 @@ SOURCES += pixmapitem.cpp \ | |||
| 8 | mainwidget.cpp \ | 8 | mainwidget.cpp \ |
| 9 | point.cpp \ | 9 | point.cpp \ |
| 10 | audioplayer.cpp \ | 10 | audioplayer.cpp \ |
| 11 | clicklabel.cpp \ | ||
| 11 | sceneholder.cpp \ | 12 | sceneholder.cpp \ |
| 12 | util.cpp | 13 | util.cpp |
| 13 | HEADERS += pixmapitem.h \ | 14 | HEADERS += pixmapitem.h \ |
| @@ -20,6 +21,7 @@ HEADERS += pixmapitem.h \ | |||
| 20 | constants.h \ | 21 | constants.h \ |
| 21 | point.h \ | 22 | point.h \ |
| 22 | audioplayer.h \ | 23 | audioplayer.h \ |
| 24 | clicklabel.h \ | ||
| 23 | sceneholder.h \ | 25 | sceneholder.h \ |
| 24 | util.h | 26 | util.h |
| 25 | RESOURCES += pacman.qrc | 27 | RESOURCES += pacman.qrc |
diff --git a/pacman-c++/pacman.qrc b/pacman-c++/pacman.qrc index b116a30..4fb542e 100644 --- a/pacman-c++/pacman.qrc +++ b/pacman-c++/pacman.qrc | |||
| @@ -17,6 +17,8 @@ | |||
| 17 | <file alias="actor2icon">pics/actor2icon.png</file> | 17 | <file alias="actor2icon">pics/actor2icon.png</file> |
| 18 | <file alias="actor3icon">pics/actor3icon.png</file> | 18 | <file alias="actor3icon">pics/actor3icon.png</file> |
| 19 | <file alias="actor4icon">pics/actor4icon.png</file> | 19 | <file alias="actor4icon">pics/actor4icon.png</file> |
| 20 | <file alias="soundon">pics/soundon.xpm</file> | ||
| 21 | <file alias="soundoff">pics/soundoff.xpm</file> | ||
| 20 | </qresource> | 22 | </qresource> |
| 21 | <qresource prefix="/sound"> | 23 | <qresource prefix="/sound"> |
| 22 | <file alias="sound1">sound/intro.ogg</file> | 24 | <file alias="sound1">sound/intro.ogg</file> |
diff --git a/pacman-c++/pics/soundoff.xpm b/pacman-c++/pics/soundoff.xpm new file mode 100644 index 0000000..ba33f5f --- /dev/null +++ b/pacman-c++/pics/soundoff.xpm | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | /* XPM */ | ||
| 2 | static char * soundoff_xpm[] = { | ||
| 3 | "12 10 2 1", | ||
| 4 | " c None", | ||
| 5 | ". c #000000", | ||
| 6 | " ", | ||
| 7 | " . ", | ||
| 8 | " .. . .", | ||
| 9 | ".... . . ", | ||
| 10 | ".... .. ", | ||
| 11 | ".... .. ", | ||
| 12 | ".... . . ", | ||
| 13 | " .. . .", | ||
| 14 | " . ", | ||
| 15 | " "}; | ||
diff --git a/pacman-c++/pics/soundon.xpm b/pacman-c++/pics/soundon.xpm new file mode 100644 index 0000000..e6ca41e --- /dev/null +++ b/pacman-c++/pics/soundon.xpm | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | /* XPM */ | ||
| 2 | static char * soundoff_xpm[] = { | ||
| 3 | "12 10 2 1", | ||
| 4 | " c None", | ||
| 5 | ". c #000000", | ||
| 6 | " . ", | ||
| 7 | " . . ", | ||
| 8 | " .. . . ", | ||
| 9 | ".... . . ", | ||
| 10 | ".... . . ", | ||
| 11 | ".... . . ", | ||
| 12 | ".... . . ", | ||
| 13 | " .. . . ", | ||
| 14 | " . . ", | ||
| 15 | " . "}; | ||
diff --git a/pacman-c++/sceneholder.h b/pacman-c++/sceneholder.h index cf6941a..f188956 100644 --- a/pacman-c++/sceneholder.h +++ b/pacman-c++/sceneholder.h | |||
| @@ -35,4 +35,4 @@ protected: | |||
| 35 | 35 | ||
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | #endif // SCENEHOLDER_H \ No newline at end of file | 38 | #endif // SCENEHOLDER_H |
