Преглед изворни кода

【更改】移除限制提示仅保留按钮置灰

删去悬停提示以减少维护:移除 OneShotText、LocaleSelector 及其单测,
PlayButtonStatePatch 仅在限制生效时置原生 Interactable=false,
不再调用 SetDisabledTooltip;同步更新 README 与原理文档。
PJ568 пре 1 месец
родитељ
комит
6e9c225b43

+ 2 - 4
README.md

@@ -11,13 +11,12 @@
 - **会话级限制**:以“本次 SPT 进程”为单位,进入过一次战局或藏身处后不再允许开始新战局。
 - **可开关**:在配置中随时启用/关闭限制。
 - **可重置**:无需重启,在配置里勾选一次性重置项即可清除“已进过局”标记。
-- **本地化提示**:根据系统区域自动选择中/英文案。
 
 ## 机制
 
 - **会话级**:标记只存于内存,SPT 进程结束后自然消失,重启即恢复。
 - **触发条件**:成功进入过至少一次战局或藏身处(判定钩子见 `docs/principle.md`)。
-- **被禁入口**:在已有标记时,主菜单的“开始战局”与“重连”入口会被置灰并显示提示(仅前端限制,见“已知限制”);藏身处入口不受限,仍可进入。
+- **被禁入口**:在已有标记时,主菜单的“开始战局”与“重连”入口会被置灰、不可点击,不显示提示(仅前端限制,见“已知限制”);藏身处入口不受限,仍可进入。
 
 ## 安装
 
@@ -71,13 +70,12 @@ Once a raid (or the hideout) has been entered, the plugin blocks starting anothe
 - **Session-scoped**: the flag lives in memory for the SPT process; entering a raid or the hideout blocks further raid starts until restart.
 - **Toggleable**: enable/disable the restriction from config at any time.
 - **Resettable**: clear the "entered" flag from a one-shot config item without restarting.
-- **Localized message**: Chinese/English text chosen from the system locale.
 
 ## How it works
 
 - **Session-scoped**: the flag is in-memory only and disappears when the SPT process ends.
 - **Trigger**: at least one raid or hideout entry has succeeded (hook points in `docs/principle.md`).
-- **Blocked entry**: once flagged, the main-menu "Play" and "Reconnect" entries are greyed out with a tooltip (client-side only, see limitations); the hideout entry stays available.
+- **Blocked entry**: once flagged, the main-menu "Play" and "Reconnect" entries are greyed out and unclickable, with no tooltip (client-side only, see limitations); the hideout entry stays available.
 
 ## Installation
 

+ 2 - 4
docs/principle.md

@@ -23,8 +23,7 @@
 ## 拦截点:开始战局
 
 - **流程拦截**:`Patches/BlockStartPatch.cs` 以 `[HarmonyPrefix]` 挂钩 `EFT.MainMenuShowOperation.ShowScreen(EFT.UI.EMenuType screen, bool turnOn)`。当 `screen` 为 `Play`(0) 或 `Reconnect`(12) 且 `ShouldBlockStart(PluginConfig.Enabled.Value)` 为真时 `return false`,静默跳过整段界面切换;`Hideout`(11) 等其它界面一律放行,不弹窗。
-- **视图反馈**:`Patches/PlayButtonStatePatch.cs` 以 `[HarmonyPostfix]` 挂钩 `EFT.UI.MenuScreen.Show(Profile, MatchmakerPlayersController, ESessionMode)` 与 `MenuScreen.OnMatchingTypeUpdate`,在它们之后调用原生 `_playButton.SetDisabledTooltip(...)` 并置 `Interactable = false`:原生实现会把按钮 alpha 降到 0.3 且禁用点击,悬停显示提示。非限制态**不干预**按钮,交由游戏原生逻辑(如组队匹配禁用态)决定。
-- 文案取自 `OneShotText.Get(...)`,按 `LocalizationManager.Instance.Culture` 经 `LocaleSelector.Resolve` 选择中/英文。
+- **视图反馈**:`Patches/PlayButtonStatePatch.cs` 以 `[HarmonyPostfix]` 挂钩 `EFT.UI.MenuScreen.Show(Profile, MatchmakerPlayersController, ESessionMode)` 与 `MenuScreen.OnMatchingTypeUpdate`,在它们之后仅置 `_playButton.Interactable = false`:原生实现会把按钮 alpha 降到 0.3 且禁用点击,**不显示 tooltip**。非限制态**不干预**按钮,交由游戏原生逻辑(如组队匹配禁用态)决定。
 
 ## 复位
 
@@ -63,8 +62,7 @@ try to start raid   →  query (SessionGate.ShouldBlockStart)  →  block or all
 ## Interception: starting a raid
 
 - **Flow interception**: `Patches/BlockStartPatch.cs` hooks `EFT.MainMenuShowOperation.ShowScreen(EFT.UI.EMenuType screen, bool turnOn)` via `[HarmonyPrefix]`. When `screen` is `Play` (0) or `Reconnect` (12) and `ShouldBlockStart(PluginConfig.Enabled.Value)` is true, it returns `false` to silently skip the whole screen-switch flow; `Hideout` (11) and other screens pass through with no popup.
