Compare commits
2 Commits
fefca3ca68
...
776ff4f4aa
| Author | SHA1 | Date | |
|---|---|---|---|
| 776ff4f4aa | |||
| 318331a21e |
@@ -1,6 +1,6 @@
|
||||
# NESLite
|
||||
|
||||
NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.0,内置固定提交的
|
||||
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.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 游戏容器,可切换原始像素整数缩放,左右为虚拟按键,左上角提供游戏列表、导入和
|
||||
|
||||
@@ -21,8 +21,8 @@ android {
|
||||
applicationId = "org.neslite.app"
|
||||
minSdk = 28
|
||||
targetSdk = 36
|
||||
versionCode = 1000000
|
||||
versionName = "1.0.0"
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,9 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
private val profileResolver = ControllerProfileResolver()
|
||||
private lateinit var profileStore: ControllerProfileStore
|
||||
private val controllerProfiles = mutableMapOf<Int, ControllerProfile>()
|
||||
private val readyControllerProfileIds = mutableSetOf<Int>()
|
||||
private var appSettingsLoaded = false
|
||||
private var virtualButtonSwapsOverride: Pair<Boolean, Boolean>? = null
|
||||
private val controllerIdentities = mutableMapOf<Int, ControllerIdentity>()
|
||||
private val controllerProfileRevisions = mutableMapOf<Int, Int>()
|
||||
private var selectedControllerId: Int? = null
|
||||
@@ -1213,7 +1216,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
}
|
||||
})
|
||||
settingsPanel.addView(Button(this).apply {
|
||||
text = "手动设置手柄按键、摇杆与功能键"
|
||||
text = "交换 X/Y、A/B 按键与手动映射"
|
||||
setOnClickListener {
|
||||
showControllerSettings(returnToPause = false, returnToSettings = true)
|
||||
}
|
||||
@@ -1313,7 +1316,12 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
val loaded = appSettingsStore.load()
|
||||
val loadedCores = runCatching { corePreferencesStore.load() }
|
||||
runOnUiThread {
|
||||
appSettings = loaded
|
||||
// A controller profile can finish loading before the application settings.
|
||||
appSettings = virtualButtonSwapsOverride?.let { (swapAB, swapXY) ->
|
||||
loaded.copy(virtualSwapAB = swapAB, virtualSwapXY = swapXY)
|
||||
} ?: loaded
|
||||
appSettingsLoaded = true
|
||||
if (appSettings != loaded) persistAppSettings()
|
||||
loadedCores.onSuccess {
|
||||
corePreferences = it
|
||||
corePreferencesReady = true
|
||||
@@ -1322,6 +1330,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
}
|
||||
applyAppSettings()
|
||||
renderSettings()
|
||||
renderControllerSettings()
|
||||
if (!loaded.guideCompleted) showFirstUseGuide()
|
||||
}
|
||||
}
|
||||
@@ -1330,6 +1339,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
private fun applyAppSettings() {
|
||||
muted = appSettings.muted
|
||||
if (::virtualGamepad.isInitialized) {
|
||||
virtualGamepad.configureButtonSwaps(appSettings.virtualSwapAB, appSettings.virtualSwapXY)
|
||||
virtualGamepad.configureDpad(
|
||||
mode = appSettings.directionMode,
|
||||
scale = appSettings.virtualDpadSize.scale,
|
||||
@@ -1352,9 +1362,29 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun syncVirtualButtonSwaps() {
|
||||
val deviceId = selectedControllerId ?: return
|
||||
// Do not overwrite saved screen controls with a temporary default during reconnect.
|
||||
if (deviceId !in readyControllerProfileIds) return
|
||||
val profile = controllerProfiles[deviceId] ?: return
|
||||
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(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() {
|
||||
@@ -1479,7 +1509,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
manualMappingIndex = null
|
||||
bindingCaptureWaitForNeutral = false
|
||||
controllerSettingsMessage = "可逐项设置全部按键,也可以点击任意动作单独修改。"
|
||||
showOverlayPage(OverlayPage.CONTROLLER_SETTINGS, "手柄按键设置")
|
||||
showOverlayPage(OverlayPage.CONTROLLER_SETTINGS, "屏幕与手柄按键设置")
|
||||
renderControllerSettings()
|
||||
}
|
||||
|
||||
@@ -1499,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() }
|
||||
@@ -1515,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 持久化"),
|
||||
)
|
||||
@@ -1527,6 +1607,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
setOnClickListener {
|
||||
val index = controllers.indexOfFirst { it.deviceId == selectedControllerId }
|
||||
selectedControllerId = controllers[(index + 1).mod(controllers.size)].deviceId
|
||||
syncVirtualButtonSwaps()
|
||||
draftProfile = selectedControllerId?.let(controllerProfiles::get)
|
||||
pendingBindingAction = null
|
||||
manualMappingIndex = null
|
||||
@@ -1565,14 +1646,6 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
})
|
||||
})
|
||||
}
|
||||
controllerSettingsPanel.addView(Button(this).apply {
|
||||
text = if (profile.swapAB) "A/B 交换:开" else "A/B 交换:关"
|
||||
setOnClickListener {
|
||||
draftProfile = profile.toggleAB()
|
||||
controllerSettingsMessage = "已交换 NES A/B;保存后生效。"
|
||||
renderControllerSettings()
|
||||
}
|
||||
})
|
||||
controllerSettingsPanel.addView(body("轴按下阈值:${formatThreshold(profile.pressThreshold)}"))
|
||||
controllerSettingsPanel.addView(SeekBar(this).apply {
|
||||
min = 20
|
||||
@@ -1810,9 +1883,8 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
private fun saveControllerProfile() {
|
||||
val deviceId = selectedControllerId ?: return
|
||||
val profile = draftProfile?.copy(origin = ProfileOrigin.CUSTOM) ?: return
|
||||
val previousProfile = controllerProfiles[deviceId]
|
||||
controllerProfileRevisions[deviceId] = (controllerProfileRevisions[deviceId] ?: 0) + 1
|
||||
controllerProfiles[deviceId] = profile
|
||||
val revision = (controllerProfileRevisions[deviceId] ?: 0) + 1
|
||||
controllerProfileRevisions[deviceId] = revision
|
||||
pendingBindingAction = null
|
||||
manualMappingIndex = null
|
||||
bindingCaptureWaitForNeutral = false
|
||||
@@ -1820,15 +1892,25 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
controllerScope.launch {
|
||||
val result = runCatching { profileStore.save(profile) }
|
||||
runOnUiThread {
|
||||
if (controllerProfileRevisions[deviceId] != revision ||
|
||||
controllerIdentities[deviceId]?.fingerprint() != profile.fingerprint
|
||||
) return@runOnUiThread
|
||||
if (result.isSuccess) {
|
||||
inputRouter.clearDevice(deviceId).let(::applyRoutedInput)
|
||||
axisHysteresis.clearDevice(deviceId)
|
||||
controllerProfiles[deviceId] = profile
|
||||
readyControllerProfileIds += deviceId
|
||||
if (selectedControllerId == deviceId) {
|
||||
syncVirtualButtonSwaps()
|
||||
if (draftProfile?.copy(origin = ProfileOrigin.CUSTOM) == profile) draftProfile = profile
|
||||
}
|
||||
}
|
||||
if (selectedControllerId != deviceId) return@runOnUiThread
|
||||
controllerSettingsMessage = if (result.isSuccess) {
|
||||
"设置已保存;重连和重启后按设备特征恢复。"
|
||||
"设置已保存,屏幕按键已同步;重连和重启后恢复。"
|
||||
} else {
|
||||
if (previousProfile == null) controllerProfiles.remove(deviceId)
|
||||
else controllerProfiles[deviceId] = previousProfile
|
||||
"保存失败:${result.exceptionOrNull()?.message ?: "未知错误"};修改仍保留在页面,可重试保存。"
|
||||
}
|
||||
draftProfile = profile
|
||||
renderControllerSettings()
|
||||
}
|
||||
}
|
||||
@@ -1838,9 +1920,8 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
val deviceId = selectedControllerId ?: return
|
||||
val identity = controllerIdentities[deviceId] ?: return
|
||||
val defaultProfile = profileResolver.resolve(identity)
|
||||
controllerProfileRevisions[deviceId] = (controllerProfileRevisions[deviceId] ?: 0) + 1
|
||||
controllerProfiles[deviceId] = defaultProfile
|
||||
draftProfile = defaultProfile
|
||||
val revision = (controllerProfileRevisions[deviceId] ?: 0) + 1
|
||||
controllerProfileRevisions[deviceId] = revision
|
||||
pendingBindingAction = null
|
||||
manualMappingIndex = null
|
||||
bindingCaptureWaitForNeutral = false
|
||||
@@ -1848,9 +1929,22 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
controllerScope.launch {
|
||||
val result = runCatching { profileStore.reset(identity) }
|
||||
runOnUiThread {
|
||||
if (controllerProfileRevisions[deviceId] != revision ||
|
||||
controllerIdentities[deviceId]?.fingerprint() != identity.fingerprint()
|
||||
) return@runOnUiThread
|
||||
if (result.isSuccess) {
|
||||
inputRouter.clearDevice(deviceId).let(::applyRoutedInput)
|
||||
axisHysteresis.clearDevice(deviceId)
|
||||
controllerProfiles[deviceId] = defaultProfile
|
||||
readyControllerProfileIds += deviceId
|
||||
if (selectedControllerId == deviceId) {
|
||||
syncVirtualButtonSwaps()
|
||||
draftProfile = defaultProfile
|
||||
}
|
||||
}
|
||||
if (selectedControllerId != deviceId) return@runOnUiThread
|
||||
controllerSettingsMessage = if (result.isSuccess) {
|
||||
"已恢复安全的通用默认配置。"
|
||||
"已恢复通用默认配置,屏幕按键也已恢复。"
|
||||
} else {
|
||||
"恢复默认失败:${result.exceptionOrNull()?.message ?: "未知错误"}"
|
||||
}
|
||||
@@ -1862,12 +1956,14 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
private fun syncControllerProfiles() {
|
||||
val connected = controllers.mapTo(mutableSetOf()) { it.deviceId }
|
||||
controllerProfiles.keys.retainAll(connected)
|
||||
readyControllerProfileIds.retainAll(connected)
|
||||
controllerIdentities.keys.retainAll(connected)
|
||||
controllerProfileRevisions.keys.retainAll(connected)
|
||||
controllers.forEach { controller ->
|
||||
val identity = controller.toIdentity()
|
||||
if (controllerIdentities[controller.deviceId]?.fingerprint() == identity.fingerprint()) return@forEach
|
||||
controllerIdentities[controller.deviceId] = identity
|
||||
readyControllerProfileIds.remove(controller.deviceId)
|
||||
controllerProfiles[controller.deviceId] = profileResolver.resolve(identity)
|
||||
val revision = (controllerProfileRevisions[controller.deviceId] ?: 0) + 1
|
||||
controllerProfileRevisions[controller.deviceId] = revision
|
||||
@@ -1881,7 +1977,9 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
val cleared = inputRouter.clearDevice(controller.deviceId)
|
||||
axisHysteresis.clearDevice(controller.deviceId)
|
||||
controllerProfiles[controller.deviceId] = restored
|
||||
readyControllerProfileIds += controller.deviceId
|
||||
applyRoutedInput(cleared)
|
||||
if (selectedControllerId == controller.deviceId) syncVirtualButtonSwaps()
|
||||
if (selectedControllerId == controller.deviceId && draftProfile == null) {
|
||||
renderControllerSettings()
|
||||
}
|
||||
@@ -1893,7 +1991,10 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
selectedControllerId = controllers.firstOrNull()?.deviceId
|
||||
draftProfile = null
|
||||
pendingBindingAction = null
|
||||
manualMappingIndex = null
|
||||
bindingCaptureWaitForNeutral = false
|
||||
}
|
||||
syncVirtualButtonSwaps()
|
||||
renderControllerSettings()
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ internal fun computeVirtualGamepadGeometry(
|
||||
dpadScale: Float = 1f,
|
||||
dpadHorizontalOffset: Float = 0f,
|
||||
dpadVerticalOffset: Float = 0f,
|
||||
swapAB: Boolean = false,
|
||||
swapXY: Boolean = false,
|
||||
): VirtualGamepadGeometry {
|
||||
val w = width.coerceAtLeast(1f)
|
||||
val h = height.coerceAtLeast(1f)
|
||||
@@ -96,5 +98,13 @@ internal fun computeVirtualGamepadGeometry(
|
||||
),
|
||||
pause = VirtualControl(w - rightInset - sideWidth * 0.72f - horizontalShift + shift, h * 0.13f, utilityRadius),
|
||||
reset = VirtualControl(baseResetX + shift, h * 0.13f, utilityRadius),
|
||||
)
|
||||
).let { geometry ->
|
||||
// Drawing, pressed feedback and touch hit testing all use these same controls.
|
||||
geometry.copy(
|
||||
faceA = if (swapAB) geometry.faceB else geometry.faceA,
|
||||
faceB = if (swapAB) geometry.faceA else geometry.faceB,
|
||||
faceX = if (swapXY) geometry.faceY else geometry.faceX,
|
||||
faceY = if (swapXY) geometry.faceX else geometry.faceY,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ class VirtualGamepadView(
|
||||
private var safeLeft = 0f
|
||||
private var safeRight = 0f
|
||||
private var screenShift = 0f
|
||||
private var swapAB = false
|
||||
private var swapXY = false
|
||||
private var directionMode = DirectionMode.EIGHT_WAY
|
||||
private var dpadScale = 1.18f
|
||||
private var dpadHorizontalOffset = 0f
|
||||
@@ -88,6 +90,15 @@ class VirtualGamepadView(
|
||||
invalidate()
|
||||
}
|
||||
|
||||
internal fun configureButtonSwaps(swapAB: Boolean, swapXY: Boolean) {
|
||||
if (this.swapAB == swapAB && this.swapXY == swapXY) return
|
||||
// Release touches against the old layout before changing their targets.
|
||||
clearInputs()
|
||||
this.swapAB = swapAB
|
||||
this.swapXY = swapXY
|
||||
invalidate()
|
||||
}
|
||||
|
||||
internal fun configureDpad(
|
||||
mode: DirectionMode,
|
||||
scale: Float,
|
||||
@@ -285,6 +296,8 @@ class VirtualGamepadView(
|
||||
dpadScale = dpadScale,
|
||||
dpadHorizontalOffset = dpadHorizontalOffset,
|
||||
dpadVerticalOffset = dpadVerticalOffset,
|
||||
swapAB = swapAB,
|
||||
swapXY = swapXY,
|
||||
)
|
||||
|
||||
private companion object {
|
||||
|
||||
@@ -52,6 +52,7 @@ data class ControllerProfile(
|
||||
val pressThreshold: Float = 0.55f,
|
||||
val releaseThreshold: Float = 0.35f,
|
||||
val swapAB: Boolean = false,
|
||||
val swapXY: Boolean = false,
|
||||
) {
|
||||
init {
|
||||
require(pressThreshold in 0.2f..0.95f)
|
||||
@@ -78,6 +79,16 @@ data class ControllerProfile(
|
||||
},
|
||||
)
|
||||
|
||||
fun toggleXY(): ControllerProfile {
|
||||
val x = bindings[GameAction.TURBO_A].orEmpty()
|
||||
val y = bindings[GameAction.TURBO_B].orEmpty()
|
||||
return copy(
|
||||
origin = ProfileOrigin.CUSTOM,
|
||||
bindings = bindings + mapOf(GameAction.TURBO_A to y, GameAction.TURBO_B to x),
|
||||
swapXY = !swapXY,
|
||||
)
|
||||
}
|
||||
|
||||
fun toggleAB(): ControllerProfile {
|
||||
val a = bindings[GameAction.NES_A].orEmpty()
|
||||
val b = bindings[GameAction.NES_B].orEmpty()
|
||||
|
||||
@@ -13,6 +13,7 @@ object ControllerProfileJson {
|
||||
.put("pressThreshold", profile.pressThreshold.toDouble())
|
||||
.put("releaseThreshold", profile.releaseThreshold.toDouble())
|
||||
.put("swapAB", profile.swapAB)
|
||||
.put("swapXY", profile.swapXY)
|
||||
.put(
|
||||
"bindings",
|
||||
JSONObject().apply {
|
||||
@@ -50,6 +51,7 @@ object ControllerProfileJson {
|
||||
pressThreshold = root.getDouble("pressThreshold").toFloat(),
|
||||
releaseThreshold = root.getDouble("releaseThreshold").toFloat(),
|
||||
swapAB = root.getBoolean("swapAB"),
|
||||
swapXY = root.optBoolean("swapXY", false),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ data class AppSettings(
|
||||
val virtualDpadSize: VirtualDpadSize = VirtualDpadSize.LARGE,
|
||||
val virtualDpadHorizontalOffset: Float = 0f,
|
||||
val virtualDpadVerticalOffset: Float = 0f,
|
||||
val virtualSwapAB: Boolean = false,
|
||||
val virtualSwapXY: Boolean = false,
|
||||
val guideCompleted: Boolean = false,
|
||||
)
|
||||
|
||||
@@ -63,6 +65,8 @@ class AppSettingsStore(private val context: Context) {
|
||||
virtualDpadSize = VirtualDpadSize.fromStored(values[VIRTUAL_DPAD_SIZE] ?: VirtualDpadSize.LARGE.ordinal),
|
||||
virtualDpadHorizontalOffset = (values[VIRTUAL_DPAD_HORIZONTAL_OFFSET] ?: 0f).coerceIn(-1f, 1f),
|
||||
virtualDpadVerticalOffset = (values[VIRTUAL_DPAD_VERTICAL_OFFSET] ?: 0f).coerceIn(-1f, 1f),
|
||||
virtualSwapAB = values[VIRTUAL_SWAP_AB] ?: false,
|
||||
virtualSwapXY = values[VIRTUAL_SWAP_XY] ?: false,
|
||||
guideCompleted = values[GUIDE_COMPLETED] ?: false,
|
||||
)
|
||||
}
|
||||
@@ -80,6 +84,8 @@ class AppSettingsStore(private val context: Context) {
|
||||
values[VIRTUAL_DPAD_SIZE] = settings.virtualDpadSize.ordinal
|
||||
values[VIRTUAL_DPAD_HORIZONTAL_OFFSET] = settings.virtualDpadHorizontalOffset.coerceIn(-1f, 1f)
|
||||
values[VIRTUAL_DPAD_VERTICAL_OFFSET] = settings.virtualDpadVerticalOffset.coerceIn(-1f, 1f)
|
||||
values[VIRTUAL_SWAP_AB] = settings.virtualSwapAB
|
||||
values[VIRTUAL_SWAP_XY] = settings.virtualSwapXY
|
||||
values[GUIDE_COMPLETED] = settings.guideCompleted
|
||||
}
|
||||
}
|
||||
@@ -97,6 +103,8 @@ class AppSettingsStore(private val context: Context) {
|
||||
private val VIRTUAL_DPAD_SIZE = intPreferencesKey("virtual_dpad_size")
|
||||
private val VIRTUAL_DPAD_HORIZONTAL_OFFSET = floatPreferencesKey("virtual_dpad_horizontal_offset")
|
||||
private val VIRTUAL_DPAD_VERTICAL_OFFSET = floatPreferencesKey("virtual_dpad_vertical_offset")
|
||||
private val VIRTUAL_SWAP_AB = booleanPreferencesKey("virtual_swap_ab")
|
||||
private val VIRTUAL_SWAP_XY = booleanPreferencesKey("virtual_swap_xy")
|
||||
private val GUIDE_COMPLETED = booleanPreferencesKey("guide_completed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ class BuildIdentityTest {
|
||||
@Test
|
||||
fun debugBuildUsesTheDocumentedIdentity() {
|
||||
assertEquals("org.neslite.app.debug", BuildConfig.APPLICATION_ID)
|
||||
assertEquals("1.0.0-debug", BuildConfig.VERSION_NAME)
|
||||
assertEquals(1000000, BuildConfig.VERSION_CODE)
|
||||
assertEquals("1.0.2-debug", BuildConfig.VERSION_NAME)
|
||||
assertEquals(1000002, BuildConfig.VERSION_CODE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +218,47 @@ class VirtualGamepadLayoutTest {
|
||||
assertTrue(flipped.faceB.x + flipped.faceB.radius < 2760f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun allSwapCombinationsMoveOnlyTheirMatchingLabeledTouchControls() {
|
||||
val original = computeVirtualGamepadGeometry(2760f, 1256f, 126f)
|
||||
for (swapAB in listOf(false, true)) {
|
||||
for (swapXY in listOf(false, true)) {
|
||||
val swapped = computeVirtualGamepadGeometry(
|
||||
2760f, 1256f, 126f, swapAB = swapAB, swapXY = swapXY,
|
||||
)
|
||||
assertEquals(if (swapAB) original.faceB else original.faceA, swapped.faceA)
|
||||
assertEquals(if (swapAB) original.faceA else original.faceB, swapped.faceB)
|
||||
assertEquals(if (swapXY) original.faceY else original.faceX, swapped.faceX)
|
||||
assertEquals(if (swapXY) original.faceX else original.faceY, swapped.faceY)
|
||||
// Every other control and the game viewport remain unchanged.
|
||||
assertEquals(original, swapped.copy(
|
||||
faceA = original.faceA, faceB = original.faceB,
|
||||
faceX = original.faceX, faceY = original.faceY,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swappedControlsKeepTheirPositionsAcrossDifferentInsetsAndDpadSettings() {
|
||||
for (inset in listOf(0f, 48f, 172f, 288f)) {
|
||||
val original = computeVirtualGamepadGeometry(
|
||||
2760f, 1256f, 126f, safeLeft = inset, screenShift = 47f,
|
||||
dpadScale = 1.35f, dpadHorizontalOffset = -1f, dpadVerticalOffset = 1f,
|
||||
)
|
||||
val swapped = computeVirtualGamepadGeometry(
|
||||
2760f, 1256f, 126f, safeLeft = inset, screenShift = 47f,
|
||||
dpadScale = 1.35f, dpadHorizontalOffset = -1f, dpadVerticalOffset = 1f,
|
||||
swapAB = true, swapXY = true,
|
||||
)
|
||||
assertEquals(original.faceB, swapped.faceA)
|
||||
assertEquals(original.faceA, swapped.faceB)
|
||||
assertEquals(original.faceY, swapped.faceX)
|
||||
assertEquals(original.faceX, swapped.faceY)
|
||||
assertEquals(original.horizontalShift, swapped.horizontalShift)
|
||||
}
|
||||
}
|
||||
|
||||
private fun distance(first: VirtualControl, second: VirtualControl): Float =
|
||||
hypot(first.x - second.x, first.y - second.y)
|
||||
}
|
||||
|
||||
@@ -55,6 +55,54 @@ class ControllerProfileTest {
|
||||
assertFalse(JSONObject(ControllerProfileJson.encode(swapped)).has("deviceId"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun xySwapOnlyExchangesTurboActionsAndIsReversible() {
|
||||
val original = ControllerProfileResolver().resolve(identity)
|
||||
val swapped = original.toggleXY()
|
||||
assertTrue(swapped.swapXY)
|
||||
assertFalse(swapped.swapAB)
|
||||
assertEquals(ProfileOrigin.CUSTOM, swapped.origin)
|
||||
assertEquals(setOf(GameAction.TURBO_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 99)))
|
||||
assertEquals(setOf(GameAction.TURBO_A), swapped.actionsFor(InputBinding(BindingKind.KEY, 100)))
|
||||
GameAction.entries.filter { it != GameAction.TURBO_A && it != GameAction.TURBO_B }.forEach {
|
||||
assertEquals(original.bindings[it], swapped.bindings[it])
|
||||
}
|
||||
assertEquals(original.bindings, swapped.toggleXY().bindings)
|
||||
assertFalse(swapped.toggleXY().swapXY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bothSwapsAreIndependentAndPersistTogether() {
|
||||
val original = ControllerProfileResolver().resolve(identity)
|
||||
val swapped = original.toggleAB().toggleXY()
|
||||
assertEquals(swapped, original.toggleXY().toggleAB())
|
||||
assertEquals(setOf(GameAction.NES_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 96)))
|
||||
assertEquals(setOf(GameAction.NES_A), swapped.actionsFor(InputBinding(BindingKind.KEY, 97)))
|
||||
assertEquals(swapped, ControllerProfileJson.decode(ControllerProfileJson.encode(swapped)))
|
||||
val xyOnly = swapped.toggleAB()
|
||||
assertFalse(xyOnly.swapAB)
|
||||
assertTrue(xyOnly.swapXY)
|
||||
assertEquals(original.bindings, xyOnly.toggleXY().bindings)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun legacyProfileWithoutXyFlagKeepsSavedBindings() {
|
||||
val original = ControllerProfileResolver().resolve(identity).toggleAB()
|
||||
val legacy = JSONObject(ControllerProfileJson.encode(original)).apply { remove("swapXY") }
|
||||
assertEquals(original, ControllerProfileJson.decode(legacy.toString()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun xySwapPreservesCustomAndEmptyBindings() {
|
||||
val original = ControllerProfileResolver().resolve(identity)
|
||||
.replaceBinding(GameAction.TURBO_A, InputBinding(BindingKind.KEY, 188))
|
||||
.clearBinding(GameAction.TURBO_B)
|
||||
val swapped = original.toggleXY()
|
||||
assertTrue(swapped.bindings.getValue(GameAction.TURBO_A).isEmpty())
|
||||
assertEquals(setOf(GameAction.TURBO_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 188)))
|
||||
assertEquals(original, swapped.toggleXY())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun manualMappingCanReplaceAndClearEachAction() {
|
||||
val original = ControllerProfileResolver().resolve(identity)
|
||||
|
||||
@@ -20,6 +20,8 @@ class AppSettingsTest {
|
||||
assertEquals(VirtualDpadSize.LARGE, settings.virtualDpadSize)
|
||||
assertEquals(0f, settings.virtualDpadHorizontalOffset)
|
||||
assertEquals(0f, settings.virtualDpadVerticalOffset)
|
||||
assertFalse(settings.virtualSwapAB)
|
||||
assertFalse(settings.virtualSwapXY)
|
||||
assertFalse(settings.guideCompleted)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
# NESLite 构建与打包
|
||||
|
||||
项目的 APK 打包入口统一为根目录 `打包.cmd`,项目内的编译产物、缓存、日志和交付文件统一放入
|
||||
`build/`。当前应用版本为 1.0.0,入口从 APK 构建元数据读取版本,不另写一套版本号。
|
||||
`build/`。当前应用版本为 1.0.2,入口从 APK 构建元数据读取版本,不另写一套版本号。
|
||||
|
||||
## 一键打包
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
.\打包.cmd -NoPause
|
||||
```
|
||||
|
||||
当前交付文件是 `build/releases/NESLite-1.0.0-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.0-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。
|
||||
该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.2-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。
|
||||
正式打包前必须提交源码并配置签名目录;入口读取 Windows 用户加密的密码,完成签名和签名验证。密钥位置与发布步骤见 [publishing.md](publishing.md)。
|
||||
一键打包不会运行原 `package-rc.ps1` 的全量 Stage/lint/设备测试包构建,也不表示发布门槛通过。
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
ABXY、视图/菜单键及左右肩键。随后在荣耀 Magic8 页面取得了 Android 设备身份和静态轴范围;
|
||||
实际 KeyEvent、动态轴采样、手柄模式及拔出重连仍待诊断 JSON 回填。
|
||||
|
||||
在 0.9.15-debug 中可从“设置 → 手动设置手柄按键、摇杆与功能键”进入编辑页。可选择“开始逐项手动
|
||||
在 0.9.15-debug 中可从“设置 → 交换 X/Y、A/B 按键与手动映射”进入编辑页。可选择“开始逐项手动
|
||||
设置全部按键”,按页面顺序操作 X5 Lite;也可点击任一动作单独修改或清除。轴方向捕获后先松回中位,
|
||||
冲突时确认是否替换,最后点击“保存”。配置按下表设备指纹保存,不依赖临时 deviceId。
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# NESLite 1.0.1
|
||||
|
||||
本次更新增加手柄与屏幕虚拟按键的同步交换,面向 Android 9 及以上的 arm64 设备。
|
||||
|
||||
## 本次更新
|
||||
|
||||
- 设置中提供“交换 X/Y、A/B 按键与手动映射”入口,两组可独立交换。
|
||||
- 保存后屏幕虚拟按键同步换位,文字、颜色、按下反馈和触控区域保持一致。
|
||||
- 屏幕按键在断开手柄或重启后保留最近的交换状态;恢复默认时一起还原。
|
||||
- 兼容旧手柄配置,换位前释放触控输入,保存失败时继续使用原有映射。
|
||||
|
||||
## 安装
|
||||
|
||||
安装包为 `NESLite-1.0.1-arm64-v8a.apk`,正式包名为 `org.neslite.app`,版本号为 1000001。
|
||||
沿用 1.0.0 正式签名,可直接覆盖安装旧正式版。调试版包名不同,仍需通过存档导入导出迁移进度。
|
||||
应用不附带游戏 ROM。
|
||||
|
||||
## 验证与构建材料
|
||||
|
||||
功能修改已通过 71 项单元测试和调试构建;手柄实机、触屏操作及覆盖升级仍待设备验证。
|
||||
正式打包流程校验签名、arm64 库与 16 KB 静态对齐,并输出源码、原生符号、依赖源码和 SHA-256 清单。
|
||||
具体版本、源码提交及安装包校验值见同目录的 `NESLite-1.0.1-release.json`。
|
||||
@@ -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/`。
|
||||
+8
-1
@@ -13,7 +13,14 @@
|
||||
长按游戏名可查看详情、收藏、从列表移除或选择内核。连接外接手柄后仍可按设置选择是否显示
|
||||
屏幕按键。多点触控支持方向与动作同时按住,滑出、取消、失焦或暂停都会释放输入。
|
||||
4. 点左上角“设置”图标,在画面与声音、方向与触控、手柄与辅助三个卡片中调整选项,可切换 4:3/整数缩放、最近邻/线性过滤、音量、静音、软件连发和 RB 快进。进入
|
||||
“手动设置手柄按键、摇杆与功能键”后,可启动逐项向导,也可单独点击动作修改或清除;按下物理键
|
||||
“交换 X/Y、A/B 按键与手动映射”后,无论是否连接手柄,都能看到“交换 X/Y 按键”和“交换 A/B 按键”。
|
||||
未连接手柄时,点击即可交换屏幕按键并自动保存,也可点击“恢复屏幕按键默认顺序”;无需连接手柄。
|
||||
连接手柄时,两项编辑当前手柄配置,点击“保存”后手柄与屏幕按键同步生效。
|
||||
默认 A/B 对应 NES A/B,X/Y 对应 A/B 连发;两组独立交换,保存后所选手柄与屏幕虚拟按键同步。
|
||||
屏幕上的按钮文字、颜色、按下反馈与触控区域一起换位;断开手柄或重启应用后保留最近的交换状态。
|
||||
切换所选手柄时,屏幕跟随该手柄已保存的交换设置;尚未保存的修改不会影响屏幕按键。
|
||||
已有自定义映射时,交换对应的普通或连发动作绑定;再次切换可还原,恢复默认映射会关闭两项交换。
|
||||
同一页面可启动逐项向导,也可单独点击动作修改或清除;按下物理键
|
||||
或推动轴完成捕获,检查无误后点“保存”。冲突会要求确认,设置按设备特征在重启和重连后恢复。
|
||||
“屏幕方向键与手柄摇杆”可切换四方向/八方向,并循环选择标准、大、特大方向键;两个位置滑块可
|
||||
调整方向键的水平和垂直位置。默认八方向与大号,A、B 支持两根手指同时按住。
|
||||
|
||||
Reference in New Issue
Block a user