diff options
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index b140871..c21e81d 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -65,6 +65,7 @@ void MainWidget::createGui() | |||
| 65 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); | 65 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 66 | window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height); | 66 | window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height); |
| 67 | window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint); | 67 | window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint); |
| 68 | window->setFocusPolicy(Qt::NoFocus); | ||
| 68 | 69 | ||
| 69 | layout->addLayout(scoreLayout); | 70 | layout->addLayout(scoreLayout); |
| 70 | layout->addWidget(window); | 71 | layout->addWidget(window); |
| @@ -76,35 +77,27 @@ void MainWidget::createGui() | |||
| 76 | setLayout(layout); | 77 | setLayout(layout); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | void MainWidget::updateScore() | 80 | void MainWidget::updateScore(const ProtoBuf::MapUpdate& packet) |
| 80 | { | 81 | { |
| 81 | QMapIterator<Color::Color, Actor*> i(m_actors); | 82 | QLabel *turnPointsLbl; |
| 82 | while (i.hasNext()) | 83 | QLabel *allPointsLbl; |
| 83 | { | 84 | |
| 84 | i.next(); | 85 | turnPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(0)->itemAtPosition(0,1)->widget()); |
| 85 | if (i.key() > Color::max) | 86 | allPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(0)->itemAtPosition(1,1)->widget()); |
| 86 | { | 87 | turnPointsLbl->setText(QString::number(packet.round_points_red())); |
| 87 | /* player #4 isn't supported in score */ | 88 | allPointsLbl->setText(QString::number(packet.game_points_red())); |
| 88 | Q_ASSERT(false); | 89 | |
| 89 | continue; | 90 | turnPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(1)->itemAtPosition(0,1)->widget()); |
| 90 | } | 91 | allPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(1)->itemAtPosition(1,1)->widget()); |
| 91 | int id = (i.key() >> 1); | 92 | turnPointsLbl->setText(QString::number(packet.round_points_blue())); |
| 92 | QLabel *turnPointsLbl = | 93 | allPointsLbl->setText(QString::number(packet.game_points_blue())); |
| 93 | dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(0,1)->widget()); | 94 | |
| 94 | QLabel *allPointsLbl = | 95 | turnPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(2)->itemAtPosition(0,1)->widget()); |
| 95 | dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(1,1)->widget()); | 96 | allPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(2)->itemAtPosition(1,1)->widget()); |
| 96 | turnPointsLbl->setText(QString::number(id)); | 97 | turnPointsLbl->setText(QString::number(packet.round_points_green())); |
| 97 | allPointsLbl->setText(QString::number(id)); | 98 | allPointsLbl->setText(QString::number(packet.game_points_green())); |
| 98 | } | ||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void MainWidget::updateMap(const Transmission::map_t& map) | ||
| 102 | { | ||
| 103 | SceneHolder::updateMap(map); | ||
| 104 | updateScore(); | ||
| 105 | } | ||
| 106 | |||
| 107 | |||
| 108 | Transmission::field_t MainWidget::translateKey(int key, int def) | 101 | Transmission::field_t MainWidget::translateKey(int key, int def) |
| 109 | { | 102 | { |
| 110 | switch(key) | 103 | switch(key) |
| @@ -166,6 +159,7 @@ void MainWidget::tick() | |||
| 166 | } | 159 | } |
| 167 | } | 160 | } |
| 168 | updateMap(map); | 161 | updateMap(map); |
| 162 | updateScore(packet); | ||
| 169 | } | 163 | } |
| 170 | } | 164 | } |
| 171 | 165 | ||
