Manic EMU is an all-in-one retro game emulator for iOS. It packs powerful features while keeping a clean, sleek UI and delivering buttery-smooth gameplay.
Swift
Focus Kit is complete, now with full controller navigation support
Daiunoace976fc9c0e
diff --git a/Dependencies/Libretro b/Dependencies/Libretroindex 4afce318..3305ec7f 160000--- a/Dependencies/Libretro+++ b/Dependencies/Libretro@@ -1 +1 @@-Subproject commit 4afce318b5960dedbb772316835469d2ecb5445b+Subproject commit 3305ec7f8cf0b4a773ad282893b1bbbb5a246de5diff --git a/ManicEmu/ManicEmu.xcodeproj/project.pbxproj b/ManicEmu/ManicEmu.xcodeproj/project.pbxprojindex e9d55add..42a1bc08 100644--- a/ManicEmu/ManicEmu.xcodeproj/project.pbxproj+++ b/ManicEmu/ManicEmu.xcodeproj/project.pbxproj@@ -373,6 +373,8 @@57B6ECCD2D798425002E619C /* CheatTypeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57B6ECCC2D798419002E619C /* CheatTypeExtensions.swift */; };57B6ECF52D79F1EA002E619C /* SkinSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57B6ECF42D79F1E4002E619C /* SkinSettingsView.swift */; };57BA59B52E3F13D100110849 /* LibretroCoreExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57BA59B42E3F13C900110849 /* LibretroCoreExtensions.swift */; };+ 57BA7467303486ED0039E284 /* FocusShortcutsTipsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57BA7463303486E20039E284 /* FocusShortcutsTipsView.swift */; };+ 57BA7468303486ED0039E284 /* FocusShortcutsTipsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57BA7463303486E20039E284 /* FocusShortcutsTipsView.swift */; };57BF5ECB2FDB08FE0073D318 /* ASSwitchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57BF5EC72FDB08F60073D318 /* ASSwitchView.swift */; };57BF5ECC2FDB08FE0073D318 /* ASSwitchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57BF5EC72FDB08F60073D318 /* ASSwitchView.swift */; };57BF5ED92FDB09A80073D318 /* ASCheckView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57BF5ED52FDB09A00073D318 /* ASCheckView.swift */; };@@ -1507,6 +1509,7 @@57B6ECF42D79F1E4002E619C /* SkinSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkinSettingsView.swift; sourceTree = "<group>"; };57BA45C12D1B235400BCA5E1 /* Config-Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Config-Base.xcconfig"; sourceTree = "<group>"; };57BA59B42E3F13C900110849 /* LibretroCoreExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibretroCoreExtensions.swift; sourceTree = "<group>"; };+ 57BA7463303486E20039E284 /* FocusShortcutsTipsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FocusShortcutsTipsView.swift; sourceTree = "<group>"; };57BF5EC72FDB08F60073D318 /* ASSwitchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASSwitchView.swift; sourceTree = "<group>"; };57BF5ED52FDB09A00073D318 /* ASCheckView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASCheckView.swift; sourceTree = "<group>"; };57BF5EDC2FDB09AC0073D318 /* ASRadioView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASRadioView.swift; sourceTree = "<group>"; };@@ -3038,6 +3041,7 @@F0C500000000000000000106 /* FocusCollectionView.swift */,F0C500000000000000000107 /* FocusSystem.swift */,F0C500000000000000000108 /* FocusSystem+UIViewController.swift */,+ 57BA7463303486E20039E284 /* FocusShortcutsTipsView.swift */,);path = FocusKit;sourceTree = "<group>";@@ -3615,6 +3619,7 @@57CDCE402FD5CBD3005BA4C8 /* SkinCollectionViewCell.swift in Sources */,57CDCE412FD5CBD3005BA4C8 /* Shaders.metal in Sources */,57CDCE422FD5CBD3005BA4C8 /* PersistedKit.swift in Sources */,+ 57BA7467303486ED0039E284 /* FocusShortcutsTipsView.swift in Sources */,57CDCE432FD5CBD3005BA4C8 /* GlobalCoreSwitchView.swift in Sources */,57744AE52FD91CBF00DECBC7 /* ASProgressView.swift in Sources */,57BF60082FE05CC90073D318 /* ASListInputView.swift in Sources */,@@ -4010,6 +4015,7 @@57CCB3A92D66CE610036476B /* SkinCollectionViewCell.swift in Sources */,5706B0FA2DFFED100066122E /* Shaders.metal in Sources */,576060182D22BC5900A98B0C /* PersistedKit.swift in Sources */,+ 57BA7468303486ED0039E284 /* FocusShortcutsTipsView.swift in Sources */,578E4B502F8A2AA60027E6D0 /* GlobalCoreSwitchView.swift in Sources */,57744AE62FD91CBF00DECBC7 /* ASProgressView.swift in Sources */,57BF60092FE05CC90073D318 /* ASListInputView.swift in Sources */,diff --git a/ManicEmu/ManicEmu.xcodeproj/xcshareddata/xcschemes/ManicEmuRelease.xcscheme b/ManicEmu/ManicEmu.xcodeproj/xcshareddata/xcschemes/ManicEmuRelease.xcschemeindex e3f6b9aa..bf39d4e8 100644--- a/ManicEmu/ManicEmu.xcodeproj/xcshareddata/xcschemes/ManicEmuRelease.xcscheme+++ b/ManicEmu/ManicEmu.xcodeproj/xcshareddata/xcschemes/ManicEmuRelease.xcscheme@@ -73,7 +73,7 @@buildConfiguration = "Debug"></AnalyzeAction><ArchiveAction- buildConfiguration = "SideloadRelease"+ buildConfiguration = "Release"revealArchiveInOrganizer = "YES"></ArchiveAction></Scheme>diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/sel_iconSymbols.symbolset/Contents.json b/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/sel_iconSymbols.symbolset/Contents.jsonnew file mode 100644index 00000000..4efd7125--- /dev/null+++ b/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/sel_iconSymbols.symbolset/Contents.json@@ -0,0 +1,12 @@+{+ "info" : {+ "author" : "xcode",+ "version" : 1+ },+ "symbols" : [+ {+ "filename" : "sel_iconSymbols.svg",+ "idiom" : "universal"+ }+ ]+}diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/sel_iconSymbols.symbolset/sel_iconSymbols.svg b/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/sel_iconSymbols.symbolset/sel_iconSymbols.svgnew file mode 100644index 00000000..84f5a709--- /dev/null+++ b/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/sel_iconSymbols.symbolset/sel_iconSymbols.svg@@ -0,0 +1,49 @@+<?xml version="1.0" encoding="UTF-8"?>+<svg height="600" width="800" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">+ <g id="Notes" font-family="'LucidaGrande', 'Lucida Grande', sans-serif" font-size="13">+ <rect fill="white" height="600.0" width="800.0" x="0.0" y="0.0" />+ <g font-size="13">+ <text x="18.0" y="176.0">Small</text>+ <text x="18.0" y="376.0">Medium</text>+ <text x="18.0" y="576.0">Large</text>+ </g>+ <g font-size="9">+ <text x="250.0" y="30.0">Ultralight</text>+ <text x="450.0" y="30.0">Regular</text>+ <text x="650.0" y="30.0">Black</text>+ <text id="template-version" fill="#505050" text-anchor="end" x="785.0" y="575.0">Template v.3.0</text>+ <a href="https://wangchujiang.com/#/app">+ <text fill="#505050" text-anchor="end" x="785.0" y="590.0">https://wangchujiang.com/#/app</text>+ </a>+ </g>+ </g>+ <g id="Guides" stroke="rgb(39, 170, 225)" stroke-width="0.5">+ <path id="Capline-S" d="M18,76 l800,0" />+ <path id="H-reference" d="M85,145.755 L87.685,145.755 L113.369,79.287 L114.052,79.287 L114.052,76 L112.148,76 L85,145.755 Z M95.693,121.536 L130.996,121.536 L130.263,119.313 L96.474,119.313 L95.693,121.536 Z M139.15,145.755 L141.787,145.755 L114.638,76 L113.466,76 L113.466,79.287 L139.15,145.755 Z" stroke="none" />+ <path id="Baseline-S" d="M18,146 l800,0" />+ <path id="left-margin-Ultralight-S" d="M211,56 l0,110" />+ <path id="right-margin-Ultralight-S" d="M319,56 l0,110" />+ <path id="left-margin-Regular-S" d="M411,56 l0,110" />+ <path id="right-margin-Regular-S" d="M519,56 l0,110" />+ <path id="left-margin-Black-S" d="M611,56 l0,110" />+ <path id="right-margin-Black-S" d="M719,56 l0,110" />+ <path id="Capline-M" d="M18,276 l800,0" />+ <path id="Baseline-M" d="M18,346 l800,0" />+ <path id="Capline-L" d="M18,476 l800,0" />+ <path id="Baseline-L" d="M18,546 l800,0" />+ </g>+ <g id="Symbols">+ <g id="Ultralight-S">+ <path d="M229.842,90.389 C228.798,90.39 227.797,90.805 227.059,91.543 C226.321,92.281 225.906,93.282 225.904,94.326 L225.904,127.705 C225.906,128.749 226.321,129.75 227.059,130.488 C227.797,131.226 228.798,131.641 229.842,131.643 L300.158,131.643 C301.203,131.643 302.204,131.228 302.942,130.489 C303.681,129.751 304.095,128.75 304.095,127.705 L304.095,94.31 C304.09,93.269 303.673,92.272 302.935,91.538 C302.198,90.803 301.199,90.39 300.158,90.389 L229.842,90.389 Z M300.153,136.521 L229.842,136.521 C227.497,136.521 225.248,135.589 223.59,133.931 C221.932,132.273 221,130.024 221,127.679 L221,94.31 C221,91.965 221.932,89.716 223.59,88.058 C225.248,86.4 227.497,85.469 229.842,85.469 L300.158,85.469 C302.503,85.469 304.752,86.4 306.41,88.058 C308.068,89.716 309,91.965 309,94.31 L309,127.69 C309,130.035 308.068,132.284 306.41,133.942 C304.752,135.6 302.503,136.531 300.158,136.531 L300.153,136.521 Z" />+ <path d="M296.689,120.169 L285.767,120.169 L285.767,98.034 C285.767,97.684 285.628,97.348 285.38,97.1 C285.133,96.852 284.797,96.713 284.446,96.713 L281.981,96.713 C281.806,96.711 281.633,96.743 281.471,96.809 C281.309,96.874 281.161,96.971 281.037,97.094 C280.912,97.217 280.814,97.363 280.746,97.525 C280.679,97.686 280.644,97.859 280.644,98.034 L280.644,123.961 C280.644,124.135 280.679,124.307 280.745,124.467 C280.812,124.628 280.91,124.774 281.033,124.897 C281.156,125.019 281.303,125.117 281.463,125.183 C281.624,125.249 281.797,125.282 281.971,125.282 L296.705,125.282 C297.055,125.28 297.39,125.141 297.637,124.893 C297.885,124.646 298.024,124.311 298.026,123.961 L298.026,121.501 C298.026,121.325 297.991,121.152 297.924,120.99 C297.857,120.828 297.758,120.681 297.634,120.557 C297.51,120.434 297.363,120.336 297.2,120.269 C297.038,120.202 296.865,120.169 296.689,120.169 Z M275.963,98.039 C275.963,97.865 275.929,97.693 275.862,97.532 C275.796,97.372 275.698,97.226 275.575,97.103 C275.451,96.98 275.305,96.883 275.144,96.817 C274.983,96.751 274.811,96.717 274.637,96.718 L259.903,96.718 C259.553,96.719 259.217,96.859 258.969,97.106 C258.72,97.354 258.579,97.689 258.577,98.039 L258.577,123.961 C258.578,124.311 258.718,124.648 258.967,124.895 C259.216,125.143 259.552,125.282 259.903,125.282 L274.637,125.282 C274.987,125.28 275.322,125.141 275.57,124.893 C275.817,124.646 275.957,124.311 275.958,123.961 L275.958,121.501 C275.958,121.15 275.819,120.813 275.572,120.565 C275.324,120.316 274.988,120.176 274.637,120.174 L263.715,120.174 L263.715,113.554 L269.707,113.554 C270.05,113.543 270.376,113.399 270.616,113.153 C270.856,112.906 270.99,112.576 270.991,112.232 L270.991,109.767 C270.99,109.419 270.852,109.085 270.607,108.838 C270.361,108.591 270.029,108.45 269.681,108.446 L263.694,108.446 L263.694,101.831 L274.616,101.831 C274.793,101.833 274.969,101.801 275.133,101.735 C275.297,101.669 275.446,101.571 275.571,101.446 C275.697,101.321 275.796,101.173 275.864,101.01 C275.931,100.846 275.965,100.671 275.963,100.494 L275.963,98.039 Z M253.839,115.967 C253.777,115.343 253.627,114.732 253.391,114.152 C252.483,112.087 250.803,110.46 248.711,109.616 C247.417,109.144 246.081,108.795 244.721,108.576 C243.879,108.405 243.036,108.243 242.199,108.056 C241.5,107.92 240.821,107.692 240.181,107.38 C239.364,106.948 238.558,106.511 238.231,105.601 C238.127,105.292 238.091,104.964 238.123,104.64 C238.155,104.316 238.256,104.002 238.418,103.719 C238.941,102.969 239.676,102.393 240.529,102.065 C241.441,101.653 242.431,101.446 243.431,101.458 C244.431,101.47 245.416,101.7 246.318,102.132 C246.554,102.257 246.78,102.4 246.994,102.559 C247.473,102.913 247.906,103.325 248.284,103.786 C248.562,104.148 248.902,104.458 249.288,104.702 C249.75,104.949 250.272,105.064 250.796,105.034 C251.67,105.034 252.876,104.899 253.397,104.083 C253.536,103.877 253.62,103.639 253.641,103.391 C253.643,103.056 253.594,102.723 253.495,102.403 C253.333,101.86 253.082,101.349 252.752,100.889 C252.283,100.244 251.744,99.653 251.145,99.126 C250.994,98.996 250.827,98.892 250.671,98.773 C248.132,96.937 245.011,96.09 241.892,96.39 C240.289,96.587 238.737,97.086 237.32,97.862 C236.154,98.517 235.142,99.417 234.356,100.499 C233.358,101.853 232.839,103.499 232.879,105.18 C232.937,106.851 233.562,108.453 234.652,109.721 C235.186,110.34 235.81,110.875 236.504,111.307 C238.616,112.508 242.225,113.309 245.137,114.001 C246.178,114.256 247.181,114.474 248.008,115.239 C248.275,115.512 248.476,115.843 248.596,116.206 C249.116,117.766 247.884,119.067 246.63,119.738 C245.993,120.058 245.311,120.281 244.607,120.398 C243.726,120.544 242.827,120.533 241.949,120.367 C241.265,120.265 240.603,120.05 239.988,119.732 C239.353,119.324 238.819,118.777 238.428,118.13 C238.297,117.902 238.14,117.689 237.96,117.496 C237.461,117.102 236.83,116.916 236.197,116.976 C235.813,116.983 235.43,117.023 235.053,117.095 C234.713,117.151 234.382,117.247 234.065,117.382 C233.737,117.52 233.47,117.773 233.316,118.094 C233.189,118.391 233.136,118.714 233.16,119.035 C233.164,119.121 233.173,119.206 233.186,119.29 C233.256,119.761 233.418,120.214 233.664,120.622 C234.21,121.556 234.914,122.388 235.745,123.082 C236.005,123.29 236.265,123.487 236.535,123.675 C236.985,123.987 237.46,124.262 237.955,124.496 C239.617,125.249 241.415,125.653 243.239,125.682 C244.292,125.678 245.34,125.545 246.36,125.287 C248.177,124.885 249.854,124.005 251.217,122.738 C251.601,122.374 251.949,121.973 252.258,121.542 C253.416,119.924 253.974,117.952 253.839,115.967 Z" />+ </g>+ <g id="Regular-S">+ <path d="M429.842,90.389 C428.798,90.39 427.797,90.805 427.059,91.543 C426.321,92.281 425.906,93.282 425.904,94.326 L425.904,127.705 C425.906,128.749 426.321,129.75 427.059,130.488 C427.797,131.226 428.798,131.641 429.842,131.643 L500.158,131.643 C501.203,131.643 502.204,131.228 502.942,130.489 C503.681,129.751 504.095,128.75 504.095,127.705 L504.095,94.31 C504.09,93.269 503.673,92.272 502.935,91.538 C502.198,90.803 501.199,90.39 500.158,90.389 L429.842,90.389 Z M500.153,136.521 L429.842,136.521 C427.497,136.521 425.248,135.589 423.59,133.931 C421.932,132.273 421,130.024 421,127.679 L421,94.31 C421,91.965 421.932,89.716 423.59,88.058 C425.248,86.4 427.497,85.469 429.842,85.469 L500.158,85.469 C502.503,85.469 504.752,86.4 506.41,88.058 C508.068,89.716 509,91.965 509,94.31 L509,127.69 C509,130.035 508.068,132.284 506.41,133.942 C504.752,135.6 502.503,136.531 500.158,136.531 L500.153,136.521 Z" />+ <path d="M496.689,120.169 L485.767,120.169 L485.767,98.034 C485.767,97.684 485.628,97.348 485.38,97.1 C485.133,96.852 484.797,96.713 484.446,96.713 L481.981,96.713 C481.806,96.711 481.633,96.743 481.471,96.809 C481.309,96.874 481.161,96.971 481.037,97.094 C480.912,97.217 480.814,97.363 480.746,97.525 C480.679,97.686 480.644,97.859 480.644,98.034 L480.644,123.961 C480.644,124.135 480.679,124.307 480.745,124.467 C480.812,124.628 480.91,124.774 481.033,124.897 C481.156,125.019 481.303,125.117 481.463,125.183 C481.624,125.249 481.797,125.282 481.971,125.282 L496.705,125.282 C497.055,125.28 497.39,125.141 497.637,124.893 C497.885,124.646 498.024,124.311 498.026,123.961 L498.026,121.501 C498.026,121.325 497.991,121.152 497.924,120.99 C497.857,120.828 497.758,120.681 497.634,120.557 C497.51,120.434 497.363,120.336 497.2,120.269 C497.038,120.202 496.865,120.169 496.689,120.169 Z M475.963,98.039 C475.963,97.865 475.929,97.693 475.862,97.532 C475.796,97.372 475.698,97.226 475.575,97.103 C475.451,96.98 475.305,96.883 475.144,96.817 C474.983,96.751 474.811,96.717 474.637,96.718 L459.903,96.718 C459.553,96.719 459.217,96.859 458.969,97.106 C458.72,97.354 458.579,97.689 458.577,98.039 L458.577,123.961 C458.578,124.311 458.718,124.648 458.967,124.895 C459.216,125.143 459.552,125.282 459.903,125.282 L474.637,125.282 C474.987,125.28 475.322,125.141 475.57,124.893 C475.817,124.646 475.957,124.311 475.958,123.961 L475.958,121.501 C475.958,121.15 475.819,120.813 475.572,120.565 C475.324,120.316 474.988,120.176 474.637,120.174 L463.715,120.174 L463.715,113.554 L469.707,113.554 C470.05,113.543 470.376,113.399 470.616,113.153 C470.856,112.906 470.99,112.576 470.991,112.232 L470.991,109.767 C470.99,109.419 470.852,109.085 470.607,108.838 C470.361,108.591 470.029,108.45 469.681,108.446 L463.694,108.446 L463.694,101.831 L474.616,101.831 C474.793,101.833 474.969,101.801 475.133,101.735 C475.297,101.669 475.446,101.571 475.571,101.446 C475.697,101.321 475.796,101.173 475.864,101.01 C475.931,100.846 475.965,100.671 475.963,100.494 L475.963,98.039 Z M453.839,115.967 C453.777,115.343 453.627,114.732 453.391,114.152 C452.483,112.087 450.803,110.46 448.711,109.616 C447.417,109.144 446.081,108.795 444.721,108.576 C443.879,108.405 443.036,108.243 442.199,108.056 C441.5,107.92 440.821,107.692 440.181,107.38 C439.364,106.948 438.558,106.511 438.231,105.601 C438.127,105.292 438.091,104.964 438.123,104.64 C438.155,104.316 438.256,104.002 438.418,103.719 C438.941,102.969 439.676,102.393 440.529,102.065 C441.441,101.653 442.431,101.446 443.431,101.458 C444.431,101.47 445.416,101.7 446.318,102.132 C446.554,102.257 446.78,102.4 446.994,102.559 C447.473,102.913 447.906,103.325 448.284,103.786 C448.562,104.148 448.902,104.458 449.288,104.702 C449.75,104.949 450.272,105.064 450.796,105.034 C451.67,105.034 452.876,104.899 453.397,104.083 C453.536,103.877 453.62,103.639 453.641,103.391 C453.643,103.056 453.594,102.723 453.495,102.403 C453.333,101.86 453.082,101.349 452.752,100.889 C452.283,100.244 451.744,99.653 451.145,99.126 C450.994,98.996 450.827,98.892 450.671,98.773 C448.132,96.937 445.011,96.09 441.892,96.39 C440.289,96.587 438.737,97.086 437.32,97.862 C436.154,98.517 435.142,99.417 434.356,100.499 C433.358,101.853 432.839,103.499 432.879,105.18 C432.937,106.851 433.562,108.453 434.652,109.721 C435.186,110.34 435.81,110.875 436.504,111.307 C438.616,112.508 442.225,113.309 445.138,114.001 C446.178,114.256 447.181,114.474 448.008,115.239 C448.275,115.512 448.476,115.843 448.596,116.206 C449.116,117.766 447.884,119.067 446.63,119.738 C445.993,120.058 445.311,120.281 444.607,120.398 C443.726,120.544 442.827,120.533 441.949,120.367 C441.265,120.265 440.603,120.05 439.988,119.732 C439.353,119.324 438.819,118.777 438.428,118.13 C438.297,117.902 438.14,117.689 437.96,117.496 C437.461,117.102 436.83,116.916 436.197,116.976 C435.813,116.983 435.43,117.023 435.053,117.095 C434.713,117.151 434.382,117.247 434.065,117.382 C433.737,117.52 433.47,117.773 433.316,118.094 C433.189,118.391 433.136,118.714 433.16,119.035 C433.164,119.121 433.173,119.206 433.186,119.29 C433.256,119.761 433.418,120.214 433.664,120.622 C434.21,121.556 434.914,122.388 435.745,123.082 C436.005,123.29 436.265,123.487 436.535,123.675 C436.985,123.987 437.46,124.262 437.955,124.496 C439.617,125.249 441.415,125.653 443.239,125.682 C444.292,125.678 445.34,125.545 446.36,125.287 C448.177,124.885 449.854,124.005 451.217,122.738 C451.601,122.374 451.949,121.973 452.258,121.542 C453.416,119.924 453.974,117.952 453.839,115.967 Z" />+ </g>+ <g id="Black-S">+ <path d="M629.842,90.389 C628.798,90.39 627.797,90.805 627.059,91.543 C626.321,92.281 625.906,93.282 625.904,94.326 L625.904,127.705 C625.906,128.749 626.321,129.75 627.059,130.488 C627.797,131.226 628.798,131.641 629.842,131.643 L700.158,131.643 C701.203,131.643 702.204,131.228 702.942,130.489 C703.681,129.751 704.095,128.75 704.095,127.705 L704.095,94.31 C704.09,93.269 703.673,92.272 702.935,91.538 C702.198,90.803 701.199,90.39 700.158,90.389 L629.842,90.389 Z M700.153,136.521 L629.842,136.521 C627.497,136.521 625.248,135.589 623.59,133.931 C621.932,132.273 621,130.024 621,127.679 L621,94.31 C621,91.965 621.932,89.716 623.59,88.058 C625.248,86.4 627.497,85.469 629.842,85.469 L700.158,85.469 C702.503,85.469 704.752,86.4 706.41,88.058 C708.068,89.716 709,91.965 709,94.31 L709,127.69 C709,130.035 708.068,132.284 706.41,133.942 C704.752,135.6 702.503,136.531 700.158,136.531 L700.153,136.521 Z" />+ <path d="M696.689,120.169 L685.767,120.169 L685.767,98.034 C685.767,97.684 685.628,97.348 685.38,97.1 C685.133,96.852 684.797,96.713 684.446,96.713 L681.981,96.713 C681.806,96.711 681.633,96.743 681.471,96.809 C681.309,96.874 681.161,96.971 681.037,97.094 C680.912,97.217 680.814,97.363 680.746,97.525 C680.679,97.686 680.644,97.859 680.644,98.034 L680.644,123.961 C680.644,124.135 680.679,124.307 680.745,124.467 C680.812,124.628 680.91,124.774 681.033,124.897 C681.156,125.019 681.303,125.117 681.463,125.183 C681.624,125.249 681.797,125.282 681.971,125.282 L696.705,125.282 C697.055,125.28 697.39,125.141 697.637,124.893 C697.885,124.646 698.024,124.311 698.026,123.961 L698.026,121.501 C698.026,121.325 697.991,121.152 697.924,120.99 C697.857,120.828 697.758,120.681 697.634,120.557 C697.51,120.434 697.362,120.336 697.2,120.269 C697.038,120.202 696.865,120.169 696.689,120.169 Z M675.963,98.039 C675.963,97.865 675.929,97.693 675.862,97.532 C675.796,97.372 675.698,97.226 675.575,97.103 C675.451,96.98 675.305,96.883 675.144,96.817 C674.983,96.751 674.811,96.717 674.637,96.718 L659.903,96.718 C659.552,96.719 659.217,96.859 658.969,97.106 C658.72,97.354 658.579,97.689 658.577,98.039 L658.577,123.961 C658.578,124.311 658.718,124.648 658.967,124.895 C659.216,125.143 659.552,125.282 659.903,125.282 L674.637,125.282 C674.987,125.28 675.322,125.141 675.57,124.893 C675.817,124.646 675.957,124.311 675.958,123.961 L675.958,121.501 C675.958,121.15 675.819,120.813 675.572,120.565 C675.324,120.316 674.988,120.176 674.637,120.174 L663.715,120.174 L663.715,113.554 L669.707,113.554 C670.05,113.543 670.376,113.399 670.616,113.153 C670.856,112.906 670.99,112.576 670.991,112.232 L670.991,109.767 C670.99,109.419 670.852,109.085 670.607,108.838 C670.361,108.591 670.029,108.45 669.681,108.446 L663.694,108.446 L663.694,101.831 L674.616,101.831 C674.793,101.833 674.969,101.801 675.133,101.735 C675.297,101.669 675.446,101.571 675.571,101.446 C675.697,101.321 675.796,101.173 675.864,101.01 C675.931,100.846 675.965,100.671 675.963,100.494 L675.963,98.039 Z M653.839,115.967 C653.777,115.343 653.627,114.732 653.391,114.152 C652.483,112.087 650.803,110.46 648.71,109.616 C647.417,109.144 646.081,108.795 644.721,108.576 C643.879,108.405 643.036,108.243 642.199,108.056 C641.5,107.92 640.821,107.692 640.181,107.38 C639.364,106.948 638.558,106.511 638.231,105.601 C638.127,105.292 638.091,104.964 638.123,104.64 C638.155,104.316 638.256,104.002 638.418,103.719 C638.941,102.969 639.676,102.393 640.529,102.065 C641.441,101.653 642.431,101.446 643.431,101.458 C644.431,101.47 645.416,101.7 646.318,102.132 C646.554,102.257 646.78,102.4 646.994,102.559 C647.473,102.913 647.906,103.325 648.284,103.786 C648.562,104.148 648.902,104.458 649.288,104.702 C649.75,104.949 650.272,105.064 650.796,105.034 C651.67,105.034 652.876,104.899 653.397,104.083 C653.536,103.877 653.62,103.639 653.641,103.391 C653.643,103.056 653.594,102.723 653.495,102.403 C653.333,101.86 653.082,101.349 652.752,100.889 C652.283,100.244 651.744,99.653 651.145,99.126 C650.994,98.996 650.827,98.892 650.671,98.773 C648.132,96.937 645.011,96.09 641.892,96.39 C640.289,96.587 638.737,97.086 637.32,97.862 C636.154,98.517 635.142,99.417 634.356,100.499 C633.358,101.853 632.839,103.499 632.879,105.18 C632.937,106.851 633.562,108.453 634.652,109.721 C635.185,110.34 635.81,110.875 636.504,111.307 C638.615,112.508 642.225,113.309 645.137,114.001 C646.178,114.256 647.181,114.474 648.008,115.239 C648.275,115.512 648.476,115.843 648.596,116.206 C649.116,117.766 647.884,119.067 646.63,119.738 C645.993,120.058 645.311,120.281 644.607,120.398 C643.726,120.544 642.826,120.533 641.949,120.367 C641.265,120.265 640.603,120.05 639.988,119.732 C639.353,119.324 638.819,118.777 638.428,118.13 C638.297,117.902 638.14,117.689 637.96,117.496 C637.461,117.102 636.83,116.916 636.197,116.976 C635.813,116.983 635.43,117.023 635.053,117.095 C634.713,117.151 634.381,117.247 634.065,117.382 C633.737,117.52 633.47,117.773 633.316,118.094 C633.189,118.391 633.135,118.714 633.16,119.035 C633.164,119.121 633.173,119.206 633.186,119.29 C633.256,119.761 633.418,120.214 633.664,120.622 C634.21,121.556 634.914,122.388 635.745,123.082 C636.005,123.29 636.265,123.487 636.535,123.675 C636.985,123.987 637.46,124.262 637.955,124.496 C639.616,125.249 641.415,125.653 643.239,125.682 C644.292,125.678 645.339,125.545 646.36,125.287 C648.177,124.885 649.854,124.005 651.217,122.738 C651.601,122.374 651.949,121.973 652.258,121.542 C653.415,119.924 653.974,117.952 653.839,115.967 Z" />+ </g>+ </g>+</svg>\ No newline at end of filediff --git a/ManicEmu/ManicEmu/Resources/Config-Base.xcconfig b/ManicEmu/ManicEmu/Resources/Config-Base.xcconfigindex 7e6a0e47..dab52c62 100644--- a/ManicEmu/ManicEmu/Resources/Config-Base.xcconfig+++ b/ManicEmu/ManicEmu/Resources/Config-Base.xcconfig@@ -11,7 +11,7 @@// https://help.apple.com/xcode/#/dev745c5c974APP_BUNDLE_IDENTIFIER = com.aoshuang.manicemu-APP_BUILD_VERSION = 0+APP_BUILD_VERSION = 1APP_VERSION = 2.0.0// Prebuilt cores under ProjectManicEMU/Cores (Citra.framework, *.libretro.framework, …)diff --git a/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings b/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.stringsindex da06e62a..072ad117 100644--- a/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings+++ b/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings@@ -1015,3 +1015,4 @@ Press the controller button to complete mapping...";"FocusHintMove" = "Move";"FocusHintBack" = "Back";"FocusHintAdjust" = "Adjust";+"FocusShortcutsTips" = "Tips";diff --git a/ManicEmu/ManicEmu/Resources/zh-Hans.lproj/Localizable.strings b/ManicEmu/ManicEmu/Resources/zh-Hans.lproj/Localizable.stringsindex 023a7384..16a2402b 100644--- a/ManicEmu/ManicEmu/Resources/zh-Hans.lproj/Localizable.strings+++ b/ManicEmu/ManicEmu/Resources/zh-Hans.lproj/Localizable.strings@@ -1010,3 +1010,4 @@"FocusHintMove" = "移动";"FocusHintBack" = "后退";"FocusHintAdjust" = "调整";+"FocusShortcutsTips" = "提示";diff --git a/ManicEmu/ManicEmu/Sources/Base/Application.swift b/ManicEmu/ManicEmu/Sources/Base/Application.swiftindex 95e85742..25b89f4b 100644--- a/ManicEmu/ManicEmu/Sources/Base/Application.swift+++ b/ManicEmu/ManicEmu/Sources/Base/Application.swift@@ -10,20 +10,17 @@import UIKitclass ManicApplication: UIApplication {- // 键盘事件已统一由 DeltaCore 的 KeyboardGameController(GCKeyboard)采集,- // 不再使用 handleKeyUIEvent 私有 API 通路。+ //Keyboard events are now uniformly captured by DeltaCore's KeyboardGameController (GCKeyboard),+ //and the private API path via handleKeyUIEvent is no longer used.override func sendEvent(_ event: UIEvent) {- // 用户触摸屏幕代表切换为触摸操作意图,移除 FocusKit 当前焦点(位置已记忆,方向键可恢复)+ // When the user touches the screen, it signals a switch to touch-based interaction, removing FocusKit's current focus (the position is remembered and can be restored with the arrow keys).if event.type == .touches,let touches = event.allTouches,touches.contains(where: { $0.phase == .began }) {FocusSystem.shared.userDidTouchScreen()}super.sendEvent(event)-// if PlayViewController.isGaming, PlayViewController.currentGameType == .dos {-// LibretroCore.sharedInstance().send(event)-// }}@@ -32,8 +29,14 @@ class ManicApplication: UIApplication {for press in presses {LibretroCore.sharedInstance().handle(press, with: event, down: true)}+ super.pressesBegan(presses, with: event)+ return+ }+ // Gamepad UIPress on iPad drives system focus on the main thread (Metal hitch).+ // Keyboard keys while typing must still reach the text field.+ if shouldForwardPressesToUIKit(presses) {+ super.pressesBegan(presses, with: event)}- super.pressesBegan(presses, with: event)}override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) {@@ -41,8 +44,17 @@ class ManicApplication: UIApplication {for press in presses {LibretroCore.sharedInstance().handle(press, with: event, down: false)}+ super.pressesEnded(presses, with: event)+ return+ }+ if shouldForwardPressesToUIKit(presses) {+ super.pressesEnded(presses, with: event)}- super.pressesEnded(presses, with: event)+ }++ private func shouldForwardPressesToUIKit(_ presses: Set<UIPress>) -> Bool {+ let hasKeyboardKey = presses.contains { $0.key != nil }+ return hasKeyboardKey && FocusSystem.shared.isEditingText}}diff --git a/ManicEmu/ManicEmu/Sources/Base/ApplicationSceneDelegate.swift b/ManicEmu/ManicEmu/Sources/Base/ApplicationSceneDelegate.swiftindex cf112cbd..34fd971a 100644--- a/ManicEmu/ManicEmu/Sources/Base/ApplicationSceneDelegate.swift+++ b/ManicEmu/ManicEmu/Sources/Base/ApplicationSceneDelegate.swift@@ -6,6 +6,7 @@//import UIKit+import GameControllerimport OAuthSwiftimport UniformTypeIdentifiers@@ -21,7 +22,7 @@ class ApplicationSceneDelegate: UIResponder, UIWindowSceneDelegate {window = UIWindow(windowScene: windowScene)ApplicationSceneDelegate.applicationWindow = windowwindow?.tintColor = R.Color.Main- //初始化数据库+ installGamepadEventInteraction(on: window)ResourcesKit.loadResources { isSuccess inDatabase.setup {ThemeManager.shared.setup()@@ -63,6 +64,20 @@ class ApplicationSceneDelegate: UIResponder, UIWindowSceneDelegate {}}+ /// Route gamepad HID through Game Controller instead of UIKit (iPad system focus hitch).+ /// iOS 18+; older versions fall back to swallowing gamepad UIPress in ManicApplication.+ private func installGamepadEventInteraction(on window: UIWindow?) {+ guard let window else { return }+ if #available(iOS 18.0, *) {+ let interaction = GCEventInteraction()+ interaction.handledEventTypes = .gamepad+ if #available(iOS 26.0, *) {+ interaction.receivesEventsInView = false+ }+ window.addInteraction(interaction)+ }+ }+func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {for URLContext in URLContexts {let url = URLContext.urldiff --git a/ManicEmu/ManicEmu/Sources/Business/CheatCode/Views/AddCheatCodeView.swift b/ManicEmu/ManicEmu/Sources/Business/CheatCode/Views/AddCheatCodeView.swiftindex 01bce0d2..d5de8477 100644--- a/ManicEmu/ManicEmu/Sources/Business/CheatCode/Views/AddCheatCodeView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/CheatCode/Views/AddCheatCodeView.swift@@ -71,7 +71,7 @@ class AddCheatCodeView: BaseView {button.allAttributes[.disabled] = disableAttributeslet view = ASButtonView(button)-+ view.enableFocusEffects = falseview.didTapButton = { [weak self] inguard let self = self else { return }self.collectionView.endEditing(true)diff --git a/ManicEmu/ManicEmu/Sources/Business/CheatCode/Views/GamehackingView.swift b/ManicEmu/ManicEmu/Sources/Business/CheatCode/Views/GamehackingView.swiftindex 0120a773..b8519ef5 100644--- a/ManicEmu/ManicEmu/Sources/Business/CheatCode/Views/GamehackingView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/CheatCode/Views/GamehackingView.swift@@ -282,6 +282,7 @@ class GamehackingView: BaseView {titleColor: R.Color.LabelPrimary.forceStyle(.dark),titleAlignment: .center,background: R.Color.Main))+ view.enableFocusEffects = falseview.isHidden = trueview.didTapButton = { [weak self] inself?.collectSelectedCheatsAndSave()diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASIcon.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASIcon.swiftindex b028a95d..8fe77c08 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASIcon.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASIcon.swift@@ -104,4 +104,17 @@ enum ASIcon {}return tempIcon}++ func updateCornerStyle(_ cornerStyle: ASCornerStyle) -> Self {+ switch self {+ case .symbol(let sFSymbol, let weight, let colors, _, let animated):+ return .symbol(sFSymbol, weight: weight, colors: colors, cornerStyle: cornerStyle, animated: animated)+ case .symbolImage(let uIImage, let weight, let colors, _, let animated):+ return .symbolImage(uIImage, weight: weight, colors: colors, cornerStyle: cornerStyle, animated: animated)+ case .image(let uIImage, let color, _):+ return .image(uIImage, color: color, cornerStyle: cornerStyle)+ case .imageUrl(let uRL, let processSize, _):+ return .imageUrl(uRL, processSize: processSize, cornerStyle: cornerStyle)+ }+ }}diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASListPage.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASListPage.swiftindex ddb06210..da3fd806 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASListPage.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASListPage.swift@@ -324,7 +324,8 @@ extension ASListPage {titleColor: UIColor = R.Color.LabelPrimary,detail: String? = nil,detailColor: UIColor = R.Color.LabelSecondary,- state: ASSwitch.State = .off) -> Self {+ state: ASSwitch.State = .off,+ enablePressEffect: Bool = true) -> Self {var styles = [Style]()if let icon {styles.append(.icon(icon))@@ -336,7 +337,7 @@ extension ASListPage {styles.append(.detail(.extraSmallText(detail, color: detailColor)))}styles.append(.switch(.init(state: state)))- return .normal(styles)+ return .normal(styles, enablePressEffect: enablePressEffect)}static func iconTitleDetailCell(icon: ASIcon? = nil,diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASSegment.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASSegment.swiftindex 296347fd..1ad7639b 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASSegment.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASSegment.swift@@ -16,7 +16,7 @@ struct ASSegment {var contentInsets = UIEdgeInsets(inset: R.Size.ContentSpaceTiny)var itemSpacing = R.Size.ContentSpaceTiny- static func iconSegment(icons: [ASIcon], index: Int = 0) -> Self {+ static func iconSegment(icons: [ASIcon], index: Int = 0) -> Self {Self(items: icons.map({ASButton.iconOnly(icon: $0,iconSize: CGSize(R.Size.ButtonExtraSmall),diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Protocols/ShowableView.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Protocols/ShowableView.swiftindex f46b4217..861999e6 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Protocols/ShowableView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Protocols/ShowableView.swift@@ -42,6 +42,8 @@ protocol ShowableView: UIViewAndControllerType {//Page hide callbackfunc didHide()++ func preferredFocusView() -> UIView?}extension ShowableView where Self: UIView {@@ -76,6 +78,8 @@ extension ShowableView where Self: UIView {view?.didShowUp()}, dismiss: { [weak view] inview?.didHide()+ }, preferredFocusView: { [weak view] in+ return view?.preferredFocusView()})return view}@@ -93,6 +97,10 @@ extension ShowableView where Self: UIView {func didShowUp() {}func didHide() {}++ func preferredFocusView() -> UIView? {+ return nil+ }}fileprivate var ShowableViewShowAsSheetKey: UInt8 = 0diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/ViewControllers/BaseViewController.swift b/ManicEmu/ManicEmu/Sources/Business/Common/ViewControllers/BaseViewController.swiftindex 1606b024..9e5001f1 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/ViewControllers/BaseViewController.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/ViewControllers/BaseViewController.swift@@ -121,9 +121,9 @@ class BaseViewController: UIViewController {}/// Presented pages own a FocusKit context. Home tabs are sibling roots activated by HomeViewController.- /// PlayViewController disables FocusKit while gaming and must not push a competing context.+ /// Live emulation keeps FocusKit off; a paused game (GameOptions, etc.) can take a context.var shouldManageFocusContext: Bool {- presentingViewController != nil && !PlayViewController.isGaming+ presentingViewController != nil && !PlayViewController.isEmulationActive}override func viewDidAppear(_ animated: Bool) {diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASListPageView.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASListPageView.swiftindex 71a57f9c..1652b666 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASListPageView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASListPageView.swift@@ -602,6 +602,7 @@ extension ASListPageView {return bottomButton}let view = ASButtonView(bottom)+ view.enableFocusEffects = falsebottomButton = viewreturn view}diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASProgressView.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASProgressView.swiftindex 4cf07465..80278202 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASProgressView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASProgressView.swift@@ -65,6 +65,7 @@ class ASProgressView: BaseView {self.updateValue(sender.value)}slider.enableFocusAdjustment()+ slider.enableFocusEffects = falsereturn slider}()diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSheetView.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSheetView.swiftindex 46e1523d..7dad090a 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSheetView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSheetView.swift@@ -35,7 +35,8 @@ class ASSheetView: BaseView {enableMultiInstance: Bool = false,action: ASSheetViewAction? = nil,showSuccess: ((SheetTarget) -> Void)? = nil,- dismiss: (()->Void)? = nil) {+ dismiss: (()->Void)? = nil,+ preferredFocusView: (() -> UIView?)? = nil) {Sheet { sheetView inif let identifier {@@ -223,7 +224,9 @@ class ASSheetView: BaseView {//dismiss callbacksheetView.onViewDidAppear { sheet in- sheet.pushOverlayFocusContext()+ sheet.pushOverlayFocusContext(configure: { context in+ context.preferredFocusView = preferredFocusView+ })syncLandscapeBackgroundCovering()}sheetView.onViewDidDisappear { sheet indiff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSymbolsButtonView.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSymbolsButtonView.swiftindex 267b0a77..12f7369e 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSymbolsButtonView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSymbolsButtonView.swift@@ -108,7 +108,7 @@ class ASSymbolsButtonView: UIVisualEffectView {for (index, icon) in icons.enumerated() {let iconView = ensureIconView(at: index)- iconView.icon = icon+ iconView.icon = icon.updateCornerStyle(.circle)rebindTapGesture(for: iconView, at: index)containerView.addArrangedSubview(iconView)}diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASTextView.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASTextView.swiftindex dbe223d9..73549bc7 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASTextView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASTextView.swift@@ -109,6 +109,23 @@ class ASTextView: BaseView {fatalError("init(coder:) has not been implemented")}+ override var canBecomeFirstResponder: Bool {+ return isEditable+ }++ @discardableResult+ override func becomeFirstResponder() -> Bool {+ if isEditable {+ return textView.becomeFirstResponder()+ }+ return false+ }++ @discardableResult+ override func resignFirstResponder() -> Bool {+ return textView.resignFirstResponder()+ }+@objc private func handleTextDidChange() {let value = textView.text ?? ""// 同步模型但不刷新视图,防止重置 attributedText 打断选区与编辑菜单diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/LimitedTextInputView.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/LimitedTextInputView.swiftindex b1d45ffa..36379833 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/LimitedTextInputView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/LimitedTextInputView.swift@@ -82,7 +82,10 @@ struct LimitedTextInputView {make.top.equalTo((detailView ?? navigationView).snp.bottom).offset(R.Size.ContentSpaceSmall)make.height.equalTo(R.Size.ItemHeightMedium)}+ // Touch: open the keyboard after the alert animates.+ // Controller/keyboard: wait for A on the already-focused field.DispatchQueue.main.asyncAfter(delay: 0.35) {+ guard !FocusSystem.shared.hasExternalInput else { return }inputView.becomeFirstResponder()}diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/TitleSortCollectionCell.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/TitleSortCollectionCell.swiftindex 2bfd267c..f0411710 100644--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/TitleSortCollectionCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/TitleSortCollectionCell.swift@@ -31,6 +31,7 @@ class TitleSortCollectionCell: UICollectionViewCell {}icon.backgroundColor = .clear+ icon.isFocusable = falseaddSubview(icon)icon.snp.makeConstraints { make inmake.size.equalTo(R.Size.IconSizeMedium)diff --git a/ManicEmu/ManicEmu/Sources/Business/Controllers/ViewControllers/ControllerMappingViewController.swift b/ManicEmu/ManicEmu/Sources/Business/Controllers/ViewControllers/ControllerMappingViewController.swiftindex aa677791..6bc59f34 100644--- a/ManicEmu/ManicEmu/Sources/Business/Controllers/ViewControllers/ControllerMappingViewController.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Controllers/ViewControllers/ControllerMappingViewController.swift@@ -11,6 +11,9 @@ import UIKitclass ControllerMappingViewController: BaseViewController {+ private static weak var capturingInstance: ControllerMappingViewController?+ static var isCapturingInput: Bool { capturingInstance != nil }+private var controllerMappingView: ControllerMappingView@available(*, unavailable)@@ -48,8 +51,8 @@ class ControllerMappingViewController: BaseViewController {override func viewDidAppear(_ animated: Bool) {super.viewDidAppear(animated)- // Mapping consumes the same controller/keyboard events as FocusKit.- FocusSystem.shared.isEnabled = false+ Self.capturingInstance = self+ PlayViewController.refreshExternalInputSink()}override func viewWillAppear(_ animated: Bool) {@@ -69,7 +72,10 @@ class ControllerMappingViewController: BaseViewController {override func viewWillDisappear(_ animated: Bool) {super.viewWillDisappear(animated)- FocusSystem.shared.isEnabled = true+ if Self.capturingInstance === self {+ Self.capturingInstance = nil+ }+ PlayViewController.refreshExternalInputSink()AppDelegate.orientation = R.Config.DefaultOrientation}}diff --git a/ManicEmu/ManicEmu/Sources/Business/Controllers/Views/ControllerMappingView.swift b/ManicEmu/ManicEmu/Sources/Business/Controllers/Views/ControllerMappingView.swiftindex 2ff5e73c..467daa5d 100644--- a/ManicEmu/ManicEmu/Sources/Business/Controllers/Views/ControllerMappingView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Controllers/Views/ControllerMappingView.swift@@ -423,18 +423,6 @@ class ControllerMappingView: BaseView {} else if inputString == "rightThumbstickButton" {return "R3"} else {-// if gameController.name.contains("DualShock", caseSensitive: false) || gameController.name.contains("DualSense", caseSensitive: false) {-// //索尼的手柄 b->× x->△ a->○ y->□-// if controllerInputString == "b" {-// return "×"-// } else if controllerInputString == "a" {-// return "○"-// } else if controllerInputString == "y" {-// return "□"-// } else if controllerInputString == "x" {-// return "△"-// }-// }if let firstUppercased = inputString.first?.uppercased() {return firstUppercased + inputString.dropFirst()}@@ -568,6 +556,12 @@ class ControllerMappingView: BaseView {extension ControllerMappingView: GameControllerReceiver {//这里只处理mfi控制器func gameController(_ gameController: any DeltaCore.GameController, didActivate input: any DeltaCore.Input, value: Double) {+ if !Thread.isMainThread {+ DispatchQueue.main.async { [weak self] in+ self?.gameController(gameController, didActivate: input, value: value)+ }+ return+ }guard gameController.inputType != .keyboard else { return }if gameController.inputType == .controllerSkin, selectedSkinInput == nil {if input.stringValue.contains("touchScreenX", caseSensitive: false) ||diff --git a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/CitraAdvancedSettingView.swift b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/CitraAdvancedSettingView.swiftindex 06319ece..d61013db 100644--- a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/CitraAdvancedSettingView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/CitraAdvancedSettingView.swift@@ -116,12 +116,9 @@ class CitraAdvancedSettingView: BaseView {private func makeCell(for item: SettingItem) -> ASListPage.Cell {switch item.type {case .switch:- let cell = ASListPage.Cell.iconTitleDetailSwitchCell(title: item.key,- state: currentBool(for: item) ? .on : .off)- if let styles = cell.normalValue?.styles {- return .normal(styles, enablePressEffect: false)- }- return cell+ return ASListPage.Cell.iconTitleDetailSwitchCell(title: item.key,+ state: currentBool(for: item) ? .on : .off,+ enablePressEffect: false)case .option:return .iconTitleDetailChevronCell(title: item.key,chevronTitle: currentOptionLabel(for: item))diff --git a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoDetailView.swift b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoDetailView.swiftindex 6ea52b2a..0042f966 100644--- a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoDetailView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoDetailView.swift@@ -64,7 +64,7 @@ class GameInfoDetailView: BaseView {return view}()- private lazy var startGameButton: ASButtonView = {+ lazy var startGameButton: ASButtonView = {let view = ASButtonView(.extraLarge(icon: .symbol(.playFill, colors: [R.Color.LabelPrimary.forceStyle(.dark)]),title: R.string.localizable.play(),titleColor: R.Color.LabelPrimary.forceStyle(.dark),@@ -72,6 +72,7 @@ class GameInfoDetailView: BaseView {sizeStyle: .fixHeight(R.Size.ButtonLarge,insets: .init(horizontal: R.Size.ItemHeightMedium*2,vertical: R.Size.ContentSpaceSmall*2))))+ view.enableFocusEffects = falseview.didTapButton = { [weak self] inguard let self = self else { return }PlayViewController.startGame(game: game)diff --git a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoView.swift b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoView.swiftindex 2e5ba31d..d90e73e1 100644--- a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoView.swift@@ -248,6 +248,10 @@ extension GameInfoView: ShowableView {sheetData.fullScreenForLandscape = truereturn sheetData}++ func preferredFocusView() -> UIView? {+ return gameInfoDetailView.startGameButton+ }}extension GameInfoView: ViewTransition {diff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameCollectionViewCell.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameCollectionViewCell.swiftindex 0d665782..67d3b3b3 100644--- a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameCollectionViewCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameCollectionViewCell.swift@@ -75,6 +75,7 @@ class GameCollectionViewCell: UICollectionViewCell {super.init(frame: frame)backgroundColor = .clearenablePressEffect = true+ enableFocusEffects = falsecontentView.addSubview(selectedBackground)selectedBackground.snp.makeConstraints { make indiff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameListLandscapeView.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameListLandscapeView.swiftindex 1ab78d4a..b77a5477 100644--- a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameListLandscapeView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameListLandscapeView.swift@@ -171,10 +171,14 @@ class GameListLandscapeView: BaseView {}()private lazy var tipsButton: ASButtonView = {- //暂不需要点击事件 后续再添加- let view = ASButtonView(.extraSmall(icon: .symbol(.questionmarkCircle, colors: [R.Color.LabelSecondary]),- title: "Tips",- titleColor: R.Color.LabelSecondary).enableGlass(true))+ // Visual hint only; hold Command / Select to show the cheatsheet.+ var button = ASButton.extraSmall(icon: .symbol(.command, colors: [R.Color.LabelSecondary]),+ title: R.string.localizable.focusShortcutsTips(),+ titleColor: R.Color.LabelSecondary).enableGlass(true)+ button.state = .disabled+ let view = ASButtonView(button)+ view.isFocusable = false+ view.isHidden = truereturn view}()@@ -306,12 +310,12 @@ class GameListLandscapeView: BaseView {make.bottom.equalTo(safeAreaLayoutGuide)}- //Tips按钮 右下角addSubview(tipsButton)tipsButton.snp.makeConstraints { make inmake.trailing.equalTo(safeAreaLayoutGuide).inset(R.Size.ContentSpaceHuge)make.bottom.equalTo(safeAreaLayoutGuide).inset(R.Size.ContentSpaceLarge)}+ updateTipsButton()//聚焦信息面板 位置跟随聚焦cell 由updateInfoPanelPosition动态更新偏移addSubview(infoPanelView)@@ -380,6 +384,29 @@ class GameListLandscapeView: BaseView {self.carouselView.reloadItems(at: [IndexPath(row: row, section: 0)])}})++ let inputChange: (Notification) -> Void = { [weak self] _ in+ self?.updateTipsButton()+ }+ notificationTokens.append(center.addObserver(forName: .externalGameControllerDidConnect, object: nil, queue: .main, using: inputChange))+ notificationTokens.append(center.addObserver(forName: .externalGameControllerDidDisconnect, object: nil, queue: .main, using: inputChange))+ notificationTokens.append(center.addObserver(forName: .externalKeyboardDidConnect, object: nil, queue: .main, using: inputChange))+ notificationTokens.append(center.addObserver(forName: .externalKeyboardDidDisconnect, object: nil, queue: .main, using: inputChange))+ }++ /// Hide when nothing is connected; Command glyph for keyboard-only, Select glyph when a gamepad is present.+ private func updateTipsButton() {+ let connected = ExternalGameControllerManager.shared.connectedControllers+ guard !connected.isEmpty else {+ tipsButton.isHidden = true+ return+ }+ tipsButton.isHidden = false+ let hasGamepad = connected.contains { $0.inputType != .keyboard }+ let icon: ASIcon = hasGamepad+ ? .symbolImage(R.image.sel_iconSymbols(), colors: [R.Color.LabelSecondary])+ : .symbol(.command, colors: [R.Color.LabelSecondary])+ tipsButton.setIcon(icon)}//MARK: - 数据管线@@ -924,7 +951,8 @@ class GameListLandscapeView: BaseView {itemLayout = .fixedHeight(R.Size.ItemHeightExtraLarge)case .toggle:cell = .iconTitleDetailSwitchCell(title: entry.item.title,- state: entry.item.currentBool ? .on : .off)+ state: entry.item.currentBool ? .on : .off,+ enablePressEffect: false)itemLayout = .fixedHeight(R.Size.ItemHeightLarge)case .optionalNumber, .selection:cell = .iconTitleChevronCell(title: entry.item.title,@@ -1072,13 +1100,11 @@ class GameListLandscapeView: BaseView {cardView.focusCommands = [FocusCommand(key: .left, title: moveTitle, handler: { [weak self] inguard let self else { return true }- _ = self.shiftCarouselPage(Locale.isRTLLanguage ? 1 : -1)- return true+ return self.shiftCarouselPage(Locale.isRTLLanguage ? 1 : -1)}),FocusCommand(key: .right, title: moveTitle, handler: { [weak self] inguard let self else { return true }- _ = self.shiftCarouselPage(Locale.isRTLLanguage ? -1 : 1)- return true+ return self.shiftCarouselPage(Locale.isRTLLanguage ? -1 : 1)})]cardView.onFocusConfirm = { [weak self] indiff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameListView.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameListView.swiftindex 95a405f2..0b3e79bf 100644--- a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameListView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameListView.swift@@ -826,6 +826,28 @@ extension GameListView: UICollectionViewDataSource {showTitle: !R.Style.GamesHideTitle || isSearchMode,indexPath: indexPath)}++ cell.onFocusConfirm = { [weak self] in+ guard let self else { return false }+ if self.isSelectionMode {+ if let selectedItems = self.collectionView.indexPathsForSelectedItems,+ selectedItems.contains(where: { $0 == indexPath }) {+ //deselected+ self.collectionView.deselectItem(at: indexPath, animated: true)+ self.deselectItem(at: indexPath)+ } else {+ //selected+ if self.collectionView(self.collectionView, shouldSelectItemAt: indexPath) {+ self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])+ self.selectItem(at: indexPath)+ }+ }+ } else {+ let _ = self.collectionView(self.collectionView, shouldSelectItemAt: indexPath)+ }+ return true+ }+return cell}@@ -892,7 +914,7 @@ extension UIView {}extension GameListView: UICollectionViewDelegate {- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {+ func selectItem(at indexPath: IndexPath) {if isSelectionMode {if let selectedItems = collectionView.indexPathsForSelectedItems?.count {if selectedItems == totalGamesCountForCurrentMode && selectedItems > 1 {@@ -906,6 +928,10 @@ extension GameListView: UICollectionViewDelegate {}}+ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {+ selectItem(at: indexPath)+ }+func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {if isSelectionMode {if let game = getGame(at: indexPath) {@@ -942,7 +968,7 @@ extension GameListView: UICollectionViewDelegate {return false}- func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {+ func deselectItem(at indexPath: IndexPath) {if let selectCount = collectionView.indexPathsForSelectedItems?.count {didListViewSelectionChange?(selectCount > 0 ? .selectSome(onlyOne: selectCount == 1) : .selectNone);if selectCount == 0 {@@ -951,6 +977,10 @@ extension GameListView: UICollectionViewDelegate {}}+ func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {+ deselectItem(at: indexPath)+ }+func scrollViewDidScroll(_ scrollView: UIScrollView) {didScroll?()diff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameMetadataView.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameMetadataView.swiftindex b9f1c558..6b0ecbf0 100644--- a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameMetadataView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameMetadataView.swift@@ -120,6 +120,12 @@ extension GameMetadataView {init(text: String) {super.init(frame: .zero)+ isFocusable = true+ onFocusConfirm = { [weak self] in+ self?.textView.becomeFirstResponder()+ return true+ }+backgroundColor = R.Color.InputBoxmasksToBounds = truediff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameOptionsView.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameOptionsView.swiftindex 2556d420..87739666 100644--- a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameOptionsView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GameOptionsView.swift@@ -171,7 +171,9 @@ class GameOptionsView: BaseView {return ASListPage.Cell.iconTitleDetailSwitchCell(icon: option.icon,title: option.title,detail: detail,- state: switchValue)+ state: switchValue,+ enablePressEffect: false)+} else if let imageValue = accessory.imageValue {return ASListPage.Cell.iconTitleImageChevronCell(icon: option.icon,diff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GamesCollectionReusableView.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GamesCollectionReusableView.swiftindex 78de800e..05f86927 100644--- a/ManicEmu/ManicEmu/Sources/Business/Games/Views/GamesCollectionReusableView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Views/GamesCollectionReusableView.swift@@ -59,6 +59,7 @@ class GamesCollectionReusableView: UICollectionReusableView {make.trailing.equalToSuperview()}titleContainer.enablePressEffect = true+ titleContainer.enableFocusEffects = falsetitleContainer.addTapGesture { [weak self] gesture inguard let self else { return }self.didTapPlatform?()@@ -83,11 +84,13 @@ class GamesCollectionReusableView: UICollectionReusableView {make.trailing.equalToSuperview()}brandImageContainer.enablePressEffect = true+ brandImageContainer.enableFocusEffects = falsebrandImageContainer.addTapGesture { [weak self] gesture inguard let self else { return }self.didTapPlatform?()}+ gamesCountButton.enableFocusEffects = falseaddSubview(gamesCountButton)gamesCountButton.snp.makeConstraints { make inmake.centerY.equalToSuperview()diff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Views/ManufacturerCategoryView.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Views/ManufacturerCategoryView.swiftindex 117f56d4..c7b4c68c 100644--- a/ManicEmu/ManicEmu/Sources/Business/Games/Views/ManufacturerCategoryView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Views/ManufacturerCategoryView.swift@@ -17,6 +17,7 @@ class ManufacturerCategoryView: BaseView {super.init(frame: frame)backgroundColor = .clearenablePressEffect = true+ enableFocusEffects = falseaddSubview(normalImageView)@@ -163,6 +164,13 @@ extension ManufacturerCategoryView: UICollectionViewDataSource {cell.onLongPress = {ASWebView.show(url: R.URLs.manufacturer(manufacturer))}+ cell.onFocusConfirm = { [weak self] in+ guard let self else { return false }+ if self.collectionView(self.collectionView, shouldSelectItemAt: indexPath) {+ self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])+ }+ return true+ }return cell}}diff --git a/ManicEmu/ManicEmu/Sources/Business/Home/ViewControllers/HomeViewController.swift b/ManicEmu/ManicEmu/Sources/Business/Home/ViewControllers/HomeViewController.swiftindex 19c204ce..209ce122 100644--- a/ManicEmu/ManicEmu/Sources/Business/Home/ViewControllers/HomeViewController.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Home/ViewControllers/HomeViewController.swift@@ -53,7 +53,6 @@ class HomeViewController: BaseViewController {lazy var homeTabBar: HomeTabBar = {let view = HomeTabBar()- view.isFocusable = falseview.selectionChange = { [weak self] selection invar selection = selectionif Locale.isRTLLanguage {@@ -307,6 +306,8 @@ class HomeViewController: BaseViewController {shouldHandoffTabFocus = falseviewController.activateFocusRoot { [weak self] context inguard let self else { return }+ // Tab bar lives on HomeViewController; include it in this tab's page-level search.+ context.addAdditionalSearchRoot(self.homeTabBar)context.addCommands([FocusCommand(key: FocusKey("control+1"), title: R.string.localizable.tabbarTitleGames(), action: { [weak self] inself?.homeTabBar.currentSelection = .gamesdiff --git a/ManicEmu/ManicEmu/Sources/Business/Home/Views/HomeTabBar.swift b/ManicEmu/ManicEmu/Sources/Business/Home/Views/HomeTabBar.swiftindex e59ba6a0..6f268348 100644--- a/ManicEmu/ManicEmu/Sources/Business/Home/Views/HomeTabBar.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Home/Views/HomeTabBar.swift@@ -46,8 +46,7 @@ class HomeTabBar: BaseView {titleLabel.alpha = isSelected ? 1 : 0enablePressEffect = true- // Tab items are switched by Home's page-level left/right, not by focusing the bar itself.- isFocusable = false+ enableFocusEffects = falselet contentView = UIView()contentView.addSubviews([symbolView, titleLabel])@@ -159,6 +158,9 @@ class HomeTabBar: BaseView {/// 选中状态更改回调var selectionChange: ((BarSelection) -> Void)?++ private weak var focusedBar: BarView?+ private weak var lastFocusedBar: BarView?/// 当前的选中状态 修改此值会回调selectionChangevar currentSelection: BarSelection = .games {@@ -213,6 +215,7 @@ class HomeTabBar: BaseView {}enablePressEffect = true+ isFocusable = truegamesBar.setPressEffectListener { [weak self] state inguard let self, FocusSystem.shared.currentFocusedView == nil else { return }self.focusEffect = state == .lift@@ -237,6 +240,18 @@ class HomeTabBar: BaseView {settingsBar.addTapGesture { [weak self] gesture inself?.currentSelection = .settings}+ gamesBar.onFocusConfirm = { [weak self] in+ self?.currentSelection = .games+ return true+ }+ importBar.onFocusConfirm = { [weak self] in+ self?.currentSelection = .imports+ return true+ }+ settingsBar.onFocusConfirm = { [weak self] in+ self?.currentSelection = .settings+ return true+ }}override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {@@ -348,3 +363,95 @@ class HomeTabBar: BaseView {}}}++// MARK: - FocusContainer++extension HomeTabBar: FocusContainer {+ var isolatesFocusNavigation: Bool { true }++ var canEnterFocus: Bool {+ window != nil && !isHidden && alpha > 0.01+ }++ func enterFocus(from direction: FocusDirection?, preferred: UIView?) -> UIView? {+ _ = preferred+ // Content may only enter the tab bar by heading down. Left/right/up stay on the page.+ if let direction, direction != .down { return nil }+ let bar = barView(for: currentSelection)+ guard bar.fk_canFocus else { return nil }+ applyBarFocus(bar)+ return bar+ }++ func navigateFocus(_ direction: FocusDirection, current: UIView?) -> FocusContainerResult {+ switch direction {+ case .up, .down:+ return .exit+ case .left, .right:+ let origin = (current as? BarView) ?? focusedBar ?? barView(for: currentSelection)+ guard let next = adjacentBar(from: origin, direction: direction) else {+ return .handled(origin)+ }+ applyBarFocus(next)+ return .handled(next)+ }+ }++ var currentFocusedDescendant: UIView? { focusedBar }++ var lastFocusedDescendant: UIView? { lastFocusedBar }++ func resignFocus() {+ focusedBar = nil+ }++ func performPrimaryActionOnFocused() -> Bool {+ focusedBar?.fk_performPrimaryAction() ?? false+ }++ func focusEntryFrame(from direction: FocusDirection) -> CGRect? {+ FocusEngine.frameInWindow(of: barView(for: currentSelection))+ }+}++extension HomeTabBar {+ private var orderedBars: [BarView] { [gamesBar, importBar, settingsBar] }++ private func barView(for selection: BarSelection) -> BarView {+ switch selection {+ case .games: return gamesBar+ case .imports: return importBar+ case .settings: return settingsBar+ }+ }++ private func selection(for bar: BarView) -> BarSelection? {+ if bar === gamesBar { return .games }+ if bar === importBar { return .imports }+ if bar === settingsBar { return .settings }+ return nil+ }++ private func adjacentBar(from current: BarView, direction: FocusDirection) -> BarView? {+ let bars = orderedBars+ guard let index = bars.firstIndex(where: { $0 === current }) else { return bars.first }+ var delta = direction == .right ? 1 : -1+ if Locale.isRTLLanguage {+ delta = -delta+ }+ let next = (index + delta + bars.count) % bars.count+ return bars[next]+ }++ private func applyBarFocus(_ bar: BarView) {+ if let focusedBar, focusedBar !== bar {+ focusedBar.fk_applyFocus(false)+ }+ bar.fk_applyFocus(true)+ focusedBar = bar+ lastFocusedBar = bar+ if let selection = selection(for: bar), currentSelection != selection {+ currentSelection = selection+ }+ }+}diff --git a/ManicEmu/ManicEmu/Sources/Business/Import/Views/ImportFileCollectionViewCell.swift b/ManicEmu/ManicEmu/Sources/Business/Import/Views/ImportFileCollectionViewCell.swiftindex af0d8af7..282cb7b4 100644--- a/ManicEmu/ManicEmu/Sources/Business/Import/Views/ImportFileCollectionViewCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Import/Views/ImportFileCollectionViewCell.swift@@ -24,7 +24,6 @@ class ImportFileCollectionViewCell: UICollectionViewCell {private var infoContainerView: UIView = {let view = UIView()view.backgroundColor = R.Color.BackgroundSecondary- view.layerCornerRadius = R.Size.CornerRadiusLargereturn view}()@@ -34,6 +33,7 @@ class ImportFileCollectionViewCell: UICollectionViewCell {override init(frame: CGRect) {super.init(frame: frame)enablePressEffect = true+ layerCornerRadius = R.Size.CornerRadiusLargeinfoContainerView.addSubview(topLeftGradientView)topLeftGradientView.snp.makeConstraints { make indiff --git a/ManicEmu/ManicEmu/Sources/Business/Import/Views/ImportMottoCollectionViewCell.swift b/ManicEmu/ManicEmu/Sources/Business/Import/Views/ImportMottoCollectionViewCell.swiftindex 8234adc3..484ac6a6 100644--- a/ManicEmu/ManicEmu/Sources/Business/Import/Views/ImportMottoCollectionViewCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Import/Views/ImportMottoCollectionViewCell.swift@@ -37,6 +37,8 @@ class ImportMottoCollectionViewCell: UICollectionViewCell {layer.zPosition = .greatestFiniteMagnitude+ keepCellHeightView.layerCornerRadius = R.Size.CornerRadiusMedium+addSubviews([keepCellHeightView, backgroundGradientView, imageView, labelView])keepCellHeightView.snp.makeConstraints { make in@@ -73,6 +75,14 @@ class ImportMottoCollectionViewCell: UICollectionViewCell {size: CGSize(width: backgroundGradientView.width,height: backgroundGradientView.height*2))).cgPathbackgroundGradientView.layer.mask = ovalLayer++ if UIDevice.isPhone, UIDevice.isLandscape {+ keepCellHeightView.backgroundColor = R.Color.BackgroundSecondary+ backgroundGradientView.isHidden = true+ } else {+ keepCellHeightView.backgroundColor = .clear+ backgroundGradientView.isHidden = false+ }}func updateViews() {diff --git a/ManicEmu/ManicEmu/Sources/Business/Import/Views/MultiDiscBuilderView.swift b/ManicEmu/ManicEmu/Sources/Business/Import/Views/MultiDiscBuilderView.swiftindex 33122742..31f94c92 100644--- a/ManicEmu/ManicEmu/Sources/Business/Import/Views/MultiDiscBuilderView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Import/Views/MultiDiscBuilderView.swift@@ -126,6 +126,7 @@ class MultiDiscBuilderView: BaseView {guard let self else { return }self.importGame()}+ view.enableFocusEffects = falsereturn view}()diff --git a/ManicEmu/ManicEmu/Sources/Business/Import/Views/MultiDiscItemCollectionCell.swift b/ManicEmu/ManicEmu/Sources/Business/Import/Views/MultiDiscItemCollectionCell.swiftindex 212a8144..65fe5a9b 100644--- a/ManicEmu/ManicEmu/Sources/Business/Import/Views/MultiDiscItemCollectionCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Import/Views/MultiDiscItemCollectionCell.swift@@ -47,6 +47,7 @@ class MultiDiscItemCollectionCell: UICollectionViewCell {make.top.trailing.equalToSuperview().inset(R.Size.ContentSpaceMedium)}+ deleteIcon.isFocusable = falseaddSubview(deleteIcon)deleteIcon.backgroundColor = R.Color.BackgroundTertiarydeleteIcon.snp.makeConstraints { make indiff --git a/ManicEmu/ManicEmu/Sources/Business/OnlinePlay/Views/LibretroNetplayView.swift b/ManicEmu/ManicEmu/Sources/Business/OnlinePlay/Views/LibretroNetplayView.swiftindex 3fab394b..7d980379 100644--- a/ManicEmu/ManicEmu/Sources/Business/OnlinePlay/Views/LibretroNetplayView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/OnlinePlay/Views/LibretroNetplayView.swift@@ -252,13 +252,10 @@ class LibretroNetplayView: BaseView {private func makeIdleCell(for item: IdleItem) -> ASListPage.Cell {if item.isSwitch {- let cell = ASListPage.Cell.iconTitleDetailSwitchCell(icon: item.icon,- title: item.title,- state: boolValue(for: item) ? .on : .off)- if let styles = cell.normalValue?.styles {- return .normal(styles, enablePressEffect: false)- }- return cell+ return ASListPage.Cell.iconTitleDetailSwitchCell(icon: item.icon,+ title: item.title,+ state: boolValue(for: item) ? .on : .off,+ enablePressEffect: false)}let password = stringValue(for: item)return .iconTitleDetailChevronCell(icon: item.icon,@@ -322,13 +319,10 @@ class LibretroNetplayView: BaseView {}private func makeHostSwitchCell() -> ASListPage.Cell {- let cell = ASListPage.Cell.iconTitleDetailSwitchCell(icon: .symbolImage(R.image.online_iconSymbols()),- title: R.string.localizable.startNetplayHost(),- state: session.isHosting ? .on : .off)- if let styles = cell.normalValue?.styles {- return .normal(styles, enablePressEffect: false)- }- return cell+ return ASListPage.Cell.iconTitleDetailSwitchCell(icon: .symbolImage(R.image.online_iconSymbols()),+ title: R.string.localizable.startNetplayHost(),+ state: session.isHosting ? .on : .off,+ enablePressEffect: false)}private func makeRefreshCell(title: String) -> ASListPage.Cell {diff --git a/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift b/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swiftindex 073c8bc5..5df36bd6 100644--- a/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift@@ -663,6 +663,8 @@ class PlayViewController: GameViewController {super.viewDidLoad()PlayViewController.currentPlayViewController = self+ ExternalInputDispatch.sink = .gameplay+ FocusSystem.shared.isEnabled = false//发送开始游戏通知NotificationCenter.default.post(name: R.NotificationName.StartPlayGame, object: nil)@@ -772,9 +774,9 @@ class PlayViewController: GameViewController {citraCore?.destory()}+ removeExternalGameControllerReceivers()PlayViewController.currentPlayViewController = nil-- FocusSystem.shared.isEnabled = true+ PlayViewController.refreshExternalInputSink()//发送结束游戏通知NotificationCenter.default.post(name: R.NotificationName.StopPlayGame, object: nil)@@ -856,6 +858,15 @@ class PlayViewController: GameViewController {}override func gameController(_ gameController: any GameController, didActivate input: any Input, value: Double) {+ if !Thread.isMainThread {+ DispatchQueue.main.async { [weak self] in+ self?.gameController(gameController, didActivate: input, value: value)+ }+ return+ }+ if gameController.inputType == .mfi || gameController.inputType == .keyboard {+ guard ExternalInputDispatch.sink == .gameplay else { return }+ }guard !isPaused else { return }if let directKeyboardInput = input as? AnyInput,directKeyboardInput.type == .controller(GameControllerInputType("directKeyboard")),@@ -868,6 +879,12 @@ class PlayViewController: GameViewController {}override func gameController(_ gameController: any GameController, didDeactivate input: any Input) {+ if !Thread.isMainThread {+ DispatchQueue.main.async { [weak self] in+ self?.gameController(gameController, didDeactivate: input)+ }+ return+ }if let directKeyboardInput = input as? AnyInput,directKeyboardInput.type == .controller(GameControllerInputType("directKeyboard")),manicGame.isLibretroType,@@ -1265,20 +1282,25 @@ extension PlayViewController {guard !isWFCConnect else {return false}+ var didPause = falseif manicGame.isCitra3DS {citraCore?.pause()- return true+ didPause = true} else if manicGame.isLibretroType {LibretroCore.sharedInstance().pause()- return true+ didPause = true} else if manicGame.isJGenesisCore {jGenesisCore?.pause()- return true+ didPause = true} else if manicGame.isJ2MECore {j2meCore?.pause()- return true+ didPause = true}- return false+ if didPause {+ releaseHeldExternalCoreInputs()+ PlayViewController.refreshExternalInputSink()+ }+ return didPause}private func resumeEmulationAndHandleAudio() {@@ -1295,6 +1317,48 @@ extension PlayViewController {j2meCore?.resume()updateAudio()}+ PlayViewController.refreshExternalInputSink()+ replayHeldExternalCoreInputs()+ }++ /// Release mapped core / function keys so pause does not leave a stuck input.+ private func releaseHeldExternalCoreInputs() {+ guard let emulatorCore else { return }+ for controller in ExternalGameControllerManager.shared.connectedControllers {+ let held = controller.activatedInputs+ for (physicalInput, _) in held {+ if let mapped = controller.mappedInput(for: physicalInput, receiver: emulatorCore) {+ emulatorCore.gameController(controller, didDeactivate: mapped)+ }+ if let mapped = controller.mappedInput(for: physicalInput, receiver: self) {+ gameController(controller, didDeactivate: mapped)+ }+ }+ }+ }++ /// Re-apply still-held analog sticks after resume. Digital buttons are not replayed+ /// so closing a menu while holding A cannot fire an in-game confirm.+ private func replayHeldExternalCoreInputs() {+ guard ExternalInputDispatch.sink == .gameplay else { return }+ guard let emulatorCore else { return }+ for controller in ExternalGameControllerManager.shared.connectedControllers {+ for (physicalInput, value) in controller.activatedInputs {+ guard physicalInput.isContinuous else { continue }+ if let mapped = controller.mappedInput(for: physicalInput, receiver: emulatorCore) {+ emulatorCore.gameController(controller, didActivate: mapped, value: value)+ }+ }+ }+ }++ private func removeExternalGameControllerReceivers() {+ for controller in ExternalGameControllerManager.shared.connectedControllers {+ controller.removeReceiver(self)+ if let emulatorCore {+ controller.removeReceiver(emulatorCore)+ }+ }}private func updateAudio() {@@ -3855,6 +3919,28 @@ extension PlayViewController: GameViewControllerDelegate {extension PlayViewController {static var isGaming: Bool { currentPlayViewController != nil }+ /// Playing and the core is not paused. Pause (GameOptions, etc.) yields FocusKit instead of cores.+ static var isEmulationActive: Bool {+ guard let currentPlayViewController else { return false }+ return !currentPlayViewController.isPaused+ }++ static func refreshExternalInputSink() {+ if ControllerMappingViewController.isCapturingInput {+ ExternalInputDispatch.sink = .mapping+ FocusSystem.shared.isEnabled = false+ return+ }+ if isEmulationActive {+ ExternalInputDispatch.sink = .gameplay+ FocusSystem.shared.isEnabled = false+ FocusSystem.shared.userDidTouchScreen()+ } else {+ ExternalInputDispatch.sink = .focusKit+ FocusSystem.shared.isEnabled = true+ }+ }+static var enableAirplay: Bool {if let _ = currentPlayViewController {return truediff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/ColorPickerView.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/ColorPickerView.swiftindex 17b18eca..26e11aa5 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/ColorPickerView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/ColorPickerView.swift@@ -98,6 +98,7 @@ class ColorPickerView: BaseView {titleColor: R.Color.LabelPrimary.forceStyle(.dark),titleAlignment: .center,background: R.Color.Main))+ view.enableFocusEffects = falseview.didTapButton = { [weak self] inguard let self else { return }if var themeColor = self.themeColor {diff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/CoverStyleCollectionViewCell.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/CoverStyleCollectionViewCell.swiftindex 58870777..22487b9d 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/CoverStyleCollectionViewCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/CoverStyleCollectionViewCell.swift@@ -56,6 +56,7 @@ class CoverStyleCollectionViewCell: UICollectionViewCell {view.minimumTrackTintColor = R.Color.Mainview.maximumTrackTintColor = R.Color.BackgroundTertiaryview.enableFocusAdjustment()+ view.enableFocusEffects = falsereturn view}()diff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/DesktopIconCollectionViewCell.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/DesktopIconCollectionViewCell.swiftindex 179245cd..30f22f36 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/DesktopIconCollectionViewCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/DesktopIconCollectionViewCell.swift@@ -41,6 +41,7 @@ class DesktopIconCollectionViewCell: UICollectionViewCell {super.init(frame: frame)enablePressEffect = true+ enableFocusEffects = falseaddSubview(imageView)imageView.snp.makeConstraints { make indiff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/JITSettingView.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/JITSettingView.swiftindex b024b8ea..052ad03c 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/JITSettingView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/JITSettingView.swift@@ -337,6 +337,7 @@ class JITSettingView: BaseView {private lazy var navigationView: ASNavigationView = {var navigation = ASListPage.Navigation.defaultNavigation(title: "JIT",titleIcon: .symbolImage(R.image.jit_iconSymbols()))+ navigation.enableClose = showCloselet view = ASNavigationView(navigation)view.didTapClose = { [weak self] inguard let self = self else { return }diff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/PlatformSortCollectionViewCell.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/PlatformSortCollectionViewCell.swiftindex 21c97e64..3ca3eb12 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/PlatformSortCollectionViewCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/PlatformSortCollectionViewCell.swift@@ -41,6 +41,7 @@ class PlatformSortCollectionViewCell: UICollectionViewCell {}icon.backgroundColor = .clear+ icon.isFocusable = falseaddSubview(icon)icon.snp.makeConstraints { make inmake.size.equalTo(R.Size.IconSizeMedium)diff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsAdventureCardView.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsAdventureCardView.swiftindex 6312f864..727ea968 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsAdventureCardView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsAdventureCardView.swift@@ -29,6 +29,7 @@ class SettingsAdventureCardView: BaseView {view.layerBorderWidth = R.Size.Borderview.isUserInteractionEnabled = trueview.enablePressEffect = true+ view.enableFocusEffects = falsereturn view}()diff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsBottomView.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsBottomView.swiftindex 417fa546..f23f6803 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsBottomView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsBottomView.swift@@ -36,6 +36,7 @@ class SettingsBottomView: BaseView {make.top.bottom.equalToSuperview()}supportUsView.enablePressEffect = true+ supportUsView.enableFocusEffects = falsesupportUsView.addTapGesture { gesture inUIApplication.shared.open(R.URLs.Donate)}diff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsMembershipView.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsMembershipView.swiftindex 682d6ef5..7ada41de 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsMembershipView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsMembershipView.swift@@ -19,6 +19,7 @@ class SettingsMembershipView: BaseView {super.init(frame: frame)enablePressEffect = true+ enableFocusEffects = falselet containerView = UIView()containerView.layerCornerRadius = R.Size.CornerRadiusLargediff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsRateUsView.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsRateUsView.swiftindex 2fd08f9c..1a8eab05 100644--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsRateUsView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsRateUsView.swift@@ -10,6 +10,7 @@ class SettingsRateUsView: BaseView {override init(frame: CGRect) {super.init(frame: frame)enablePressEffect = true+ enableFocusEffects = falselet containerView = UIView()containerView.layerCornerRadius = R.Size.CornerRadiusLargediff --git a/ManicEmu/ManicEmu/Sources/Business/Skin/Views/SkinCollectionViewCell.swift b/ManicEmu/ManicEmu/Sources/Business/Skin/Views/SkinCollectionViewCell.swiftindex 99904295..3c441556 100644--- a/ManicEmu/ManicEmu/Sources/Business/Skin/Views/SkinCollectionViewCell.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Skin/Views/SkinCollectionViewCell.swift@@ -69,6 +69,7 @@ class SkinCollectionViewCell: UICollectionViewCell {var playcaseButton: UIImageView = {let view = UIImageView(image: R.image.playcase_footnote())view.enablePressEffect = true+ view.isFocusable = falseview.isHidden = trueview.isUserInteractionEnabled = truereturn view@@ -84,6 +85,7 @@ class SkinCollectionViewCell: UICollectionViewCell {right: R.Size.ContentSpaceSmall),titlePosition: .right,enableGlass: true)+ view.isFocusable = falseview.enableRoundCorner = trueview.isHidden = truereturn view@@ -98,6 +100,7 @@ class SkinCollectionViewCell: UICollectionViewCell {override init(frame: CGRect) {super.init(frame: frame)enablePressEffect = true+ enableFocusEffects = falselayerCornerRadius = R.Size.CornerRadiusMediumbackgroundColor = R.Color.BackgroundPrimarydiff --git a/ManicEmu/ManicEmu/Sources/Business/Skin/Views/SkinSettingsView.swift b/ManicEmu/ManicEmu/Sources/Business/Skin/Views/SkinSettingsView.swiftindex 6374f762..50114de3 100644--- a/ManicEmu/ManicEmu/Sources/Business/Skin/Views/SkinSettingsView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Skin/Views/SkinSettingsView.swift@@ -490,10 +490,8 @@ class SkinSettingsView: BaseView {let layout = UICollectionViewCompositionalLayout { [weak self] sectionIndex, env inguard let self = self else { return nil }- let column: CGFloat- if UIDevice.isPhone || self.showClose {- column = self.isPortraitSkinPage ? 2.0 : 1.0- } else {+ var column: CGFloat = self.isPortraitSkinPage ? 2.0 : 1.0+ if UIDevice.isPad, UIDevice.isLandscape {column = self.isPortraitSkinPage ? 3.0 : 2.0}@@ -777,6 +775,26 @@ extension SkinSettingsView: UICollectionViewDataSource {cell.playcaseButton.addTapGesture { _ inPlayCasePromoView.show(showDontShow: false)}+ cell.onFocusConfirm = { [weak self] in+ guard let self else { return false }+ if self.isEditMode {+ if let selectedItems = self.collectionView.indexPathsForSelectedItems,+ selectedItems.contains(where: { $0 == indexPath }) {+ //deselected+ self.collectionView.deselectItem(at: indexPath, animated: true)+ self.deselectItem(at: indexPath)+ } else {+ //selected+ if self.collectionView(self.collectionView, shouldSelectItemAt: indexPath) {+ self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])+ self.selectItem(at: indexPath)+ }+ }+ } else {+ let _ = self.collectionView(self.collectionView, shouldSelectItemAt: indexPath)+ }+ return true+ }return cell}}@@ -880,18 +898,26 @@ extension SkinSettingsView: UICollectionViewDelegate {}}- func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {+ func deselectItem(at indexPath: IndexPath) {guard isEditMode else { return }updateNavigation()updateToolView()}- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {+ func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {+ deselectItem(at: indexPath)+ }++ func selectItem(at indexPath: IndexPath) {guard isEditMode else { return }updateNavigation()updateToolView()}+ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {+ selectItem(at: indexPath)+ }+private func resetSkin(gameType: GameType? = nil) {if let gameType {Prefference.defalut.deletePrefference(kind: .skin,diff --git a/ManicEmu/ManicEmu/Sources/Business/TriggerPro/Views/AddTriggerButtonStyleView.swift b/ManicEmu/ManicEmu/Sources/Business/TriggerPro/Views/AddTriggerButtonStyleView.swiftindex 0c4b9e7d..be1aaff0 100644--- a/ManicEmu/ManicEmu/Sources/Business/TriggerPro/Views/AddTriggerButtonStyleView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/TriggerPro/Views/AddTriggerButtonStyleView.swift@@ -213,6 +213,8 @@ class AddTriggerButtonStyleView: BaseView {let view = UISlider()view.minimumTrackTintColor = R.Color.Mainview.maximumTrackTintColor = R.Color.BackgroundTertiary+ view.enableFocusAdjustment()+ view.enableFocusEffects = falsereturn view}()diff --git a/ManicEmu/ManicEmu/Sources/Business/TriggerPro/Views/TriggerProManageView.swift b/ManicEmu/ManicEmu/Sources/Business/TriggerPro/Views/TriggerProManageView.swiftindex 4b0026d9..44035eaa 100644--- a/ManicEmu/ManicEmu/Sources/Business/TriggerPro/Views/TriggerProManageView.swift+++ b/ManicEmu/ManicEmu/Sources/Business/TriggerPro/Views/TriggerProManageView.swift@@ -355,11 +355,11 @@ class TriggerProManageView: BaseView {}private func getNavigation() -> ASListPage.Navigation {-- let navigation = ASListPage.Navigation.defaultNavigation(title: "TriggerPro",+ var navigation = ASListPage.Navigation.defaultNavigation(title: "TriggerPro",titleIcon: .symbolImage(R.image.triggerpro_iconSymbols()),tools: datas.count > 0 ? [.symbolImage(R.image.selectedit_iconSymbols())] : [],edit: R.string.localizable.selectAll())+ navigation.enableClose = showClosereturn navigation}diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusCollectionView.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusCollectionView.swiftindex 73b0e8a6..c5a0bbd4 100644--- a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusCollectionView.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusCollectionView.swift@@ -17,8 +17,11 @@ import UIKit/// 设计要点:/// - 焦点锚点:`FocusedElement`(cell 或 supplementary),视觉通过 `focusEffect` 呈现。/// - cell / header / footer 均可聚焦整体或其内部 `isFocusable` 子视图。-/// - 跨元素寻径基于 layoutAttributes 空间搜索(同行左右 / 同列上下)。-/// - supplementary 滚动使用 `scrollRectToVisible`(`scrollToItem` 仅适用于 cell)。+/// - Item-to-item search uses layout frames + IndexPath. A cell is focused first;+/// down/right then enters inner controls, which keep four-way navigation until+/// that heading is empty and focus leaves the cell.+/// - Vertical collections center the focused item; horizontal / orthogonal+/// scrollers use a minimum reveal so a strip does not jump.// MARK: - 配置属性@@ -79,6 +82,8 @@ extension UICollectionView: FocusContainer {return focusCoordinator.firstFocusableElement() != nil}+ var isolatesFocusNavigation: Bool { true }+func enterFocus(from direction: FocusDirection?, preferred: UIView?) -> UIView? {focusCoordinator.enter(from: direction, preferred: preferred)}@@ -125,9 +130,17 @@ private final class FocusCollectionCoordinator: NSObject {private var pendingEntryDirection: FocusDirection?private var pendingEntryOriginFrame: CGRect?+ private weak var pendingPreferredInner: UIView?+ /// Last inner focus per item. Re-entering that item restores it (cell as container).+ private var lastInnerByElement: [FocusedElement: WeakView] = [:]private var pendingProbe: (element: FocusedElement, direction: FocusDirection?, originFrame: CGRect?)?private var scrollAnchor: FocusedElement?+ private final class WeakView {+ weak var view: UIView?+ init(_ view: UIView) { self.view = view }+ }+var focusedIndexPath: IndexPath? {if case .cell(let indexPath)? = focusedElement { return indexPath }return nil@@ -157,8 +170,13 @@ private final class FocusCollectionCoordinator: NSObject {if let preferred, preferred !== collectionView,let element = focusedElement(containing: preferred), isFocusableElement(element) {- let originFrame = FocusEngine.frameInWindow(of: preferred)- switch moveTo(element, direction: direction, originFrame: originFrame, shouldFocus: true) {+ switch moveTo(+ element,+ direction: direction,+ originFrame: FocusEngine.frameInWindow(of: preferred),+ shouldFocus: true,+ preferredInner: preferred+ ) {case .handled(let view): return viewcase .exit: return collectionView}@@ -210,6 +228,7 @@ private final class FocusCollectionCoordinator: NSObject {focusedElement = nilpendingEntryDirection = nilpendingEntryOriginFrame = nil+ pendingPreferredInner = nil}// MARK: 方向导航@@ -227,18 +246,24 @@ private final class FocusCollectionCoordinator: NSObject {return moveTo(target, direction: direction, originFrame: nil, shouldFocus: true)}+ // Cell is focused first. Down/right may enter inner items; once inside,+ // all four directions stay among inners until that heading is empty.if let element = focusedElement,- let host = hostView(for: element),- let inner = focusedTarget, inner !== host, inner.isDescendant(of: host) {- let candidates = FocusEngine.collectCandidates(in: host)- .filter { $0 !== inner && !$0.isDescendant(of: inner) }- if let next = FocusEngine.bestCandidate(from: FocusEngine.frameInWindow(of: inner),- direction: direction,- candidates: candidates) {- inner.fk_applyFocus(false)- next.fk_applyFocus(true)- focusedTarget = next- scrollToMakeVisible(element, focusedView: next)+ let host = hostView(for: element) {+ let current = focusedTarget ?? host+ let insideCell = current !== host && current.isDescendant(of: host)+ if insideCell {+ if let next = FocusEngine.nextCandidate(+ from: current,+ direction: direction,+ insideHost: host+ ) {+ moveFocusInsideCell(from: current, to: next, host: host, element: element)+ return .handled(next)+ }+ } else if direction == .down || direction == .right,+ let next = firstInner(in: host, from: direction) {+ moveFocusInsideCell(from: current, to: next, host: host, element: element)return .handled(next)}}@@ -247,9 +272,18 @@ private final class FocusCollectionCoordinator: NSObject {return .exit}let originFrame = focusedTarget.map { FocusEngine.frameInWindow(of: $0) }+ ?? cellFrameInWindow(for: current)return moveTo(resolved.element, direction: direction, originFrame: originFrame, shouldFocus: resolved.shouldFocus)}+ private func cellFrameInWindow(for element: FocusedElement) -> CGRect? {+ guard let collectionView, let window = collectionView.window,+ let attributes = layoutAttributes(for: element) else {+ return focusedTarget.map { FocusEngine.frameInWindow(of: $0) }+ }+ return collectionView.convert(attributes.frame, to: window)+ }+private func resolveNavigationTarget(from start: FocusedElement, direction: FocusDirection) -> (element: FocusedElement, shouldFocus: Bool)? {guard let collectionView else { return nil }@@ -259,27 +293,11 @@ private final class FocusCollectionCoordinator: NSObject {}guard let _ = layoutAttributes(for: start) else { return nil }-- var current = start- var farthest: FocusedElement?- var visited = Set<FocusedElement>()-- while let next = nextElement(from: current, direction: direction) {- guard visited.insert(next).inserted else { break }- farthest = next-- if let _ = hostView(for: next) {- if isFocusableElement(next) {- return (next, true)- }- } else if isNavigableElement(next) {- return (next, true)- }- current = next+ guard let next = nextElement(from: start, direction: direction) else { return nil }+ if let _ = hostView(for: next) {+ return (next, isFocusableElement(next))}-- guard let farthest else { return nil }- return (farthest, false)+ return (next, isNavigableElement(next))}private func resolveOrthogonalNavigation(from start: IndexPath, direction: FocusDirection) -> (element: FocusedElement, shouldFocus: Bool)? {@@ -294,16 +312,28 @@ private final class FocusCollectionCoordinator: NSObject {}}- private func moveTo(_ element: FocusedElement, direction: FocusDirection?, originFrame: CGRect?, shouldFocus: Bool) -> FocusContainerResult {+ private func moveTo(+ _ element: FocusedElement,+ direction: FocusDirection?,+ originFrame: CGRect?,+ shouldFocus: Bool,+ preferredInner: UIView? = nil+ ) -> FocusContainerResult {guard let collectionView else { return .exit }lastFocusedElement = element- scrollToReveal(element, direction: direction)+ scrollToReveal(element)if shouldFocus, let host = hostView(for: element), isFocusableElement(element) {pendingProbe = nilscrollAnchor = nil- focus(element, direction: direction, originFrame: originFrame, scroll: false)+ focus(+ element,+ direction: direction,+ originFrame: originFrame,+ preferredInner: preferredInner,+ scroll: false+ )return .handled(focusedTarget ?? host)}@@ -315,9 +345,99 @@ private final class FocusCollectionCoordinator: NSObject {return .handled(collectionView)}- private func scrollPosition(for direction: FocusDirection?) -> UICollectionView.ScrollPosition {- guard let direction else { return [] }- return direction.isHorizontal ? .centeredHorizontally : .centeredVertically+ private func scrollToReveal(_ element: FocusedElement) {+ scrollToMakeVisible(element, focusedView: nil, animated: true)+ }++ private func scrollToMakeVisible(_ element: FocusedElement, focusedView: UIView?, animated: Bool = true) {+ guard let collectionView else { return }++ if let target = focusedView ?? hostView(for: element) {+ revealInEnclosingScrollers(target, element: element, animated: animated)+ return+ }++ if case .cell(let indexPath) = element {+ if isPrimarilyVertical(collectionView) {+ collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: animated)+ } else {+ collectionView.scrollToItem(at: indexPath, at: [], animated: animated)+ }+ return+ }++ guard let attributes = layoutAttributes(for: element) else { return }+ if isPrimarilyVertical(collectionView) {+ centerVertically(attributes.frame, in: collectionView, animated: animated)+ } else {+ revealRect(attributes.frame.insetBy(dx: -8, dy: -8), in: collectionView, animated: animated)+ }+ }++ /// Nested horizontal scrollers: minimum reveal. This collection, if it+ /// scrolls vertically, centers the item. Stops here so a parent pager+ /// (Home `PageContentView`) is not moved.+ private func revealInEnclosingScrollers(_ view: UIView, element: FocusedElement, animated: Bool) {+ var current: UIView? = view.superview+ while let candidate = current {+ if let scrollView = candidate as? UIScrollView, !scrollView.isPagingEnabled {+ if scrollView === collectionView {+ revealInCollection(view, element: element, animated: animated)+ } else if isPrimarilyHorizontal(scrollView) || isPrimarilyVertical(scrollView) {+ let frame = view.convert(view.bounds, to: scrollView).insetBy(dx: -8, dy: -8)+ revealRect(frame, in: scrollView, animated: animated)+ }+ }+ if candidate === collectionView { break }+ current = candidate.superview+ }+ }++ private func revealInCollection(_ view: UIView, element: FocusedElement, animated: Bool) {+ guard let collectionView else { return }+ if isPrimarilyVertical(collectionView) {+ switch element {+ case .cell(let indexPath):+ collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: animated)+ case .supplementary:+ centerVertically(view.convert(view.bounds, to: collectionView), in: collectionView, animated: animated)+ }+ return+ }+ let frame = view.convert(view.bounds, to: collectionView).insetBy(dx: -8, dy: -8)+ revealRect(frame, in: collectionView, animated: animated)+ }++ /// True when this scroller's extra content is mainly on X (orthogonal strips).+ private func isPrimarilyHorizontal(_ scrollView: UIScrollView) -> Bool {+ let extraX = scrollView.contentSize.width - scrollView.bounds.width+ let extraY = scrollView.contentSize.height - scrollView.bounds.height+ return extraX > 1 && extraX > extraY+ }++ /// True when this scroller's extra content is mainly on Y (game grids, lists).+ private func isPrimarilyVertical(_ scrollView: UIScrollView) -> Bool {+ let extraX = scrollView.contentSize.width - scrollView.bounds.width+ let extraY = scrollView.contentSize.height - scrollView.bounds.height+ return extraY > 1 && extraY >= extraX+ }++ private func centerVertically(_ rect: CGRect, in scrollView: UIScrollView, animated: Bool) {+ let inset = scrollView.adjustedContentInset+ let visibleHeight = scrollView.bounds.height - inset.top - inset.bottom+ guard visibleHeight > 0.5 else { return }+ let minOffset = -inset.top+ let maxOffset = max(minOffset, scrollView.contentSize.height - scrollView.bounds.height + inset.bottom)+ var offset = scrollView.contentOffset+ offset.y = min(max(rect.midY - visibleHeight / 2 - inset.top, minOffset), maxOffset)+ guard abs(offset.y - scrollView.contentOffset.y) > 0.5 else { return }+ scrollView.setContentOffset(offset, animated: animated)+ }++ private func revealRect(_ rect: CGRect, in scrollView: UIScrollView, animated: Bool) {+ let visible = scrollView.bounds.inset(by: scrollView.adjustedContentInset)+ guard !visible.contains(rect) else { return }+ scrollView.scrollRectToVisible(rect, animated: animated)}// MARK: 确定键@@ -345,7 +465,13 @@ private final class FocusCollectionCoordinator: NSObject {// MARK: 聚焦- private func focus(_ element: FocusedElement, direction: FocusDirection?, originFrame: CGRect?, scroll: Bool = true) {+ private func focus(+ _ element: FocusedElement,+ direction: FocusDirection?,+ originFrame: CGRect?,+ preferredInner: UIView? = nil,+ scroll: Bool = true+ ) {if focusedElement != element, let focusedTarget {focusedTarget.fk_applyFocus(false)self.focusedTarget = nil@@ -355,6 +481,7 @@ private final class FocusCollectionCoordinator: NSObject {lastFocusedElement = elementpendingEntryDirection = directionpendingEntryOriginFrame = originFrame+ pendingPreferredInner = preferredInnerif scroll {scrollToMakeVisible(element, focusedView: nil)}@@ -385,8 +512,6 @@ private final class FocusCollectionCoordinator: NSObject {var target = focusedTargetif target == nil || (target !== currentHost && !(target!.isDescendant(of: currentHost))) {target = resolveFocusTarget(in: currentHost)- pendingEntryDirection = nil- pendingEntryOriginFrame = nil}guard let target else {focusedTarget?.fk_applyFocus(false)@@ -394,6 +519,9 @@ private final class FocusCollectionCoordinator: NSObject {focusedHost = nilscrollAnchor = elementfocusedElement = nil+ pendingPreferredInner = nil+ pendingEntryDirection = nil+ pendingEntryOriginFrame = nilreturn}@@ -402,6 +530,12 @@ private final class FocusCollectionCoordinator: NSObject {}focusedHost = currentHostfocusedTarget = target+ if let element = focusedElement {+ rememberInner(target, for: element)+ }+ pendingPreferredInner = nil+ pendingEntryDirection = nil+ pendingEntryOriginFrame = nil}private func resolvePendingProbeIfPossible() {@@ -416,15 +550,89 @@ private final class FocusCollectionCoordinator: NSObject {}private func resolveFocusTarget(in host: UIView) -> UIView? {- if host.fk_canFocus { return host }-- let candidates = FocusEngine.collectCandidates(in: host)+ if host.fk_canFocus {+ return host+ }+ let candidates = focusableTargets(in: host)guard !candidates.isEmpty else { return nil }++ if let preferred = pendingPreferredInner, isValidInner(preferred, host: host, candidates: candidates) {+ return preferred+ }+ if let element = focusedElement,+ let remembered = lastInner(for: element),+ isValidInner(remembered, host: host, candidates: candidates) {+ return remembered+ }if let direction = pendingEntryDirection, let origin = pendingEntryOriginFrame,- let best = FocusEngine.bestCandidate(from: origin, direction: direction, candidates: candidates) {+ let best = FocusEngine.bestCandidate(+ from: origin,+ direction: direction,+ candidates: candidates,+ searchBounds: FocusEngine.frameInWindow(of: host),+ expandPolicy: .verticalOnly,+ geometry: .viewFrame+ ) {return best}- return FocusEngine.initialCandidate(in: host) ?? host+ return FocusEngine.topLeadingCandidate(among: candidates)+ }++ private func focusableTargets(in host: UIView) -> [UIView] {+ var candidates = FocusEngine.collectFocusableDescendants(in: host)+ if host.fk_canFocus {+ candidates.append(host)+ }+ var seen = Set<ObjectIdentifier>()+ var resolved: [UIView] = []+ resolved.reserveCapacity(candidates.count)+ for view in candidates {+ if seen.insert(ObjectIdentifier(view)).inserted {+ resolved.append(view)+ }+ }+ return resolved+ }++ private func lastInner(for element: FocusedElement) -> UIView? {+ lastInnerByElement[element]?.view+ }++ private func rememberInner(_ view: UIView, for element: FocusedElement) {+ lastInnerByElement[element] = WeakView(view)+ }++ private func isValidInner(_ view: UIView, host: UIView, candidates: [UIView]) -> Bool {+ guard view === host || view.isDescendant(of: host) else { return false }+ return candidates.contains { $0 === view }+ }++ /// Enter an inner control from a focused cell. Origin is the cell's top-leading+ /// corner so inners inside the cell frame still count as down/right.+ private func firstInner(in host: UIView, from direction: FocusDirection) -> UIView? {+ let inners = FocusEngine.collectFocusableDescendants(in: host)+ guard !inners.isEmpty else { return nil }+ let hostFrame = FocusEngine.frameInWindow(of: host)+ let origin = CGRect(x: hostFrame.minX, y: hostFrame.minY, width: 1, height: 1)+ return FocusEngine.bestCandidate(+ from: origin,+ direction: direction,+ candidates: inners,+ searchBounds: hostFrame,+ expandPolicy: .all,+ geometry: .viewFrame+ ) ?? FocusEngine.topLeadingCandidate(among: inners)+ }++ private func moveFocusInsideCell(from current: UIView, to next: UIView, host: UIView, element: FocusedElement) {+ if current !== next {+ current.fk_applyFocus(false)+ }+ next.fk_applyFocus(true)+ rememberInner(next, for: element)+ focusedTarget = next+ focusedHost = host+ scrollToMakeVisible(element, focusedView: next)}// MARK: 可视区 / 滚动@@ -453,35 +661,6 @@ private final class FocusCollectionCoordinator: NSObject {return CGRect(x: frame.midX, y: frame.midY, width: 1, height: 1)}- private func scrollToReveal(_ element: FocusedElement, direction: FocusDirection?) {- guard let collectionView else { return }- switch element {- case .cell(let indexPath):- collectionView.scrollToItem(at: indexPath, at: scrollPosition(for: direction), animated: true)- case .supplementary:- scrollToMakeVisible(element, focusedView: nil, animated: true)- }- }-- private func scrollToMakeVisible(_ element: FocusedElement, focusedView: UIView?, animated: Bool = true) {- guard let collectionView else { return }-- let targetFrame: CGRect- if let focusedView {- targetFrame = focusedView.convert(focusedView.bounds, to: collectionView).insetBy(dx: -8, dy: -8)- } else if let host = hostView(for: element) {- targetFrame = host.convert(host.bounds, to: collectionView).insetBy(dx: -8, dy: -8)- } else if let attributes = layoutAttributes(for: element) {- targetFrame = attributes.frame.insetBy(dx: -8, dy: -8)- } else {- return- }-- let visible = collectionView.bounds.inset(by: collectionView.adjustedContentInset)- guard !visible.contains(targetFrame) else { return }- collectionView.scrollRectToVisible(targetFrame, animated: animated)- }-// MARK: 寻径private func nextElement(from current: FocusedElement, direction: FocusDirection) -> FocusedElement? {@@ -497,21 +676,7 @@ private final class FocusCollectionCoordinator: NSObject {}}- guard let attributes = layoutAttributes(for: current) else { return nil }-- if let found = spatialSearch(from: attributes, direction: direction) {- return found- }-- if direction.isHorizontal {- return nil- }-- if case .cell(let indexPath) = current,- let next = arithmeticNextSection(from: indexPath, direction: direction) {- return .cell(next)- }- return nil+ return sequentialItem(from: current, direction: direction)}private func adjacentItem(from current: IndexPath, direction: FocusDirection) -> IndexPath? {@@ -543,96 +708,53 @@ private final class FocusCollectionCoordinator: NSObject {return IndexPath(item: item, section: section)}- private func sharesRow(_ origin: CGRect, with candidate: CGRect, tolerance: CGFloat = 4) -> Bool {- candidate.maxY > origin.minY + tolerance && candidate.minY < origin.maxY - tolerance- }-- private func sharesColumn(_ origin: CGRect, with candidate: CGRect, tolerance: CGFloat = 4) -> Bool {- candidate.maxX > origin.minX + tolerance && candidate.minX < origin.maxX - tolerance- }-- private func spatialSearch(from origin: UICollectionViewLayoutAttributes, direction: FocusDirection) -> FocusedElement? {- guard let collectionView else { return nil }- let contentSize = collectionView.collectionViewLayout.collectionViewContentSize- let limit = direction.isHorizontal ? contentSize.width : contentSize.height-- var offset: CGFloat = 0- var distance: CGFloat = 600- while offset < limit + distance {- if let found = spatialSearch(from: origin, direction: direction, offset: offset, distance: distance) {- return found- }- offset += distance- distance = 3000+ /// Item-to-item search inside a collection, including section headers.+ /// Up/down pick the nearest row (header vs cells). Left/right stay in the+ /// current row so a full-width header cannot steal a hop between cells.+ private func sequentialItem(from current: FocusedElement, direction: FocusDirection) -> FocusedElement? {+ guard let originFrame = layoutAttributes(for: current)?.frame else { return nil }+ let items = allNavigableLayoutItems().filter { $0.element != current }+ guard !items.isEmpty else { return nil }+ let frames = items.map(\.frame)+ let bounds = frames.reduce(originFrame) { $0.union($1) }+ guard let index = FocusEngine.bestFrameIndex(+ from: originFrame,+ direction: direction,+ frames: frames,+ searchBounds: bounds,+ expandPolicy: .verticalOnly+ ) else {+ return nil}- return nil+ return items[index].element}- private func spatialSearch(from origin: UICollectionViewLayoutAttributes,- direction: FocusDirection,- offset: CGFloat,- distance: CGFloat) -> FocusedElement? {- guard let collectionView else { return nil }- let originFrame = origin.frame-- let searchRect: CGRect- switch direction {- case .up:- searchRect = CGRect(x: originFrame.minX, y: originFrame.midY - offset - distance,- width: originFrame.width, height: distance)- case .down:- searchRect = CGRect(x: originFrame.minX, y: originFrame.midY + offset,- width: originFrame.width, height: distance)- case .left:- searchRect = CGRect(x: originFrame.midX - offset - distance, y: originFrame.minY,- width: distance, height: originFrame.height)- case .right:- searchRect = CGRect(x: originFrame.midX + offset, y: originFrame.minY,- width: distance, height: originFrame.height)- }-- let candidates = collectionView.collectionViewLayout.layoutAttributesForElements(in: searchRect) ?? []-- var best: UICollectionViewLayoutAttributes?- var bestDistance = CGFloat.greatestFiniteMagnitude- var bestTransverse = CGFloat.greatestFiniteMagnitude-- for attributes in candidates {- guard !attributes.isHidden, attributes.alpha > 0 else { continue }- guard attributesElement(from: attributes) != attributesElement(from: origin) else { continue }- guard isNavigableAttributes(attributes) else { continue }-- let mainDistance: CGFloat- switch direction {- case .up: mainDistance = origin.center.y - attributes.center.y- case .down: mainDistance = attributes.center.y - origin.center.y- case .left: mainDistance = origin.center.x - attributes.center.x- case .right: mainDistance = attributes.center.x - origin.center.x- }- guard mainDistance > 0 else { continue }-- if direction.isHorizontal {- guard sharesRow(originFrame, with: attributes.frame) else { continue }- } else {- guard sharesColumn(originFrame, with: attributes.frame) else { continue }+ private func allNavigableLayoutItems() -> [(element: FocusedElement, frame: CGRect)] {+ guard let collectionView else { return [] }+ var result: [(FocusedElement, CGRect)] = []+ for section in 0..<collectionView.numberOfSections {+ for kind in [UICollectionView.elementKindSectionHeader, UICollectionView.elementKindSectionFooter] {+ let element = FocusedElement.supplementary(kind: kind, section: section)+ if let frame = layoutFrameIfNavigable(element) {+ result.append((element, frame))+ }}-- let transverse: CGFloat- if direction.isHorizontal {- transverse = abs(attributes.center.y - origin.center.y)- } else {- transverse = abs(attributes.center.x - origin.center.x)+ for item in 0..<collectionView.numberOfItems(inSection: section) {+ let element = FocusedElement.cell(IndexPath(item: item, section: section))+ if let frame = layoutFrameIfNavigable(element) {+ result.append((element, frame))+ }}+ }+ return result+ }- if mainDistance < bestDistance- || (mainDistance == bestDistance && (transverse < bestTransverse- || (transverse == bestTransverse && attributes.indexPath.section < (best?.indexPath.section ?? Int.max)))) {- best = attributes- bestDistance = mainDistance- bestTransverse = transverse- }+ private func layoutFrameIfNavigable(_ element: FocusedElement) -> CGRect? {+ guard isNavigableElement(element), let frame = layoutAttributes(for: element)?.frame else { return nil }+ if hostView(for: element) == nil {+ return frame}- return best.map { attributesElement(from: $0) }+ return isFocusableElement(element) ? frame : nil}private func entryElement(from direction: FocusDirection?) -> FocusedElement? {diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusContainer.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusContainer.swiftindex 457ad9b7..f91c9667 100644--- a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusContainer.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusContainer.swift@@ -18,11 +18,17 @@ enum FocusContainerResult {case exit}-/// 具有"进入层级"能力的容器视图。+/// A container that can be entered as a focus level.///-/// 对外层引擎而言,页面级寻径会展开容器内部已实例化的可聚焦后代参与打分;-/// 命中后调用 `enterFocus(from:preferred:)` 进入容器;容器内导航仍由容器自行管理。+/// Page-level search flattens focusable descendants; the container view is+/// never a candidate. `UICollectionView` then isolates D-pad to item/IndexPath+/// search; each cell is a mini-page for its inner focusable views. Other+/// containers stay in the page-level pool and only receive enter/leave callbacks.protocol FocusContainer: UIView {+ /// When true, D-pad stays inside this container until it returns `.exit`.+ /// `UICollectionView` isolates; generic containers stay in the page-level pool.+ var isolatesFocusNavigation: Bool { get }+/// 容器当前是否可以被进入(例如 UICollectionView 无任何 item 时应返回 false)var canEnterFocus: Bool { get }@@ -49,15 +55,15 @@ protocol FocusContainer: UIView {/// 焦点位于容器内部时生效的额外命令func containerFocusCommands() -> [FocusCommand]- /// 供外层空间寻径打分的"进入落点"参考矩形(window 坐标系)。- /// 全屏容器与页面上其他可聚焦视图(如悬浮工具条)frame 重叠时,- /// 容器整体 frame 会被半平面过滤排除导致无法进入;- /// 返回进入后实际会落焦的位置可让打分准确。返回 nil 表示使用容器整体 frame。+ /// Window-space rect used when the container itself is the candidate (no+ /// flattened descendant). Prefer the entry slot over the full container+ /// frame so a full-screen list can still lose to a floating toolbar.func focusEntryFrame(from direction: FocusDirection) -> CGRect?}extension FocusContainer {var canEnterFocus: Bool { true }+ var isolatesFocusNavigation: Bool { false }func containerFocusCommands() -> [FocusCommand] { [] }func focusEntryFrame(from direction: FocusDirection) -> CGRect? { nil }diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusContext.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusContext.swiftindex 42ae8474..d56b1d40 100644--- a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusContext.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusContext.swift@@ -16,9 +16,22 @@ import ProHUD/// ProHUD 的 alert/sheet、侧边栏等都可以各自作为一个 context。/// `FocusSystem` 以栈维护 context,只有栈顶 context 接收输入事件。final class FocusContext {- /// 焦点导航的根视图,候选收集只在此子树内进行+ /// 焦点导航的根视图,候选收集默认在此子树内进行private(set) weak var rootView: UIView?+ /// Views that participate in page-level search even if they are not+ /// descendants of `rootView` (parent-owned chrome such as a tab bar).+ private var additionalSearchRootRefs: [WeakSearchRoot] = []++ private final class WeakSearchRoot {+ weak var view: UIView?+ let enterHeadings: Set<FocusDirection>+ init(_ view: UIView, enterHeadings: Set<FocusDirection>) {+ self.view = view+ self.enterHeadings = enterHeadings+ }+ }+/// 页面拥有者(UIViewController / ProHUD 的 SheetTarget、AlertTarget 等),/// 用于取消键(b)的默认关闭行为private(set) weak var owner: AnyObject?@@ -73,6 +86,38 @@ final class FocusContext {commands.removeAll()}+ /// Register chrome that should compete in this page's directional search.+ /// `enterHeadings` limits which D-pad directions may land in that chrome+ /// (bottom tab bar: `.down` only, so left/right/up stay in page content).+ func addAdditionalSearchRoot(_ view: UIView, enterHeadings: Set<FocusDirection> = [.down]) {+ additionalSearchRootRefs.removeAll { $0.view == nil || $0.view === view }+ additionalSearchRootRefs.append(WeakSearchRoot(view, enterHeadings: enterHeadings))+ }++ var additionalSearchRoots: [UIView] {+ additionalSearchRootRefs.compactMap(\.view)+ }++ func additionalSearchRoots(entering direction: FocusDirection) -> [UIView] {+ additionalSearchRootRefs.compactMap { ref in+ guard let view = ref.view, ref.enterHeadings.contains(direction) else { return nil }+ return view+ }+ }++ /// Whether `view` belongs to this page: `rootView` or an additional search root.+ func contains(_ view: UIView) -> Bool {+ if let root = rootView, view === root || view.isDescendant(of: root) {+ return true+ }+ for extra in additionalSearchRoots {+ if view === extra || view.isDescendant(of: extra) {+ return true+ }+ }+ return false+ }+// MARK: - 取消键默认行为/// 取消键(b)处理:cancelHandler 优先,未消费则按 owner 类型执行默认关闭diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusEngine.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusEngine.swiftindex 65825cef..830c8454 100644--- a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusEngine.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusEngine.swift@@ -9,27 +9,53 @@import UIKit-/// 空间寻径引擎:负责候选收集与"按下方向键后该聚焦谁"的核心算法。+/// Spatial focus engine: collect candidates and pick the next view for a D-pad heading.///-/// 设计原则(视觉优先):-/// - 所有候选使用 window 坐标系下的真实 frame 打分;-/// - 可见面积不足 1/3(≥2/3 在屏外)的候选不参与寻径,避免 PageView 邻页露边被误选;-/// - 页面级寻径时展开 FocusContainer 内部已实例化的可聚焦后代,用真实 frame 与悬浮层竞争;-/// 命中后代后由 FocusSystem 折叠为 enterContainer,容器内仍走 indexPath 导航;-/// - 离开容器时排除该容器整棵子树,只与页面级 sibling 竞争;-/// - 半平面 + 投影重叠 + 主轴距离的经典空间寻径,不做屏外兜底。+/// Three layers:+/// 1. Page-level: every focusable descendant competes. Container views are+/// skipped; a hit inside a container then calls enter/leave APIs.+/// 2. `UICollectionView` isolates after enter. Item-to-item search uses each+/// cell's layout frame and IndexPath so an off-axis inner switch does not+/// cause the engine to skip that item.+/// 3. Cell interior is a mini-page: the cell is the search root, inner+/// focusable views compete with their own frames (never the cell layout+/// frame). Same lane-then-expand rules, clipped to the cell. Re-entering+/// an item restores the last inner focus.+///+/// Geometry: left/right stay in the same row when a same-row target exists+/// (page-level `.all` then fans out if the row is empty). Up/down pick the+/// nearest in-heading target so a closer overlay is not skipped.enum FocusEngine {- /// 判定"在方向半平面内"时允许的边缘重叠容差- private static let overlapTolerance: CGFloat = 4+ private static let lanePadRatio: CGFloat = 0.15+ private static let lanePadFloor: CGFloat = 8+ /// Y-overlap above this fraction of the smaller height means "same row".+ private static let sameRowOverlapRatio: CGFloat = 0.35+ private static let sameRowOverlapFloor: CGFloat = 4++ enum ExpandPolicy {+ /// Lane only. Left/right that must yield to a neighbor use this.+ case none+ /// Up/down may fan out across the search root; left/right stay in the row.+ case verticalOnly+ /// Left/right: same row first, then nearest in-heading (side panes).+ /// Up/down: nearest in-heading so a closer overlay is not skipped.+ case all+ }- /// 视图面积中处于屏幕外的比例 ≥ 此值时视为屏外(可见面积须 > 1/3)- private static let offScreenAreaThreshold: CGFloat = 2.0 / 3.0+ /// Which window rect represents a candidate while scoring.+ enum GeometryPolicy {+ /// The view's own frame. Cell-interior / mini-page search.+ case viewFrame+ /// Enclosing collection item layout frame so an off-axis switch still+ /// stands in for its row at page level.+ case collectionItemFrame+ }- // MARK: - 候选收集+ // MARK: - Candidate collection- /// 深度遍历 root 子树,收集可聚焦视图。- /// - `excludingContainerSubtree`:容器退出时的页面级寻径,整棵子树不参与候选。+ /// Depth-first collect of focusable views under `root`.+ /// - `excludingContainerSubtree`: when leaving a container, omit that whole tree.static func collectCandidates(in root: UIView, excludingContainerSubtree: UIView? = nil) -> [UIView] {var result: [UIView] = []collect(from: root, into: &result, excludingContainerSubtree: excludingContainerSubtree)@@ -45,15 +71,9 @@ enum FocusEngine {if let container = view as? FocusContainer, view.isFocusable {if container.canEnterFocus {- var flattened: [UIView] = []- collectFlattenedInterior(from: view, into: &flattened)- if flattened.isEmpty {- result.append(view)- } else {- result.append(contentsOf: flattened)- }+ collectFlattenedInterior(from: view, into: &result)} else {- // Empty collections still host overlays (blank slate). Keep walking children.+ // Empty collections can still host overlays (blank slate).for subview in view.subviews {collect(from: subview, into: &result, excludingContainerSubtree: excludingContainerSubtree)}@@ -61,7 +81,7 @@ enum FocusEngine {return}- if view.fk_canFocus {+ if view.isFocusable {result.append(view)return}@@ -71,23 +91,26 @@ enum FocusEngine {}}- /// 展开容器内部已实例化的可聚焦后代(嵌套容器递归展开)+ /// Focusable descendants of `host` (not `host` itself). Walks into a+ /// focusable host so a cell and its switch can both participate.+ static func collectFocusableDescendants(in host: UIView) -> [UIView] {+ var result: [UIView] = []+ for subview in host.subviews {+ collect(from: subview, into: &result, excludingContainerSubtree: nil)+ }+ return result+ }+private static func collectFlattenedInterior(from view: UIView, into result: inout [UIView]) {for subview in view.subviews {guard !subview.isHidden, subview.alpha > 0.01 else { continue }if let nested = subview as? FocusContainer, subview.isFocusable, nested.canEnterFocus {- var inner: [UIView] = []- collectFlattenedInterior(from: subview, into: &inner)- if inner.isEmpty {- result.append(subview)- } else {- result.append(contentsOf: inner)- }+ collectFlattenedInterior(from: subview, into: &result)continue}- if subview.fk_canFocus {+ if subview.isFocusable {result.append(subview)continue}@@ -96,7 +119,7 @@ enum FocusEngine {}}- /// 向上查找可进入的 FocusContainer 祖先+ /// Nearest enterable FocusContainer ancestor (or the view itself).static func focusContainer(for view: UIView) -> (UIView & FocusContainer)? {var current: UIView? = viewwhile let candidate = current {@@ -108,12 +131,12 @@ enum FocusEngine {return nil}- // MARK: - 初始焦点+ // MARK: - Initial focus- /// 选择初始焦点:屏内候选里尽可能靠近左上角(x、y 同等权重)+ /// First focus: on-screen candidate closest to the top-leading corner.static func initialCandidate(in root: UIView) -> UIView? {- let visibleBounds = root.window?.bounds- let candidates = onScreenCandidates(from: collectCandidates(in: root), visibleBounds: visibleBounds)+ let visibleBounds = searchBounds(for: root)+ let candidates = visibleCandidates(from: collectCandidates(in: root), visibleBounds: visibleBounds)guard !candidates.isEmpty else { return nil }return candidates.min { lhs, rhs in@@ -129,47 +152,193 @@ enum FocusEngine {return lhs.minX < rhs.minX}- // MARK: - 方向寻径+ // MARK: - Directional search- /// 从 origin 出发,在 root 子树内寻找 direction 方向上最合适的下一个焦点。- /// 仅返回屏内候选;无候选时返回 nil(由 FocusSystem 通知业务方滚动)。+ /// Next focus from `origin` under `root`. Returns nil when nothing is in-heading (caller may scroll).+ /// `additionalRoots` are searched too (chrome that is not a descendant of `root`).static func nextCandidate(from origin: UIView,direction: FocusDirection,in root: UIView,originFrame: CGRect? = nil,- excludingContainerSubtree: UIView? = nil+ excludingContainerSubtree: UIView? = nil,+ additionalRoots: [UIView] = []) -> UIView? {let frame = originFrame ?? frameInWindow(of: origin)- let visibleBounds = origin.window?.bounds- let candidates = onScreenCandidates(- from: collectCandidates(in: root, excludingContainerSubtree: excludingContainerSubtree).filter {- !$0.isDescendant(of: origin) && !origin.isDescendant(of: $0)+ var collected = collectCandidates(in: root, excludingContainerSubtree: excludingContainerSubtree)+ for extra in additionalRoots {+ guard extra !== root, extra !== excludingContainerSubtree else { continue }+ if extra.isDescendant(of: root) { continue }+ if let excluded = excludingContainerSubtree, extra.isDescendant(of: excluded) { continue }+ collected.append(contentsOf: collectCandidates(in: extra, excludingContainerSubtree: excludingContainerSubtree))+ }+ var bounds = searchBounds(for: root) ?? searchBounds(for: origin)+ for extra in additionalRoots {+ if let extraBounds = searchBounds(for: extra) {+ bounds = bounds.map { $0.union(extraBounds) } ?? extraBounds+ }+ }+ let candidates = visibleCandidates(+ from: collected.filter {+ $0 !== origin && !$0.isDescendant(of: origin) && !origin.isDescendant(of: $0)},- visibleBounds: visibleBounds+ visibleBounds: bounds+ )+ return bestCandidate(+ from: frame,+ direction: direction,+ candidates: candidates,+ searchBounds: bounds,+ expandPolicy: .all,+ geometry: .collectionItemFrame+ )+ }++ /// Mini-page search inside `host` (a collection cell, header, or similar).+ /// `host` is the search root, not a candidate. Inner views use their own+ /// frames; up/down may fan out only within `host`.+ static func nextCandidate(+ from origin: UIView,+ direction: FocusDirection,+ insideHost host: UIView+ ) -> UIView? {+ let inners = collectFocusableDescendants(in: host)+ let group: [UIView]+ if origin !== host {+ group = inners.filter { $0 !== origin && !$0.isDescendant(of: origin) }+ } else {+ group = inners+ }+ guard !group.isEmpty else { return nil }+ return bestCandidate(+ from: frameInWindow(of: origin),+ direction: direction,+ candidates: group,+ searchBounds: frameInWindow(of: host),+ expandPolicy: .verticalOnly,+ geometry: .viewFrame)- return bestCandidate(from: frame, direction: direction, candidates: candidates)}- /// 纯几何打分。容器兜底候选使用 `focusEntryFrame`,其余用自身 window frame。- static func bestCandidate(from originFrame: CGRect, direction: FocusDirection, candidates: [UIView]) -> UIView? {- var best: UIView?+ /// Geometric pick among views.+ static func bestCandidate(+ from originFrame: CGRect,+ direction: FocusDirection,+ candidates: [UIView],+ searchBounds: CGRect? = nil,+ expandPolicy: ExpandPolicy = .verticalOnly,+ geometry: GeometryPolicy = .collectionItemFrame+ ) -> UIView? {+ guard !candidates.isEmpty else { return nil }+ let frames = candidates.map { scoringFrame(for: $0, direction: direction, geometry: geometry) }+ let bounds = searchBounds ?? boundsSpanned(by: originFrame, frames: frames)+ guard let index = bestFrameIndex(+ from: originFrame,+ direction: direction,+ frames: frames,+ searchBounds: bounds,+ expandPolicy: expandPolicy+ ) else {+ return nil+ }+ return candidates[index]+ }++ /// Top-leading view among already-collected candidates (own frames).+ static func topLeadingCandidate(among views: [UIView]) -> UIView? {+ views.min { lhs, rhs in+ preferTopLeft(frameInWindow(of: lhs), frameInWindow(of: rhs))+ }+ }++ /// Geometric pick among raw frames (content space or window space).+ ///+ /// Horizontal headings keep the row unless `.all` finds the row empty+ /// (then the nearest in-heading target, e.g. a side pane). Vertical+ /// headings with expand pick nearest on the main axis so a closer+ /// overlay wins over a farther in-lane cell.+ static func bestFrameIndex(+ from originFrame: CGRect,+ direction: FocusDirection,+ frames: [CGRect],+ searchBounds: CGRect,+ expandPolicy: ExpandPolicy = .verticalOnly+ ) -> Int? {+ func pick(expandCrossAxis: Bool) -> Int? {+ pickIndex(+ from: originFrame,+ direction: direction,+ frames: frames,+ bounds: searchBounds,+ expandCrossAxis: expandCrossAxis+ )+ }+ switch expandPolicy {+ case .none:+ return pick(expandCrossAxis: false)+ case .verticalOnly:+ return pick(expandCrossAxis: !direction.isHorizontal)+ case .all:+ if direction.isHorizontal, let lane = pick(expandCrossAxis: false) {+ return lane+ }+ return pick(expandCrossAxis: true)+ }+ }++ /// Heading half-plane used to query layout attributes.+ static func headingSearchRect(+ from origin: CGRect,+ direction: FocusDirection,+ bounds: CGRect,+ expandCrossAxis: Bool+ ) -> CGRect {+ searchRect(from: origin, direction: direction, bounds: bounds, expandCrossAxis: expandCrossAxis)+ }++ private static func pickIndex(+ from origin: CGRect,+ direction: FocusDirection,+ frames: [CGRect],+ bounds: CGRect,+ expandCrossAxis: Bool+ ) -> Int? {+ let beam = searchRect(from: origin, direction: direction, bounds: bounds, expandCrossAxis: expandCrossAxis)+ guard beam.width > 0.5, beam.height > 0.5 else { return nil }++ var bestIndex: Int?var bestScore: Score?- for candidate in candidates {- let targetFrame = scoringFrame(for: candidate, direction: direction)- guard let score = score(from: originFrame, to: targetFrame, direction: direction) else { continue }+ for (index, target) in frames.enumerated() {+ guard let score = score(+ from: origin,+ to: target,+ direction: direction,+ beam: beam,+ requireLane: !expandCrossAxis+ ) else {+ continue+ }if bestScore == nil || score < bestScore! {- best = candidate+ bestIndex = indexbestScore = score}}- return best+ return bestIndex}- /// 参与打分的矩形:容器兜底候选取进入落点,其余取 window frame- private static func scoringFrame(for candidate: UIView, direction: FocusDirection) -> CGRect {- if let container = candidate as? (UIView & FocusContainer),+ /// Empty containers are not candidates; this is only a fallback if one slips through.+ private static func scoringFrame(+ for candidate: UIView,+ direction: FocusDirection,+ geometry: GeometryPolicy+ ) -> CGRect {+ if geometry == .collectionItemFrame,+ let itemFrame = collectionItemFrameInWindow(for: candidate) {+ return itemFrame+ }+ if geometry == .collectionItemFrame,+ let container = candidate as? (UIView & FocusContainer),container.isFocusable,let entryFrame = container.focusEntryFrame(from: direction) {return entryFrame@@ -177,102 +346,241 @@ enum FocusEngine {return frameInWindow(of: candidate)}- /// 仅保留屏内可见面积超过 1/3 的候选(≤1/3 可见视为屏外)- private static func onScreenCandidates(from candidates: [UIView], visibleBounds: CGRect?) -> [UIView] {+ /// Prefer the cell/supplementary layout frame so an off-axis inner switch+ /// still represents its item in page-level competition.+ static func collectionItemFrameInWindow(for view: UIView) -> CGRect? {+ guard let window = view.window else { return nil }+ var current: UIView? = view+ while let candidate = current {+ if let cell = candidate as? UICollectionViewCell,+ let collectionView = cell.superview as? UICollectionView,+ collectionView.isFocusable,+ let indexPath = collectionView.indexPath(for: cell),+ let attributes = collectionView.layoutAttributesForItem(at: indexPath) {+ return collectionView.convert(attributes.frame, to: window)+ }+ if let reusable = candidate as? UICollectionReusableView,+ reusable.superview is UICollectionView,+ let collectionView = reusable.superview as? UICollectionView,+ collectionView.isFocusable {+ for section in 0..<collectionView.numberOfSections {+ for kind in [UICollectionView.elementKindSectionHeader, UICollectionView.elementKindSectionFooter] {+ let indexPath = IndexPath(item: 0, section: section)+ if collectionView.supplementaryView(forElementKind: kind, at: indexPath) === reusable,+ let attributes = collectionView.layoutAttributesForSupplementaryElement(ofKind: kind, at: indexPath) {+ return collectionView.convert(attributes.frame, to: window)+ }+ }+ }+ }+ if candidate is UICollectionView { break }+ current = candidate.superview+ }+ return nil+ }++ /// Any on-screen pixel is enough. Fully off-screen views are skipped.+ private static func visibleCandidates(from candidates: [UIView], visibleBounds: CGRect?) -> [UIView] {guard let bounds = visibleBounds else { return candidates }- return candidates.filter { isSufficientlyVisibleInWindow(frameInWindow(of: $0), visibleBounds: bounds) }+ return candidates.filter { isVisibleInWindow(frameInWindow(of: $0), visibleBounds: bounds) }}- /// 视图在 window 中的可见面积占比是否超过 (1 - offScreenAreaThreshold),即少于 2/3 在屏外- static func isSufficientlyVisibleInWindow(_ frame: CGRect, visibleBounds: CGRect) -> Bool {+ private static func isVisibleInWindow(_ frame: CGRect, visibleBounds: CGRect) -> Bool {guard frame.width > 0, frame.height > 0 else { return false }let intersection = frame.intersection(visibleBounds)- guard !intersection.isNull, intersection.width > 0, intersection.height > 0 else { return false }- let visibleRatio = (intersection.width * intersection.height) / (frame.width * frame.height)- return visibleRatio > (1 - offScreenAreaThreshold)+ return !intersection.isNull && intersection.width > 0.5 && intersection.height > 0.5}- // MARK: - 打分+ // MARK: - Scoring- /// 排序键(越小越优):- /// 1. 横向/纵向投影是否与 origin 重叠(正右方胜过斜右方更近)- /// 2. 主轴边到边距离- /// 3. 横轴中心偏移- /// 4. tie-break+ /// Smaller is better. Nearest ahead on the heading, then less side gap.private struct Score: Comparable {- let overlapGroup: Int // 0 = 投影重叠, 1 = 不重叠let mainDistance: CGFloat- let transverseDistance: CGFloat+ let transverseGap: CGFloatlet tieBreak: CGFloatstatic func < (lhs: Score, rhs: Score) -> Bool {- if lhs.overlapGroup != rhs.overlapGroup { return lhs.overlapGroup < rhs.overlapGroup }- if abs(lhs.mainDistance - rhs.mainDistance) > 0.5 { return lhs.mainDistance < rhs.mainDistance }- if abs(lhs.transverseDistance - rhs.transverseDistance) > 0.5 { return lhs.transverseDistance < rhs.transverseDistance }+ if abs(lhs.mainDistance - rhs.mainDistance) > 0.5 {+ return lhs.mainDistance < rhs.mainDistance+ }+ if abs(lhs.transverseGap - rhs.transverseGap) > 0.5 {+ return lhs.transverseGap < rhs.transverseGap+ }return lhs.tieBreak < rhs.tieBreak}}- /// 目标整体位于 origin 的 direction 方向外侧(允许少量重叠容差),且中心在同侧- private static func isBeyond(_ target: CGRect, of origin: CGRect, direction: FocusDirection) -> Bool {+ private static func score(+ from origin: CGRect,+ to target: CGRect,+ direction: FocusDirection,+ beam: CGRect,+ requireLane: Bool+ ) -> Score? {+ guard isInHeading(target, of: origin, direction: direction) else { return nil }+ if requireLane {+ guard sharesLane(origin, target, direction: direction) else { return nil }+ }++ let hit = target.intersection(beam)+ guard !hit.isNull, hit.width > 0.5, hit.height > 0.5 else { return nil }++ return Score(+ mainDistance: mainAxisDistance(from: origin, to: target, direction: direction),+ transverseGap: crossAxisGap(from: origin, to: target, direction: direction),+ tieBreak: target.minY * 10000 + target.minX+ )+ }++ /// Center must sit further along the heading, and the target must actually+ /// start further on that axis. A full-width header that contains a cell+ /// has a further center but a smaller minX — it is not "to the right".+ static func isInHeading(_ target: CGRect, of origin: CGRect, direction: FocusDirection) -> Bool {switch direction {- case .up: return target.maxY <= origin.minY + overlapTolerance && target.midY < origin.midY- case .down: return target.minY >= origin.maxY - overlapTolerance && target.midY > origin.midY- case .left: return target.maxX <= origin.minX + overlapTolerance && target.midX < origin.midX- case .right: return target.minX >= origin.maxX - overlapTolerance && target.midX > origin.midX+ case .up:+ return target.midY < origin.midY - 0.5 && target.maxY < origin.maxY - 0.5+ case .down:+ return target.midY > origin.midY + 0.5 && target.minY > origin.minY + 0.5+ case .left:+ return target.midX < origin.midX - 0.5 && target.maxX < origin.maxX - 0.5+ case .right:+ return target.midX > origin.midX + 0.5 && target.minX > origin.minX + 0.5}}- private static func score(from origin: CGRect, to target: CGRect, direction: FocusDirection) -> Score? {- guard isBeyond(target, of: origin, direction: direction) else { return nil }+ /// Lane pass: the two frames must overlap enough on the cross axis.+ /// A few pixels of contact from beam padding is not a shared row/column.+ ///+ /// A full-bleed view always contains a small origin on the cross axis+ /// (a 28pt nav icon vs a list row). That is not the same column; the+ /// expand pass should still see nearer centered overlays.+ static func sharesLane(_ origin: CGRect, _ target: CGRect, direction: FocusDirection) -> Bool {+ let overlap: CGFloat+ let smaller: CGFloat+ let larger: CGFloat+ if direction.isHorizontal {+ overlap = min(origin.maxY, target.maxY) - max(origin.minY, target.minY)+ smaller = min(origin.height, target.height)+ larger = max(origin.height, target.height)+ } else {+ overlap = min(origin.maxX, target.maxX) - max(origin.minX, target.minX)+ smaller = min(origin.width, target.width)+ larger = max(origin.width, target.width)+ }+ guard overlap > sameRowOverlapFloor, smaller > 0.5 else { return false }+ if larger > smaller * 2, overlap < larger * sameRowOverlapRatio {+ return false+ }+ return overlap >= smaller * sameRowOverlapRatio+ }- let mainDistance: CGFloat+ /// Distance to the target's near edge along the heading. Symmetric for reverse.+ static func mainAxisDistance(from origin: CGRect, to target: CGRect, direction: FocusDirection) -> CGFloat {switch direction {- case .up: mainDistance = max(0, origin.minY - target.maxY)- case .down: mainDistance = max(0, target.minY - origin.maxY)- case .left: mainDistance = max(0, origin.minX - target.maxX)- case .right: mainDistance = max(0, target.minX - origin.maxX)+ case .right: return target.minX - origin.maxX+ case .left: return origin.minX - target.maxX+ case .down: return target.minY - origin.maxY+ case .up: return origin.minY - target.maxY}+ }- let overlaps: Bool- let transverseDistance: CGFloat- let tieBreak: CGFloat+ /// Gap between the two intervals on the cross axis (0 when they overlap).+ private static func crossAxisGap(from origin: CGRect, to target: CGRect, direction: FocusDirection) -> CGFloat {if direction.isHorizontal {- overlaps = target.maxY > origin.minY && target.minY < origin.maxY- transverseDistance = abs(target.midY - origin.midY)- tieBreak = target.minY * 10000 + target.minX- } else {- overlaps = target.maxX > origin.minX && target.minX < origin.maxX- transverseDistance = abs(target.midX - origin.midX)- tieBreak = target.minY * 10000 + target.minX+ if target.maxY < origin.minY { return origin.minY - target.maxY }+ if target.minY > origin.maxY { return target.minY - origin.maxY }+ return 0}+ if target.maxX < origin.minX { return origin.minX - target.maxX }+ if target.minX > origin.maxX { return target.minX - origin.maxX }+ return 0+ }- return Score(- overlapGroup: overlaps ? 0 : 1,- mainDistance: mainDistance,- transverseDistance: transverseDistance,- tieBreak: tieBreak- )+ /// Beam along the heading. Narrow pass is the origin lane (with a little pad).+ /// Expanded pass uses the full search bounds on the cross axis.+ /// Main-axis start is the origin's near edge so overlapping views are included.+ private static func searchRect(+ from origin: CGRect,+ direction: FocusDirection,+ bounds: CGRect,+ expandCrossAxis: Bool+ ) -> CGRect {+ switch direction {+ case .right:+ let lane = horizontalLane(origin: origin, bounds: bounds, expand: expandCrossAxis)+ return CGRect(x: origin.minX, y: lane.origin, width: max(0, bounds.maxX - origin.minX), height: lane.size)+ case .left:+ let lane = horizontalLane(origin: origin, bounds: bounds, expand: expandCrossAxis)+ return CGRect(x: bounds.minX, y: lane.origin, width: max(0, origin.maxX - bounds.minX), height: lane.size)+ case .down:+ let lane = verticalLane(origin: origin, bounds: bounds, expand: expandCrossAxis)+ return CGRect(x: lane.origin, y: origin.minY, width: lane.size, height: max(0, bounds.maxY - origin.minY))+ case .up:+ let lane = verticalLane(origin: origin, bounds: bounds, expand: expandCrossAxis)+ return CGRect(x: lane.origin, y: bounds.minY, width: lane.size, height: max(0, origin.maxY - bounds.minY))+ }}- // MARK: - 工具+ private static func horizontalLane(origin: CGRect, bounds: CGRect, expand: Bool) -> (origin: CGFloat, size: CGFloat) {+ if expand { return (bounds.minY, bounds.height) }+ let pad = max(lanePadFloor, origin.height * lanePadRatio)+ let minY = max(bounds.minY, origin.minY - pad)+ let maxY = min(bounds.maxY, origin.maxY + pad)+ return (minY, max(0, maxY - minY))+ }++ private static func verticalLane(origin: CGRect, bounds: CGRect, expand: Bool) -> (origin: CGFloat, size: CGFloat) {+ if expand { return (bounds.minX, bounds.width) }+ let pad = max(lanePadFloor, origin.width * lanePadRatio)+ let minX = max(bounds.minX, origin.minX - pad)+ let maxX = min(bounds.maxX, origin.maxX + pad)+ return (minX, max(0, maxX - minX))+ }++ /// On-screen portion of `view` in window space. Sheets expand to the sheet, not the window.+ private static func searchBounds(for view: UIView) -> CGRect? {+ guard let window = view.window else { return nil }+ let rootFrame = view.convert(view.bounds, to: window)+ let intersection = rootFrame.intersection(window.bounds)+ if intersection.isNull || intersection.width < 0.5 || intersection.height < 0.5 {+ return window.bounds+ }+ return intersection+ }- /// 视图 frame 换算到 window 坐标系+ private static func boundsSpanned(by origin: CGRect, frames: [CGRect]) -> CGRect {+ frames.reduce(origin) { $0.union($1) }+ }++ // MARK: - Geometry helpers++ /// Window frame used for pathfinding. Ignores this view's own transform so a+ /// focus lift (scale + translate up) does not make same-row siblings look+ /// like they sit below. Ancestor transforms (carousel layout) are kept.static func frameInWindow(of view: UIView) -> CGRect {guard let window = view.window else { return view.frame }+ if view.focusEffect, view.transform != .identity, let superview = view.superview {+ let size = view.bounds.size+ let untransformed = CGRect(+ x: view.center.x - size.width / 2,+ y: view.center.y - size.height / 2,+ width: size.width,+ height: size.height+ )+ return superview.convert(untransformed, to: window)+ }return view.convert(view.bounds, to: window)}- /// 目标在滚动容器中不完全可见时,滚动使其可见。- /// UICollectionView 容器自行处理滚动,这里只处理普通 UIScrollView 祖先。+ /// Scroll an ordinary UIScrollView ancestor so `view` is on-screen.+ /// Collection containers scroll themselves; paging parents must not move.static func ensureVisible(_ view: UIView) {var current = view.superviewwhile let candidate = current {- if let collectionView = candidate as? UICollectionView {- current = collectionView.superview- continue+ if candidate is UICollectionView {+ return}- if let scrollView = candidate as? UIScrollView {+ if let scrollView = candidate as? UIScrollView, !scrollView.isPagingEnabled {let frame = view.convert(view.bounds, to: scrollView)let visible = scrollView.bounds.inset(by: scrollView.adjustedContentInset)if !visible.contains(frame) {diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusKeyObserver.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusKeyObserver.swiftindex 8286ae38..ac1aa866 100644--- a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusKeyObserver.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusKeyObserver.swift@@ -14,6 +14,9 @@ import Foundation/// 键盘由 DeltaCore 的 KeyboardGameController 通过 GCKeyboard(HID 原始按键状态)采集,/// 完全绕开 UIKit 的 UIKeyCommand/系统快捷键消费机制(系统保留组合如 ⌃⌘F 除外)。///+/// 仅在 ExternalInputDispatch.sink == .focusKit 时处理(未游戏或游戏已暂停)。+/// 游戏运行中的按键由 PlayViewController 与模拟核心接收,不经过本类。+////// 本类只负责两件事:/// 1. 摇杆方向输入的按住去重;/// 2. 键盘修饰键组合成 chord,固定顺序 control → option → shift → command,@@ -36,13 +39,21 @@ class FocusKeyObserver {private static var activeComposedKeys = [String: String]()func start() {+ _ = FocusSystem.sharedexternalGameControllerDidPress = NotificationCenter.default.addObserver(forName: .externalGameControllerDidPress, object: nil, queue: .main) { notification in- guard !PlayViewController.isGaming else { return }+ guard ExternalInputDispatch.sink == .focusKit else { return }if let userInfo = notification.userInfo,let input = userInfo["input"] as? any Input {if input.type == .controller(.keyboard) {+ if FocusSystem.shared.isEditingText {+ // Letters stay with the field; Escape still ends editing.+ if input.stringValue == "escape" {+ Self.handleKeyboard(input.stringValue, isPressed: true)+ }+ return+ }Self.handleKeyboard(input.stringValue, isPressed: true)return}@@ -52,7 +63,7 @@ class FocusKeyObserver {}externalGameControllerDidRelease = NotificationCenter.default.addObserver(forName: .externalGameControllerDidRelease, object: nil, queue: .main) { notification in- guard !PlayViewController.isGaming else { return }+ guard ExternalInputDispatch.sink == .focusKit else { return }if let userInfo = notification.userInfo,let input = userInfo["input"] as? any Input {@@ -89,6 +100,10 @@ class FocusKeyObserver {// MARK: - 键盘处理+ func handleTextEditingDidBegin() {+ Self.resetKeyboardState()+ }+private static func resetKeyboardState() {heldModifiers.removeAll()activeComposedKeys.removeAll()@@ -140,12 +155,10 @@ class FocusKeyObserver {// MARK: - 输出private static func activateKey(_ key: String) {- Log.debug("[FocusKeyObserver] activateKey: \(key)")FocusSystem.shared.keyDown(mappingKey(key))}private static func deactivateKey(_ key: String) {- Log.debug("[FocusKeyObserver] deactivateKey: \(key)")// 释放时走同样的映射,保证 keyDown/keyUp 配对FocusSystem.shared.keyUp(mappingKey(key))}diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusShortcutsTipsView.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusShortcutsTipsView.swiftnew file mode 100644index 00000000..146b811a--- /dev/null+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusShortcutsTipsView.swift@@ -0,0 +1,512 @@+//+// FocusShortcutsTipsView.swift+// ManicEmu+//+// Created by Daiuno on 2026/8/18.+// Copyright © 2026 Manic EMU. All rights reserved.+//++import UIKit++/// Full-screen shortcut cheatsheet. Shown while Command / Control / Select is held;+/// not focusable and not interactive. Gameplay never reaches here because FocusKit is off.+final class FocusShortcutsTipsView: BaseView, ViewTransition {++ enum Source {+ case keyboard+ case controller+ }++ private static let shared = FocusShortcutsTipsView()+ private static var holdingKeys = Set<FocusKey>()++ private static let cellHeight = R.Size.ItemHeightTiny+ private static let rowSpacing = R.Size.ContentSpaceSmall+ private static let columnSpacing = R.Size.ContentSpaceLarge+ private static let maxColumnWidth: CGFloat = 340+ private static let badgeHeight: CGFloat = R.Size.IconSizeMedium.height++ private var source: Source = .keyboard+ private var items: [Item] = []+ private var paddedItems: [Item?] = []+ private var columnCount = 1+ private var rowCount = 1+ private var lastLayoutSize: CGSize = .zero++ private let headerIconView = ASIconView(.symbolImage(R.image.info_iconSymbols(), colors: [R.Color.LabelPrimary]))+ private let headerTitleView = ASLabelView(text: .extraLargeText(R.string.localizable.focusShortcutsTips()))+ private lazy var collectionView: UICollectionView = {+ let view = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())+ view.backgroundColor = .clear+ view.showsVerticalScrollIndicator = false+ view.showsHorizontalScrollIndicator = false+ view.isScrollEnabled = false+ view.isUserInteractionEnabled = false+ view.isFocusable = false+ view.allowsSelection = false+ view.contentInsetAdjustmentBehavior = .never+ view.clipsToBounds = true+ view.dataSource = self+ view.register(Cell.self, forCellWithReuseIdentifier: Cell.reuseId)+ return view+ }()++ static func isTriggerKey(_ key: FocusKey) -> Bool {+ key == .command || key == .control || key == .select+ }++ /// Present while `key` is held. Stacks if several trigger keys are down; hides when the last one is released.+ static func show(source: Source, holding key: FocusKey) {+ guard FocusSystem.shared.isEnabled, FocusSystem.shared.currentContext != nil else { return }+ holdingKeys.insert(key)+ shared.present(source: source)+ }++ static func handleKeyUp(_ key: FocusKey) {+ guard holdingKeys.remove(key) != nil else { return }+ if holdingKeys.isEmpty {+ shared.dismiss()+ }+ }++ static func hide() {+ holdingKeys.removeAll()+ shared.dismiss()+ }++ override init(frame: CGRect) {+ super.init(frame: frame)+ isFocusable = false+ isUserInteractionEnabled = false+ accessibilityElementsHidden = true+ isHidden = true+ alpha = 0+ backgroundColor = .clear+ makeBlur(blurColor: R.Color.BackgroundPrimary)++ let header = UIView()+ header.addSubviews([headerIconView, headerTitleView])+ headerIconView.snp.makeConstraints { make in+ make.leading.centerY.equalToSuperview()+ make.size.equalTo(R.Size.IconSizeMedium)+ }+ headerTitleView.snp.makeConstraints { make in+ make.leading.equalTo(headerIconView.snp.trailing).offset(R.Size.ContentSpaceExtraSmall)+ make.top.bottom.trailing.equalToSuperview()+ }++ addSubviews([header, collectionView])+ header.snp.makeConstraints { make in+ make.top.equalTo(safeAreaLayoutGuide).offset(R.Size.ContentSpaceSmall)+ make.leading.equalTo(safeAreaLayoutGuide).offset(R.Size.ContentSpaceHuge)+ make.trailing.lessThanOrEqualTo(safeAreaLayoutGuide).inset(R.Size.ContentSpaceHuge)+ }+ collectionView.snp.makeConstraints { make in+ make.top.equalTo(header.snp.bottom).offset(R.Size.ContentSpaceLarge)+ make.leading.trailing.equalTo(safeAreaLayoutGuide).inset(R.Size.ContentSpaceHuge)+ make.bottom.equalTo(safeAreaLayoutGuide).inset(R.Size.ContentSpaceLarge)+ }+ }++ required init?(coder: NSCoder) {+ fatalError("init(coder:) has not been implemented")+ }++ override func layoutSubviews() {+ super.layoutSubviews()+ updateGridIfNeeded()+ }++ func viewDidTransition() {+ updateGridIfNeeded(force: true)+ }++ private func present(source: Source) {+ guard let window = UIWindow.topWindow else { return }+ self.source = source+ reloadItems()+ if superview !== window {+ removeFromSuperview()+ window.addSubview(self)+ snp.remakeConstraints { make in+ make.edges.equalToSuperview()+ }+ }+ window.bringSubviewToFront(self)+ isHidden = false+ layoutIfNeeded()+ updateGridIfNeeded(force: true)+ if alpha < 1 {+ UIView.normalAnimate {+ self.alpha = 1+ }+ }+ }++ private func dismiss() {+ guard superview != nil, !isHidden else { return }+ UIView.normalAnimate {+ self.alpha = 0+ } completion: { _ in+ guard Self.holdingKeys.isEmpty else { return }+ self.isHidden = true+ self.removeFromSuperview()+ }+ }++ private func reloadItems() {+ let triggerKeys: Set<FocusKey> = [.command, .control, .select]+ items = FocusSystem.shared.currentHints.compactMap { hint in+ if hint.keys.contains(where: { triggerKeys.contains($0) }) { return nil }+ let keys = hint.keys.filter { key in+ switch source {+ case .keyboard:+ return !key.isExclusiveControllerKey+ case .controller:+ return key.isControllerKey+ }+ }+ guard !keys.isEmpty else { return nil }+ return Item(title: hint.title, badges: Self.compactBadges(keys.map { $0.badge(for: source) }))+ }+ }++ private func updateGridIfNeeded(force: Bool = false) {+ let available = collectionView.bounds.size+ guard available.width > 1, available.height > 1 else { return }+ collectionView.isHidden = items.isEmpty+ guard !items.isEmpty else {+ if force || !paddedItems.isEmpty {+ paddedItems = []+ lastLayoutSize = available+ collectionView.reloadData()+ }+ return+ }+ let grid = Self.grid(itemCount: items.count, in: available)+ let padded = Self.pad(items, columns: grid.columns, rows: grid.rows)+ let sizeChanged = lastLayoutSize != available+ let gridChanged = grid.columns != columnCount || grid.rows != rowCount+ guard force || sizeChanged || gridChanged else { return }++ columnCount = grid.columns+ rowCount = grid.rows+ lastLayoutSize = available+ paddedItems = padded+ collectionView.setCollectionViewLayout(+ makeLayout(columns: grid.columns, rows: grid.rows, availableWidth: available.width),+ animated: false+ )+ collectionView.reloadData()+ }++ private static func compactBadges(_ badges: [FocusKey.Badge]) -> [FocusKey.Badge] {+ var texts: [String] = []+ var result: [FocusKey.Badge] = []+ for badge in badges {+ switch badge {+ case .text(let string):+ texts.append(string)+ case .icon:+ if !texts.isEmpty {+ result.append(.text(texts.joined(separator: " ")))+ texts.removeAll()+ }+ result.append(badge)+ }+ }+ if !texts.isEmpty {+ result.append(.text(texts.joined(separator: " ")))+ }+ return result+ }++ private static func grid(itemCount: Int, in available: CGSize) -> (columns: Int, rows: Int) {+ let maxRows = max(1, Int(floor((available.height + rowSpacing) / (cellHeight + rowSpacing))))+ let columns = max(1, Int(ceil(Double(itemCount) / Double(maxRows))))+ let rows = min(maxRows, max(1, Int(ceil(Double(itemCount) / Double(columns)))))+ return (columns, rows)+ }++ private static func pad(_ items: [Item], columns: Int, rows: Int) -> [Item?] {+ let total = columns * rows+ return (0..<total).map { $0 < items.count ? items[$0] : nil }+ }++ private func makeLayout(columns: Int, rows: Int, availableWidth: CGFloat) -> UICollectionViewLayout {+ let spacing = Self.columnSpacing+ let columnWidth = min(+ Self.maxColumnWidth,+ (availableWidth - CGFloat(max(0, columns - 1)) * spacing) / CGFloat(columns)+ )+ let columnHeight = CGFloat(rows) * Self.cellHeight + CGFloat(max(0, rows - 1)) * Self.rowSpacing+ return UICollectionViewCompositionalLayout { _, _ in+ let item = NSCollectionLayoutItem(+ layoutSize: NSCollectionLayoutSize(+ widthDimension: .fractionalWidth(1),+ heightDimension: .absolute(Self.cellHeight)+ )+ )+ let columnGroup: NSCollectionLayoutGroup+ let columnSize = NSCollectionLayoutSize(+ widthDimension: .absolute(columnWidth),+ heightDimension: .absolute(columnHeight)+ )+ if #available(iOS 16.0, tvOS 16.0, *) {+ columnGroup = NSCollectionLayoutGroup.vertical(layoutSize: columnSize, repeatingSubitem: item, count: rows)+ } else {+ columnGroup = NSCollectionLayoutGroup.vertical(layoutSize: columnSize, subitem: item, count: rows)+ }+ columnGroup.interItemSpacing = .fixed(Self.rowSpacing)++ let groupSize = NSCollectionLayoutSize(+ widthDimension: .absolute(columnWidth * CGFloat(columns) + spacing * CGFloat(max(0, columns - 1))),+ heightDimension: .absolute(columnHeight)+ )+ let group: NSCollectionLayoutGroup+ if #available(iOS 16.0, tvOS 16.0, *) {+ group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, repeatingSubitem: columnGroup, count: columns)+ } else {+ group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: columnGroup, count: columns)+ }+ group.interItemSpacing = .fixed(spacing)+ let section = NSCollectionLayoutSection(group: group)+ // One column is narrower than the view; center it instead of pinning leading.+ if columns == 1 {+ let inset = max(0, (availableWidth - columnWidth) / 2)+ section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: inset, bottom: 0, trailing: inset)+ }+ return section+ }+ }+}++// MARK: - Data source++extension FocusShortcutsTipsView: UICollectionViewDataSource {+ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {+ paddedItems.count+ }++ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {+ let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Cell.reuseId, for: indexPath) as! Cell+ cell.configure(paddedItems[indexPath.item])+ return cell+ }+}++// MARK: - Cell++private extension FocusShortcutsTipsView {+ struct Item {+ let title: String+ let badges: [FocusKey.Badge]+ }++ final class Cell: UICollectionViewCell {+ static let reuseId = "FocusShortcutsTipsCell"++ private let chromeView = UIView()+ private let titleLabel = ASLabelView()+ private let badgeStack = UIStackView()+ private var appliedChrome = false++ override init(frame: CGRect) {+ super.init(frame: frame)+ isFocusable = false+ isUserInteractionEnabled = false+ backgroundColor = .clear+ contentView.backgroundColor = .clear++ chromeView.layerCornerRadius = FocusShortcutsTipsView.cellHeight / 2+ chromeView.layer.borderWidth = 1+ chromeView.layer.borderColor = R.Color.Border.cgColor+ chromeView.clipsToBounds = true++ badgeStack.axis = .horizontal+ badgeStack.spacing = R.Size.ContentSpaceTiny+ badgeStack.alignment = .center++ contentView.addSubview(chromeView)+ chromeView.addSubviews([titleLabel, badgeStack])+ chromeView.snp.makeConstraints { make in+ make.edges.equalToSuperview()+ }+ titleLabel.snp.makeConstraints { make in+ make.leading.equalToSuperview().offset(R.Size.ContentSpaceSmall)+ make.centerY.equalToSuperview()+ }+ badgeStack.snp.makeConstraints { make in+ make.leading.greaterThanOrEqualTo(titleLabel.snp.trailing).offset(R.Size.ContentSpaceTiny)+ make.trailing.equalToSuperview().inset(R.Size.ContentSpaceExtraSmall)+ make.centerY.equalToSuperview()+ make.height.equalTo(FocusShortcutsTipsView.badgeHeight)+ }+ titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)+ badgeStack.setContentCompressionResistancePriority(.required, for: .horizontal)+ }++ required init?(coder: NSCoder) {+ fatalError("init(coder:) has not been implemented")+ }++ override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {+ super.traitCollectionDidChange(previousTraitCollection)+ if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {+ chromeView.layer.borderColor = R.Color.Border.cgColor+ }+ }++ func configure(_ item: Item?) {+ applyChromeIfNeeded()+ guard let item else {+ chromeView.isHidden = true+ return+ }+ chromeView.isHidden = false+ titleLabel.text = ASText(attributes: .footnote(+ text: item.title,+ color: R.Color.LabelPrimary+ ))+ rebuildBadges(item.badges)+ }++ private func applyChromeIfNeeded() {+ guard !appliedChrome else { return }+ appliedChrome = true+ if #available(iOS 26.0, tvOS 26.0, *) {+ chromeView.makeGlass()+ } else {+ chromeView.backgroundColor = R.Color.BackgroundSecondary.withAlphaComponent(0.7)+ }+ }++ private func rebuildBadges(_ badges: [FocusKey.Badge]) {+ badgeStack.arrangedSubviews.forEach { $0.removeFromSuperview() }+ for badge in badges {+ badgeStack.addArrangedSubview(Self.makeBadgeView(badge))+ }+ }++ private static func makeBadgeView(_ badge: FocusKey.Badge) -> UIView {+ let view = UIView()+ view.backgroundColor = R.Color.BackgroundTertiary+ view.clipsToBounds = true++ switch badge {+ case .text(let string):+ let label = ASLabelView(text: ASText(attributes: ASText.Attributes(+ text: string,+ color: R.Color.LabelPrimary,+ font: R.Font.Caption(emphasis: true),+ alignment: .center+ )))+ view.addSubview(label)+ label.snp.makeConstraints { make in+ make.centerY.equalToSuperview()+ make.leading.trailing.equalToSuperview().inset(R.Size.ContentSpaceExtraSmall)+ }+ case .icon(let icon):+ let iconView = ASIconView(icon)+ view.addSubview(iconView)+ iconView.snp.makeConstraints { make in+ make.center.equalToSuperview()+ make.size.equalTo(CGSize(width: 14, height: 14))+ }+ }++ view.snp.makeConstraints { make in+ make.height.equalTo(FocusShortcutsTipsView.badgeHeight)+ make.width.greaterThanOrEqualTo(FocusShortcutsTipsView.badgeHeight)+ }+ view.layerCornerRadius = FocusShortcutsTipsView.badgeHeight / 2+ return view+ }+ }+}++// MARK: - Key classification / badge text++private extension FocusKey {+ enum Badge {+ case text(String)+ case icon(ASIcon)+ }++ static let exclusiveControllerNames: Set<String> = [+ "leftShoulder", "rightShoulder", "leftTrigger", "rightTrigger",+ "leftThumbstickButton", "rightThumbstickButton",+ "leftThumbstickUp", "leftThumbstickDown", "leftThumbstickLeft", "leftThumbstickRight",+ "rightThumbstickUp", "rightThumbstickDown", "rightThumbstickLeft", "rightThumbstickRight",+ "menu", "select", "start", "plus", "minus", "home", "options",+ "l1", "l2", "l3", "r1", "r2", "r3"+ ]++ static let sharedControllerNames: Set<String> = [+ "a", "b", "x", "y", "up", "down", "left", "right"+ ]++ /// Shoulders, sticks, menu/select/start — never shown in the keyboard cheatsheet.+ var isExclusiveControllerKey: Bool {+ if rawValue.contains("+") { return false }+ return Self.exclusiveControllerNames.contains(rawValue)+ }++ var isControllerKey: Bool {+ if rawValue.contains("+") { return false }+ return isExclusiveControllerKey || Self.sharedControllerNames.contains(rawValue)+ }++ func badge(for source: FocusShortcutsTipsView.Source) -> Badge {+ if source == .controller, rawValue == "menu" || rawValue == "home" {+ return .icon(.symbolImage(R.image.home_iconSymbols(), colors: [R.Color.LabelPrimary]))+ }+ return .text(displayLabel(for: source))+ }++ func displayLabel(for source: FocusShortcutsTipsView.Source) -> String {+ switch source {+ case .keyboard:+ switch self {+ case .a: return "return"+ case .b: return "escape"+ default: return rawValue+ }+ case .controller:+ return controllerShortName+ }+ }++ /// Same abbreviations as controller mapping bubbles (L1/L2/L3…).+ var controllerShortName: String {+ switch rawValue {+ case "leftShoulder", "l1": return "L1"+ case "leftTrigger", "l2": return "L2"+ case "leftThumbstickButton", "l3": return "L3"+ case "leftThumbstickDown": return "L↓"+ case "leftThumbstickLeft": return "L←"+ case "leftThumbstickRight": return "L→"+ case "leftThumbstickUp": return "L↑"+ case "rightShoulder", "r1": return "R1"+ case "rightTrigger", "r2": return "R2"+ case "rightThumbstickButton", "r3": return "R3"+ case "rightThumbstickDown": return "R↓"+ case "rightThumbstickLeft": return "R←"+ case "rightThumbstickRight": return "R→"+ case "rightThumbstickUp": return "R↑"+ case "up": return "↑"+ case "down": return "↓"+ case "left": return "←"+ case "right": return "→"+ case "plus": return "+"+ case "minus": return "-"+ case "a", "b", "x", "y":+ return rawValue.uppercased()+ default:+ if let first = rawValue.first {+ return first.uppercased() + rawValue.dropFirst()+ }+ return rawValue+ }+ }+}diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusSystem.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusSystem.swiftindex 9e1f31b6..331cf211 100644--- a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusSystem.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusSystem.swift@@ -84,12 +84,90 @@ final class FocusSystem {/// 焦点当前所在的容器private weak var focusedContainer: (UIView & FocusContainer)?- /// 是否已接入手柄或外接键盘。未接入时不展示焦点高亮,方向键首次按下才会落焦。+ /// Last successful D-pad hop. Opposite direction from the landing view+ /// returns here so A→B then reverse lands on A, not a different neighbor.+ private struct FocusHop {+ weak var from: UIView?+ let direction: FocusDirection+ }+ private var lastHop: FocusHop?++ /// True when a hardware keyboard/gamepad is connected. No highlight until the first direction key.var hasExternalInput: Bool {ExternalGameControllerManager.shared.connectedControllers.count > 0}++ /// True while a text field/view is first responder. Keyboard then types; FocusKit stays idle.+ var isEditingText: Bool {+ Self.textInputIsFirstResponder+ }++ private static var textInputIsFirstResponder: Bool {+ guard let responder = UIResponder.firstResponder else { return false }+ if responder is UITextField || responder is UITextView {+ return true+ }+ var view = responder as? UIView+ while let current = view {+ if current is UITextField || current is UITextView || current is UISearchBar {+ return true+ }+ view = current.superview+ }+ return false+ }- private init() {}+ private var textEditingObservers: [Any] = []++ private init() {+ let center = NotificationCenter.default+ let beginEditing: (Notification) -> Void = { [weak self] _ in+ self?.handleTextEditingDidBegin()+ }+ textEditingObservers = [+ center.addObserver(forName: UITextField.textDidBeginEditingNotification, object: nil, queue: .main, using: beginEditing),+ center.addObserver(forName: UITextView.textDidBeginEditingNotification, object: nil, queue: .main, using: beginEditing)+ ]+ registerShortcutTipsCommands()+ }++ /// Long-press Command / Control / Select to show the cheatsheet. Only runs while FocusKit is enabled.+ private func registerShortcutTipsCommands() {+ let title = R.string.localizable.focusShortcutsTips()+ let mappings: [(FocusKey, FocusShortcutsTipsView.Source)] = [+ (.command, .keyboard),+ (.control, .keyboard),+ (.select, .controller)+ ]+ for (key, source) in mappings {+ addGlobalCommand(FocusCommand(key: key, pressType: .longPress, title: title) { [weak self] in+ guard let self else { return false }+ guard self.isEnabled, self.currentContext != nil else { return false }+ let extraKeys = self.heldKeys.keys.filter { $0 != key }+ if extraKeys.contains(where: { !FocusShortcutsTipsView.isTriggerKey($0) }) {+ return false+ }+ FocusShortcutsTipsView.show(source: source, holding: key)+ return true+ })+ }+ }++ private func handleTextEditingDidBegin() {+ FocusKeyObserver.shared.handleTextEditingDidBegin()+ cancelAllPresses()+ userDidTouchScreen()+ }++ /// Resign the current text input. Restores the FocusKit highlight on the field.+ private func endTextEditing() {+ guard isEditingText else { return }+ UIResponder.firstResponder?.resignFirstResponder()+ currentContext?.rootView?.window?.endEditing(true)+ guard let context = currentContext else { return }+ guard focusedView == nil && focusedContainer == nil else { return }+ establishInitialFocus(in: context)+ }// MARK: - Context 栈@@ -98,6 +176,7 @@ final class FocusSystem {guard !contexts.contains(where: { $0 === context }) else { return }rememberAndClearCurrentFocus()contexts.append(context)+ lastHop = nilactivateTopContext()}@@ -109,6 +188,7 @@ final class FocusSystem {if popped.contains(where: { containsCurrentFocus(in: $0) }) {clearCurrentFocus()}+ lastHop = nilactivateTopContext()}@@ -124,6 +204,7 @@ final class FocusSystem {if let top = contexts.last, top !== context {rememberAndClearCurrentFocus()contexts.removeLast()+ lastHop = nil}if !contexts.contains(where: { $0 === context }) {contexts.append(context)@@ -133,6 +214,8 @@ final class FocusSystem {/// 替换栈底 context(Home Tab 等同级页面)。/// 三个 Tab 各持有自己的 FocusContext,不互相压栈;Sheet 等覆盖层仍叠在当前 Tab 之上。+ /// If the current focus already belongs to the incoming context (shared+ /// chrome such as a tab bar), keep it instead of re-establishing.func replaceRoot(with context: FocusContext) {if contexts.isEmpty {contexts.append(context)@@ -146,11 +229,12 @@ final class FocusSystem {return}let replacingActive = contexts.count == 1- if replacingActive {+ let keepFocus = replacingActive && currentFocusedView.map { isView($0, inside: context) } == true+ if replacingActive && !keepFocus {rememberAndClearCurrentFocus()}contexts[0] = context- if replacingActive {+ if replacingActive && !keepFocus {activateTopContext()}}@@ -159,6 +243,7 @@ final class FocusSystem {func reset() {clearCurrentFocus()contexts.removeAll()+ lastHop = nil}// MARK: - 全局命令@@ -180,7 +265,14 @@ final class FocusSystem {/// 否则等到 `keyUp(_:)` 时按短按分发。func keyDown(_ key: FocusKey) {guard isEnabled else { return }- // 输入源应保证 down/up 配对,重复按下兜底忽略+ // Typing: leave arrows/confirm with the field. B/Esc only ends editing.+ if isEditingText {+ if key == .b {+ endTextEditing()+ }+ return+ }+ // Sources should pair down/up; ignore a repeated down.guard heldKeys[key] == nil else { return }let state = HeldKeyState()@@ -205,15 +297,16 @@ final class FocusSystem {}}- /// 按键抬起。与 `keyDown(_:)` 配对调用。+ /// Key released; pairs with `keyDown(_:)`.func keyUp(_ key: FocusKey) {guard let state = heldKeys.removeValue(forKey: key) else { return }state.invalidate()+ FocusShortcutsTipsView.handleKeyUp(key)guard isEnabled else { return }- // 方向键在按下/连发阶段已经响应过,抬起只做清理+ // Direction keys already navigated on down / repeat; up is cleanup only.if key.direction != nil { return }- // 长按已被消费,短按不再触发+ // Long-press already consumed this press; skip the tap.if state.longPressHandled { return }send(key)@@ -274,6 +367,7 @@ final class FocusSystem {state.invalidate()}heldKeys.removeAll()+ FocusShortcutsTipsView.hide()}// MARK: - 手动焦点控制@@ -288,6 +382,7 @@ final class FocusSystem {} else {setFocus(view, container: nil, context: context)}+ lastHop = nil}/// 焦点失效(如页面内容刷新)后重建焦点@@ -391,31 +486,37 @@ final class FocusSystem {private func moveFocus(_ direction: FocusDirection, in context: FocusContext) {guard let root = context.rootView else { return }- // 尚无焦点:建立初始焦点(仍属方向键触发,需带上方向)+ // No focus yet: establish one, still tagged with the D-pad heading.if focusedView == nil && focusedContainer == nil {establishInitialFocus(in: context, direction: direction)return}- // 焦点在容器内:先让容器消化+ let originView = focusedView ?? (focusedContainer as UIView?)++ // Isolating containers own D-pad, including reverse within the container.+ // Page-level reverse hop must not skip remaining inner targets in a cell.var exitingContainer: (UIView & FocusContainer)?- if let container = focusedContainer {+ if let container = focusedContainer, container.isolatesFocusNavigation {switch container.navigateFocus(direction, current: focusedView) {case .handled(let view):updateFocusInsideContainer(container, view: view, direction: direction, context: context)+ rememberHop(from: originView, direction: direction)returncase .exit:exitingContainer = container}}- // 页面级空间寻径。出发点优先用实际聚焦的 cell/子视图:- // 全屏容器与页面上其他可聚焦视图(悬浮工具条等)重叠时,- // 以容器整体 frame 出发会把所有 sibling 都过滤掉,导致无法离开容器+ if tryReverseHop(direction, from: originView, in: context, exitingContainer: exitingContainer) {+ return+ }++ // Page-level search. Prefer the real focused cell/subview as origin so a+ // full-screen list can still yield to overlapping overlays (toolbars).let origin: UIView? = focusedView ?? (focusedContainer as UIView?)guard let origin else { return }- // 容器无内部焦点(翻页滚动的退化态)时以容器可视中心为出发点,- // 同样是为了避免容器整体 frame 过滤掉重叠的 sibling+ // Degenerate container (paging with no inner focus): aim from the visible center.var originFrame: CGRect?if focusedView == nil, let container = focusedContainer {let frame = FocusEngine.frameInWindow(of: container)@@ -426,16 +527,52 @@ final class FocusSystem {direction: direction,in: root,originFrame: originFrame,- excludingContainerSubtree: exitingContainer+ excludingContainerSubtree: exitingContainer,+ additionalRoots: context.additionalSearchRoots(entering: direction)) else {notifyNavigationBlocked(direction, in: context)return}applyNavigationTarget(target, direction: direction, context: context)+ rememberHop(from: originView, direction: direction)+ }++ /// Opposite of the last hop returns to that view when it is still valid.+ /// If an isolating container just exited, only reverse to a view outside it —+ /// going back to a different inner of that container is the container's job.+ private func tryReverseHop(+ _ direction: FocusDirection,+ from current: UIView?,+ in context: FocusContext,+ exitingContainer: (UIView & FocusContainer)? = nil+ ) -> Bool {+ guard direction == lastHop?.direction.opposite,+ let previous = lastHop?.from,+ previous.window != nil,+ previous !== current,+ isView(previous, inside: context)+ else {+ return false+ }+ if let exiting = exitingContainer,+ previous === exiting || previous.isDescendant(of: exiting) {+ return false+ }+ let stillFocusable = previous.fk_canFocus || FocusEngine.focusContainer(for: previous) != nil+ guard stillFocusable else { return false }++ applyNavigationTarget(previous, direction: direction, context: context)+ if currentFocusedView === current { return false }+ rememberHop(from: current, direction: direction)+ return true+ }++ private func rememberHop(from origin: UIView?, direction: FocusDirection) {+ lastHop = FocusHop(from: origin, direction: direction)}- /// 页面级寻径命中后落焦:内部后代折叠为 enterContainer,普通视图直接 setFocus+ /// After a page-level hit: enter the container if the target lives inside one.private func applyNavigationTarget(_ target: UIView, direction: FocusDirection?, context: FocusContext) {if let container = FocusEngine.focusContainer(for: target), target !== container {enterContainer(container, from: direction, preferred: target, context: context, notifyDirection: direction)@@ -470,14 +607,14 @@ final class FocusSystem {releaseCurrentFocus(exceptContainer: container)focusedContainer = containerfocusedView = (inner === container) ? nil : inner- context.lastFocusedView = inner === container ? container : inner+ rememberContentFocus(focusedView ?? container, in: context)notifyFocusChange(direction: notifyDirection ?? direction)}private func updateFocusInsideContainer(_ container: UIView & FocusContainer, view: UIView, direction: FocusDirection, context: FocusContext) {focusedContainer = containerfocusedView = (view === container) ? nil : view- context.lastFocusedView = view === container ? container : view+ rememberContentFocus(focusedView ?? container, in: context)notifyFocusChange(direction: direction)}@@ -486,12 +623,18 @@ final class FocusSystem {releaseCurrentFocus(exceptContainer: container)focusedView = viewfocusedContainer = container- context.lastFocusedView = view+ rememberContentFocus(view, in: context)view.fk_applyFocus(true)FocusEngine.ensureVisible(view)notifyFocusChange(direction: direction)}+ /// Chrome in additional search roots keeps its own memory; page restore should return to content.+ private func rememberContentFocus(_ view: UIView, in context: FocusContext) {+ guard let root = context.rootView, view === root || view.isDescendant(of: root) else { return }+ context.lastFocusedView = view+ }+private func notifyFocusChange(direction: FocusDirection? = nil) {currentContext?.onFocusChange?(currentFocusedView, direction)}@@ -516,6 +659,7 @@ final class FocusSystem {private func clearCurrentFocus() {let hadFocus = focusedView != nil || focusedContainer != nilreleaseCurrentFocus()+ lastHop = nilif hadFocus {notifyFocusChange()}@@ -598,8 +742,7 @@ final class FocusSystem {}private func isView(_ view: UIView, inside context: FocusContext) -> Bool {- guard let root = context.rootView else { return false }- return view === root || view.isDescendant(of: root)+ context.contains(view)}private func containsCurrentFocus(in context: FocusContext) -> Bool {diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusTypes.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusTypes.swiftindex af406288..66ed161f 100644--- a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusTypes.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/FocusTypes.swift@@ -28,15 +28,21 @@ struct FocusKey: Hashable, RawRepresentable, ExpressibleByStringLiteral, CustomSinit(_ rawValue: String) { self.rawValue = rawValue }init(stringLiteral value: String) { self.rawValue = value }- /// 方向:移动焦点+ /// Direction: move focusstatic let up = FocusKey("up")static let down = FocusKey("down")static let left = FocusKey("left")static let right = FocusKey("right")- /// 确定:默认执行焦点视图的点击模拟+ /// Confirm: default is a click on the focused viewstatic let a = FocusKey("a")- /// 取消:默认关闭当前页面(dismiss / ProHUD pop / navigation pop)+ /// Cancel: default dismisses the current page (sheet / ProHUD / navigation pop)static let b = FocusKey("b")+ /// Keyboard modifier; long-press shows the shortcut cheatsheet+ static let command = FocusKey("command")+ /// Keyboard modifier; long-press shows the shortcut cheatsheet+ static let control = FocusKey("control")+ /// Controller Select / View / − ; long-press shows the shortcut cheatsheet+ static let select = FocusKey("select")/// 若是方向键则返回对应方向var direction: FocusDirection? {diff --git a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/Focusable.swift b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/Focusable.swiftindex cae7cacb..6ab4fd6a 100644--- a/ManicEmu/ManicEmu/Sources/Tools/FocusKit/Focusable.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/FocusKit/Focusable.swift@@ -89,8 +89,13 @@ extension UIView {/// 视图自身(不含祖先链)是否具备聚焦条件;祖先可见性由引擎遍历时保证var fk_defaultCanFocus: Bool {guard isFocusable else { return false }- guard window != nil, !isHidden, alpha > 0.01 else { return false }- guard bounds.width > 0, bounds.height > 0 else { return false }+ guard window != nil else { return false }+ var node: UIView? = self+ while let current = node {+ if current.isHidden || current.alpha <= 0.01 { return false }+ node = current.superview+ }+ guard bounds.width > 0.5, bounds.height > 0.5 else { return false }if let control = self as? UIControl, !control.isEnabled, onFocusConfirm == nil { return false }return true}@@ -147,18 +152,20 @@ extension UIView {}overrideUserInterfaceStyle = UIDevice.isDarkMode ? .light : .darkbackgroundColor = R.Color.BackgroundPrimary.forceStyle(UIDevice.isDarkMode ? .light : .dark)- let w = bounds.width- let h = bounds.height- guard w > 0.5, h > 0.5 else { return }- let shortest = min(w, h)- let longest = max(w, h)- let aspectRatio = longest / shortest- if aspectRatio > 2.0 {- layerCornerRadius = shortest / 2.0- } else if shortest / longest > 0.9 {- layerCornerRadius = h / 2.0- } else {- layerCornerRadius = R.Size.AppleIconCornerRadius(height: h)+ if layerCornerRadius == 0 {+ let w = bounds.width+ let h = bounds.height+ guard w > 0.5, h > 0.5 else { return }+ let shortest = min(w, h)+ let longest = max(w, h)+ let aspectRatio = longest / shortest+ if aspectRatio > 1.1 {+ layerCornerRadius = shortest / 2.0+ } else if shortest / longest > 0.9 {+ layerCornerRadius = h / 2.0+ } else {+ layerCornerRadius = R.Size.AppleIconCornerRadius(height: h)+ }}}@@ -219,7 +226,7 @@ extension UIView {extension UISlider {/// Make the slider focusable and consume left/right to nudge value.- func enableFocusAdjustment(step: Float = 0.05) {+ func enableFocusAdjustment(step: Float = 0.01) {isFocusable = truefocusCommands = [FocusCommand(key: .left, title: R.string.localizable.focusHintAdjust(), action: { [weak self] in