more base work for LAN
This commit is contained in:
parent
86bf219450
commit
ca4d745e71
|
@ -20,15 +20,154 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//
|
||||
#include <enet/enet.h>
|
||||
|
||||
#include <QStandardItemModel>
|
||||
|
||||
#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
|
||||
|
|
|
@ -20,9 +20,101 @@
|
|||
#define LAN_H
|
||||
|
||||
#include <string>
|
||||
#include <QDialog>
|
||||
|
||||
#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
|
||||
{
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LANDialog</class>
|
||||
<widget class="QDialog" name="LANDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>522</width>
|
||||
<height>391</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>LAN SHITO</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblStatus">
|
||||
<property name="text">
|
||||
<string>STATUS PLACEHOLDER</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="tvPlayerList"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LANStartClientDialog</class>
|
||||
<widget class="QDialog" name="LANStartClientDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>229</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Join LAN game - melonDS</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Player name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtPlayerName"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Host address:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="txtIPAddress"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>LANStartClientDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>LANStartClientDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LANStartHostDialog</class>
|
||||
<widget class="QDialog" name="LANStartHostDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>389</width>
|
||||
<height>228</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Host LAN game - melonDS</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Player name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtPlayerName"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Number of players:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="sbNumPlayers"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>LANStartHostDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>LANStartHostDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue