Merge branch 'master' of https://github.com/Anuken/Mindustry into steam
This commit is contained in:
@@ -41,12 +41,12 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform
|
||||
assets.setLoader(Texture.class, "." + mapExtension, new MapPreviewLoader());
|
||||
atlas = TextureAtlas.blankAtlas();
|
||||
|
||||
UI.loadDefaultFont();
|
||||
UI.loadSystemCursors();
|
||||
|
||||
//1. bundles
|
||||
//2. rest of vars
|
||||
assets.load(new Vars());
|
||||
|
||||
UI.loadDefaultFont();
|
||||
|
||||
assets.load(new AssetDescriptor<>("sprites/sprites.atlas", TextureAtlas.class)).loaded = t -> atlas = (TextureAtlas)t;
|
||||
|
||||
assets.loadRun("maps", Map.class, () -> maps.loadPreviews());
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.anuke.arc.*;
|
||||
import io.anuke.arc.assets.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.ai.*;
|
||||
import io.anuke.mindustry.core.*;
|
||||
@@ -24,6 +25,8 @@ import io.anuke.mindustry.world.blocks.defense.ForceProjector.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
|
||||
import static io.anuke.arc.Core.settings;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Vars implements Loadable{
|
||||
/** Whether to load locales.*/
|
||||
@@ -260,6 +263,8 @@ public class Vars implements Loadable{
|
||||
Core.keybinds.setDefaults(Binding.values());
|
||||
Core.settings.load();
|
||||
|
||||
UnitScl.dp.setProduct(settings.getInt("uiscale", 100) / 100f);
|
||||
|
||||
if(!loadLocales) return;
|
||||
|
||||
try{
|
||||
|
||||
@@ -8,7 +8,6 @@ import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.input.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.core.GameState.*;
|
||||
@@ -18,7 +17,7 @@ import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.input.*;
|
||||
import io.anuke.mindustry.maps.*;
|
||||
import io.anuke.mindustry.maps.Map;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.ui.dialogs.*;
|
||||
@@ -26,8 +25,8 @@ import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.storage.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.*;
|
||||
import java.time.format.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
|
||||
import static io.anuke.arc.Core.*;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@@ -67,7 +66,7 @@ public class Control implements ApplicationListener, Loadable{
|
||||
Core.app.post(() -> Core.app.post(() -> {
|
||||
if(Net.active() && player.getClosestCore() != null){
|
||||
//set to closest core since that's where the player will probably respawn; prevents camera jumps
|
||||
Core.camera.position.set(player.getClosestCore());
|
||||
Core.camera.position.set(player.isDead() ? player.getClosestCore() : player);
|
||||
}else{
|
||||
//locally, set to player position since respawning occurs immediately
|
||||
Core.camera.position.set(player);
|
||||
@@ -159,8 +158,6 @@ public class Control implements ApplicationListener, Loadable{
|
||||
|
||||
Draw.scl = 1f / Core.atlas.find("scale_marker").getWidth();
|
||||
|
||||
UnitScl.dp.setProduct(settings.getInt("uiscale", 100) / 100f);
|
||||
|
||||
Core.input.setCatch(KeyCode.BACK, true);
|
||||
|
||||
data.load();
|
||||
@@ -223,7 +220,9 @@ public class Control implements ApplicationListener, Loadable{
|
||||
player.add();
|
||||
}
|
||||
|
||||
Core.input.addProcessor(input);
|
||||
Events.on(ClientLoadEvent.class, e -> {
|
||||
Core.input.addProcessor(input);
|
||||
});
|
||||
}
|
||||
|
||||
public void playMap(Map map, Rules rules){
|
||||
@@ -232,8 +231,8 @@ public class Control implements ApplicationListener, Loadable{
|
||||
world.loadMap(map, rules);
|
||||
state.rules = rules;
|
||||
logic.play();
|
||||
if(settings.getBool("savecreate")){
|
||||
control.saves.addSave(map.name() + "-" + DateTimeFormatter.ofPattern("MMM dd h:mm").format(LocalDateTime.now()));
|
||||
if(settings.getBool("savecreate") && !world.isInvalidMap()){
|
||||
control.saves.addSave(map.name() + " " + new SimpleDateFormat("MMM dd h:mm", Locale.getDefault()).format(new Date()));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -387,6 +386,8 @@ public class Control implements ApplicationListener, Loadable{
|
||||
@Override
|
||||
public void update(){
|
||||
saves.update();
|
||||
//update and load any requested assets
|
||||
assets.update();
|
||||
|
||||
input.updateController();
|
||||
|
||||
|
||||
@@ -319,6 +319,15 @@ public class NetServer implements ApplicationListener{
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
clientCommands.<Player>register("sync", "Re-synchronize world state.", (args, player) -> {
|
||||
if(player.isLocal){
|
||||
player.sendMessage("[scarlet]Re-synchronizing as the host is pointless.");
|
||||
}else{
|
||||
Call.onWorldDataBegin(player.con.id);
|
||||
netServer.sendWorldData(player, player.con.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int votesRequired(){
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.anuke.arc.assets.*;
|
||||
import io.anuke.arc.assets.loaders.*;
|
||||
import io.anuke.arc.assets.loaders.resolvers.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.freetype.*;
|
||||
import io.anuke.arc.freetype.FreeTypeFontGenerator.*;
|
||||
import io.anuke.arc.freetype.FreetypeFontLoader.*;
|
||||
@@ -87,6 +88,7 @@ public class UI implements ApplicationListener, Loadable{
|
||||
skin.addRegions(Core.atlas);
|
||||
loadExtraStyle(skin);
|
||||
skin.add("outline", Core.assets.get("outline"));
|
||||
skin.getFont("outline").getData().markupEnabled = true;
|
||||
skin.getFont("default").getData().markupEnabled = true;
|
||||
skin.getFont("default").setOwnsTexture(false);
|
||||
skin.load(Core.files.internal("sprites/uiskin.json"));
|
||||
@@ -134,13 +136,20 @@ public class UI implements ApplicationListener, Loadable{
|
||||
public static void loadDefaultFont(){
|
||||
FileHandleResolver resolver = new InternalFileHandleResolver();
|
||||
Core.assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
|
||||
Core.assets.setLoader(BitmapFont.class, null, new FreetypeFontLoader(resolver));
|
||||
Core.assets.setLoader(BitmapFont.class, null, new FreetypeFontLoader(resolver){
|
||||
@Override
|
||||
public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, FreeTypeFontLoaderParameter parameter){
|
||||
if(fileName.equals("outline")){
|
||||
parameter.fontParameters.borderWidth = UnitScl.dp.scl(2f);
|
||||
parameter.fontParameters.spaceX -= parameter.fontParameters.borderWidth;
|
||||
}
|
||||
parameter.fontParameters.size = fontParameter().size;
|
||||
return super.loadSync(manager, fileName, file, parameter);
|
||||
}
|
||||
});
|
||||
|
||||
FreeTypeFontParameter param = new FreeTypeFontParameter(){{
|
||||
size = fontParameter().size;
|
||||
borderColor = Color.DARK_GRAY;
|
||||
borderWidth = UnitScl.dp.scl(2f);
|
||||
spaceX -= borderWidth;
|
||||
incremental = true;
|
||||
}};
|
||||
|
||||
|
||||
@@ -101,9 +101,8 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f);
|
||||
}
|
||||
|
||||
//deconstructing is 2x as fast
|
||||
if(current.breaking){
|
||||
entity.deconstruct(unit, core, 2f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
entity.deconstruct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
}else{
|
||||
entity.construct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
}
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.Events;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.assets.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.game.EventType.StateChangeEvent;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.io.SaveIO.SaveException;
|
||||
import io.anuke.mindustry.io.SaveMeta;
|
||||
import io.anuke.arc.util.async.*;
|
||||
import io.anuke.mindustry.core.GameState.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.io.*;
|
||||
import io.anuke.mindustry.io.SaveIO.*;
|
||||
import io.anuke.mindustry.maps.Map;
|
||||
import io.anuke.mindustry.type.Zone;
|
||||
import io.anuke.mindustry.type.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.io.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.saveExtension;
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Saves{
|
||||
private int nextSlot;
|
||||
private Array<SaveSlot> saves = new Array<>();
|
||||
private IntMap<SaveSlot> saveMap = new IntMap<>();
|
||||
private SaveSlot current;
|
||||
private AsyncExecutor previewExecutor = new AsyncExecutor(1);
|
||||
private boolean saving;
|
||||
private float time;
|
||||
|
||||
@@ -32,6 +33,8 @@ public class Saves{
|
||||
private long lastTimestamp;
|
||||
|
||||
public Saves(){
|
||||
Core.assets.setLoader(Texture.class, ".spreview", new SavePreviewLoader());
|
||||
|
||||
Events.on(StateChangeEvent.class, event -> {
|
||||
if(event.to == State.menu){
|
||||
totalPlaytime = 0;
|
||||
@@ -162,6 +165,7 @@ public class Saves{
|
||||
|
||||
public class SaveSlot{
|
||||
public final int index;
|
||||
boolean requestedPreview;
|
||||
SaveMeta meta;
|
||||
|
||||
public SaveSlot(int index){
|
||||
@@ -174,6 +178,7 @@ public class Saves{
|
||||
meta = SaveIO.getMeta(index);
|
||||
current = this;
|
||||
totalPlaytime = meta.timePlayed;
|
||||
savePreview();
|
||||
}catch(Exception e){
|
||||
throw new SaveException(e);
|
||||
}
|
||||
@@ -191,6 +196,41 @@ public class Saves{
|
||||
}
|
||||
|
||||
totalPlaytime = prev;
|
||||
savePreview();
|
||||
}
|
||||
|
||||
private void savePreview(){
|
||||
if(Core.assets.isLoaded(loadPreviewFile().path())){
|
||||
Core.assets.unload(loadPreviewFile().path());
|
||||
}
|
||||
previewExecutor.submit(() -> {
|
||||
try{
|
||||
previewFile().writePNG(renderer.minimap.getPixmap());
|
||||
requestedPreview = false;
|
||||
}catch(Throwable t){
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Texture previewTexture(){
|
||||
if(!previewFile().exists()){
|
||||
return null;
|
||||
}else if(Core.assets.isLoaded(loadPreviewFile().path())){
|
||||
return Core.assets.get(loadPreviewFile().path());
|
||||
}else if(!requestedPreview){
|
||||
Core.assets.load(new AssetDescriptor<>(loadPreviewFile(), Texture.class));
|
||||
requestedPreview = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private FileHandle previewFile(){
|
||||
return mapPreviewDirectory.child("save_slot_" + index + ".png");
|
||||
}
|
||||
|
||||
private FileHandle loadPreviewFile(){
|
||||
return previewFile().sibling(previewFile().name() + ".spreview");
|
||||
}
|
||||
|
||||
public boolean isHidden(){
|
||||
@@ -214,7 +254,7 @@ public class Saves{
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return Core.settings.getString("save-" + index + "-name", "untittled");
|
||||
return Core.settings.getString("save-" + index + "-name", "untitled");
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
@@ -270,6 +310,10 @@ public class Saves{
|
||||
current = null;
|
||||
}
|
||||
|
||||
if(Core.assets.isLoaded(loadPreviewFile().path())){
|
||||
Core.assets.unload(loadPreviewFile().path());
|
||||
}
|
||||
|
||||
saveSlots();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ public class MinimapRenderer implements Disposable{
|
||||
Events.on(TileChangeEvent.class, event -> Core.app.post(() -> update(event.tile)));
|
||||
}
|
||||
|
||||
public Pixmap getPixmap(){
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
public Texture getTexture(){
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
private int prevX, prevY, prevRotation;
|
||||
|
||||
public MobileInput(){
|
||||
Core.input.addProcessor(new GestureDetector(20, 0.5f, 0.4f, 0.15f, this));
|
||||
Events.on(ClientLoadEvent.class, e -> {
|
||||
Core.input.addProcessor(new GestureDetector(20, 0.5f, 0.4f, 0.15f, this));
|
||||
});
|
||||
}
|
||||
|
||||
//region utility methods
|
||||
|
||||
23
core/src/io/anuke/mindustry/io/SavePreviewLoader.java
Normal file
23
core/src/io/anuke/mindustry/io/SavePreviewLoader.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package io.anuke.mindustry.io;
|
||||
|
||||
import io.anuke.arc.assets.*;
|
||||
import io.anuke.arc.assets.loaders.*;
|
||||
import io.anuke.arc.assets.loaders.resolvers.*;
|
||||
import io.anuke.arc.files.*;
|
||||
|
||||
public class SavePreviewLoader extends TextureLoader{
|
||||
|
||||
public SavePreviewLoader(){
|
||||
super(new AbsoluteFileHandleResolver());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAsync(AssetManager manager, String fileName, FileHandle file, TextureParameter parameter){
|
||||
try{
|
||||
super.loadAsync(manager, fileName, file.sibling(file.nameWithoutExtension()), parameter);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
file.sibling(file.nameWithoutExtension()).delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class MapPreviewLoader extends TextureLoader{
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
MapPreviewParameter param = (MapPreviewParameter)parameter;
|
||||
Vars.maps.createNewPreview(param.map);
|
||||
Vars.maps.queueNewPreview(param.map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ public class Maps{
|
||||
private Json json = new Json();
|
||||
|
||||
private AsyncExecutor executor = new AsyncExecutor(2);
|
||||
private ObjectSet<Map> previewList = new ObjectSet<>();
|
||||
|
||||
/** Returns a list of all maps, including custom ones. */
|
||||
public Array<Map> all(){
|
||||
@@ -58,6 +59,10 @@ public class Maps{
|
||||
Events.on(ClientLoadEvent.class, event -> {
|
||||
maps.sort();
|
||||
});
|
||||
|
||||
if(Core.assets != null){
|
||||
((CustomLoader)Core.assets.getLoader(Content.class)).loaded = this::createAllPreviews;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,8 +154,13 @@ public class Maps{
|
||||
}
|
||||
}
|
||||
|
||||
if(Core.assets.isLoaded(map.previewFile().path() + "." + mapExtension)){
|
||||
Core.assets.unload(map.previewFile().path() + "." + mapExtension);
|
||||
}
|
||||
|
||||
Pixmap pix = MapIO.generatePreview(world.getTiles());
|
||||
executor.submit(() -> map.previewFile().writePNG(pix));
|
||||
writeCache(map);
|
||||
|
||||
map.texture = new Texture(pix);
|
||||
}
|
||||
@@ -309,27 +319,39 @@ public class Maps{
|
||||
}
|
||||
|
||||
public void loadPreviews(){
|
||||
Array<Map> createNew = new Array<>();
|
||||
|
||||
for(Map map : maps){
|
||||
//try to load preview
|
||||
if(map.previewFile().exists()){
|
||||
//this may fail, but calls createNewPreview
|
||||
Core.assets.load(new AssetDescriptor<>(map.previewFile().path() + "." + mapExtension, Texture.class, new MapPreviewParameter(map))).loaded = t -> map.texture = (Texture)t;
|
||||
}else{
|
||||
createNew.add(map);
|
||||
}
|
||||
|
||||
try{
|
||||
readCache(map);
|
||||
}catch(Exception ignored){
|
||||
try{
|
||||
readCache(map);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
queueNewPreview(map);
|
||||
}
|
||||
}else{
|
||||
queueNewPreview(map);
|
||||
}
|
||||
}
|
||||
|
||||
((CustomLoader)Core.assets.getLoader(Content.class)).loaded = () -> Core.app.post(() -> createNew.each(this::createNewPreview));
|
||||
}
|
||||
|
||||
public void createNewPreview(Map map){
|
||||
private void createAllPreviews(){
|
||||
Core.app.post(() -> {
|
||||
for(Map map : previewList){
|
||||
createNewPreview(map);
|
||||
}
|
||||
previewList.clear();
|
||||
});
|
||||
}
|
||||
|
||||
public void queueNewPreview(Map map){
|
||||
Core.app.post(() -> previewList.add(map));
|
||||
}
|
||||
|
||||
private void createNewPreview(Map map){
|
||||
try{
|
||||
//if it's here, then the preview failed to load or doesn't exist, make it
|
||||
//this has to be done synchronously!
|
||||
|
||||
@@ -15,8 +15,8 @@ import io.anuke.mindustry.game.*;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.*;
|
||||
import java.time.*;
|
||||
import java.time.format.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
|
||||
public class CrashSender{
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CrashSender{
|
||||
}
|
||||
|
||||
try{
|
||||
File file = new File(OS.getAppDataDirectoryString(Vars.appName), "crashes/crash-report-" + DateTimeFormatter.ofPattern("MM_dd_yyyy_HH_mm_ss").format(LocalDateTime.now()) + ".txt");
|
||||
File file = new File(OS.getAppDataDirectoryString(Vars.appName), "crashes/crash-report-" + new SimpleDateFormat("MM_dd_yyyy_HH_mm_ss").format(new Date()) + ".txt");
|
||||
Files.createDirectories(Paths.get(OS.getAppDataDirectoryString(Vars.appName), "crashes"));
|
||||
Files.write(file.toPath(), parseException(exception).getBytes());
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.arc.graphics.Texture;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.scene.ui.Image;
|
||||
import io.anuke.arc.scene.ui.layout.UnitScl;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
|
||||
public class BorderImage extends Image{
|
||||
private float thickness = 4f;
|
||||
public float thickness = 4f;
|
||||
public Color borderColor = Pal.gray;
|
||||
|
||||
public BorderImage(){
|
||||
|
||||
@@ -27,6 +28,11 @@ public class BorderImage extends Image{
|
||||
thickness = thick;
|
||||
}
|
||||
|
||||
public BorderImage border(Color color){
|
||||
this.borderColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
@@ -34,7 +40,7 @@ public class BorderImage extends Image{
|
||||
float scaleX = getScaleX();
|
||||
float scaleY = getScaleY();
|
||||
|
||||
Draw.color(Pal.gray);
|
||||
Draw.color(borderColor);
|
||||
Draw.alpha(parentAlpha);
|
||||
Lines.stroke(UnitScl.dp.scl(thickness));
|
||||
Lines.rect(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.scene.*;
|
||||
import io.anuke.arc.scene.style.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.scene.utils.*;
|
||||
@@ -77,20 +78,30 @@ public class DeployDialog extends FloatingDialog{
|
||||
}}.setScaling(Scaling.fit));
|
||||
|
||||
if(control.saves.getZoneSlot() != null){
|
||||
float size = 230f;
|
||||
float size = 250f;
|
||||
|
||||
stack.add(new Table(t -> {
|
||||
SaveSlot slot = control.saves.getZoneSlot();
|
||||
|
||||
Stack sub = new Stack();
|
||||
|
||||
if(control.saves.getZoneSlot().getZone() != null){
|
||||
if(slot.getZone() != null){
|
||||
sub.add(new Table(f -> f.margin(4f).add(new Image("whiteui")).color(Color.fromGray(0.1f)).grow()));
|
||||
sub.add(new Table(f -> f.margin(4f).add(new Image(control.saves.getZoneSlot().getZone().preview).setScaling(Scaling.fit)).color(Color.DARK_GRAY).grow()));
|
||||
|
||||
sub.add(new Table(f -> f.margin(4f).add(new Image(slot.getZone().preview).setScaling(Scaling.fit)).update(img -> {
|
||||
TextureRegionDrawable draw = (TextureRegionDrawable)img.getDrawable();
|
||||
if(draw.getRegion().getTexture().isDisposed()){
|
||||
draw.setRegion(slot.getZone().preview);
|
||||
}
|
||||
|
||||
Texture text = slot.previewTexture();
|
||||
if(draw.getRegion() == slot.getZone().preview && text != null){
|
||||
draw.setRegion(new TextureRegion(text));
|
||||
}
|
||||
}).color(Color.DARK_GRAY).grow()));
|
||||
}
|
||||
|
||||
TextButton button = Elements.newButton(Core.bundle.format("resume", slot.getZone().localizedName()), "square", () -> {
|
||||
|
||||
hide();
|
||||
ui.loadAnd(() -> {
|
||||
logic.reset();
|
||||
@@ -127,7 +138,7 @@ public class DeployDialog extends FloatingDialog{
|
||||
slot.delete();
|
||||
setup();
|
||||
});
|
||||
}).width(230f).height(50f).padTop(3);
|
||||
}).width(size).height(50f).padTop(3);
|
||||
}));
|
||||
}else{
|
||||
stack.add(new View());
|
||||
|
||||
@@ -3,6 +3,9 @@ package io.anuke.mindustry.ui.dialogs;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.scene.style.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
@@ -12,6 +15,7 @@ import io.anuke.mindustry.game.Saves.*;
|
||||
import io.anuke.mindustry.io.*;
|
||||
import io.anuke.mindustry.io.SaveIO.*;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -55,33 +59,35 @@ public class LoadDialog extends FloatingDialog{
|
||||
for(SaveSlot slot : array){
|
||||
if(slot.isHidden()) continue;
|
||||
|
||||
TextButton button = new TextButton("[accent]" + slot.getName(), "clear");
|
||||
button.getLabelCell().growX().left();
|
||||
button.getLabelCell().padBottom(8f);
|
||||
button.getLabelCell().top().left().growX();
|
||||
TextButton button = new TextButton("", "clear");
|
||||
button.getLabel().remove();
|
||||
button.clearChildren();
|
||||
|
||||
button.defaults().left();
|
||||
|
||||
button.table(t -> {
|
||||
t.right();
|
||||
button.table(title -> {
|
||||
title.add("[accent]" + slot.getName()).left().growX().width(230f).wrap();
|
||||
|
||||
t.addImageButton("icon-floppy", "emptytoggle", iconsize, () -> {
|
||||
slot.setAutosave(!slot.isAutosave());
|
||||
}).checked(slot.isAutosave()).right();
|
||||
title.table(t -> {
|
||||
t.right();
|
||||
|
||||
t.addImageButton("icon-trash", "empty", iconsize, () -> {
|
||||
ui.showConfirm("$confirm", "$save.delete.confirm", () -> {
|
||||
slot.delete();
|
||||
setup();
|
||||
});
|
||||
}).size(iconsize).right();
|
||||
t.addImageButton("icon-floppy", "emptytoggle", iconsize, () -> {
|
||||
slot.setAutosave(!slot.isAutosave());
|
||||
}).checked(slot.isAutosave()).right();
|
||||
|
||||
t.addImageButton("icon-pencil", "empty", iconsize, () -> {
|
||||
ui.showTextInput("$save.rename", "$save.rename.text", slot.getName(), text -> {
|
||||
slot.setName(text);
|
||||
setup();
|
||||
});
|
||||
}).size(iconsize).right();
|
||||
t.addImageButton("icon-trash", "empty", iconsize, () -> {
|
||||
ui.showConfirm("$confirm", "$save.delete.confirm", () -> {
|
||||
slot.delete();
|
||||
setup();
|
||||
});
|
||||
}).size(iconsize).right();
|
||||
|
||||
t.addImageButton("icon-pencil", "empty", iconsize, () -> {
|
||||
ui.showTextInput("$save.rename", "$save.rename.text", slot.getName(), text -> {
|
||||
slot.setName(text);
|
||||
setup();
|
||||
});
|
||||
}).size(iconsize).right();
|
||||
|
||||
t.addImageButton("icon-save", "empty", iconsize, () -> {
|
||||
if(!ios){
|
||||
@@ -105,26 +111,45 @@ public class LoadDialog extends FloatingDialog{
|
||||
}).size(iconsize).right();
|
||||
|
||||
|
||||
}).padRight(-10).growX();
|
||||
}).padRight(-10).growX();
|
||||
}).growX().colspan(2);
|
||||
button.row();
|
||||
|
||||
String color = "[lightgray]";
|
||||
TextureRegion def = Core.atlas.find("nomap");
|
||||
|
||||
button.left().add(new BorderImage(def, 4f)).update(i -> {
|
||||
TextureRegionDrawable draw = (TextureRegionDrawable)i.getDrawable();
|
||||
if(draw.getRegion().getTexture().isDisposed()){
|
||||
draw.setRegion(def);
|
||||
}
|
||||
|
||||
Texture text = slot.previewTexture();
|
||||
if(draw.getRegion() == def && text != null){
|
||||
draw.setRegion(new TextureRegion(text));
|
||||
}
|
||||
i.setScaling(Scaling.fit);
|
||||
}).left().size(160f).padRight(6);
|
||||
|
||||
button.table(meta -> {
|
||||
meta.left().top();
|
||||
meta.defaults().padBottom(-2).left().width(290f);
|
||||
meta.row();
|
||||
meta.labelWrap(Core.bundle.format("save.map", color + (slot.getMap() == null ? Core.bundle.get("unknown") : slot.getMap().name())));
|
||||
meta.row();
|
||||
meta.labelWrap(Core.bundle.format("save.wave", color + slot.getWave()));
|
||||
meta.row();
|
||||
meta.labelWrap(() -> Core.bundle.format("save.autosave", color + Core.bundle.get(slot.isAutosave() ? "on" : "off")));
|
||||
meta.row();
|
||||
meta.labelWrap(() -> Core.bundle.format("save.playtime", color + slot.getPlayTime()));
|
||||
meta.row();
|
||||
meta.labelWrap(Core.bundle.format("save.date", color + slot.getDate()));
|
||||
meta.row();
|
||||
}).left().growX().width(250f);
|
||||
|
||||
button.defaults().padBottom(3);
|
||||
button.row();
|
||||
button.add(Core.bundle.format("save.map", color + (slot.getMap() == null ? Core.bundle.get("unknown") : slot.getMap().name())));
|
||||
button.row();
|
||||
button.add(Core.bundle.format("save.wave", color + slot.getWave()));
|
||||
button.row();
|
||||
button.label(() -> Core.bundle.format("save.autosave", color + Core.bundle.get(slot.isAutosave() ? "on" : "off")));
|
||||
button.row();
|
||||
button.label(() -> Core.bundle.format("save.playtime", color + slot.getPlayTime()));
|
||||
button.row();
|
||||
button.add(Core.bundle.format("save.date", color + slot.getDate())).colspan(2).padTop(5).right();
|
||||
button.row();
|
||||
modifyButton(button, slot);
|
||||
|
||||
slots.add(button).uniformX().fillX().pad(4).padRight(-4).margin(10f).marginLeft(20f).marginRight(20f);
|
||||
slots.row();
|
||||
slots.add(button).uniformX().fillX().pad(4).padRight(-4).margin(10f).row();
|
||||
}
|
||||
|
||||
cont.add(pane);
|
||||
|
||||
@@ -1,30 +1,33 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.input.KeyCode;
|
||||
import io.anuke.arc.scene.event.InputEvent;
|
||||
import io.anuke.arc.scene.event.InputListener;
|
||||
import io.anuke.arc.scene.ui.layout.UnitScl;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.input.*;
|
||||
import io.anuke.arc.scene.event.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
|
||||
public class MinimapDialog extends FloatingDialog{
|
||||
|
||||
public MinimapDialog(){
|
||||
super("$minimap");
|
||||
setFillParent(false);
|
||||
setFillParent(true);
|
||||
|
||||
shown(this::setup);
|
||||
|
||||
addCloseButton();
|
||||
shouldPause = true;
|
||||
titleTable.remove();
|
||||
onResize(this::setup);
|
||||
}
|
||||
|
||||
public void drawBackground(float x, float y){
|
||||
drawDefaultBackground(x, y);
|
||||
}
|
||||
|
||||
void setup(){
|
||||
cont.clear();
|
||||
float size = Math.min(Core.graphics.getWidth(), Core.graphics.getHeight()) / UnitScl.dp.scl(1f) / 1.3f;
|
||||
cont.clearChildren();
|
||||
|
||||
cont.table("pane", t -> {
|
||||
t.addRect((x, y, width, height) -> {
|
||||
@@ -37,7 +40,7 @@ public class MinimapDialog extends FloatingDialog{
|
||||
renderer.minimap.drawEntities(x, y, width, height);
|
||||
}
|
||||
}).grow();
|
||||
}).size(size);
|
||||
}).size(Math.min(Core.graphics.getWidth() / 1.1f, Core.graphics.getHeight() / 1.3f)).padTop(-20f);
|
||||
|
||||
cont.addListener(new InputListener(){
|
||||
@Override
|
||||
@@ -45,18 +48,22 @@ public class MinimapDialog extends FloatingDialog{
|
||||
renderer.minimap.zoomBy(amounty);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
cont.addListener(new ElementGestureListener(){
|
||||
float lzoom = -1f;
|
||||
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
|
||||
return true;
|
||||
public void touchUp(InputEvent event, float x, float y, int pointer, KeyCode button){
|
||||
lzoom = renderer.minimap.getZoom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchDragged(InputEvent event, float x, float y, int pointer){
|
||||
if(mobile){
|
||||
float max = Math.min(world.width(), world.height()) / 16f / 2f;
|
||||
renderer.minimap.setZoom(1f + y / cont.getHeight() * (max - 1f));
|
||||
public void zoom(InputEvent event, float initialDistance, float distance){
|
||||
if(lzoom < 0){
|
||||
lzoom = renderer.minimap.getZoom();
|
||||
}
|
||||
renderer.minimap.setZoom(initialDistance / distance * lzoom);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user