From 9c6fd38e68b5bdae55b49d8d587a86cb66592559 Mon Sep 17 00:00:00 2001 From: notify Date: Mon, 10 Jun 2024 14:55:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E5=A4=A7=E5=8E=85=E6=94=B9=E6=88=90?= =?UTF-8?q?=E8=87=B3=E5=B0=91=E8=83=BD=E7=8E=A9=E7=9A=84=E7=A8=8B=E5=BA=A6?= =?UTF-8?q?=EF=BC=8C=E9=B8=BD=E4=B8=80=E4=B8=AA=E7=89=88=E6=9C=AC=E5=85=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Fk/Config.qml | 2 + Fk/Logic.js | 1 - Fk/Pages/Lobby.qml | 146 ++++++++++++++++++++++++------------------- src/server/lobby.cpp | 14 +++++ src/server/lobby.h | 1 + 5 files changed, 99 insertions(+), 65 deletions(-) diff --git a/Fk/Config.qml b/Fk/Config.qml index fa47a54b..452a0e09 100644 --- a/Fk/Config.qml +++ b/Fk/Config.qml @@ -43,6 +43,8 @@ QtObject { property string password: "" property string cipherText property string aeskey + // string => { roomId => config } + property var roomConfigCache: ({}) // Client data property string serverMotd: "" diff --git a/Fk/Logic.js b/Fk/Logic.js index aa7fc923..b098e7ef 100644 --- a/Fk/Logic.js +++ b/Fk/Logic.js @@ -163,7 +163,6 @@ callbacks["UpdateRoomList"] = (data) => { data.forEach(room => { const [roomId, roomName, gameMode, playerNum, capacity, hasPassword, outdated] = room; - for (let j=0;j<40;j++) current.roomModel.append({ roomId, roomName, gameMode, playerNum, capacity, hasPassword, outdated, diff --git a/Fk/Pages/Lobby.qml b/Fk/Pages/Lobby.qml index 8c59d164..4931978c 100644 --- a/Fk/Pages/Lobby.qml +++ b/Fk/Pages/Lobby.qml @@ -22,7 +22,7 @@ Item { radius: 8 height: 124 - 8 width: 124 - 8 - color: "lightgreen" + color: outdated ? "#E2E2E2" : "lightgreen" Text { id: roomNameText @@ -50,7 +50,7 @@ Item { Image { source: AppPath + "/image/button/skill/locked.png" - // visible: hasPassword + visible: hasPassword scale: 0.8 anchors.bottom: parent.bottom anchors.left: parent.left @@ -68,41 +68,97 @@ Item { anchors.rightMargin: 8 } - // Button { - // text: (playerNum < capacity) ? luatr("Enter") : - // luatr("Observe") - - // enabled: !opTimer.running && !outdated - - // onClicked: { - // opTimer.start(); - // if (hasPassword) { - // lobby_dialog.sourceComponent = enterPassword; - // lobby_dialog.item.roomId = roomId; - // lobby_dialog.item.playerNum = playerNum; - // lobby_dialog.item.capacity = capacity; - // lobby_drawer.open(); - // } else { - // enterRoom(roomId, playerNum, capacity, ""); - // } - // } - // } - TapHandler { gesturePolicy: TapHandler.WithinBounds enabled: !opTimer.running && !outdated onTapped: { lobby_dialog.sourceComponent = roomDetailDialog; - //lobby_dialog.item.roomId = roomId; - //lobby_dialog.item.playerNum = playerNum; - //lobby_dialog.item.capacity = capacity; + lobby_dialog.item.roomData = { + roomId, roomName, gameMode, playerNum, capacity, + hasPassword, outdated, + }; + lobby_dialog.item.roomConfig = config.roomConfigCache?.[config.serverAddr]?.[roomId] lobby_drawer.open(); } } } } + Component { + id: roomDetailDialog + ColumnLayout { + property var roomData: ({ + roomName: "", + hasPassword: true, + }) + property var roomConfig: undefined + signal finished() + anchors.fill: parent + anchors.margins: 16 + + Text { + text: roomData.roomName + font.pixelSize: 18 + } + + Text { + font.pixelSize: 18 + text: { + let ret = luatr(roomData.gameMode); + ret += (' #' + roomData.roomId); + ret += (' ' + roomData.playerNum + '/' + roomData.capacity); + return ret; + } + } + + Item { Layout.fillHeight: true } + + // Dummy + Text { + text: "在未来的版本中这一块区域将增加更多实用的功能,
"+ + "例如直接查看房间的各种配置信息
"+ + "以及更多与禁将有关的实用功能!"+ + "注:绿色按钮为试做型UI 后面优化" + font.pixelSize: 18 + } + + RowLayout { + Layout.fillWidth: true + Text { + visible: roomData.hasPassword + text: luatr("Please input room's password") + } + + TextField { + id: passwordEdit + visible: roomData.hasPassword + Layout.fillWidth: true + onTextChanged: root.password = text; + } + + Item { + visible: !roomData.hasPassword + Layout.fillWidth: true + } + + Button { + // text: "OK" + text: (roomData.playerNum < roomData.capacity) ? luatr("Enter") : luatr("Observe") + onClicked: { + enterRoom(roomData.roomId, roomData.playerNum, roomData.capacity, + roomData.hasPassword ? root.password : ""); + lobby_dialog.item.finished(); + } + } + } + + Component.onCompleted: { + passwordEdit.text = ""; + } + } + } + ListModel { id: roomModel } @@ -130,14 +186,9 @@ Item { RowLayout { Layout.fillWidth: true Item { Layout.fillWidth: true } - Text { - width: parent.width - horizontalAlignment: Text.AlignHCenter - text: luatr("Room List").arg(roomModel.count) - } Button { Layout.alignment: Qt.AlignRight - text: luatr("Refresh Room List") + text: luatr("Refresh Room List").arg(roomModel.count) enabled: !opTimer.running onClicked: { opTimer.start(); @@ -326,39 +377,6 @@ Item { } } - Component { - id: enterPassword - ColumnLayout { - property int roomId - property int playerNum - property int capacity - signal finished() - anchors.fill: parent - anchors.margins: 16 - - Text { - text: luatr("Please input room's password") - } - - TextField { - id: passwordEdit - onTextChanged: root.password = text; - } - - Button { - text: "OK" - onClicked: { - enterRoom(roomId, playerNum, capacity, root.password); - parent.finished(); - } - } - - Component.onCompleted: { - passwordEdit.text = ""; - } - } - } - function enterRoom(roomId, playerNum, capacity, pw) { config.replaying = false; if (playerNum < capacity) { diff --git a/src/server/lobby.cpp b/src/server/lobby.cpp index 62d92756..bddcb429 100644 --- a/src/server/lobby.cpp +++ b/src/server/lobby.cpp @@ -83,6 +83,19 @@ void Lobby::createRoom(ServerPlayer *sender, const QString &jsonData) { ServerInstance->createRoom(sender, name, capacity, timeout, settings); } +void Lobby::getRoomConfig(ServerPlayer *sender, const QString &jsonData) { + auto arr = String2Json(jsonData).array(); + auto roomId = arr[0].toInt(); + auto room = ServerInstance->findRoom(roomId); + if (room) { + auto settings = room->getSettings(); + // 手搓JSON数组 跳过编码解码 + sender->doNotify("GetRoomConfig", QString("[%1,%2]").arg(roomId).arg(settings)); + } else { + sender->doNotify("ErrorMsg", "no such room"); + } +} + void Lobby::enterRoom(ServerPlayer *sender, const QString &jsonData) { auto arr = String2Json(jsonData).array(); auto roomId = arr[0].toInt(); @@ -137,6 +150,7 @@ void Lobby::handlePacket(ServerPlayer *sender, const QString &command, {"UpdateAvatar", &Lobby::updateAvatar}, {"UpdatePassword", &Lobby::updatePassword}, {"CreateRoom", &Lobby::createRoom}, + {"GetRoomConfig", &Lobby::getRoomConfig}, {"EnterRoom", &Lobby::enterRoom}, {"ObserveRoom", &Lobby::observeRoom}, {"RefreshRoomList", &Lobby::refreshRoomList}, diff --git a/src/server/lobby.h b/src/server/lobby.h index 3a988a92..dad70931 100644 --- a/src/server/lobby.h +++ b/src/server/lobby.h @@ -18,6 +18,7 @@ class Lobby : public RoomBase { void updateAvatar(ServerPlayer *, const QString &); void updatePassword(ServerPlayer *, const QString &); void createRoom(ServerPlayer *, const QString &); + void getRoomConfig(ServerPlayer *, const QString &); void enterRoom(ServerPlayer *, const QString &); void observeRoom(ServerPlayer *, const QString &); void refreshRoomList(ServerPlayer *, const QString &);