Add text input option allowing empty text (#9058)
* feat: Add option allowing empty text input * feat: Implement https://github.com/Anuken/Arc/pull/155 * chore: Add missing null checks in Menus
This commit is contained in:
@@ -270,8 +270,15 @@ public class UI implements ApplicationListener, Loadable{
|
||||
});
|
||||
}
|
||||
|
||||
public void showTextInput(String titleText, String text, int textLength, String def, boolean numbers, Cons<String> confirmed, Runnable closed){
|
||||
|
||||
public void showTextInput(String titleText, String text, int textLength, String def, boolean numbers, Cons<String> confirmed, Runnable closed) {
|
||||
showTextInput(titleText, text, textLength, def, numbers, false, confirmed, closed);
|
||||
}
|
||||
|
||||
public void showTextInput(String titleText, String text, int textLength, String def, boolean numbers, boolean allowEmpty, Cons<String> confirmed, Runnable closed){
|
||||
if(mobile){
|
||||
var description = text;
|
||||
var empty = allowEmpty;
|
||||
Core.input.getTextInput(new TextInput(){{
|
||||
this.title = (titleText.startsWith("@") ? Core.bundle.get(titleText.substring(1)) : titleText);
|
||||
this.text = def;
|
||||
@@ -279,7 +286,8 @@ public class UI implements ApplicationListener, Loadable{
|
||||
this.maxLength = textLength;
|
||||
this.accepted = confirmed;
|
||||
this.canceled = closed;
|
||||
this.allowEmpty = false;
|
||||
this.allowEmpty = empty;
|
||||
this.message = description;
|
||||
}});
|
||||
}else{
|
||||
new Dialog(titleText){{
|
||||
@@ -296,11 +304,11 @@ public class UI implements ApplicationListener, Loadable{
|
||||
buttons.button("@ok", () -> {
|
||||
confirmed.get(field.getText());
|
||||
hide();
|
||||
}).disabled(b -> field.getText().isEmpty());
|
||||
}).disabled(b -> !allowEmpty && field.getText().isEmpty());
|
||||
|
||||
keyDown(KeyCode.enter, () -> {
|
||||
String text = field.getText();
|
||||
if(!text.isEmpty()){
|
||||
if(allowEmpty || !text.isEmpty()){
|
||||
confirmed.get(text);
|
||||
hide();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class Menus{
|
||||
@Remote(variants = Variant.both)
|
||||
public static void menu(int menuId, String title, String message, String[][] options){
|
||||
if(title == null) title = "";
|
||||
if(message == null) message = "";
|
||||
if(options == null) options = new String[0][0];
|
||||
|
||||
ui.showMenu(title, message, options, (option) -> Call.menuChoose(player, menuId, option));
|
||||
@@ -39,6 +40,7 @@ public class Menus{
|
||||
@Remote(variants = Variant.both)
|
||||
public static void followUpMenu(int menuId, String title, String message, String[][] options){
|
||||
if(title == null) title = "";
|
||||
if(message == null) message = "";
|
||||
if(options == null) options = new String[0][0];
|
||||
|
||||
ui.showFollowUpMenu(menuId, title, message, options, (option) -> Call.menuChoose(player, menuId, option));
|
||||
@@ -61,9 +63,16 @@ public class Menus{
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
public static void textInput(int textInputId, String title, String message, int textLength, String def, boolean numeric){
|
||||
if(title == null) title = "";
|
||||
textInput(textInputId, title, message, textLength, def, numeric, false);
|
||||
}
|
||||
|
||||
ui.showTextInput(title, message, textLength, def, numeric, (text) -> {
|
||||
@Remote(variants = Variant.both)
|
||||
public static void textInput(int textInputId, String title, String message, int textLength, String def, boolean numeric, boolean allowEmpty){
|
||||
if(title == null) title = "";
|
||||
if(message == null) message = "";
|
||||
if(def == null) def = "";
|
||||
|
||||
ui.showTextInput(title, message, textLength, def, numeric, allowEmpty, (text) -> {
|
||||
Call.textInputResult(player, textInputId, text);
|
||||
}, () -> {
|
||||
Call.textInputResult(player, textInputId, null);
|
||||
|
||||
Reference in New Issue
Block a user