mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-18 15:21:50 -08:00
New mobile text dialog / Cleanup / Minimap fix / Collision optimization
This commit is contained in:
parent
d6661da0a7
commit
afec65eb56
14 changed files with 41 additions and 436 deletions
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout_root"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/gdxDialogsEditTextInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
>
|
||||
|
||||
<requestFocus />
|
||||
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ allprojects {
|
|||
appName = 'Mindustry'
|
||||
gdxVersion = '1.9.9'
|
||||
roboVMVersion = '2.3.0'
|
||||
uCoreVersion = 'b276342625ac843932266aff194b9d4f5c26707b'
|
||||
uCoreVersion = 'c93c55179ec05b44926d59c5878534a3177d804f'
|
||||
|
||||
getVersionString = {
|
||||
String buildVersion = getBuildVersion()
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ public class Blocks extends BlockList implements ContentList{
|
|||
}
|
||||
};
|
||||
|
||||
//Registers build blocks from size 1-6
|
||||
//no reference is needed here since they can be looked up by name later
|
||||
for(int i = 1; i <= 6; i++){
|
||||
new BuildBlock("build" + i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,12 +218,6 @@ public class Logic extends Module{
|
|||
if(group.isEmpty()) continue;
|
||||
|
||||
EntityQuery.collideGroups(bulletGroup, group);
|
||||
EntityQuery.collideGroups(group, playerGroup);
|
||||
|
||||
for(EntityGroup other : unitGroups){
|
||||
if(other.isEmpty()) continue;
|
||||
EntityQuery.collideGroups(group, other);
|
||||
}
|
||||
}
|
||||
|
||||
EntityQuery.collideGroups(bulletGroup, playerGroup);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,21 @@
|
|||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.scene.ui.Dialog;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static io.anuke.mindustry.Vars.mobile;
|
||||
|
||||
public abstract class Platform {
|
||||
/**Each separate game platform should set this instance to their own implementation.*/
|
||||
public static Platform instance = new Platform() {};
|
||||
|
|
@ -17,7 +25,34 @@ public abstract class Platform {
|
|||
addDialog(field, 16);
|
||||
}
|
||||
/**See addDialog().*/
|
||||
public void addDialog(TextField field, int maxLength){}
|
||||
public void addDialog(TextField field, int maxLength){
|
||||
if(!mobile) return; //this is mobile only, desktop doesn't need dialogs
|
||||
|
||||
field.tapped(() -> {
|
||||
Log.info("yappd");
|
||||
Dialog dialog = new Dialog("", "dialog");
|
||||
dialog.setFillParent(true);
|
||||
dialog.content().top();
|
||||
dialog.content().defaults().height(65f);
|
||||
TextField to = dialog.content().addField(field.getText(), t-> {}).pad(15).width(250f).get();
|
||||
to.setMaxLength(maxLength);
|
||||
to.keyDown(Keys.ENTER, () -> dialog.content().find("okb").fireClick());
|
||||
dialog.content().addButton("$text.ok", () -> {
|
||||
field.clearText();
|
||||
field.appendText(to.getText());
|
||||
field.change();
|
||||
dialog.hide();
|
||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||
}).width(90f).name("okb");
|
||||
|
||||
dialog.show();
|
||||
Timers.runTask(1f, () -> {
|
||||
to.setCursorPosition(to.getText().length());
|
||||
Core.scene.setKeyboardFocus(to);
|
||||
Gdx.input.setOnscreenKeyboardVisible(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**Update discord RPC.*/
|
||||
public void updateRPC(){}
|
||||
/**Called when the game is exited.*/
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public class MinimapRenderer implements Disposable{
|
|||
for(Unit unit : units){
|
||||
float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y) / rect.width * h;
|
||||
Draw.color(unit.getTeam().color);
|
||||
Draw.rect("white", x + rx, y + ry, w / (sz * 2), h / (sz * 2));
|
||||
Draw.crect(Draw.getBlankRegion(), x + rx, y + ry, w / (sz * 2), h / (sz * 2));
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
package io.anuke.mindustry.maps.generation.pathfinding;
|
||||
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
|
||||
public class FlowPathFinder extends TilePathfinder{
|
||||
protected float[][] weights;
|
||||
|
||||
public FlowPathFinder(Tile[][] tiles){
|
||||
super(tiles);
|
||||
this.weights = new float[tiles.length][tiles[0].length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void search(Tile start, Tile end, Array<Tile> out){
|
||||
|
||||
}
|
||||
|
||||
public void search(Tile start, Predicate<Tile> result, Array<Tile> out){
|
||||
Queue<Tile> queue = new Queue<>();
|
||||
|
||||
for(int i = 0; i < weights.length; i++){
|
||||
for(int j = 0; j < weights[0].length; j++){
|
||||
if(result.test(tiles[i][j])){
|
||||
weights[i][j] = 100000;
|
||||
queue.addLast(tiles[i][j]);
|
||||
}else{
|
||||
weights[i][j] = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while(queue.size > 0){
|
||||
Tile tile = queue.first();
|
||||
for(GridPoint2 point : Geometry.d4){
|
||||
int nx = tile.x + point.x, ny = tile.y + point.y;
|
||||
if(inBounds(nx, ny) && weights[nx][ny] < weights[tile.x][tile.y] - 1f && tiles[nx][ny].passable()){
|
||||
weights[nx][ny] = weights[tile.x][tile.y] - 1;
|
||||
queue.addLast(tiles[nx][ny]);
|
||||
if(result.test(tiles[nx][ny])){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.add(start);
|
||||
while(true){
|
||||
Tile tile = out.peek();
|
||||
|
||||
Tile max = null;
|
||||
float maxf = weights[tile.x][tile.y];
|
||||
for(GridPoint2 point : Geometry.d4){
|
||||
int nx = tile.x + point.x, ny = tile.y + point.y;
|
||||
if(inBounds(nx, ny) && (weights[nx][ny] > maxf)){
|
||||
max = tiles[nx][ny];
|
||||
maxf = weights[nx][ny];
|
||||
|
||||
if(MathUtils.isEqual(maxf, 100000)){
|
||||
out.add(max);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(max == null){
|
||||
break;
|
||||
}
|
||||
out.add(max);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package io.anuke.mindustry.maps.generation.pathfinding;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.util.Structs;
|
||||
|
||||
public abstract class TilePathfinder{
|
||||
protected Tile[][] tiles;
|
||||
|
||||
public TilePathfinder(Tile[][] tiles){
|
||||
this.tiles = tiles;
|
||||
}
|
||||
|
||||
protected boolean inBounds(int x, int y){
|
||||
return Structs.inBounds(x, y, tiles);
|
||||
}
|
||||
|
||||
public abstract void search(Tile start, Tile end, Array<Tile> out);
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ public class UnitFactory extends Block{
|
|||
if(!Net.client()){
|
||||
BaseUnit unit = factory.type.create(tile.getTeam());
|
||||
unit.setSpawner(tile);
|
||||
unit.set(tile.drawx(), tile.drawy());
|
||||
unit.set(tile.drawx() + Mathf.range(4), tile.drawy() + Mathf.range(4));
|
||||
unit.add();
|
||||
unit.getVelocity().y = factory.launchVelocity;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import io.anuke.mindustry.core.Platform;
|
|||
import io.anuke.mindustry.game.Saves.SaveSlot;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
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;
|
||||
|
|
@ -40,16 +39,6 @@ public class IOSLauncher extends IOSApplication.Delegate {
|
|||
|
||||
Platform.instance = new Platform() {
|
||||
|
||||
@Override
|
||||
public void addDialog(TextField field) {
|
||||
TextFieldDialogListener.add(field, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDialog(TextField field, int maxLength) {
|
||||
TextFieldDialogListener.add(field, maxLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shareFile(FileHandle file){
|
||||
FileHandle to = Gdx.files.absolute(getDocumentsDirectory()).child(file.name());
|
||||
|
|
|
|||
|
|
@ -1,105 +0,0 @@
|
|||
package io.anuke.mindustry;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
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;
|
||||
import org.robovm.apple.foundation.NSRange;
|
||||
import org.robovm.apple.uikit.*;
|
||||
import org.robovm.rt.bro.annotation.ByVal;
|
||||
|
||||
public class TextFieldDialogListener {
|
||||
|
||||
public static void add(TextField field, int maxLength){
|
||||
field.addListener(new ClickListener(){
|
||||
public void clicked(final InputEvent event, float x, float y){
|
||||
show(field, maxLength);
|
||||
event.cancel();
|
||||
}
|
||||
});
|
||||
field.addListener(new InputListener(){
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static void show(TextField field, int maxLength){
|
||||
|
||||
UIAlertViewDelegateAdapter delegate = new UIAlertViewDelegateAdapter() {
|
||||
|
||||
@Override
|
||||
public void didDismiss(UIAlertView alertView, long buttonIndex) {
|
||||
if (buttonIndex == 1) {
|
||||
UITextField textField = alertView.getTextField(0);
|
||||
final String result = textField.getText();
|
||||
|
||||
Gdx.app.postRunnable(() -> {
|
||||
field.setText(result);
|
||||
field.change();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked(UIAlertView alertView, long buttonIndex) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel(UIAlertView alertView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void willPresent(UIAlertView alertView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didPresent(UIAlertView alertView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void willDismiss(UIAlertView alertView, long buttonIndex) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldEnableFirstOtherButton(UIAlertView alertView) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
String[] otherButtons = new String[1];
|
||||
otherButtons[0] = "OK";
|
||||
|
||||
UIAlertView alertView = new UIAlertView("", "", delegate, "Cancel", otherButtons);
|
||||
|
||||
alertView.setAlertViewStyle(UIAlertViewStyle.PlainTextInput);
|
||||
|
||||
UITextField uiTextField = alertView.getTextField(0);
|
||||
uiTextField.setText(field.getText());
|
||||
|
||||
uiTextField.setDelegate(new UITextFieldDelegateAdapter() {
|
||||
@Override
|
||||
public boolean shouldChangeCharacters(UITextField textField, @ByVal NSRange nsRange, String additionalText) {
|
||||
|
||||
if (textField.getText().length() + additionalText.length() > maxLength) {
|
||||
String oldText = textField.getText();
|
||||
String newText = oldText + additionalText;
|
||||
textField.setText(newText.substring(0, maxLength));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
alertView.show();
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue