mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Some ui improvements
This commit is contained in:
parent
52375468e4
commit
63a402a7fa
@ -18,8 +18,11 @@ Lobby::Lobby(QWidget *parent) :
|
||||
connect(&socketLobby, SIGNAL(receive(QString)), this, SLOT(dispatchMessage(QString)));
|
||||
connect(&socketLobby, SIGNAL(disconnect()), this, SLOT(onDisconnected()));
|
||||
|
||||
ui->hostEdit->setText(QString::fromStdString(settings["launcher"]["lobbyUrl"].String()));
|
||||
ui->portEdit->setText(QString::number(settings["launcher"]["lobbyPort"].Integer()));
|
||||
QString hostString("%1:%2");
|
||||
hostString = hostString.arg(QString::fromStdString(settings["launcher"]["lobbyUrl"].String()));
|
||||
hostString = hostString.arg(settings["launcher"]["lobbyPort"].Integer());
|
||||
|
||||
ui->serverEdit->setText(hostString);
|
||||
ui->userEdit->setText(QString::fromStdString(settings["launcher"]["lobbyUsername"].String()));
|
||||
}
|
||||
|
||||
@ -172,7 +175,7 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
||||
ui->playersList->clear();
|
||||
for(int i = 0; i < amount; ++i, tagPoint += 2)
|
||||
{
|
||||
ui->playersList->addItem(args[tagPoint]);
|
||||
ui->playersList->addItem(new QListWidgetItem(QIcon("icons:mod-enabled.png"), args[tagPoint]));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -180,8 +183,8 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
||||
protocolAssert(args.size() == 1);
|
||||
//actually start game
|
||||
gameArgs << "--lobby";
|
||||
gameArgs << "--lobby-address" << ui->hostEdit->text();
|
||||
gameArgs << "--lobby-port" << ui->portEdit->text();
|
||||
gameArgs << "--lobby-address" << serverUrl;
|
||||
gameArgs << "--lobby-port" << QString::number(serverPort);
|
||||
gameArgs << "--uuid" << args[0];
|
||||
startGame(gameArgs);
|
||||
break;
|
||||
@ -209,9 +212,14 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
||||
}
|
||||
|
||||
if(authentificationStatus == AuthStatus::AUTH_ERROR)
|
||||
{
|
||||
socketLobby.disconnectServer();
|
||||
}
|
||||
else
|
||||
{
|
||||
authentificationStatus = AuthStatus::AUTH_OK;
|
||||
ui->newButton->setEnabled(true);
|
||||
}
|
||||
}
|
||||
catch(const ProtocolError & e)
|
||||
{
|
||||
@ -247,6 +255,10 @@ void Lobby::onDisconnected()
|
||||
authentificationStatus = AuthStatus::AUTH_NONE;
|
||||
ui->stackedWidget->setCurrentWidget(ui->sessionsPage);
|
||||
ui->connectButton->setChecked(false);
|
||||
ui->serverEdit->setEnabled(true);
|
||||
ui->newButton->setEnabled(false);
|
||||
ui->joinButton->setEnabled(false);
|
||||
ui->sessionsTable->clear();
|
||||
}
|
||||
|
||||
void Lobby::chatMessage(QString title, QString body, bool isSystem)
|
||||
@ -287,21 +299,34 @@ void Lobby::on_connectButton_toggled(bool checked)
|
||||
authentificationStatus = AuthStatus::AUTH_NONE;
|
||||
username = ui->userEdit->text();
|
||||
const int connectionTimeout = settings["launcher"]["connectionTimeout"].Integer();
|
||||
|
||||
auto serverStrings = ui->serverEdit->text().split(":");
|
||||
if(serverStrings.size() != 2)
|
||||
{
|
||||
QMessageBox::critical(this, "Connection error", "Server address must have the format URL:port");
|
||||
return;
|
||||
}
|
||||
|
||||
serverUrl = serverStrings[0];
|
||||
serverPort = serverStrings[1].toInt();
|
||||
|
||||
Settings node = settings.write["launcher"];
|
||||
node["lobbyUrl"].String() = ui->hostEdit->text().toStdString();
|
||||
node["lobbyPort"].Integer() = ui->portEdit->text().toInt();
|
||||
node["lobbyUrl"].String() = serverUrl.toStdString();
|
||||
node["lobbyPort"].Integer() = serverPort;
|
||||
node["lobbyUsername"].String() = username.toStdString();
|
||||
|
||||
ui->serverEdit->setEnabled(false);
|
||||
|
||||
sysMessage("Connecting to " + ui->hostEdit->text() + ":" + ui->portEdit->text());
|
||||
sysMessage("Connecting to " + serverUrl + ":" + QString::number(serverPort));
|
||||
//show text immediately
|
||||
ui->chat->repaint();
|
||||
qApp->processEvents();
|
||||
|
||||
socketLobby.connectServer(ui->hostEdit->text(), ui->portEdit->text().toInt(), username, connectionTimeout);
|
||||
socketLobby.connectServer(serverUrl, serverPort, username, connectionTimeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->serverEdit->setEnabled(true);
|
||||
socketLobby.disconnectServer();
|
||||
}
|
||||
}
|
||||
@ -336,3 +361,10 @@ void Lobby::on_buttonReady_clicked()
|
||||
socketLobby.requestReadySession(session);
|
||||
}
|
||||
|
||||
|
||||
void Lobby::on_sessionsTable_itemSelectionChanged()
|
||||
{
|
||||
auto selection = ui->sessionsTable->selectedItems();
|
||||
ui->joinButton->setEnabled(!selection.empty());
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,12 @@ private slots:
|
||||
|
||||
void onDisconnected();
|
||||
|
||||
void on_sessionsTable_itemSelectionChanged();
|
||||
|
||||
private:
|
||||
QString serverUrl;
|
||||
int serverPort;
|
||||
|
||||
Ui::Lobby *ui;
|
||||
SocketLobby socketLobby;
|
||||
QString hostSession;
|
||||
|
@ -14,21 +14,7 @@
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="4">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>User</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6">
|
||||
<item row="0" column="5">
|
||||
<widget class="QPushButton" name="connectButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
@ -44,40 +30,47 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="QLineEdit" name="messageEdit"/>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLineEdit" name="portEdit">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="inputMethodHints">
|
||||
<set>Qt::ImhDigitsOnly</set>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>5002</string>
|
||||
<string>Username</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="hostEdit">
|
||||
<property name="text">
|
||||
<string>127.0.0.1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<item row="0" column="4">
|
||||
<widget class="QLineEdit" name="userEdit"/>
|
||||
</item>
|
||||
<item row="2" column="4" rowspan="2" colspan="3">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="serverEdit">
|
||||
<property name="text">
|
||||
<string>127.0.0.1:5002</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QPlainTextEdit" name="chat">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3" rowspan="2" colspan="3">
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
@ -132,15 +125,21 @@
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="newButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New game</string>
|
||||
<string>New room</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="joinButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Join game</string>
|
||||
<string>Join room</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -200,16 +199,6 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="4">
|
||||
<widget class="QPlainTextEdit" name="chat">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="4">
|
||||
<widget class="QLineEdit" name="messageEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
Loading…
Reference in New Issue
Block a user