diff --git a/src/frontend/qt_sdl/LAN.cpp b/src/frontend/qt_sdl/LAN.cpp index 49646952..d5e8ef9a 100644 --- a/src/frontend/qt_sdl/LAN.cpp +++ b/src/frontend/qt_sdl/LAN.cpp @@ -20,15 +20,154 @@ #include #include -// +#include + +#include #include "LAN.h" #include "Config.h" -//#include "main.h" -// +#include "main.h" + +#include "ui_LANStartHostDialog.h" +#include "ui_LANStartClientDialog.h" +#include "ui_LANDialog.h" -//extern EmuThread* emuThread; +extern EmuThread* emuThread; +LANDialog* lanDlg; + + +LANStartHostDialog::LANStartHostDialog(QWidget* parent) : QDialog(parent), ui(new Ui::LANStartHostDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + //ui->txtPort->setText("8064"); +} + +LANStartHostDialog::~LANStartHostDialog() +{ + delete ui; +} + +void LANStartHostDialog::done(int r) +{ + if (r == QDialog::Accepted) + { + std::string player = ui->txtPlayerName->text().toStdString(); + //int port = ui->txtPort->text().toInt(); + + // TODO validate input!! + + lanDlg = LANDialog::openDlg(parentWidget()); + + //Netplay::StartHost(player.c_str(), port); + } + + QDialog::done(r); +} + + +LANStartClientDialog::LANStartClientDialog(QWidget* parent) : QDialog(parent), ui(new Ui::LANStartClientDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + //ui->txtPort->setText("8064"); +} + +LANStartClientDialog::~LANStartClientDialog() +{ + delete ui; +} + +void LANStartClientDialog::done(int r) +{ + if (r == QDialog::Accepted) + { + std::string player = ui->txtPlayerName->text().toStdString(); + std::string host = ui->txtIPAddress->text().toStdString(); + //int port = ui->txtPort->text().toInt(); + + // TODO validate input!! + + lanDlg = LANDialog::openDlg(parentWidget()); + + //Netplay::StartClient(player.c_str(), host.c_str(), port); + } + + QDialog::done(r); +} + + +LANDialog::LANDialog(QWidget* parent) : QDialog(parent), ui(new Ui::LANDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + QStandardItemModel* model = new QStandardItemModel(); + ui->tvPlayerList->setModel(model); + + connect(this, &LANDialog::sgUpdatePlayerList, this, &LANDialog::doUpdatePlayerList); +} + +LANDialog::~LANDialog() +{ + delete ui; +} + +void LANDialog::done(int r) +{ + // ??? + + QDialog::done(r); +} + +void LANDialog::updatePlayerList(LAN::Player* players, int num) +{ + emit sgUpdatePlayerList(players, num); +} + +void LANDialog::doUpdatePlayerList(LAN::Player* players, int num) +{ + QStandardItemModel* model = (QStandardItemModel*)ui->tvPlayerList->model(); + + model->clear(); + model->setRowCount(num); + + // TODO: remove IP column in final product + + const QStringList header = {"#", "Player", "Status", "Ping", "IP"}; + model->setHorizontalHeaderLabels(header); + + for (int i = 0; i < num; i++) + { + LAN::Player* player = &players[i]; + + QString id = QString("%0").arg(player->ID+1); + model->setItem(i, 0, new QStandardItem(id)); + + QString name = player->Name; + model->setItem(i, 1, new QStandardItem(name)); + + QString status; + switch (player->Status) + { + case 1: status = ""; break; + case 2: status = "Host"; break; + default: status = "ded"; break; + } + model->setItem(i, 2, new QStandardItem(status)); + + // TODO: ping + model->setItem(i, 3, new QStandardItem("x")); + + char ip[32]; + u32 addr = player->Address; + sprintf(ip, "%d.%d.%d.%d", addr&0xFF, (addr>>8)&0xFF, (addr>>16)&0xFF, addr>>24); + model->setItem(i, 4, new QStandardItem(ip)); + } +} namespace LAN diff --git a/src/frontend/qt_sdl/LAN.h b/src/frontend/qt_sdl/LAN.h index bc19e662..41f4df1b 100644 --- a/src/frontend/qt_sdl/LAN.h +++ b/src/frontend/qt_sdl/LAN.h @@ -20,9 +20,101 @@ #define LAN_H #include +#include #include "types.h" +namespace Ui +{ +class LANStartHostDialog; +class LANStartClientDialog; +class LANDialog; +} + +namespace LAN +{ +struct Player +{ + int ID; + char Name[32]; + int Status; // 0=no player 1=normal 2=host 3=connecting + u32 Address; +}; +} + +class LANStartHostDialog : public QDialog +{ + Q_OBJECT + +public: + explicit LANStartHostDialog(QWidget* parent); + ~LANStartHostDialog(); + + static LANStartHostDialog* openDlg(QWidget* parent) + { + LANStartHostDialog* dlg = new LANStartHostDialog(parent); + dlg->open(); + return dlg; + } + +private slots: + void done(int r); + +private: + Ui::LANStartHostDialog* ui; +}; + +class LANStartClientDialog : public QDialog +{ + Q_OBJECT + +public: + explicit LANStartClientDialog(QWidget* parent); + ~LANStartClientDialog(); + + static LANStartClientDialog* openDlg(QWidget* parent) + { + LANStartClientDialog* dlg = new LANStartClientDialog(parent); + dlg->open(); + return dlg; + } + +private slots: + void done(int r); + +private: + Ui::LANStartClientDialog* ui; +}; + +class LANDialog : public QDialog +{ + Q_OBJECT + +public: + explicit LANDialog(QWidget* parent); + ~LANDialog(); + + static LANDialog* openDlg(QWidget* parent) + { + LANDialog* dlg = new LANDialog(parent); + dlg->show(); + return dlg; + } + + void updatePlayerList(LAN::Player* players, int num); + +signals: + void sgUpdatePlayerList(LAN::Player* players, int num); + +private slots: + void done(int r); + + void doUpdatePlayerList(LAN::Player* players, int num); + +private: + Ui::LANDialog* ui; +}; + namespace LAN { diff --git a/src/frontend/qt_sdl/LANDialog.ui b/src/frontend/qt_sdl/LANDialog.ui new file mode 100644 index 00000000..e99000e4 --- /dev/null +++ b/src/frontend/qt_sdl/LANDialog.ui @@ -0,0 +1,31 @@ + + + LANDialog + + + + 0 + 0 + 522 + 391 + + + + LAN SHITO + + + + + + STATUS PLACEHOLDER + + + + + + + + + + + diff --git a/src/frontend/qt_sdl/LANStartClientDialog.ui b/src/frontend/qt_sdl/LANStartClientDialog.ui new file mode 100644 index 00000000..8721bfe7 --- /dev/null +++ b/src/frontend/qt_sdl/LANStartClientDialog.ui @@ -0,0 +1,97 @@ + + + LANStartClientDialog + + + + 0 + 0 + 400 + 229 + + + + + 0 + 0 + + + + Join LAN game - melonDS + + + + QLayout::SetFixedSize + + + + + + + Player name: + + + + + + + + + + Host address: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + LANStartClientDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + LANStartClientDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/LANStartHostDialog.ui b/src/frontend/qt_sdl/LANStartHostDialog.ui new file mode 100644 index 00000000..0d6cd50c --- /dev/null +++ b/src/frontend/qt_sdl/LANStartHostDialog.ui @@ -0,0 +1,97 @@ + + + LANStartHostDialog + + + + 0 + 0 + 389 + 228 + + + + + 0 + 0 + + + + Host LAN game - melonDS + + + + QLayout::SetFixedSize + + + + + + + Player name: + + + + + + + + + + Number of players: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + LANStartHostDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + LANStartHostDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 1e290ff0..138e5ab2 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -88,6 +88,7 @@ #include "Wifi.h" #include "Platform.h" #include "IPC.h" +#include "LAN.h" #include "Netplay.h" #include "Config.h" #include "DSi_I2C.h" @@ -1584,6 +1585,14 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) submenu->addSeparator(); + actLANStartHost = submenu->addAction("Host LAN game"); + connect(actLANStartHost, &QAction::triggered, this, &MainWindow::onLANStartHost); + + actLANStartClient = submenu->addAction("Join LAN game"); + connect(actLANStartClient, &QAction::triggered, this, &MainWindow::onLANStartClient); + + submenu->addSeparator(); + actMPStartHost = submenu->addAction("NETPLAY HOST"); connect(actMPStartHost, &QAction::triggered, this, &MainWindow::onMPStartHost); @@ -2859,6 +2868,16 @@ void MainWindow::onMPNewInstance() newinst.startDetached(); } +void MainWindow::onLANStartHost() +{ + LANStartHostDialog::openDlg(this); +} + +void MainWindow::onLANStartClient() +{ + LANStartClientDialog::openDlg(this); +} + void MainWindow::onMPStartHost() { //Netplay::StartHost(); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 2d6ddae7..93bcf6e0 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -311,6 +311,8 @@ private slots: void onRAMInfo(); void onOpenTitleManager(); void onMPNewInstance(); + void onLANStartHost(); + void onLANStartClient(); void onMPStartHost(); void onMPStartClient(); void onMPTest(); @@ -411,6 +413,8 @@ public: QAction* actRAMInfo; QAction* actTitleManager; QAction* actMPNewInstance; + QAction* actLANStartHost; + QAction* actLANStartClient; QAction* actMPStartHost; QAction* actMPStartClient; QAction* actMPTest;