mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-24 14:49:53 -06:00
actually make that client connect UI work
This commit is contained in:
@ -51,6 +51,7 @@
|
|||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "LAN.h"
|
#include "LAN.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
@ -110,7 +111,11 @@ LANStartClientDialog::LANStartClientDialog(QWidget* parent) : QDialog(parent), u
|
|||||||
const QStringList listheader = {"Name", "Players", "Status"};
|
const QStringList listheader = {"Name", "Players", "Status"};
|
||||||
model->setHorizontalHeaderLabels(listheader);
|
model->setHorizontalHeaderLabels(listheader);
|
||||||
|
|
||||||
|
connect(ui->tvAvailableGames->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
|
||||||
|
this, SLOT(onGameSelectionChanged(const QItemSelection&, const QItemSelection&)));
|
||||||
|
|
||||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Connect");
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Connect");
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
|
|
||||||
QPushButton* btn = ui->buttonBox->addButton("Direct connect...", QDialogButtonBox::ActionRole);
|
QPushButton* btn = ui->buttonBox->addButton("Direct connect...", QDialogButtonBox::ActionRole);
|
||||||
connect(btn, SIGNAL(clicked()), this, SLOT(onDirectConnect()));
|
connect(btn, SIGNAL(clicked()), this, SLOT(onDirectConnect()));
|
||||||
@ -127,33 +132,86 @@ LANStartClientDialog::~LANStartClientDialog()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LANStartClientDialog::onGameSelectionChanged(const QItemSelection& cur, const QItemSelection& prev)
|
||||||
|
{
|
||||||
|
QModelIndexList indlist = cur.indexes();
|
||||||
|
if (indlist.count() == 0)
|
||||||
|
{
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LANStartClientDialog::on_tvAvailableGames_doubleClicked(QModelIndex index)
|
||||||
|
{
|
||||||
|
done(QDialog::Accepted);
|
||||||
|
}
|
||||||
|
|
||||||
void LANStartClientDialog::onDirectConnect()
|
void LANStartClientDialog::onDirectConnect()
|
||||||
{
|
{
|
||||||
|
if (ui->txtPlayerName->text().trimmed().isEmpty())
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, "melonDS", "Please enter a player name before connecting.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString host = QInputDialog::getText(this, "Direct connect", "Host address:");
|
QString host = QInputDialog::getText(this, "Direct connect", "Host address:");
|
||||||
if (host.isEmpty()) return;
|
if (host.isEmpty()) return;
|
||||||
|
|
||||||
printf("dicks: %s\n", host.toStdString().c_str());
|
std::string hostname = host.toStdString();
|
||||||
//QDialog::done(QDialog::Accepted);
|
std::string player = ui->txtPlayerName->text().toStdString();
|
||||||
|
|
||||||
|
LAN::EndDiscovery();
|
||||||
|
if (!LAN::StartClient(player.c_str(), hostname.c_str()))
|
||||||
|
{
|
||||||
|
QString msg = QString("Failed to connect to the host %0.").arg(QString::fromStdString(hostname));
|
||||||
|
QMessageBox::warning(this, "melonDS", msg);
|
||||||
|
LAN::StartDiscovery();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lanDlg = LANDialog::openDlg(parentWidget());
|
||||||
|
QDialog::done(QDialog::Accepted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LANStartClientDialog::done(int r)
|
void LANStartClientDialog::done(int r)
|
||||||
{
|
{
|
||||||
if (r == QDialog::Accepted)
|
if (r == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
std::string player = ui->txtPlayerName->text().toStdString();
|
if (ui->txtPlayerName->text().trimmed().isEmpty())
|
||||||
//std::string host = ui->txtIPAddress->text().toStdString();
|
{
|
||||||
|
QMessageBox::warning(this, "melonDS", "Please enter a player name before connecting.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO validate input!!
|
QModelIndexList indlist = ui->tvAvailableGames->selectionModel()->selectedRows();
|
||||||
|
if (indlist.count() == 0) return;
|
||||||
|
|
||||||
|
QStandardItemModel* model = (QStandardItemModel*)ui->tvAvailableGames->model();
|
||||||
|
QStandardItem* item = model->item(indlist[0].row());
|
||||||
|
u32 addr = item->data().toUInt();
|
||||||
|
char hostname[16];
|
||||||
|
snprintf(hostname, 16, "%d.%d.%d.%d", (addr>>24), ((addr>>16)&0xFF), ((addr>>8)&0xFF), (addr&0xFF));
|
||||||
|
|
||||||
|
std::string player = ui->txtPlayerName->text().toStdString();
|
||||||
|
|
||||||
|
LAN::EndDiscovery();
|
||||||
|
if (!LAN::StartClient(player.c_str(), hostname))
|
||||||
|
{
|
||||||
|
QString msg = QString("Failed to connect to the host %0.").arg(QString(hostname));
|
||||||
|
QMessageBox::warning(this, "melonDS", msg);
|
||||||
|
LAN::StartDiscovery();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lanDlg = LANDialog::openDlg(parentWidget());
|
lanDlg = LANDialog::openDlg(parentWidget());
|
||||||
|
|
||||||
//LAN::StartClient(player.c_str(), host.c_str());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TEST!!
|
LAN::EndDiscovery();
|
||||||
printf("borp\n");
|
|
||||||
//LAN::StartDiscovery();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QDialog::done(r);
|
QDialog::done(r);
|
||||||
@ -191,6 +249,7 @@ void LANStartClientDialog::doUpdateDiscoveryList()
|
|||||||
for (const auto& [key, data] : LAN::DiscoveryList)
|
for (const auto& [key, data] : LAN::DiscoveryList)
|
||||||
{
|
{
|
||||||
model->item(i, 0)->setText(data.SessionName);
|
model->item(i, 0)->setText(data.SessionName);
|
||||||
|
model->item(i, 0)->setData(QVariant(key));
|
||||||
|
|
||||||
QString plcount = QString("%0/%1").arg(data.NumPlayers).arg(data.MaxPlayers);
|
QString plcount = QString("%0/%1").arg(data.NumPlayers).arg(data.MaxPlayers);
|
||||||
model->item(i, 1)->setText(plcount);
|
model->item(i, 1)->setText(plcount);
|
||||||
@ -463,7 +522,8 @@ bool StartHost(const char* playername, int numplayers)
|
|||||||
Active = true;
|
Active = true;
|
||||||
IsHost = true;
|
IsHost = true;
|
||||||
|
|
||||||
lanDlg->updatePlayerList(Players, NumPlayers);
|
if (lanDlg)
|
||||||
|
lanDlg->updatePlayerList(Players, NumPlayers);
|
||||||
|
|
||||||
StartDiscovery();
|
StartDiscovery();
|
||||||
return true;
|
return true;
|
||||||
@ -708,7 +768,8 @@ void ProcessHostEvent(ENetEvent& event)
|
|||||||
ENetPacket* pkt = enet_packet_create(cmd, 2+sizeof(Players), ENET_PACKET_FLAG_RELIABLE);
|
ENetPacket* pkt = enet_packet_create(cmd, 2+sizeof(Players), ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_host_broadcast(Host, 0, pkt);
|
enet_host_broadcast(Host, 0, pkt);
|
||||||
|
|
||||||
lanDlg->updatePlayerList(Players, NumPlayers);
|
if (lanDlg)
|
||||||
|
lanDlg->updatePlayerList(Players, NumPlayers);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -811,7 +872,8 @@ void ProcessClientEvent(ENetEvent& event)
|
|||||||
Players[i].Name[31] = '\0';
|
Players[i].Name[31] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
lanDlg->updatePlayerList(Players, NumPlayers);
|
if (lanDlg)
|
||||||
|
lanDlg->updatePlayerList(Players, NumPlayers);
|
||||||
|
|
||||||
// establish connections to any new clients
|
// establish connections to any new clients
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QItemSelection>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
@ -100,6 +101,8 @@ signals:
|
|||||||
void sgUpdateDiscoveryList();
|
void sgUpdateDiscoveryList();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void onGameSelectionChanged(const QItemSelection& cur, const QItemSelection& prev);
|
||||||
|
void on_tvAvailableGames_doubleClicked(QModelIndex index);
|
||||||
void onDirectConnect();
|
void onDirectConnect();
|
||||||
void done(int r);
|
void done(int r);
|
||||||
|
|
||||||
|
@ -61,7 +61,11 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="tvAvailableGames"/>
|
<widget class="QTreeView" name="tvAvailableGames">
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
Reference in New Issue
Block a user