fix: move game exit into virtual utility controls for 1.0.5
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# NESLite
|
||||
|
||||
NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.4,内置固定提交的
|
||||
NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.5,内置固定提交的
|
||||
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.4](docs/releases/1.0.4.md),首次发布说明见 [1.0.0](docs/releases/1.0.0.md)。
|
||||
[发行版](http://git.m3frame.com/shen/NESLite/releases),本次更新说明见 [1.0.5](docs/releases/1.0.5.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 = 1000004
|
||||
versionName = "1.0.4"
|
||||
versionCode = 1000005
|
||||
versionName = "1.0.5"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
ndk {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.neslite.app
|
||||
|
||||
import android.os.SystemClock
|
||||
import android.view.MotionEvent
|
||||
import org.junit.Assert.assertEquals
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
@@ -26,7 +29,14 @@ class ExitControlsTest {
|
||||
@Test
|
||||
fun gameExitWithNoSessionOpensLibraryAndApplicationExitClosesTask() = withPreparedSettings {
|
||||
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
|
||||
onView(withContentDescription("退出游戏")).perform(click())
|
||||
scenario.onActivity { activity ->
|
||||
val view = MainActivity::class.java.getDeclaredField("virtualGamepad").apply { isAccessible = true }
|
||||
.get(activity) as VirtualGamepadView
|
||||
val geometry = VirtualGamepadView::class.java.getDeclaredMethod("geometry").apply { isAccessible = true }
|
||||
.invoke(view) as VirtualGamepadGeometry
|
||||
touch(view, MotionEvent.ACTION_DOWN, geometry.exit.x, geometry.exit.y)
|
||||
touch(view, MotionEvent.ACTION_UP, geometry.exit.x, geometry.exit.y)
|
||||
}
|
||||
onView(allOf(withText("游戏列表"), isDisplayed())).check(matches(isDisplayed()))
|
||||
onView(allOf(withText("退出应用"), isDisplayed())).perform(click())
|
||||
awaitDestroyed(scenario)
|
||||
@@ -42,6 +52,41 @@ class ExitControlsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun exitRequiresATapAndDoesNotFireFromSlidingOrCancelledTouches() {
|
||||
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
instrumentation.runOnMainSync {
|
||||
var exits = 0
|
||||
val view = VirtualGamepadView(instrumentation.targetContext, { _, _, _ -> }, {}, { exits++ })
|
||||
view.layout(0, 0, 2760, 1256)
|
||||
val geometry = VirtualGamepadView::class.java.getDeclaredMethod("geometry").apply { isAccessible = true }
|
||||
.invoke(view) as VirtualGamepadGeometry
|
||||
val x = geometry.exit.x
|
||||
val y = geometry.exit.y
|
||||
touch(view, MotionEvent.ACTION_DOWN, x, y)
|
||||
assertEquals(0, exits)
|
||||
touch(view, MotionEvent.ACTION_UP, x, y)
|
||||
assertEquals(1, exits)
|
||||
touch(view, MotionEvent.ACTION_DOWN, x, y)
|
||||
touch(view, MotionEvent.ACTION_MOVE, x, y + geometry.exit.radius * 4)
|
||||
touch(view, MotionEvent.ACTION_UP, x, y)
|
||||
touch(view, MotionEvent.ACTION_DOWN, x, y)
|
||||
touch(view, MotionEvent.ACTION_CANCEL, x, y)
|
||||
touch(view, MotionEvent.ACTION_UP, x, y)
|
||||
touch(view, MotionEvent.ACTION_DOWN, geometry.faceA.x, geometry.faceA.y)
|
||||
touch(view, MotionEvent.ACTION_MOVE, x, y)
|
||||
touch(view, MotionEvent.ACTION_UP, x, y)
|
||||
assertEquals(1, exits)
|
||||
}
|
||||
}
|
||||
|
||||
private fun touch(view: VirtualGamepadView, action: Int, x: Float, y: Float) {
|
||||
val now = SystemClock.uptimeMillis()
|
||||
MotionEvent.obtain(now, now, action, x, y, 0).let { event ->
|
||||
try { view.onTouchEvent(event) } finally { event.recycle() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun awaitDestroyed(scenario: ActivityScenario<MainActivity>) = runBlocking {
|
||||
withTimeout(5000L) {
|
||||
while (scenario.state != Lifecycle.State.DESTROYED) delay(50L)
|
||||
|
||||
@@ -829,6 +829,7 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
if (activeSessionId == 0L) showEmulatorStatus("请先从游戏列表选择游戏")
|
||||
else sendControlCommand("reset")
|
||||
},
|
||||
onExit = { requestExit(ExitDestination.LIBRARY) },
|
||||
onHorizontalShiftChanged = { horizontalShift ->
|
||||
gameViewport.translationX = -horizontalShift
|
||||
},
|
||||
@@ -865,13 +866,6 @@ class MainActivity : ComponentActivity(), InputManager.InputDeviceListener {
|
||||
addView(libraryRailButton)
|
||||
addView(railButton("+", "导入游戏", ::openImportPage))
|
||||
addView(railButton("⚙", "设置", ::showSettings))
|
||||
addView(Button(context).apply {
|
||||
text = "退出游戏"
|
||||
contentDescription = "退出游戏"
|
||||
isAllCaps = false
|
||||
textSize = 12f
|
||||
setOnClickListener { requestExit(ExitDestination.LIBRARY) }
|
||||
}, LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dp(38)))
|
||||
},
|
||||
FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dp(44), Gravity.START or Gravity.TOP).apply {
|
||||
leftMargin = dp(6)
|
||||
|
||||
@@ -20,6 +20,7 @@ internal data class VirtualGamepadGeometry(
|
||||
val start: VirtualControl,
|
||||
val pause: VirtualControl,
|
||||
val reset: VirtualControl,
|
||||
val exit: VirtualControl,
|
||||
)
|
||||
|
||||
internal fun computeVirtualGamepadGeometry(
|
||||
@@ -59,8 +60,11 @@ internal fun computeVirtualGamepadGeometry(
|
||||
val expandedRightWidth = (w - rightInset - baseGameRight).coerceAtLeast(1f)
|
||||
val faceX = baseGameRight + expandedRightWidth * 0.50f
|
||||
val faceGapX = min(faceRadius * 1.70f, expandedRightWidth * 0.50f - faceRadius)
|
||||
val baseResetX = w - rightInset - sideWidth * 0.28f - horizontalShift
|
||||
val rightmostControl = maxOf(faceX + faceGapX + faceRadius, baseResetX + utilityRadius)
|
||||
val utilityGapX = expandedRightWidth / 3f
|
||||
val rightmostControl = maxOf(
|
||||
faceX + faceGapX + faceRadius,
|
||||
faceX + utilityGapX + utilityRadius * 1.14f,
|
||||
)
|
||||
val shift = screenShift.coerceIn(0f, (w - rightmostControl - edgeGap).coerceAtLeast(0f))
|
||||
val gameLeft = baseGameLeft + shift
|
||||
val gameRight = baseGameRight + shift
|
||||
@@ -96,8 +100,10 @@ internal fun computeVirtualGamepadGeometry(
|
||||
h * 0.89f,
|
||||
menuRadius,
|
||||
),
|
||||
pause = VirtualControl(w - rightInset - sideWidth * 0.72f - horizontalShift + shift, h * 0.13f, utilityRadius),
|
||||
reset = VirtualControl(baseResetX + shift, h * 0.13f, utilityRadius),
|
||||
// Keep all three utility buttons inside the same right-side area as ABXY.
|
||||
pause = VirtualControl(faceX - utilityGapX + shift, h * 0.13f, utilityRadius),
|
||||
reset = VirtualControl(faceX + shift, h * 0.13f, utilityRadius),
|
||||
exit = VirtualControl(faceX + utilityGapX + shift, h * 0.13f, utilityRadius),
|
||||
).let { geometry ->
|
||||
// Drawing, pressed feedback and touch hit testing all use these same controls.
|
||||
geometry.copy(
|
||||
|
||||
@@ -20,11 +20,13 @@ class VirtualGamepadView(
|
||||
context: Context,
|
||||
private val onTransition: (pointerId: Int, action: GameAction, pressed: Boolean) -> Unit,
|
||||
private val onReset: () -> Unit,
|
||||
private val onExit: () -> Unit = {},
|
||||
private val onHorizontalShiftChanged: (Float) -> Unit = {},
|
||||
) : View(context) {
|
||||
private val tracker = VirtualInputTracker()
|
||||
private val dpadResolver = VirtualDpadResolver()
|
||||
private val resetPointers = mutableSetOf<Int>()
|
||||
private val exitPointers = mutableMapOf<Int, Boolean>()
|
||||
private val resetRunnables = mutableMapOf<Int, Runnable>()
|
||||
private val fill = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.argb(145, 45, 52, 64) }
|
||||
private val turboFill = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.argb(150, 65, 79, 99) }
|
||||
@@ -56,7 +58,7 @@ class VirtualGamepadView(
|
||||
|
||||
init {
|
||||
isFocusable = true
|
||||
contentDescription = "屏幕虚拟手柄:方向、A、B、X、Y、Start、Select、暂停和重置"
|
||||
contentDescription = "屏幕虚拟手柄:方向、A、B、X、Y、Start、Select、暂停、重置和退出"
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
@@ -72,6 +74,7 @@ class VirtualGamepadView(
|
||||
drawControl(canvas, geometry.start, "Start", compact = true, isPressed = GameAction.START in pressed)
|
||||
drawControl(canvas, geometry.pause, "暂停", compact = true, isPressed = GameAction.PAUSE_MENU in pressed)
|
||||
drawControl(canvas, geometry.reset, "重置", compact = true, secondary = "长按", isPressed = resetPointers.isNotEmpty())
|
||||
drawControl(canvas, geometry.exit, "退出", compact = true, isPressed = exitPointers.values.any { it })
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
@@ -124,7 +127,9 @@ class VirtualGamepadView(
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> updatePointer(event, event.actionIndex)
|
||||
MotionEvent.ACTION_MOVE -> repeat(event.pointerCount) { updatePointer(event, it) }
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> releasePointer(event.getPointerId(event.actionIndex))
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> releasePointer(
|
||||
event.getPointerId(event.actionIndex), event.getX(event.actionIndex), event.getY(event.actionIndex),
|
||||
)
|
||||
MotionEvent.ACTION_CANCEL -> clearInputs()
|
||||
}
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP) performClick()
|
||||
@@ -140,6 +145,7 @@ class VirtualGamepadView(
|
||||
resetRunnables.values.forEach(::removeCallbacks)
|
||||
resetRunnables.clear()
|
||||
resetPointers.clear()
|
||||
exitPointers.clear()
|
||||
emit(tracker.clear())
|
||||
invalidate()
|
||||
}
|
||||
@@ -148,6 +154,19 @@ class VirtualGamepadView(
|
||||
val pointerId = event.getPointerId(index)
|
||||
val x = event.getX(index)
|
||||
val y = event.getY(index)
|
||||
if (pointerId in exitPointers) {
|
||||
exitPointers[pointerId] = exitPointers[pointerId] == true && inside(geometry().exit, x, y)
|
||||
invalidate()
|
||||
return
|
||||
}
|
||||
val startingTouch = event.actionMasked == MotionEvent.ACTION_DOWN ||
|
||||
event.actionMasked == MotionEvent.ACTION_POINTER_DOWN
|
||||
if (startingTouch && inside(geometry().exit, x, y)) {
|
||||
exitPointers[pointerId] = true
|
||||
emit(tracker.update(pointerId, emptySet()))
|
||||
invalidate()
|
||||
return
|
||||
}
|
||||
if (inside(geometry().reset, x, y)) {
|
||||
emit(tracker.update(pointerId, emptySet()))
|
||||
beginResetHold(pointerId)
|
||||
@@ -160,9 +179,11 @@ class VirtualGamepadView(
|
||||
emit(tracker.update(pointerId, hitTestActions(pointerId, x, y)))
|
||||
}
|
||||
|
||||
private fun releasePointer(pointerId: Int) {
|
||||
private fun releasePointer(pointerId: Int, x: Float, y: Float) {
|
||||
val exitClicked = exitPointers.remove(pointerId) == true && inside(geometry().exit, x, y)
|
||||
cancelPendingReset(pointerId, keepConsumed = false)
|
||||
emit(tracker.update(pointerId, null))
|
||||
if (exitClicked) onExit()
|
||||
}
|
||||
|
||||
private fun beginResetHold(pointerId: Int) {
|
||||
|
||||
@@ -7,7 +7,7 @@ class BuildIdentityTest {
|
||||
@Test
|
||||
fun debugBuildUsesTheDocumentedIdentity() {
|
||||
assertEquals("org.neslite.app.debug", BuildConfig.APPLICATION_ID)
|
||||
assertEquals("1.0.4-debug", BuildConfig.VERSION_NAME)
|
||||
assertEquals(1000004, BuildConfig.VERSION_CODE)
|
||||
assertEquals("1.0.5-debug", BuildConfig.VERSION_NAME)
|
||||
assertEquals(1000005, BuildConfig.VERSION_CODE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ class VirtualGamepadLayoutTest {
|
||||
geometry.start,
|
||||
geometry.pause,
|
||||
geometry.reset,
|
||||
geometry.exit,
|
||||
)
|
||||
|
||||
assertTrue(leftControls.all { it.x + it.radius <= geometry.gameLeft })
|
||||
@@ -97,6 +98,7 @@ class VirtualGamepadLayoutTest {
|
||||
geometry.start,
|
||||
geometry.pause,
|
||||
geometry.reset,
|
||||
geometry.exit,
|
||||
)
|
||||
|
||||
assertTrue(controls.all { it.x - it.radius >= 0f && it.x + it.radius <= width })
|
||||
@@ -163,9 +165,9 @@ class VirtualGamepadLayoutTest {
|
||||
assertEquals(right.pause.radius, left.pause.radius, 0.01f)
|
||||
assertEquals(movement, left.gameLeft - right.gameLeft, 0.01f)
|
||||
val leftControls = listOf(left.up, left.down, left.left, left.right, left.select,
|
||||
left.faceX, left.faceY, left.faceA, left.faceB, left.start, left.pause, left.reset)
|
||||
left.faceX, left.faceY, left.faceA, left.faceB, left.start, left.pause, left.reset, left.exit)
|
||||
val rightControls = listOf(right.up, right.down, right.left, right.right, right.select,
|
||||
right.faceX, right.faceY, right.faceA, right.faceB, right.start, right.pause, right.reset)
|
||||
right.faceX, right.faceY, right.faceA, right.faceB, right.start, right.pause, right.reset, right.exit)
|
||||
leftControls.zip(rightControls).forEach { (shifted, original) ->
|
||||
assertEquals(movement, shifted.x - original.x, 0.01f)
|
||||
assertEquals(original.radius, shifted.radius, 0.01f)
|
||||
@@ -259,6 +261,26 @@ class VirtualGamepadLayoutTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun utilityRowStaysOutsideViewportWithSeparateTouchTargets() {
|
||||
for ((width, height) in listOf(2760f to 1256f, 2400f to 1080f, 1920f to 1080f)) {
|
||||
for (inset in listOf(0f, 48f, 160f)) {
|
||||
val geometry = computeVirtualGamepadGeometry(width, height, 126f,
|
||||
safeLeft = inset, safeRight = inset, screenShift = 128f, dpadScale = 1.18f)
|
||||
val row = listOf(geometry.pause, geometry.reset, geometry.exit)
|
||||
row.forEach {
|
||||
assertEquals(geometry.pause.radius, it.radius, 0.01f)
|
||||
assertEquals(geometry.pause.y, it.y, 0.01f)
|
||||
assertTrue(it.x - it.radius * 1.14f >= geometry.gameRight)
|
||||
assertTrue(it.x + it.radius * 1.14f <= width)
|
||||
}
|
||||
row.zipWithNext().forEach { (left, right) ->
|
||||
assertTrue(right.x - left.x > (left.radius + right.radius) * 1.14f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun distance(first: VirtualControl, second: VirtualControl): Float =
|
||||
hypot(first.x - second.x, first.y - second.y)
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
# NESLite 构建与打包
|
||||
|
||||
项目的 APK 打包入口统一为根目录 `打包.cmd`,项目内的编译产物、缓存、日志和交付文件统一放入
|
||||
`build/`。当前应用版本为 1.0.4,入口从 APK 构建元数据读取版本,不另写一套版本号。
|
||||
`build/`。当前应用版本为 1.0.5,入口从 APK 构建元数据读取版本,不另写一套版本号。
|
||||
|
||||
## 一键打包
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
.\打包.cmd -NoPause
|
||||
```
|
||||
|
||||
当前交付文件是 `build/releases/NESLite-1.0.4-debug-arm64-v8a.apk`,旁边的 `.sha256` 保存校验值。
|
||||
当前交付文件是 `build/releases/NESLite-1.0.5-debug-arm64-v8a.apk`,旁边的 `.sha256` 保存校验值。
|
||||
入口检查工具链与固定依赖、编译选定 APK、检查原生库和 APK 的 16 KB 对齐,成功后复制产物。
|
||||
它不会自动启动单元测试、ROM 遍历、设备测试或发布回归;失败会返回非零退出码,旧交付 APK 不冒充本次成功产物。
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
.\打包.cmd release -NoPause
|
||||
```
|
||||
|
||||
该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.4-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。
|
||||
该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.5-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。
|
||||
正式打包前必须提交源码并配置签名目录;入口读取 Windows 用户加密的密码,完成签名和签名验证。密钥位置与发布步骤见 [publishing.md](publishing.md)。
|
||||
一键打包不会运行原 `package-rc.ps1` 的全量 Stage/lint/设备测试包构建,也不表示发布门槛通过。
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# NESLite 1.0.5
|
||||
|
||||
调整游戏画面的退出按钮,避免遮挡中央游戏窗口。
|
||||
|
||||
- 移除左上角工具栏中的矩形“退出游戏”按钮。
|
||||
- 右侧上方按“暂停、重置、退出”排列,三个按钮沿用相同的圆形尺寸、描边和配色。
|
||||
- “退出”仍执行暂停、确认、保存并返回游戏列表的安全退出流程;滑入或滑出取消的触摸不会误触退出。
|
||||
- 暂停菜单中的退出游戏及退出应用入口保留。
|
||||
|
||||
正式安装包为 `NESLite-1.0.5-arm64-v8a.apk`,版本号为 1000005,沿用原有正式签名。
|
||||
新增不同横屏尺寸与安全边距下的按钮布局检查,并更新设备点击测试;设备测试仍需连接手机执行。
|
||||
82 项单元测试通过,应用和设备测试包编译成功;实机点击测试尚未执行。
|
||||
Reference in New Issue
Block a user