Skip to content

为 SettingsV2 的各个开关添加快捷键绑定#114

Draft
Wind-DeterMination-backup wants to merge 8 commits intoTinyLake:mainfrom
Wind-DeterMination-backup:settingV2-update
Draft

为 SettingsV2 的各个开关添加快捷键绑定#114
Wind-DeterMination-backup wants to merge 8 commits intoTinyLake:mainfrom
Wind-DeterMination-backup:settingV2-update

Conversation

@Wind-DeterMination-backup
Copy link
Copy Markdown

@Wind-DeterMination-backup Wind-DeterMination-backup commented Mar 14, 2026

功能概述

这个 PR 为 SettingsV2 的布尔开关设置项新增了快捷键绑定能力,目标是让用户可以直接在设置界面中为开关项配置快捷键,而不需要再把这类状态切换逻辑硬编码到独立的全局按键里。

本次实现覆盖了以下用户侧行为:

  • 每个 SettingsV2 设置项右侧都显示一个快捷键 icon
  • CheckPref(布尔开关)支持真正的快捷键绑定
  • 非布尔设置项显示禁用占位 icon,避免 UI 行为不一致
  • 快捷键支持两种模式:togglehold
  • 点击设置行右侧 icon 后,直接复用现有 Controls 界面的多键/修饰键捕获逻辑
  • 已绑定的快捷键支持右键展开管理面板,用于切换模式和解绑

设计与实现说明

1. SettingsV2 层的实现

核心逻辑落在 src/mindustryX/features/SettingsV2.kt

  • CheckPref 增加了内部快捷键处理器 ShortcutHandler
  • 每个布尔设置项都会创建一个隐藏的 KeyBind
  • 快捷键模式单独持久化到 Core.settings,键名格式为 settingV2-shortcut-mode-<name>
  • 运行时通过 SettingsV2.pollShortcuts() 轮询这些绑定,并驱动对应设置项状态变化

hold 模式当前语义是“按住期间临时反转当前布尔值,松开后恢复原值”,而不是单纯“强制置 true”。这样对默认开启和默认关闭的开关都可用。

2. UI 层的实现

SettingsV2.Data.addTools() 现在统一插入快捷键工具位:

  • 基类 Data 默认提供禁用的快捷键 icon,提示“仅开关设置项支持快捷键”
  • CheckPref 重写 addShortcutTool(),提供可交互的快捷键按钮
  • 左键直接进入按键捕获
  • 右键打开快捷键面板,面板内可执行重新绑定、模式切换、解绑
  • 面板内标签、模式按钮、解绑按钮,以及设置列表上的快捷键按钮状态,都已做 UI 同步刷新,避免绑定后状态不更新

这样可以保证:

  • 设置页主列表与浮动设置面板行为一致
  • overlay 相关设置行不会因为工具栏扩展而失去右侧控制位
  • 非开关项仍然保持统一的行结构和视觉布局

3. KeybindDialog / 底层绑定复用

为了避免重新发明一套快捷键捕获逻辑,本次直接复用了 work/core/src/mindustry/ui/dialogs/KeybindDialog.java 的按键捕获流程,并做了几项底层扩展:

  • 抽出静态入口 showRebindDialog(...),让 SettingsV2 可以直接调用 Controls 的捕获逻辑
  • 增加 isCapturing(),在捕获期间暂停常规快捷键轮询,避免误触发功能
  • 将 SettingsV2 隐藏绑定从 Controls 列表中过滤掉
  • Controls 的“重置全部”只重置可见绑定,不再误清 SettingsV2 的隐藏绑定
  • 新绑定写入前会自动清掉冲突绑定,避免同一按键同时驱动多个逻辑
  • Escape 被保留为取消捕获,不允许作为可绑定快捷键,和提示文案保持一致

这些底层改动已经同步导出为 patch:

  • patches/client/0074-FC-SettingsV2-shortcut-capture-integration.patch
  • patches/client/0075-fix-reserve-escape-for-key-capture-cancel.patch
  • patches/client/0076-refactor-simplify-rebind-session-flow.patch

4. 主循环接入

src/mindustryX/Hooks.java 中新增了:

  • SettingsV2.INSTANCE.pollShortcuts();

这样设置项快捷键与原有 BindingExt.pollKeys() 一样,运行在客户端 update 流程中。

同时 src/mindustryX/features/BindingExt.kt 也增加了捕获期间短路:

  • KeybindDialog.isCapturing()true 时不处理常规功能快捷键

这保证了 SettingsV2 快捷键捕获与原有功能键系统不会互相干扰。

与 Gemini Review 相关的修正

这个 PR 在开发过程中多轮触发了 Gemini review,并已经把其中有价值的建议逐步落实到实现里,包括:

  • 去掉冗余的 shortcutBind.load()
  • 复用快捷键按钮样式,避免重复分配 ImageButtonStyle
  • hold 模式调整为“临时反转当前值”
  • 修复快捷键面板和设置列表按钮的 UI 响应性问题
  • 保留 Escape 作为捕获取消键,不允许绑定
  • 简化 RebindSession.rebind(...) 的参数结构
  • CheckPref 的快捷键逻辑内聚到 ShortcutHandler