-- **View feedback**: `Patches/PlayButtonStatePatch.cs` hooks `EFT.UI.MenuScreen.Show(Profile, MatchmakerPlayersController, ESessionMode)` and `MenuScreen.OnMatchingTypeUpdate` via `[HarmonyPostfix]`, then calls native `_playButton.SetDisabledTooltip(...)` and sets `Interactable = false`: the native implementation dims the button to alpha 0.3, disables clicks, and shows the tooltip on hover. When not blocked it leaves the button untouched so native logic (e.g. group-match disabling) decides.
-- Text comes from `OneShotText.Get(...)`, selected by `LocalizationManager.Instance.Culture` via `LocaleSelector.Resolve`.
+- **View feedback**: `Patches/PlayButtonStatePatch.cs` hooks `EFT.UI.MenuScreen.Show(Profile, MatchmakerPlayersController, ESessionMode)` and `MenuScreen.OnMatchingTypeUpdate` via `[HarmonyPostfix]`, then only sets `Interactable = false`: the native implementation dims the button to alpha 0.3 and disables clicks, with **no tooltip**. When not blocked it leaves the button untouched so native logic (e.g. group-match disabling) decides.
 
 ## Reset
 

+ 0 - 24
src/OneShot.Core/LocaleSelector.cs

@@ -1,24 +0,0 @@
-namespace OneShot.Core
-{
-    /// <summary>
-    /// 根据 .NET 区域文化名选择文案语言。纯逻辑,无游戏/Unity 依赖。
-    /// Selects the message locale from a .NET culture name. Pure logic, no game/Unity dependency.
-    /// </summary>
-    public static class LocaleSelector
-    {
-        public const string English = "en";
-        public const string ChineseSimplified = "zh-CN";
-
-        /// <summary>
-        /// 归一化区域文化名:以 <c>zh</c> 开头者归为简体中文,其余归为英文,空值回退英文。
-        /// Normalizes a culture name: anything starting with <c>zh</c> maps to Simplified Chinese,
-        /// everything else maps to English, and empty values fall back to English.
-        /// </summary>
-        public static string Resolve(string culture)
-        {
-            if (string.IsNullOrWhiteSpace(culture)) return English;
-            if (culture.Trim().StartsWith("zh", System.StringComparison.OrdinalIgnoreCase)) return ChineseSimplified;
-            return English;
-        }
-    }
-}

+ 0 - 41
src/OneShot.Core/OneShotText.cs

@@ -1,41 +0,0 @@
-using System.Collections.Generic;
-
-namespace OneShot.Core
-{
-    /// <summary>
-    /// 内嵌本地化文案表。当前仅需展示一条“已被限制”提示,故不引入完整 i18n 框架。
-    /// Embedded localized strings. Only one "blocked" message is needed, so no full i18n framework is introduced.
-    /// </summary>
-    public static class OneShotText
-    {
-        /// <summary>“已被限制”提示的文案键。</summary>
-        public const string BlockedMessageKey = "oneshot/blocked_message";
-
-        private static readonly Dictionary<string, string> BlockedMessages = new Dictionary<string, string>
-        {
-            {
-                LocaleSelector.ChineseSimplified,
-                "本局 SPT 运行中你已进入过战局或藏身处,无法再开始游戏。重启 SPT 可重置。"
-            },
-            {
-                LocaleSelector.English,
-                "You have already entered a raid or the hideout during this SPT session, so you cannot start another raid. Restart SPT to reset."
-            },
-        };
-
-        /// <summary>
-        /// 按归一化语言返回“已被限制”提示;未知语言回退英文。
-        /// Returns the "blocked" message for a normalized locale; unknown locales fall back to English.
-        /// </summary>
-        public static string Get(string localeId)
-        {
-            string locale = LocaleSelector.Resolve(localeId);
-            if (BlockedMessages.TryGetValue(locale, out string message))
-            {
-                return message;
-            }
-
-            return BlockedMessages[LocaleSelector.English];
-        }
-    }
-}

+ 11 - 25
src/OneShot.Plugin/Patches/PlayButtonStatePatch.cs

@@ -3,17 +3,15 @@ using EFT;
 using EFT.UI;
 using EFT.UI.Matchmaker;
 using HarmonyLib;
