FreeKill/qml/Pages/Danmaku.qml
notify 0e51614588
Observer chat (#125)
新增旁观者聊天栏兼公告栏
增加服务端广播消息功能
修复单机启动失败时被心跳包卡死机的情况
修复发配音时undefined
聊天信息服务端回显
2023-04-18 23:26:15 +08:00

80 lines
1.6 KiB
QML

import QtQuick
Item {
id: root
width: 900
height: 20
visible: false
property bool newTxtAvailable: true
property var stashedTxt: []
property int currentRunning: 0
onNewTxtAvailableChanged: {
if (!newTxtAvailable || stashedTxt.length === 0) {
return;
}
let t = stashedTxt.splice(0, 1)[0];
let obj = txtComponent.createObject(root, { text: t });
obj.finished.connect(() => obj.destroy());
obj.start();
}
onCurrentRunningChanged: {
visible = !!currentRunning;
}
Rectangle {
anchors.fill: parent
color: "black"
opacity: 0.7
}
Component {
id: txtComponent
Text {
id: txt
color: "white"
font.pixelSize: 18
font.family: fontLibian.name
textFormat: TextEdit.RichText
y: -1
property bool changedAvail: false
signal finished()
onXChanged: {
if (root.width - x - 40 > width && !changedAvail) {
root.newTxtAvailable = true;
changedAvail = true;
}
}
PropertyAnimation on x {
id: txtAnim
running: false
from: root.width
to: -txt.width
duration: (root.width + txt.width) * 5
onFinished: {
root.currentRunning--;
txt.finished();
}
}
function start() {
root.newTxtAvailable = false;
root.currentRunning++;
txtAnim.start();
}
}
}
function sendLog(txt) {
root.stashedTxt.push(txt);
if (root.newTxtAvailable) {
root.newTxtAvailable = false;
root.newTxtAvailable = true;
}
}
}