Discord integration, basic rich presence

This commit is contained in:
BeefEX
2018-01-02 17:21:03 +01:00
parent b6845d5d10
commit 12fad819b5
9 changed files with 70 additions and 7 deletions

View File

@@ -53,6 +53,16 @@ public class AndroidLauncher extends AndroidApplication{
public void addDialog(TextField field){ public void addDialog(TextField field){
TextFieldDialogListener.add(field); TextFieldDialogListener.add(field);
} }
@Override
public void onSceneChange(String state, String details, String icon) {
}
@Override
public void onGameExit() {
}
}; };
Mindustry.donationsCallable = new Callable(){ @Override public void run(){ showDonations(); } }; Mindustry.donationsCallable = new Callable(){ @Override public void run(){ showDonations(); } };

View File

@@ -42,6 +42,7 @@ project(":desktop") {
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion" compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion"
compile "com.esotericsoftware:kryonet:2.22.0-RC1" compile "com.esotericsoftware:kryonet:2.22.0-RC1"
compile "com.github.MinnDevelopment:Java-DiscordRPC:dbd4aac"
} }
} }

View File

@@ -30,7 +30,10 @@ public class Mindustry extends ModuleCore {
@Override public String format(int number){ return number + ""; } @Override public String format(int number){ return number + ""; }
@Override public void openLink(String link){ } @Override public void openLink(String link){ }
@Override public void addDialog(TextField field){} @Override public void addDialog(TextField field){}
@Override public void onSceneChange(String state, String details, String icon) {}
@Override public void onGameExit() { }
}; };
public static boolean externalBundle = false; public static boolean externalBundle = false;
@Override @Override
@@ -45,6 +48,12 @@ public class Mindustry extends ModuleCore {
module(Vars.netClient = new NetClient()); module(Vars.netClient = new NetClient());
} }
@Override
public void dispose() {
platforms.onGameExit();
super.dispose();
}
public void loadBundle(){ public void loadBundle(){
I18NBundle.setExceptionOnMissingKey(false); I18NBundle.setExceptionOnMissingKey(false);

View File

@@ -42,7 +42,7 @@ public class Vars{
//how much the zoom changes every zoom button press //how much the zoom changes every zoom button press
public static final int zoomScale = Math.round(Unit.dp.scl(1)); public static final int zoomScale = Math.round(Unit.dp.scl(1));
//if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available //if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available
public static boolean debug = false; public static boolean debug = true;
//whether the player can clip through walls //whether the player can clip through walls
public static boolean noclip = false; public static boolean noclip = false;
//whether to draw chunk borders //whether to draw chunk borders

View File

@@ -33,6 +33,7 @@ import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.graphics.Atlas; import io.anuke.ucore.graphics.Atlas;
import io.anuke.ucore.modules.Module; import io.anuke.ucore.modules.Module;
import io.anuke.ucore.scene.ui.layout.Unit; import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Input; import io.anuke.ucore.util.Input;
import io.anuke.ucore.util.InputProxy; import io.anuke.ucore.util.InputProxy;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
@@ -75,6 +76,7 @@ public class Control extends Module{
private InputProxy proxy; private InputProxy proxy;
private float controlx, controly; private float controlx, controly;
private boolean controlling; private boolean controlling;
private Map map;
public Control(){ public Control(){
if(Mindustry.args.contains("-debug", false)) if(Mindustry.args.contains("-debug", false))
@@ -293,6 +295,10 @@ public class Control extends Module{
}); });
Timers.run(18, ()-> ui.hideLoading()); Timers.run(18, ()-> ui.hideLoading());
this.map = map;
Mindustry.platforms.onSceneChange(Bundles.get("text.playing", "Playing on map") + ": " + map.name, Bundles.get("text.wavenumber", "Wave") + " 0", "fight");
} }
public GameMode getMode(){ public GameMode getMode(){
@@ -323,6 +329,7 @@ public class Control extends Module{
} }
public void runWave(){ public void runWave(){
Mindustry.platforms.onSceneChange(Bundles.get("text.playing", "Playing on map") + ": " + map.name, Bundles.get("text.wavenumber", "Wave") + " " + wave, "fight");
if(Net.client() && Net.active()){ if(Net.client() && Net.active()){
return; return;
} }

View File

@@ -9,4 +9,6 @@ public interface PlatformFunction{
public String format(int number); public String format(int number);
public void openLink(String link); public void openLink(String link);
public void addDialog(TextField field); public void addDialog(TextField field);
public void onSceneChange(String state, String details, String icon);
public void onGameExit();
} }

View File

@@ -2,10 +2,7 @@ package io.anuke.mindustry.resource;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.DefenseBlocks; import io.anuke.mindustry.world.blocks.*;
import io.anuke.mindustry.world.blocks.DistributionBlocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.WeaponBlocks;
import static io.anuke.mindustry.resource.Section.*; import static io.anuke.mindustry.resource.Section.*;

View File

@@ -1,5 +1,8 @@
package io.anuke.mindustry.desktop; package io.anuke.mindustry.desktop;
import club.minnced.discord.rpc.DiscordEventHandlers;
import club.minnced.discord.rpc.DiscordRPC;
import club.minnced.discord.rpc.DiscordRichPresence;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
@@ -68,7 +71,31 @@ public class DesktopLauncher {
public void addDialog(TextField field){ public void addDialog(TextField field){
} }
};
@Override
public void onSceneChange(String state, String details, String icon) {
DiscordRPC lib = DiscordRPC.INSTANCE;
String applicationId = "397335883319083018";
DiscordEventHandlers handlers = new DiscordEventHandlers();
lib.Discord_Initialize(applicationId, handlers, true, "");
DiscordRichPresence presence = new DiscordRichPresence();
presence.startTimestamp = System.currentTimeMillis() / 1000; // epoch second
presence.state = state;
//presence.details = details;
presence.largeImageKey = "logo";
presence.largeImageText = details;
lib.Discord_UpdatePresence(presence);
}
@Override
public void onGameExit() {
DiscordRPC.INSTANCE.Discord_Shutdown();
}
};
Mindustry.args = Array.with(arg); Mindustry.args = Array.with(arg);

View File

@@ -112,7 +112,17 @@ public class HtmlLauncher extends GwtApplication {
public void addDialog(TextField field){ public void addDialog(TextField field){
} }
};
@Override
public void onSceneChange(String state, String details, String icon) {
}
@Override
public void onGameExit() {
}
};
return new Mindustry(); return new Mindustry();
} }