feat(saves): 截图缩略图墙(M251 · D54 全套:解码/缓存/上限/可见失败)
按 D54 落地,解码在 palette-extract、缓存在 presenter、像素随快照走、壳层只画。
palette-extract(上一提交)→ presenter:
- dto/saves/preview.rs:ScreenshotPreview{NotGenerated,Ready,Failed} + ThumbnailView
(带 is_consistent:长度 ≠ w×h×4 的像素不许进渲染器)+ ScreenshotThumbKind;
ScreenshotView 新增 preview 字段(像素不落盘,随 IPC 面走);
- host/saves/thumbs.rs:attach() 在后台线程(spawn_list 同一条线程)按 mtime 倒序解前
60 张、单张 >8 MiB 先查大小不进解码器、失败也逐条带原因;进程级 memo 键 =
(路径, mtime, 大小),覆盖/替换都会重解;超过 240 条只留本拍碰到的键;
- presenter 新增依赖 unlucky-palette-extract(塔已批,方向 presenter → palette-extract)。
app-iced:
- saves.rs 拆成 model / rows / wall(原文件 385 行,加完墙必破 400):model 里建一次
iced Handle(渲染回调零解码、零重复上传),wall 3 列排格子,没像素的格子给
160×90 占位框 + 逐条原因;text.rs 拆出 text/saves.rs 承载存档/截图一族文案;
- i18n 加 4 条「这一格为什么没有图」(未生成/太大/读不出/解不出)+ 金表同步;
- 出图夹具(saves_shot)合成两种场景的像素,并摆出四种格子(真图×2/未生成/超限失败)。
用例:presenter 9 条(含缓存命中不重解、mtime 变了必重解、第 61 张不解、
>8MiB 不进解码器、缓存有界)+ app-iced 3 条(三种格子的副文案、坏像素降级)。
This commit is contained in:
1 parent
798bfb279b
commit
843f6d08f9
21 files changed
+1519
-360
No files matched your search
@@ -46,17 +46,23 @@ const OLDEST: u64 = NEWEST - 42 * 24 * 3_600_000;
|
||||
/// 其中一个世界/一张截图的 mtime 是 `None`:那是「时间未知」这条分支的唯一出图证据。
|
||||
#[must_use]
|
||||
pub fn view(instance: &str) -> unlucky_presenter::dto::SavesListView {
|
||||
use unlucky_presenter::dto::{SavesListView, ScreenshotView, WorldView};
|
||||
use unlucky_presenter::dto::{
|
||||
SavesListView, ScreenshotPreview, ScreenshotThumbFailure, ScreenshotThumbKind,
|
||||
ScreenshotView, WorldView,
|
||||
};
|
||||
|
||||
let world = |dir: &str, icon: bool, modified_ms: Option<u64>| WorldView {
|
||||
dir: dir.to_string(),
|
||||
icon,
|
||||
modified_ms,
|
||||
};
|
||||
let shot = |file: &str, bytes: u64, modified_ms: Option<u64>| ScreenshotView {
|
||||
file: file.to_string(),
|
||||
bytes,
|
||||
modified_ms,
|
||||
let shot = |file: &str, bytes: u64, modified_ms: Option<u64>, preview: ScreenshotPreview| {
|
||||
ScreenshotView {
|
||||
file: file.to_string(),
|
||||
bytes,
|
||||
modified_ms,
|
||||
preview,
|
||||
}
|
||||
};
|
||||
|
||||
SavesListView {
|
||||
@@ -71,10 +77,38 @@ pub fn view(instance: &str) -> unlucky_presenter::dto::SavesListView {
|
||||
],
|
||||
screenshots_dir: "D:/ULL/.ULL/data/instances/Better-MC/screenshots".to_string(),
|
||||
screenshots_exists: true,
|
||||
// 四张截图,把缩略图墙的**四种格子**一次摆出来(M251):
|
||||
// ① 白天(真像素)② 黄昏(真像素)③ 「未生成预览」占位 ④ 具名的失败原因。
|
||||
// 像素是**合成的**(下面 `scene`):夹具不连真实解码器,出图只证明墙的排版与状态,
|
||||
// 解码由 presenter 的 `host::saves::thumbs` 用例用真 PNG 钉住。
|
||||
screenshots: vec![
|
||||
shot("2024-05-01_10.00.00.png", 1_887_436, Some(NEWEST)),
|
||||
shot("2024-04-30_21.14.05.png", 2_097_152, Some(MIDDLE)),
|
||||
shot("2024-04-20_08.30.00.png", 964_608, None),
|
||||
shot(
|
||||
"2024-05-01_10.00.00.png",
|
||||
1_887_436,
|
||||
Some(NEWEST),
|
||||
ScreenshotPreview::Ready(scene(1)),
|
||||
),
|
||||
shot(
|
||||
"2024-04-30_21.14.05.png",
|
||||
2_097_152,
|
||||
Some(MIDDLE),
|
||||
ScreenshotPreview::Ready(scene(2)),
|
||||
),
|
||||
shot(
|
||||
"2024-04-20_08.30.00.png",
|
||||
964_608,
|
||||
None,
|
||||
ScreenshotPreview::NotGenerated,
|
||||
),
|
||||
shot(
|
||||
"2024-04-11_19.02.41.png",
|
||||
9_437_184,
|
||||
Some(OLDEST),
|
||||
ScreenshotPreview::Failed(ScreenshotThumbFailure {
|
||||
kind: ScreenshotThumbKind::TooLarge,
|
||||
detail: "9437184 > 8388608 字节".to_string(),
|
||||
}),
|
||||
),
|
||||
],
|
||||
skipped: Vec::new(),
|
||||
// 出图夹具不造回执:默认那一张就是「刚列完目录」的样子。
|
||||
@@ -165,3 +199,55 @@ pub fn seed(app: &mut crate::app::state::App, instance: &str) {
|
||||
Mode::Plain | Mode::BackedUp => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// 一张**合成的**缩略图(160×90 RGBA):天空渐变 + 地面 + 太阳/月亮。
|
||||
///
|
||||
/// 为什么合成而不是读真图:夹具的职责是「让页面有东西可画」,而它跑在截图通道的第 3 帧——
|
||||
/// 真解码要真的有一张 PNG 在盘上、还要等后台线程回来。合成像素让出图**确定**(两张主题图
|
||||
/// 逐像素可比),并且明确地不假装自己是解码证据(那由 presenter 的用例负责)。
|
||||
///
|
||||
/// `tone`:`1` = 白天(亮天空 + 绿地面),其余 = 黄昏(橙天空 + 暗地面)。同一套几何,
|
||||
/// 两种配色——墙上两格一眼能看出"每格各画各的"。
|
||||
fn scene(tone: u8) -> unlucky_presenter::dto::ThumbnailView {
|
||||
const W: u32 = 160;
|
||||
const H: u32 = 90;
|
||||
// 地平线在 2/3 高度(截图里天空总比地面多)。
|
||||
const HORIZON: u32 = H * 2 / 3;
|
||||
let (sky_top, sky_bottom, ground, sun): ([u8; 3], [u8; 3], [u8; 3], [u8; 3]) = if tone == 1 {
|
||||
([128, 176, 240], [200, 224, 248], [86, 138, 66], [255, 246, 186])
|
||||
} else {
|
||||
([96, 66, 96], [232, 148, 96], [58, 74, 48], [255, 214, 150])
|
||||
};
|
||||
let mut pixels = Vec::with_capacity((W * H * 4) as usize);
|
||||
for y in 0..H {
|
||||
for x in 0..W {
|
||||
let (r, g, b) = if y < HORIZON {
|
||||
// 天空:从顶到底线性插值(`t` = 0..=255 的定点比例)。
|
||||
let t = y * 255 / HORIZON.max(1);
|
||||
let mix = |from: u8, to: u8| -> u8 {
|
||||
let span = i32::from(to) - i32::from(from);
|
||||
(i32::from(from) + span * t as i32 / 255) as u8
|
||||
};
|
||||
(mix(sky_top[0], sky_bottom[0]), mix(sky_top[1], sky_bottom[1]), mix(sky_top[2], sky_bottom[2]))
|
||||
} else {
|
||||
// 地面:按 3px 一条的条纹给出「方块地形」的观感。
|
||||
let stripe = (y / 3) % 2 == 0;
|
||||
let shade: u8 = if stripe { 0 } else { 14 };
|
||||
(ground[0].saturating_sub(shade), ground[1].saturating_sub(shade), ground[2].saturating_sub(shade))
|
||||
};
|
||||
// 太阳/月亮:右上角一个 18px 的圆(够小,不会盖住画面主体)。
|
||||
let (dx, dy) = (x as i32 - 126, y as i32 - 26);
|
||||
let (r, g, b) = if dx * dx + dy * dy <= 18 * 18 {
|
||||
(sun[0], sun[1], sun[2])
|
||||
} else {
|
||||
(r, g, b)
|
||||
};
|
||||
pixels.extend_from_slice(&[r, g, b, 255]);
|
||||
}
|
||||
}
|
||||
unlucky_presenter::dto::ThumbnailView {
|
||||
width: W,
|
||||
height: H,
|
||||
pixels,
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,20 @@
|
||||
//!
|
||||
//! 写操作**成功**也有一句话([`Saves::notice`]):重命名 / 删除的结果列表上看得见,但备份的落点
|
||||
//! 看不见——「点了备份然后什么也没发生」是静默失败,所以回执里带上完整路径与字节数。
|
||||
//!
|
||||
//! # 截图区是**缩略图墙**(M251 · SAVESHOTS,D54)
|
||||
//!
|
||||
//! | 变化 | 落点 |
|
||||
//! |---|---|
|
||||
//! | 截图不再是一行字,而是「图 + 副文案」的格子 | [`wall`](3 列,见那个模块的文档) |
|
||||
//! | 像素**不在**这里解,也不在渲染回调里解 | presenter 的后台线程(`host::saves::thumbs`)解好、随快照过来;本层只把 `Handle` 建一次(`model::from_state`) |
|
||||
//! | 没有像素的格子**不许留白** | 占位框 + 一句短话;副文案把原因说全(超 8 MiB / 读不出 / 解不出 / 超 60 张预算) |
|
||||
//!
|
||||
//! ## 为什么拆成三个文件
|
||||
//!
|
||||
//! 加完缩略图墙之后 `saves.rs` 会越过 400 行硬线:模型([`model`])、行与操作区([`rows`])、
|
||||
//! 墙([`wall`])各占一块,本文件只剩「卡片骨架 + 小标 + 空态 + 错误行」。
|
||||
//! 路径不变([`model`] 的东西用 `pub use` 转出),`view/instances.rs` 与用例的 import 一行不改。
|
||||
|
||||
use iced::widget::{column, container, row};
|
||||
use iced::{Alignment, Element, Length};
|
||||
@@ -58,9 +72,6 @@ use iced::{Alignment, Element, Length};
|
||||
use unlucky_design::color::Role;
|
||||
use unlucky_design::spacing::Space;
|
||||
use unlucky_design::typography::TypeRole;
|
||||
use unlucky_i18n::Catalog;
|
||||
use unlucky_presenter::dto::{SavesFailureKind, SavesFailureOp, SavesFailureView};
|
||||
use unlucky_presenter::state::SavesState;
|
||||
|
||||
use crate::app::components::buttons::{self, Button};
|
||||
use crate::app::components::interaction::Interaction;
|
||||
@@ -72,158 +83,18 @@ use super::forced_state;
|
||||
use super::state::Message as PageMessage;
|
||||
use super::Texts;
|
||||
|
||||
mod model;
|
||||
mod rows;
|
||||
/// 写操作成功那句话的产地(实现在 [`rows`] 里,页面与测试都从这一条路取)。
|
||||
mod wall;
|
||||
|
||||
pub use model::{failure_line, from_state, Row, Saves, Shot, ShotPreview};
|
||||
/// 写操作成功那句话的产地(实现在 [`rows`] 里)。
|
||||
///
|
||||
/// 生产代码走 `model::from_state → rows::op_line`;这条 re-export 只给**用例**用
|
||||
/// (`tests/saves/write.rs` 从这里取),所以挂在 `cfg(test)` 下,免得非测试构建报未用导入。
|
||||
#[cfg(test)]
|
||||
pub(super) use rows::op_line;
|
||||
|
||||
/// 列表里的一行(一个世界 / 一张截图)。
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Row {
|
||||
/// 世界目录名或截图文件名(磁盘原样;写操作把它原样带回去当「源」)。
|
||||
pub name: String,
|
||||
/// 右侧/下方副文案(时间、大小、图标标记,已由这一层拼好)。
|
||||
pub detail: String,
|
||||
}
|
||||
|
||||
/// 正在行内重命名的那一行(来源是 presenter 的 `SavesState::draft`)。
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Editing {
|
||||
/// 哪个世界。
|
||||
pub dir: String,
|
||||
/// 输入框里的内容(原样)。
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
/// SAVES 区的展示模型(`Model::saves`)。
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct Saves {
|
||||
/// 这份数据属于哪个实例(`None` = 不在详情页 / 还没请求过)。
|
||||
pub bound: Option<String>,
|
||||
/// 正在读盘(进详情页首帧:请求已发出、快照还没回来)。
|
||||
pub loading: bool,
|
||||
/// 读盘/打开/写操作失败的人读原因(app 层按 i18n 拼好)。
|
||||
pub error: Option<String>,
|
||||
/// 这一条失败能不能靠「再列一次」解决(只有读盘失败算)。
|
||||
pub retryable: bool,
|
||||
/// 手里有没有一份**快照**(`false` = 只拿到了失败,"还没有世界"那几句不许画)。
|
||||
pub has_view: bool,
|
||||
/// 两个目录都不存在(新实例的常态:还没进过游戏)。
|
||||
pub missing: bool,
|
||||
/// 世界行。
|
||||
pub worlds: Vec<Row>,
|
||||
/// 截图行(新的在前,顺序由 core 给)。
|
||||
pub screenshots: Vec<Row>,
|
||||
/// 计数行(`3 个世界 · 12 张截图`):**在这一层算好**,页面只借 `&str`。
|
||||
///
|
||||
/// 为什么不留到页面里 `format!`:iced 的 `Element` 只借这一帧的数据,页面函数返回的是
|
||||
/// **借用局部变量的树**,局部 `String` 一出栈就悬空(`E0515`)。与 [`super::mods::Mods`]
|
||||
/// 的 `count` 同一条做法。
|
||||
pub count: String,
|
||||
/// 跳过条目数(符号链接 / 非图片 / 读不出)。
|
||||
pub skipped: usize,
|
||||
/// 跳过提示(`跳过 3 项`)。
|
||||
pub skipped_note: String,
|
||||
/// 正在行内重命名的那一行(`None` = 没有在改名)。
|
||||
pub editing: Option<Editing>,
|
||||
/// 有写操作在飞的那个世界(`None` = 空闲)。
|
||||
pub busy: Option<String>,
|
||||
/// 上一次写操作成功的那句话(`None` = 这一拍没有回执)。
|
||||
pub notice: Option<String>,
|
||||
}
|
||||
|
||||
impl Saves {
|
||||
/// 有没有拿到一份快照(成功或失败都算;`loading` 中不算)。
|
||||
#[must_use]
|
||||
pub fn loaded(&self) -> bool {
|
||||
self.bound.is_some() && !self.loading
|
||||
}
|
||||
|
||||
/// 两个目录都在、但里面什么都没有(**必须先有一份快照**:纯失败态不是"这里空的")。
|
||||
#[must_use]
|
||||
pub fn nothing_yet(&self) -> bool {
|
||||
self.has_view && !self.missing && self.worlds.is_empty() && self.screenshots.is_empty()
|
||||
}
|
||||
|
||||
/// 这个世界的写操作在飞吗(那一行画「正在处理…」并把按钮拿掉)。
|
||||
#[must_use]
|
||||
pub fn busy_with(&self, dir: &str) -> bool {
|
||||
self.busy.as_deref() == Some(dir)
|
||||
}
|
||||
}
|
||||
|
||||
/// presenter 的视图态 → 页面要画的东西(**唯一**的转换点,`app/view/instances.rs` 调)。
|
||||
///
|
||||
/// 三条口径:
|
||||
///
|
||||
/// 1. **失败不清列表**:list 失败时保留上一份 `worlds`/`screenshots`(用户还能看见旧列表,
|
||||
/// 只是多一条红字),只有"从来没有过快照"时才是一条纯错误态;
|
||||
/// 2. **不做乐观更新**:行上的名字只来自快照,写操作的"在飞"只用来置灰那一行;
|
||||
/// 3. **回执只画一次**:`view.last_op` 是 host 写在快照里的,下一次普通 List 就没了。
|
||||
#[must_use]
|
||||
pub fn from_state(state: &SavesState, catalog: Catalog) -> Saves {
|
||||
let texts = Texts::of(catalog);
|
||||
let mut out = Saves {
|
||||
bound: state.bound.clone(),
|
||||
loading: state.bound.is_some() && state.view.is_none() && state.failed.is_none(),
|
||||
editing: state.draft.as_ref().map(|draft| Editing {
|
||||
dir: draft.dir.clone(),
|
||||
text: draft.text.clone(),
|
||||
}),
|
||||
busy: state.pending.as_ref().map(|op| op.dir().to_string()),
|
||||
..Saves::default()
|
||||
};
|
||||
if let Some(view) = &state.view {
|
||||
out.has_view = true;
|
||||
out.missing = !view.exists && !view.screenshots_exists;
|
||||
// 计数直接问快照(`view.world_count()`),不从刚装好的 `out.worlds` 再数一遍——
|
||||
// M224 出图实测过"先算计数后装列表"画出 `0 启用 · 0 禁用` 的那种顺序错,这里从根上绕开。
|
||||
out.worlds = view
|
||||
.worlds
|
||||
.iter()
|
||||
.map(|world| Row {
|
||||
name: world.dir.clone(),
|
||||
detail: rows::world_detail(world.icon, world.modified_ms, texts),
|
||||
})
|
||||
.collect();
|
||||
out.screenshots = view
|
||||
.screenshots
|
||||
.iter()
|
||||
.map(|shot| Row {
|
||||
name: shot.file.clone(),
|
||||
detail: rows::shot_detail(shot.bytes, shot.modified_ms, texts),
|
||||
})
|
||||
.collect();
|
||||
out.count = texts.saves_count(view.world_count(), view.screenshot_count());
|
||||
out.skipped = view.skipped_count();
|
||||
out.skipped_note = texts.saves_skipped(out.skipped);
|
||||
out.notice = view.last_op.as_ref().map(|op| op_line(op, texts));
|
||||
}
|
||||
if let Some(failure) = &state.failed {
|
||||
out.loading = false;
|
||||
out.error = Some(failure_line(failure, texts));
|
||||
// 只有「读盘 / 列目录」失败才值得重试;写操作的重试就是再点一次那个按钮。
|
||||
out.retryable = failure.op.is_none() && failure.kind != SavesFailureKind::OpenFailed;
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// 失败的一句话(**唯一产地**:页面内红字用它,本版没有 Toast)。
|
||||
#[must_use]
|
||||
pub fn failure_line(failure: &SavesFailureView, texts: Texts) -> String {
|
||||
let reason = texts.saves_reason(failure.kind);
|
||||
let sentence = match (failure.op, failure.kind) {
|
||||
(Some(SavesFailureOp::Rename), _) => texts.saves_rename_failed(&failure.file, reason),
|
||||
(Some(SavesFailureOp::Delete), _) => texts.saves_delete_failed(&failure.file, reason),
|
||||
(Some(SavesFailureOp::Backup), _) => texts.saves_backup_failed(&failure.file, reason),
|
||||
(None, SavesFailureKind::OpenFailed) => texts.saves_open_failed(reason),
|
||||
(None, _) => texts.saves_failed(reason),
|
||||
};
|
||||
if failure.detail.is_empty() {
|
||||
return sentence;
|
||||
}
|
||||
format!("{sentence}({})", failure.detail)
|
||||
}
|
||||
|
||||
/// 画 SAVES 区(实例页唯一入口,`detail.rs` 调它)。
|
||||
pub(super) fn section<'a>(
|
||||
ui: &'a Ui,
|
||||
@@ -293,9 +164,8 @@ pub(super) fn section<'a>(
|
||||
if saves.screenshots.is_empty() {
|
||||
body = body.push(note(ui, texts.saves_no_screenshots()));
|
||||
} else {
|
||||
for item in &saves.screenshots {
|
||||
body = body.push(rows::world_plain(ui, item));
|
||||
}
|
||||
// 缩略图墙(M251):一行三格,没像素的格子给占位框 + 原因,不留白。
|
||||
body = body.push(wall::grid(ui, &saves.screenshots));
|
||||
}
|
||||
if saves.skipped > 0 {
|
||||
body = body.push(note(ui, &saves.skipped_note));
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
//! SAVES 区的**视图模型**:快照 → 页面要画的东西(M235 的行 + M251 的缩略图墙)。
|
||||
//!
|
||||
//! 从 `saves.rs` 拆出(M251:加完缩略图墙的模型之后那个文件会越过 400 行硬线)。
|
||||
//! 拆法是「**纯搬移 + 一族新增**」:`Row` / `Editing` / `Saves` / [`from_state`] /
|
||||
//! [`failure_line`] 一律逐行搬来,只把截图那一族从「一行字」换成 [`Shot`](缩略图 + 副文案);
|
||||
//! `saves.rs` 用 `pub use model::{…}` 保住原有路径,页面与用例的 import 一行不改。
|
||||
//!
|
||||
//! # 缩略图的句柄为什么在这里建
|
||||
//!
|
||||
//! [`from_state`] 是「快照 → 模型」的**唯一**转换点,而 `iced` 的 `Handle::from_rgba` 会把像素
|
||||
//! 搬进渲染器(一次上传)。渲染回调(`view()`)每帧都跑、`refresh_view` 只在事件之后跑,
|
||||
//! 所以句柄只能在这里建一次:建在 `view()` 里等于每帧重传 6MB 纹理。
|
||||
//!
|
||||
//! 这也正是 D54「**不许在渲染回调里解码**」的同一条纪律的延伸:解码在 presenter 的后台线程,
|
||||
//! 句柄在这里,`view()` 只借。
|
||||
|
||||
use iced::widget::image::Handle;
|
||||
|
||||
use unlucky_i18n::Catalog;
|
||||
use unlucky_presenter::dto::{
|
||||
SavesFailureKind, SavesFailureOp, SavesFailureView, ScreenshotPreview, ScreenshotThumbKind,
|
||||
ScreenshotView,
|
||||
};
|
||||
use unlucky_presenter::state::SavesState;
|
||||
|
||||
use super::rows;
|
||||
use super::Texts;
|
||||
|
||||
/// 列表里的一个**世界**行。
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Row {
|
||||
/// 世界目录名(磁盘原样;写操作把它原样带回去当「源」)。
|
||||
pub name: String,
|
||||
/// 右侧/下方副文案(时间、图标标记,已由这一层拼好)。
|
||||
pub detail: String,
|
||||
}
|
||||
|
||||
/// 缩略图墙上的一格(一张截图)。
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Shot {
|
||||
/// 磁盘文件名(含扩展名)。墙上一格不印它(`160px` 放不下),但失败原因要能指认它。
|
||||
pub name: String,
|
||||
/// 格子下面的副文案:正常时是「大小 · 时间」,没有预览时是**为什么**没有。
|
||||
pub detail: String,
|
||||
/// 图本身(或占位)。
|
||||
pub preview: ShotPreview,
|
||||
}
|
||||
|
||||
/// 一格截图里的画面。
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ShotPreview {
|
||||
/// 缩略图(句柄在 [`from_state`] 里建好;见模块文档)。
|
||||
Ready {
|
||||
/// 已上传的 RGBA 句柄。
|
||||
handle: Handle,
|
||||
},
|
||||
/// 没有可画的像素:框里一句话(「未生成预览」/ 具名原因)。
|
||||
Missing {
|
||||
/// 短句(`160×90` 的框里放得下)。
|
||||
note: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// 正在行内重命名的那一行(来源是 presenter 的 `SavesState::draft`)。
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Editing {
|
||||
/// 哪个世界。
|
||||
pub dir: String,
|
||||
/// 输入框里的内容(原样)。
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
/// SAVES 区的展示模型(`Model::saves`)。
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct Saves {
|
||||
/// 这份数据属于哪个实例(`None` = 不在详情页 / 还没请求过)。
|
||||
pub bound: Option<String>,
|
||||
/// 正在读盘(进详情页首帧:请求已发出、快照还没回来)。
|
||||
pub loading: bool,
|
||||
/// 读盘/打开/写操作失败的人读原因(app 层按 i18n 拼好)。
|
||||
pub error: Option<String>,
|
||||
/// 这一条失败能不能靠「再列一次」解决(只有读盘失败算)。
|
||||
pub retryable: bool,
|
||||
/// 手里有没有一份**快照**(`false` = 只拿到了失败,"还没有世界"那几句不许画)。
|
||||
pub has_view: bool,
|
||||
/// 两个目录都不存在(新实例的常态:还没进过游戏)。
|
||||
pub missing: bool,
|
||||
/// 世界行。
|
||||
pub worlds: Vec<Row>,
|
||||
/// 截图墙(新的在前,顺序由 core 给)。
|
||||
pub screenshots: Vec<Shot>,
|
||||
/// 计数行(`3 个世界 · 12 张截图`):**在这一层算好**,页面只借 `&str`。
|
||||
///
|
||||
/// 为什么不留到页面里 `format!`:iced 的 `Element` 只借这一帧的数据,页面函数返回的是
|
||||
/// **借用局部变量的树**,局部 `String` 一出栈就悬空(`E0515`)。与 [`super::Row`]
|
||||
/// 之外的 `Mods::count` 同一条做法。
|
||||
pub count: String,
|
||||
/// 跳过条目数(符号链接 / 非图片 / 读不出)。
|
||||
pub skipped: usize,
|
||||
/// 跳过提示(`跳过 3 项`)。
|
||||
pub skipped_note: String,
|
||||
/// 正在行内重命名的那一行(`None` = 没有在改名)。
|
||||
pub editing: Option<Editing>,
|
||||
/// 有写操作在飞的那个世界(`None` = 空闲)。
|
||||
pub busy: Option<String>,
|
||||
/// 上一次写操作成功的那句话(`None` = 这一拍没有回执)。
|
||||
pub notice: Option<String>,
|
||||
}
|
||||
|
||||
impl Saves {
|
||||
/// 有没有拿到一份快照(成功或失败都算;`loading` 中不算)。
|
||||
#[must_use]
|
||||
pub fn loaded(&self) -> bool {
|
||||
self.bound.is_some() && !self.loading
|
||||
}
|
||||
|
||||
/// 两个目录都在、但里面什么都没有(**必须先有一份快照**:纯失败态不是"这里空的")。
|
||||
#[must_use]
|
||||
pub fn nothing_yet(&self) -> bool {
|
||||
self.has_view && !self.missing && self.worlds.is_empty() && self.screenshots.is_empty()
|
||||
}
|
||||
|
||||
/// 这个世界的写操作在飞吗(那一行画「正在处理…」并把按钮拿掉)。
|
||||
#[must_use]
|
||||
pub fn busy_with(&self, dir: &str) -> bool {
|
||||
self.busy.as_deref() == Some(dir)
|
||||
}
|
||||
|
||||
/// 截图墙里有多少张**真出图**了(出图与用例的抓手:`0` 就是一张都没解出来)。
|
||||
#[must_use]
|
||||
pub fn thumbnails(&self) -> usize {
|
||||
self.screenshots
|
||||
.iter()
|
||||
.filter(|shot| matches!(shot.preview, ShotPreview::Ready { .. }))
|
||||
.count()
|
||||
}
|
||||
}
|
||||
|
||||
/// presenter 的视图态 → 页面要画的东西(**唯一**的转换点,`app/view/instances.rs` 调)。
|
||||
///
|
||||
/// 三条口径:
|
||||
///
|
||||
/// 1. **失败不清列表**:list 失败时保留上一份 `worlds`/`screenshots`(用户还能看见旧列表,
|
||||
/// 只是多一条红字),只有"从来没有过快照"时才是一条纯错误态;
|
||||
/// 2. **不做乐观更新**:行上的名字只来自快照,写操作的"在飞"只用来置灰那一行;
|
||||
/// 3. **回执只画一次**:`view.last_op` 是 host 写在快照里的,下一次普通 List 就没了。
|
||||
#[must_use]
|
||||
pub fn from_state(state: &SavesState, catalog: Catalog) -> Saves {
|
||||
let texts = Texts::of(catalog);
|
||||
let mut out = Saves {
|
||||
bound: state.bound.clone(),
|
||||
loading: state.bound.is_some() && state.view.is_none() && state.failed.is_none(),
|
||||
editing: state.draft.as_ref().map(|draft| Editing {
|
||||
dir: draft.dir.clone(),
|
||||
text: draft.text.clone(),
|
||||
}),
|
||||
busy: state.pending.as_ref().map(|op| op.dir().to_string()),
|
||||
..Saves::default()
|
||||
};
|
||||
if let Some(view) = &state.view {
|
||||
out.has_view = true;
|
||||
out.missing = !view.exists && !view.screenshots_exists;
|
||||
// 计数直接问快照(`view.world_count()`),不从刚装好的 `out.worlds` 再数一遍——
|
||||
// M224 出图实测过"先算计数后装列表"画出 `0 启用 · 0 禁用` 的那种顺序错,这里从根上绕开。
|
||||
out.worlds = view
|
||||
.worlds
|
||||
.iter()
|
||||
.map(|world| Row {
|
||||
name: world.dir.clone(),
|
||||
detail: rows::world_detail(world.icon, world.modified_ms, texts),
|
||||
})
|
||||
.collect();
|
||||
out.screenshots = view
|
||||
.screenshots
|
||||
.iter()
|
||||
.map(|shot| shot_cell(shot, texts))
|
||||
.collect();
|
||||
out.count = texts.saves_count(view.world_count(), view.screenshot_count());
|
||||
out.skipped = view.skipped_count();
|
||||
out.skipped_note = texts.saves_skipped(out.skipped);
|
||||
out.notice = view.last_op.as_ref().map(|op| rows::op_line(op, texts));
|
||||
}
|
||||
if let Some(failure) = &state.failed {
|
||||
out.loading = false;
|
||||
out.error = Some(failure_line(failure, texts));
|
||||
// 只有「读盘 / 列目录」失败才值得重试;写操作的重试就是再点一次那个按钮。
|
||||
out.retryable = failure.op.is_none() && failure.kind != SavesFailureKind::OpenFailed;
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// 一张截图 → 墙上的一格(缩略图句柄 / 占位 + 副文案)。
|
||||
///
|
||||
/// **三种状态各有各的话**(D54 第 6 条:失败逐条可见):
|
||||
///
|
||||
/// | 快照里的状态 | 框里 | 副文案 |
|
||||
/// |---|---|---|
|
||||
/// | `Ready`(像素自洽) | 真图 | `大小 · 时间` |
|
||||
/// | `Ready`(像素长度不对) | 「解不出这张图」 | 同一句 + 原因(防御性:壳层不该拿到坏像素) |
|
||||
/// | `NotGenerated` | 「未生成预览」 | 同一句(超预算没轮到) |
|
||||
/// | `Failed` | 具名原因 | 原因 + OS/解码器原文(有的话) |
|
||||
fn shot_cell(shot: &ScreenshotView, texts: Texts) -> Shot {
|
||||
let stamp = rows::shot_detail(shot.bytes, shot.modified_ms, texts);
|
||||
match &shot.preview {
|
||||
ScreenshotPreview::Ready(thumb) if thumb.is_consistent() => Shot {
|
||||
name: shot.file.clone(),
|
||||
detail: stamp,
|
||||
// 一次上传:像素从这里搬进渲染器,之后每帧只借用同一个句柄。
|
||||
preview: ShotPreview::Ready {
|
||||
handle: Handle::from_rgba(thumb.width, thumb.height, thumb.pixels.clone()),
|
||||
},
|
||||
},
|
||||
// 像素长度与宽高对不上:壳层不该拿到这种数据,但拿到了也不能画成花屏。
|
||||
ScreenshotPreview::Ready(_) => {
|
||||
missing(shot, texts.saves_preview_reason(ScreenshotThumbKind::Decode), "")
|
||||
}
|
||||
ScreenshotPreview::NotGenerated => missing(shot, texts.saves_preview_none(), ""),
|
||||
ScreenshotPreview::Failed(failure) => missing(
|
||||
shot,
|
||||
texts.saves_preview_reason(failure.kind),
|
||||
failure.detail.as_str(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// 「没有可画的像素」那一格:框里一句短话,格子下面把原因说全。
|
||||
///
|
||||
/// 短话与副文案**分开**是刻意的:`160×90` 的框里塞不下 OS 原文,而原文正是用户能自己动手的
|
||||
/// 那一半信息(权限 / 被占用 / 文件没了),所以它去副文案那一行(会换行,不会丢)。
|
||||
/// **不靠字符串切分**去拆两句:切分遇到「原因本身带括号」就会切错(这条踩过)。
|
||||
fn missing(shot: &ScreenshotView, note: &str, detail: &str) -> Shot {
|
||||
let caption = if detail.is_empty() {
|
||||
note.to_string()
|
||||
} else {
|
||||
format!("{note}({detail})")
|
||||
};
|
||||
Shot {
|
||||
name: shot.file.clone(),
|
||||
detail: caption,
|
||||
preview: ShotPreview::Missing {
|
||||
note: note.to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// 失败的一句话(**唯一产地**:页面内红字用它,本版没有 Toast)。
|
||||
#[must_use]
|
||||
pub fn failure_line(failure: &SavesFailureView, texts: Texts) -> String {
|
||||
let reason = texts.saves_reason(failure.kind);
|
||||
let sentence = match (failure.op, failure.kind) {
|
||||
(Some(SavesFailureOp::Rename), _) => texts.saves_rename_failed(&failure.file, reason),
|
||||
(Some(SavesFailureOp::Delete), _) => texts.saves_delete_failed(&failure.file, reason),
|
||||
(Some(SavesFailureOp::Backup), _) => texts.saves_backup_failed(&failure.file, reason),
|
||||
(None, SavesFailureKind::OpenFailed) => texts.saves_open_failed(reason),
|
||||
(None, _) => texts.saves_failed(reason),
|
||||
};
|
||||
if failure.detail.is_empty() {
|
||||
return sentence;
|
||||
}
|
||||
format!("{sentence}({})", failure.detail)
|
||||
}
|
||||
@@ -6,8 +6,10 @@
|
||||
//! | 函数 | 画什么 |
|
||||
//! |---|---|
|
||||
//! | [`world`] | 一个世界:名字 + 副文案 +(空闲)重命名/备份/删除、(在飞)「正在处理…」、(改名中)输入框 + 改名/取消 |
|
||||
//! | [`world_plain`] | 只读的一行(截图用它:截图不在三个写操作的范围里) |
|
||||
//! | [`world_detail`] / [`shot_detail`] | 两行副文案 |
|
||||
//! | [`world_detail`] / [`shot_detail`] | 两行副文案(`shot_detail` 现在喂缩略图墙的格子,见 [`super::wall`]) |
|
||||
//!
|
||||
//! M251:原来给截图用的只读行 [`world_plain`] **已删**——截图改画缩略图墙(`super::wall`),
|
||||
//! 留着一个没人调的 `pub(super) fn` 只会在 `-D warnings` 下变成死代码告警。
|
||||
//!
|
||||
//! 三枚按钮与「打开存档文件夹」同一条口径:`buttons::text` + `frame::BASE`(M237:卡片里的控件
|
||||
//! 把底传成卡底,hover/禁用状态才叠在卡实色上),出图取证时整行一起跟 `--force-state`。
|
||||
@@ -83,11 +85,6 @@ pub(super) fn world<'a>(
|
||||
.into()
|
||||
}
|
||||
|
||||
/// 只读的一行(截图)。与 [`world`] 的区别只有一条:没有操作区。
|
||||
pub(super) fn world_plain<'a>(ui: &'a Ui, item: &'a Row) -> Element<'a, Message> {
|
||||
labels(ui, item, Role::OnSurface).into()
|
||||
}
|
||||
|
||||
/// 行内重命名:输入框 + 「改名」/「取消」(占满整行,副文案让位)。
|
||||
fn rename_row<'a>(
|
||||
ui: &'a Ui,
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
//! 截图**缩略图墙**(M251 · SAVESHOTS,D54)。
|
||||
//!
|
||||
//! ## 画什么
|
||||
//!
|
||||
//! 每格 = 「图(或占位框)」+ 下面一行副文案,按 [`PER_ROW`] 列换行排。图的最大边由
|
||||
//! `palette_extract::THUMBNAIL_MAX_EDGE = 160` 定(解码那一侧),这里只负责**摆**:
|
||||
//!
|
||||
//! | 格子内容 | 画什么 |
|
||||
//! |---|---|
|
||||
//! | [`ShotPreview::Ready`] | `iced::widget::image::Handle` 已经是 RGBA 像素,直接画(**不再解码**) |
|
||||
//! | [`ShotPreview::Missing`] | `160×90` 的描边占位框 + 一句短话(「未生成预览」/ 具名原因) |
|
||||
//!
|
||||
//! ## 为什么不用 `grid_row`
|
||||
//!
|
||||
//! iced 0.14 的基础控件里没有流式网格,而本仓没有引 `iced_aw` 之类的扩展 crate(多一个依赖要过
|
||||
//! `deny.toml`)。墙的行数是 `ceil(n / PER_ROW)`,用手写的 `column` + `row` 摆——比引一个
|
||||
//! 扩展 crate 便宜,也比让它自己换行可靠(换行行为不会被窗口宽度悄悄改掉)。
|
||||
//!
|
||||
//! ## 宽高比
|
||||
//!
|
||||
//! 缩略图的**长边是 160**,短边按原图比例(截图通常 16:9 ⇒ 160×90)。所以宽度钉死、高度
|
||||
//! `Shrink`:`iced` 的 image 控件在 `width = Fixed` / `height = Shrink` 下按原图比例取高,
|
||||
//! 不拉伸(`ContentFit::Contain` 默认)。占位框反而钉死 `160×90`——它是"这里本该有一张图"的
|
||||
//! 占位,尺寸要可预测,不能让一句话把它撑变形。
|
||||
//!
|
||||
//! ## 一行放几格
|
||||
//!
|
||||
//! [`PER_ROW`] = 3:`3 × 160 + 2 × 12 = 504px`。详情列在 1180 宽的窗口里内宽约 700,放 4 格
|
||||
//! (676px)会贴边;窄窗口(<840 时详情整页替换)只剩约 500 内宽,3 格是**同时能站住两档**的
|
||||
//! 那个数。改它之前先看 `DevDocs/artifacts/m251/` 的两张图。
|
||||
|
||||
use iced::widget::{column, container, image, row};
|
||||
use iced::{Alignment, Background, Element, Length};
|
||||
|
||||
use unlucky_design::color::Role;
|
||||
use unlucky_design::shape::ShapeScale;
|
||||
use unlucky_design::spacing::Space;
|
||||
use unlucky_design::typography::TypeRole;
|
||||
|
||||
use crate::theme::Ui;
|
||||
|
||||
use super::super::frame;
|
||||
use super::super::Message;
|
||||
use super::{Shot, ShotPreview};
|
||||
|
||||
/// 一格缩略图的宽(= 解码侧的最大边,两者必须同源:图比格子小会留白,比格子大会被缩)。
|
||||
const THUMB_WIDTH: f32 = 160.0;
|
||||
|
||||
/// 占位框的高(16:9,与常见的截图宽高比一致)。
|
||||
const THUMB_HEIGHT: f32 = 90.0;
|
||||
|
||||
/// 一行放几格(理由见模块文档)。
|
||||
const PER_ROW: usize = 3;
|
||||
|
||||
/// 整面墙(`saves.rs` 的 `section` 调;空列表不该走到这里)。
|
||||
pub(super) fn grid<'a>(ui: &'a Ui, shots: &'a [Shot]) -> Element<'a, Message> {
|
||||
let mut wall = column![]
|
||||
.spacing(ui.space(Space::X3))
|
||||
.width(Length::Fill);
|
||||
for chunk in shots.chunks(PER_ROW) {
|
||||
let mut line = row![]
|
||||
.spacing(ui.space(Space::X3))
|
||||
.align_y(Alignment::Start);
|
||||
for shot in chunk {
|
||||
line = line.push(cell(ui, shot));
|
||||
}
|
||||
wall = wall.push(line);
|
||||
}
|
||||
wall.into()
|
||||
}
|
||||
|
||||
/// 一格:图或占位框 + 副文案。
|
||||
fn cell<'a>(ui: &'a Ui, shot: &'a Shot) -> Element<'a, Message> {
|
||||
let picture: Element<'a, Message> = match &shot.preview {
|
||||
ShotPreview::Ready { handle } => image(handle.clone())
|
||||
.width(Length::Fixed(THUMB_WIDTH))
|
||||
.height(Length::Shrink)
|
||||
.border_radius(ui.radius_dp(ShapeScale::Small))
|
||||
.into(),
|
||||
ShotPreview::Missing { note } => placeholder(ui, note.as_str()),
|
||||
};
|
||||
column![
|
||||
picture,
|
||||
frame::text_role(
|
||||
ui,
|
||||
TypeRole::BodySmall,
|
||||
false,
|
||||
shot.detail.as_str(),
|
||||
ui.color(Role::OnSurfaceVariant),
|
||||
)
|
||||
]
|
||||
.spacing(ui.space(Space::X1))
|
||||
.width(Length::Fixed(THUMB_WIDTH))
|
||||
.into()
|
||||
}
|
||||
|
||||
/// 占位框:描边 + 容器色底 + 居中的那句短话。
|
||||
///
|
||||
/// 颜色全部走令牌(D55 第 3 条:组件源码里不许出现字面色值);底用 `SurfaceContainerHigh`
|
||||
/// 而不是画布色,是为了在卡片(`SurfaceContainerLow`)上还能看出"这里有一个格子"。
|
||||
fn placeholder<'a>(ui: &'a Ui, note: &'a str) -> Element<'a, Message> {
|
||||
container(frame::text_role_centered(
|
||||
ui,
|
||||
TypeRole::BodySmall,
|
||||
false,
|
||||
note,
|
||||
ui.color(Role::OnSurfaceVariant),
|
||||
))
|
||||
.width(Length::Fixed(THUMB_WIDTH))
|
||||
.height(Length::Fixed(THUMB_HEIGHT))
|
||||
.padding(ui.space(Space::X2))
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center)
|
||||
.style(move |_theme| container::Style {
|
||||
background: Some(Background::Color(ui.color(Role::SurfaceContainerHigh))),
|
||||
border: ui.outlined(ShapeScale::Small),
|
||||
..container::Style::default()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
@@ -49,11 +49,17 @@ const ALLOWED: &[&str] = &[
|
||||
];
|
||||
|
||||
/// 页面取词的六个源码文件(死 key 扫描与旧串扫描共用)。
|
||||
const PAGE_SOURCES: [(&str, &str); 9] = [
|
||||
const PAGE_SOURCES: [(&str, &str); 12] = [
|
||||
("instances.rs", include_str!("../../instances.rs")),
|
||||
("instances/detail.rs", include_str!("../detail.rs")),
|
||||
("instances/demo.rs", include_str!("../demo.rs")),
|
||||
("instances/text.rs", include_str!("../text.rs")),
|
||||
// M251:存档 / 截图一族从 text.rs 拆出(那边越过 400 行)——新文件必须一起扫,
|
||||
// 否则那四句缩略图文案会被当成「死 key」。
|
||||
(
|
||||
"instances/text/saves.rs",
|
||||
include_str!("../text/saves.rs"),
|
||||
),
|
||||
(
|
||||
"instances/launch_args.rs",
|
||||
include_str!("../launch_args.rs"),
|
||||
@@ -68,6 +74,16 @@ const PAGE_SOURCES: [(&str, &str); 9] = [
|
||||
("instances/saves.rs", include_str!("../saves.rs")),
|
||||
// M247:SAVES 区的行与操作区(重命名 / 备份 / 删除 + 行内输入框)
|
||||
("instances/saves/rows.rs", include_str!("../saves/rows.rs")),
|
||||
// M251:SAVES 区的视图模型(快照 → 行/格子;缩略图句柄在这里建)
|
||||
(
|
||||
"instances/saves/model.rs",
|
||||
include_str!("../saves/model.rs"),
|
||||
),
|
||||
// M251:截图缩略图墙
|
||||
(
|
||||
"instances/saves/wall.rs",
|
||||
include_str!("../saves/wall.rs"),
|
||||
),
|
||||
];
|
||||
|
||||
/// 页面五件套里**允许出现的字符串字面量**(凡是带 ASCII 单词的都必须在这张表里)。
|
||||
@@ -319,25 +335,32 @@ fn every_english_literal_in_the_page_sources_is_whitelisted() {
|
||||
"只扫到 {checked} 条带英文的字面量,扫描器可能失效了"
|
||||
);
|
||||
|
||||
// 反向锚②:这些来源**必须**真的在用 Texts / 目录
|
||||
// 反向锚②:这些来源**必须**真的在用 Texts / 目录。
|
||||
//
|
||||
// M251:原来按下标取(`PAGE_SOURCES[5]`),插进一条新文件就整体错位——改成**按文件名取**,
|
||||
// 以后再拆文件不必回来改下标(拆错文件时仍然会红:找不到那个名字就 panic)。
|
||||
let source = |name: &str| -> &'static str {
|
||||
PAGE_SOURCES
|
||||
.iter()
|
||||
.find(|(file, _)| *file == name)
|
||||
.map(|(_, source)| *source)
|
||||
.unwrap_or_else(|| panic!("PAGE_SOURCES 里没有 {name}:拆文件之后忘了登记?"))
|
||||
};
|
||||
assert!(source("instances.rs").contains("Texts::of("), "实例页没有从 Texts 取词");
|
||||
assert!(
|
||||
PAGE_SOURCES[0].1.contains("Texts::of("),
|
||||
"实例页没有从 Texts 取词"
|
||||
);
|
||||
assert!(
|
||||
PAGE_SOURCES[0].1.contains("Header::new(texts.title())"),
|
||||
source("instances.rs").contains("Header::new(texts.title())"),
|
||||
"页头标题必须是词表里的那条(`Header::new` 里写死字符串 = 中文界面上顶着英文标题)"
|
||||
);
|
||||
assert!(
|
||||
PAGE_SOURCES[3].1.contains("Key::Instances"),
|
||||
source("instances/text.rs").contains("Key::Instances"),
|
||||
"text.rs 没有引用本族的 key"
|
||||
);
|
||||
assert!(
|
||||
PAGE_SOURCES[5].1.contains("Key::InstancesStage"),
|
||||
source("app/view/instances.rs").contains("Key::InstancesStage"),
|
||||
"阶段标签没有走目录"
|
||||
);
|
||||
assert!(
|
||||
PAGE_SOURCES[4].1.contains("texts.launch_title()"),
|
||||
source("instances/launch_args.rs").contains("texts.launch_title()"),
|
||||
"启动参数区没有走目录"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
|
||||
use unlucky_presenter::dto::{
|
||||
SavesArea, SavesFailureKind, SavesFailureView, SavesListView, SavesSkipKind, SavesSkipView,
|
||||
ScreenshotView, WorldView,
|
||||
ScreenshotPreview, ScreenshotThumbFailure, ScreenshotThumbKind, ScreenshotView, ThumbnailView,
|
||||
WorldView,
|
||||
};
|
||||
use unlucky_presenter::state::SavesState;
|
||||
|
||||
use super::super::saves::{failure_line, from_state};
|
||||
use super::super::saves::{failure_line, from_state, ShotPreview};
|
||||
use super::super::Texts;
|
||||
use unlucky_i18n::Lang;
|
||||
|
||||
@@ -36,6 +37,12 @@ fn view(instance: &str) -> SavesListView {
|
||||
file: "2024-05-01_10.00.00.png".to_string(),
|
||||
bytes: 2_048,
|
||||
modified_ms: None,
|
||||
// M251:一像素的缩略图——这条用例只关心「格子/计数/副文案」的映射,不关心解码。
|
||||
preview: ScreenshotPreview::Ready(ThumbnailView {
|
||||
width: 1,
|
||||
height: 1,
|
||||
pixels: vec![0x2E, 0x7D, 0x4F, 0xFF],
|
||||
}),
|
||||
}],
|
||||
skipped: vec![SavesSkipView {
|
||||
area: SavesArea::Screenshots,
|
||||
@@ -79,6 +86,11 @@ fn the_snapshot_becomes_rows_with_stamps_and_badges() {
|
||||
);
|
||||
|
||||
assert_eq!(saves.screenshots.len(), 1);
|
||||
assert_eq!(
|
||||
saves.thumbnails(),
|
||||
1,
|
||||
"带了像素的截图必须变成一格真图(不是占位)"
|
||||
);
|
||||
assert!(
|
||||
saves.screenshots[0].detail.contains("2.0 KB"),
|
||||
"截图的副文案要带大小:{:?}",
|
||||
@@ -243,3 +255,103 @@ fn millisecond_stamps_are_rendered_in_utc() {
|
||||
}
|
||||
|
||||
mod write;
|
||||
|
||||
/// **缩略图墙的三种格子**(M251 · D54 第 6 条):有像素 / 没轮到 / 具名失败,副文案各说各的。
|
||||
///
|
||||
/// 抓得住:①有像素却不画(`Ready` 被吞成占位);②「没生成」与「失败」被合并成同一句
|
||||
/// (用户没法分辨"刷新一下可能就有了"与"得自己去修文件");③失败原因没上屏(原文丢掉)。
|
||||
/// 抓不住:像素画得对不对(`Element` 没有内省接口,只能靠 `DevDocs/artifacts/m251/` 的图)。
|
||||
#[test]
|
||||
fn every_preview_state_gets_its_own_caption() {
|
||||
let texts = Texts::of(Lang::ZhCn.catalog());
|
||||
let mut snapshot = view("a");
|
||||
snapshot.screenshots = vec![
|
||||
ScreenshotView {
|
||||
file: "ok.png".to_string(),
|
||||
bytes: 2_048,
|
||||
modified_ms: Some(STAMP),
|
||||
preview: ScreenshotPreview::Ready(ThumbnailView {
|
||||
width: 2,
|
||||
height: 1,
|
||||
pixels: vec![1, 2, 3, 4, 5, 6, 7, 8],
|
||||
}),
|
||||
},
|
||||
ScreenshotView {
|
||||
file: "pending.png".to_string(),
|
||||
bytes: 4_096,
|
||||
modified_ms: Some(STAMP - 1),
|
||||
preview: ScreenshotPreview::NotGenerated,
|
||||
},
|
||||
ScreenshotView {
|
||||
file: "huge.png".to_string(),
|
||||
bytes: 9_437_184,
|
||||
modified_ms: Some(STAMP - 2),
|
||||
preview: ScreenshotPreview::Failed(ScreenshotThumbFailure {
|
||||
kind: ScreenshotThumbKind::TooLarge,
|
||||
detail: "9437184 > 8388608 字节".to_string(),
|
||||
}),
|
||||
},
|
||||
];
|
||||
let mut state = bound_state("a");
|
||||
state.changed(snapshot);
|
||||
let saves = from_state(&state, Lang::ZhCn.catalog());
|
||||
|
||||
assert_eq!(saves.thumbnails(), 1, "只有第一格有像素");
|
||||
assert!(matches!(
|
||||
saves.screenshots[0].preview,
|
||||
ShotPreview::Ready { .. }
|
||||
));
|
||||
assert_eq!(
|
||||
saves.screenshots[1].preview,
|
||||
ShotPreview::Missing {
|
||||
note: texts.saves_preview_none().to_string()
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
saves.screenshots[2].preview,
|
||||
ShotPreview::Missing {
|
||||
note: texts
|
||||
.saves_preview_reason(ScreenshotThumbKind::TooLarge)
|
||||
.to_string()
|
||||
}
|
||||
);
|
||||
// 失败的副文案要带 OS/解码器原文(只进括号),没生成的那格只要一句短话。
|
||||
assert_eq!(
|
||||
saves.screenshots[2].detail,
|
||||
format!(
|
||||
"{}(9437184 > 8388608 字节)",
|
||||
texts.saves_preview_reason(ScreenshotThumbKind::TooLarge)
|
||||
)
|
||||
);
|
||||
assert_eq!(saves.screenshots[1].detail, texts.saves_preview_none());
|
||||
}
|
||||
|
||||
/// 像素长度与宽高对不上时**不许**建句柄(`Handle::from_rgba` 不校验长度 ⇒ 画出来是花屏)。
|
||||
///
|
||||
/// 抓得住:把 `is_consistent()` 那道判断删掉(这时会走 `Ready`,`thumbnails()` 变 1 而断言要 0)。
|
||||
#[test]
|
||||
fn inconsistent_pixels_are_shown_as_a_failure_not_a_broken_image() {
|
||||
let mut snapshot = view("a");
|
||||
snapshot.screenshots = vec![ScreenshotView {
|
||||
file: "short.png".to_string(),
|
||||
bytes: 10,
|
||||
modified_ms: Some(STAMP),
|
||||
preview: ScreenshotPreview::Ready(ThumbnailView {
|
||||
width: 4,
|
||||
height: 4,
|
||||
pixels: vec![0; 15],
|
||||
}),
|
||||
}];
|
||||
let mut state = bound_state("a");
|
||||
state.changed(snapshot);
|
||||
let saves = from_state(&state, Lang::ZhCn.catalog());
|
||||
assert_eq!(saves.thumbnails(), 0, "坏像素不该被当成图");
|
||||
assert_eq!(
|
||||
saves.screenshots[0].preview,
|
||||
ShotPreview::Missing {
|
||||
note: Texts::of(Lang::ZhCn.catalog())
|
||||
.saves_preview_reason(ScreenshotThumbKind::Decode)
|
||||
.to_string()
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -26,7 +26,10 @@
|
||||
//! `Row.status`(「阶段 · 百分比」是一整句),与元信息卡同一层——页面只画模型给的字符串。
|
||||
|
||||
use unlucky_i18n::{Catalog, Key};
|
||||
use unlucky_presenter::dto::{ModFailureKind, SavesFailureKind};
|
||||
use unlucky_presenter::dto::ModFailureKind;
|
||||
|
||||
/// 存档 / 截图一族的文案(M235 读路径 + M247 写操作 + M251 缩略图)
|
||||
mod saves;
|
||||
|
||||
/// 实例页 + 详情列的文案(一个 `Catalog` 的薄包装,`Copy`)。
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -212,167 +215,6 @@ impl Texts {
|
||||
})
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- 存档区(M235)
|
||||
pub(super) fn saves_title(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesTitle)
|
||||
}
|
||||
/// 「3 个世界 · 12 张截图」。
|
||||
pub(super) fn saves_count(self, worlds: usize, shots: usize) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesCount,
|
||||
&[
|
||||
("worlds", &worlds.to_string()),
|
||||
("shots", &shots.to_string()),
|
||||
],
|
||||
)
|
||||
}
|
||||
pub(super) fn saves_loading(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesLoading)
|
||||
}
|
||||
pub(super) fn saves_empty(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesEmpty)
|
||||
}
|
||||
pub(super) fn saves_missing_dir(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesMissingDir)
|
||||
}
|
||||
pub(super) fn saves_worlds(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesWorlds)
|
||||
}
|
||||
pub(super) fn saves_screenshots(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesScreenshots)
|
||||
}
|
||||
pub(super) fn saves_no_worlds(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesNoWorlds)
|
||||
}
|
||||
pub(super) fn saves_no_screenshots(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesNoScreenshots)
|
||||
}
|
||||
/// 「有图标」:只判 `icon.png` 存不存在(不解码,缩略图墙不在 U3 范围内)。
|
||||
pub(super) fn saves_world_icon(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesWorldIcon)
|
||||
}
|
||||
pub(super) fn saves_time_unknown(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesTimeUnknown)
|
||||
}
|
||||
/// 「跳过 3 项」。
|
||||
pub(super) fn saves_skipped(self, count: usize) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesSkipped, &[("count", &count.to_string())])
|
||||
}
|
||||
pub(super) fn saves_open_folder(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesOpenFolder)
|
||||
}
|
||||
pub(super) fn saves_retry(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesRetry)
|
||||
}
|
||||
/// 读目录失败的主句:`读取 saves/ 失败:目录不可用`。
|
||||
pub(super) fn saves_failed(self, reason: &str) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesFailed, &[("reason", reason)])
|
||||
}
|
||||
/// 打开文件夹失败的主句:`打开文件夹失败:文件管理器没起来`。
|
||||
pub(super) fn saves_open_failed(self, reason: &str) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesOpenFailed, &[("reason", reason)])
|
||||
}
|
||||
/// 失败大类的短句(`SavesFailureKind` → 一句话;写操作那八类各有自己的话)。
|
||||
pub(super) fn saves_reason(self, kind: SavesFailureKind) -> &'static str {
|
||||
self.text(match kind {
|
||||
SavesFailureKind::DirUnusable => Key::InstancesSavesReasonDir,
|
||||
SavesFailureKind::InstanceUnavailable => Key::InstancesSavesReasonInstance,
|
||||
SavesFailureKind::OpenFailed => Key::InstancesSavesReasonOpen,
|
||||
SavesFailureKind::WriteUnsafeName => Key::InstancesSavesReasonUnsafeName,
|
||||
SavesFailureKind::WriteSymlink => Key::InstancesSavesReasonSymlink,
|
||||
SavesFailureKind::WriteMissing => Key::InstancesSavesReasonMissing,
|
||||
SavesFailureKind::WriteNotADirectory => Key::InstancesSavesReasonNotDir,
|
||||
SavesFailureKind::WriteConflict => Key::InstancesSavesReasonConflict,
|
||||
SavesFailureKind::WriteBoundary => Key::InstancesSavesReasonBoundary,
|
||||
SavesFailureKind::WriteTooLarge => Key::InstancesSavesReasonTooLarge,
|
||||
SavesFailureKind::GameRunning => Key::InstancesSavesReasonRunning,
|
||||
SavesFailureKind::WriteFailed => Key::InstancesSavesReasonWrite,
|
||||
})
|
||||
}
|
||||
|
||||
// ------------------------------------------------- 存档写操作(M247 · SAVESOPS)
|
||||
pub(super) fn saves_rename(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesRename)
|
||||
}
|
||||
pub(super) fn saves_backup(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesBackup)
|
||||
}
|
||||
pub(super) fn saves_delete(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesDelete)
|
||||
}
|
||||
/// 行内输入框的占位符(不是按钮文案:它说「该填什么」)。
|
||||
pub(super) fn saves_rename_placeholder(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesRenamePlaceholder)
|
||||
}
|
||||
pub(super) fn saves_rename_confirm(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesRenameConfirm)
|
||||
}
|
||||
pub(super) fn saves_cancel(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesCancel)
|
||||
}
|
||||
/// 「正在处理…」:写请求在飞时顶替那一行的操作区。
|
||||
pub(super) fn saves_busy(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesBusy)
|
||||
}
|
||||
pub(super) fn saves_delete_title(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesDeleteTitle)
|
||||
}
|
||||
/// 删除确认框的正文:`{dir} 和它里面的全部内容都会被删除,且不能撤销。`
|
||||
pub(super) fn saves_delete_body(self, dir: &str) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesDeleteBody, &[("dir", dir)])
|
||||
}
|
||||
pub(super) fn saves_delete_confirm(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesDeleteConfirm)
|
||||
}
|
||||
/// 改名成功的回执:`已把 A 改名为 B。`
|
||||
pub(super) fn saves_renamed(self, from: &str, to: &str) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesRenamed, &[("from", from), ("to", to)])
|
||||
}
|
||||
/// 删除成功的回执:`已删除 A。`
|
||||
pub(super) fn saves_deleted(self, dir: &str) -> String {
|
||||
self.0.render(Key::InstancesSavesDeleted, &[("dir", dir)])
|
||||
}
|
||||
/// 备份成功的回执:`已把 A 备份到 D:/…/A-…zip(1.2 MiB)。`
|
||||
pub(super) fn saves_backed_up(self, dir: &str, path: &str, size: &str) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesBackedUp,
|
||||
&[("dir", dir), ("path", path), ("size", size)],
|
||||
)
|
||||
}
|
||||
/// 「跳过 N 个符号链接」(备份时没跟随的那些)。
|
||||
pub(super) fn saves_backup_skipped(self, count: usize) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesBackupSkipped,
|
||||
&[("count", &count.to_string())],
|
||||
)
|
||||
}
|
||||
/// 重命名失败的主句:`重命名 A 失败:同名世界已存在`。
|
||||
pub(super) fn saves_rename_failed(self, file: &str, reason: &str) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesRenameFailed,
|
||||
&[("file", file), ("reason", reason)],
|
||||
)
|
||||
}
|
||||
/// 删除失败的主句。
|
||||
pub(super) fn saves_delete_failed(self, file: &str, reason: &str) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesDeleteFailed,
|
||||
&[("file", file), ("reason", reason)],
|
||||
)
|
||||
}
|
||||
/// 备份失败的主句。
|
||||
pub(super) fn saves_backup_failed(self, file: &str, reason: &str) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesBackupFailed,
|
||||
&[("file", file), ("reason", reason)],
|
||||
)
|
||||
}
|
||||
|
||||
fn text(self, key: Key) -> &'static str {
|
||||
self.0.text(key)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
//! 实例页文本入口的**存档 / 截图一族**(从 `text.rs` 拆出:那边加完缩略图那四句之后越过
|
||||
//! 400 行硬线,M251)。
|
||||
//!
|
||||
//! 拆法是「**纯搬移 + 一族新增**」:M235 的读路径、M247 的写操作、M251 的缩略图三批 key 全在这一
|
||||
//! 个 `impl Texts` 块里,`text.rs` 保留导航 / 元信息 / MODS 那几族。两处都是 `impl Texts`(Rust
|
||||
//! 允许这么写),调用方依旧写 `texts.saves_*()`,路径不变。
|
||||
//!
|
||||
//! 口径与 `text.rs` 完全一致:**不拼中文**,每个方法只把 `Key` 翻成 `&'static str`(带占位符的用
|
||||
//! `Catalog::render` 现填);带 `{reason}` / `{file}` 的句子由调用方把「已完成的事实」传进来。
|
||||
|
||||
use unlucky_i18n::Key;
|
||||
use unlucky_presenter::dto::{SavesFailureKind, ScreenshotThumbKind};
|
||||
|
||||
use super::Texts;
|
||||
|
||||
impl Texts {
|
||||
// ------------------------------------------------------------- 存档区(M235)
|
||||
pub(in crate::pages::instances) fn saves_title(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesTitle)
|
||||
}
|
||||
/// 「3 个世界 · 12 张截图」。
|
||||
pub(in crate::pages::instances) fn saves_count(self, worlds: usize, shots: usize) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesCount,
|
||||
&[
|
||||
("worlds", &worlds.to_string()),
|
||||
("shots", &shots.to_string()),
|
||||
],
|
||||
)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_loading(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesLoading)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_empty(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesEmpty)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_missing_dir(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesMissingDir)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_worlds(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesWorlds)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_screenshots(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesScreenshots)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_no_worlds(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesNoWorlds)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_no_screenshots(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesNoScreenshots)
|
||||
}
|
||||
/// 「有图标」:只判 `icon.png` 存不存在(不解码,缩略图墙不在 U3 范围内)。
|
||||
pub(in crate::pages::instances) fn saves_world_icon(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesWorldIcon)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_time_unknown(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesTimeUnknown)
|
||||
}
|
||||
/// 「跳过 3 项」。
|
||||
pub(in crate::pages::instances) fn saves_skipped(self, count: usize) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesSkipped, &[("count", &count.to_string())])
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_open_folder(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesOpenFolder)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_retry(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesRetry)
|
||||
}
|
||||
/// 读目录失败的主句:`读取 saves/ 失败:目录不可用`。
|
||||
pub(in crate::pages::instances) fn saves_failed(self, reason: &str) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesFailed, &[("reason", reason)])
|
||||
}
|
||||
/// 打开文件夹失败的主句:`打开文件夹失败:文件管理器没起来`。
|
||||
pub(in crate::pages::instances) fn saves_open_failed(self, reason: &str) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesOpenFailed, &[("reason", reason)])
|
||||
}
|
||||
/// 失败大类的短句(`SavesFailureKind` → 一句话;写操作那八类各有自己的话)。
|
||||
pub(in crate::pages::instances) fn saves_reason(self, kind: SavesFailureKind) -> &'static str {
|
||||
self.text(match kind {
|
||||
SavesFailureKind::DirUnusable => Key::InstancesSavesReasonDir,
|
||||
SavesFailureKind::InstanceUnavailable => Key::InstancesSavesReasonInstance,
|
||||
SavesFailureKind::OpenFailed => Key::InstancesSavesReasonOpen,
|
||||
SavesFailureKind::WriteUnsafeName => Key::InstancesSavesReasonUnsafeName,
|
||||
SavesFailureKind::WriteSymlink => Key::InstancesSavesReasonSymlink,
|
||||
SavesFailureKind::WriteMissing => Key::InstancesSavesReasonMissing,
|
||||
SavesFailureKind::WriteNotADirectory => Key::InstancesSavesReasonNotDir,
|
||||
SavesFailureKind::WriteConflict => Key::InstancesSavesReasonConflict,
|
||||
SavesFailureKind::WriteBoundary => Key::InstancesSavesReasonBoundary,
|
||||
SavesFailureKind::WriteTooLarge => Key::InstancesSavesReasonTooLarge,
|
||||
SavesFailureKind::GameRunning => Key::InstancesSavesReasonRunning,
|
||||
SavesFailureKind::WriteFailed => Key::InstancesSavesReasonWrite,
|
||||
})
|
||||
}
|
||||
|
||||
// ------------------------------------------------- 存档写操作(M247 · SAVESOPS)
|
||||
pub(in crate::pages::instances) fn saves_rename(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesRename)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_backup(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesBackup)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_delete(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesDelete)
|
||||
}
|
||||
/// 行内输入框的占位符(不是按钮文案:它说「该填什么」)。
|
||||
pub(in crate::pages::instances) fn saves_rename_placeholder(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesRenamePlaceholder)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_rename_confirm(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesRenameConfirm)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_cancel(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesCancel)
|
||||
}
|
||||
/// 「正在处理…」:写请求在飞时顶替那一行的操作区。
|
||||
pub(in crate::pages::instances) fn saves_busy(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesBusy)
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_delete_title(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesDeleteTitle)
|
||||
}
|
||||
/// 删除确认框的正文:`{dir} 和它里面的全部内容都会被删除,且不能撤销。`
|
||||
pub(in crate::pages::instances) fn saves_delete_body(self, dir: &str) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesDeleteBody, &[("dir", dir)])
|
||||
}
|
||||
pub(in crate::pages::instances) fn saves_delete_confirm(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesDeleteConfirm)
|
||||
}
|
||||
/// 改名成功的回执:`已把 A 改名为 B。`
|
||||
pub(in crate::pages::instances) fn saves_renamed(self, from: &str, to: &str) -> String {
|
||||
self.0
|
||||
.render(Key::InstancesSavesRenamed, &[("from", from), ("to", to)])
|
||||
}
|
||||
/// 删除成功的回执:`已删除 A。`
|
||||
pub(in crate::pages::instances) fn saves_deleted(self, dir: &str) -> String {
|
||||
self.0.render(Key::InstancesSavesDeleted, &[("dir", dir)])
|
||||
}
|
||||
/// 备份成功的回执:`已把 A 备份到 D:/…/A-…zip(1.2 MiB)。`
|
||||
pub(in crate::pages::instances) fn saves_backed_up(self, dir: &str, path: &str, size: &str) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesBackedUp,
|
||||
&[("dir", dir), ("path", path), ("size", size)],
|
||||
)
|
||||
}
|
||||
/// 「跳过 N 个符号链接」(备份时没跟随的那些)。
|
||||
pub(in crate::pages::instances) fn saves_backup_skipped(self, count: usize) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesBackupSkipped,
|
||||
&[("count", &count.to_string())],
|
||||
)
|
||||
}
|
||||
/// 重命名失败的主句:`重命名 A 失败:同名世界已存在`。
|
||||
pub(in crate::pages::instances) fn saves_rename_failed(self, file: &str, reason: &str) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesRenameFailed,
|
||||
&[("file", file), ("reason", reason)],
|
||||
)
|
||||
}
|
||||
/// 删除失败的主句。
|
||||
pub(in crate::pages::instances) fn saves_delete_failed(self, file: &str, reason: &str) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesDeleteFailed,
|
||||
&[("file", file), ("reason", reason)],
|
||||
)
|
||||
}
|
||||
/// 备份失败的主句。
|
||||
pub(in crate::pages::instances) fn saves_backup_failed(self, file: &str, reason: &str) -> String {
|
||||
self.0.render(
|
||||
Key::InstancesSavesBackupFailed,
|
||||
&[("file", file), ("reason", reason)],
|
||||
)
|
||||
}
|
||||
// ------------------------------------------------- 截图缩略图(M251 · SAVESHOTS)
|
||||
/// 「这一格为什么没有图」的短句(`未生成预览` / 太大 / 读不出 / 解不出)。
|
||||
pub(in crate::pages::instances) fn saves_preview_reason(self, kind: ScreenshotThumbKind) -> &'static str {
|
||||
self.text(match kind {
|
||||
ScreenshotThumbKind::TooLarge => Key::InstancesSavesPreviewTooLarge,
|
||||
ScreenshotThumbKind::Unreadable => Key::InstancesSavesPreviewUnreadable,
|
||||
ScreenshotThumbKind::Decode => Key::InstancesSavesPreviewDecode,
|
||||
})
|
||||
}
|
||||
|
||||
/// 「没轮到」那一句(超 60 张刷新预算 / 这一拍还没解到)。
|
||||
pub(in crate::pages::instances) fn saves_preview_none(self) -> &'static str {
|
||||
self.text(Key::InstancesSavesPreviewNone)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user