New mobile text dialog / Cleanup / Minimap fix / Collision optimization

This commit is contained in:
Anuken
2018-11-17 11:13:59 -05:00
parent d6661da0a7
commit afec65eb56
14 changed files with 41 additions and 436 deletions

View File

@@ -27,7 +27,6 @@ import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.ui.dialogs.FileChooser;
import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.scene.ui.TextField;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Strings;
@@ -52,11 +51,6 @@ public class AndroidLauncher extends PatchedAndroidApplication{
config.useImmersiveMode = true;
Platform.instance = new Platform(){
@Override
public void addDialog(TextField field, int length){
TextFieldDialogListener.add(field, 0, length);
}
@Override
public void openDonations(){
showDonations();

View File

@@ -1,119 +0,0 @@
package io.anuke.mindustry;
import android.app.Activity;
import android.app.AlertDialog;
import android.text.InputFilter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.EditText;
import com.badlogic.gdx.Gdx;
public class AndroidTextFieldDialog{
private Activity activity;
private EditText userInput;
private AlertDialog.Builder builder;
private TextPromptListener listener;
private boolean isBuild;
public AndroidTextFieldDialog(){
this.activity = (Activity) Gdx.app;
load();
}
public AndroidTextFieldDialog show(){
activity.runOnUiThread(() -> {
AlertDialog dialog = builder.create();
dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
});
return this;
}
private AndroidTextFieldDialog load(){
activity.runOnUiThread(() -> {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
LayoutInflater li = LayoutInflater.from(activity);
View promptsView = li.inflate(getResourceId("gdxdialogs_inputtext", "layout"), null);
alertDialogBuilder.setView(promptsView);
userInput = promptsView.findViewById(getResourceId("gdxDialogsEditTextInput", "id"));
alertDialogBuilder.setCancelable(false);
builder = alertDialogBuilder;
isBuild = true;
});
// Wait till TextPrompt is built.
while(!isBuild){
try{
Thread.sleep(10);
}catch(InterruptedException ignored){
}
}
return this;
}
public int getResourceId(String pVariableName, String pVariableType){
try{
return activity.getResources().getIdentifier(pVariableName, pVariableType, activity.getPackageName());
}catch(Exception e){
Gdx.app.error("Android Dialogs", "Cannot find resouce with name: " + pVariableName
+ " Did you copy the layouts to /res/layouts and /res/layouts_v14 ?");
e.printStackTrace();
return -1;
}
}
public AndroidTextFieldDialog setText(CharSequence value){
userInput.append(value);
return this;
}
public AndroidTextFieldDialog setCancelButtonLabel(CharSequence label){
builder.setNegativeButton(label, (dialog, id) -> dialog.cancel());
return this;
}
public AndroidTextFieldDialog setConfirmButtonLabel(CharSequence label){
builder.setPositiveButton(label, (dialog, id) -> {
if(listener != null && !userInput.getText().toString().isEmpty()){
listener.confirm(userInput.getText().toString());
}
});
return this;
}
public AndroidTextFieldDialog setTextPromptListener(TextPromptListener listener){
this.listener = listener;
return this;
}
public AndroidTextFieldDialog setInputType(int type){
userInput.setInputType(type);
return this;
}
public AndroidTextFieldDialog setMaxLength(int length){
userInput.setFilters(new InputFilter[]{new InputFilter.LengthFilter(length)});
return this;
}
public interface TextPromptListener{
void confirm(String text);
}
}

View File

@@ -1,68 +0,0 @@
package io.anuke.mindustry;
import android.text.InputType;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import io.anuke.ucore.scene.event.ChangeListener;
import io.anuke.ucore.scene.event.ClickListener;
import io.anuke.ucore.scene.event.InputEvent;
import io.anuke.ucore.scene.event.InputListener;
import io.anuke.ucore.scene.ui.TextField;
public class TextFieldDialogListener extends ClickListener{
private TextField field;
private int type;
private int max;
//type - 0 is text, 1 is numbers, 2 is decimals
public TextFieldDialogListener(TextField field, int type, int max){
this.field = field;
this.type = type;
this.max = max;
}
public static void add(TextField field, int type, int max){
field.addListener(new TextFieldDialogListener(field, type, max));
field.addListener(new InputListener(){
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
Gdx.input.setOnscreenKeyboardVisible(false);
return false;
}
});
}
public static void add(TextField field){
add(field, 0, 16);
}
public void clicked(final InputEvent event, float x, float y){
if(Gdx.app.getType() == ApplicationType.Desktop) return;
AndroidTextFieldDialog dialog = new AndroidTextFieldDialog();
dialog.setTextPromptListener(text ->
Gdx.app.postRunnable(() -> {
field.clearText();
field.appendText(text);
field.fire(new ChangeListener.ChangeEvent());
Gdx.graphics.requestRendering();
}));
if(type == 0){
dialog.setInputType(InputType.TYPE_CLASS_TEXT);
}else if(type == 1){
dialog.setInputType(InputType.TYPE_CLASS_NUMBER);
}else if(type == 2){
dialog.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
}
dialog.setConfirmButtonLabel("OK").setText(field.getText());
dialog.setCancelButtonLabel("Cancel");
dialog.setMaxLength(max);
dialog.show();
event.cancel();
}
}