cc-pets 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +24 -2
- package/CC_BRIDGE.zh-CN.md +19 -2
- package/CHANGELOG.md +111 -0
- package/CHANGELOG.zh-CN.md +111 -0
- package/CONTRIBUTING.md +35 -10
- package/CONTRIBUTING.zh-CN.md +28 -10
- package/README.md +212 -32
- package/README.zh-CN.md +167 -36
- package/Resources/AgentIcons/claude.png +0 -0
- package/Resources/AgentIcons/codex.icns +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.vsix +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.zip +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +699 -20
- package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
- package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +90 -25
- package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
- package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +17 -3
- package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +71 -23
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
- package/Sources/CCPets/{CCPetsAppDelegate+Settings.m → App/CCPetsAppDelegate+Settings.m} +87 -102
- package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +121 -51
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
- package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +17 -2
- package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +107 -11
- package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
- package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
- package/Sources/CCPets/{main.m → App/main.m} +74 -1
- package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
- package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +43 -23
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +832 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +59 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +576 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +507 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +106 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +897 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
- package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
- package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +2 -1
- package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +148 -36
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.m +64 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.h +23 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.m +475 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
- package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +11 -2
- package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +19 -2
- package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +4 -1
- package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
- package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
- package/Sources/CCPets/Pet/PetView+Private.h +81 -0
- package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
- package/Sources/CCPets/Pet/PetView.m +635 -0
- package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
- package/Sources/CCPets/Support/CCPetsDoctor.m +646 -0
- package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
- package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
- package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
- package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +33 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +117 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +44 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +279 -0
- package/Sources/CCPets/UI/CCPetsGlassView.h +57 -0
- package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +60 -11
- package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
- package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +64 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +1412 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +135 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +865 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +288 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +712 -0
- package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
- package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
- package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
- package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
- package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
- package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +97 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +323 -0
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
- package/Sources/CCPets/Usage/CCPetsUsage.h +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +174 -19
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +598 -0
- package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
- package/Sources/CCPets/Usage/QuotaDashboardView.m +713 -0
- package/THIRD_PARTY_NOTICES.md +8 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -2
- package/bin/cc-pets +8 -6
- package/bin/claude-with-pet +12 -2
- package/bin/codex-with-pet +15 -5
- package/package.json +5 -1
- package/plugins/jetbrains/README.md +62 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalBridge.java +379 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalIdentity.java +24 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalStartup.java +12 -0
- package/plugins/jetbrains/src/main/resources/META-INF/plugin.xml +23 -0
- package/plugins/jetbrains/src/main/resources/META-INF/pluginIcon.svg +380 -0
- package/plugins/vscode/README.md +63 -0
- package/plugins/vscode/extension.js +210 -0
- package/plugins/vscode/package.json +18 -0
- package/scripts/build-idea-plugin.sh +101 -0
- package/scripts/build-vscode-extension.sh +112 -0
- package/scripts/build.sh +31 -5
- package/scripts/compile-cached.zsh +133 -0
- package/scripts/i18n.zsh +9 -52
- package/scripts/install-app.sh +4 -0
- package/scripts/install-shell-integration.sh +17 -10
- package/scripts/uninstall-shell-integration.sh +6 -1
- package/Sources/CCPets/CCPetsEvents.h +0 -10
- package/Sources/CCPets/CCPetsGlassView.h +0 -31
- package/Sources/CCPets/CCPetsUsage.h +0 -36
- package/Sources/CCPets/CCPetsUsage.m +0 -2069
- package/Sources/CCPets/PetView.m +0 -1839
- package/Sources/CCPets/QuotaDashboardView.m +0 -1145
- package/scripts/bridge/cli.mjs +0 -237
- package/scripts/bridge/core.mjs +0 -228
- package/scripts/bridge/hook.mjs +0 -150
- package/scripts/bridge/install.mjs +0 -311
- package/scripts/bridge/mcp-server.mjs +0 -308
- package/scripts/bridge/options.mjs +0 -87
- package/scripts/bridge/process.mjs +0 -151
- package/scripts/bridge/reservations.mjs +0 -248
- package/scripts/bridge/store.mjs +0 -433
- package/scripts/bridge/watch.mjs +0 -69
- package/scripts/check-l10n.mjs +0 -168
- package/scripts/configure-updater.mjs +0 -43
- package/scripts/detect-cli.mjs +0 -68
- package/scripts/doctor.mjs +0 -470
- package/scripts/i18n.mjs +0 -122
- package/scripts/install-claude-hooks.mjs +0 -253
- package/scripts/install-codex-hooks.mjs +0 -78
- package/scripts/integration-markers.mjs +0 -51
- package/scripts/locales/zh-Hans.json +0 -366
- package/scripts/pet-store.mjs +0 -415
- package/scripts/uninstall-integrations.mjs +0 -205
- /package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.h → Pet/CCPetsImageLoader.h} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.h → Pet/CCPetsPetSize.h} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.m → Pet/CCPetsPetSize.m} +0 -0
- /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
- /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +0 -0
- /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.h → UI/MenuPetSizeView.h} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.m → UI/MenuPetSizeView.m} +0 -0
- /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#import "PetView+Private.h"
|
|
2
|
+
|
|
3
|
+
// 按下后位移超过这个距离才判定为拖动,之内视为点击。
|
|
4
|
+
static const CGFloat PetDragThreshold = 3.0;
|
|
5
|
+
// 拖动滞后只做水平方向。窗口左右各有 43px 余量,而下方是 0——垂直滞后往下一点就被裁掉,
|
|
6
|
+
// 只留向上会变成不对称的怪动作,不如不做。反正拖动本来就按水平方向选跑动行,
|
|
7
|
+
// 水平滞后正好强化那个方向感。
|
|
8
|
+
static const CGFloat PetDragLagMax = 13.0;
|
|
9
|
+
static const CGFloat PetDragLagFactor = 0.85;
|
|
10
|
+
// 松手后的"落脚":先压扁再回弹到静止。锚点在脚底,所以压扁是往下坐,不会越界。
|
|
11
|
+
static const NSTimeInterval PetSettleDuration = 0.34;
|
|
12
|
+
|
|
13
|
+
@implementation PetView (Interaction)
|
|
14
|
+
// 桌宠是 LSUIElement + NSNonactivatingPanel,几乎永远不是活跃应用。不接受 first mouse
|
|
15
|
+
// 的话,AppKit 会把点击非活跃应用窗口的第一次 mouseDown 当成"激活点击"消耗掉,视图
|
|
16
|
+
// 根本收不到——表现为要点两下才拖得动。以前靠 movableByWindowBackground 拖动时不受
|
|
17
|
+
// 影响(窗口背景拖动在窗口服务器层处理,不走视图的 first mouse 判定),关掉它之后
|
|
18
|
+
// 这个缺陷才暴露出来。
|
|
19
|
+
- (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
|
|
20
|
+
// 精灵区的拖动由 runWindowDragWithEvent: 自己发起,不让 AppKit 的窗口背景拖动同时
|
|
21
|
+
// 介入同一次按下;窗口透明区没有这个覆写,继续走 movableByWindowBackground。
|
|
22
|
+
// 两条路径底层都是窗口服务器拖动,手感一致。
|
|
23
|
+
- (BOOL)mouseDownCanMoveWindow { return NO; }
|
|
24
|
+
// 阈值起点取事件自带的坐标,不用 NSEvent.mouseLocation(那是"处理这条事件时"鼠标的实时
|
|
25
|
+
// 位置)。主线程被别的活儿占住时,mouseDown 会晚一截才被处理,实时位置早已跟着手滑走,
|
|
26
|
+
// 起点于是落在远处,后面要多走同样的距离才够过阈值——表现为按住之后宠物迟迟不动。
|
|
27
|
+
// 阈值判定发生在窗口服务器接手拖动之前,窗口此刻还没动,所以窗口坐标是稳定的参照系。
|
|
28
|
+
- (void)mouseDown:(NSEvent *)event {
|
|
29
|
+
[self noteActivity];
|
|
30
|
+
self.agentActive = NO;
|
|
31
|
+
self.dragStartMouse = event.locationInWindow;
|
|
32
|
+
}
|
|
33
|
+
- (void)mouseDragged:(NSEvent *)event {
|
|
34
|
+
if (self.draggingPet) return;
|
|
35
|
+
NSPoint current = event.locationInWindow;
|
|
36
|
+
CGFloat horizontal = current.x - self.dragStartMouse.x;
|
|
37
|
+
CGFloat vertical = current.y - self.dragStartMouse.y;
|
|
38
|
+
if (hypot(horizontal, vertical) < PetDragThreshold) return;
|
|
39
|
+
[self runWindowDragWithEvent:event movingRight:horizontal >= 0];
|
|
40
|
+
}
|
|
41
|
+
// 拖动交给窗口服务器:它不依赖应用事件流,所以掠过其他窗口、拖出屏幕、
|
|
42
|
+
// 应用非活跃都不会中断。这个 API 会立即返回,且 mouseUp 可能不会发回应用,
|
|
43
|
+
// 因此不能在调用后立刻恢复 idle;释放兜底由 nextFrame: 检查物理按键状态。
|
|
44
|
+
- (void)runWindowDragWithEvent:(NSEvent *)event movingRight:(BOOL)movingRight {
|
|
45
|
+
self.draggingPet = YES;
|
|
46
|
+
if (self.pocketHoverChanged) self.pocketHoverChanged(NO);
|
|
47
|
+
if (self.dragStateChanged) self.dragStateChanged(YES);
|
|
48
|
+
[self playRow:movingRight ? 1 : 2 throughFrame:7 oneShot:NO];
|
|
49
|
+
[self startObservingWindowMove];
|
|
50
|
+
|
|
51
|
+
[self.window performWindowDragWithEvent:event];
|
|
52
|
+
}
|
|
53
|
+
- (void)startObservingWindowMove {
|
|
54
|
+
if (self.observingWindowMove || !self.window) return;
|
|
55
|
+
self.lastDragWindowOrigin = self.window.frame.origin;
|
|
56
|
+
self.observingWindowMove = YES;
|
|
57
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
58
|
+
selector:@selector(petWindowMovedWhileDragging:)
|
|
59
|
+
name:NSWindowDidMoveNotification object:self.window];
|
|
60
|
+
}
|
|
61
|
+
- (void)stopObservingWindowMove {
|
|
62
|
+
if (!self.observingWindowMove) return;
|
|
63
|
+
self.observingWindowMove = NO;
|
|
64
|
+
[NSNotificationCenter.defaultCenter removeObserver:self
|
|
65
|
+
name:NSWindowDidMoveNotification object:self.window];
|
|
66
|
+
}
|
|
67
|
+
// 精灵在窗口内往反方向落后一点,看着就有了重量。滞后量跟这一帧的位移走,
|
|
68
|
+
// 停手不动时位移为 0,会自然归位。
|
|
69
|
+
- (void)petWindowMovedWhileDragging:(NSNotification *)notification {
|
|
70
|
+
if (!self.draggingPet || self.reduceMotion) return;
|
|
71
|
+
NSPoint origin = self.window.frame.origin;
|
|
72
|
+
CGFloat dx = origin.x - self.lastDragWindowOrigin.x;
|
|
73
|
+
self.lastDragWindowOrigin = origin;
|
|
74
|
+
|
|
75
|
+
CGFloat lag = -dx * PetDragLagFactor;
|
|
76
|
+
lag = MAX(-PetDragLagMax, MIN(PetDragLagMax, lag));
|
|
77
|
+
// 缩短隐式动画时长:默认 0.25s 追不上手,看着是糊而不是滞后。0.12s 既平滑又跟手。
|
|
78
|
+
[CATransaction begin];
|
|
79
|
+
[CATransaction setAnimationDuration:0.12];
|
|
80
|
+
[CATransaction setAnimationTimingFunction:
|
|
81
|
+
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
|
|
82
|
+
self.spriteLayer.transform = CATransform3DMakeTranslation(lag, 0, 0);
|
|
83
|
+
[CATransaction commit];
|
|
84
|
+
}
|
|
85
|
+
- (void)endPetDrag {
|
|
86
|
+
if (!self.draggingPet) return;
|
|
87
|
+
self.draggingPet = NO;
|
|
88
|
+
[self stopObservingWindowMove];
|
|
89
|
+
if (self.dragStateChanged) self.dragStateChanged(NO);
|
|
90
|
+
[self playRow:0 throughFrame:5 oneShot:NO];
|
|
91
|
+
[self playSettleAnimation];
|
|
92
|
+
}
|
|
93
|
+
// 落脚:从当前滞后位置 → 压扁 → 轻微回弹过冲 → 静止。
|
|
94
|
+
// 整段只动 transform 一个属性,和挂在 position.y 上的呼吸互不干扰。
|
|
95
|
+
- (void)playSettleAnimation {
|
|
96
|
+
CALayer *layer = self.spriteLayer;
|
|
97
|
+
if (!layer) return;
|
|
98
|
+
if (self.reduceMotion) {
|
|
99
|
+
layer.transform = CATransform3DIdentity;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
CATransform3D current = ((CALayer *)layer.presentationLayer ?: layer).transform;
|
|
103
|
+
CAKeyframeAnimation *settle = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
|
|
104
|
+
settle.values = @[
|
|
105
|
+
[NSValue valueWithCATransform3D:current],
|
|
106
|
+
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.07, 0.92, 1.0)],
|
|
107
|
+
[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.97, 1.04, 1.0)],
|
|
108
|
+
[NSValue valueWithCATransform3D:CATransform3DIdentity]
|
|
109
|
+
];
|
|
110
|
+
settle.keyTimes = @[@0.0, @0.34, @0.68, @1.0];
|
|
111
|
+
settle.duration = PetSettleDuration;
|
|
112
|
+
settle.timingFunction = [CAMediaTimingFunction
|
|
113
|
+
functionWithName:kCAMediaTimingFunctionEaseOut];
|
|
114
|
+
// 先把 model 值落到静止态且不触发隐式动画,否则它会和下面的关键帧同时跑。
|
|
115
|
+
[CATransaction begin];
|
|
116
|
+
[CATransaction setDisableActions:YES];
|
|
117
|
+
layer.transform = CATransform3DIdentity;
|
|
118
|
+
[CATransaction commit];
|
|
119
|
+
[layer addAnimation:settle forKey:@"settle"];
|
|
120
|
+
}
|
|
121
|
+
- (void)mouseUp:(NSEvent *)event {
|
|
122
|
+
if (self.draggingPet) {
|
|
123
|
+
[self endPetDrag];
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
[self handleInteractionClick];
|
|
127
|
+
}
|
|
128
|
+
- (void)handleInteractionClick {
|
|
129
|
+
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
130
|
+
if (![defaults boolForKey:PetInteractionEnabledKey]) {
|
|
131
|
+
[self playRow:7 throughFrame:5 oneShot:YES];
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
NSTimeInterval interval = [defaults doubleForKey:PetInteractionIntervalKey];
|
|
135
|
+
interval = MAX(0.4, MIN(3.0, interval));
|
|
136
|
+
NSInteger heartThreshold = MAX((NSInteger)2,
|
|
137
|
+
[defaults integerForKey:PetInteractionHeartThresholdKey]);
|
|
138
|
+
NSInteger annoyedThreshold = MAX(heartThreshold + 1,
|
|
139
|
+
[defaults integerForKey:PetInteractionAnnoyedThresholdKey]);
|
|
140
|
+
NSTimeInterval now = CFAbsoluteTimeGetCurrent();
|
|
141
|
+
if (now - self.lastInteractionClickAt > interval) {
|
|
142
|
+
self.interactionClickCount = 0;
|
|
143
|
+
}
|
|
144
|
+
self.lastInteractionClickAt = now;
|
|
145
|
+
self.interactionClickCount++;
|
|
146
|
+
|
|
147
|
+
if (self.interactionClickCount >= annoyedThreshold) {
|
|
148
|
+
[self spawnInteractionSymbols:@[@"💢", @"╬", @"!"]
|
|
149
|
+
color:NSColor.systemOrangeColor];
|
|
150
|
+
[self playRow:5 throughFrame:7 oneShot:YES];
|
|
151
|
+
if (self.interactionPhraseRequested) {
|
|
152
|
+
self.interactionPhraseRequested(@"click_annoyed");
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (self.interactionClickCount >= heartThreshold) {
|
|
157
|
+
[self spawnInteractionSymbols:@[@"♥︎", @"♥︎", @"♥︎"]
|
|
158
|
+
color:NSColor.systemPinkColor];
|
|
159
|
+
[self playRow:3 throughFrame:3 oneShot:YES];
|
|
160
|
+
if (self.interactionPhraseRequested) {
|
|
161
|
+
self.interactionPhraseRequested(@"click_heart");
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
[self playRow:7 throughFrame:5 oneShot:YES];
|
|
166
|
+
}
|
|
167
|
+
- (void)spawnInteractionSymbols:(NSArray<NSString *> *)symbols color:(NSColor *)color {
|
|
168
|
+
NSTimeInterval duration = self.reduceMotion ? 0.45 : 0.95;
|
|
169
|
+
for (NSUInteger index = 0; index < symbols.count; index++) {
|
|
170
|
+
CGFloat x = 34.0 + arc4random_uniform(66);
|
|
171
|
+
CGFloat y = 104.0 + arc4random_uniform(12);
|
|
172
|
+
NSTextField *label = [NSTextField labelWithString:symbols[index]];
|
|
173
|
+
label.alignment = NSTextAlignmentCenter;
|
|
174
|
+
label.font = [NSFont systemFontOfSize:index == 0 ? 21 : 17
|
|
175
|
+
weight:NSFontWeightBold];
|
|
176
|
+
label.textColor = color;
|
|
177
|
+
label.frame = NSMakeRect(x, y, 30, 28);
|
|
178
|
+
label.wantsLayer = YES;
|
|
179
|
+
label.layer.zPosition = 20;
|
|
180
|
+
[self addSubview:label];
|
|
181
|
+
|
|
182
|
+
CFTimeInterval delay = index * 0.08;
|
|
183
|
+
CGPoint start = label.layer.position;
|
|
184
|
+
CGPoint end = CGPointMake(start.x + ((NSInteger)index - 1) * 10,
|
|
185
|
+
start.y + (self.reduceMotion ? 0 : 34 + index * 5));
|
|
186
|
+
CAKeyframeAnimation *position = [CAKeyframeAnimation animationWithKeyPath:@"position"];
|
|
187
|
+
position.values = @[[NSValue valueWithPoint:start], [NSValue valueWithPoint:end]];
|
|
188
|
+
CAKeyframeAnimation *opacity = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
|
|
189
|
+
opacity.values = @[@0.0, @1.0, @1.0, @0.0];
|
|
190
|
+
opacity.keyTimes = @[@0.0, @0.18, @0.68, @1.0];
|
|
191
|
+
CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
|
|
192
|
+
scale.values = @[@0.65, @1.12, @1.0];
|
|
193
|
+
scale.keyTimes = @[@0.0, @0.35, @1.0];
|
|
194
|
+
CAAnimationGroup *group = [CAAnimationGroup animation];
|
|
195
|
+
group.animations = @[position, opacity, scale];
|
|
196
|
+
group.duration = duration;
|
|
197
|
+
group.beginTime = CACurrentMediaTime() + delay;
|
|
198
|
+
group.fillMode = kCAFillModeBoth;
|
|
199
|
+
group.removedOnCompletion = NO;
|
|
200
|
+
[label.layer addAnimation:group forKey:@"interactionFloat"];
|
|
201
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
|
|
202
|
+
(int64_t)((duration + delay + 0.05) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
203
|
+
[label removeFromSuperview];
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
@end
|