mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
This commit is contained in:
@@ -98,6 +98,17 @@ public final class FileUtil {
|
|||||||
return dir.delete();
|
return dir.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean deleteFile(String filename) {
|
||||||
|
try {
|
||||||
|
File file = new File(filename);
|
||||||
|
return file.delete();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void copyFile(String sourceFilename, String destFilename) {
|
public static void copyFile(String sourceFilename, String destFilename) {
|
||||||
File source = new File(sourceFilename);
|
File source = new File(sourceFilename);
|
||||||
if (!source.exists()) { return; } //if source doesn't exist, nothing to copy
|
if (!source.exists()) { return; } //if source doesn't exist, nothing to copy
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ public class Main extends AndroidApplication {
|
|||||||
|
|
||||||
AndroidAdapter adapter = new AndroidAdapter(this.getContext());
|
AndroidAdapter adapter = new AndroidAdapter(this.getContext());
|
||||||
|
|
||||||
//enforce orientation based on whether device is a tablet
|
|
||||||
adapter.setLandscapeMode(adapter.isTablet);
|
|
||||||
|
|
||||||
//establish assets directory
|
//establish assets directory
|
||||||
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||||
Gdx.app.error("Forge", "Can't access external storage");
|
Gdx.app.error("Forge", "Can't access external storage");
|
||||||
@@ -47,6 +44,16 @@ public class Main extends AndroidApplication {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//enforce orientation based on whether device is a tablet and user preference
|
||||||
|
adapter.switchOrientationFile = assetsDir + "switch_orientation.ini";
|
||||||
|
boolean landscapeMode = adapter.isTablet == !FileUtil.doesFileExist(adapter.switchOrientationFile);
|
||||||
|
if (landscapeMode) {
|
||||||
|
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
}
|
||||||
|
|
||||||
initialize(Forge.getApp(new AndroidClipboard(), adapter, assetsDir));
|
initialize(Forge.getApp(new AndroidClipboard(), adapter, assetsDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +94,7 @@ public class Main extends AndroidApplication {
|
|||||||
private class AndroidAdapter implements IDeviceAdapter {
|
private class AndroidAdapter implements IDeviceAdapter {
|
||||||
private final boolean isTablet;
|
private final boolean isTablet;
|
||||||
private final ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
private final ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
private String switchOrientationFile;
|
||||||
|
|
||||||
private AndroidAdapter(Context context) {
|
private AndroidAdapter(Context context) {
|
||||||
isTablet = (context.getResources().getConfiguration().screenLayout
|
isTablet = (context.getResources().getConfiguration().screenLayout
|
||||||
@@ -167,11 +175,12 @@ public class Main extends AndroidApplication {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLandscapeMode(boolean landscapeMode) {
|
public void setLandscapeMode(boolean landscapeMode) {
|
||||||
if (landscapeMode) {
|
//create file to indicate that portrait mode should be used for tablet or landscape should be used for phone
|
||||||
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
if (landscapeMode != isTablet) {
|
||||||
|
FileUtil.writeFile(switchOrientationFile, "1");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
FileUtil.deleteFile(switchOrientationFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package forge.app;
|
|||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglClipboard;
|
import com.badlogic.gdx.backends.lwjgl.LwjglClipboard;
|
||||||
@@ -21,11 +22,22 @@ public class Main {
|
|||||||
FileUtil.ensureDirectoryExists(assetsDir);
|
FileUtil.ensureDirectoryExists(assetsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
new LwjglApplication(Forge.getApp(new LwjglClipboard(), new DesktopAdapter(),
|
String switchOrientationFile = assetsDir + "switch_orientation.ini";
|
||||||
assetsDir), "Forge", Utils.DEV_SCREEN_WIDTH, Utils.DEV_SCREEN_HEIGHT);
|
boolean landscapeMode = FileUtil.doesFileExist(switchOrientationFile);
|
||||||
|
int screenWidth = landscapeMode ? (int)(Utils.BASE_HEIGHT * 16 / 9) : (int)Utils.BASE_WIDTH;
|
||||||
|
int screenHeight = (int)Utils.BASE_HEIGHT;
|
||||||
|
|
||||||
|
new LwjglApplication(Forge.getApp(new LwjglClipboard(), new DesktopAdapter(switchOrientationFile),
|
||||||
|
assetsDir), "Forge", screenWidth, screenHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DesktopAdapter implements IDeviceAdapter {
|
private static class DesktopAdapter implements IDeviceAdapter {
|
||||||
|
private final String switchOrientationFile;
|
||||||
|
|
||||||
|
private DesktopAdapter(String switchOrientationFile0) {
|
||||||
|
switchOrientationFile = switchOrientationFile0;
|
||||||
|
}
|
||||||
|
|
||||||
//just assume desktop always connected to wifi
|
//just assume desktop always connected to wifi
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnectedToInternet() {
|
public boolean isConnectedToInternet() {
|
||||||
@@ -73,7 +85,13 @@ public class Main {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLandscapeMode(boolean landscapeMode) {
|
public void setLandscapeMode(boolean landscapeMode) {
|
||||||
//TODO: Consider supporting toggling this on desktop for testing
|
//create file to indicate that landscape mode should be used
|
||||||
|
if (landscapeMode) {
|
||||||
|
FileUtil.writeFile(switchOrientationFile, "1");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FileUtil.deleteFile(switchOrientationFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,9 +121,16 @@ public class Forge implements ApplicationListener {
|
|||||||
openScreen(HomeScreen.instance);
|
openScreen(HomeScreen.instance);
|
||||||
splashScreen = null;
|
splashScreen = null;
|
||||||
|
|
||||||
if (isLandscapeMode()) { //open preferred new game screen by default if landscape mode
|
boolean isLandscapeMode = isLandscapeMode();
|
||||||
|
if (isLandscapeMode) { //open preferred new game screen by default if landscape mode
|
||||||
NewGameMenu.getPreferredScreen().open();
|
NewGameMenu.getPreferredScreen().open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update landscape mode preference if it doesn't match what the app loaded as
|
||||||
|
if (FModel.getPreferences().getPrefBoolean(FPref.UI_LANDSCAPE_MODE) != isLandscapeMode) {
|
||||||
|
FModel.getPreferences().setPref(FPref.UI_LANDSCAPE_MODE, isLandscapeMode);
|
||||||
|
FModel.getPreferences().save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Clipboard getClipboard() {
|
public static Clipboard getClipboard() {
|
||||||
|
|||||||
@@ -62,7 +62,9 @@ public class SettingsPage extends TabPage<SettingsScreen> {
|
|||||||
@Override
|
@Override
|
||||||
public void select() {
|
public void select() {
|
||||||
super.select();
|
super.select();
|
||||||
if (Forge.isLandscapeMode() != FModel.getPreferences().getPrefBoolean(FPref.UI_LANDSCAPE_MODE)) {
|
boolean landscapeMode = FModel.getPreferences().getPrefBoolean(FPref.UI_LANDSCAPE_MODE);
|
||||||
|
Forge.getDeviceAdapter().setLandscapeMode(landscapeMode); //ensure device able to save off ini file so landscape change takes effect
|
||||||
|
if (Forge.isLandscapeMode() != landscapeMode) {
|
||||||
FOptionPane.showConfirmDialog("You must restart Forge for this change to take effect.", "Restart Forge", "Restart", "Later", new Callback<Boolean>() {
|
FOptionPane.showConfirmDialog("You must restart Forge for this change to take effect.", "Restart Forge", "Restart", "Later", new Callback<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(Boolean result) {
|
public void run(Boolean result) {
|
||||||
|
|||||||
@@ -15,15 +15,11 @@ public class Utils {
|
|||||||
|
|
||||||
private static final float AVG_FINGER_SIZE_CM = 1.1f;
|
private static final float AVG_FINGER_SIZE_CM = 1.1f;
|
||||||
|
|
||||||
//Swap commented out line below to specify average finger size and dev screen size
|
//Swap commented out line below to specify average finger size
|
||||||
private static final float ppcX = Gdx.graphics.getPpcX(), ppcY = Gdx.graphics.getPpcY();
|
private static final float ppcX = Gdx.graphics.getPpcX(), ppcY = Gdx.graphics.getPpcY();
|
||||||
public static final int DEV_SCREEN_WIDTH = DEV_SCREEN_LANDSCAPE ? (int)(BASE_HEIGHT * 16 / 9) : (int)BASE_WIDTH;
|
|
||||||
public static final int DEV_SCREEN_HEIGHT = (int)BASE_HEIGHT;
|
|
||||||
//private static final float ppcX = 169f / AVG_FINGER_SIZE_CM, ppcY = 237f / AVG_FINGER_SIZE_CM;
|
//private static final float ppcX = 169f / AVG_FINGER_SIZE_CM, ppcY = 237f / AVG_FINGER_SIZE_CM;
|
||||||
//public static final int DEV_SCREEN_WIDTH = 400, DEV_SCREEN_HEIGHT = 600;
|
|
||||||
//private static final float scaleX = 1.41f, scaleY = 1.25f;
|
//private static final float scaleX = 1.41f, scaleY = 1.25f;
|
||||||
//private static final float ppcX = Gdx.graphics.getPpcX() * scaleX, ppcY = Gdx.graphics.getPpcY() * scaleY;
|
//private static final float ppcX = Gdx.graphics.getPpcX() * scaleX, ppcY = Gdx.graphics.getPpcY() * scaleY;
|
||||||
//public static final int DEV_SCREEN_WIDTH = (int)(BASE_WIDTH * scaleX), DEV_SCREEN_HEIGHT = (int)(BASE_HEIGHT * scaleY);
|
|
||||||
|
|
||||||
//round to nearest int to reduce floating point display issues
|
//round to nearest int to reduce floating point display issues
|
||||||
//reduce if either would take up too large a percentage of the screen to prevent layouts not working
|
//reduce if either would take up too large a percentage of the screen to prevent layouts not working
|
||||||
|
|||||||
Reference in New Issue
Block a user