Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 58 additions & 19 deletions forge-gui-mobile-dev/src/forge/app/GameLauncher.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package forge.app;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Graphics.DisplayMode;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Clipboard;
Expand Down Expand Up @@ -58,28 +59,60 @@ public GameLauncher(final String versionString, final String[] args) {
}

// Retrieve command line parameters
int windowHeight = 0;
int windowWidth = 0;
boolean isPortrait = false;
boolean manualWindowSize = false;
Integer widthArg = null;
Integer heightArg = null;
boolean portraitArg = false;
boolean landscapeArg = false;
for(String arg : args) {
if(arg.startsWith("width=")) {
windowWidth = Integer.parseInt(arg.substring(6));
manualWindowSize = true;
}
if(arg.startsWith("height=")) {
windowHeight = Integer.parseInt(arg.substring(7));
manualWindowSize = true;
}
if(arg.equalsIgnoreCase("portrait")) {
isPortrait = true;
}
if(arg.startsWith("width=")) widthArg = Integer.parseInt(arg.substring(6));
else if(arg.startsWith("height=")) heightArg = Integer.parseInt(arg.substring(7));
else if(arg.equalsIgnoreCase("portrait")) portraitArg = true;
else if(arg.equalsIgnoreCase("landscape")) landscapeArg = true;
}

// Check if the manually supplied window size indicates portrait mode
if ((windowHeight > 0) && (windowWidth > 0)) {
if (windowHeight > windowWidth) {
isPortrait = true;
boolean hasAnyDimArg = (widthArg != null || heightArg != null);
boolean hasBothDims = (widthArg != null && heightArg != null);

boolean manualWindowSize = hasAnyDimArg;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should clean up some of these booleans
these command line arguments don't really need their own ones if you're just going to reassign them to another anyway
just makes things messier


// Only disable desktop auto-orientation when the user *really* overrides it
boolean overrideOrientation = portraitArg || landscapeArg || hasBothDims;
Forge.setDesktopAutoOrientation(!overrideOrientation);

// Determine desired portrait/landscape only if we are overriding orientation.
boolean isPortrait = false;
if (portraitArg) isPortrait = true;
else if (landscapeArg) isPortrait = false;
else if (hasBothDims) isPortrait = (heightArg > widthArg);

// Initialize window size
int windowWidth = 0, windowHeight = 0;

if (manualWindowSize) {
float aspect = getPrimaryScreenAspect(); // width/height

// If explicit portrait/landscape requested, coerce aspect direction
if (portraitArg && aspect > 1f) aspect = 1f / aspect;
if (landscapeArg && aspect < 1f) aspect = 1f / aspect;

if (widthArg != null && heightArg == null) {
windowWidth = widthArg;
windowHeight = Math.max(1, Math.round(windowWidth / aspect));
} else if (heightArg != null && widthArg == null) {
windowHeight = heightArg;
windowWidth = Math.max(1, Math.round(windowHeight * aspect));
} else { // both provided
windowWidth = widthArg;
windowHeight = heightArg;
}

// If user explicitly overrode orientation (portrait/landscape or both dims), normalize by swapping
if (overrideOrientation) {
if (isPortrait && windowHeight < windowWidth) {
int tmp = windowHeight; windowHeight = windowWidth; windowWidth = tmp;
} else if (!isPortrait && windowWidth < windowHeight) {
int tmp = windowHeight; windowHeight = windowWidth; windowWidth = tmp;
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo if the size from settings is used it shouldn't be messed with
or at the very least only if the orientation arguments are actually provided
otherwise you're making it more difficult to freely combine both parts in case the screen size is big enough for either mode

Expand Down Expand Up @@ -138,4 +171,10 @@ public void focusLost() {

new Lwjgl3Application(start, config);
}

private static float getPrimaryScreenAspect() {
DisplayMode dm = Lwjgl3ApplicationConfiguration.getDisplayMode();
if (dm == null || dm.height == 0) return 16f / 9f; // sane fallback
return (float) dm.width / (float) dm.height; // width/height
}
}
10 changes: 10 additions & 0 deletions forge-gui-mobile/src/forge/Forge.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class Forge implements ApplicationListener {
public static boolean forcedEnglishonCJKMissing = false;
public static boolean createNewAdventureMap = false;
private static Localizer localizer;
private static boolean desktopAutoOrientation = true;

public static ApplicationListener getApp(HWInfo hwInfo, Clipboard clipboard0, IDeviceAdapter deviceAdapter0, String assetDir0, boolean propertyConfig, boolean androidOrientation, int totalRAM, boolean isTablet, int AndroidAPI) {
if (app == null) {
Expand Down Expand Up @@ -191,6 +192,11 @@ public void create() {
screenWidth = Gdx.app.getGraphics().getWidth();
screenHeight = Gdx.app.getGraphics().getHeight();

// Desktop default: auto-detect from initial window/backbuffer aspect ratio
if (!GuiBase.isAndroid() && desktopAutoOrientation) {
isPortraitMode = screenHeight > screenWidth;
}

Gdx.input.setInputProcessor(inputProcessor);
/*
Set CatchBackKey here and exit the app when you hit the
Expand Down Expand Up @@ -1659,4 +1665,8 @@ private void translateButtons(Controller controller, int buttonIndex, boolean ke
if (Controllers.getCurrent() != null)
System.out.println("Gamepad: " + Controllers.getCurrent().getName());
}

public static void setDesktopAutoOrientation(boolean auto) {
desktopAutoOrientation = auto;
}
}