2018-01-19 13:42:21 +00:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <future>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QList>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QMetaType>
|
|
|
|
#include <QTime>
|
|
|
|
#include <QtConcurrent/QtConcurrentRun>
|
|
|
|
#include "citra_qt/game_list_p.h"
|
|
|
|
#include "citra_qt/multiplayer/client_room.h"
|
|
|
|
#include "citra_qt/multiplayer/message.h"
|
2018-11-24 08:22:14 +00:00
|
|
|
#include "citra_qt/multiplayer/moderation_dialog.h"
|
2018-04-20 06:39:01 +00:00
|
|
|
#include "citra_qt/multiplayer/state.h"
|
2018-01-19 13:42:21 +00:00
|
|
|
#include "common/logging/log.h"
|
2020-08-20 19:54:01 +00:00
|
|
|
#include "network/announce_multiplayer_session.h"
|
2018-04-18 16:29:03 +00:00
|
|
|
#include "ui_client_room.h"
|
2018-01-19 13:42:21 +00:00
|
|
|
|
|
|
|
ClientRoomWindow::ClientRoomWindow(QWidget* parent)
|
|
|
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
|
2018-04-18 05:06:02 +00:00
|
|
|
ui(std::make_unique<Ui::ClientRoom>()) {
|
2018-01-19 13:42:21 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
// setup the callbacks for network updates
|
|
|
|
if (auto member = Network::GetRoomMember().lock()) {
|
|
|
|
member->BindOnRoomInformationChanged(
|
|
|
|
[this](const Network::RoomInformation& info) { emit RoomInformationChanged(info); });
|
|
|
|
member->BindOnStateChanged(
|
|
|
|
[this](const Network::RoomMember::State& state) { emit StateChanged(state); });
|
|
|
|
|
|
|
|
connect(this, &ClientRoomWindow::RoomInformationChanged, this,
|
|
|
|
&ClientRoomWindow::OnRoomUpdate);
|
|
|
|
connect(this, &ClientRoomWindow::StateChanged, this, &::ClientRoomWindow::OnStateChange);
|
2018-11-07 14:41:56 +00:00
|
|
|
// Update the state
|
|
|
|
OnStateChange(member->GetState());
|
2018-01-19 13:42:21 +00:00
|
|
|
} else {
|
|
|
|
// TODO (jroweboy) network was not initialized?
|
|
|
|
}
|
|
|
|
|
2019-07-22 21:28:10 +00:00
|
|
|
connect(ui->disconnect, &QPushButton::clicked, this, &ClientRoomWindow::Disconnect);
|
2018-01-19 13:42:21 +00:00
|
|
|
ui->disconnect->setDefault(false);
|
|
|
|
ui->disconnect->setAutoDefault(false);
|
2018-11-24 08:22:14 +00:00
|
|
|
connect(ui->moderation, &QPushButton::clicked, [this] {
|
|
|
|
ModerationDialog dialog(this);
|
|
|
|
dialog.exec();
|
|
|
|
});
|
|
|
|
ui->moderation->setDefault(false);
|
|
|
|
ui->moderation->setAutoDefault(false);
|
2018-12-01 01:28:55 +00:00
|
|
|
connect(ui->chat, &ChatRoom::UserPinged, this, &ClientRoomWindow::ShowNotification);
|
2018-01-19 13:42:21 +00:00
|
|
|
UpdateView();
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:29:03 +00:00
|
|
|
ClientRoomWindow::~ClientRoomWindow() = default;
|
|
|
|
|
2018-11-24 08:22:14 +00:00
|
|
|
void ClientRoomWindow::SetModPerms(bool is_mod) {
|
2018-11-24 08:26:12 +00:00
|
|
|
ui->chat->SetModPerms(is_mod);
|
2018-11-24 08:22:14 +00:00
|
|
|
ui->moderation->setVisible(is_mod);
|
|
|
|
ui->moderation->setDefault(false);
|
|
|
|
ui->moderation->setAutoDefault(false);
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:08:33 +00:00
|
|
|
void ClientRoomWindow::RetranslateUi() {
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
ui->chat->RetranslateUi();
|
|
|
|
}
|
|
|
|
|
2018-01-19 13:42:21 +00:00
|
|
|
void ClientRoomWindow::OnRoomUpdate(const Network::RoomInformation& info) {
|
|
|
|
UpdateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) {
|
2018-12-15 09:13:46 +00:00
|
|
|
if (state == Network::RoomMember::State::Joined ||
|
|
|
|
state == Network::RoomMember::State::Moderator) {
|
|
|
|
|
2018-01-19 13:42:21 +00:00
|
|
|
ui->chat->Clear();
|
|
|
|
ui->chat->AppendStatusMessage(tr("Connected"));
|
2018-12-15 09:13:46 +00:00
|
|
|
SetModPerms(state == Network::RoomMember::State::Moderator);
|
2018-01-19 13:42:21 +00:00
|
|
|
}
|
|
|
|
UpdateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientRoomWindow::Disconnect() {
|
2018-04-20 06:39:01 +00:00
|
|
|
auto parent = static_cast<MultiplayerState*>(parentWidget());
|
2018-04-25 16:31:51 +00:00
|
|
|
if (parent->OnCloseRoom()) {
|
2018-01-19 13:42:21 +00:00
|
|
|
ui->chat->AppendStatusMessage(tr("Disconnected"));
|
2018-04-05 18:07:11 +00:00
|
|
|
close();
|
2018-01-19 13:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientRoomWindow::UpdateView() {
|
|
|
|
if (auto member = Network::GetRoomMember().lock()) {
|
|
|
|
if (member->IsConnected()) {
|
|
|
|
ui->chat->Enable();
|
|
|
|
ui->disconnect->setEnabled(true);
|
|
|
|
auto memberlist = member->GetMemberInformation();
|
|
|
|
ui->chat->SetPlayerList(memberlist);
|
|
|
|
const auto information = member->GetRoomInformation();
|
|
|
|
setWindowTitle(QString(tr("%1 (%2/%3 members) - connected"))
|
|
|
|
.arg(QString::fromStdString(information.name))
|
|
|
|
.arg(memberlist.size())
|
|
|
|
.arg(information.member_slots));
|
2018-04-30 07:40:51 +00:00
|
|
|
ui->description->setText(QString::fromStdString(information.description));
|
2018-01-19 13:42:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO(B3N30): can't get RoomMember*, show error and close window
|
|
|
|
close();
|
|
|
|
}
|
2019-01-16 14:01:21 +00:00
|
|
|
|
|
|
|
void ClientRoomWindow::UpdateIconDisplay() {
|
|
|
|
ui->chat->UpdateIconDisplay();
|
|
|
|
}
|