Fixed some crashes
This commit is contained in:
@@ -11,6 +11,7 @@ import io.anuke.mindustry.core.*;
|
|||||||
import io.anuke.mindustry.game.EventType.*;
|
import io.anuke.mindustry.game.EventType.*;
|
||||||
import io.anuke.mindustry.gen.*;
|
import io.anuke.mindustry.gen.*;
|
||||||
import io.anuke.mindustry.graphics.*;
|
import io.anuke.mindustry.graphics.*;
|
||||||
|
import io.anuke.mindustry.maps.*;
|
||||||
|
|
||||||
import static io.anuke.arc.Core.*;
|
import static io.anuke.arc.Core.*;
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
@@ -35,9 +36,8 @@ public class ClientLauncher extends ApplicationCore{
|
|||||||
|
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
assets = new AssetManager();
|
assets = new AssetManager();
|
||||||
|
assets.setLoader(Texture.class, "." + mapExtension, new MapPreviewLoader());
|
||||||
atlas = TextureAtlas.blankAtlas();
|
atlas = TextureAtlas.blankAtlas();
|
||||||
assets.load("sprites/logo.png", Texture.class);
|
|
||||||
assets.finishLoading();
|
|
||||||
|
|
||||||
UI.loadDefaultFont();
|
UI.loadDefaultFont();
|
||||||
UI.loadSystemCursors();
|
UI.loadSystemCursors();
|
||||||
@@ -139,27 +139,14 @@ public class ClientLauncher extends ApplicationCore{
|
|||||||
Draw.proj().setOrtho(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
|
Draw.proj().setOrtho(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||||
|
|
||||||
float height = UnitScl.dp.scl(50f);
|
float height = UnitScl.dp.scl(50f);
|
||||||
Texture logo = Core.assets.get("sprites/logo.png");
|
|
||||||
float logoscl = UnitScl.dp.scl(1);
|
|
||||||
float logow = Math.min(logo.getWidth() * logoscl, Core.graphics.getWidth() - UnitScl.dp.scl(20));
|
|
||||||
float logoh = logow * (float)logo.getHeight() / logo.getWidth();
|
|
||||||
|
|
||||||
float fx = (int)(Core.graphics.getWidth() / 2f);
|
Draw.color(Color.BLACK);
|
||||||
float fy = (int)(Core.graphics.getHeight() - 6 - logoh) + logoh / 2 - (Core.graphics.isPortrait() ? UnitScl.dp.scl(30f) : 0f);
|
|
||||||
|
|
||||||
Draw.color();
|
|
||||||
|
|
||||||
//Draw.rect(Draw.wrap(logo), fx, fy, logow, logoh);
|
|
||||||
|
|
||||||
Lines.stroke(graphics.getWidth()*10, Color.BLACK);
|
|
||||||
Tmp.v1.set(graphics.getWidth(), graphics.getHeight()).scl(smoothProgress);
|
|
||||||
Fill.poly(graphics.getWidth()/2f, graphics.getHeight()/2f, 6, Mathf.dst(graphics.getWidth()/2f, graphics.getHeight()/2f) * smoothProgress);
|
Fill.poly(graphics.getWidth()/2f, graphics.getHeight()/2f, 6, Mathf.dst(graphics.getWidth()/2f, graphics.getHeight()/2f) * smoothProgress);
|
||||||
//Lines.line(0, 0, Tmp.v1.x, Tmp.v1.y, CapStyle.none);
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|
||||||
float w = graphics.getWidth()*0.6f;
|
float w = graphics.getWidth()*0.6f;
|
||||||
|
|
||||||
Draw.color(Pal.darkerGray);
|
Draw.color(Color.BLACK);
|
||||||
Fill.rect(graphics.getWidth()/2f, graphics.getHeight()/2f, w, height);
|
Fill.rect(graphics.getWidth()/2f, graphics.getHeight()/2f, w, height);
|
||||||
|
|
||||||
Draw.color(Pal.accent);
|
Draw.color(Pal.accent);
|
||||||
|
|||||||
@@ -32,11 +32,6 @@ public class EventType{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when the core app is first loaded. */
|
|
||||||
public static class AppLoadEvent{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DisposeEvent{
|
public static class DisposeEvent{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ public class Map implements Comparable<Map>{
|
|||||||
return Vars.mapPreviewDirectory.child(file.nameWithoutExtension() + ".png");
|
return Vars.mapPreviewDirectory.child(file.nameWithoutExtension() + ".png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileHandle cacheFile(){
|
||||||
|
return Vars.mapPreviewDirectory.child(file.nameWithoutExtension() + "-cache.dat");
|
||||||
|
}
|
||||||
|
|
||||||
public void setHighScore(int score){
|
public void setHighScore(int score){
|
||||||
Core.settings.put("hiscore" + file.nameWithoutExtension(), score);
|
Core.settings.put("hiscore" + file.nameWithoutExtension(), score);
|
||||||
Vars.data.modified();
|
Vars.data.modified();
|
||||||
@@ -124,11 +128,11 @@ public class Map implements Comparable<Map>{
|
|||||||
@Override
|
@Override
|
||||||
public int compareTo(Map map){
|
public int compareTo(Map map){
|
||||||
int type = -Boolean.compare(custom, map.custom);
|
int type = -Boolean.compare(custom, map.custom);
|
||||||
if(type != 0){
|
if(type != 0) return type;
|
||||||
return type;
|
int modes = Boolean.compare(Gamemode.pvp.valid(this), Gamemode.pvp.valid(map));
|
||||||
}else{
|
if(modes != 0) return modes;
|
||||||
return name().compareTo(map.name());
|
|
||||||
}
|
return name().compareTo(map.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,14 +3,17 @@ package io.anuke.mindustry.maps;
|
|||||||
import io.anuke.arc.*;
|
import io.anuke.arc.*;
|
||||||
import io.anuke.arc.assets.*;
|
import io.anuke.arc.assets.*;
|
||||||
import io.anuke.arc.collection.*;
|
import io.anuke.arc.collection.*;
|
||||||
|
import io.anuke.arc.collection.IntSet.*;
|
||||||
import io.anuke.arc.files.*;
|
import io.anuke.arc.files.*;
|
||||||
import io.anuke.arc.function.*;
|
import io.anuke.arc.function.*;
|
||||||
import io.anuke.arc.graphics.*;
|
import io.anuke.arc.graphics.*;
|
||||||
import io.anuke.arc.util.*;
|
import io.anuke.arc.util.*;
|
||||||
import io.anuke.arc.util.async.*;
|
import io.anuke.arc.util.async.*;
|
||||||
|
import io.anuke.arc.util.io.*;
|
||||||
import io.anuke.arc.util.serialization.*;
|
import io.anuke.arc.util.serialization.*;
|
||||||
import io.anuke.mindustry.content.*;
|
import io.anuke.mindustry.content.*;
|
||||||
import io.anuke.mindustry.game.*;
|
import io.anuke.mindustry.game.*;
|
||||||
|
import io.anuke.mindustry.game.EventType.*;
|
||||||
import io.anuke.mindustry.io.*;
|
import io.anuke.mindustry.io.*;
|
||||||
import io.anuke.mindustry.maps.MapPreviewLoader.*;
|
import io.anuke.mindustry.maps.MapPreviewLoader.*;
|
||||||
import io.anuke.mindustry.maps.filters.*;
|
import io.anuke.mindustry.maps.filters.*;
|
||||||
@@ -50,6 +53,12 @@ public class Maps{
|
|||||||
return maps.find(m -> m.name().equals(name));
|
return maps.find(m -> m.name().equals(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Maps(){
|
||||||
|
Events.on(ClientLoadEvent.class, event -> {
|
||||||
|
maps.sort();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a map from the map folder and returns it. Should only be used for zone maps.
|
* Loads a map from the map folder and returns it. Should only be used for zone maps.
|
||||||
* Does not add this map to the map list.
|
* Does not add this map to the map list.
|
||||||
@@ -299,16 +308,23 @@ public class Maps{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadPreviews(){
|
public void loadPreviews(){
|
||||||
Core.assets.setLoader(Texture.class, "." + mapExtension, new MapPreviewLoader());
|
|
||||||
for(Map map : maps){
|
for(Map map : maps){
|
||||||
//try to load preview
|
//try to load preview
|
||||||
if(map.previewFile().exists()){
|
if(map.previewFile().exists()){
|
||||||
//this may fail, but calls createNewPreview
|
//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;
|
Core.assets.load(new AssetDescriptor<>(map.previewFile().path() + "." + mapExtension, Texture.class, new MapPreviewParameter(map))).loaded = t -> map.texture = (Texture)t;
|
||||||
}else{
|
}else{
|
||||||
createNewPreview(map);
|
Core.app.post(() -> createNewPreview(map));
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
readCache(map);
|
||||||
|
}catch(Exception ignored){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createNewPreview(Map map){
|
public void createNewPreview(Map map){
|
||||||
@@ -317,11 +333,41 @@ public class Maps{
|
|||||||
//this has to be done synchronously!
|
//this has to be done synchronously!
|
||||||
Pixmap pix = MapIO.generatePreview(map);
|
Pixmap pix = MapIO.generatePreview(map);
|
||||||
Core.app.post(() -> map.texture = new Texture(pix));
|
Core.app.post(() -> map.texture = new Texture(pix));
|
||||||
executor.submit(() -> map.previewFile().writePNG(pix));
|
executor.submit(() -> {
|
||||||
|
try{
|
||||||
|
map.previewFile().writePNG(pix);
|
||||||
|
writeCache(map);
|
||||||
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
Log.err("Failed to generate preview!", e);
|
Log.err("Failed to generate preview!", e);
|
||||||
//TODO create error texture instead?
|
//TODO create error texture instead?
|
||||||
map.texture = new Texture("zones/nomap.png");
|
Core.app.post(() -> map.texture = new Texture("zones/nomap.png"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeCache(Map map) throws IOException{
|
||||||
|
try(DataOutputStream stream = new DataOutputStream(map.cacheFile().write(false, Streams.DEFAULT_BUFFER_SIZE))){
|
||||||
|
stream.write(0);
|
||||||
|
stream.writeInt(map.spawns);
|
||||||
|
stream.write(map.teams.size);
|
||||||
|
IntSetIterator iter = map.teams.iterator();
|
||||||
|
while(iter.hasNext){
|
||||||
|
stream.write(iter.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readCache(Map map) throws IOException{
|
||||||
|
try(DataInputStream stream = new DataInputStream(map.cacheFile().read(Streams.DEFAULT_BUFFER_SIZE))){
|
||||||
|
stream.read(); //version
|
||||||
|
map.spawns = stream.readInt();
|
||||||
|
int teamsize = stream.readByte();
|
||||||
|
for(int i = 0; i < teamsize; i++){
|
||||||
|
map.teams.add(stream.read());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +389,7 @@ public class Maps{
|
|||||||
}
|
}
|
||||||
|
|
||||||
maps.add(map);
|
maps.add(map);
|
||||||
//maps.sort();
|
maps.sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadCustomMaps(){
|
private void loadCustomMaps(){
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import io.anuke.mindustry.game.Version;
|
|||||||
import io.anuke.mindustry.graphics.MenuRenderer;
|
import io.anuke.mindustry.graphics.MenuRenderer;
|
||||||
import io.anuke.mindustry.ui.MobileButton;
|
import io.anuke.mindustry.ui.MobileButton;
|
||||||
|
|
||||||
|
import static io.anuke.arc.Core.assets;
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class MenuFragment extends Fragment{
|
public class MenuFragment extends Fragment{
|
||||||
@@ -27,24 +28,13 @@ public class MenuFragment extends Fragment{
|
|||||||
private MenuRenderer renderer;
|
private MenuRenderer renderer;
|
||||||
|
|
||||||
public MenuFragment(){
|
public MenuFragment(){
|
||||||
|
assets.load("sprites/logo.png", Texture.class);
|
||||||
|
assets.finishLoading();
|
||||||
Events.on(DisposeEvent.class, event -> {
|
Events.on(DisposeEvent.class, event -> {
|
||||||
renderer.dispose();
|
renderer.dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawLogo(){
|
|
||||||
Texture logo = Core.assets.get("sprites/logo.png");
|
|
||||||
float logoscl = UnitScl.dp.scl(1);
|
|
||||||
float logow = Math.min(logo.getWidth() * logoscl, Core.graphics.getWidth() - UnitScl.dp.scl(20));
|
|
||||||
float logoh = logow * (float)logo.getHeight() / logo.getWidth();
|
|
||||||
|
|
||||||
float fx = (int)(Core.graphics.getWidth() / 2f);
|
|
||||||
float fy = (int)(Core.graphics.getHeight() - 6 - logoh) + logoh / 2 - (Core.graphics.isPortrait() ? UnitScl.dp.scl(30f) : 0f);
|
|
||||||
|
|
||||||
Draw.color();
|
|
||||||
Draw.rect(Draw.wrap(logo), fx, fy, logow, logoh);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Group parent){
|
public void build(Group parent){
|
||||||
renderer = new MenuRenderer();
|
renderer = new MenuRenderer();
|
||||||
|
|||||||
Reference in New Issue
Block a user