验证

已执行的验证:

  • work\\gradlew.bat :core:compileJava
  • 多轮 Gemini review
  • 检查 SettingsV2 主列表、快捷键面板、Controls 捕获逻辑、隐藏绑定过滤、冲突清理、overlay 行结构兼容性

补充说明:当前仓库的 patchGeneratedSources / kapt 在增量构建下偶发出现生成目录脏状态,处理方式是清理 work/core/build 后重跑;这属于工作树构建环境问题,不是本次功能逻辑本身的回归。

@Wind-DeterMination-backup
Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the user experience by introducing customizable keyboard shortcuts for toggle settings in SettingsV2. Users can now assign keys to quickly switch settings or hold a key to temporarily activate them, streamlining gameplay and interaction with the game's features. The implementation carefully integrates with existing keybinding systems while keeping setting-specific shortcuts separate for better organization and conflict avoidance.

Highlights

  • Shortcut Bindings for SettingsV2 Toggles: Added the ability to assign keyboard shortcuts to toggle settings within SettingsV2, enhancing accessibility and user control.
  • Toggle and Hold Shortcut Modes: Implemented two distinct shortcut modes: 'toggle' for switching a setting on/off with a single press, and 'hold' for temporarily activating a setting while the key is pressed.
  • Hidden Keybind Persistence: Introduced a mechanism for per-setting keybind persistence that is hidden from the main controls list, ensuring these specific binds do not interfere with general keybind management.
  • KeybindDialog Integration and Refinement: Reused the existing KeybindDialog for capturing shortcut inputs and isolated the hidden setting binds to prevent them from being reset or displayed in the standard keybinds list.
  • Localization Support: Added new localization strings in both Chinese and English for all new shortcut-related UI elements and messages.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • assets/bundles/bundle-mdtx.properties
    • Added new localization keys for shortcut configuration, including labels for current shortcut, mode selection (toggle/hold), rebind, capture instructions, unset, unbind, and unsupported messages.
  • assets/bundles/bundle-mdtx_en.properties
    • Added new English localization keys for shortcut configuration, mirroring the Chinese additions for internationalization.
  • patches/client/0074-FC-SettingsV2-shortcut-capture-integration.patch
    • Introduced a patch to KeybindDialog.java to refactor keybinding logic, enabling support for hidden keybinds specific to SettingsV2. This includes modifying the rebind process, adding methods for clearing conflicting binds, and introducing a RebindSession class for managing the rebind dialog state.
  • src/mindustryX/Hooks.java
    • Integrated a call to SettingsV2.pollShortcuts() within the main update loop to continuously monitor and respond to custom setting shortcuts.
  • src/mindustryX/features/BindingExt.kt
    • Updated the pollKeys() method to include a check for KeybindDialog.isCapturing(), preventing general keybinds from being processed while a shortcut is being captured.
  • src/mindustryX/features/SettingsV2.kt
    • Implemented the core shortcut functionality for CheckPref settings, including defining ShortcutMode (toggle/hold), managing hidden KeyBind instances, and providing UI elements for binding, mode selection, and unbinding. Added pollShortcut() for runtime processing of these binds and isHiddenSettingKeybind() for filtering them from the main keybind list.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 introduces a valuable feature for adding shortcut bindings to toggleable settings, complete with 'toggle' and 'hold' modes. The implementation is robust, particularly the refactoring of KeybindDialog to support reusable key capture and the thoughtful design of the 'hold' functionality. The UI for managing these shortcuts is also user-friendly. I've identified a couple of minor areas for improvement in SettingsV2.kt related to performance and code simplification. Overall, this is a well-executed feature addition.

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 introduces a valuable feature for adding shortcut bindings to toggleable settings. The implementation is well-thought-out, particularly the refactoring of KeybindDialog for reusability and the comprehensive shortcut logic within SettingsV2.kt. The support for both 'toggle' and 'hold' modes is a great touch. I have a few suggestions to enhance code quality and performance.

@Wind-DeterMination-backup
Copy link
Copy Markdown
Author

/gemini review

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 introduces a great new feature for binding shortcuts to toggle settings, including both 'toggle' and 'hold' modes. The implementation is well-structured, with a thoughtful refactoring of KeybindDialog to make the key capture logic reusable and robust. I have one suggestion to make the 'hold' mode more versatile, but overall this is a high-quality contribution.

@Wind-DeterMination-backup
Copy link
Copy Markdown
Author

