2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Window
|
2022-03-23 11:40:28 +00:00
|
|
|
import "Logic.js" as Logic
|
2023-05-19 02:08:36 +00:00
|
|
|
import Fk.Pages
|
2022-01-24 02:23:08 +00:00
|
|
|
|
|
|
|
Window {
|
2022-12-18 04:52:52 +00:00
|
|
|
id: realMainWin
|
2022-04-30 07:27:56 +00:00
|
|
|
visible: true
|
2022-09-14 05:01:10 +00:00
|
|
|
width: 960
|
|
|
|
height: 540
|
2023-02-15 13:20:40 +00:00
|
|
|
minimumWidth: 160
|
|
|
|
minimumHeight: 90
|
2023-04-21 12:57:03 +00:00
|
|
|
title: "FreeKill v" + FkVersion
|
2022-04-30 07:27:56 +00:00
|
|
|
property var callbacks: Logic.callbacks
|
2023-05-18 23:45:21 +00:00
|
|
|
property var tipList: []
|
2022-01-24 02:23:08 +00:00
|
|
|
|
2022-09-14 05:01:10 +00: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
|
2023-04-27 06:15:08 +00:00
|
|
|
property bool is_pending: false
|
|
|
|
property var pending_message: []
|
2022-09-14 05:01:10 +00:00
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
Config {
|
|
|
|
id: config
|
|
|
|
}
|
|
|
|
|
2022-05-01 10:37:13 +00:00
|
|
|
Image {
|
2023-02-15 11:54:35 +00:00
|
|
|
source: config.lobbyBg
|
2022-05-01 10:37:13 +00: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 07:27:56 +00:00
|
|
|
StackView {
|
|
|
|
id: mainStack
|
|
|
|
visible: !mainWindow.busy
|
2023-02-15 13:20:40 +00:00
|
|
|
// If error occurs during loading initialItem, the program will fall into "polish()" loop
|
2023-05-19 02:08:36 +00:00
|
|
|
// initialItem: init
|
2022-04-30 07:27:56 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
}
|
2022-01-24 02:23:08 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Component { id: init; Init {} }
|
2023-02-15 11:54:35 +00:00
|
|
|
Component { id: packageManage; PackageManage {} }
|
2022-04-30 07:27:56 +00:00
|
|
|
Component { id: lobby; Lobby {} }
|
|
|
|
Component { id: generalsOverview; GeneralsOverview {} }
|
|
|
|
Component { id: cardsOverview; CardsOverview {} }
|
2023-03-20 06:53:56 +00:00
|
|
|
Component { id: modesOverview; ModesOverview {} }
|
2022-04-30 07:27:56 +00:00
|
|
|
Component { id: room; Room {} }
|
2023-01-12 14:53:22 +00:00
|
|
|
Component { id: aboutPage; About {} }
|
2022-03-01 05:18:00 +00:00
|
|
|
|
2022-05-01 10:37:13 +00:00
|
|
|
property var generalsOverviewPage
|
|
|
|
property var cardsOverviewPage
|
2023-03-20 06:53:56 +00:00
|
|
|
property alias modesOverviewPage: modesOverview
|
2023-01-12 14:53:22 +00:00
|
|
|
property alias aboutPage: aboutPage
|
2022-04-30 07:27:56 +00:00
|
|
|
property bool busy: false
|
2023-02-15 11:54:35 +00:00
|
|
|
property string busyText: ""
|
|
|
|
onBusyChanged: busyText = "";
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
BusyIndicator {
|
2023-05-18 23:45:21 +00:00
|
|
|
id: busyIndicator
|
2022-04-30 07:27:56 +00:00
|
|
|
running: true
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: mainWindow.busy === true
|
|
|
|
}
|
2023-05-18 23:45:21 +00:00
|
|
|
|
|
|
|
Text {
|
|
|
|
anchors.top: busyIndicator.bottom
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.topMargin: 8
|
|
|
|
visible: mainWindow.busy === true
|
|
|
|
|
|
|
|
property int idx: 1
|
|
|
|
text: tipList[idx - 1] ?? ""
|
|
|
|
color: "#F0E5DA"
|
|
|
|
font.pixelSize: 20
|
|
|
|
font.family: fontLibian.name
|
|
|
|
style: Text.Outline
|
|
|
|
styleColor: "#3D2D1C"
|
|
|
|
textFormat: Text.RichText
|
|
|
|
width: parent.width * 0.7
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
wrapMode: Text.WrapAnywhere
|
|
|
|
|
|
|
|
onVisibleChanged: idx = 0;
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
running: parent.visible
|
|
|
|
interval: 3600
|
|
|
|
repeat: true
|
|
|
|
onTriggered: {
|
|
|
|
const oldIdx = parent.idx;
|
|
|
|
while (parent.idx === oldIdx) {
|
|
|
|
parent.idx = Math.floor(Math.random() * tipList.length) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 11:54:35 +00:00
|
|
|
Item {
|
|
|
|
visible: mainWindow.busy === true && mainWindow.busyText !== ""
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
height: 32
|
|
|
|
width: parent.width
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
2023-03-20 06:53:56 +00:00
|
|
|
color: "#88EEEEEE"
|
2023-02-15 11:54:35 +00:00
|
|
|
}
|
|
|
|
Text {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: mainWindow.busyText
|
|
|
|
font.pixelSize: 24
|
|
|
|
}
|
|
|
|
}
|
2022-01-24 02:23:08 +00:00
|
|
|
|
2023-02-15 11:54:35 +00: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 13:20:40 +00:00
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
2023-02-15 11:54:35 +00:00
|
|
|
padding: 12
|
|
|
|
contentItem: Text {
|
|
|
|
text: errDialog.txt
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
2023-03-18 07:34:42 +00:00
|
|
|
TapHandler {
|
|
|
|
onTapped: errDialog.close();
|
2023-02-15 11:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
ToastManager {
|
|
|
|
id: toast
|
|
|
|
}
|
2022-01-24 02:23:08 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Connections {
|
|
|
|
target: Backend
|
|
|
|
function onNotifyUI(command, jsonData) {
|
2023-02-15 11:54:35 +00:00
|
|
|
if (command === "ErrorDialog") {
|
|
|
|
errDialog.txt = jsonData;
|
|
|
|
errDialog.open();
|
|
|
|
return;
|
|
|
|
}
|
2023-04-27 06:15:08 +00:00
|
|
|
if (mainWindow.is_pending && command !== "ChangeSelf") {
|
|
|
|
mainWindow.pending_message.push({ command: command, jsonData: jsonData });
|
2022-04-30 07:27:56 +00:00
|
|
|
} else {
|
2023-04-27 06:15:08 +00:00
|
|
|
if (command === "StartChangeSelf") {
|
|
|
|
mainWindow.is_pending = true;
|
|
|
|
}
|
|
|
|
mainWindow.handleMessage(command, jsonData);
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2023-04-27 06:15:08 +00:00
|
|
|
|
|
|
|
function fetchMessage() {
|
|
|
|
let ret = pending_message.splice(0, 1)[0];
|
|
|
|
if (pending_message.length === 0) {
|
|
|
|
is_pending = false;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleMessage(command, jsonData) {
|
|
|
|
let cb = callbacks[command]
|
|
|
|
if (typeof(cb) === "function") {
|
|
|
|
cb(jsonData);
|
|
|
|
} else {
|
|
|
|
callbacks["ErrorMsg"]("Unknown command " + command + "!");
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 05:01:10 +00:00
|
|
|
}
|
2022-05-02 06:00:47 +00:00
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
Shortcut {
|
|
|
|
sequences: [ StandardKey.FullScreen ]
|
|
|
|
onActivated: {
|
|
|
|
if (realMainWin.visibility === Window.FullScreen)
|
|
|
|
realMainWin.showNormal();
|
|
|
|
else
|
|
|
|
realMainWin.showFullScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:53:56 +00:00
|
|
|
Loader {
|
|
|
|
id: splashLoader
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
Component.onCompleted: {
|
2023-05-19 02:08:36 +00:00
|
|
|
mainStack.push(init);
|
|
|
|
if (!Debugging) {
|
|
|
|
splashLoader.source = "Splash.qml";
|
|
|
|
splashLoader.item.disappeared.connect(() => {
|
|
|
|
splashLoader.source = "";
|
|
|
|
});
|
2023-02-15 13:20:40 +00:00
|
|
|
}
|
2023-01-03 15:37:14 +00:00
|
|
|
if (OS !== "Android" && OS !== "Web") {
|
2023-02-27 02:23:48 +00:00
|
|
|
x = config.winX;
|
|
|
|
y = config.winY;
|
2022-12-18 04:52:52 +00:00
|
|
|
width = config.winWidth;
|
|
|
|
height = config.winHeight;
|
|
|
|
}
|
2023-05-18 23:45:21 +00:00
|
|
|
|
|
|
|
const tips = Backend.loadTips();
|
|
|
|
tipList = tips.trim().split("\n");
|
2022-12-18 04:52:52 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 06:00:47 +00:00
|
|
|
onClosing: {
|
2022-12-18 04:52:52 +00:00
|
|
|
config.winWidth = width;
|
|
|
|
config.winHeight = height;
|
|
|
|
config.saveConf();
|
2023-05-19 15:03:39 +00:00
|
|
|
Backend.quitLobby(false);
|
2022-05-02 06:00:47 +00:00
|
|
|
}
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|