Skip to content

[F] DisplayInTouch无法热开启:在游戏开始后再按键打开DisplayInTouch会无效,由于组件未被创建#123

Merged
clansty merged 1 commit intoMuNET-OSS:mainfrom
Starrah:fix-display-touch
Apr 4, 2026
Merged

[F] DisplayInTouch无法热开启:在游戏开始后再按键打开DisplayInTouch会无效,由于组件未被创建#123
clansty merged 1 commit intoMuNET-OSS:mainfrom
Starrah:fix-display-touch

Conversation

@Starrah
Copy link
Copy Markdown
Contributor

@Starrah Starrah commented Apr 4, 2026

之前版本代码中,CreateDisplay创建组件,是仅在GameProcess Onstart的时候,根据DisplayType的值,调用一次的。
导致如果游戏开始时玩家没有开启DisplayInTouch,那组件就不会被创建;游戏过程中按触发功能的按键,尽管DisplayType调成了1,但由于没有组件,所以还是显示不出来。

Summary by Sourcery

通过在功能被切换为开启时再创建显示器,而不是只在游戏开始时创建,确保游戏内触摸显示 UI 可以在游戏开始后动态启用。

Bug Fixes:

  • 修复了在游戏中途启用 DisplayInTouch 时不显示的问题,因为如果在游戏开始时被禁用,其 UI 组件从未被创建。

Enhancements:

  • 重构显示创建逻辑,使多部件显示类型(4 和 5)都能在 CreateDisplay 帮助方法中得到一致的处理。
Original summary in English

Summary by Sourcery

Ensure in-game touch display UI can be enabled dynamically after game start by creating the display when the feature is toggled on instead of only at game start.

Bug Fixes:

  • Fix DisplayInTouch not appearing when enabled mid-game because its UI components were never created if disabled at game start.

Enhancements:

  • Refactor display creation logic so multi-part display types (4 and 5) are consistently handled inside the CreateDisplay helper.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 4, 2026

审阅者指南(在小型 PR 中折叠)

审阅者指南

在游戏进行中,当中途开启该功能时,于 GameProcess.OnUpdate 中延迟创建 DisplayInTouch UI,并将显示类型拆分逻辑(类型 4/5)重构到 CreateDisplay 中,以便在非游戏开始阶段也能复用。

在 GameProcess.OnUpdate 期间延迟创建 DisplayInTouch 的时序图

sequenceDiagram
    actor Player
    participant InputSystem
    participant GameProcess
    participant DisplayTouchInGame
    participant GameMonitor0 as GameMonitor_0
    participant CanvasList0 as canvasGameObjects_0

    Player->>InputSystem: PressToggleDisplayInTouchKey
    InputSystem->>DisplayTouchInGame: Update displayType[0] to enabled

    loop Every frame
        GameProcess->>GameProcess: OnUpdate
        GameProcess-->>DisplayTouchInGame: OnGameProcessUpdate(____monitors)
        DisplayTouchInGame->>CanvasList0: Check Count
        alt Display just enabled and no canvas yet
            DisplayTouchInGame->>DisplayTouchInGame: CreateDisplay(displayType[0], ____monitors[0])
            DisplayTouchInGame->>GameMonitor0: Find Canvas/Sub and create UI
            DisplayTouchInGame->>CanvasList0: Add created GameObjects
        else Display already created or disabled
            DisplayTouchInGame->>CanvasList0: Iterate and update active state
        end
    end
Loading

DisplayTouchInGame 及相关方法的类图

classDiagram
    class GameProcess {
        +OnUpdate()
    }

    class GameMonitor {
        +gameObject
    }

    class GameObject {
        +transform
    }

    class Transform {
        +Find(path)
    }

    class DisplayTouchInGame {
        <<static>>
        -int[] displayType
        -List~GameObject~[] canvasGameObjects
        +OnMusicSelectProcessUpdate()
        +OnGameProcessUpdate(GameMonitor[] ____monitors)
        +OnGameStart(GameMonitor[] ____monitors)
        -CreateDisplay(int type, GameMonitor monitor)
    }

    GameProcess ..> DisplayTouchInGame : HarmonyPostfix_OnUpdate
    GameProcess --> GameMonitor : uses
    DisplayTouchInGame --> GameMonitor : uses
    DisplayTouchInGame --> GameObject : creates
    GameObject --> Transform : has
    Transform --> GameObject : returns
Loading

文件层面的修改

