fix: allow virtual button swaps without a controller in 1.0.2

This commit is contained in:
2026-10-29 12:29:08 +08:00
parent 318331a21e
commit 776ff4f4aa
8 changed files with 185 additions and 41 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
# NESLite
NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.1,内置固定提交的
NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.2,内置固定提交的
FCEUmm 和 Nestopia,可设置默认内核,也可长按游戏单独选择,下次打开游戏时生效。两个内核的存档
独立保留。0.9.17 对已确认哈希的“龙珠英雄”自动使用 Dendy 制式,两个内核的桌面启动与菜单检查
通过,详见 [兼容修复记录](docs/reports/long-zhu-ying-xiong-0.9.17.md)。
@@ -8,7 +8,7 @@ FCEUmm 和 Nestopia,可设置默认内核,也可长按游戏单独选择,
见 [显示修复记录](docs/reports/integer-scaling-0.9.18.md)。
源码仓库:[shen/NESLite](http://git.m3frame.com/shen/NESLite)。安装包、源码与校验值见
[发行版](http://git.m3frame.com/shen/NESLite/releases),本次更新说明见 [1.0.1](docs/releases/1.0.1.md),首次发布说明见 [1.0.0](docs/releases/1.0.0.md)。
[发行版](http://git.m3frame.com/shen/NESLite/releases),本次更新说明见 [1.0.2](docs/releases/1.0.2.md),首次发布说明见 [1.0.0](docs/releases/1.0.0.md)。
用户已确认产品可发布;历史测试报告中未归档的专项证据仍保留原状态,不据此宣称所有计划测试均已执行。
主界面固定为横屏游戏布局:中央是 4:3 游戏容器,可切换原始像素整数缩放,左右为虚拟按键,左上角提供游戏列表、导入和
+2 -2
View File
@@ -21,8 +21,8 @@ android {
applicationId = "org.neslite.app"
minSdk = 28
targetSdk = 36
versionCode = 1000001
versionName = "1.0.1"
versionCode = 1000002
versionName = "1.0.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
ndk {
@@ -0,0 +1,87 @@
package org.neslite.app
import android.os.SystemClock
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.junit.Assume.assumeTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.neslite.app.diagnostics.DeviceDiagnostics
import org.neslite.app.settings.AppSettingsStore
@RunWith(AndroidJUnit4::class)
class ButtonSwapSettingsTest {
@Test
fun noControllerCanSwapPersistReopenAndResetScreenButtons() {
assumeTrue("Disconnect external controllers for this test", DeviceDiagnostics.controllerDeviceIds().isEmpty())
val store = AppSettingsStore(InstrumentationRegistry.getInstrumentation().targetContext)
val previous = runBlocking { store.load() }
runBlocking { store.save(previous.copy(guideCompleted = true, virtualSwapAB = false, virtualSwapXY = false)) }
try {
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
openSwaps()
awaitButton("交换 X/Y 按键:关")
awaitButton("交换 A/B 按键:关")
onView(withText("交换 X/Y 按键:关")).perform(click())
onView(withText("交换 A/B 按键:关")).perform(click())
awaitSaved(store, swapAB = true, swapXY = true)
onView(withText("交换 A/B 按键:开")).perform(click())
awaitSaved(store, swapAB = false, swapXY = true)
scenario.recreate()
openSwaps()
awaitButton("交换 X/Y 按键:开")
awaitButton("交换 A/B 按键:关")
onView(withText("恢复屏幕按键默认顺序")).perform(scrollTo(), click())
awaitSaved(store, swapAB = false, swapXY = false)
awaitButton("交换 X/Y 按键:关")
awaitButton("交换 A/B 按键:关")
}
} finally {
runBlocking { store.save(previous) }
}
}
private fun openSwaps() {
onView(withContentDescription("设置")).perform(click())
onView(withText("交换 X/Y、A/B 按键与手动映射")).perform(scrollTo(), click())
}
private fun awaitButton(label: String) {
val deadline = SystemClock.uptimeMillis() + 5000L
while (true) {
try {
onView(withText(label)).check(matches(isDisplayed())).check(matches(isEnabled()))
return
} catch (failure: NoMatchingViewException) {
if (SystemClock.uptimeMillis() >= deadline) throw failure
} catch (failure: AssertionError) {
if (SystemClock.uptimeMillis() >= deadline) throw failure
}
SystemClock.sleep(50L)
}
}
private fun awaitSaved(store: AppSettingsStore, swapAB: Boolean, swapXY: Boolean) = runBlocking {
withTimeout(5000L) {
while (true) {
val settings = store.load()
if (settings.virtualSwapAB == swapAB && settings.virtualSwapXY == swapXY) break
delay(50L)
}
}
}
}
@@ -1330,6 +1330,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
}
applyAppSettings()
renderSettings()
renderControllerSettings()
if (!loaded.guideCompleted) showFirstUseGuide()
}
}
@@ -1366,19 +1367,24 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
// Do not overwrite saved screen controls with a temporary default during reconnect.
if (deviceId !in readyControllerProfileIds) return
val profile = controllerProfiles[deviceId] ?: return
virtualButtonSwapsOverride = profile.swapAB to profile.swapXY
val updated = appSettings.copy(virtualSwapAB = profile.swapAB, virtualSwapXY = profile.swapXY)
updateVirtualButtonSwaps(profile.swapAB, profile.swapXY)
}
private fun updateVirtualButtonSwaps(swapAB: Boolean, swapXY: Boolean) {
virtualButtonSwapsOverride = swapAB to swapXY
val updated = appSettings.copy(virtualSwapAB = swapAB, virtualSwapXY = swapXY)
val changed = updated != appSettings
appSettings = updated
if (::virtualGamepad.isInitialized) {
virtualGamepad.configureButtonSwaps(profile.swapAB, profile.swapXY)
virtualGamepad.configureButtonSwaps(swapAB, swapXY)
}
if (changed && appSettingsLoaded) persistAppSettings()
}
private fun persistAppSettings() {
val snapshot = appSettings
controllerScope.launch { appSettingsStore.save(snapshot) }
// Start preference writes in UI order, including rapid independent swap toggles.
controllerScope.launch(Dispatchers.Main.immediate) { appSettingsStore.save(snapshot) }
}
private fun showFirstUseGuide() {
@@ -1503,7 +1509,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
manualMappingIndex = null
bindingCaptureWaitForNeutral = false
controllerSettingsMessage = "可逐项设置全部按键,也可以点击任意动作单独修改。"
showOverlayPage(OverlayPage.CONTROLLER_SETTINGS, "手柄按键设置")
showOverlayPage(OverlayPage.CONTROLLER_SETTINGS, "屏幕与手柄按键设置")
renderControllerSettings()
}
@@ -1523,15 +1529,64 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
controllerReturnToSettings = false
}
private fun renderButtonSwapSettings(profile: ControllerProfile?) {
controllerSettingsPanel.addView(section("交换 X/Y、A/B 按键"))
controllerSettingsPanel.addView(body(
if (profile == null) {
"调整屏幕虚拟按键的位置:点击后立即生效并自动保存,重启后保留。按钮文字、颜色和触控区域一起换位。"
} else {
"默认顺序:A → NES A,B → NES B,X → A 连发,Y → B 连发。\n" +
"两组可独立交换;已有自定义映射时,交换对应的普通或连发动作绑定。点击保存后,当前手柄和屏幕按键同步交换。"
},
))
val swapXY = profile?.swapXY ?: appSettings.virtualSwapXY
val swapAB = profile?.swapAB ?: appSettings.virtualSwapAB
controllerSettingsPanel.addView(Button(this).apply {
text = if (swapXY) "交换 X/Y 按键:开" else "交换 X/Y 按键:关"
isEnabled = profile == null || (pendingBindingAction == null && manualMappingIndex == null)
setOnClickListener {
if (profile == null) {
updateVirtualButtonSwaps(appSettings.virtualSwapAB, !appSettings.virtualSwapXY)
} else {
draftProfile = profile.toggleXY()
controllerSettingsMessage = "已交换 A/B 连发按键(默认 X/Y);保存后生效。"
}
renderControllerSettings()
}
})
controllerSettingsPanel.addView(Button(this).apply {
text = if (swapAB) "交换 A/B 按键:开" else "交换 A/B 按键:关"
isEnabled = profile == null || (pendingBindingAction == null && manualMappingIndex == null)
setOnClickListener {
if (profile == null) {
updateVirtualButtonSwaps(!appSettings.virtualSwapAB, appSettings.virtualSwapXY)
} else {
draftProfile = profile.toggleAB()
controllerSettingsMessage = "已交换 NES A/B;保存后生效。"
}
renderControllerSettings()
}
})
if (profile == null) {
controllerSettingsPanel.addView(Button(this).apply {
text = "恢复屏幕按键默认顺序"
setOnClickListener {
updateVirtualButtonSwaps(swapAB = false, swapXY = false)
renderControllerSettings()
}
})
}
}
private fun renderControllerSettings() {
if (!::controllerSettingsPanel.isInitialized || controllerSettingsPanel.visibility != View.VISIBLE) return
controllerSettingsPanel.removeAllViews()
controllerSettingsPanel.addView(section("手柄映射与死区"))
val deviceId = selectedControllerId
val controller = controllers.firstOrNull { it.deviceId == deviceId }
val profile = draftProfile ?: deviceId?.let(controllerProfiles::get)
val profile = if (controller == null) null else draftProfile ?: deviceId?.let(controllerProfiles::get)
renderButtonSwapSettings(profile)
if (controller == null || profile == null) {
controllerSettingsPanel.addView(body("当前没有已连接的手柄;设置入口保持可达,连接后即可编辑。"))
controllerSettingsPanel.addView(body("未连接手柄也可以交换上方的屏幕按键。手柄按键映射和摇杆设置需连接手柄后使用。"))
controllerSettingsPanel.addView(Button(this).apply {
text = "关闭"
setOnClickListener { closeControllerSettings() }
@@ -1539,6 +1594,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
focusFirstButton(controllerSettingsPanel)
return
}
controllerSettingsPanel.addView(section("手柄映射与死区"))
controllerSettingsPanel.addView(
body("${controller.name}\n档案:${profile.origin} · ${profile.fingerprint.take(12)};不使用临时 deviceId 持久化"),
)
@@ -1590,29 +1646,6 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
})
})
}
controllerSettingsPanel.addView(section("交换 X/Y、A/B 按键"))
controllerSettingsPanel.addView(body(
"默认顺序:A → NES A,B → NES B,X → A 连发,Y → B 连发。\n" +
"两组可独立交换;已有自定义映射时,交换对应的普通或连发动作绑定。点击保存后,当前手柄和屏幕按键同步交换;屏幕按键的文字与触控位置一起调整。",
))
controllerSettingsPanel.addView(Button(this).apply {
text = if (profile.swapXY) "交换 X/Y 按键:开" else "交换 X/Y 按键:关"
isEnabled = pendingBindingAction == null && manualMappingIndex == null
setOnClickListener {
draftProfile = profile.toggleXY()
controllerSettingsMessage = "已交换 A/B 连发按键(默认 X/Y);保存后生效。"
renderControllerSettings()
}
})
controllerSettingsPanel.addView(Button(this).apply {
text = if (profile.swapAB) "交换 A/B 按键:开" else "交换 A/B 按键:关"
isEnabled = pendingBindingAction == null && manualMappingIndex == null
setOnClickListener {
draftProfile = profile.toggleAB()
controllerSettingsMessage = "已交换 NES A/B;保存后生效。"
renderControllerSettings()
}
})
controllerSettingsPanel.addView(body("轴按下阈值:${formatThreshold(profile.pressThreshold)}"))
controllerSettingsPanel.addView(SeekBar(this).apply {
min = 20
@@ -1958,6 +1991,8 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
selectedControllerId = controllers.firstOrNull()?.deviceId
draftProfile = null
pendingBindingAction = null
manualMappingIndex = null
bindingCaptureWaitForNeutral = false
}
syncVirtualButtonSwaps()
renderControllerSettings()
@@ -7,7 +7,7 @@ class BuildIdentityTest {
@Test
fun debugBuildUsesTheDocumentedIdentity() {
assertEquals("org.neslite.app.debug", BuildConfig.APPLICATION_ID)
assertEquals("1.0.1-debug", BuildConfig.VERSION_NAME)
assertEquals(1000001, BuildConfig.VERSION_CODE)
assertEquals("1.0.2-debug", BuildConfig.VERSION_NAME)
assertEquals(1000002, BuildConfig.VERSION_CODE)
}
}
+3 -3
View File
@@ -1,7 +1,7 @@
# NESLite 构建与打包
项目的 APK 打包入口统一为根目录 `打包.cmd`,项目内的编译产物、缓存、日志和交付文件统一放入
`build/`。当前应用版本为 1.0.1,入口从 APK 构建元数据读取版本,不另写一套版本号。
`build/`。当前应用版本为 1.0.2,入口从 APK 构建元数据读取版本,不另写一套版本号。
## 一键打包
@@ -14,7 +14,7 @@
.\打包.cmd -NoPause
```
当前交付文件是 `build/releases/NESLite-1.0.1-debug-arm64-v8a.apk`,旁边的 `.sha256` 保存校验值。
当前交付文件是 `build/releases/NESLite-1.0.2-debug-arm64-v8a.apk`,旁边的 `.sha256` 保存校验值。
入口检查工具链与固定依赖、编译选定 APK、检查原生库和 APK 的 16 KB 对齐,成功后复制产物。
它不会自动启动单元测试、ROM 遍历、设备测试或发布回归;失败会返回非零退出码,旧交付 APK 不冒充本次成功产物。
@@ -24,7 +24,7 @@
.\打包.cmd release -NoPause
```
该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.1-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。
该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.2-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。
正式打包前必须提交源码并配置签名目录;入口读取 Windows 用户加密的密码,完成签名和签名验证。密钥位置与发布步骤见 [publishing.md](publishing.md)。
一键打包不会运行原 `package-rc.ps1` 的全量 Stage/lint/设备测试包构建,也不表示发布门槛通过。
+20
View File
@@ -0,0 +1,20 @@
# NESLite 1.0.2
修复未连接外接手柄时,无法调整屏幕虚拟按键顺序的问题。
## 本次更新
- “设置 → 交换 X/Y、A/B 按键与手动映射”始终显示两组交换选项。
- 未连接手柄时,点击立即调整屏幕按键并自动保存,重新打开应用后保留。
- 新增“恢复屏幕按键默认顺序”,无需连接手柄即可还原。
- 已连接手柄时,保留逐设备保存与手柄、屏幕同步交换的行为。
- 调整设置保存顺序,防止快速切换两组按键时旧设置覆盖新设置。
## 安装与验证
正式安装包为 `NESLite-1.0.2-arm64-v8a.apk`,版本号为 1000002,沿用原有正式签名。
可覆盖升级 1.0.0、1.0.1 正式版;调试版与正式版包名不同。
新增无手柄场景的界面回归测试,覆盖选项可用、独立交换、保存、重建页面和恢复默认。
71 项单元测试全部通过,界面测试安装包编译成功。当前环境没有连接测试设备,界面测试尚未在设备运行。
源码、符号、签名安装包和校验清单由正式打包入口统一生成到 `build/releases/`。
+3 -1
View File
@@ -13,7 +13,9 @@
长按游戏名可查看详情、收藏、从列表移除或选择内核。连接外接手柄后仍可按设置选择是否显示
屏幕按键。多点触控支持方向与动作同时按住,滑出、取消、失焦或暂停都会释放输入。
4. 点左上角“设置”图标,在画面与声音、方向与触控、手柄与辅助三个卡片中调整选项,可切换 4:3/整数缩放、最近邻/线性过滤、音量、静音、软件连发和 RB 快进。进入
“交换 X/Y、A/B 按键与手动映射”后,可分别开启“交换 X/Y 按键”和“交换 A/B 按键”,点击保存后生效。
“交换 X/Y、A/B 按键与手动映射”后,无论是否连接手柄,都能看到“交换 X/Y 按键”和“交换 A/B 按键”。
未连接手柄时,点击即可交换屏幕按键并自动保存,也可点击“恢复屏幕按键默认顺序”;无需连接手柄。
连接手柄时,两项编辑当前手柄配置,点击“保存”后手柄与屏幕按键同步生效。
默认 A/B 对应 NES A/B,X/Y 对应 A/B 连发;两组独立交换,保存后所选手柄与屏幕虚拟按键同步。
屏幕上的按钮文字、颜色、按下反馈与触控区域一起换位;断开手柄或重启应用后保留最近的交换状态。
切换所选手柄时,屏幕跟随该手柄已保存的交换设置;尚未保存的修改不会影响屏幕按键。