Skip to content

Commit

Permalink
Fix Escape to go back, input text bleed issue, Esc to unfocus UIFocus…
Browse files Browse the repository at this point in the history
…InputTextField

Fixes tModLoader#874 after tModLoader#3346 regression
  • Loading branch information
JavidPack committed May 23, 2024
1 parent 2079943 commit cb8a660
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@
text2 += PlayerInput.BuildCommand(Lang.misc[93].Value, false, PlayerInput.ProfileGamepadUI.KeyStatus["MouseRight"]);

if (flag3)
@@ -1486,8 +_,19 @@

cp3.OnSpecialInteracts += () => PlayerInput.BuildCommand(Lang.misc[53].Value, false, PlayerInput.ProfileGamepadUI.KeyStatus["MouseLeft"]) + PlayerInput.BuildCommand(Lang.misc[82].Value, false, PlayerInput.ProfileGamepadUI.KeyStatus["Inventory"]) + FancyUISpecialInstructions();
cp3.UpdateEvent += delegate {
+ bool flag11 = PlayerInput.Triggers.JustPressed.Inventory;
+ if (Main.inputTextEscape) {
+ Main.inputTextEscape = false;
+ flag11 = true;
+ }
+
+ if (CanExecuteInputCommand() && flag11)
+ FancyExit();
+
+ /* Above: Copied over Main.inputTextEscape bypass from MainMenu (1000) to FancyUI (1004) because tModLoader has some FancyUI/UIState menus that have text input.
if (CanExecuteInputCommand() && PlayerInput.Triggers.JustPressed.Inventory)
FancyExit();
+ */

UILinkPointNavigator.Shortcuts.BackButtonInUse = false;
};
@@ -1632,6 +_,12 @@
if (Main.MenuUI.CurrentState is IHaveBackButtonCommand haveBackButtonCommand)
haveBackButtonCommand.HandleBackButtonUsage();
Expand Down
8 changes: 8 additions & 0 deletions patches/tModLoader/Terraria/Main.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,14 @@
wallFrameCounter[144]++;
int num3 = 5;
int num4 = 10;
@@ -15815,6 +_,7 @@
}
}

+ /// <summary> Clears text input from any keys pressed since the last time <see cref="GetInputText"/> was called. Call when activating a menu with text input or focusing an element with text input to prevent keys pressed beforehand to be immediately captured as input. </summary>
public static void clrInput()
{
keyCount = 0;
@@ -15840,7 +_,8 @@
text = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ private void DownloadAllFilteredMods(UIMouseEvent @event, UIElement element)

public override void Draw(SpriteBatch spriteBatch)
{
// @TODO: Why this is done on Draw? (plus hard coded 101 :|)
UILinkPointNavigator.Shortcuts.BackButtonCommand = 101;
// @TODO: Why this is done on Draw?
UILinkPointNavigator.Shortcuts.BackButtonCommand = 7;

base.Draw(spriteBatch);
for (int i = 0; i < CategoryButtons.Count; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ protected override void DrawSelf(SpriteBatch spriteBatch)
GameInput.PlayerInput.WritingText = true;
Main.instance.HandleIME();
string newString = Main.GetInputText(CurrentString);
if (Main.inputTextEscape) {
Main.inputTextEscape = false;
Focused = false;
OnUnfocus?.Invoke(this, new EventArgs());
}
if (!newString.Equals(CurrentString)) {
CurrentString = newString;
OnTextChange?.Invoke(this, new EventArgs());
Expand Down
4 changes: 0 additions & 4 deletions patches/tModLoader/Terraria/ModLoader/UI/UIInputTextField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public UIInputTextField(string hintText)

protected override void DrawSelf(SpriteBatch spriteBatch)
{
// Note: This is a hacky solution that doesn't respect the actual KeyboardUI["Inventory"] keybind. Hopefully later Terraria updates handle allowing the inventory/back keybind to work properly in situations where text is being input
if (Main.keyState.IsKeyDown(Keys.Escape) && !Main.oldKeyState.IsKeyDown(Keys.Escape)) {
UILinksInitializer.FancyExit();
}
GameInput.PlayerInput.WritingText = true;
Main.instance.HandleIME();
string newString = Main.GetInputText(_currentString);
Expand Down
1 change: 1 addition & 0 deletions patches/tModLoader/Terraria/ModLoader/UI/UIModPacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public override void OnInitialize()
private static void SaveNewModList(UIMouseEvent evt, UIElement listeningElement)
{
SoundEngine.PlaySound(11);
Main.clrInput();
VirtualKeyboard.Text = "";
Main.MenuUI.SetState(VirtualKeyboard);
Main.menuMode = 888;
Expand Down
1 change: 1 addition & 0 deletions patches/tModLoader/Terraria/ModLoader/UI/UIModSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public override void Draw(SpriteBatch spriteBatch)
public override void OnActivate()
{
_cts = new CancellationTokenSource();
Main.clrInput();
ModCompile.UpdateReferencesFolder();
_uIPanel.Append(_uiLoader);
_modList.Clear();
Expand Down
8 changes: 4 additions & 4 deletions patches/tModLoader/Terraria/ModLoader/UI/UIMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public override void OnInitialize()
Top = { Pixels = -20 }
}.WithFadedMouseOver();

buttonB.OnLeftClick += BackClick;
buttonB.OnLeftClick += (_, _) => HandleBackButtonUsage();

uIElement.Append(buttonB);
buttonOMF = new UIAutoScaleTextTextPanel<LocalizedText>(Language.GetText("tModLoader.ModsOpenModsFolders"));
Expand Down Expand Up @@ -266,7 +266,7 @@ private void UpdateTopRowButtons()
uIElement.AddOrRemoveChild(buttonRM, ModCompile.DeveloperMode || !forceReloadHidden);
}

internal void BackClick(UIMouseEvent evt, UIElement listeningElement)
public void HandleBackButtonUsage()
{
// To prevent entering the game with Configs that violate ReloadRequired
if (ConfigManager.AnyModNeedsReload()) {
Expand All @@ -282,7 +282,7 @@ internal void BackClick(UIMouseEvent evt, UIElement listeningElement)

ConfigManager.OnChangedAll();

(this as IHaveBackButtonCommand).HandleBackButtonUsage();
IHaveBackButtonCommand.GoBackTo(PreviousUIState);
}

private void ReloadMods(UIMouseEvent evt, UIElement listeningElement)
Expand Down Expand Up @@ -375,7 +375,7 @@ public override void Update(GameTime gameTime)

public override void Draw(SpriteBatch spriteBatch)
{
UILinkPointNavigator.Shortcuts.BackButtonCommand = 102;
UILinkPointNavigator.Shortcuts.BackButtonCommand = 7;
base.Draw(spriteBatch);
for (int i = 0; i < _categoryButtons.Count; i++) {
if (_categoryButtons[i].IsMouseHovering) {
Expand Down

0 comments on commit cb8a660

Please sign in to comment.