feat(ui): 主菜单/暂停菜单屏幕状态机——中文标题「年糕历险记」、按钮点击、Esc 暂停(烟雾测试 10 秒无崩溃)

This commit is contained in:
NianGao Dev
2026-08-15 23:43:31 +08:00
parent 272f69b6a3
commit 6cc0f12079
4 changed files with 248 additions and 3 deletions

View File

@@ -31,6 +31,12 @@ type inputState struct {
breakHeld bool
placeDown bool
selectSlot int // -1 无
// 鼠标与 UI 事件(UI与输入.md §6 屏幕交互)
cursorX, cursorY float64
clickX, clickY float32
clicked bool
escPressed bool
}
// newInputState 创建输入状态并注册回调。
@@ -63,7 +69,7 @@ func (in *inputState) keyCallback(_ *glfw.Window, key glfw.Key, _ int, action gl
in.sprint = down
case glfw.KeyEscape:
if action == glfw.Press {
in.win.SetShouldClose(true)
in.escPressed = true // 暂停/继续由屏幕状态机处理
}
case glfw.Key1, glfw.Key2, glfw.Key3, glfw.Key4, glfw.Key5, glfw.Key6, glfw.Key7, glfw.Key8, glfw.Key9:
if action == glfw.Press {
@@ -78,6 +84,9 @@ func (in *inputState) mouseButtonCallback(_ *glfw.Window, button glfw.MouseButto
case glfw.MouseButtonLeft:
if action == glfw.Press {
in.breakDown = true
in.clicked = true
in.clickX = float32(in.cursorX)
in.clickY = float32(in.cursorY)
}
in.breakHeld = action != glfw.Release
case glfw.MouseButtonRight:
@@ -89,6 +98,7 @@ func (in *inputState) mouseButtonCallback(_ *glfw.Window, button glfw.MouseButto
// cursorCallback 鼠标移动:yaw/pitch 累积(渲染.md §2 主线程消费)。
func (in *inputState) cursorCallback(_ *glfw.Window, x, y float64) {
in.cursorX, in.cursorY = x, y
if in.firstMouse {
in.lastX, in.lastY = x, y
in.firstMouse = false