From 3070ecdea76531d7720b03c662f5201863efa567 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 30 Jan 2017 04:14:09 +0800 Subject: [PATCH 1/7] [Browser] Allow connecting by double click --- apps/browser/MainWindow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/browser/MainWindow.cpp b/apps/browser/MainWindow.cpp index c6b5a7564..2da8736b4 100644 --- a/apps/browser/MainWindow.cpp +++ b/apps/browser/MainWindow.cpp @@ -39,6 +39,8 @@ MainWindow::MainWindow(QWidget *parent) connect(actionPlay, SIGNAL(triggered(bool)), this, SLOT(play())); connect(tblServerBrowser, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected())); connect(tblFavorites, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected())); + connect(tblFavorites, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play())); + connect(tblServerBrowser, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play())); loadFavorites(); } From 6b42f870a7e8b0f3b6d9a6d653b74c54e93e1ab9 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 30 Jan 2017 04:15:42 +0800 Subject: [PATCH 2/7] [Browser] Use constant instead magic value --- apps/browser/netutils/Utils.cpp | 2 +- apps/browser/netutils/Utils.hpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/browser/netutils/Utils.cpp b/apps/browser/netutils/Utils.cpp index 60e009cca..a876cc9c3 100644 --- a/apps/browser/netutils/Utils.cpp +++ b/apps/browser/netutils/Utils.cpp @@ -20,7 +20,7 @@ unsigned int PingRakNetServer(const char *addr, unsigned short port) RakNet::Packet *packet; bool done = false; int attempts = 0; - RakNet::TimeMS time = 999; + RakNet::TimeMS time = PING_UNREACHABLE; RakNet::SocketDescriptor socketDescriptor {0, ""}; RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance(); diff --git a/apps/browser/netutils/Utils.hpp b/apps/browser/netutils/Utils.hpp index 99e3e49a6..1be5b788b 100644 --- a/apps/browser/netutils/Utils.hpp +++ b/apps/browser/netutils/Utils.hpp @@ -9,6 +9,8 @@ #include +#define PING_UNREACHABLE 999 + unsigned int PingRakNetServer(const char *addr, unsigned short port); struct ServerExtendedData From dba98f9261a0e6a95da6113ea94359c63191b63f Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 30 Jan 2017 04:17:18 +0800 Subject: [PATCH 3/7] [Browser] Not trying to download extended data if server is unreachable --- apps/browser/NetController.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/browser/NetController.cpp b/apps/browser/NetController.cpp index 3182c84ef..e07f74f9f 100644 --- a/apps/browser/NetController.cpp +++ b/apps/browser/NetController.cpp @@ -217,7 +217,10 @@ void NetController::updateInfo() QStringList addr = sd->addr.split(":"); sd->ping = PingRakNetServer(addr[0].toLatin1(), addr[1].toUShort()); - sed = getExtendedData(addr[0].toLatin1(), addr[1].toUShort()); + if(sd->ping != PING_UNREACHABLE) + sed = getExtendedData(addr[0].toLatin1(), addr[1].toUShort()); + else + qDebug() << "Server is unreachable"; } QStringList NetController::players() From f86d17d8a670fbe93433c832a08fa9576e7c2afb Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 30 Jan 2017 07:14:02 +0800 Subject: [PATCH 4/7] [Browser] Add custom proxy model --- apps/browser/CMakeLists.txt | 2 + apps/browser/MySortFilterProxyModel.cpp | 52 +++++++++++++++++++++++++ apps/browser/MySortFilterProxyModel.hpp | 27 +++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 apps/browser/MySortFilterProxyModel.cpp create mode 100644 apps/browser/MySortFilterProxyModel.hpp diff --git a/apps/browser/CMakeLists.txt b/apps/browser/CMakeLists.txt index dc8b2b9ed..95f09bfec 100644 --- a/apps/browser/CMakeLists.txt +++ b/apps/browser/CMakeLists.txt @@ -11,6 +11,7 @@ set(BROWSER ServerModel.cpp NetController.cpp ServerInfoDialog.cpp + MySortFilterProxyModel.cpp netutils/HTTPNetwork.cpp netutils/Utils.cpp ${CMAKE_SOURCE_DIR}/files/tes3mp/browser.rc @@ -20,6 +21,7 @@ set(BROWSER_HEADER_MOC MainWindow.hpp ServerModel.hpp ServerInfoDialog.hpp + MySortFilterProxyModel.hpp ) set(BROWSER_HEADER diff --git a/apps/browser/MySortFilterProxyModel.cpp b/apps/browser/MySortFilterProxyModel.cpp new file mode 100644 index 000000000..3d50174a1 --- /dev/null +++ b/apps/browser/MySortFilterProxyModel.cpp @@ -0,0 +1,52 @@ +// +// Created by koncord on 30.01.17. +// + +#include "MySortFilterProxyModel.hpp" +#include "ServerModel.hpp" + +#include + +bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + + QModelIndex pingIndex = sourceModel()->index(sourceRow, ServerData::PING, sourceParent); + QModelIndex plIndex = sourceModel()->index(sourceRow, ServerData::PLAYERS, sourceParent); + QModelIndex maxPlIndex = sourceModel()->index(sourceRow, ServerData::MAX_PLAYERS, sourceParent); + + int ping = sourceModel()->data(pingIndex).toInt(); + int players = sourceModel()->data(plIndex).toInt(); + int maxPlayers = sourceModel()->data(maxPlIndex).toInt(); + + if(maxPing > 0 && (ping == -1 || ping > maxPing)) + return false; + if(filterEmpty && players == 0) + return false; + if(filterFull && players >= maxPlayers) + return false; + + return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); +} + +MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent) +{ + +} + +void MySortFilterProxyModel::filterEmptyServers(bool state) +{ + filterEmpty = state; + invalidateFilter(); +} + +void MySortFilterProxyModel::filterFullServer(bool state) +{ + filterFull = state; + invalidateFilter(); +} + +void MySortFilterProxyModel::pingLessThan(int maxPing) +{ + this->maxPing = maxPing; + invalidateFilter(); +} diff --git a/apps/browser/MySortFilterProxyModel.hpp b/apps/browser/MySortFilterProxyModel.hpp new file mode 100644 index 000000000..c53de3a90 --- /dev/null +++ b/apps/browser/MySortFilterProxyModel.hpp @@ -0,0 +1,27 @@ +// +// Created by koncord on 30.01.17. +// + +#ifndef OPENMW_MYSORTFILTERPROXYMODEL_HPP +#define OPENMW_MYSORTFILTERPROXYMODEL_HPP + + +#include + +class MySortFilterProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_FINAL; +public: + MySortFilterProxyModel(QObject *parent); + void filterFullServer(bool state); + void filterEmptyServers(bool state); + void pingLessThan(int maxPing); +private: + bool filterEmpty, filterFull; + int maxPing; +}; + + +#endif //OPENMW_MYSORTFILTERPROXYMODEL_HPP From e3a304dd03bfa6dac93060911465785f08e171c6 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 30 Jan 2017 07:16:22 +0800 Subject: [PATCH 5/7] [Browser] Add filters to UI --- files/tes3mp/ui/Main.ui | 118 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/files/tes3mp/ui/Main.ui b/files/tes3mp/ui/Main.ui index e05dbc51e..e09d8fd60 100644 --- a/files/tes3mp/ui/Main.ui +++ b/files/tes3mp/ui/Main.ui @@ -14,7 +14,7 @@ MainWindow - + @@ -68,6 +68,122 @@ + + + + Filters + + + + + + + + + + Max latency: + + + + + + + + All + + + + + <50 + + + + + <100 + + + + + <150 + + + + + <200 + + + + + <250 + + + + + + + + + + + + Game mode + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Not fully + + + + + + + With players + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + From cb0f5524be48129c9c55eaffb59f11d434e0aa71 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 30 Jan 2017 07:17:21 +0800 Subject: [PATCH 6/7] [Browser] Implement filters --- apps/browser/MainWindow.cpp | 32 +++++++++++++++++++++++++++++--- apps/browser/MainWindow.hpp | 8 ++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/apps/browser/MainWindow.cpp b/apps/browser/MainWindow.cpp index 2da8736b4..3d5abe7d4 100644 --- a/apps/browser/MainWindow.cpp +++ b/apps/browser/MainWindow.cpp @@ -23,7 +23,7 @@ MainWindow::MainWindow(QWidget *parent) browser = new ServerModel; favorites = new ServerModel; - proxyModel = new QSortFilterProxyModel; + proxyModel = new MySortFilterProxyModel(this); proxyModel->setSourceModel(browser); tblServerBrowser->setModel(proxyModel); tblFavorites->setModel(proxyModel); @@ -41,7 +41,10 @@ MainWindow::MainWindow(QWidget *parent) connect(tblFavorites, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected())); connect(tblFavorites, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play())); connect(tblServerBrowser, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play())); - + connect(cBoxNotFully, SIGNAL(toggled(bool)), this, SLOT(notFullySwitch(bool))); + connect(cBoxWithPlayers, SIGNAL(toggled(bool)), this, SLOT(havePlayersSwitch(bool))); + connect(comboLatency, SIGNAL(currentIndexChanged(int)), this, SLOT(maxLatencyChanged(int))); + connect(leGamemode, SIGNAL(textChanged(const QString &)), this, SLOT(gamemodeChanged(const QString &))); loadFavorites(); } @@ -186,4 +189,27 @@ void MainWindow::loadFavorites() addServerAndUpdate(server.toString()); file.close(); -} \ No newline at end of file +} + +void MainWindow::notFullySwitch(bool state) +{ + proxyModel->filterFullServer(state); +} + +void MainWindow::havePlayersSwitch(bool state) +{ + proxyModel->filterEmptyServers(state); +} + +void MainWindow::maxLatencyChanged(int index) +{ + int maxLatency = index * 50; + proxyModel->pingLessThan(maxLatency); + +} + +void MainWindow::gamemodeChanged(const QString &text) +{ + proxyModel->setFilterFixedString(text); + proxyModel->setFilterKeyColumn(ServerData::MODNAME); +} diff --git a/apps/browser/MainWindow.hpp b/apps/browser/MainWindow.hpp index 74e882c6d..8f67236f9 100644 --- a/apps/browser/MainWindow.hpp +++ b/apps/browser/MainWindow.hpp @@ -8,7 +8,7 @@ #include "ui_Main.h" #include "ServerModel.hpp" -#include +#include "MySortFilterProxyModel.hpp" #include class MainWindow : public QMainWindow, private Ui::MainWindow @@ -29,10 +29,14 @@ protected slots: void deleteServer(); void play(); void serverSelected(); + void notFullySwitch(bool state); + void havePlayersSwitch(bool state); + void maxLatencyChanged(int index); + void gamemodeChanged(const QString &text); private: Process::ProcessInvoker *mGameInvoker; ServerModel *browser, *favorites; - QSortFilterProxyModel *proxyModel; + MySortFilterProxyModel *proxyModel; void loadFavorites(); }; From c147d13a738ddf3b5d69f5cc2870b35e317e7781 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 30 Jan 2017 07:22:32 +0800 Subject: [PATCH 7/7] [Browser] Move hardcoded title to UI --- apps/browser/main.cpp | 1 - files/tes3mp/ui/Main.ui | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/browser/main.cpp b/apps/browser/main.cpp index 16f9833c4..ad54962c1 100644 --- a/apps/browser/main.cpp +++ b/apps/browser/main.cpp @@ -43,7 +43,6 @@ int main(int argc, char *argv[]) atexit(NetController::Destroy); QApplication app(argc, argv); MainWindow d; - d.setWindowTitle("tes3mp Server Browser"); if (d.refresh()) { diff --git a/files/tes3mp/ui/Main.ui b/files/tes3mp/ui/Main.ui index e09d8fd60..14464f306 100644 --- a/files/tes3mp/ui/Main.ui +++ b/files/tes3mp/ui/Main.ui @@ -11,7 +11,7 @@ - MainWindow + tes3mp Server Browser