Add Support for Room Descriptions

This commit is contained in:
adityaruplaha
2018-04-30 13:10:51 +05:30
committed by zhupengfei
parent c396e3c6e5
commit 5f0e189238
16 changed files with 110 additions and 23 deletions

View File

@@ -82,6 +82,7 @@ void ClientRoomWindow::UpdateView() {
.arg(QString::fromStdString(information.name))
.arg(memberlist.size())
.arg(information.member_slots));
ui->description->setText(QString::fromStdString(information.description));
return;
}
}

View File

@@ -21,6 +21,13 @@
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="description">
<property name="text">
<string>Room Description</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

View File

@@ -70,6 +70,7 @@ HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list,
if (index != -1) {
ui->game_list->setCurrentIndex(index);
}
ui->room_description->setText(UISettings::values.room_description);
}
HostRoomWindow::~HostRoomWindow() = default;
@@ -108,8 +109,10 @@ void HostRoomWindow::Host() {
auto port = ui->port->isModified() ? ui->port->text().toInt() : Network::DefaultRoomPort;
auto password = ui->password->text().toStdString();
if (auto room = Network::GetRoom().lock()) {
bool created = room->Create(ui->room_name->text().toStdString(), "", port, password,
ui->max_player->value(), game_name.toStdString(), game_id);
bool created =
room->Create(ui->room_name->text().toStdString(),
ui->room_description->toPlainText().toStdString(), "", port, password,
ui->max_player->value(), game_name.toStdString(), game_id);
if (!created) {
NetworkMessage::ShowError(NetworkMessage::COULD_NOT_CREATE_ROOM);
LOG_ERROR(Network, "Could not create room!");
@@ -132,6 +135,7 @@ void HostRoomWindow::Host() {
UISettings::values.room_port = (ui->port->isModified() && !ui->port->text().isEmpty())
? ui->port->text()
: QString::number(Network::DefaultRoomPort);
UISettings::values.room_description = ui->room_description->toPlainText();
Settings::Apply();
OnConnection();
}

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>607</width>
<height>165</height>
<height>211</height>
</rect>
</property>
<property name="windowTitle">
@@ -131,6 +131,20 @@
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Room Description</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="room_description"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="rightMargin">

View File

@@ -212,7 +212,11 @@ void Lobby::OnRefreshLobby() {
// To make the rows expandable, add the member data as a child of the first column of the
// rows with people in them and have qt set them to colspan after the model is finished
// resetting
if (room.members.size() > 0) {
if (!room.description.empty()) {
first_item->appendRow(
new LobbyItemDescription(QString::fromStdString(room.description)));
}
if (!room.members.empty()) {
first_item->appendRow(new LobbyItemExpandedMemberList(members));
}
}
@@ -228,8 +232,8 @@ void Lobby::OnRefreshLobby() {
// Set the member list child items to span all columns
for (int i = 0; i < proxy->rowCount(); i++) {
auto parent = model->item(i, 0);
if (parent->hasChildren()) {
ui->room_list->setFirstColumnSpanned(0, proxy->index(i, 0), true);
for (int j = 0; j < parent->rowCount(); j++) {
ui->room_list->setFirstColumnSpanned(j, proxy->index(i, 0), true);
}
}
}

View File

@@ -55,6 +55,31 @@ public:
}
};
class LobbyItemDescription : public LobbyItem {
public:
static const int DescriptionRole = Qt::UserRole + 1;
LobbyItemDescription() = default;
explicit LobbyItemDescription(QString description) {
setData(description, DescriptionRole);
}
QVariant data(int role) const override {
if (role != Qt::DisplayRole) {
return LobbyItem::data(role);
}
auto description = data(DescriptionRole).toString();
description.prepend("Description: ");
return description;
}
bool operator<(const QStandardItem& other) const override {
return data(DescriptionRole)
.toString()
.localeAwareCompare(other.data(DescriptionRole).toString()) < 0;
}
};
class LobbyItemGame : public LobbyItem {
public:
static const int TitleIDRole = Qt::UserRole + 1;