2022-09-14 05:01:10 +00:00
|
|
|
import QtQuick
|
|
|
|
import Qt.labs.folderlistmodel
|
2022-04-14 10:22:00 +00:00
|
|
|
import "../skin-bank.js" as SkinBank
|
|
|
|
|
|
|
|
Item {
|
2022-04-30 07:27:56 +00:00
|
|
|
property string source: ""
|
|
|
|
property int currentFrame: 0
|
|
|
|
property alias interval: timer.interval
|
|
|
|
property int loadedFrameCount: 0
|
|
|
|
property bool autoStart: false
|
|
|
|
property bool loop: false
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
signal loaded()
|
|
|
|
signal started()
|
|
|
|
signal finished()
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
id: root
|
|
|
|
width: childrenRect.width
|
|
|
|
height: childrenRect.height
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
FolderListModel {
|
|
|
|
id: fileModel
|
|
|
|
folder: SkinBank.PIXANIM_DIR + source
|
|
|
|
nameFilters: ["*.png"]
|
|
|
|
showDirs: false
|
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Repeater {
|
|
|
|
id: frames
|
|
|
|
model: fileModel
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Image {
|
|
|
|
source: SkinBank.PIXANIM_DIR + root.source + "/" + index
|
|
|
|
visible: false
|
|
|
|
onStatusChanged: {
|
|
|
|
if (status == Image.Ready) {
|
|
|
|
loadedFrameCount++;
|
|
|
|
if (loadedFrameCount == fileModel.count)
|
|
|
|
root.loaded();
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
onLoaded: {
|
|
|
|
if (autoStart)
|
|
|
|
timer.start();
|
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
interval: 50
|
|
|
|
repeat: true
|
|
|
|
onTriggered: {
|
|
|
|
if (currentFrame >= fileModel.count) {
|
|
|
|
frames.itemAt(fileModel.count - 1).visible = false;
|
|
|
|
if (loop) {
|
|
|
|
currentFrame = 0;
|
|
|
|
} else {
|
|
|
|
timer.stop();
|
|
|
|
root.finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (currentFrame > 0)
|
|
|
|
frames.itemAt(currentFrame - 1).visible = false;
|
|
|
|
frames.itemAt(currentFrame).visible = true;
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
currentFrame++;
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function start()
|
|
|
|
{
|
|
|
|
if (loadedFrameCount == fileModel.count) {
|
|
|
|
timer.start();
|
|
|
|
} else {
|
|
|
|
root.loaded.connect(function(){
|
|
|
|
timer.start();
|
|
|
|
});
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function stop()
|
|
|
|
{
|
|
|
|
timer.stop();
|
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|