Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

iOS shell: the button test's controller drawing on the mapping card

v0lumehi2dca64404a68
diff --git a/frontend-ios/README.md b/frontend-ios/README.md
index e8a97667..f434d0f0 100644
--- a/frontend-ios/README.md
+++ b/frontend-ios/README.md
@@ -33,7 +33,7 @@ All boundary types are in `Sources/ShellUI/ShellInputs.swift` and `ShellArtwork.
- `ShellActions`: selection, Play, setting changes, game-data and cloud-folder requests, reset, log, app update and Back. The game ID is always passed.
- `ShellInput`: an optional semantic controller event with an increasing sequence and the device that sent it (`InputDevice`: a controller family or the keyboard), so the hints draw that device's glyphs.
-`ShellControllers` is a separate library target, not part of the views: `GamepadAdapter` reads every GameController controller (D-pad and left stick with a deadzone and the Mac's repeat on hold, A activates, B goes back, X and Menu open game settings, Y opens Controllers, by label so each family confirms with its own button) and reports `ShellInput` actions and the connected controllers with their battery. Its pure mapping (`PadMapper`, `RepeatTiming`) is unit tested. The Controllers page also opens a Button mapping card for all games: Swap A and B as a segmented choice, then the 16 buttons in four groups (face buttons, shoulders and triggers, D-pad, more), each row the button's glyph, where it sits and what it sends, with a cream dot on a row that differs and Reset in a footer that does not scroll. The buttons are named as on a Switch controller, by position, as the engine maps every controller. A row picked shows the buttons it can send as a grid of glyphs, and None. These affect games only. Its Button test card draws an Xbox-style controller and lights up each button, trigger and stick of the controller that moved as it is pressed (hold B to close), and forgets a controller that disconnects. Shell menus keep A to confirm and B to go back. Each game's settings have one Button mapping row that opens the same card for that game, which can follow all games, override single buttons, turn a button off, or explicitly keep A and B unswapped. `PadMappingCaptureTests` renders these views on the Mac (`NX_SHELL_CAPTURE_DIR`, `NX_SHELL_CAPTURE_LANG`). The demo uses it, the real shell can too.
+`ShellControllers` is a separate library target, not part of the views: `GamepadAdapter` reads every GameController controller (D-pad and left stick with a deadzone and the Mac's repeat on hold, A activates, B goes back, X and Menu open game settings, Y opens Controllers, by label so each family confirms with its own button) and reports `ShellInput` actions and the connected controllers with their battery. Its pure mapping (`PadMapper`, `RepeatTiming`) is unit tested. The Controllers page also opens a Button mapping card for all games: on top the button test's controller drawing with the Switch names of its places, where a tap on a button opens its choices, a cream ring marks a changed button and a button held on a connected controller lights up, then Swap A and B as a segmented choice, then the 16 buttons in four groups (face buttons, shoulders and triggers, D-pad, more), each row the button's glyph, where it sits and what it sends, with a cream dot on a row that differs and Reset in a footer that does not scroll. The buttons are named as on a Switch controller, by position, as the engine maps every controller. A row picked shows the buttons it can send as a grid of glyphs, and None. These affect games only. Its Button test card draws an Xbox-style controller and lights up each button, trigger and stick of the controller that moved as it is pressed (hold B to close), and forgets a controller that disconnects. Shell menus keep A to confirm and B to go back. Each game's settings have one Button mapping row that opens the same card for that game, which can follow all games, override single buttons, turn a button off, or explicitly keep A and B unswapped. `PadMappingCaptureTests` renders these views on the Mac (`NX_SHELL_CAPTURE_DIR`, `NX_SHELL_CAPTURE_LANG`). The demo uses it, the real shell can too.
```swift
LibraryView(
diff --git a/frontend-ios/Sources/ShellUI/ButtonTestView.swift b/frontend-ios/Sources/ShellUI/ButtonTestView.swift
index 6c216ecb..59c4eb2f 100644
--- a/frontend-ios/Sources/ShellUI/ButtonTestView.swift
+++ b/frontend-ios/Sources/ShellUI/ButtonTestView.swift
@@ -90,6 +90,15 @@ struct ButtonTestView: View {
/// buttons in their own colours, everything else in cream.
struct XboxControllerDiagram: View {
let snapshot: PadSnapshot
+ /// The mapping card's drawing: the buttons carry the Switch names of their places and one quiet colour. False: the
+ /// button test, with Xbox's names and colours.
+ var switchNames = false
+ /// Buttons drawn with a cream ring: the ones the mapping changed.
+ var marked: Set<PadElement> = []
+ /// A tap on a button, which also makes each button a VoiceOver element. Nil: the drawing is a picture (the button test).
+ var tap: ((PadElement) -> Void)? = nil
+ /// What VoiceOver says a button sends, on the mapping card.
+ var value: (PadElement) -> String = { _ in "" }
static let design = CGSize(width: 320, height: 220)
static func name(_ element: PadElement) -> String {
@@ -114,10 +123,101 @@ struct XboxControllerDiagram: View {
}
}
+ /// Where each element sits in the design space and how large it is, shared by the drawing, the rings and the hotspots.
+ nonisolated static func frame(_ e: PadElement) -> (center: CGPoint, size: CGSize) {
+ switch e {
+ case .leftTrigger: (CGPoint(x: 83, y: 13), CGSize(width: 42, height: 22))
+ case .rightTrigger: (CGPoint(x: 237, y: 13), CGSize(width: 42, height: 22))
+ case .leftBumper: (CGPoint(x: 88, y: 32), CGSize(width: 72, height: 12))
+ case .rightBumper: (CGPoint(x: 232, y: 32), CGSize(width: 72, height: 12))
+ case .leftStick: (CGPoint(x: 88, y: 92), CGSize(width: 46, height: 46))
+ case .rightStick: (CGPoint(x: 202, y: 140), CGSize(width: 46, height: 46))
+ case .up: (CGPoint(x: 118, y: 128), CGSize(width: 12, height: 12))
+ case .down: (CGPoint(x: 118, y: 152), CGSize(width: 12, height: 12))
+ case .left: (CGPoint(x: 106, y: 140), CGSize(width: 12, height: 12))
+ case .right: (CGPoint(x: 130, y: 140), CGSize(width: 12, height: 12))
+ case .y: (CGPoint(x: 240, y: 70), CGSize(width: 20, height: 20))
+ case .x: (CGPoint(x: 219, y: 92), CGSize(width: 20, height: 20))
+ case .b: (CGPoint(x: 261, y: 92), CGSize(width: 20, height: 20))
+ case .a: (CGPoint(x: 240, y: 114), CGSize(width: 20, height: 20))
+ case .view: (CGPoint(x: 138, y: 92), CGSize(width: 14, height: 14))
+ case .menu: (CGPoint(x: 182, y: 92), CGSize(width: 14, height: 14))
+ case .home: (CGPoint(x: 160, y: 60), CGSize(width: 22, height: 22))
+ }
+ }
+
+ /// The text on an element: Xbox's names for the test, the Switch names by position on the mapping card.
+ private func label(_ e: PadElement) -> String {
+ guard switchNames, let button = PadMap.button(at: e) else { return Self.name(e) }
+ return button
+ }
+
var body: some View {
GeometryReader { geometry in
let s = min(geometry.size.width / Self.design.width, geometry.size.height / Self.design.height)
ZStack(alignment: .topLeading) {
+ drawing(s: s)
+ ForEach(PadElement.allCases.filter(marked.contains), id: \.self) { ring($0, s: s) }
+ if let tap { hotspots(s: s, tap: tap) }
+ }
+ .frame(width: Self.design.width * s, height: Self.design.height * s)
+ .contentShape(Rectangle())
+ .onTapGesture(coordinateSpace: .local) { point in
+ // The nearest button to the touch, so the close face buttons each get the most room a finger can have.
+ guard let tap, let e = Self.nearest(to: CGPoint(x: point.x / s, y: point.y / s)) else { return }
+ tap(e)
+ }
+ .allowsHitTesting(tap != nil)
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+ }
+
+ /// The mappable element nearest a point of the design space, within a finger's reach (nil for the body or the Xbox button).
+ nonisolated static func nearest(to point: CGPoint) -> PadElement? {
+ let candidates = PadElement.allCases.filter { PadMap.button(at: $0) != nil }
+ let distances = candidates.map { e -> (PadElement, CGFloat) in
+ let f = frame(e)
+ // To the element's edge, so a wide bumper is as easy to hit at its end as at its middle.
+ let dx = max(0, abs(point.x - f.center.x) - f.size.width / 2), dy = max(0, abs(point.y - f.center.y) - f.size.height / 2)
+ return (e, hypot(dx, dy))
+ }
+ guard let best = distances.min(by: { $0.1 < $1.1 }), best.1 <= 18 else { return nil }
+ return best.0
+ }
+
+ /// One VoiceOver button per mappable element, at least 44 points, over the drawing. Touch goes through the nearest-button tap.
+ private func hotspots(s: CGFloat, tap: @escaping (PadElement) -> Void) -> some View {
+ ForEach(PadElement.allCases.filter { PadMap.button(at: $0) != nil }, id: \.self) { e in
+ let f = Self.frame(e)
+ let button = PadMap.button(at: e) ?? ""
+ Color.clear
+ .frame(width: max(44, f.size.width * s), height: max(44, f.size.height * s))
+ .position(x: f.center.x * s, y: f.center.y * s)
+ .accessibilityElement()
+ .accessibilityLabel(PadMap.label(button) + ", " + PadMap.place(button))
+ .accessibilityValue(value(e))
+ .accessibilityAddTraits(.isButton)
+ .accessibilityAction { tap(e) }
+ .accessibilityIdentifier("padMapping.drawing.\(button)")
+ }
+ }
+
+ /// A cream ring around a button the mapping changed, in the button's own shape.
+ @ViewBuilder private func ring(_ e: PadElement, s: CGFloat) -> some View {
+ let f = Self.frame(e)
+ let line = max(1.5, 2 * s)
+ let size = CGSize(width: f.size.width + 7, height: f.size.height + 7)
+ switch e {
+ case .leftBumper, .rightBumper:
+ place(Capsule().stroke(ShellPalette.cream, lineWidth: line), center: f.center, size: size, s: s)
+ case .leftTrigger, .rightTrigger, .up, .down, .left, .right:
+ place(RoundedRectangle(cornerRadius: 6 * s).stroke(ShellPalette.cream, lineWidth: line), center: f.center, size: size, s: s)
+ default:
+ place(Circle().stroke(ShellPalette.cream, lineWidth: line), center: f.center, size: size, s: s)
+ }
+ }
+
+ @ViewBuilder private func drawing(s: CGFloat) -> some View {
trigger(.leftTrigger, value: snapshot.leftTrigger, x: 62, s: s)
trigger(.rightTrigger, value: snapshot.rightTrigger, x: 216, s: s)
bumper(.leftBumper, x: 52, s: s)
@@ -129,18 +229,16 @@ struct XboxControllerDiagram: View {
stick(.leftStick, at: CGPoint(x: 88, y: 92), offset: snapshot.leftStick, s: s)
stick(.rightStick, at: CGPoint(x: 202, y: 140), offset: snapshot.rightStick, s: s)
dpad(center: CGPoint(x: 118, y: 140), s: s)
- face(.y, at: CGPoint(x: 240, y: 70), color: Color(red: 0.98, green: 0.80, blue: 0.20), s: s)
- face(.x, at: CGPoint(x: 219, y: 92), color: Color(red: 0.25, green: 0.55, blue: 1.0), s: s)
- face(.b, at: CGPoint(x: 261, y: 92), color: Color(red: 0.95, green: 0.30, blue: 0.28), s: s)
- face(.a, at: CGPoint(x: 240, y: 114), color: Color(red: 0.35, green: 0.80, blue: 0.30), s: s)
- small(.view, symbol: "rectangle.on.rectangle", at: CGPoint(x: 138, y: 92), s: s)
- small(.menu, symbol: "line.3.horizontal", at: CGPoint(x: 182, y: 92), s: s)
+ // Xbox's colours in the test. On the mapping card the letters are the Switch's, at other places, so one quiet colour.
+ face(.y, at: CGPoint(x: 240, y: 70), color: switchNames ? Self.neutral : Color(red: 0.98, green: 0.80, blue: 0.20), s: s)
+ face(.x, at: CGPoint(x: 219, y: 92), color: switchNames ? Self.neutral : Color(red: 0.25, green: 0.55, blue: 1.0), s: s)
+ face(.b, at: CGPoint(x: 261, y: 92), color: switchNames ? Self.neutral : Color(red: 0.95, green: 0.30, blue: 0.28), s: s)
+ face(.a, at: CGPoint(x: 240, y: 114), color: switchNames ? Self.neutral : Color(red: 0.35, green: 0.80, blue: 0.30), s: s)
+ small(.view, symbol: switchNames ? "minus" : "rectangle.on.rectangle", at: CGPoint(x: 138, y: 92), s: s)
+ small(.menu, symbol: switchNames ? "plus" : "line.3.horizontal", at: CGPoint(x: 182, y: 92), s: s)
home(at: CGPoint(x: 160, y: 60), s: s)
- }
- .frame(width: Self.design.width * s, height: Self.design.height * s)
- .frame(maxWidth: .infinity, maxHeight: .infinity)
- }
}
+ private static let neutral = Color(white: 0.82)
private func held(_ e: PadElement) -> Bool { snapshot.pressed.contains(e) }
@@ -157,7 +255,7 @@ struct XboxControllerDiagram: View {
shape.fill(Color.white.opacity(0.06))
shape.fill(ShellPalette.cream.opacity(0.9)).scaleEffect(x: 1, y: max(0, min(1, held(e) && value < 0.05 ? 1 : value)), anchor: .bottom)
shape.stroke(Color.white.opacity(on ? 0.9 : 0.35), lineWidth: max(1, 1.4 * s))
- Text(Self.name(e)).font(ShellFonts.fixed(9 * s, weight: .bold)).foregroundStyle(on ? .black : .white.opacity(0.7))
+ Text(label(e)).font(ShellFonts.fixed(9 * s, weight: .bold)).foregroundStyle(on ? .black : .white.opacity(0.7))
.frame(maxHeight: .infinity)
},
center: CGPoint(x: x + 21, y: 13), size: CGSize(width: 42, height: 22), s: s)
@@ -169,7 +267,7 @@ struct XboxControllerDiagram: View {
ZStack {
Capsule().fill(on ? ShellPalette.cream : Color.white.opacity(0.06))
Capsule().stroke(Color.white.opacity(on ? 0.9 : 0.35), lineWidth: max(1, 1.4 * s))
- Text(Self.name(e)).font(ShellFonts.fixed(8 * s, weight: .bold)).foregroundStyle(on ? .black : .white.opacity(0.7))
+ Text(label(e)).font(ShellFonts.fixed(8 * s, weight: .bold)).foregroundStyle(on ? .black : .white.opacity(0.7))
},
center: CGPoint(x: x + 36, y: 32), size: CGSize(width: 72, height: 12), s: s)
}
@@ -204,7 +302,7 @@ struct XboxControllerDiagram: View {
ZStack {
Circle().fill(on ? color : Color.black.opacity(0.35))
Circle().stroke(on ? Color.white : color.opacity(0.8), lineWidth: max(1, 1.5 * s))
- Text(Self.name(e)).font(ShellFonts.fixed(11 * s, weight: .heavy)).foregroundStyle(on ? .black : color)
+ Text(label(e)).font(ShellFonts.fixed(11 * s, weight: .heavy)).foregroundStyle(on ? .black : color)
}
.shadow(color: on ? color.opacity(0.8) : .clear, radius: 8 * s),
center: c, size: CGSize(width: 20, height: 20), s: s)
diff --git a/frontend-ios/Sources/ShellUI/LibraryView.swift b/frontend-ios/Sources/ShellUI/LibraryView.swift
index eb5e2ef8..9b764de9 100644
--- a/frontend-ios/Sources/ShellUI/LibraryView.swift
+++ b/frontend-ios/Sources/ShellUI/LibraryView.swift
@@ -217,6 +217,7 @@ public struct LibraryView: View {
.transition(.opacity)
PadMappingCard(title: padMappingTitle(padMapping.gameID), rows: padMappingRows(padMapping.gameID),
inherited: padMapping.gameID == ControllersView.mappingID ? nil : globalPadMap, openRow: padMapping.row,
+ held: padSnapshot?.pressed ?? [],
open: openPadRow, pick: pickPadValue, backToList: closePadRow, reset: resetPadMapping, close: closePadMapping)
.padding(.horizontal, 16).padding(.vertical, 12)
.frame(maxWidth: .infinity, maxHeight: .infinity)
@@ -456,11 +457,18 @@ public struct LibraryView: View {
noteTouch()
returnFocus = focus.id
padMapping = PadMappingState(gameID: id)
+ // A button held on a controller lights its place on the card's drawing, as in the button test.
+ actions.onButtonTest(true)
// The swap's current segment, or the first button while a game's swap is neither on, off nor the shell's.
let swap = padMappingRows(id).first
focus.id = swap?.value == "custom" ? "map.row.pad.A" : "map.swap." + (swap?.value ?? "")
}
- private func closePadMapping() { padMapping = nil; focus.id = returnFocus }
+ private func closePadMapping() {
+ guard padMapping != nil else { return }
+ padMapping = nil
+ actions.onButtonTest(false)
+ focus.id = returnFocus
+ }
private func openPadRow(_ row: String) {
noteTouch()
padMapping?.row = row
diff --git a/frontend-ios/Sources/ShellUI/PadMap.swift b/frontend-ios/Sources/ShellUI/PadMap.swift
index 5c56a1dd..27a9a0cf 100644
--- a/frontend-ios/Sources/ShellUI/PadMap.swift
+++ b/frontend-ios/Sources/ShellUI/PadMap.swift
@@ -49,6 +49,33 @@ public struct PadMap: Equatable, Sendable {
}
public static var options: [SettingOption] { (buttons + ["none"]).map { SettingOption($0, label($0)) } }
+ /// The Switch button at an element's place on the drawn controller, by position as the engine maps a controller: the
+ /// right face button (Xbox's B) is A, the bottom one B, the top one X, the left one Y, View is − and Menu is +.
+ /// Nil for the Xbox button, which no game sees.
+ static func button(at element: PadElement) -> String? {
+ switch element {
+ case .b: "A"
+ case .a: "B"
+ case .y: "X"
+ case .x: "Y"
+ case .leftBumper: "L"
+ case .rightBumper: "R"
+ case .leftTrigger: "ZL"
+ case .rightTrigger: "ZR"
+ case .leftStick: "LS"
+ case .rightStick: "RS"
+ case .menu: "Plus"
+ case .view: "Minus"
+ case .up: "Up"
+ case .down: "Down"
+ case .left: "Left"
+ case .right: "Right"
+ case .home: nil
+ }
+ }
+ /// The element a Switch button sits at on the drawing.
+ static func element(of button: String) -> PadElement? { PadElement.allCases.first { self.button(at: $0) == button } }
+
/// The 16 buttons in the four groups the mapping card shows, each with its heading. The D-pad reads up, down, left, right.
static var groups: [(title: String, buttons: [String])] {
[(ShellStrings.text("Face buttons"), ["A", "B", "X", "Y"]),
diff --git a/frontend-ios/Sources/ShellUI/PadMappingView.swift b/frontend-ios/Sources/ShellUI/PadMappingView.swift
index 68c397f2..2358c914 100644
--- a/frontend-ios/Sources/ShellUI/PadMappingView.swift
+++ b/frontend-ios/Sources/ShellUI/PadMappingView.swift
@@ -98,6 +98,8 @@ struct PadMappingCard: View {
/// The shell's map, which a game's rows follow until they are changed. Nil on the shell's own card.
var inherited: PadMap?
let openRow: String?
+ /// The buttons held on a connected controller, lit on the drawing. Empty without one.
+ var held: Set<PadElement> = []
let open: (String) -> Void
let pick: (String, String) -> Void
let backToList: () -> Void
@@ -213,6 +215,7 @@ struct PadMappingCard: View {
Text(ShellStrings.text(isGame ? "For this game only. A button left alone does what it does in all games."
: "For controllers in games only. This app’s menus keep A to confirm and B to go back."))
.shellType(ShellType.note).foregroundStyle(.white.opacity(0.5)).fixedSize(horizontal: false, vertical: true)
+ drawing
if let swapRow { swap(swapRow) }
ForEach(PadMap.groups, id: \.title) { group in
VStack(alignment: .leading, spacing: 10) {
@@ -236,6 +239,34 @@ struct PadMappingCard: View {
.padding(.horizontal, 20).padding(.vertical, 18)
}
+ /// The controller as the button test draws it, with the Switch names of its places. A tap on a button opens its choices,
+ /// as its row does. A cream ring marks a changed button, a button held on a connected controller lights up. The rows
+ /// below stay the way for a controller and say the same in words.
+ private var drawing: some View {
+ func row(_ e: PadElement) -> SettingRow? {
+ PadMap.button(at: e).flatMap { button in rows.first { PadMappingRows.button(of: $0) == button } }
+ }
+ let marked = Set(rows.filter { !$0.fromShell }.compactMap { PadMap.element(of: PadMappingRows.button(of: $0)) })
+ return VStack(spacing: 10) {
+ XboxControllerDiagram(snapshot: PadSnapshot(pressed: held), switchNames: true, marked: marked,
+ tap: { e in if let row = row(e) { open(row.id) } },
+ value: { e in
+ guard let row = row(e) else { return "" }
+ let sends = PadMap.label(PadMappingRows.output(of: row, inherited: inherited))
+ return row.fromShell ? sends : sends + ", " + ShellStrings.text("Changed")
+ })
+ .aspectRatio(XboxControllerDiagram.design.width / XboxControllerDiagram.design.height, contentMode: .fit)
+ .frame(maxWidth: 420)
+ .accessibilityElement(children: .contain)
+ .accessibilityLabel(ShellStrings.text("Controller"))
+ .accessibilityIdentifier("padMapping.drawing")
+ Text(ShellStrings.text("Tap a button to change what it sends."))
+ .shellType(ShellType.note).foregroundStyle(.white.opacity(0.45)).multilineTextAlignment(.center)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .frame(maxWidth: .infinity)
+ }
+
/// Swap A and B: Off and On, and for a game first the shell's choice. Equal segments, stacked when they do not fit.
private func swap(_ row: SettingRow) -> some View {
// The shell's choice reads All games in a segment, short enough for three segments on a phone.
diff --git a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
index cd80ebce..ebecb56c 100644
--- a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
+++ b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
@@ -5105,6 +5105,46 @@
}
}
},
+ "Tap a button to change what it sends.": {
+ "localizations": {
+ "de": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tippe auf eine Taste, um zu ändern, was sie auslöst."
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tap a button to change what it sends."
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Touchez un bouton pour changer ce qu’il envoie."
+ }
+ },
+ "it": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tocca un tasto per cambiare cosa invia."
+ }
+ },
+ "sv": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tryck på en knapp för att ändra vad den skickar."
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "点按某个按键即可更改它对应的键。"
+ }
+ }
+ }
+ },
"The first start waits a few minutes for it, once.": {
"localizations": {
"de": {
diff --git a/frontend-ios/Sources/ShellUI/ShellInputs.swift b/frontend-ios/Sources/ShellUI/ShellInputs.swift
index 4533d0ef..4a91d475 100644
--- a/frontend-ios/Sources/ShellUI/ShellInputs.swift
+++ b/frontend-ios/Sources/ShellUI/ShellInputs.swift
@@ -214,7 +214,7 @@ public struct ShellActions {
public var onClearShellCloud: () -> Void
public var onGlobalPadMapChange: (String, String) -> Void
public var onGlobalPadMapReset: () -> Void
- /// The button test opened (true) or closed: the host sends `PadSnapshot`s only in between.
+ /// The button test or the mapping card opened (true) or closed: the host sends `PadSnapshot`s only in between.
public var onButtonTest: (Bool) -> Void
/// Deletes the game's data on this device and takes it off the list. `saves`: its saves go too.
public var onDeleteGame: (_ gameID: String, _ saves: Bool) -> Void
diff --git a/frontend-ios/Tests/ShellUITests/PadMapTests.swift b/frontend-ios/Tests/ShellUITests/PadMapTests.swift
index 5a81f19d..437b5c9e 100644
--- a/frontend-ios/Tests/ShellUITests/PadMapTests.swift
+++ b/frontend-ios/Tests/ShellUITests/PadMapTests.swift
@@ -71,6 +71,26 @@ import Testing
let shellRow = PadMappingRows.global(global)[1]
#expect(PadMappingRows.button(of: shellRow) == "A" && PadMappingRows.output(of: shellRow, inherited: nil) == "B")
}
+ @Test func everyButtonHasItsPlaceOnTheDrawing() {
+ for button in PadMap.buttons {
+ let element = PadMap.element(of: button)
+ #expect(element != nil && element.flatMap(PadMap.button(at:)) == button, "\(button)")
+ }
+ // By position, as the engine maps a controller: Xbox's B (right) is A, its A (bottom) is B.
+ #expect(PadMap.button(at: .b) == "A" && PadMap.button(at: .a) == "B" && PadMap.button(at: .y) == "X" && PadMap.button(at: .x) == "Y")
+ #expect(PadMap.button(at: .home) == nil)
+ }
+ @Test func aTouchPicksTheNearestButton() {
+ for element in PadElement.allCases where element != .home {
+ #expect(XboxControllerDiagram.nearest(to: XboxControllerDiagram.frame(element).center) == element, "\(element)")
+ }
+ // Between the right and the bottom face button, nearer the right one.
+ #expect(XboxControllerDiagram.nearest(to: CGPoint(x: 256, y: 99)) == .b)
+ // The end of a bumper, the controller's body and the Xbox button pick nothing else.
+ #expect(XboxControllerDiagram.nearest(to: CGPoint(x: 56, y: 32)) == .leftBumper)
+ #expect(XboxControllerDiagram.nearest(to: CGPoint(x: 160, y: 200)) == nil)
+ #expect(XboxControllerDiagram.nearest(to: XboxControllerDiagram.frame(.home).center) == nil)
+ }
@Test func theCardGroupsEveryButtonOnce() {
let grouped = PadMap.groups.flatMap(\.buttons)
#expect(grouped.count == PadMap.buttons.count && Set(grouped) == Set(PadMap.buttons))
diff --git a/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift b/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift
index 22fb14d1..ada926bd 100644
--- a/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift
+++ b/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift
@@ -56,8 +56,9 @@ final class PadMappingCaptureTests: XCTestCase {
}
}
- private func card(_ title: String, rows: [SettingRow], inherited: PadMap?, open: String? = nil) -> some View {
- PadMappingCard(title: title, rows: rows, inherited: inherited, openRow: open, open: { _ in }, pick: { _, _ in },
+ private func card(_ title: String, rows: [SettingRow], inherited: PadMap?, open: String? = nil,
+ held: Set<PadElement> = []) -> some View {
+ PadMappingCard(title: title, rows: rows, inherited: inherited, openRow: open, held: held, open: { _ in }, pick: { _, _ in },
backToList: {}, reset: {}, close: {})
.padding(16)
.background(Color.black.opacity(0.55))
@@ -77,6 +78,8 @@ final class PadMappingCaptureTests: XCTestCase {
func testCaptureTheCardOfAGame() throws {
try capture("pad-card-game", width: 512, card("Hades II", rows: gameRows, inherited: global))
+ // A controller's bottom face button held while the card is open: its place (B on a Switch) lights up.
+ try capture("pad-card-game-held", width: 512, card("Hades II", rows: gameRows, inherited: global, held: [.a]))
try capture("pad-card-game-options", width: 512, card("Hades II", rows: gameRows, inherited: global, open: "pad.Y"))
// A phone: the card at the width an iPhone gives it.
try capture("pad-card-game-phone", width: 393, card("Hades II", rows: gameRows, inherited: global))
diff --git a/frontend/l10n/de.json b/frontend/l10n/de.json
index ca3eb220..7d55ed20 100644
--- a/frontend/l10n/de.json
+++ b/frontend/l10n/de.json
@@ -657,6 +657,7 @@
"ios.ui.padSwapAB": "A und B tauschen",
"ios.ui.padSwapNote": "Legt A auf die untere Taste, wo Xbox- und PlayStation-Controller bestätigen.",
"ios.ui.padSwapped": "A und B getauscht",
+ "ios.ui.padTapDrawing": "Tippe auf eine Taste, um zu ändern, was sie auslöst.",
"ios.ui.padTestNote": "Jede Taste leuchtet auf, wenn du sie drückst.",
"ios.ui.padTopButton": "Obere Taste",
"ios.ui.padUp": "Oben",
diff --git a/frontend/l10n/en.json b/frontend/l10n/en.json
index c9710a99..271795a8 100644
--- a/frontend/l10n/en.json
+++ b/frontend/l10n/en.json
@@ -758,6 +758,7 @@
"ios.ui.padSwapAB": "Swap A and B",
"ios.ui.padSwapNote": "Puts A on the bottom button, where Xbox and PlayStation controllers confirm.",
"ios.ui.padSwapped": "A and B swapped",
+ "ios.ui.padTapDrawing": "Tap a button to change what it sends.",
"ios.ui.padTestNote": "See each button light up as you press it.",
"ios.ui.padTopButton": "Top button",
"ios.ui.padUp": "Up",
diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.json
index 4bdc6420..4fa68274 100644
--- a/frontend/l10n/fr.json
+++ b/frontend/l10n/fr.json
@@ -659,6 +659,7 @@
"ios.ui.padSwapAB": "Inverser A et B",
"ios.ui.padSwapNote": "Place A sur le bouton du bas, là où les manettes Xbox et PlayStation valident.",
"ios.ui.padSwapped": "A et B inversés",
+ "ios.ui.padTapDrawing": "Touchez un bouton pour changer ce qu’il envoie.",
"ios.ui.padTestNote": "Chaque bouton s’allume quand vous appuyez dessus.",
"ios.ui.padTopButton": "Bouton du haut",
"ios.ui.padUp": "Haut",
diff --git a/frontend/l10n/it.json b/frontend/l10n/it.json
index 1de8d919..e0b1c219 100644
--- a/frontend/l10n/it.json
+++ b/frontend/l10n/it.json
@@ -660,6 +660,7 @@
"ios.ui.padSwapAB": "Scambia A e B",
"ios.ui.padSwapNote": "Mette A sul tasto in basso, dove confermano i controller Xbox e PlayStation.",
"ios.ui.padSwapped": "A e B scambiati",
+ "ios.ui.padTapDrawing": "Tocca un tasto per cambiare cosa invia.",
"ios.ui.padTestNote": "Ogni tasto si illumina quando lo premi.",
"ios.ui.padTopButton": "Tasto in alto",
"ios.ui.padUp": "Su",
diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.json
index f85c6dcd..7398089a 100644
--- a/frontend/l10n/sv.json
+++ b/frontend/l10n/sv.json
@@ -502,6 +502,7 @@
"ios.ui.padSwapAB": "Byt A och B",
"ios.ui.padSwapNote": "Lägger A på den nedre knappen, där Xbox- och PlayStation-handkontroller bekräftar.",
"ios.ui.padSwapped": "A och B bytta",
+ "ios.ui.padTapDrawing": "Tryck på en knapp för att ändra vad den skickar.",
"ios.ui.padTestNote": "Se varje knapp lysa upp när du trycker på den.",
"ios.ui.padTopButton": "Övre knappen",
"ios.ui.padUp": "Upp",
diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.json
index dfa965d5..0fb3b60c 100644
--- a/frontend/l10n/zh.json
+++ b/frontend/l10n/zh.json
@@ -759,6 +759,7 @@
"ios.ui.padSwapAB": "交换 A 和 B",
"ios.ui.padSwapNote": "把 A 放到下方按键,与 Xbox 和 PlayStation 手柄的确认键位置一致。",
"ios.ui.padSwapped": "已交换 A 和 B",
+ "ios.ui.padTapDrawing": "点按某个按键即可更改它对应的键。",
"ios.ui.padTestNote": "按下按键时,对应的位置会亮起。",
"ios.ui.padTopButton": "上方按键",
"ios.ui.padUp": "上",