2022-09-14 13:01:10 +08:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Window
|
2022-03-23 19:40:28 +08:00
|
|
|
import "Logic.js" as Logic
|
2022-03-01 13:18:00 +08:00
|
|
|
import "Pages"
|
2022-01-24 10:23:08 +08:00
|
|
|
|
|
|
|
Window {
|
2022-12-18 12:52:52 +08:00
|
|
|
id: realMainWin
|
2022-04-30 15:27:56 +08:00
|
|
|
visible: true
|
2022-09-14 13:01:10 +08:00
|
|
|
width: 960
|
|
|
|
height: 540
|
2023-02-15 21:20:40 +08:00
|
|
|
minimumWidth: 160
|
|
|
|
minimumHeight: 90
|
2022-04-30 15:27:56 +08:00
|
|
|
property var callbacks: Logic.callbacks
|
2022-01-24 10:23:08 +08:00
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
Item {
|
|
|
|
id: mainWindow
|
|
|
|
width: (parent.width / parent.height < 960 / 540)
|
|
|
|
? 960 : 540 * parent.width / parent.height
|
|
|
|
height: (parent.width / parent.height > 960 / 540)
|
|
|
|
? 540 : 960 * parent.height / parent.width
|
|
|
|
scale: parent.width / width
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
2022-12-18 12:52:52 +08:00
|
|
|
Config {
|
|
|
|
id: config
|
|
|
|
}
|
|
|
|
|
2022-05-01 18:37:13 +08:00
|
|
|
Image {
|
2023-02-15 19:54:35 +08:00
|
|
|
source: config.lobbyBg
|
2022-05-01 18:37:13 +08:00
|
|
|
anchors.fill: parent
|
|
|
|
fillMode: Image.PreserveAspectCrop
|
|
|
|
}
|
|
|
|
|
|
|
|
FontLoader { id: fontLibian; source: AppPath + "/fonts/FZLBGBK.ttf" }
|
|
|
|
FontLoader { id: fontLi2; source: AppPath + "/fonts/FZLE.ttf" }
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
StackView {
|
|
|
|
id: mainStack
|
|
|
|
visible: !mainWindow.busy
|
2023-02-15 21:20:40 +08:00
|
|
|
// If error occurs during loading initialItem, the program will fall into "polish()" loop
|
|
|
|
// initialItem: OS !== "Web" ? init : webinit
|
2022-04-30 15:27:56 +08:00
|
|
|
anchors.fill: parent
|
|
|
|
}
|
2022-01-24 10:23:08 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
Component { id: init; Init {} }
|
2023-01-03 23:37:14 +08:00
|
|
|
Component { id: webinit; WebInit {} }
|
2023-02-15 19:54:35 +08:00
|
|
|
Component { id: packageManage; PackageManage {} }
|
2022-04-30 15:27:56 +08:00
|
|
|
Component { id: lobby; Lobby {} }
|
|
|
|
Component { id: generalsOverview; GeneralsOverview {} }
|
|
|
|
Component { id: cardsOverview; CardsOverview {} }
|
2023-03-20 14:53:56 +08:00
|
|
|
Component { id: modesOverview; ModesOverview {} }
|
2022-04-30 15:27:56 +08:00
|
|
|
Component { id: room; Room {} }
|
2023-01-12 22:53:22 +08:00
|
|
|
Component { id: aboutPage; About {} }
|
2022-03-01 13:18:00 +08:00
|
|
|
|
2022-05-01 18:37:13 +08:00
|
|
|
property var generalsOverviewPage
|
|
|
|
property var cardsOverviewPage
|
2023-03-20 14:53:56 +08:00
|
|
|
property alias modesOverviewPage: modesOverview
|
2023-01-12 22:53:22 +08:00
|
|
|
property alias aboutPage: aboutPage
|
2022-04-30 15:27:56 +08:00
|
|
|
property bool busy: false
|
2023-02-15 19:54:35 +08:00
|
|
|
property string busyText: ""
|
|
|
|
onBusyChanged: busyText = "";
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
BusyIndicator {
|
|
|
|
running: true
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: mainWindow.busy === true
|
|
|
|
}
|
2023-02-15 19:54:35 +08:00
|
|
|
Item {
|
|
|
|
visible: mainWindow.busy === true && mainWindow.busyText !== ""
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
height: 32
|
|
|
|
width: parent.width
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
2023-03-20 14:53:56 +08:00
|
|
|
color: "#88EEEEEE"
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
|
|
|
Text {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: mainWindow.busyText
|
|
|
|
font.pixelSize: 24
|
|
|
|
}
|
|
|
|
}
|
2022-01-24 10:23:08 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
// global popup. it is modal and just lower than toast
|
|
|
|
Rectangle {
|
|
|
|
id: globalPopupDim
|
|
|
|
anchors.fill: parent
|
|
|
|
color: "black"
|
|
|
|
opacity: 0
|
|
|
|
visible: !mainWindow.busy
|
2022-03-27 20:00:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
property bool stateVisible: false
|
|
|
|
states: [
|
2023-02-26 16:51:29 +08:00
|
|
|
State {
|
2022-04-30 15:27:56 +08:00
|
|
|
when: globalPopupDim.stateVisible
|
|
|
|
PropertyChanges { target: globalPopupDim; opacity: 0.5 }
|
|
|
|
},
|
2023-02-26 16:51:29 +08:00
|
|
|
State {
|
2022-04-30 15:27:56 +08:00
|
|
|
when: !globalPopupDim.stateVisible
|
|
|
|
PropertyChanges { target: globalPopupDim; opacity: 0.0 }
|
|
|
|
}
|
|
|
|
]
|
2023-02-26 16:51:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
transitions: Transition {
|
|
|
|
NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
|
2022-03-27 20:00:29 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-03-27 20:00:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
Popup {
|
|
|
|
id: globalPopup
|
|
|
|
property string source: ""
|
|
|
|
modal: true
|
2023-02-26 16:51:29 +08:00
|
|
|
dim: false // cannot animate the dim
|
2022-04-30 15:27:56 +08:00
|
|
|
focus: true
|
|
|
|
opacity: mainWindow.busy ? 0 : 1
|
|
|
|
closePolicy: Popup.CloseOnEscape
|
|
|
|
anchors.centerIn: parent
|
2022-03-27 20:00:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
onAboutToShow: {
|
|
|
|
globalPopupDim.stateVisible = true
|
|
|
|
}
|
2022-03-27 20:00:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
enter: Transition {
|
|
|
|
NumberAnimation { properties: "opacity"; from: 0; to: 1 }
|
|
|
|
NumberAnimation { properties: "scale"; from: 0.4; to: 1 }
|
|
|
|
}
|
2022-03-27 20:00:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
onAboutToHide: {
|
|
|
|
globalPopupDim.stateVisible = false
|
|
|
|
}
|
2022-03-27 20:00:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
exit: Transition {
|
|
|
|
NumberAnimation { properties: "opacity"; from: 1; to: 0 }
|
|
|
|
NumberAnimation { properties: "scale"; from: 1; to: 0.4 }
|
2022-03-27 20:00:29 +08:00
|
|
|
}
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
Loader {
|
|
|
|
visible: !mainWindow.busy
|
|
|
|
source: globalPopup.source === "" ? "" : "GlobalPopups/" + globalPopup.source
|
|
|
|
onSourceChanged: {
|
|
|
|
if (item === null)
|
|
|
|
return;
|
|
|
|
item.finished.connect(() => {
|
|
|
|
globalPopup.close();
|
|
|
|
globalPopup.source = "";
|
|
|
|
});
|
|
|
|
}
|
2022-01-24 10:23:08 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
2023-02-15 19:54:35 +08:00
|
|
|
Popup {
|
|
|
|
id: errDialog
|
|
|
|
property string txt: ""
|
|
|
|
modal: true
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: Math.min(contentWidth + 24, realMainWin.width * 0.9)
|
|
|
|
height: Math.min(contentHeight + 24, realMainWin.height * 0.9)
|
2023-02-15 21:20:40 +08:00
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
2023-02-15 19:54:35 +08:00
|
|
|
padding: 12
|
|
|
|
contentItem: Text {
|
|
|
|
text: errDialog.txt
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
2023-03-18 15:34:42 +08:00
|
|
|
TapHandler {
|
|
|
|
onTapped: errDialog.close();
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
ToastManager {
|
|
|
|
id: toast
|
|
|
|
}
|
2022-01-24 10:23:08 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
Connections {
|
|
|
|
target: Backend
|
|
|
|
function onNotifyUI(command, jsonData) {
|
2023-02-15 19:54:35 +08:00
|
|
|
if (command === "ErrorDialog") {
|
|
|
|
errDialog.txt = jsonData;
|
|
|
|
errDialog.open();
|
|
|
|
return;
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
let cb = callbacks[command]
|
|
|
|
if (typeof(cb) === "function") {
|
|
|
|
cb(jsonData);
|
|
|
|
} else {
|
|
|
|
callbacks["ErrorMsg"]("Unknown command " + command + "!");
|
|
|
|
}
|
2022-01-24 10:23:08 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
2022-05-02 14:00:47 +08:00
|
|
|
|
2022-12-18 12:52:52 +08:00
|
|
|
Shortcut {
|
|
|
|
sequences: [ StandardKey.FullScreen ]
|
|
|
|
onActivated: {
|
|
|
|
if (realMainWin.visibility === Window.FullScreen)
|
|
|
|
realMainWin.showNormal();
|
|
|
|
else
|
|
|
|
realMainWin.showFullScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-20 14:53:56 +08:00
|
|
|
Loader {
|
|
|
|
id: splashLoader
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
|
|
|
|
2022-12-18 12:52:52 +08:00
|
|
|
Component.onCompleted: {
|
2023-02-15 21:20:40 +08:00
|
|
|
if (OS !== "Web") {
|
|
|
|
mainStack.push(init);
|
2023-03-20 14:53:56 +08:00
|
|
|
if (!Debugging) {
|
|
|
|
splashLoader.source = "Splash.qml";
|
|
|
|
splashLoader.item.disappeared.connect(() => {
|
|
|
|
splashLoader.source = "";
|
|
|
|
});
|
|
|
|
}
|
2023-02-15 21:20:40 +08:00
|
|
|
} else {
|
|
|
|
mainStack.push(webinit);
|
|
|
|
}
|
2023-01-03 23:37:14 +08:00
|
|
|
if (OS !== "Android" && OS !== "Web") {
|
2023-02-27 10:23:48 +08:00
|
|
|
x = config.winX;
|
|
|
|
y = config.winY;
|
2022-12-18 12:52:52 +08:00
|
|
|
width = config.winWidth;
|
|
|
|
height = config.winHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-02 14:00:47 +08:00
|
|
|
onClosing: {
|
2022-12-18 12:52:52 +08:00
|
|
|
config.winWidth = width;
|
|
|
|
config.winHeight = height;
|
|
|
|
config.saveConf();
|
2022-05-02 14:00:47 +08:00
|
|
|
Backend.quitLobby();
|
|
|
|
}
|
2022-01-24 10:23:08 +08:00
|
|
|
}
|