diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc index f8ce1bb8f..1aebae80e 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -124,6 +124,10 @@ resources/userlevels/registered.svg resources/userlevels/moderator.svg resources/userlevels/admin.svg + + resources/userlevels/registered_buddy.svg + resources/userlevels/admin_buddy.svg + resources/userlevels/moderator_buddy.svg resources/news/exclamation_mark.svg resources/news/question_mark.svg diff --git a/cockatrice/resources/buddy_icon.svg b/cockatrice/resources/buddy_icon.svg new file mode 100644 index 000000000..14fcd596c --- /dev/null +++ b/cockatrice/resources/buddy_icon.svg @@ -0,0 +1,115 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/resources/empty_icon.svg b/cockatrice/resources/empty_icon.svg new file mode 100644 index 000000000..ff4027a8f --- /dev/null +++ b/cockatrice/resources/empty_icon.svg @@ -0,0 +1,105 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/resources/userlevels/admin_buddy.svg b/cockatrice/resources/userlevels/admin_buddy.svg new file mode 100644 index 000000000..0d4defb53 --- /dev/null +++ b/cockatrice/resources/userlevels/admin_buddy.svg @@ -0,0 +1,125 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/resources/userlevels/moderator_buddy.svg b/cockatrice/resources/userlevels/moderator_buddy.svg new file mode 100644 index 000000000..677c6e13a --- /dev/null +++ b/cockatrice/resources/userlevels/moderator_buddy.svg @@ -0,0 +1,147 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/resources/userlevels/registered_buddy.svg b/cockatrice/resources/userlevels/registered_buddy.svg new file mode 100644 index 000000000..14fcd596c --- /dev/null +++ b/cockatrice/resources/userlevels/registered_buddy.svg @@ -0,0 +1,115 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index 5d85f58ce..e8bb69069 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -132,7 +132,8 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use if (!sameSender) { if (!sender.isEmpty()) { const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize(); - cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel)); + QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); + cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel, buddyList.contains(sender)).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel)); cursor.insertText(" "); } cursor.setCharFormat(senderFormat); diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 7d29b48bf..33f71285c 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -578,9 +578,13 @@ MessagesSettingsPage::MessagesSettingsPage() ignoreUnregUsersMainChat.setChecked(settingsCache->getIgnoreUnregisteredUsers()); connect(&ignoreUnregUsersMainChat, SIGNAL(stateChanged(int)), settingsCache, SLOT(setIgnoreUnregisteredUsers(int))); + showBuddyIcon.setChecked(settingsCache->getShowBuddyIcon()); + connect(&showBuddyIcon, SIGNAL(stateChanged(int)), settingsCache, SLOT(setShowBuddyIcon(int))); + QGridLayout *chatGrid = new QGridLayout; chatGrid->addWidget(&chatMentionCheckBox, 0, 0); chatGrid->addWidget(&ignoreUnregUsersMainChat, 1, 0); + chatGrid->addWidget(&showBuddyIcon, 2, 0); chatGroupBox = new QGroupBox; chatGroupBox->setLayout(chatGrid); @@ -651,6 +655,7 @@ void MessagesSettingsPage::retranslateUi() aRemove->setText(tr("&Remove")); chatGroupBox->setTitle(tr("Chat settings")); chatMentionCheckBox.setText(tr("Enable chat mentions ('@yourusername' in chat log will be highlighted)")); + showBuddyIcon.setText(tr("Show buddy Icon")); messageShortcuts->setTitle(tr("In-game message macros")); ignoreUnregUsersMainChat.setText(tr("Ignore unregistered users in main chat")); } diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index a3875c5c1..58caac297 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -162,6 +162,7 @@ private: QAction *aRemove; QCheckBox chatMentionCheckBox; QCheckBox ignoreUnregUsersMainChat; + QCheckBox showBuddyIcon; QGroupBox *chatGroupBox; QGroupBox *messageShortcuts; diff --git a/cockatrice/src/pixmapgenerator.cpp b/cockatrice/src/pixmapgenerator.cpp index 8bae48539..45c9c5a6b 100644 --- a/cockatrice/src/pixmapgenerator.cpp +++ b/cockatrice/src/pixmapgenerator.cpp @@ -134,8 +134,9 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr QMap CountryPixmapGenerator::pmCache; -QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags userLevel) +QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags userLevel, bool isBuddy) { + int key = height * 10000 + (int) userLevel; if (pmCache.contains(key)) return pmCache.value(key); @@ -149,6 +150,10 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user levelString = "registered"; else levelString = "normal"; + + if (isBuddy) + levelString.append("_buddy"); + QSvgRenderer svg(QString(":/resources/userlevels/" + levelString + ".svg")); int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height()); QPixmap pixmap(width, height); @@ -160,4 +165,20 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user return pixmap; } +QMap PixmapGenerator::pmCache; +QPixmap PixmapGenerator::generatePixmap(int height, QString resourceName) { + if (pmCache.contains(resourceName)) + return pmCache.value(resourceName); + + QSvgRenderer svg(resourceName); + int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height()); + QPixmap pixmap(width, height); + pixmap.fill(Qt::transparent); + QPainter painter(&pixmap); + svg.render(&painter, QRectF(0, 0, width, height)); + + pmCache.insert(resourceName, pixmap); + return pixmap; +} + QMap UserLevelPixmapGenerator::pmCache; diff --git a/cockatrice/src/pixmapgenerator.h b/cockatrice/src/pixmapgenerator.h index 67a8b2b2e..023675b11 100644 --- a/cockatrice/src/pixmapgenerator.h +++ b/cockatrice/src/pixmapgenerator.h @@ -50,7 +50,15 @@ class UserLevelPixmapGenerator { private: static QMap pmCache; public: - static QPixmap generatePixmap(int height, UserLevelFlags userLevel); + static QPixmap generatePixmap(int height, UserLevelFlags userLevel, bool isBuddy); + static void clear() { pmCache.clear(); } +}; + +class PixmapGenerator { +private: + static QMap pmCache; +public: + static QPixmap generatePixmap(int height, QString resourceName); static void clear() { pmCache.clear(); } }; diff --git a/cockatrice/src/playerlistwidget.cpp b/cockatrice/src/playerlistwidget.cpp index 4edf26edb..46673ce8f 100644 --- a/cockatrice/src/playerlistwidget.cpp +++ b/cockatrice/src/playerlistwidget.cpp @@ -118,7 +118,9 @@ void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon()) : (prop.ready_start() ? readyIcon : notReadyIcon)); if (prop.has_user_info()) { player->setData(3, Qt::UserRole, prop.user_info().user_level()); - player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(prop.user_info().user_level())))); + QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); + QString userName = QString(prop.user_info().name().c_str()); + player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(prop.user_info().user_level()), buddyList.contains(userName)))); player->setText(4, QString::fromStdString(prop.user_info().name())); const QString country = QString::fromStdString(prop.user_info().country()); if (!country.isEmpty()) diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 8bfbeb2dd..57fea9925 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -59,6 +59,8 @@ SettingsCache::SettingsCache() ignoreUnregisteredUsers = settings->value("chat/ignore_unregistered", false).toBool(); + showBuddyIcon = settings->value("chat/showbuddyicon", true).toBool(); + attemptAutoConnect = settings->value("server/auto_connect", 0).toBool(); } @@ -244,6 +246,11 @@ void SettingsCache::setChatMention(int _chatMention) { settings->setValue("chat/mention", chatMention); } +void SettingsCache::setShowBuddyIcon(int _showBuddyIcon) { + showBuddyIcon = _showBuddyIcon; + settings->setValue("chat/showbuddyicon", showBuddyIcon); +} + void SettingsCache::setZoneViewSortByName(int _zoneViewSortByName) { zoneViewSortByName = _zoneViewSortByName; diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index b4d6e9bf1..6ecacdbcb 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -57,6 +57,7 @@ private: int minPlayersForMultiColumnLayout; bool tapAnimation; bool chatMention; + bool showBuddyIcon; bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView, zoneViewShuffle; bool soundEnabled; QString soundPath; @@ -96,6 +97,11 @@ public: int getMinPlayersForMultiColumnLayout() const { return minPlayersForMultiColumnLayout; } bool getTapAnimation() const { return tapAnimation; } bool getChatMention() const { return chatMention; } + /** + Returns if the buddy icon should be displayed in chat. + @return buddyIcon if the buddy icon should be displayed in chat. + */ + bool getShowBuddyIcon() const { return showBuddyIcon; } bool getZoneViewSortByName() const { return zoneViewSortByName; } bool getZoneViewSortByType() const { return zoneViewSortByType; } /** @@ -146,6 +152,7 @@ public slots: void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout); void setTapAnimation(int _tapAnimation); void setChatMention(int _chatMention); + void setShowBuddyIcon(int _showBuddyIcon); void setZoneViewSortByName(int _zoneViewSortByName); void setZoneViewSortByType(int _zoneViewSortByType); void setZoneViewPileView(int _zoneViewPileView); diff --git a/cockatrice/src/userlist.cpp b/cockatrice/src/userlist.cpp index c6174a6e5..49f1b45fd 100644 --- a/cockatrice/src/userlist.cpp +++ b/cockatrice/src/userlist.cpp @@ -180,6 +180,7 @@ void UserListTWI::setUserInfo(const ServerInfo_User &_userInfo) { userInfo = _userInfo; + QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); setData(0, Qt::UserRole, userInfo.user_level()); setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(userInfo.user_level())))); setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(userInfo.country()))));