变更 详情 文件
确保在游玩过程中,当功能被切换为开启时按需创建 DisplayInTouch 画布,而不是仅在游戏开始时创建。
  • 修改 GameProcess.OnUpdate 的 Harmony postfix 签名以接收私有的 GameMonitor[] 字段,从而在更新时可以访问 monitors。
  • 在逐帧更新循环中,检测 displayType 表明功能已开启但尚未创建任何 canvasGameObjects 的情况,并在此时调用 CreateDisplay 来构建 UI。
  • 保留现有用于更新激活状态的 canvasGameObjects 循环,使新创建的画布能在同一帧内立刻被处理。
AquaMai.Mods/Utils/DisplayTouchInGame.cs
将显示类型拆分逻辑(针对类型 4 和 5)集中到 CreateDisplay 内部复用,而不是只在 GameStart 中处理。
  • OnGameStart 中移除对 displayType 值 4 和 5 的特殊处理,将其简化为在类型落入范围时始终调用 CreateDisplay(type, monitor)
  • 更新 CreateDisplay,使其在内部将类型 4 和 5 拆分为两次调用(先对类型 3,再对 type-3)之后,再执行对 1–3 范围的约束。
  • 保持 CreateDisplay 中的参数校验,对超出范围的基础类型抛出异常,以确保无效配置能尽早被发现。
AquaMai.Mods/Utils/DisplayTouchInGame.cs

技巧与命令

与 Sourcery 交互

  • 触发新的审阅: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 在某条审阅评论下回复,要求 Sourcery 从该评论创建一个 issue。你也可以直接回复 @sourcery-ai issue 来从该评论生成 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 摘要。也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可(重新)生成审阅者指南。
  • 一次解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。当你已经处理完所有评论且不想再看到它们时会很有用。
  • 一次忽略所有 Sourcery 审阅: 在 pull request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审阅。特别适合在你希望从一次全新的审阅开始时使用——别忘了再评论 @sourcery-ai review 来触发新的审阅!

自定义你的使用体验

访问你的 控制面板 来:

  • 启用或禁用诸如 Sourcery 自动生成的 pull request 摘要、审阅者指南等审阅功能。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds lazy creation of DisplayInTouch UI during GameProcess.OnUpdate when the feature is toggled on mid‑game, and refactors the display-type splitting logic (types 4/5) into CreateDisplay so it can be reused outside of game start.

Sequence diagram for lazy DisplayInTouch creation during GameProcess.OnUpdate

sequenceDiagram
    actor Player
    participant InputSystem
    participant GameProcess
    participant DisplayTouchInGame
    participant GameMonitor0 as GameMonitor_0
    participant CanvasList0 as canvasGameObjects_0

    Player->>InputSystem: PressToggleDisplayInTouchKey
    InputSystem->>DisplayTouchInGame: Update displayType[0] to enabled

    loop Every frame
        GameProcess->>GameProcess: OnUpdate
        GameProcess-->>DisplayTouchInGame: OnGameProcessUpdate(____monitors)
        DisplayTouchInGame->>CanvasList0: Check Count
        alt Display just enabled and no canvas yet
            DisplayTouchInGame->>DisplayTouchInGame: CreateDisplay(displayType[0], ____monitors[0])
            DisplayTouchInGame->>GameMonitor0: Find Canvas/Sub and create UI
            DisplayTouchInGame->>CanvasList0: Add created GameObjects
        else Display already created or disabled
            DisplayTouchInGame->>CanvasList0: Iterate and update active state
        end
    end
Loading

Class diagram for DisplayTouchInGame and related methods

classDiagram
    class GameProcess {
        +OnUpdate()
    }

    class GameMonitor {
        +gameObject
    }

    class GameObject {
        +transform
    }

    class Transform {
        +Find(path)
    }

    class DisplayTouchInGame {
        <<static>>
        -int[] displayType
        -List~GameObject~[] canvasGameObjects
        +OnMusicSelectProcessUpdate()
        +OnGameProcessUpdate(GameMonitor[] ____monitors)
        +OnGameStart(GameMonitor[] ____monitors)
        -CreateDisplay(int type, GameMonitor monitor)
    }

    GameProcess ..> DisplayTouchInGame : HarmonyPostfix_OnUpdate
    GameProcess --> GameMonitor : uses
    DisplayTouchInGame --> GameMonitor : uses
    DisplayTouchInGame --> GameObject : creates
    GameObject --> Transform : has
    Transform --> GameObject : returns
Loading

File-Level Changes

