feat: imported input-box pets, with dsh-Go's sprite packs
Nothing is built in: Settings → 宠物 shows "尚未导入宠物" until a zip is picked. The zip holds a dsh-Go pack.json and PNG sheets; it is validated (pack.json, every named sheet) and unpacked under the app's private files directory, with enable, size (40/52/64) and remove kept on the device. A pack's canvas, anchor, per-animation box and frame list drive rendering: PetSlot reserves the area above the baseline and stands the sprite on the composer's top edge (or on the activity cap while a turn runs). Idle, thinking, working and error follow the chat's state, and a tap plays the pack's react-left/react-right. Only one sheet is decoded at a time. path_provider's JNI binding does not load on this engine, so MainActivity exposes the files directory over a tiny method channel instead. dist/deepy-whale-pet.zip is the Deepy whale for testing. Tests cover the real pack manifest, frame/state mapping and zip import. 0.4.0 (400).
This commit is contained in:
1 parent
ff0dbf1b37
commit
d72af036a1
16 files changed
+1410
-12
No files matched your search
@@ -12,6 +12,7 @@ import '../state.dart';
|
||||
import '../widgets/composer_attachment.dart';
|
||||
import '../widgets/markdown_view.dart';
|
||||
import '../widgets/composer_box.dart';
|
||||
import '../widgets/pet_sprite.dart';
|
||||
import '../widgets/model_controls.dart';
|
||||
import '../widgets/slash_palette.dart';
|
||||
import '../widgets/usage_ring.dart';
|
||||
@@ -169,6 +170,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
Expanded(child: _messageList()),
|
||||
_permissions(),
|
||||
_forms(),
|
||||
PetSlot(state: _petState()),
|
||||
if (chat.running) _activityStrip(),
|
||||
_composer(widget.keyboardInset),
|
||||
],
|
||||
@@ -1341,6 +1343,21 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// The mood the pet draws: the same activity the strip shows, then a failed
|
||||
/// last turn, then idle.
|
||||
String _petState() {
|
||||
if (chat.running) {
|
||||
return _activity().title == '思考中' ? 'thinking' : 'working';
|
||||
}
|
||||
for (var i = chat.msgs.length - 1; i >= 0; i--) {
|
||||
final m = chat.msgs[i];
|
||||
if (m.type == 'assistant' || m.type == 'idle') {
|
||||
return m.error != null && !m.error!.isEmpty ? 'error' : 'idle';
|
||||
}
|
||||
}
|
||||
return 'idle';
|
||||
}
|
||||
|
||||
/// What the agent is doing right now, for the strip above the composer.
|
||||
({String title, String detail}) _activity() {
|
||||
for (var i = chat.msgs.length - 1; i >= 0; i--) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../state.dart';
|
||||
import '../widgets/composer_attachment.dart';
|
||||
import '../widgets/composer_box.dart';
|
||||
import '../widgets/model_controls.dart';
|
||||
import '../widgets/pet_sprite.dart';
|
||||
import '../widgets/slash_palette.dart';
|
||||
import 'files_panel.dart';
|
||||
|
||||
@@ -259,6 +260,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
items: _attachments,
|
||||
onRemove: _removeAttachment,
|
||||
),
|
||||
const PetSlot(state: 'idle'),
|
||||
_composer(theme, widget.keyboardInset),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// Settings. Three groups for now: appearance (device-local theme), chat (the
|
||||
// server's follow-up behavior) and a pet placeholder.
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../appearance_prefs.dart';
|
||||
import '../pets/pet_library.dart';
|
||||
import '../state.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
@@ -19,6 +21,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
super.initState();
|
||||
// Pick up a change made on another client while this page opens.
|
||||
widget.app.refreshFollowUpBehavior();
|
||||
PetLibrary.instance.ensureLoaded();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -27,7 +30,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('设置')),
|
||||
body: ListenableBuilder(
|
||||
listenable: Listenable.merge([widget.app, look]),
|
||||
listenable: Listenable.merge(
|
||||
[widget.app, look, PetLibrary.instance]),
|
||||
builder: (context, _) {
|
||||
final theme = Theme.of(context);
|
||||
return ListView(
|
||||
@@ -37,12 +41,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
_appearance(theme, look),
|
||||
const _SectionHeader('聊天'),
|
||||
_chat(theme),
|
||||
const _SectionHeader('宠物'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 4, 20, 8),
|
||||
child: Text('暂未提供设置',
|
||||
style: TextStyle(fontSize: 13, color: theme.hintColor)),
|
||||
),
|
||||
const _SectionHeader('宠物',
|
||||
note: '默认不提供;宠物包只存放在本机'),
|
||||
_pet(theme),
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -173,6 +174,131 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
widget.app.clearLastError();
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- pet
|
||||
|
||||
Widget _pet(ThemeData theme) {
|
||||
final library = PetLibrary.instance;
|
||||
final pack = library.pack;
|
||||
if (pack == null) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const ListTile(
|
||||
title: Text('尚未导入宠物'),
|
||||
subtitle: Text('默认不提供宠物。导入一个宠物包(.zip)后,它会站在输入框上方。'),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: FilledButton.tonalIcon(
|
||||
onPressed: _importPet,
|
||||
icon: const Icon(Icons.file_upload_outlined, size: 18),
|
||||
label: const Text('导入宠物包'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
final info = [pack.author, pack.license]
|
||||
.where((s) => s.trim().isNotEmpty)
|
||||
.join(' · ');
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(pack.name.isEmpty ? pack.id : pack.name),
|
||||
subtitle: info.isEmpty
|
||||
? null
|
||||
: Text(info, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('启用宠物'),
|
||||
subtitle: const Text('站在输入框上方,默认关闭'),
|
||||
value: library.enabled,
|
||||
onChanged: (v) => library.setEnabled(v),
|
||||
),
|
||||
const _Label('大小'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
for (final (size, label) in const [
|
||||
(40.0, '小'),
|
||||
(52.0, '中'),
|
||||
(64.0, '大'),
|
||||
])
|
||||
ChoiceChip(
|
||||
label: Text(label),
|
||||
selected: (library.size - size).abs() < 0.5,
|
||||
onSelected: (_) => library.setSize(size),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 2, 20, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: _importPet,
|
||||
icon: const Icon(Icons.swap_horiz, size: 18),
|
||||
label: const Text('更换宠物包'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TextButton(
|
||||
onPressed: _confirmRemovePet,
|
||||
child: const Text('移除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _importPet() async {
|
||||
try {
|
||||
final file = await FilePicker.pickFile(
|
||||
dialogTitle: '选择宠物包(.zip)',
|
||||
type: FileType.custom,
|
||||
allowedExtensions: const ['zip'],
|
||||
);
|
||||
if (file == null) return;
|
||||
final bytes = await file.readAsBytes();
|
||||
final pack = await PetLibrary.instance.importZip(bytes);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content:
|
||||
Text('已导入 ${pack.name.isEmpty ? pack.id : pack.name}')),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('导入失败:$e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _confirmRemovePet() async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialog) => AlertDialog(
|
||||
title: const Text('移除宠物?'),
|
||||
content: const Text('本机保存的宠物包会被删除。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialog, false),
|
||||
child: const Text('取消')),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(dialog, true),
|
||||
child: const Text('移除')),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok == true) await PetLibrary.instance.remove();
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionHeader extends StatelessWidget {
|
||||
|
||||
Reference in new issue
Block a user