Finish all editor features
@ -6,6 +6,8 @@
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
22
android/res/layout-v14/gdxdialogs_inputtext.xml
Executable file
@ -0,0 +1,22 @@
|
||||
<?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"
|
||||
android:maxLength="15"
|
||||
>
|
||||
|
||||
<requestFocus />
|
||||
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
43
android/res/layout/gdxdialogs_inputtext.xml
Executable file
@ -0,0 +1,43 @@
|
||||
<?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" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gdxDialogsEnterTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
|
||||
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gdxDialogsEnterMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
|
||||
|
||||
/>
|
||||
|
||||
|
||||
<EditText
|
||||
android:id="@+id/gdxDialogsEditTextInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:maxLength="15"
|
||||
>
|
||||
|
||||
<requestFocus />
|
||||
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
@ -15,6 +15,7 @@ import android.os.Bundle;
|
||||
import android.telephony.TelephonyManager;
|
||||
import io.anuke.mindustry.io.PlatformFunction;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class AndroidLauncher extends AndroidApplication{
|
||||
@ -47,6 +48,11 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
Intent intent = new Intent( Intent.ACTION_VIEW, marketUri );
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDialog(TextField field){
|
||||
TextFieldDialogListener.add(field);
|
||||
}
|
||||
};
|
||||
|
||||
Mindustry.donationsCallable = new Callable(){ @Override public void run(){ showDonations(); } };
|
||||
|
135
android/src/io/anuke/mindustry/AndroidTextFieldDialog.java
Normal file
@ -0,0 +1,135 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.text.InputFilter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import android.widget.EditText;
|
||||
|
||||
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(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gdx.app.error("Android Dialogs", AndroidTextFieldDialog.class.getSimpleName() + " now shown.");
|
||||
AlertDialog dialog = builder.create();
|
||||
|
||||
dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private AndroidTextFieldDialog load() {
|
||||
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
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 = (EditText) 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 e) {
|
||||
}
|
||||
}
|
||||
|
||||
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, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setConfirmButtonLabel(CharSequence label) {
|
||||
builder.setPositiveButton(label, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int 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 static interface TextPromptListener{
|
||||
public void confirm(String text);
|
||||
}
|
||||
|
||||
}
|
71
android/src/io/anuke/mindustry/TextFieldDialogListener.java
Normal file
@ -0,0 +1,71 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
|
||||
import com.badlogic.gdx.Application.ApplicationType;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import android.text.InputType;
|
||||
import io.anuke.mindustry.AndroidTextFieldDialog.TextPromptListener;
|
||||
import io.anuke.ucore.scene.event.InputEvent;
|
||||
import io.anuke.ucore.scene.event.InputListener;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
import io.anuke.ucore.scene.utils.ChangeListener;
|
||||
import io.anuke.ucore.scene.utils.ClickListener;
|
||||
|
||||
public class TextFieldDialogListener extends ClickListener{
|
||||
private TextField field;
|
||||
private int type;
|
||||
private int 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, 15);
|
||||
}
|
||||
|
||||
//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 void clicked(final InputEvent event, float x, float y){
|
||||
|
||||
if(Gdx.app.getType() == ApplicationType.Desktop) return;
|
||||
|
||||
AndroidTextFieldDialog dialog = new AndroidTextFieldDialog();
|
||||
|
||||
dialog.setTextPromptListener(new TextPromptListener(){
|
||||
public void confirm(String text){
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
@ -79,7 +79,7 @@ project(":core") {
|
||||
apply plugin: "java"
|
||||
|
||||
dependencies {
|
||||
compile 'com.github.anuken:ucore:9c523c4'
|
||||
compile 'com.github.anuken:ucore:a525ad2043'
|
||||
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
|
||||
}
|
||||
|
BIN
core/assets-raw/sprites/ui/icon-file-text.png
Executable file
After Width: | Height: | Size: 199 B |
BIN
core/assets-raw/sprites/ui/icon-file.png
Normal file
After Width: | Height: | Size: 231 B |
BIN
core/assets-raw/sprites/ui/icon-folder-parent.png
Executable file
After Width: | Height: | Size: 231 B |
BIN
core/assets-raw/sprites/ui/icon-folder.png
Executable file
After Width: | Height: | Size: 214 B |
BIN
core/assets-raw/sprites/ui/icon-home.png
Executable file
After Width: | Height: | Size: 220 B |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 80 KiB |
@ -13,6 +13,7 @@ import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.modules.ModuleCore;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
|
||||
public class Mindustry extends ModuleCore {
|
||||
public static Callable donationsCallable;
|
||||
@ -22,6 +23,7 @@ public class Mindustry extends ModuleCore {
|
||||
@Override public String format(Date date){ return "invalid date"; }
|
||||
@Override public String format(int number){ return number + ""; }
|
||||
@Override public void openLink(String link){ }
|
||||
@Override public void addDialog(TextField field){}
|
||||
};
|
||||
|
||||
//always initialize blocks in this order, otherwise there are ID errors
|
||||
|
@ -23,6 +23,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.function.Listenable;
|
||||
import io.anuke.ucore.function.VisibilityProvider;
|
||||
import io.anuke.ucore.modules.SceneModule;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
@ -469,4 +470,16 @@ public class UI extends SceneModule{
|
||||
((HudFragment)hudfrag).updateItems();
|
||||
}
|
||||
|
||||
public void showConfirm(String title, String text, Listenable confirmed){
|
||||
FloatingDialog dialog = new FloatingDialog(title);
|
||||
dialog.content().add(text).pad(4f).units(Unit.dp);
|
||||
dialog.buttons().defaults().size(200f, 54f).pad(2f).units(Unit.dp);
|
||||
dialog.buttons().addButton("Cancel", dialog::hide);
|
||||
dialog.buttons().addButton("OK", () -> {
|
||||
dialog.hide();
|
||||
confirmed.listen();
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ public class AndroidInput extends InputHandler{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
enableHold = player.breakMode == PlaceMode.holdDelete;
|
||||
|
||||
if(enableHold && player.recipe != null && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.inPixels(50))
|
||||
&& !ui.hasMouse()){
|
||||
|
@ -82,7 +82,7 @@ public enum PlaceMode{
|
||||
holdDelete{
|
||||
{
|
||||
delete = true;
|
||||
shown = false;
|
||||
shown = true;
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
|
@ -2,8 +2,11 @@ package io.anuke.mindustry.io;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
|
||||
public interface PlatformFunction{
|
||||
public String format(Date date);
|
||||
public String format(int number);
|
||||
public void openLink(String link);
|
||||
public void addDialog(TextField field);
|
||||
}
|
||||
|
@ -12,11 +12,19 @@ import io.anuke.mindustry.world.ColorMapper;
|
||||
|
||||
public enum EditorTool{
|
||||
pencil{
|
||||
{
|
||||
edit = true;
|
||||
}
|
||||
|
||||
public void touched(MapEditor editor, int x, int y){
|
||||
editor.draw(x, y);
|
||||
}
|
||||
},
|
||||
fill{
|
||||
{
|
||||
edit = true;
|
||||
}
|
||||
|
||||
public void touched(MapEditor editor, int x, int y){
|
||||
Pixmap pix = editor.pixmap();
|
||||
|
||||
@ -63,6 +71,7 @@ public enum EditorTool{
|
||||
}
|
||||
},
|
||||
zoom;
|
||||
boolean edit;
|
||||
|
||||
public void touched(MapEditor editor, int x, int y){
|
||||
|
||||
|
@ -84,13 +84,13 @@ public class MapEditor{
|
||||
this.brushSize = 1;
|
||||
if(map.pixmap == null){
|
||||
pixmap = new Pixmap(256, 256, Format.RGB888);
|
||||
pixmap.setColor(ColorMapper.getColor(Blocks.stone));
|
||||
pixmap.setColor(ColorMapper.getColor(drawBlock));
|
||||
pixmap.fill();
|
||||
texture = new Texture(pixmap);
|
||||
}else{
|
||||
pixmap = map.pixmap;
|
||||
pixmap.setColor(ColorMapper.getColor(Blocks.stone));
|
||||
texture = map.texture;
|
||||
pixmap.setColor(ColorMapper.getColor(drawBlock));
|
||||
}
|
||||
|
||||
}
|
||||
@ -161,8 +161,24 @@ public class MapEditor{
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
public void setPixmap(Pixmap out){
|
||||
if(pixmap.getWidth() == out.getWidth() && pixmap.getHeight() == out.getHeight()){
|
||||
pixmap.dispose();
|
||||
pixmap = out;
|
||||
texture.draw(out, 0, 0);
|
||||
}else{
|
||||
pixmap.dispose();
|
||||
texture.dispose();
|
||||
pixmap = out;
|
||||
texture = new Texture(out);
|
||||
}
|
||||
pixmap.setColor(ColorMapper.getColor(drawBlock));
|
||||
map.pixmap = pixmap;
|
||||
map.texture = texture;
|
||||
}
|
||||
|
||||
public void resize(int width, int height){
|
||||
Pixmap out = Pixmaps.resize(pixmap, width, height);
|
||||
Pixmap out = Pixmaps.resize(pixmap, width, height, ColorMapper.getColor(Blocks.stone));
|
||||
pixmap.dispose();
|
||||
pixmap = out;
|
||||
texture.dispose();
|
||||
@ -174,5 +190,6 @@ public class MapEditor{
|
||||
filterPixmap = null;
|
||||
filterTexture = null;
|
||||
}
|
||||
pixmap.setColor(ColorMapper.getColor(drawBlock));
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package io.anuke.mindustry.mapeditor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.ui.FileChooser;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.ColorMapper.BlockPair;
|
||||
@ -12,6 +17,7 @@ import io.anuke.mindustry.world.blocks.SpecialBlocks;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Pixmaps;
|
||||
import io.anuke.ucore.scene.builders.*;
|
||||
import io.anuke.ucore.scene.ui.*;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
@ -24,6 +30,8 @@ public class MapEditorDialog extends Dialog{
|
||||
private MapLoadDialog loadDialog;
|
||||
private MapSaveDialog saveDialog;
|
||||
private MapResizeDialog resizeDialog;
|
||||
private FileChooser openFile, saveFile;
|
||||
private boolean saved = false;
|
||||
|
||||
private ButtonGroup<ImageButton> blockgroup;
|
||||
|
||||
@ -33,8 +41,54 @@ public class MapEditorDialog extends Dialog{
|
||||
dialog = new MapGenerateDialog(editor);
|
||||
view = new MapView(editor);
|
||||
|
||||
openFile = new FileChooser("Load Image", FileChooser.pngFilter, true, file -> {
|
||||
Vars.ui.showLoading();
|
||||
Timers.run(3f, () -> {
|
||||
try{
|
||||
Pixmap pixmap = new Pixmap(file);
|
||||
if(verifySize(pixmap)){
|
||||
editor.setPixmap(pixmap);
|
||||
}else{
|
||||
Vars.ui.showError("[orange]Invalid image dimensions![]\nValid map dimensions: " + Arrays.toString(MapEditor.validMapSizes));
|
||||
}
|
||||
}catch (Exception e){
|
||||
Vars.ui.showError("Error loading image file!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
Vars.ui.hideLoading();
|
||||
});
|
||||
});
|
||||
|
||||
saveFile = new FileChooser("Save Image", false, file -> {
|
||||
if(!file.extension().toLowerCase().equals(".png")){
|
||||
file = file.parent().child(file.nameWithoutExtension() + ".png");
|
||||
}
|
||||
FileHandle result = file;
|
||||
Vars.ui.showLoading();
|
||||
Timers.run(3f, () -> {
|
||||
try{
|
||||
Pixmaps.write(editor.pixmap(), result);
|
||||
}catch (Exception e){
|
||||
Vars.ui.showError("Error saving image file!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
Vars.ui.hideLoading();
|
||||
});
|
||||
});
|
||||
|
||||
loadDialog = new MapLoadDialog(map -> {
|
||||
editor.beginEdit(map);
|
||||
saveDialog.setFieldText(map.name);
|
||||
Vars.ui.showLoading();
|
||||
|
||||
Timers.run(3f, () -> {
|
||||
Map copy = new Map();
|
||||
copy.name = map.name;
|
||||
copy.id = -1;
|
||||
copy.pixmap = Pixmaps.copy(map.pixmap);
|
||||
copy.texture = new Texture(copy.pixmap);
|
||||
editor.beginEdit(copy);
|
||||
Vars.ui.hideLoading();
|
||||
});
|
||||
});
|
||||
|
||||
resizeDialog = new MapResizeDialog(editor, (x, y) -> {
|
||||
@ -51,6 +105,7 @@ public class MapEditorDialog extends Dialog{
|
||||
saveDialog = new MapSaveDialog(name -> {
|
||||
Vars.ui.showLoading();
|
||||
if(verifyMap()){
|
||||
saved = true;
|
||||
editor.getMap().name = name;
|
||||
Timers.run(10f, () -> {
|
||||
Vars.world.maps().saveAndReload(editor.getMap(), editor.pixmap());
|
||||
@ -70,11 +125,16 @@ public class MapEditorDialog extends Dialog{
|
||||
build.end();
|
||||
|
||||
shown(() -> {
|
||||
saved = true;
|
||||
editor.beginEdit(new Map());
|
||||
Core.scene.setScrollFocus(view);
|
||||
});
|
||||
}
|
||||
|
||||
public void resetSaved(){
|
||||
saved = false;
|
||||
}
|
||||
|
||||
public void updateSelectedBlock(){
|
||||
Block block = editor.getDrawBlock();
|
||||
int i = 0;
|
||||
@ -103,6 +163,12 @@ public class MapEditorDialog extends Dialog{
|
||||
|
||||
row();
|
||||
|
||||
new imagebutton("icon-cursor", 10f*3f, () -> {
|
||||
resizeDialog.show();
|
||||
}).text("resize").padTop(4f);
|
||||
|
||||
row();
|
||||
|
||||
new imagebutton("icon-load", isize, () -> {
|
||||
loadDialog.show();
|
||||
}).text("load map");
|
||||
@ -116,25 +182,23 @@ public class MapEditorDialog extends Dialog{
|
||||
row();
|
||||
|
||||
new imagebutton("icon-load", isize, () -> {
|
||||
|
||||
openFile.show();
|
||||
}).text("load image");
|
||||
|
||||
row();
|
||||
|
||||
new imagebutton("icon-save", isize, () -> {
|
||||
|
||||
saveFile.show();
|
||||
}).text("save image");
|
||||
|
||||
row();
|
||||
|
||||
new imagebutton("icon-cursor", 10f*3f, () -> {
|
||||
resizeDialog.show();
|
||||
}).text("resize").padTop(4f);
|
||||
|
||||
row();
|
||||
|
||||
new imagebutton("icon-arrow-left", isize, () -> {
|
||||
if(!saved){
|
||||
Vars.ui.showConfirm("Confirm Exit", "[scarlet]You have unsaved changes![]\nAre you sure you want to exit?", () -> hide());
|
||||
}else{
|
||||
hide();
|
||||
}
|
||||
}).padBottom(0).text("back");
|
||||
|
||||
}}.left().growY().end();
|
||||
@ -186,6 +250,18 @@ public class MapEditorDialog extends Dialog{
|
||||
}}.grow().end();
|
||||
}
|
||||
|
||||
private boolean verifySize(Pixmap pix){
|
||||
boolean w = false, h = false;
|
||||
for(int i : MapEditor.validMapSizes){
|
||||
if(pix.getWidth() == i)
|
||||
w = true;
|
||||
if(pix.getHeight() == i)
|
||||
h = true;
|
||||
}
|
||||
|
||||
return w && h;
|
||||
}
|
||||
|
||||
private boolean verifyMap(){
|
||||
int psc = ColorMapper.getColor(SpecialBlocks.playerSpawn);
|
||||
int esc = ColorMapper.getColor(SpecialBlocks.enemySpawn);
|
||||
@ -221,6 +297,7 @@ public class MapEditorDialog extends Dialog{
|
||||
private void addBlockSelection(Table table){
|
||||
Table content = new Table();
|
||||
ScrollPane pane = new ScrollPane(content, "volume");
|
||||
pane.setScrollingDisabled(true, false);
|
||||
pane.setFadeScrollBars(false);
|
||||
pane.setOverscroll(true, false);
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
@ -242,10 +319,12 @@ public class MapEditorDialog extends Dialog{
|
||||
}
|
||||
}
|
||||
|
||||
group.getButtons().get(3).setChecked(true);
|
||||
content.padLeft(Unit.dp.inPixels(-5f));
|
||||
|
||||
group.getButtons().get(2).setChecked(true);
|
||||
|
||||
Table extra = new Table("button");
|
||||
extra.addWrap(() -> editor.getDrawBlock().name).width(120f).center();
|
||||
extra.labelWrap(() -> editor.getDrawBlock().name).width(120f).center();
|
||||
table.add(extra).growX();
|
||||
table.row();
|
||||
table.add(pane).growY().fillX();
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Scaling;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.mapeditor.MapFilter.GenPref;
|
||||
import io.anuke.mindustry.ui.BorderImage;
|
||||
import io.anuke.mindustry.ui.FloatingDialog;
|
||||
@ -71,9 +72,15 @@ public class MapGenerateDialog extends FloatingDialog{
|
||||
apply();
|
||||
});
|
||||
buttons().addButton("Apply", () ->{
|
||||
Vars.ui.showLoading();
|
||||
|
||||
Timers.run(3f, () ->{
|
||||
editor.applyFilter();
|
||||
Vars.ui.hideLoading();
|
||||
Vars.ui.getEditorDialog().resetSaved();
|
||||
hide();
|
||||
});
|
||||
});
|
||||
|
||||
shown(() ->{
|
||||
loading = true;
|
||||
|
@ -16,6 +16,7 @@ public class MapResizeDialog extends FloatingDialog{
|
||||
public MapResizeDialog(MapEditor editor, BiConsumer<Integer, Integer> cons){
|
||||
super("resize map");
|
||||
shown(() -> {
|
||||
content().clear();
|
||||
Pixmap pix = editor.pixmap();
|
||||
width = pix.getWidth();
|
||||
height = pix.getHeight();
|
||||
@ -48,7 +49,7 @@ public class MapResizeDialog extends FloatingDialog{
|
||||
table.row();
|
||||
}
|
||||
|
||||
content().add(() ->
|
||||
content().label(() ->
|
||||
width + height > 512 ? "[scarlet]Warning!\n[]Maps larger than 256 units may be laggy and unstable." : ""
|
||||
).get().setAlignment(Align.center, Align.center);
|
||||
content().row();
|
||||
|
@ -17,7 +17,7 @@ public class MapSaveDialog extends FloatingDialog{
|
||||
|
||||
shown(() -> {
|
||||
content().clear();
|
||||
content().add(() ->{
|
||||
content().label(() ->{
|
||||
Map map = Vars.world.maps().getMap(field.getText());
|
||||
if(map != null){
|
||||
if(map.custom){
|
||||
@ -47,6 +47,11 @@ public class MapSaveDialog extends FloatingDialog{
|
||||
buttons().add(button);
|
||||
}
|
||||
|
||||
public void setFieldText(String text){
|
||||
field.setText(text);
|
||||
}
|
||||
|
||||
|
||||
private boolean invalid(){
|
||||
if(field.getText().isEmpty()){
|
||||
return true;
|
||||
|
@ -11,12 +11,11 @@ import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.event.InputEvent;
|
||||
import io.anuke.ucore.scene.event.InputListener;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
@ -36,6 +35,7 @@ public class MapView extends Element implements GestureListener{
|
||||
this.editor = editor;
|
||||
|
||||
Inputs.addProcessor(0, new GestureDetector(20, 0.5f, 2, 0.15f, this));
|
||||
setTouchable(Touchable.enabled);
|
||||
|
||||
addListener(new InputListener(){
|
||||
int lastx, lasty;
|
||||
@ -48,6 +48,10 @@ public class MapView extends Element implements GestureListener{
|
||||
lasty = p.y;
|
||||
tool.touched(editor, p.x, p.y);
|
||||
|
||||
if(tool.edit){
|
||||
Vars.ui.getEditorDialog().resetSaved();
|
||||
}
|
||||
|
||||
drawing = true;
|
||||
return true;
|
||||
}
|
||||
@ -62,6 +66,7 @@ public class MapView extends Element implements GestureListener{
|
||||
GridPoint2 p = project(x, y);
|
||||
|
||||
if(drawing && tool == EditorTool.pencil){
|
||||
Vars.ui.getEditorDialog().resetSaved();
|
||||
Array<GridPoint2> points = br.line(lastx, lasty, p.x, p.y);
|
||||
for(GridPoint2 point : points){
|
||||
editor.draw(point.x, point.y);
|
||||
@ -71,20 +76,6 @@ public class MapView extends Element implements GestureListener{
|
||||
lasty = p.y;
|
||||
}
|
||||
});
|
||||
|
||||
addListener(new InputListener(){
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
return tool == EditorTool.zoom;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void touchDragged (InputEvent event, float x, float y, int pointer) {
|
||||
//offsetx += Gdx.input.getDeltaX(pointer) / zoom;
|
||||
//offsety -= Gdx.input.getDeltaY(pointer) / zoom;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -106,23 +97,28 @@ public class MapView extends Element implements GestureListener{
|
||||
}
|
||||
|
||||
private GridPoint2 project(float x, float y){
|
||||
float size = Math.min(width, height)*zoom;
|
||||
x = (x - getWidth()/2 + size/2 - offsetx*zoom) / size * editor.texture().getWidth();
|
||||
y = (y - getHeight()/2 + size/2 - offsety*zoom) / size * editor.texture().getHeight();
|
||||
float ratio = 1f / ((float)editor.pixmap().getWidth() / editor.pixmap().getHeight());
|
||||
float size = Math.min(width, height);
|
||||
float sclwidth = size * zoom;
|
||||
float sclheight = size * zoom * ratio;
|
||||
x = (x - getWidth()/2 + sclwidth/2 - offsetx*zoom) / sclwidth * editor.texture().getWidth();
|
||||
y = (y - getHeight()/2 + sclheight/2 - offsety*zoom) / sclheight * editor.texture().getHeight();
|
||||
return Tmp.g1.set((int)x, editor.texture().getHeight() - 1 - (int)y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float alpha){
|
||||
float ratio = 1f / ((float)editor.pixmap().getWidth() / editor.pixmap().getHeight());
|
||||
float size = Math.min(width, height);
|
||||
float sclsize = size * zoom;
|
||||
float sclwidth = size * zoom;
|
||||
float sclheight = size * zoom * ratio;
|
||||
float centerx = x + width/2 + offsetx * zoom;
|
||||
float centery = y + height/2 + offsety * zoom;
|
||||
|
||||
batch.flush();
|
||||
boolean pop = ScissorStack.pushScissors(Tmp.r1.set(x + width/2 - size/2, y + height/2 - size/2, size, size));
|
||||
|
||||
batch.draw(editor.texture(), centerx - sclsize/2, centery - sclsize/2, sclsize, sclsize);
|
||||
batch.draw(editor.texture(), centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
|
||||
batch.flush();
|
||||
|
||||
if(pop) ScissorStack.popScissors();
|
||||
@ -134,7 +130,10 @@ public class MapView extends Element implements GestureListener{
|
||||
}
|
||||
|
||||
private boolean active(){
|
||||
return Core.scene.getKeyboardFocus() != null && Core.scene.getKeyboardFocus().isDescendantOf(Vars.ui.getEditorDialog()) && Vars.ui.isEditing() && tool == EditorTool.zoom;
|
||||
return Core.scene.getKeyboardFocus() != null
|
||||
&& Core.scene.getKeyboardFocus().isDescendantOf(Vars.ui.getEditorDialog())
|
||||
&& Vars.ui.isEditing() && tool == EditorTool.zoom &&
|
||||
Core.scene.hit(Graphics.mouse().x, Graphics.mouse().y, true) == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
337
core/src/io/anuke/mindustry/ui/FileChooser.java
Normal file
@ -0,0 +1,337 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
import io.anuke.ucore.scene.ui.*;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class FileChooser extends FloatingDialog{
|
||||
|
||||
private Table files;
|
||||
private FileHandle homeDirectory = Gdx.files.local(Gdx.files.getExternalStoragePath());
|
||||
private FileHandle directory = homeDirectory;
|
||||
private ScrollPane pane;
|
||||
private TextField navigation, filefield;
|
||||
private TextButton ok;
|
||||
private FileHistory stack = new FileHistory();
|
||||
private Predicate<FileHandle> filter;
|
||||
private Consumer<FileHandle> selectListener;
|
||||
private boolean open;
|
||||
|
||||
public FileChooser(String title, boolean open, Consumer<FileHandle> result){
|
||||
this(title, defaultFilter, open, result);
|
||||
}
|
||||
|
||||
public FileChooser(String title, Predicate<FileHandle> filter, boolean open, Consumer<FileHandle> result){
|
||||
super(title);
|
||||
this.open = open;
|
||||
this.filter = filter;
|
||||
this.selectListener = result;
|
||||
setupWidgets();
|
||||
}
|
||||
|
||||
private void setupWidgets(){
|
||||
getCell(content()).maxWidth(Gdx.graphics.getWidth()/2);
|
||||
content().pad(-Unit.dp.inPixels(10));
|
||||
|
||||
Table content = new Table();
|
||||
|
||||
filefield = new TextField();
|
||||
if(!open) Mindustry.platforms.addDialog(filefield);
|
||||
filefield.setDisabled(open);
|
||||
|
||||
ok = new TextButton(open ? "Open" : "Save");
|
||||
|
||||
ok.clicked(() -> {
|
||||
if(ok.isDisabled()) return;
|
||||
if(selectListener != null)
|
||||
selectListener.accept(directory.child(filefield.getText()));
|
||||
hide();
|
||||
});
|
||||
|
||||
filefield.changed(() -> {
|
||||
ok.setDisabled(filefield.getText().replace(" ", "").isEmpty());
|
||||
});
|
||||
|
||||
filefield.change();
|
||||
|
||||
TextButton cancel = new TextButton("Cancel");
|
||||
cancel.clicked(() -> hide());
|
||||
|
||||
navigation = new TextField("");
|
||||
navigation.setTouchable(Touchable.disabled);
|
||||
|
||||
files = new Table();
|
||||
|
||||
pane = new ScrollPane(files){
|
||||
public float getPrefHeight(){
|
||||
return Gdx.graphics.getHeight();
|
||||
}
|
||||
};
|
||||
pane.setOverscroll(false, false);
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
updateFiles(true);
|
||||
|
||||
Table icontable = new Table();
|
||||
|
||||
float isize = Unit.dp.inPixels(14*2);
|
||||
|
||||
ImageButton up = new ImageButton("icon-folder-parent");
|
||||
up.resizeImage(isize);
|
||||
up.clicked(()->{
|
||||
directory = directory.parent();
|
||||
updateFiles(true);
|
||||
});
|
||||
|
||||
ImageButton back = new ImageButton("icon-arrow-left");
|
||||
back.resizeImage(isize);
|
||||
|
||||
ImageButton forward = new ImageButton("icon-arrow-right");
|
||||
forward.resizeImage(isize);
|
||||
|
||||
forward.clicked(()-> stack.forward());
|
||||
|
||||
back.clicked(()-> stack.back());
|
||||
|
||||
ImageButton home = new ImageButton("icon-home");
|
||||
home.resizeImage(isize);
|
||||
home.clicked(()->{
|
||||
directory = homeDirectory;
|
||||
updateFiles(true);
|
||||
});
|
||||
|
||||
icontable.defaults().height(50).growX().uniform();
|
||||
icontable.add(home);
|
||||
icontable.add(back);
|
||||
icontable.add(forward);
|
||||
icontable.add(up);
|
||||
|
||||
Table fieldcontent = new Table();
|
||||
fieldcontent.bottom().left().add(new Label("File Name:"));
|
||||
fieldcontent.add(filefield).height(40f).fillX().expandX().padLeft(10f);
|
||||
|
||||
Table buttons = new Table();
|
||||
buttons.defaults().growX().height(50);
|
||||
buttons.add(cancel);
|
||||
buttons.add(ok);
|
||||
|
||||
content.top().left();
|
||||
content.add(icontable).expandX().fillX();
|
||||
content.row();
|
||||
|
||||
//content.add(navigation).colspan(3).left().padBottom(10f).expandX().fillX().height(40f);
|
||||
//content.row();
|
||||
|
||||
content.center().add(pane).width(Gdx.graphics.getWidth()/2).colspan(3).units(Unit.px).grow();
|
||||
content.row();
|
||||
|
||||
if(!open){
|
||||
content.bottom().left().add(fieldcontent).colspan(3).grow().padTop(-2).padBottom(2);
|
||||
content.row();
|
||||
}
|
||||
|
||||
content.add(buttons).growX();
|
||||
|
||||
content().add(content);
|
||||
//content().add(icontable).expandY().top();
|
||||
}
|
||||
|
||||
private void updateFileFieldStatus(){
|
||||
if(!open){
|
||||
ok.setDisabled(filefield.getText().replace(" ", "").isEmpty());
|
||||
}else{
|
||||
ok.setDisabled(!directory.child(filefield.getText()).exists() || directory.child(filefield.getText()).isDirectory());
|
||||
}
|
||||
}
|
||||
|
||||
private FileHandle[] getFileNames(){
|
||||
FileHandle[] handles = directory.list(new FileFilter(){
|
||||
@Override
|
||||
public boolean accept(File file){
|
||||
return !file.getName().startsWith(".");
|
||||
}
|
||||
});
|
||||
|
||||
Arrays.sort(handles, new Comparator<FileHandle>(){
|
||||
@Override
|
||||
public int compare(FileHandle a, FileHandle b){
|
||||
if(a.isDirectory() && !b.isDirectory()) return -1;
|
||||
if( !a.isDirectory() && b.isDirectory()) return 1;
|
||||
return a.name().compareTo(b.name());
|
||||
}
|
||||
});
|
||||
return handles;
|
||||
}
|
||||
|
||||
private void updateFiles(boolean push){
|
||||
if(push) stack.push(directory);
|
||||
navigation.setText(directory.toString());
|
||||
|
||||
GlyphLayout layout = Pools.obtain(GlyphLayout.class);
|
||||
|
||||
layout.setText(Core.font, navigation.getText());
|
||||
|
||||
if(layout.width < navigation.getWidth()){
|
||||
navigation.setCursorPosition(0);
|
||||
}else{
|
||||
navigation.setCursorPosition(navigation.getText().length());
|
||||
}
|
||||
|
||||
Pools.free(layout);
|
||||
|
||||
files.clearChildren();
|
||||
FileHandle[] names = getFileNames();
|
||||
|
||||
Image upimage = new Image("icon-folder-parent");
|
||||
|
||||
TextButton upbutton = new TextButton(".." + directory.toString());
|
||||
upbutton.clicked(()->{
|
||||
directory = directory.parent();
|
||||
updateFiles(true);
|
||||
});
|
||||
|
||||
upbutton.left().add(upimage).padRight(4f).size(14*2);
|
||||
upbutton.getCells().reverse();
|
||||
|
||||
files.top().left().add(upbutton).align(Align.topLeft).fillX().expandX().height(50).pad(2).colspan(2);
|
||||
upbutton.getLabel().setAlignment(Align.left);
|
||||
|
||||
files.row();
|
||||
|
||||
ButtonGroup<TextButton> group = new ButtonGroup<TextButton>();
|
||||
group.setMinCheckCount(0);
|
||||
|
||||
for(FileHandle file : names){
|
||||
if( !file.isDirectory() && !filter.test(file)) continue; //skip non-filtered files
|
||||
|
||||
String filename = file.name();
|
||||
|
||||
TextButton button = new TextButton(shorten(filename), "toggle");
|
||||
group.add(button);
|
||||
|
||||
button.clicked(()->{
|
||||
if( !file.isDirectory()){
|
||||
filefield.setText(filename);
|
||||
updateFileFieldStatus();
|
||||
}else{
|
||||
directory = directory.child(filename);
|
||||
updateFiles(true);
|
||||
}
|
||||
});
|
||||
|
||||
filefield.changed(()->{
|
||||
button.setChecked(filename.equals(filefield.getText()));
|
||||
});
|
||||
|
||||
Image image = new Image(file.isDirectory() ? "icon-folder" : "icon-file-text");
|
||||
|
||||
button.add(image).padRight(4f).size(14*2f);
|
||||
button.getCells().reverse();
|
||||
files.top().left().add(button).align(Align.topLeft).fillX().expandX()
|
||||
.height(50).pad(2).padTop(0).padBottom(0).colspan(2);
|
||||
button.getLabel().setAlignment(Align.left);
|
||||
files.row();
|
||||
}
|
||||
|
||||
pane.setScrollY(0f);
|
||||
updateFileFieldStatus();
|
||||
|
||||
if(open) filefield.clearText();
|
||||
}
|
||||
|
||||
private String shorten(String string){
|
||||
int max = 30;
|
||||
if(string.length() <= max){
|
||||
return string;
|
||||
}else{
|
||||
return string.substring(0, max - 3).concat("...");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog show(){
|
||||
super.show();
|
||||
Core.scene.setScrollFocus(pane);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void fileSelected(Consumer<FileHandle> listener){
|
||||
this.selectListener = listener;
|
||||
}
|
||||
|
||||
public class FileHistory{
|
||||
private Array<FileHandle> history = new Array<FileHandle>();
|
||||
private int index;
|
||||
|
||||
public FileHistory(){
|
||||
|
||||
}
|
||||
|
||||
public void push(FileHandle file){
|
||||
if(index != history.size) history.truncate(index);
|
||||
history.add(file);
|
||||
index ++;
|
||||
}
|
||||
|
||||
public void back(){
|
||||
if( !canBack()) return;
|
||||
index --;
|
||||
directory = history.get(index - 1);
|
||||
updateFiles(false);
|
||||
}
|
||||
|
||||
public void forward(){
|
||||
if( !canForward()) return;
|
||||
directory = history.get(index);
|
||||
index ++;
|
||||
updateFiles(false);
|
||||
}
|
||||
|
||||
public boolean canForward(){
|
||||
return !(index >= history.size);
|
||||
}
|
||||
|
||||
public boolean canBack(){
|
||||
return !(index == 1) && index > 0;
|
||||
}
|
||||
|
||||
void print(){
|
||||
|
||||
System.out.println("\n\n\n\n\n\n");
|
||||
int i = 0;
|
||||
for(FileHandle file : history){
|
||||
i ++;
|
||||
if(index == i){
|
||||
System.out.println("[[" + file.toString() + "]]");
|
||||
}else{
|
||||
System.out.println("--" + file.toString() + "--");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static interface FileHandleFilter{
|
||||
public boolean accept(FileHandle file);
|
||||
}
|
||||
|
||||
public static Predicate<FileHandle> pngFilter = file -> file.extension().equalsIgnoreCase("png");
|
||||
public static Predicate<FileHandle> jpegFilter = file -> file.extension().equalsIgnoreCase("png") || file.extension().equalsIgnoreCase("jpg") || file.extension().equalsIgnoreCase("jpeg");
|
||||
public static Predicate<FileHandle> defaultFilter = file -> true;
|
||||
}
|
@ -8,7 +8,6 @@ import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.function.StringSupplier;
|
||||
import io.anuke.ucore.scene.ui.*;
|
||||
import io.anuke.ucore.scene.ui.layout.Stack;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
@ -18,6 +17,7 @@ import io.anuke.ucore.scene.utils.Elements;
|
||||
public class LevelDialog extends FloatingDialog{
|
||||
private Map selectedMap = Vars.world.maps().getMap(0);
|
||||
private TextureRegion region = new TextureRegion();
|
||||
private ScrollPane pane;
|
||||
|
||||
public LevelDialog(){
|
||||
super("Level Select");
|
||||
@ -34,7 +34,7 @@ public class LevelDialog extends FloatingDialog{
|
||||
|
||||
void setup(){
|
||||
Table maps = new Table();
|
||||
ScrollPane pane = new ScrollPane(maps);
|
||||
pane = new ScrollPane(maps);
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
int maxwidth = 4;
|
||||
@ -66,7 +66,7 @@ public class LevelDialog extends FloatingDialog{
|
||||
Table inset = new Table("pane-button");
|
||||
inset.add("[accent]"+map.name).pad(3f).units(Unit.dp);
|
||||
inset.row();
|
||||
inset.add((StringSupplier)(()->"High Score: [accent]" + Settings.getInt("hiscore" + map.name)))
|
||||
inset.label((() -> "High Score: [accent]" + Settings.getInt("hiscore" + map.name)))
|
||||
.pad(3f).units(Unit.dp);
|
||||
inset.pack();
|
||||
|
||||
@ -80,7 +80,21 @@ public class LevelDialog extends FloatingDialog{
|
||||
ImageButton image = new ImageButton(new TextureRegion(map.texture), "togglemap");
|
||||
image.row();
|
||||
image.add(inset).width(images+6).units(Unit.dp);
|
||||
TextButton[] delete = new TextButton[1];
|
||||
if(map.custom){
|
||||
image.row();
|
||||
delete[0] = image.addButton("Delete", () -> {
|
||||
Vars.ui.showConfirm("Confirm Delete", "Are you sure you want to delete\nthe map \"[orange]" + map.name + "[]\"?", () -> {
|
||||
Vars.world.maps().removeMap(map);
|
||||
reload();
|
||||
Core.scene.setScrollFocus(pane);
|
||||
});
|
||||
}).width(images+16).units(Unit.dp).padBottom(-10f).grow().get();
|
||||
}
|
||||
image.clicked(()->{
|
||||
if(delete[0] != null && delete[0].getClickListener().isOver()){
|
||||
return;
|
||||
}
|
||||
selectedMap = map;
|
||||
hide();
|
||||
Vars.control.playMap(selectedMap);
|
||||
@ -90,7 +104,7 @@ public class LevelDialog extends FloatingDialog{
|
||||
stack.add(back);
|
||||
stack.add(image);
|
||||
|
||||
maps.add(stack).width(170).pad(4f).units(Unit.dp);
|
||||
maps.add(stack).width(170).top().pad(4f).units(Unit.dp);
|
||||
|
||||
maps.padRight(Unit.dp.inPixels(26));
|
||||
|
||||
|
@ -51,6 +51,18 @@ public class Maps implements Disposable{
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMap(Map map){
|
||||
maps.remove(map.id);
|
||||
mapNames.remove(map.name);
|
||||
Array<Map> out = new Array<>();
|
||||
for(Map m : maps.values()){
|
||||
if(m.custom){
|
||||
out.add(m);
|
||||
}
|
||||
}
|
||||
saveMaps(out, Vars.customMapDirectory.child("maps.json"));
|
||||
}
|
||||
|
||||
public void saveAndReload(Map map, Pixmap out){
|
||||
if(map.pixmap != null && out != map.pixmap && map.texture != null){
|
||||
map.texture.dispose();
|
||||
@ -58,6 +70,7 @@ public class Maps implements Disposable{
|
||||
}else if (out == map.pixmap){
|
||||
map.texture.draw(out, 0, 0);
|
||||
}
|
||||
|
||||
map.pixmap = out;
|
||||
if(map.texture == null) map.texture = new Texture(map.pixmap);
|
||||
|
||||
@ -90,6 +103,7 @@ public class Maps implements Disposable{
|
||||
if(map.custom){
|
||||
if(map.name.equals(toSave.name)){
|
||||
out.add(toSave);
|
||||
toSave.id = map.id;
|
||||
added = true;
|
||||
}else{
|
||||
out.add(map);
|
||||
|
@ -26,7 +26,7 @@ public class NuclearReactor extends LiquidItemPowerGenerator{
|
||||
protected Color coolColor = new Color(1, 1, 1, 0f);
|
||||
protected Color hotColor = Color.valueOf("ff9575a3");
|
||||
protected int fuelUseTime = 120; //time to consume 1 fuel
|
||||
protected float powerMultiplier = 0.2f; //power per frame, depends on full capacity
|
||||
protected float powerMultiplier = 0.3f; //power per frame, depends on full capacity
|
||||
protected float heating = 0.007f; //heating per frame
|
||||
protected float coolantPower = 0.007f; //how much heat decreases per coolant unit
|
||||
protected float smokeThreshold = 0.3f; //threshold at which block starts smoking
|
||||
|
BIN
desktop/mindustry-maps/desert2.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
desktop/mindustry-maps/desert23.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
desktop/mindustry-maps/desert2asd.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
desktop/mindustry-maps/island2.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
@ -1 +1 @@
|
||||
{"maps":[{"id":13,"name":"custom","custom":true},{"id":14,"name":"wowmap","custom":true},{"id":15,"name":"moremap","custom":true},{"id":16,"name":"trash","custom":true},{"id":17,"name":"wonderifthisworks","custom":true}]}
|
||||
{"maps":[]}
|
BIN
desktop/mindustry-maps/maze2.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
desktop/mindustry-maps/sadfa.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
desktop/mindustry-maps/spiral12.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 856 B After Width: | Height: | Size: 1.3 KiB |
BIN
desktop/mindustry-maps/tundra213123.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
@ -14,6 +14,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.io.PlatformFunction;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
|
||||
public class DesktopLauncher {
|
||||
|
||||
@ -47,6 +48,11 @@ public class DesktopLauncher {
|
||||
Vars.ui.showError("Error opening link.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDialog(TextField field){
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Mindustry.args = Array.with(arg);
|
||||
|
@ -17,6 +17,7 @@ import com.google.gwt.user.client.ui.*;
|
||||
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.io.PlatformFunction;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
|
||||
public class HtmlLauncher extends GwtApplication {
|
||||
static final int WIDTH = 800;
|
||||
@ -106,6 +107,11 @@ public class HtmlLauncher extends GwtApplication {
|
||||
public void openLink(String link){
|
||||
Window.open(link, "_blank", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDialog(TextField field){
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
return new Mindustry();
|
||||
|