Change Details Files
Ensure DisplayInTouch canvases are created on-demand during gameplay when the feature is toggled on, not only at game start.
  • Change Harmony postfix signature for GameProcess.OnUpdate to accept the private GameMonitor[] field so monitors are available during updates.
  • In the per-frame update loop, detect cases where displayType indicates the feature is on but no canvasGameObjects have been created yet, and call CreateDisplay to build the UI at that moment.
  • Keep the existing loop that updates active canvasGameObjects, so newly created canvases will be picked up immediately in the same frame.
AquaMai.Mods/Utils/DisplayTouchInGame.cs
Centralize and reuse display-type decomposition logic (for types 4 and 5) inside CreateDisplay instead of GameStart-only handling.
  • Remove the special handling of displayType values 4 and 5 from OnGameStart, simplifying it to always call CreateDisplay(type, monitor) when the type is within range.
  • Update CreateDisplay to internally decompose types 4 and 5 into two calls (first for type 3, then for type-3) before enforcing the 1–3 range.
  • Keep the argument validation in CreateDisplay to throw for out-of-range base types, ensuring invalid configurations are caught early.
AquaMai.Mods/Utils/DisplayTouchInGame.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些高层次的反馈:

  • CreateDisplay 上方的注释仍然写着它只接受类型 1–3,并且类型 4/5 应该拆成两个调用,这已经和当前实现不一致了;建议更新这个注释,以准确描述新的行为和有效输入范围。
  • OnGameProcessUpdate 中,延迟调用的 CreateDisplay 只检查了 displayType[i] > 0,但现在 CreateDisplay 会在 1–5 之外的取值时抛出异常;这里最好和 OnGameStart 中使用的范围检查保持一致,或者以其他方式防止无效类型传入。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- The comment above `CreateDisplay` still says it only accepts types 1–3 and that 4/5 should be split into two calls, which no longer matches the implementation; consider updating this comment to accurately describe the new behavior and valid input range.
- In `OnGameProcessUpdate`, the lazy `CreateDisplay` call only checks `displayType[i] > 0`, but `CreateDisplay` will now throw for values outside 1–5; it may be safer to mirror the same range check used in `OnGameStart` or otherwise guard against invalid types there.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • The comment above CreateDisplay still says it only accepts types 1–3 and that 4/5 should be split into two calls, which no longer matches the implementation; consider updating this comment to accurately describe the new behavior and valid input range.
  • In OnGameProcessUpdate, the lazy CreateDisplay call only checks displayType[i] > 0, but CreateDisplay will now throw for values outside 1–5; it may be safer to mirror the same range check used in OnGameStart or otherwise guard against invalid types there.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The comment above `CreateDisplay` still says it only accepts types 1–3 and that 4/5 should be split into two calls, which no longer matches the implementation; consider updating this comment to accurately describe the new behavior and valid input range.
- In `OnGameProcessUpdate`, the lazy `CreateDisplay` call only checks `displayType[i] > 0`, but `CreateDisplay` will now throw for values outside 1–5; it may be safer to mirror the same range check used in `OnGameStart` or otherwise guard against invalid types there.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the DisplayTouchInGame utility to support dynamic display creation during game updates and refactors the CreateDisplay method to handle specific display types recursively. The review feedback suggests improving code readability by shortening a verbose comment and updating method documentation to accurately reflect the supported display types.

@Starrah Starrah force-pushed the fix-display-touch branch from 80f46e2 to 07f98a3 Compare April 4, 2026 09:41
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="AquaMai.Mods/Utils/DisplayTouchInGame.cs">

<violation number="1" location="AquaMai.Mods/Utils/DisplayTouchInGame.cs:91">
P1: Guard the hot-create path when `prefab` is still null. Right now this new branch bypasses the existing `OnGameStart` null check and can throw when the toggle key is pressed before `RegisterMouseTouchPanel` has initialized the prefab.</violation>

<violation number="2" location="AquaMai.Mods/Utils/DisplayTouchInGame.cs:132">
P3: The comment `// type 只能传入 1 2 3,如果是 4 或 5 的话,拆分成两个 call` is now stale. Since the recursive handling of types 4 and 5 has been moved into `CreateDisplay` itself, this method now accepts 1–5 directly. Update the comment to reflect the current behavior.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@Starrah Starrah force-pushed the fix-display-touch branch from 07f98a3 to aadf425 Compare April 4, 2026 09:47
@clansty clansty merged commit b086691 into MuNET-OSS:main Apr 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants