mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-05 15:58:14 +07:00
Added sharing for iOS saves, fixed icons
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
@ -61,8 +61,8 @@ public abstract class Platform {
|
||||
}
|
||||
return Base64Coder.decode(uuid);
|
||||
}
|
||||
/**Only used for iOS or android: open the share menu for a map pixmap.*/
|
||||
public void shareImage(Pixmap pixmap){}
|
||||
/**Only used for iOS or android: open the share menu for a map or save.*/
|
||||
public void shareFile(FileHandle file){}
|
||||
/**Use the default thread provider from the kryonet module for this.*/
|
||||
public ThreadProvider getThreadProvider(){
|
||||
return new ThreadProvider() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.mapeditor;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
@ -235,8 +236,14 @@ public class MapEditorDialog extends Dialog{
|
||||
//iOS doesn't really support saving raw files. Sharing is used instead.
|
||||
if(!ios){
|
||||
saveFile.show();
|
||||
}else {
|
||||
Platform.instance.shareImage(editor.pixmap());
|
||||
}else{
|
||||
try{
|
||||
FileHandle file = Gdx.files.local(("map-" + ((editor.getMap().name == null) ? "unknown" : editor.getMap().name) + ".png"));
|
||||
Pixmaps.write(editor.pixmap(), file);
|
||||
Platform.instance.shareFile(file);
|
||||
}catch (Exception e){
|
||||
ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false)));
|
||||
}
|
||||
}
|
||||
}).text("$text.editor.saveimage");
|
||||
|
||||
|
@ -25,7 +25,6 @@ public class ChangelogDialog extends FloatingDialog{
|
||||
content().add("$text.changelog.loading");
|
||||
|
||||
if(!ios) {
|
||||
|
||||
Changelogs.getChangelog(result -> {
|
||||
versions = result;
|
||||
Gdx.app.postRunnable(this::setup);
|
||||
|
@ -1,7 +1,10 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.io.Saves.SaveSlot;
|
||||
import io.anuke.ucore.core.Core;
|
||||
@ -83,14 +86,24 @@ public class LoadDialog extends FloatingDialog{
|
||||
|
||||
if(!gwt) {
|
||||
t.addImageButton("icon-save", "empty", 14 * 3, () -> {
|
||||
new FileChooser("$text.save.export", false, file -> {
|
||||
try {
|
||||
slot.exportFile(file);
|
||||
setup();
|
||||
} catch (IOException e) {
|
||||
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}).show();
|
||||
if(!ios) {
|
||||
new FileChooser("$text.save.export", false, file -> {
|
||||
try {
|
||||
slot.exportFile(file);
|
||||
setup();
|
||||
} catch (IOException e) {
|
||||
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}).show();
|
||||
}else{
|
||||
try {
|
||||
FileHandle file = Gdx.files.local("save-" + slot.getName() + ".mins");
|
||||
slot.exportFile(file);
|
||||
Platform.instance.shareFile(file);
|
||||
}catch (Exception e){
|
||||
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}
|
||||
}).size(14 * 3).right();
|
||||
}
|
||||
|
||||
@ -134,7 +147,7 @@ public class LoadDialog extends FloatingDialog{
|
||||
|
||||
slots.row();
|
||||
|
||||
if(gwt) return;
|
||||
if(gwt || ios) return;
|
||||
|
||||
slots.addImageTextButton("$text.save.import", "icon-add", "clear", 14*3, () -> {
|
||||
new FileChooser("$text.save.import", f -> f.extension().equals("mins"), true, file -> {
|
||||
|
@ -67,6 +67,27 @@
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
|
||||
<key>UTExportedTypeDeclarations</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UTTypeConformsTo</key>
|
||||
<array>
|
||||
<string>public.data</string>
|
||||
</array>
|
||||
<key>UTTypeDescription</key>
|
||||
<string>Mindustry Save File</string>
|
||||
<key>UTTypeIdentifier</key>
|
||||
<string>io.anuke.mindustry.savefile</string>
|
||||
<key>UTTypeTagSpecification</key>
|
||||
<dict>
|
||||
<key>public.filename-extension</key>
|
||||
<string>mins</string>
|
||||
<key>public.mime-type</key>
|
||||
<string>mindustry/mins</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</array>
|
||||
<!--<key>CFBundleIcons</key>
|
||||
<dict>
|
||||
<key>CFBundlePrimaryIcon</key>
|
||||
|
@ -17,8 +17,9 @@
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-87.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
@ -38,8 +39,9 @@
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-180.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
|
BIN
ios/data/Assets.xcassets/AppIcon.appiconset/icon-180.png
Normal file
BIN
ios/data/Assets.xcassets/AppIcon.appiconset/icon-180.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
BIN
ios/data/Assets.xcassets/AppIcon.appiconset/icon-87.png
Normal file
BIN
ios/data/Assets.xcassets/AppIcon.appiconset/icon-87.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
ios/data/icon-180.png
Normal file
BIN
ios/data/icon-180.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
BIN
ios/data/icon-87.png
Normal file
BIN
ios/data/icon-87.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
@ -4,18 +4,18 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
|
||||
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.PixmapIO;
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import io.anuke.kryonet.DefaultThreadImpl;
|
||||
import io.anuke.kryonet.KryoClient;
|
||||
import io.anuke.kryonet.KryoServer;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.core.ThreadHandler;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
import org.robovm.apple.foundation.NSAutoreleasePool;
|
||||
import org.robovm.apple.foundation.NSURL;
|
||||
import org.robovm.apple.uikit.UIActivityViewController;
|
||||
@ -23,6 +23,7 @@ import org.robovm.apple.uikit.UIApplication;
|
||||
import org.robovm.apple.uikit.UIApplicationLaunchOptions;
|
||||
import org.robovm.apple.uikit.UIApplicationOpenURLOptions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -30,6 +31,7 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import static io.anuke.mindustry.Vars.control;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public class IOSLauncher extends IOSApplication.Delegate {
|
||||
@ -74,14 +76,12 @@ public class IOSLauncher extends IOSApplication.Delegate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shareImage(Pixmap image){
|
||||
FileHandle file = Gdx.files.local("tmp-img.pmh");
|
||||
public void shareFile(FileHandle file){
|
||||
NSURL url = new NSURL(file.file());
|
||||
PixmapIO.writePNG(file, image);
|
||||
UIActivityViewController p = new UIActivityViewController(Collections.singletonList(url), null);
|
||||
|
||||
UIApplication.getSharedApplication().getKeyWindow().getRootViewController()
|
||||
.presentViewController(p, true, () -> Log.info("Success! Presented someting."));
|
||||
.presentViewController(p, true, () -> io.anuke.ucore.util.Log.info("Success! Presented {0}", file));
|
||||
}
|
||||
};
|
||||
|
||||
@ -109,12 +109,30 @@ public class IOSLauncher extends IOSApplication.Delegate {
|
||||
}
|
||||
|
||||
void openURL(NSURL url){
|
||||
Timers.runTask(30f, () -> {
|
||||
if(!ui.editor.isShown()){
|
||||
ui.editor.show();
|
||||
}
|
||||
ui.editor.tryLoadMap(Gdx.files.absolute(url.getAbsoluteString()));
|
||||
});
|
||||
String str = url.getAbsoluteString().toLowerCase();
|
||||
|
||||
if(str.endsWith("mins")){ //open save
|
||||
Timers.runTask(30f, () -> {
|
||||
FileHandle file = Gdx.files.absolute(url.getAbsoluteString());
|
||||
|
||||
if(SaveIO.isSaveValid(file)){
|
||||
try{
|
||||
control.getSaves().importSave(file);
|
||||
}catch (IOException e){
|
||||
ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}else{
|
||||
ui.showError("$text.save.import.invalid");
|
||||
}
|
||||
});
|
||||
}else if(str.endsWith("png")){ //open map
|
||||
Timers.runTask(30f, () -> {
|
||||
if(!ui.editor.isShown()){
|
||||
ui.editor.show();
|
||||
}
|
||||
ui.editor.tryLoadMap(Gdx.files.absolute(url.getAbsoluteString()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] argv) {
|
||||
|
Reference in New Issue
Block a user