/gemini review

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 introduces a new feature to bind shortcuts to toggleable settings, with support for both "toggle" and "hold" modes. The implementation is well-structured, with keybinding logic for settings encapsulated within the CheckPref class. The changes to KeybindDialog are a significant improvement, refactoring the key capture logic into a reusable, self-contained RebindSession which is then leveraged for the new settings shortcuts. The overall implementation is solid, but I've identified a couple of UI reactivity issues in the new shortcut configuration panel where the UI state doesn't update automatically after changes are made. My review includes suggestions to fix these issues using update listeners to ensure a smoother user experience.

@Wind-DeterMination-backup
Copy link
Copy Markdown
Author

/gemini review

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 introduces a new feature allowing users to bind shortcuts to toggleable settings in SettingsV2. The implementation includes support for 'toggle' and 'hold' modes for shortcuts, with persistence for these settings. The changes also involve a significant and beneficial refactoring of the KeybindDialog to better encapsulate the key rebinding logic and to support hidden keybinds that don't appear in the main controls list. The overall implementation is robust and well-designed. I have one suggestion to improve the user experience during key capture.

@Wind-DeterMination-backup
Copy link
Copy Markdown
Author

/gemini review

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 introduces a well-implemented feature for binding shortcuts to toggle settings. The changes are comprehensive, including UI for configuration, persistence, and the core logic for handling 'toggle' and 'hold' modes. The refactoring of KeybindDialog is a significant improvement, making the keybinding functionality more modular and reusable. I have a couple of minor suggestions for code simplification and idiomatic style, but overall this is a great addition.

@Wind-DeterMination-backup
Copy link
Copy Markdown
Author

/gemini review

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 introduces a well-designed feature for binding shortcuts to toggleable settings. The implementation is robust, covering both 'toggle' and 'hold' modes with a thoughtful UI/UX for configuration. A significant part of this change involves refactoring the core KeybindDialog to be more extensible and reusable, which is a great improvement. The integration with the existing settings system is clean and correctly handles potential conflicts during key capture. I have one suggestion to improve the structure of the CheckPref class for better long-term maintainability.

@Wind-DeterMination-backup
Copy link
Copy Markdown
Author

/gemini review

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 introduces a new feature allowing users to bind keyboard shortcuts to toggleable settings in SettingsV2. It adds support for both 'toggle' and 'hold' modes for these shortcuts, persisting them per-setting. The implementation is well-designed, encapsulating the shortcut logic within the CheckPref class and its inner ShortcutHandler. A significant part of this PR is the refactoring of the core KeybindDialog to expose its key-capturing functionality in a reusable way, which is done cleanly through patch files. This refactoring also introduces a welcome improvement by clearing conflicting keybinds automatically. The code quality is high, and the feature is robustly implemented. I did not find any issues of medium or higher severity.

@Wind-DeterMination-backup
Copy link
Copy Markdown
Author

根据这几轮 Gemini review,这个 PR 已经做过一轮针对性清理,结论总结如下。

已采纳并已修改的建议:

  • 去掉了 shortcutBind.load() 的冗余调用,直接依赖 KeyBind.add() / 现有加载路径
  • 将快捷键按钮样式改为复用,避免每次构建设置行都新建 ImageButtonStyle
  • hold 模式从“按住强制启用”改成“按住临时反转当前值”,兼容默认开启和默认关闭两类开关
  • 修复了快捷键管理面板的 UI 响应性问题:绑定名、模式按钮、解绑按钮都会自动刷新
  • 修复了设置列表中快捷键 icon 的选中态刷新问题
  • 保留 Escape 作为按键捕获取消键,不再允许把 Esc 绑定为设置快捷键
  • 简化了 KeybindDialog.RebindSession.rebind(...) 的参数结构
  • CheckPref 中新增的快捷键逻辑收拢到了内部 ShortcutHandler,降低了 CheckPref 本体的耦合度

有意未继续修改的点:

  • 没有继续重写历史 patch 来把所有底层改动重新压缩进 0074;目前保留 follow-up patch 0075/0076,这样可以避免为了美化 patch 历史去改写已经推送的提交链
  • 没有再把 ShortcutHandler 继续拆成独立顶级类或跨文件模块;当前保持为 CheckPref 内部类,是为了直接访问外层设置状态,同时把 diff 控制在当前 PR 范围内
  • Gemini 还给过若干纯风格化建议(例如更偏个人偏好的写法选择),这类没有继续机械采纳;当前最新 review 结论已经是“未发现 medium 及以上严重度问题”

当前 PR 的状态是:功能问题、交互问题和中等级别以上 review 问题都已经处理完成,剩余主要是可选的代码风格层面讨论。

@Wind-DeterMination-backup Wind-DeterMination-backup marked this pull request as ready for review March 15, 2026 02:02
@Wind-DeterMination-backup Wind-DeterMination-backup changed the title feat: add shortcut bindings for SettingsV2 toggles 为 SettingsV2 的各个开关添加快捷键绑定 Mar 15, 2026
@Wind-DeterMination-backup Wind-DeterMination-backup marked this pull request as draft March 27, 2026 13:47
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.

1 participant