-using OneShot.Core;
 
 namespace OneShot.Patches
 {
     /// <summary>
-    /// 主菜单“开始游戏”按钮状态补丁:限制生效时置灰并显示本地化悬停提示,未生效时不干预、交由游戏原生逻辑决定。
-    /// 仅通过原生 <see cref="DefaultUIButton.Interactable"/> 置灰(原生 alpha 0.3 且禁用点击),不自行改色、改布局或新建 UI。
-    /// Patches the main menu "play" button: greys it out with a localized tooltip while the restriction is
-    /// active, and leaves it untouched otherwise so native game logic decides. Greying only relies on the native
-    /// <see cref="DefaultUIButton.Interactable"/> (native alpha 0.3 and click disabled); no recoloring,
-    /// re-layout or new UI elements are introduced.
+    /// 主菜单“开始游戏”按钮状态补丁:限制生效时置灰,未生效时不干预、交由游戏原生逻辑决定。
+    /// 仅通过原生 <see cref="DefaultUIButton.Interactable"/> 置灰(原生 alpha 0.3 且禁用点击),不显示提示、不自行改色、改布局或新建 UI。
+    /// Patches the main menu "play" button: greys it out while the restriction is active, and leaves it untouched
+    /// otherwise so native game logic decides. Greying only relies on the native <see cref="DefaultUIButton.Interactable"/>
+    /// (native alpha 0.3 and click disabled); no tooltip, recoloring, re-layout or new UI elements are introduced.
     /// </summary>
     [HarmonyPatch(typeof(MenuScreen))]
     internal static class PlayButtonStatePatch
@@ -47,8 +45,8 @@ namespace OneShot.Patches
         }
 
         /// <summary>
-        /// 计算并施加“开始游戏”按钮状态:仅限制生效时置灰并挂提示,否则直接返回、不触碰按钮。幂等:重复调用不会叠加副作用。
-        /// Computes and applies the play button state: only greys it out with a tooltip when blocked, otherwise returns without
+        /// 计算并施加“开始游戏”按钮状态:仅限制生效时置灰,否则直接返回、不触碰按钮。幂等:重复调用不会叠加副作用。
+        /// Computes and applies the play button state: only greys it out when blocked, otherwise returns without
         /// touching the button. Idempotent: repeated calls accumulate no side effects.
         /// </summary>
         private static void ApplyState(MenuScreen menuScreen)
@@ -60,8 +58,8 @@ namespace OneShot.Patches
                 return;
             }
 
-            bool enabled = PluginConfig.Enabled != null && PluginConfig.Enabled.Value;
-            bool blocked = OneShotPlugin.Gate != null && OneShotPlugin.Gate.ShouldBlockStart(enabled);
+            bool blocked = PluginConfig.Enabled != null && PluginConfig.Enabled.Value
+                && OneShotPlugin.Gate != null && OneShotPlugin.Gate.ShouldBlockStart(true);
 
             if (!blocked)
             {
@@ -72,21 +70,9 @@ namespace OneShot.Patches
                 return;
             }
 
-            // 先登记禁用态悬停提示,再置灰;Interactable 的 setter 会据当前状态刷新提示。
-            // Register the disabled tooltip first, then grey out; the Interactable setter refreshes the tooltip for the new state.
-            menuScreen._playButton.SetDisabledTooltip(GetBlockedTooltip);
+            // 仅置灰,不挂提示;Interactable 的 setter 会据当前状态刷新按钮外观。
+            // Grey out only, no tooltip; the Interactable setter refreshes the button appearance for the new state.
             menuScreen._playButton.Interactable = false;
         }
-
-        /// <summary>
-        /// 读取游戏当前语言并返回“已被限制”的本地化提示;语言管理器缺失时回退英文。
-        /// Reads the current game culture and returns the localized "blocked" message; falls back to English when the localization manager is missing.
-        /// </summary>
-        private static string GetBlockedTooltip()
-        {
-            LocalizationManager manager = LocalizationManager.Instance;
-            string culture = manager == null ? null : manager.Culture;
-            return OneShotText.Get(LocaleSelector.Resolve(culture));
-        }
     }
 }

+ 0 - 49
tests/OneShot.Tests/LocaleSelectorTests.cs

@@ -1,49 +0,0 @@
-using OneShot.Core;
-using Xunit;
-
-namespace OneShot.Tests
-{
-    public class LocaleSelectorTests
-    {
-        [Theory]
-        [InlineData("zh-CN")]
-        [InlineData("zh-Hans")]
-        [InlineData("zh")]
-        public void Resolve_ChineseVariants_MapToChineseSimplified(string culture)
-        {
-            Assert.Equal(LocaleSelector.ChineseSimplified, LocaleSelector.Resolve(culture));
-        }
-
-        [Theory]
-        [InlineData("en-US")]
-        [InlineData("")]
-        [InlineData(null)]
-        public void Resolve_NonChineseOrEmpty_MapToEnglish(string culture)
-        {
-            Assert.Equal(LocaleSelector.English, LocaleSelector.Resolve(culture));
-        }
-
-        [Fact]
-        public void Get_Chinese_IsNonEmptyAndContainsChinese()
-        {
-            string message = OneShotText.Get(LocaleSelector.ChineseSimplified);
-
-            Assert.False(string.IsNullOrWhiteSpace(message));
-            Assert.Contains("战局", message);
-        }
-
-        [Fact]
-        public void Get_English_IsNonEmpty()
-        {
-            string message = OneShotText.Get(LocaleSelector.English);
-
-            Assert.False(string.IsNullOrWhiteSpace(message));
-        }
-
-        [Fact]
-        public void Get_UnknownLocale_FallsBackToEnglish()
-        {
-            Assert.Equal(OneShotText.Get(LocaleSelector.English), OneShotText.Get("fr"));
-        }
-    }
-}