Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
[`docs/PERFORMANCE.md`](docs/PERFORMANCE.md)。选项分支、32 pt 间距和回看修复继续保留。
此前对 Release 引擎接口被删除、剧情选项截获系统菜单输入的修复继续保留。
iPhone / iPad 默认隐藏右上角“菜单 / 快进”按钮;可在启动页“游戏操作”中开启
“显示游戏操作按钮”。双指轻点打开菜单、长按快进始终可用。Mac 默认显示两个按钮,
Vision Pro 默认仅显示菜单按钮。Apple 播放器的 MWND 剧情选择
“显示游戏操作按钮”。双指轻点打开菜单、长按快进始终可用。Mac 的菜单与快进位于顶部
“游戏”菜单栏中,Vision Pro 默认仅显示菜单按钮。Apple 播放器的 MWND 剧情选择
使用可点击的原生面板,到选择点暂停快进,点击面板外不会默认选择第一个分支。
进入存档、读档、设置或回看界面时,原生“菜单 / 快进”浮层自动隐藏;返回剧情后按用户显示偏好恢复。
回看每次从最新记录打开,可继续向前翻阅。
Expand Down Expand Up @@ -143,7 +143,8 @@ Wi-Fi 传输的说明:
| 双指轻点 | 鼠标右键(游戏菜单 / 隐藏文字框) |
| 双指上下滑动 | 鼠标滚轮(双指向上滑打开历史记录;打开后可单指拖动翻阅) |
| 长按 | 按住 Ctrl(快进),松手停止 |
| 鼠标 / 触控板(iPad、Mac) | 与 PC 版相同:按下、拖动、左右键、滚轮 |
| 鼠标 / 触控板(iPad、Mac) | 按下、拖动、左右键;向上滚动查看历史对白,向下滚动推进下一条对白,方向遵循系统滚动设置 |
| Mac 菜单栏“游戏” | “游戏菜单…”(⇧⌘M)进入存档、读档和设置;“快进”(⇧⌘F)切换快进并显示勾选状态 |
| 硬件键盘 | Enter、空格、Esc、方向键、Ctrl(按住快进)等 |
| 游戏手柄 | 左摇杆移动指针,A = 左键,B = 右键,RT = 快进,十字键上/下 = 滚轮 |
| Apple Vision Pro | 注视 + 捏合 = 轻点;其余同触控(蓝牙键盘/手柄同样可用) |
Expand Down Expand Up @@ -173,6 +174,9 @@ Release 同时提供 `Clannad-mac.zip`(Mac Catalyst 构建,未公证)。
**不需要复制数据**;选择会被记住,下次直接进入。存档写在那个目录的 `savedata/`,
与 iPhone / iPad 上的存档互不影响。

游戏过程中,通过顶部菜单栏的“游戏 → 游戏菜单…”进入原版存档、读档和设置,
通过“游戏 → 快进”切换快进。快捷键分别为 **⇧⌘M** 和 **⇧⌘F**。

需要 macOS 14 或更高版本。Release 的 Mac 版以 **Apple 芯片(arm64)** 构建,
Apple Silicon 推荐使用;Intel Mac 未做保证(可自行从源码构建 x86_64 版本)。

Expand Down
21 changes: 20 additions & 1 deletion app/Sources/App/ClannadApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,26 @@ final class OrientationController {
}
}

final class AppDelegate: NSObject, UIApplicationDelegate {
final class AppDelegate: UIResponder, UIApplicationDelegate {
override func buildMenu(with builder: UIMenuBuilder) {
super.buildMenu(with: builder)
#if targetEnvironment(macCatalyst)
guard builder.system == .main else { return }
builder.insertSibling(Self.playerMenu(), afterMenu: .view)
#endif
}

static func playerMenu() -> UIMenu {
let menu = UIKeyCommand(title: "游戏菜单…",
action: #selector(SiglusPlayerViewController.showGameMenuCommand(_:)),
input: "m", modifierFlags: [.command, .shift])
let skip = UIKeyCommand(title: "快进",
action: #selector(SiglusPlayerViewController.toggleGameSkipCommand(_:)),
input: "f", modifierFlags: [.command, .shift])
return UIMenu(title: "游戏", identifier: UIMenu.Identifier("org.local.clannad.game"),
children: [menu, skip])
}

func application(_ application: UIApplication,
supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
OrientationController.shared.mask
Expand Down
4 changes: 3 additions & 1 deletion app/Sources/App/LauncherView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ struct LauncherView: View {
if library.gameFolder != nil {
startSection
}
#if !targetEnvironment(macCatalyst)
playerControlsCard
#endif
importCard
transferCard
if let error = library.errorMessage {
Expand Down Expand Up @@ -326,7 +328,7 @@ struct LauncherView: View {
private var footer: some View {
VStack(alignment: .leading, spacing: 4) {
#if targetEnvironment(macCatalyst)
Text("操作:鼠标与键盘同 PC 版 · 左键 = 确定 · 右键 = 菜单 · 滚轮 = 回想 · 按住 Control = 快进")
Text("操作:左键 = 确定 · 右键 = 菜单 · 向上滚动 = 历史对白 · 向下滚动 = 下一条对白 · 按住 Control = 快进。菜单栏“游戏”也可打开游戏菜单和切换快进。")
#else
Text("操作:轻点 = 确定 · 双指轻点 = 右键(菜单)· 单指拖动 = 移动 · 双指上下滑 = 滚轮(回想)· 长按 = 快进(Ctrl)")
Text("也支持硬件键盘与手柄:A = 确定 · B = 菜单 · RT = 快进 · 十字键上下 = 滚轮。")
Expand Down
25 changes: 25 additions & 0 deletions app/Sources/App/PlayerScrollInput.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CoreGraphics

/// Converts direct finger motion and indirect scroll motion into engine wheel steps.
struct PlayerScrollInput {
private var remainder: CGFloat = 0
private let step: CGFloat = 22

mutating func reset() {
remainder = 0
}

mutating func scroll(by translationY: CGFloat, isDirectTouch: Bool, sendWheel: (Int32) -> Void) {
// UIKit indirect scroll translation follows content motion. Direct
// finger drags use the opposite sign for the game's wheel convention.
remainder += isDirectTouch ? -translationY : translationY
while remainder >= step {
remainder -= step
sendWheel(1)
}
while remainder <= -step {
remainder += step
sendWheel(-1)
}
}
}
86 changes: 63 additions & 23 deletions app/Sources/App/PlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
private var lastSkipPoll: CFTimeInterval = 0
private var storySelection: PlayerStorySelection?
private var choicePanel: PlayerChoicePanel?
private var systemInterfaceActive = false

/// Touch-friendly control bar (game menu and fast-forward), shown while
/// the player view is on screen only.
Expand All @@ -138,8 +139,7 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
private var loadingOverlay: UIView?
private var pendingSurface: (wPx: UInt32, hPx: UInt32, scale: Double)?

// Two-finger scroll accumulation.
private var scrollAccumulator: CGFloat = 0
private var scrollInput = PlayerScrollInput()

init(gameRoot: URL, title: String, onExit: @escaping () -> Void) {
self.gameRoot = gameRoot
Expand Down Expand Up @@ -191,6 +191,9 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
#if targetEnvironment(macCatalyst)
becomeFirstResponder()
#endif
lockToLandscape()
updateHomeIndicator()
startDisplayLink()
Expand Down Expand Up @@ -345,6 +348,9 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
return
}
handle = created
#if targetEnvironment(macCatalyst)
UIMenuSystem.main.setNeedsRevalidate()
#endif
var lw: UInt32 = 1280
var lh: UInt32 = 720
siglus_ios_logical_size(created, &lw, &lh)
Expand Down Expand Up @@ -621,10 +627,10 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
if let command = DebugScript.consumeCommand() {
NSLog("Clannad: debug command %@", command.action)
switch command.action {
case "menu": controlBar?.triggerMenuForValidation()
case "menu": openGameMenu()
case "two_finger_tap":
sendRightClick(at: CGPoint(x: metalView.bounds.midX, y: metalView.bounds.midY))
case "skip": controlBar?.triggerSkipForValidation()
case "skip": toggleFastForwardButton()
case "tap":
if let x = command.x, let y = command.y,
x.isFinite, y.isFinite, (0...1).contains(x), (0...1).contains(y) {
Expand Down Expand Up @@ -715,6 +721,7 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
let twoFingerPan = UIPanGestureRecognizer(target: self, action: #selector(handleTwoFingerPan(_:)))
twoFingerPan.minimumNumberOfTouches = 2
twoFingerPan.maximumNumberOfTouches = 2
twoFingerPan.allowedScrollTypesMask = [.continuous, .discrete]
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:)))
longPress.minimumPressDuration = 0.55

Expand All @@ -733,7 +740,6 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
]
tap.allowedTouchTypes = pointerTypes
pan.allowedTouchTypes = pointerTypes
twoFingerPan.allowedScrollTypesMask = [.continuous, .discrete]
#endif

for recognizer in [tap, twoFingerTap, pan, twoFingerPan, longPress] as [UIGestureRecognizer] {
Expand Down Expand Up @@ -887,23 +893,15 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
guard handle != nil else { return }
noteUserActivity()
switch recognizer.state {
case .began:
scrollAccumulator = 0
case .changed:
case .began, .changed:
if recognizer.state == .began { scrollInput.reset() }
let translation = recognizer.translation(in: metalView)
recognizer.setTranslation(.zero, in: metalView)
scrollAccumulator += translation.y
let step: CGFloat = 22
while scrollAccumulator <= -step {
scrollAccumulator += step
sendWheel(1) // swipe up: wheel up (backlog scroll)
}
while scrollAccumulator >= step {
scrollAccumulator -= step
sendWheel(-1) // swipe down: wheel down
scrollInput.scroll(by: translation.y, isDirectTouch: recognizer.numberOfTouches > 0) { delta in
sendWheel(delta)
}
default:
scrollAccumulator = 0
scrollInput.reset()
}
}

Expand All @@ -926,6 +924,7 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
/// Docked top-right during the story; hidden over the game's system UI so
/// its original close/navigation buttons remain visible and touchable.
private func installControlBar() {
#if !targetEnvironment(macCatalyst)
guard controlBar == nil else { return }
let bar = PlayerControlBar()
bar.setButtonsVisible(PlayerControlPreferences.buttonsVisible())
Expand All @@ -946,6 +945,7 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
bar.setFastForwardActive(isFastForwarding)
controlBar = bar
scheduleControlFade()
#endif
}

@objc private func controlPreferencesChanged() {
Expand All @@ -972,12 +972,16 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
}

private func pollSystemInterfaceState() {
guard let handle, let bar = controlBar else { return }
guard let handle else { return }
let active = siglus_ios_system_interface_active(handle) != 0
guard bar.systemInterfaceActive != active else { return }
guard systemInterfaceActive != active else { return }
systemInterfaceActive = active
if active { releaseAllFastForward() }
bar.setSystemInterfaceActive(active)
NSLog("Clannad: system interface %@; controls %@", active ? "open" : "closed", bar.isHidden ? "hidden" : "visible")
controlBar?.setSystemInterfaceActive(active)
#if targetEnvironment(macCatalyst)
UIMenuSystem.main.setNeedsRevalidate()
#endif
NSLog("Clannad: system interface %@", active ? "open" : "closed")
}

private func noteUserActivity() {
Expand Down Expand Up @@ -1048,7 +1052,7 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
// MARK: - fast forward

private func toggleFastForwardButton() {
guard choicePanel == nil else { return }
guard choicePanel == nil, !systemInterfaceActive else { return }
if let setSkip = SiglusOptionalFFI.setSkip, let handle {
// Engine-maintained skip-all: it stops by itself at choices and
// message boxes. Keep the button tint in sync with the state the
Expand Down Expand Up @@ -1106,6 +1110,9 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel
private func refreshFastForwardTint() {
let active = SiglusOptionalFFI.setSkip != nil ? skipActive : isFastForwarding
controlBar?.setFastForwardActive(active)
#if targetEnvironment(macCatalyst)
UIMenuSystem.main.setNeedsRevalidate()
#endif
}

private func releaseAllFastForward() {
Expand Down Expand Up @@ -1153,6 +1160,39 @@ final class SiglusPlayerViewController: UIViewController, UIGestureRecognizerDel

// MARK: - keyboard input

#if targetEnvironment(macCatalyst)
override var canBecomeFirstResponder: Bool { true }
#endif

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
let available = handle != nil && !didExit && !engineFailed && presentedViewController == nil
switch action {
case #selector(showGameMenuCommand(_:)):
return available
case #selector(toggleGameSkipCommand(_:)):
return available && choicePanel == nil && !systemInterfaceActive
default:
return super.canPerformAction(action, withSender: sender)
}
}

override func validate(_ command: UICommand) {
super.validate(command)
if command.action == #selector(toggleGameSkipCommand(_:)) {
command.state = skipActive || isFastForwarding ? .on : .off
}
}

@objc func showGameMenuCommand(_ command: UICommand) {
guard canPerformAction(command.action, withSender: command) else { return }
openGameMenu()
}

@objc func toggleGameSkipCommand(_ command: UICommand) {
guard canPerformAction(command.action, withSender: command) else { return }
toggleFastForwardButton()
}

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
var handled = false
for press in presses {
Expand Down
9 changes: 9 additions & 0 deletions app/Tests/PlayerControlsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ final class PlayerControlsTests: XCTestCase {
XCTAssertTrue(menu.cancelsTouchesInView)
}

func testTwoFingerPanAlsoReceivesMouseAndTrackpadScrollEvents() throws {
let player = SiglusPlayerViewController(gameRoot: URL(fileURLWithPath: "/unused"),
title: "Test", onExit: {})
player.loadViewIfNeeded()
let scroll = try XCTUnwrap(player.view.gestureRecognizers?.compactMap { $0 as? UIPanGestureRecognizer }
.first { $0.minimumNumberOfTouches == 2 })
XCTAssertEqual(scroll.allowedScrollTypesMask, [.continuous, .discrete])
}

func testFastForwardButtonReportsOnAndOff() throws {
let bar = PlayerControlBar()
let skip = try XCTUnwrap(button(in: bar, identifier: "player.skip"))
Expand Down
34 changes: 34 additions & 0 deletions app/Tests/PlayerMenuTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import XCTest
import UIKit
@testable import Clannad

@MainActor
final class PlayerMenuTests: XCTestCase {
func testGameMenuProvidesBothActionsAndShortcuts() throws {
let menu = AppDelegate.playerMenu()
XCTAssertEqual(menu.title, "游戏")
let commands = try XCTUnwrap(menu.children as? [UIKeyCommand])
XCTAssertEqual(commands.count, 2)
XCTAssertEqual(commands[0].action, #selector(SiglusPlayerViewController.showGameMenuCommand(_:)))
XCTAssertEqual(commands[1].action, #selector(SiglusPlayerViewController.toggleGameSkipCommand(_:)))
XCTAssertEqual(commands.map(\.input), ["m", "f"])
XCTAssertTrue(commands.allSatisfy { $0.modifierFlags == [.command, .shift] })
}

func testCommandsAreDisabledBeforeEngineStarts() {
let player = SiglusPlayerViewController(gameRoot: URL(fileURLWithPath: "/unused"),
title: "Test", onExit: {})
for command in AppDelegate.playerMenu().children.compactMap({ $0 as? UICommand }) {
XCTAssertFalse(player.canPerformAction(command.action, withSender: command))
}
}

func testFastForwardCommandStartsUnchecked() throws {
let player = SiglusPlayerViewController(gameRoot: URL(fileURLWithPath: "/unused"),
title: "Test", onExit: {})
let command = try XCTUnwrap(AppDelegate.playerMenu().children.last as? UICommand)
command.state = .on
player.validate(command)
XCTAssertEqual(command.state, .off)
}
}
Loading