From 02108cfa870afbb79f64481ac508920c916bd3f0 Mon Sep 17 00:00:00 2001 From: thecodershome Date: Thu, 17 Feb 2022 18:16:07 -0500 Subject: [PATCH] Allow double escape from production filter input to close Production panel. This resolves issue where escape won't close Production panel without clicking someplace else. pressing escape immediately after pressing Enter or ESC from the filer input would require clicking into the panel or mouse clicking the X close. Additionally pressing ESC will always unfocus the input. --- BetterStats/BetterStats.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/BetterStats/BetterStats.cs b/BetterStats/BetterStats.cs index 9f75253..15eba13 100644 --- a/BetterStats/BetterStats.cs +++ b/BetterStats/BetterStats.cs @@ -6,6 +6,7 @@ using UnityEngine; using UnityEngine.UI; using System.Globalization; +using UnityEngine.EventSystems; namespace BetterStats { @@ -440,10 +441,24 @@ public static void UIStatisticsWindow__OnOpen_Postfix(UIStatisticsWindow __insta _inputField.onValueChanged.AddListener((string value) => { - filterStr = value; + if (_inputField.wasCanceled) + { + // When escape key is pressed keep the current value. The default behavior was to reset/restore value to the previous submitted text + _inputField.text = filterStr; + } + else + { + filterStr = value; + } __instance.ComputeDisplayEntries(); }); + _inputField.onEndEdit.AddListener((string value) => + { + // Reset focus to allow pressing escape key to close production panel after entering value into filter inputField + EventSystem.current.SetSelectedGameObject(null); + }); + chxGO.transform.SetParent(__instance.productSortBox.transform.parent, false); txtGO.transform.SetParent(chxGO.transform, false); filterGO.transform.SetParent(__instance.productSortBox.transform.parent, false);