Call.textInput (#8355)
* Update Menus.java
* Update EventType.java
* Update UI.java
* WHY
* WHY x2
* fix
* 💀
This commit is contained in:
@@ -12,6 +12,7 @@ import static mindustry.Vars.*;
|
||||
/** Class for handling menus and notifications across the network. Unstable API! */
|
||||
public class Menus{
|
||||
private static final Seq<MenuListener> menuListeners = new Seq<>();
|
||||
private static final Seq<TextInputListener> textInputListeners = new Seq<>();
|
||||
|
||||
/** Register a *global* menu listener. If no option is chosen, the option is returned as -1. */
|
||||
public static int registerMenu(MenuListener listener){
|
||||
@@ -19,6 +20,12 @@ public class Menus{
|
||||
return menuListeners.size - 1;
|
||||
}
|
||||
|
||||
/** Register a *global* text input listener. If no text is provided, the text is returned as null. */
|
||||
public static int registerTextInput(TextInputListener listener){
|
||||
textInputListeners.add(listener);
|
||||
return textInputListeners.size - 1;
|
||||
}
|
||||
|
||||
//do not invoke any of the methods below directly, use Call
|
||||
|
||||
@Remote(variants = Variant.both)
|
||||
@@ -39,6 +46,27 @@ 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 = "";
|
||||
|
||||
ui.showTextInput(title, message, textLength, def, numeric, (text) -> {
|
||||
Call.textInputResult(player, textInputId, text);
|
||||
}, () -> {
|
||||
Call.textInputResult(player, textInputId, null);
|
||||
});
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.both)
|
||||
public static void textInputResult(@Nullable Player player, int textInputId, @Nullable String text){
|
||||
if(player != null){
|
||||
Events.fire(new TextInputEvent(player, textInputId, text));
|
||||
if(textInputId >= 0 && textInputId < textInputListeners.size){
|
||||
textInputListeners.get(textInputId).get(player, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
public static void setHudText(String message){
|
||||
if(message == null) return;
|
||||
@@ -130,4 +158,8 @@ public class Menus{
|
||||
public interface MenuListener{
|
||||
void get(Player player, int option);
|
||||
}
|
||||
|
||||
public interface TextInputListener{
|
||||
void get(Player player, @Nullable String text);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user