From 338cf383f4dfb8acdb69480ee4f6e55d79f0255a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 22 Apr 2021 19:40:14 +0200 Subject: [PATCH] removed RequiresOnScreenKeyboard --- MLEM.Ui/Elements/TextField.cs | 16 +++++++--------- MLEM/Misc/TextInputWrapper.cs | 35 +++++++++++++++-------------------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/MLEM.Ui/Elements/TextField.cs b/MLEM.Ui/Elements/TextField.cs index 64b5976..0c6565a 100644 --- a/MLEM.Ui/Elements/TextField.cs +++ b/MLEM.Ui/Elements/TextField.cs @@ -17,7 +17,7 @@ namespace MLEM.Ui.Elements { /// /// A text field element for use inside of a . /// A text field is a selectable element that can be typed in, as well as copied and pasted from. - /// If is enabled, then this text field will automatically open an on-screen keyboard when pressed using MonoGame's KeyboardInput class. + /// If an on-screen keyboard is required, then this text field will automatically open an on-screen keyboard using /// public class TextField : Element { @@ -142,14 +142,12 @@ namespace MLEM.Ui.Elements { this.Font.Set(font); TextInputWrapper.EnsureExists(); - if (TextInputWrapper.Current.RequiresOnScreenKeyboard) { - this.OnPressed += async e => { - var title = this.MobileTitle ?? this.PlaceholderText; - var result = await TextInputWrapper.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false); - if (result != null) - this.SetText(result.Replace('\n', ' '), true); - }; - } + this.OnPressed += async e => { + var title = this.MobileTitle ?? this.PlaceholderText; + var result = await TextInputWrapper.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false); + if (result != null) + this.SetText(result.Replace('\n', ' '), true); + }; this.OnTextInput += (element, key, character) => { if (!this.IsSelected || this.IsHidden) return; diff --git a/MLEM/Misc/TextInputWrapper.cs b/MLEM/Misc/TextInputWrapper.cs index a7fb3f1..bb80f0c 100644 --- a/MLEM/Misc/TextInputWrapper.cs +++ b/MLEM/Misc/TextInputWrapper.cs @@ -21,24 +21,16 @@ namespace MLEM.Misc { /// public static TextInputWrapper Current; - /// - /// Determines if this text input wrapper requires an on-screen keyboard. - /// - public abstract bool RequiresOnScreenKeyboard { get; } - /// /// Opens the on-screen keyboard for this text input wrapper. - /// Note that, if is false, this method should not be called. + /// Note that, if no on-screen keyboard is required, a null string should be returned. /// /// Title of the dialog box. /// Description of the dialog box. /// Default text displayed in the input area. /// If password mode is enabled, the characters entered are not displayed. /// Text entered by the player. Null if back was used. - /// Thrown if there is no on-screen keyboard to open, or when is false - public virtual Task OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) { - throw new InvalidOperationException(); - } + public abstract Task OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode); /// /// Adds a text input listener to this text input wrapper. @@ -78,9 +70,6 @@ namespace MLEM.Misc { /// public class DesktopGl : TextInputWrapper { - /// - public override bool RequiresOnScreenKeyboard => false; - private FieldInfo key; private FieldInfo character; private readonly Action> addListener; @@ -93,6 +82,11 @@ namespace MLEM.Misc { this.addListener = addListener; } + /// + public override Task OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) { + return Task.FromResult(null); + } + /// public override void AddListener(GameWindow window, TextInputCallback callback) { this.addListener(window, (sender, args) => { @@ -118,9 +112,6 @@ namespace MLEM.Misc { /// public class Mobile : TextInputWrapper { - /// - public override bool RequiresOnScreenKeyboard => true; - private readonly OpenOnScreenKeyboardDelegate openOnScreenKeyboard; /// @@ -159,7 +150,9 @@ namespace MLEM.Misc { public class None : TextInputWrapper { /// - public override bool RequiresOnScreenKeyboard => false; + public override Task OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) { + return Task.FromResult(null); + } /// public override void AddListener(GameWindow window, TextInputCallback callback) { @@ -175,9 +168,6 @@ namespace MLEM.Misc { /// public class Primitive : TextInputWrapper { - /// - public override bool RequiresOnScreenKeyboard => false; - private TextInputCallback callback; /// @@ -194,6 +184,11 @@ namespace MLEM.Misc { } } + /// + public override Task OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) { + return Task.FromResult(null); + } + /// public override void AddListener(GameWindow window, TextInputCallback callback) { this.callback += callback;