增加预览页介绍信息显示

This commit is contained in:
2026-04-08 09:56:25 +08:00
parent f53fee8e5a
commit 028ed1b18d
17 changed files with 1059 additions and 23 deletions

View File

@@ -30,6 +30,36 @@ void sortByFrame(QVector<Project::Entity::ImageFrame>& v) {
std::sort(v.begin(), v.end(), [](const auto& a, const auto& b) { return a.frame < b.frame; });
}
void writeIntroBlock(QDataStream& ds, const Project::Entity& entity) {
ds << entity.intro.title << entity.intro.bodyText;
ds << qint32(entity.intro.imagePathsRelative.size());
for (const auto& p : entity.intro.imagePathsRelative) {
ds << p;
}
ds << entity.intro.videoPathRelative;
}
bool readIntroBlock(QDataStream& ds, EntityIntroContent& intro) {
ds >> intro.title >> intro.bodyText;
qint32 n = 0;
ds >> n;
if (ds.status() != QDataStream::Ok || n < 0 || n > 2048) {
return false;
}
intro.imagePathsRelative.clear();
intro.imagePathsRelative.reserve(n);
for (qint32 i = 0; i < n; ++i) {
QString p;
ds >> p;
if (ds.status() != QDataStream::Ok) {
return false;
}
intro.imagePathsRelative.push_back(std::move(p));
}
ds >> intro.videoPathRelative;
return ds.status() == QDataStream::Ok;
}
bool readAnimationBlock(QDataStream& ds, Project::Entity& out, bool hasUserScaleKeys) {
out.locationKeys.clear();
out.depthScaleKeys.clear();
@@ -220,7 +250,8 @@ public:
}
writeAnimationBlock(ds, entity, true);
ds << entity.displayName << double(entity.userScale);
ds << entity.displayName << double(entity.userScale) << double(entity.distanceScaleCalibMult);
writeIntroBlock(ds, entity);
}
bool readBody(QDataStream& ds) override {
@@ -231,12 +262,17 @@ public:
}
QString dn;
double us = 1.0;
ds >> dn >> us;
double cal = 0.0;
ds >> dn >> us >> cal;
if (ds.status() != QDataStream::Ok) {
return false;
}
tmp.displayName = dn;
tmp.userScale = std::clamp(us, 1e-3, 1e3);
tmp.distanceScaleCalibMult = (cal > 0.0) ? std::clamp(cal, 1e-6, 10.0) : 0.0;
if (!readIntroBlock(ds, tmp.intro)) {
return false;
}
*m_dst = std::move(tmp);
return true;
}
@@ -293,7 +329,7 @@ bool EntityPayloadBinary::load(const QString& absolutePath, Project::Entity& ent
if (ds.status() != QDataStream::Ok || magic != kMagicPayload) {
return false;
}
if (ver != 1 && ver != 2 && ver != 3) {
if (ver != 1 && ver != 2 && ver != 3 && ver != 4 && ver != 5) {
return false;
}
Project::Entity tmp;
@@ -309,6 +345,19 @@ bool EntityPayloadBinary::load(const QString& absolutePath, Project::Entity& ent
}
tmp.displayName = dn;
tmp.userScale = std::clamp(us, 1e-3, 1e3);
if (ver >= 4) {
double cal = 0.0;
ds >> cal;
if (ds.status() != QDataStream::Ok) {
return false;
}
tmp.distanceScaleCalibMult = (cal > 0.0) ? std::clamp(cal, 1e-6, 10.0) : 0.0;
}
if (ver >= 5) {
if (!readIntroBlock(ds, tmp.intro)) {
return false;
}
}
} else {
tmp.displayName.clear();
tmp.userScale = 1.0;

View File

@@ -12,7 +12,7 @@ namespace core {
class EntityPayloadBinary {
public:
static constexpr quint32 kMagicPayload = 0x48464550; // 'HFEP'
static constexpr quint32 kPayloadVersion = 3; // v3:追加 userScaleKeys动画轨道
static constexpr quint32 kPayloadVersion = 5; // v5:追加 intro预览介绍标题/正文/配图/视频路径预留
// 旧版独立动画文件(仍用于打开 v1 项目时合并)
static constexpr quint32 kMagicLegacyAnim = 0x48465441; // 'HFTA'