mirror of
https://git.h3cjp.net/H3cJP/citra.git
synced 2024-11-26 17:53:46 +00:00
Merge pull request #4569 from zhaowenlan1779/multiplayer-fix
multiplayer: minor UI fixes
This commit is contained in:
commit
f110cd95a6
|
@ -42,8 +42,12 @@ public:
|
||||||
cur_nickname = QString::fromStdString(room->GetNickname());
|
cur_nickname = QString::fromStdString(room->GetNickname());
|
||||||
cur_username = QString::fromStdString(room->GetUsername());
|
cur_username = QString::fromStdString(room->GetUsername());
|
||||||
}
|
}
|
||||||
if (message.contains(QString("@").append(cur_nickname)) ||
|
|
||||||
(!cur_username.isEmpty() && message.contains(QString("@").append(cur_username)))) {
|
// Handle pings at the beginning and end of message
|
||||||
|
QString fixed_message = QString(" %1 ").arg(message);
|
||||||
|
if (fixed_message.contains(QString(" @%1 ").arg(cur_nickname)) ||
|
||||||
|
(!cur_username.isEmpty() &&
|
||||||
|
fixed_message.contains(QString(" @%1 ").arg(cur_username)))) {
|
||||||
|
|
||||||
contains_ping = true;
|
contains_ping = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,15 +69,18 @@ public:
|
||||||
name = QString("%1 (%2)").arg(nickname, username);
|
name = QString("%1 (%2)").arg(nickname, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString style;
|
QString style, text_color;
|
||||||
if (ContainsPing()) {
|
if (ContainsPing()) {
|
||||||
// Add a background color to these messages
|
// Add a background color to these messages
|
||||||
style = QString("background-color: %1").arg(ping_color);
|
style = QString("background-color: %1").arg(ping_color);
|
||||||
|
// Add a font color
|
||||||
|
text_color = "color='#000000'";
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString("[%1] <font color='%2'><%3></font> <font style='%4' "
|
return QString("[%1] <font color='%2'><%3></font> <font style='%4' "
|
||||||
"color='#000000'>%5</font>")
|
"%5>%6</font>")
|
||||||
.arg(timestamp, color, name.toHtmlEscaped(), style, message.toHtmlEscaped());
|
.arg(timestamp, color, name.toHtmlEscaped(), style, text_color,
|
||||||
|
message.toHtmlEscaped());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -345,6 +352,8 @@ void ChatRoom::UpdateIconDisplay() {
|
||||||
item->data(PlayerListItem::AvatarUrlRole).toString().toStdString();
|
item->data(PlayerListItem::AvatarUrlRole).toString().toStdString();
|
||||||
if (icon_cache.count(avatar_url)) {
|
if (icon_cache.count(avatar_url)) {
|
||||||
item->setData(icon_cache.at(avatar_url), Qt::DecorationRole);
|
item->setData(icon_cache.at(avatar_url), Qt::DecorationRole);
|
||||||
|
} else {
|
||||||
|
item->setData(QIcon::fromTheme("no_avatar").pixmap(48), Qt::DecorationRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,45 +367,41 @@ void ChatRoom::SetPlayerList(const Network::RoomMember::MemberList& member_list)
|
||||||
QStandardItem* name_item = new PlayerListItem(member.nickname, member.username,
|
QStandardItem* name_item = new PlayerListItem(member.nickname, member.username,
|
||||||
member.avatar_url, member.game_info.name);
|
member.avatar_url, member.game_info.name);
|
||||||
|
|
||||||
if (!icon_cache.count(member.avatar_url)) {
|
|
||||||
// Emplace a default question mark icon as avatar
|
|
||||||
icon_cache.emplace(member.avatar_url, QIcon::fromTheme("no_avatar").pixmap(48));
|
|
||||||
if (!member.avatar_url.empty()) {
|
|
||||||
#ifdef ENABLE_WEB_SERVICE
|
#ifdef ENABLE_WEB_SERVICE
|
||||||
// Start a request to get the member's avatar
|
if (!icon_cache.count(member.avatar_url) && !member.avatar_url.empty()) {
|
||||||
const QUrl url(QString::fromStdString(member.avatar_url));
|
// Start a request to get the member's avatar
|
||||||
QFuture<std::string> future = QtConcurrent::run([url] {
|
const QUrl url(QString::fromStdString(member.avatar_url));
|
||||||
WebService::Client client(
|
QFuture<std::string> future = QtConcurrent::run([url] {
|
||||||
QString("%1://%2").arg(url.scheme(), url.host()).toStdString(), "", "");
|
WebService::Client client(
|
||||||
auto result = client.GetImage(url.path().toStdString(), true);
|
QString("%1://%2").arg(url.scheme(), url.host()).toStdString(), "", "");
|
||||||
if (result.returned_data.empty()) {
|
auto result = client.GetImage(url.path().toStdString(), true);
|
||||||
LOG_ERROR(WebService, "Failed to get avatar");
|
if (result.returned_data.empty()) {
|
||||||
}
|
LOG_ERROR(WebService, "Failed to get avatar");
|
||||||
return result.returned_data;
|
}
|
||||||
});
|
return result.returned_data;
|
||||||
auto* future_watcher = new QFutureWatcher<std::string>(this);
|
});
|
||||||
connect(future_watcher, &QFutureWatcher<std::string>::finished, this,
|
auto* future_watcher = new QFutureWatcher<std::string>(this);
|
||||||
[this, future_watcher, avatar_url = member.avatar_url] {
|
connect(future_watcher, &QFutureWatcher<std::string>::finished, this,
|
||||||
const std::string result = future_watcher->result();
|
[this, future_watcher, avatar_url = member.avatar_url] {
|
||||||
if (result.empty())
|
const std::string result = future_watcher->result();
|
||||||
return;
|
if (result.empty())
|
||||||
QPixmap pixmap;
|
return;
|
||||||
if (!pixmap.loadFromData(reinterpret_cast<const u8*>(result.data()),
|
QPixmap pixmap;
|
||||||
result.size()))
|
if (!pixmap.loadFromData(reinterpret_cast<const u8*>(result.data()),
|
||||||
return;
|
result.size()))
|
||||||
icon_cache[avatar_url] = pixmap.scaled(48, 48, Qt::IgnoreAspectRatio,
|
return;
|
||||||
Qt::SmoothTransformation);
|
icon_cache[avatar_url] =
|
||||||
// Update all the displayed icons with the new icon_cache
|
pixmap.scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
UpdateIconDisplay();
|
// Update all the displayed icons with the new icon_cache
|
||||||
});
|
UpdateIconDisplay();
|
||||||
future_watcher->setFuture(future);
|
});
|
||||||
#endif
|
future_watcher->setFuture(future);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
name_item->setData(icon_cache.at(member.avatar_url), Qt::DecorationRole);
|
#endif
|
||||||
|
|
||||||
player_list->invisibleRootItem()->appendRow(name_item);
|
player_list->invisibleRootItem()->appendRow(name_item);
|
||||||
}
|
}
|
||||||
|
UpdateIconDisplay();
|
||||||
// TODO(B3N30): Restore row selection
|
// TODO(B3N30): Restore row selection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
~ChatRoom();
|
~ChatRoom();
|
||||||
|
|
||||||
void SetModPerms(bool is_mod);
|
void SetModPerms(bool is_mod);
|
||||||
|
void UpdateIconDisplay();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnRoomUpdate(const Network::RoomInformation& info);
|
void OnRoomUpdate(const Network::RoomInformation& info);
|
||||||
|
@ -58,7 +59,6 @@ private:
|
||||||
void AppendChatMessage(const QString&);
|
void AppendChatMessage(const QString&);
|
||||||
bool ValidateMessage(const std::string&);
|
bool ValidateMessage(const std::string&);
|
||||||
void SendModerationRequest(Network::RoomMessageTypes type, const std::string& nickname);
|
void SendModerationRequest(Network::RoomMessageTypes type, const std::string& nickname);
|
||||||
void UpdateIconDisplay();
|
|
||||||
|
|
||||||
bool has_mod_perms = false;
|
bool has_mod_perms = false;
|
||||||
QStandardItemModel* player_list;
|
QStandardItemModel* player_list;
|
||||||
|
|
|
@ -109,3 +109,7 @@ void ClientRoomWindow::UpdateView() {
|
||||||
// TODO(B3N30): can't get RoomMember*, show error and close window
|
// TODO(B3N30): can't get RoomMember*, show error and close window
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientRoomWindow::UpdateIconDisplay() {
|
||||||
|
ui->chat->UpdateIconDisplay();
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
~ClientRoomWindow();
|
~ClientRoomWindow();
|
||||||
|
|
||||||
void RetranslateUi();
|
void RetranslateUi();
|
||||||
|
void UpdateIconDisplay();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnRoomUpdate(const Network::RoomInformation&);
|
void OnRoomUpdate(const Network::RoomInformation&);
|
||||||
|
|
|
@ -194,6 +194,7 @@ void MultiplayerState::UpdateThemedIcons() {
|
||||||
} else {
|
} else {
|
||||||
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
|
||||||
}
|
}
|
||||||
|
client_room->UpdateIconDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BringWidgetToFront(QWidget* widget) {
|
static void BringWidgetToFront(QWidget* widget) {
|
||||||
|
|
Loading…
Reference in a new issue