From 893c5e694ef04eac97547b6aabec8c7bc759140b Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 10 May 2018 19:10:23 +0200 Subject: [PATCH 1/7] Qt/NetPlayDialog: Use more readable colors --- Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp index 556188b911..4e6d1d7681 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp @@ -449,7 +449,7 @@ void NetPlayDialog::OnMsgChangeGame(const std::string& title) m_game_button->setText(qtitle); m_current_game = title; }); - DisplayMessage(tr("Game changed to \"%1\"").arg(qtitle), "pink"); + DisplayMessage(tr("Game changed to \"%1\"").arg(qtitle), "magenta"); } void NetPlayDialog::GameStatusChanged(bool running) @@ -487,7 +487,7 @@ void NetPlayDialog::OnMsgStopGame() void NetPlayDialog::OnPadBufferChanged(u32 buffer) { QueueOnObject(this, [this, buffer] { m_buffer_size_box->setValue(buffer); }); - DisplayMessage(tr("Buffer size changed to %1").arg(buffer), "gray"); + DisplayMessage(tr("Buffer size changed to %1").arg(buffer), ""); } void NetPlayDialog::OnDesync(u32 frame, const std::string& player) From 7550389c72433acc071ae101bc813c86f9670abb Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 10 May 2018 19:19:09 +0200 Subject: [PATCH 2/7] Qt/NetPlayDialog: Escape HTML in chat --- Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp index 4e6d1d7681..c8e48d14ab 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp @@ -201,8 +201,8 @@ void NetPlayDialog::OnChat() Settings::Instance().GetNetPlayClient()->SendChatMessage(msg); m_chat_type_edit->clear(); - DisplayMessage(QStringLiteral("%1: %2").arg(QString::fromStdString(m_nickname), - QString::fromStdString(msg)), + DisplayMessage(QStringLiteral("%1: %2").arg(QString::fromStdString(m_nickname).toHtmlEscaped(), + QString::fromStdString(msg).toHtmlEscaped()), "blue"); }); } @@ -439,7 +439,7 @@ void NetPlayDialog::DisplayMessage(const QString& msg, const std::string& color, void NetPlayDialog::AppendChat(const std::string& msg) { - DisplayMessage(QString::fromStdString(msg), ""); + DisplayMessage(QString::fromStdString(msg).toHtmlEscaped(), ""); } void NetPlayDialog::OnMsgChangeGame(const std::string& title) From 6ea2b2e7e5f366374ecf2ab5a82a48e5903b7c00 Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 10 May 2018 19:26:42 +0200 Subject: [PATCH 3/7] Qt/NetPlayDialog: Fix duplicate messages --- Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp | 10 ++++++++-- Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp index c8e48d14ab..9302e20b2a 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include @@ -96,7 +96,7 @@ void NetPlayDialog::CreateMainLayout() void NetPlayDialog::CreateChatLayout() { m_chat_box = new QGroupBox(tr("Chat")); - m_chat_edit = new QTextEdit; + m_chat_edit = new QTextBrowser; m_chat_type_edit = new QLineEdit; m_chat_send_button = new QPushButton(tr("Send")); @@ -170,6 +170,9 @@ void NetPlayDialog::ConnectWidgets() // Other connect(m_buffer_size_box, static_cast(&QSpinBox::valueChanged), [this](int value) { + if (value == m_buffer_size) + return; + if (Settings::Instance().GetNetPlayServer() != nullptr) Settings::Instance().GetNetPlayServer()->AdjustPadBufferSize(value); }); @@ -288,6 +291,7 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal) { m_nickname = nickname; m_use_traversal = use_traversal; + m_buffer_size = 0; m_room_box->clear(); m_chat_edit->clear(); @@ -488,6 +492,8 @@ void NetPlayDialog::OnPadBufferChanged(u32 buffer) { QueueOnObject(this, [this, buffer] { m_buffer_size_box->setValue(buffer); }); DisplayMessage(tr("Buffer size changed to %1").arg(buffer), ""); + + m_buffer_size = static_cast(buffer); } void NetPlayDialog::OnDesync(u32 frame, const std::string& player) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h index 593d65a3c5..8326c8be9a 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h @@ -106,4 +106,5 @@ private: GameListModel* m_game_list_model = nullptr; bool m_use_traversal = false; bool m_is_copy_button_retry = false; + int m_buffer_size = 0; }; From 0ee7bddd4f2c4932757c36429b0b2b4cd6972646 Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 10 May 2018 19:38:58 +0200 Subject: [PATCH 4/7] Qt/NetPlayDialog: Add splitter --- .../Core/DolphinQt2/NetPlay/NetPlayDialog.cpp | 19 +++++++++++++++++-- .../Core/DolphinQt2/NetPlay/NetPlayDialog.h | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp index 9302e20b2a..40bc73c403 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -52,6 +53,17 @@ NetPlayDialog::NetPlayDialog(QWidget* parent) CreatePlayersLayout(); CreateMainLayout(); ConnectWidgets(); + + auto& settings = Settings::Instance().GetQSettings(); + + m_splitter->restoreState(settings.value(QStringLiteral("netplaydialog/splitter")).toByteArray()); +} + +NetPlayDialog::~NetPlayDialog() +{ + auto& settings = Settings::Instance().GetQSettings(); + + settings.setValue(QStringLiteral("netplaydialog/splitter"), m_splitter->saveState()); } void NetPlayDialog::CreateMainLayout() @@ -66,6 +78,7 @@ void NetPlayDialog::CreateMainLayout() m_record_input_box = new QCheckBox(tr("Record inputs")); m_buffer_label = new QLabel(tr("Buffer:")); m_quit_button = new QPushButton(tr("Quit")); + m_splitter = new QSplitter(Qt::Horizontal); m_game_button->setDefault(false); m_game_button->setAutoDefault(false); @@ -76,8 +89,10 @@ void NetPlayDialog::CreateMainLayout() m_main_layout->addWidget(m_game_button, 0, 0); m_main_layout->addWidget(m_md5_box, 0, 1); - m_main_layout->addWidget(m_chat_box, 1, 0); - m_main_layout->addWidget(m_players_box, 1, 1); + m_main_layout->addWidget(m_splitter, 1, 0, 1, -1); + + m_splitter->addWidget(m_chat_box); + m_splitter->addWidget(m_players_box); auto* options_widget = new QHBoxLayout; diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h index 8326c8be9a..8ab291ca9f 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h @@ -22,6 +22,7 @@ class QLineEdit; class QListWidget; class QPushButton; class QSpinBox; +class QSplitter; class QTextEdit; class NetPlayDialog : public QDialog, public NetPlayUI @@ -29,6 +30,7 @@ class NetPlayDialog : public QDialog, public NetPlayUI Q_OBJECT public: NetPlayDialog(QWidget* parent); + ~NetPlayDialog(); void show(std::string nickname, bool use_traversal); void reject() override; @@ -97,6 +99,7 @@ private: QCheckBox* m_load_wii_box; QCheckBox* m_record_input_box; QPushButton* m_quit_button; + QSplitter* m_splitter; QGridLayout* m_main_layout; MD5Dialog* m_md5_dialog; From 0141ce9305458315ff8ae663f64b38d698a3d0f8 Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 10 May 2018 19:42:15 +0200 Subject: [PATCH 5/7] Qt/NetPlayDialog: Restore window geometry --- Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp index 40bc73c403..ee8ffb084f 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp @@ -56,6 +56,7 @@ NetPlayDialog::NetPlayDialog(QWidget* parent) auto& settings = Settings::Instance().GetQSettings(); + restoreGeometry(settings.value(QStringLiteral("netplaydialog/geometry")).toByteArray()); m_splitter->restoreState(settings.value(QStringLiteral("netplaydialog/splitter")).toByteArray()); } @@ -63,6 +64,7 @@ NetPlayDialog::~NetPlayDialog() { auto& settings = Settings::Instance().GetQSettings(); + settings.setValue(QStringLiteral("netplaydialog/geometry"), saveGeometry()); settings.setValue(QStringLiteral("netplaydialog/splitter"), m_splitter->saveState()); } From 26bee9394371d3458826858f39ffc20f06f38aac Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 10 May 2018 19:47:54 +0200 Subject: [PATCH 6/7] Qt/NetPlayDialog: Show more friendly interface names --- Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp index ee8ffb084f..57829decaa 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp @@ -322,7 +322,7 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal) m_room_box->addItem(tr("Room ID")); for (const auto& iface : Settings::Instance().GetNetPlayServer()->GetInterfaceSet()) - m_room_box->addItem(QString::fromStdString(iface)); + m_room_box->addItem(iface == "!local!" ? tr("Local") : QString::fromStdString(iface)); } m_start_button->setHidden(!is_hosting); From 09449e2bcaa367901a88fab9b1da2f9e67502b49 Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 10 May 2018 20:29:51 +0200 Subject: [PATCH 7/7] Qt/NetPlayDialog: Use QToolButton instead of a QComboBox --- .../Core/DolphinQt2/NetPlay/NetPlayDialog.cpp | 81 ++++++++----------- .../Core/DolphinQt2/NetPlay/NetPlayDialog.h | 4 +- 2 files changed, 37 insertions(+), 48 deletions(-) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp index 57829decaa..02a5415ef2 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp @@ -4,6 +4,7 @@ #include "DolphinQt2/NetPlay/NetPlayDialog.h" +#include #include #include #include @@ -14,12 +15,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include @@ -72,7 +75,7 @@ void NetPlayDialog::CreateMainLayout() { m_main_layout = new QGridLayout; m_game_button = new QPushButton; - m_md5_box = new QComboBox; + m_md5_button = new QToolButton; m_start_button = new QPushButton(tr("Start")); m_buffer_size_box = new QSpinBox; m_save_sd_box = new QCheckBox(tr("Write save/SD data")); @@ -85,12 +88,35 @@ void NetPlayDialog::CreateMainLayout() m_game_button->setDefault(false); m_game_button->setAutoDefault(false); - for (const QString& text : - {tr("MD5 Check:"), tr("Current game"), tr("Other game"), tr("SD card")}) - m_md5_box->addItem(text); + auto* default_button = new QAction(tr("Calculate MD5 hash"), m_md5_button); + + auto* menu = new QMenu(this); + + auto* other_game_button = new QAction(tr("Other game"), this); + auto* sdcard_button = new QAction(tr("SD Card"), this); + + menu->addAction(other_game_button); + menu->addAction(sdcard_button); + + connect(default_button, &QAction::triggered, + [this] { Settings::Instance().GetNetPlayServer()->ComputeMD5(m_current_game); }); + connect(other_game_button, &QAction::triggered, [this] { + GameListDialog gld(this); + + if (gld.exec() == QDialog::Accepted) + { + Settings::Instance().GetNetPlayServer()->ComputeMD5(gld.GetSelectedUniqueID().toStdString()); + } + }); + connect(sdcard_button, &QAction::triggered, + [] { Settings::Instance().GetNetPlayServer()->ComputeMD5(WII_SDCARD); }); + + m_md5_button->setDefaultAction(default_button); + m_md5_button->setPopupMode(QToolButton::MenuButtonPopup); + m_md5_button->setMenu(menu); m_main_layout->addWidget(m_game_button, 0, 0); - m_main_layout->addWidget(m_md5_box, 0, 1); + m_main_layout->addWidget(m_md5_button, 0, 1); m_main_layout->addWidget(m_splitter, 1, 0, 1, -1); m_splitter->addWidget(m_chat_box); @@ -196,8 +222,6 @@ void NetPlayDialog::ConnectWidgets() connect(m_start_button, &QPushButton::clicked, this, &NetPlayDialog::OnStart); connect(m_quit_button, &QPushButton::clicked, this, &NetPlayDialog::reject); - connect(m_md5_box, static_cast(&QComboBox::currentIndexChanged), this, - &NetPlayDialog::OnMD5Combo); connect(m_game_button, &QPushButton::clicked, [this] { GameListDialog gld(this); @@ -261,40 +285,6 @@ void NetPlayDialog::OnStart() Settings::Instance().GetNetPlayServer()->StartGame(); } -void NetPlayDialog::OnMD5Combo(int index) -{ - std::string identifier; - - switch (index) - { - case 0: - return; - case 1: // Current game - identifier = m_current_game; - break; - case 2: // Other game - { - GameListDialog gld(this); - - if (gld.exec() == QDialog::Accepted) - { - identifier = gld.GetSelectedUniqueID().toStdString(); - break; - } - else - { - m_md5_box->setCurrentIndex(0); - return; - } - } - case 3: // SD Card - identifier = WII_SDCARD; - break; - } - - Settings::Instance().GetNetPlayServer()->ComputeMD5(identifier); -} - void NetPlayDialog::reject() { if (QMessageBox::question(this, tr("Confirmation"), @@ -332,7 +322,7 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal) m_buffer_label->setHidden(!is_hosting); m_kick_button->setHidden(!is_hosting); m_assign_ports_button->setHidden(!is_hosting); - m_md5_box->setHidden(!is_hosting); + m_md5_button->setHidden(!is_hosting); m_room_box->setHidden(!is_hosting); m_hostcode_label->setHidden(!is_hosting); m_hostcode_action_button->setHidden(!is_hosting); @@ -568,8 +558,7 @@ std::string NetPlayDialog::FindGame(const std::string& game) void NetPlayDialog::ShowMD5Dialog(const std::string& file_identifier) { QueueOnObject(this, [this, file_identifier] { - m_md5_box->setEnabled(false); - m_md5_box->setCurrentIndex(0); + m_md5_button->setEnabled(false); if (m_md5_dialog->isVisible()) m_md5_dialog->close(); @@ -590,7 +579,7 @@ void NetPlayDialog::SetMD5Result(int pid, const std::string& result) { QueueOnObject(this, [this, pid, result] { m_md5_dialog->SetResult(pid, result); - m_md5_box->setEnabled(true); + m_md5_button->setEnabled(true); }); } @@ -598,6 +587,6 @@ void NetPlayDialog::AbortMD5() { QueueOnObject(this, [this] { m_md5_dialog->close(); - m_md5_box->setEnabled(true); + m_md5_button->setEnabled(true); }); } diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h index 8ab291ca9f..3abba20987 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h @@ -24,6 +24,7 @@ class QPushButton; class QSpinBox; class QSplitter; class QTextEdit; +class QToolButton; class NetPlayDialog : public QDialog, public NetPlayUI { @@ -66,7 +67,6 @@ private: void ConnectWidgets(); void OnChat(); void OnStart(); - void OnMD5Combo(int index); void DisplayMessage(const QString& msg, const std::string& color, int duration = OSD::Duration::NORMAL); void UpdateGUI(); @@ -91,7 +91,7 @@ private: // Other QPushButton* m_game_button; - QComboBox* m_md5_box; + QToolButton* m_md5_button; QPushButton* m_start_button; QLabel* m_buffer_label; QSpinBox* m_buffer_size_box;