2022-03-01 13:18:00 +08:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.0
|
2022-03-23 19:40:28 +08:00
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import "RoomElement"
|
|
|
|
import "RoomLogic.js" as Logic
|
2022-03-01 13:18:00 +08:00
|
|
|
|
|
|
|
Item {
|
2022-03-23 19:40:28 +08:00
|
|
|
id: roomScene
|
|
|
|
|
|
|
|
property int playerNum: 0
|
|
|
|
property var dashboardModel
|
|
|
|
|
2022-03-27 14:49:41 +08:00
|
|
|
property bool isOwner: false
|
|
|
|
property bool isStarted: false
|
|
|
|
|
2022-03-30 14:14:40 +08:00
|
|
|
property alias popupBox: popupBox
|
2022-04-02 15:11:13 +08:00
|
|
|
property alias promptText: prompt.text
|
2022-03-30 14:14:40 +08:00
|
|
|
|
2022-03-23 19:40:28 +08:00
|
|
|
// tmp
|
2022-04-14 18:22:00 +08:00
|
|
|
Row {
|
|
|
|
Button{text:"摸1牌"
|
|
|
|
onClicked:{
|
|
|
|
Logic.moveCards([{
|
|
|
|
from:Logic.Player.DrawPile,
|
|
|
|
to:Logic.Player.PlaceHand,
|
|
|
|
cards:[1],
|
|
|
|
}])
|
|
|
|
}}
|
|
|
|
Button{text:"弃1牌"
|
|
|
|
onClicked:{Logic.moveCards([{
|
|
|
|
to:Logic.Player.DrawPile,
|
|
|
|
from:Logic.Player.PlaceHand,
|
|
|
|
cards:[1],
|
|
|
|
}])}}
|
|
|
|
}
|
2022-03-01 13:18:00 +08:00
|
|
|
Button {
|
|
|
|
text: "quit"
|
2022-04-02 15:11:13 +08:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: parent.right
|
2022-03-01 13:18:00 +08:00
|
|
|
onClicked: {
|
2022-03-28 22:24:30 +08:00
|
|
|
ClientInstance.clearPlayers();
|
2022-03-27 14:49:41 +08:00
|
|
|
ClientInstance.notifyServer("QuitRoom", "[]");
|
2022-03-01 13:18:00 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-27 14:49:41 +08:00
|
|
|
Button {
|
2022-04-03 06:41:55 +08:00
|
|
|
text: "add robot"
|
2022-03-30 14:14:40 +08:00
|
|
|
visible: dashboardModel.isOwner && !isStarted
|
2022-03-27 14:49:41 +08:00
|
|
|
anchors.centerIn: parent
|
2022-04-03 06:41:55 +08:00
|
|
|
onClicked: {
|
|
|
|
ClientInstance.notifyServer("AddRobot", "[]");
|
|
|
|
}
|
2022-03-27 14:49:41 +08:00
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-02 15:11:13 +08:00
|
|
|
states: [
|
|
|
|
State { name: "notactive" }, // Normal status
|
|
|
|
State { name: "playing" }, // Playing cards in playing phase
|
|
|
|
State { name: "responding" }, // all requests need to operate dashboard
|
|
|
|
State { name: "replying" } // requests only operate a popup window
|
|
|
|
]
|
|
|
|
state: "notactive"
|
|
|
|
transitions: [
|
|
|
|
Transition {
|
|
|
|
from: "*"; to: "notactive"
|
|
|
|
ScriptAction {
|
|
|
|
script: {
|
|
|
|
promptText = "";
|
|
|
|
progress.visible = false;
|
|
|
|
okCancel.visible = false;
|
|
|
|
endPhaseButton.visible = false;
|
|
|
|
|
|
|
|
if (popupBox.item != null) {
|
|
|
|
popupBox.item.finished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
Transition {
|
|
|
|
from: "*"; to: "playing"
|
|
|
|
ScriptAction {
|
|
|
|
script: {
|
|
|
|
progress.visible = true;
|
|
|
|
okCancel.visible = true;
|
|
|
|
endPhaseButton.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
Transition {
|
|
|
|
from: "*"; to: "responding"
|
|
|
|
ScriptAction {
|
|
|
|
script: {
|
|
|
|
progress.visible = true;
|
|
|
|
okCancel.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
Transition {
|
|
|
|
from: "*"; to: "replying"
|
|
|
|
ScriptAction {
|
|
|
|
script: {
|
|
|
|
progress.visible = true;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
}
|
2022-04-02 15:11:13 +08:00
|
|
|
]
|
2022-03-23 19:40:28 +08:00
|
|
|
|
|
|
|
/* Layout:
|
|
|
|
* +---------------------+
|
|
|
|
* | Photos, get more |
|
|
|
|
* | in arrangePhotos() |
|
|
|
|
* | tablePile |
|
|
|
|
* | progress,prompt,btn |
|
|
|
|
* +---------------------+
|
|
|
|
* | dashboard |
|
|
|
|
* +---------------------+
|
|
|
|
*/
|
|
|
|
|
2022-03-28 22:24:30 +08:00
|
|
|
ListModel {
|
|
|
|
id: photoModel
|
|
|
|
}
|
|
|
|
|
2022-03-23 19:40:28 +08:00
|
|
|
Item {
|
|
|
|
id: roomArea
|
|
|
|
width: roomScene.width
|
|
|
|
height: roomScene.height - dashboard.height
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: photos
|
|
|
|
model: photoModel
|
|
|
|
Photo {
|
2022-03-30 14:14:40 +08:00
|
|
|
general: model.general
|
|
|
|
screenName: model.screenName
|
|
|
|
role: model.role
|
|
|
|
kingdom: model.kingdom
|
|
|
|
netstate: model.netstate
|
|
|
|
maxHp: model.maxHp
|
|
|
|
hp: model.hp
|
|
|
|
seatNumber: model.seatNumber
|
|
|
|
isDead: model.isDead
|
|
|
|
dying: model.dying
|
2022-04-02 21:39:44 +08:00
|
|
|
faceup: model.faceup
|
2022-03-30 14:14:40 +08:00
|
|
|
chained: model.chained
|
|
|
|
drank: model.drank
|
|
|
|
isOwner: model.isOwner
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onWidthChanged: Logic.arrangePhotos();
|
|
|
|
onHeightChanged: Logic.arrangePhotos();
|
|
|
|
|
|
|
|
InvisibleCardArea {
|
|
|
|
id: drawPile
|
|
|
|
x: parent.width / 2
|
|
|
|
y: roomScene.height / 2
|
|
|
|
}
|
|
|
|
|
|
|
|
TablePile {
|
|
|
|
id: tablePile
|
|
|
|
width: parent.width * 0.6
|
|
|
|
height: 150
|
|
|
|
x: parent.width * 0.2
|
2022-04-14 18:22:00 +08:00
|
|
|
y: parent.height * 0.6
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dashboard {
|
|
|
|
id: dashboard
|
|
|
|
width: roomScene.width
|
|
|
|
anchors.top: roomArea.bottom
|
2022-03-24 21:23:42 +08:00
|
|
|
|
|
|
|
self.general: dashboardModel.general
|
|
|
|
self.screenName: dashboardModel.screenName
|
|
|
|
self.role: dashboardModel.role
|
|
|
|
self.kingdom: dashboardModel.kingdom
|
|
|
|
self.netstate: dashboardModel.netstate
|
|
|
|
self.maxHp: dashboardModel.maxHp
|
|
|
|
self.hp: dashboardModel.hp
|
|
|
|
self.seatNumber: dashboardModel.seatNumber
|
|
|
|
self.isDead: dashboardModel.isDead
|
|
|
|
self.dying: dashboardModel.dying
|
2022-04-02 21:39:44 +08:00
|
|
|
self.faceup: dashboardModel.faceup
|
2022-03-24 21:23:42 +08:00
|
|
|
self.chained: dashboardModel.chained
|
|
|
|
self.drank: dashboardModel.drank
|
2022-03-27 14:49:41 +08:00
|
|
|
self.isOwner: dashboardModel.isOwner
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
|
2022-04-02 15:11:13 +08:00
|
|
|
Item {
|
|
|
|
id: controls
|
|
|
|
anchors.bottom: dashboard.top
|
|
|
|
anchors.bottomMargin: -40
|
|
|
|
width: roomScene.width
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: prompt
|
|
|
|
visible: progress.visible
|
|
|
|
anchors.bottom: progress.top
|
|
|
|
anchors.bottomMargin: 8
|
|
|
|
anchors.horizontalCenter: progress.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressBar {
|
|
|
|
id: progress
|
|
|
|
width: parent.width * 0.6
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.bottom: okCancel.top
|
|
|
|
anchors.bottomMargin: 8
|
|
|
|
from: 0.0
|
|
|
|
to: 100.0
|
|
|
|
|
|
|
|
visible: false
|
|
|
|
NumberAnimation on value {
|
|
|
|
running: progress.visible
|
|
|
|
from: 100.0
|
|
|
|
to: 0.0
|
|
|
|
duration: config.roomTimeout * 1000
|
|
|
|
|
|
|
|
onFinished: {
|
|
|
|
roomScene.state = "notactive"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
id: okCancel
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.horizontalCenter: progress.horizontalCenter
|
|
|
|
spacing: 20
|
|
|
|
visible: false
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: okButton
|
|
|
|
text: "OK"
|
|
|
|
onClicked: Logic.doOkButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: cancelButton
|
|
|
|
text: "Cancel"
|
|
|
|
onClicked: Logic.doCancelButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: endPhaseButton
|
|
|
|
text: "End"
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: 40
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 30
|
|
|
|
visible: false;
|
|
|
|
onClicked: Logic.doCancelButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-30 14:14:40 +08:00
|
|
|
Loader {
|
|
|
|
id: popupBox
|
|
|
|
onSourceChanged: {
|
|
|
|
if (item === null)
|
|
|
|
return;
|
|
|
|
item.finished.connect(function(){
|
|
|
|
source = "";
|
|
|
|
});
|
|
|
|
item.widthChanged.connect(function(){
|
|
|
|
popupBox.moveToCenter();
|
|
|
|
});
|
|
|
|
item.heightChanged.connect(function(){
|
|
|
|
popupBox.moveToCenter();
|
|
|
|
});
|
|
|
|
moveToCenter();
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveToCenter()
|
|
|
|
{
|
|
|
|
item.x = Math.round((roomArea.width - item.width) / 2);
|
|
|
|
item.y = Math.round(roomArea.height * 0.67 - item.height / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 19:40:28 +08:00
|
|
|
Component.onCompleted: {
|
|
|
|
toast.show("Sucesessfully entered room.");
|
2022-03-24 21:23:42 +08:00
|
|
|
|
|
|
|
dashboardModel = {
|
2022-03-28 22:24:30 +08:00
|
|
|
id: Self.id,
|
2022-03-27 14:49:41 +08:00
|
|
|
general: Self.avatar,
|
|
|
|
screenName: Self.screenName,
|
2022-03-24 21:23:42 +08:00
|
|
|
role: "unknown",
|
|
|
|
kingdom: "qun",
|
|
|
|
netstate: "online",
|
|
|
|
maxHp: 0,
|
|
|
|
hp: 0,
|
|
|
|
seatNumber: 1,
|
|
|
|
isDead: false,
|
|
|
|
dying: false,
|
2022-04-02 21:39:44 +08:00
|
|
|
faceup: true,
|
2022-03-24 21:23:42 +08:00
|
|
|
chained: false,
|
2022-03-27 14:49:41 +08:00
|
|
|
drank: false,
|
|
|
|
isOwner: false
|
2022-03-24 21:23:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
playerNum = config.roomCapacity;
|
|
|
|
|
|
|
|
let i;
|
|
|
|
for (i = 1; i < playerNum; i++) {
|
2022-03-28 22:24:30 +08:00
|
|
|
photoModel.append({
|
|
|
|
id: -1,
|
|
|
|
index: i - 1, // For animating seat swap
|
2022-03-30 14:14:40 +08:00
|
|
|
general: "",
|
|
|
|
screenName: "",
|
|
|
|
role: "unknown",
|
|
|
|
kingdom: "qun",
|
|
|
|
netstate: "online",
|
|
|
|
maxHp: 0,
|
|
|
|
hp: 0,
|
|
|
|
seatNumber: i + 1,
|
|
|
|
isDead: false,
|
|
|
|
dying: false,
|
2022-04-02 21:39:44 +08:00
|
|
|
faceup: true,
|
2022-03-30 14:14:40 +08:00
|
|
|
chained: false,
|
|
|
|
drank: false,
|
|
|
|
isOwner: false
|
2022-03-24 21:23:42 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-23 19:40:28 +08:00
|
|
|
Logic.arrangePhotos();
|
|
|
|
}
|
2022-03-01 13:18:00 +08:00
|
|
|
}
|
|
|
|
|