SDL backend / Valid mode sprites / Better layout
This commit is contained in:
@@ -3,7 +3,7 @@ apply plugin: "java"
|
||||
sourceCompatibility = 1.8
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
project.ext.mainClassName = "io.anuke.mindustry.desktop.DesktopLauncher"
|
||||
project.ext.mainClassName = "io.anuke.mindustry.desktopsdl.DesktopLauncher"
|
||||
project.ext.assetsDir = new File("../core/assets")
|
||||
|
||||
def IKVM_DIR = System.env.IKVM_HOME
|
||||
@@ -18,6 +18,14 @@ task run(dependsOn: classes, type: JavaExec) {
|
||||
if(System.getProperty("os.name").toLowerCase().contains("mac")){
|
||||
jvmArgs("-XstartOnFirstThread", "-Djava.awt.headless=true")
|
||||
}
|
||||
|
||||
if(project.hasProperty("args")){
|
||||
args Eval.me(project.getProperties()["args"])
|
||||
}
|
||||
|
||||
if(args.contains("debug")){
|
||||
main = "io.anuke.mindustry.DebugLauncher"
|
||||
}
|
||||
}
|
||||
|
||||
task dist(type: Jar, dependsOn: classes) {
|
||||
@@ -55,6 +63,8 @@ task ikdist{
|
||||
def args = ["mono", "$IKVM_DIR/ikvmc.exe", "-target:winexe", "-static", "-out:build/libs/${filename}.exe", "build/libs/${filename}.jar"]
|
||||
if(file("../core/assets/sprites/icon.ico").exists()){
|
||||
args += ["-win32icon:../core/assets/sprites/icon.ico"]
|
||||
}else if(file("../core/assets/icons/icon.ico").exists()){
|
||||
args += ["-win32icon:../core/assets/icons/icon.ico"]
|
||||
}
|
||||
|
||||
exec{
|
||||
|
||||
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: io.anuke.mindustry.desktopsdl.DesktopLauncher
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package io.anuke.mindustry.desktopsdl;
|
||||
import io.anuke.arc.Files.*;
|
||||
import io.anuke.arc.backends.sdl.*;
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.net.*;
|
||||
|
||||
public class DesktopLauncher{
|
||||
|
||||
public static void main(String[] arg){
|
||||
try{
|
||||
|
||||
Platform.instance = new DesktopPlatform(arg);
|
||||
|
||||
Net.setClientProvider(new ArcNetClient());
|
||||
Net.setServerProvider(new ArcNetServer());
|
||||
new SdlApplication(new Mindustry(), new SdlConfig(){{
|
||||
title = "Mindustry";
|
||||
maximized = true;
|
||||
depth = 0;
|
||||
stencil = 0;
|
||||
width = 900;
|
||||
height = 700;
|
||||
setWindowIcon(FileType.Internal, "icons/icon.png");
|
||||
}});
|
||||
}catch(Throwable e){
|
||||
DesktopPlatform.handleCrash(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package io.anuke.mindustry.desktopsdl;
|
||||
|
||||
import club.minnced.discord.rpc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.serialization.*;
|
||||
import io.anuke.mindustry.core.GameState.*;
|
||||
import io.anuke.mindustry.core.*;
|
||||
import io.anuke.mindustry.net.*;
|
||||
import io.anuke.mindustry.ui.dialogs.*;
|
||||
import sdl.*;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class DesktopPlatform extends Platform{
|
||||
static boolean useDiscord = OS.is64Bit;
|
||||
final static String applicationId = "398246104468291591";
|
||||
String[] args;
|
||||
|
||||
public DesktopPlatform(String[] args){
|
||||
this.args = args;
|
||||
|
||||
testMobile = Array.with(args).contains("-testMobile");
|
||||
|
||||
if(useDiscord){
|
||||
try{
|
||||
DiscordEventHandlers handlers = new DiscordEventHandlers();
|
||||
DiscordRPC.INSTANCE.Discord_Initialize(applicationId, handlers, true, "");
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(DiscordRPC.INSTANCE::Discord_Shutdown));
|
||||
}catch(Throwable t){
|
||||
useDiscord = false;
|
||||
Log.err("Failed to initialize discord.", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handleCrash(Throwable e){
|
||||
Consumer<Runnable> dialog = r -> new Thread(r).start();
|
||||
boolean badGPU = false;
|
||||
|
||||
if(e.getMessage() != null && (e.getMessage().contains("Couldn't create window") || e.getMessage().contains("OpenGL 2.0 or higher"))){
|
||||
|
||||
dialog.accept(() -> message(
|
||||
e.getMessage().contains("Couldn't create window") ? "A graphics initialization error has occured! Try to update your graphics drivers:\n" + e.getMessage() :
|
||||
"Your graphics card does not support OpenGL 2.0!\n" +
|
||||
"Try to update your graphics drivers.\n\n" +
|
||||
"(If that doesn't work, your computer just doesn't support Mindustry.)"));
|
||||
badGPU = true;
|
||||
}
|
||||
|
||||
boolean fbgp = badGPU;
|
||||
|
||||
CrashSender.send(e, file -> {
|
||||
if(!fbgp){
|
||||
dialog.accept(() -> message("A crash has occured. It has been saved in:\n" + file.getAbsolutePath()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showFileChooser(String text, String content, Consumer<FileHandle> cons, boolean open, Predicate<String> filetype){
|
||||
new FileChooser(text, file -> filetype.test(file.extension().toLowerCase()), open, cons).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRPC(){
|
||||
|
||||
if(!useDiscord) return;
|
||||
|
||||
DiscordRichPresence presence = new DiscordRichPresence();
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
presence.state = state.rules.pvp ? "PvP" : state.rules.waves ? "Survival" : "Attack";
|
||||
if(world.getMap() == null){
|
||||
presence.details = "Unknown Map";
|
||||
}else if(!state.rules.waves){
|
||||
presence.details = Strings.capitalize(world.getMap().name());
|
||||
}else{
|
||||
presence.details = Strings.capitalize(world.getMap().name()) + " | Wave " + state.wave;
|
||||
presence.largeImageText = "Wave " + state.wave;
|
||||
}
|
||||
|
||||
if(Net.active() && playerGroup.size() > 1){
|
||||
presence.state = (state.rules.pvp ? "PvP | " : "") + playerGroup.size() + " Players";
|
||||
}else if(state.rules.waves){
|
||||
presence.state = "Survival";
|
||||
}
|
||||
}else{
|
||||
if(ui.editor != null && ui.editor.isShown()){
|
||||
presence.state = "In Editor";
|
||||
}else{
|
||||
presence.state = "In Menu";
|
||||
}
|
||||
}
|
||||
|
||||
presence.largeImageKey = "logo";
|
||||
|
||||
DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUUID(){
|
||||
try{
|
||||
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||
NetworkInterface out;
|
||||
for(out = e.nextElement(); (out.getHardwareAddress() == null || !validAddress(out.getHardwareAddress())) && e.hasMoreElements(); out = e.nextElement());
|
||||
|
||||
byte[] bytes = out.getHardwareAddress();
|
||||
byte[] result = new byte[8];
|
||||
System.arraycopy(bytes, 0, result, 0, bytes.length);
|
||||
|
||||
String str = new String(Base64Coder.encode(result));
|
||||
|
||||
if(str.equals("AAAAAAAAAOA=")) throw new RuntimeException("Bad UUID.");
|
||||
|
||||
return str;
|
||||
}catch(Exception e){
|
||||
return super.getUUID();
|
||||
}
|
||||
}
|
||||
|
||||
private static void message(String message){
|
||||
SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MESSAGEBOX_ERROR, "oh no", message);
|
||||
}
|
||||
|
||||
private boolean validAddress(byte[] bytes){
|
||||
if(bytes == null) return false;
|
||||
byte[] result = new byte[8];
|
||||
System.arraycopy(bytes, 0, result, 0, bytes.length);
|
||||
return !new String(Base64Coder.encode(result)).equals("AAAAAAAAAOA=");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user