Skip to content

Commit

Permalink
Changed auto full screen logic to use OS first and then fall back on …
Browse files Browse the repository at this point in the history
…touch screen.
  • Loading branch information
lanceewing committed Apr 4, 2024
1 parent a5c8e04 commit f91174d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/com/agifans/agile/AgileRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,6 @@ private void updateGameClock() {
public abstract void saveScreenshot(Agile agile, AppConfigItem appConfigItem, Pixmap pixmap);

public abstract boolean hasTouchScreen();

public abstract boolean isMobile();
}
4 changes: 2 additions & 2 deletions core/src/main/java/com/agifans/agile/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void show() {
Gdx.input.setInputProcessor(landscapeInputProcessor);
}

if (agileRunner.hasTouchScreen()) {
if (agileRunner.isMobile()) {
gameScreenInputProcessor.setJoystickAlignment(JoystickAlignment.RIGHT);

if (!Gdx.graphics.isFullscreen() && startedByUser) {
Expand Down Expand Up @@ -220,7 +220,7 @@ public void render(float delta) {
// This makes sure we update the Pixmap one last time before leaving, as that
// will mean that the AGI game screen starts out black for the next game.
copyPixels();
if (agileRunner.hasTouchScreen() && Gdx.graphics.isFullscreen()) {
if (agileRunner.isMobile() && Gdx.graphics.isFullscreen()) {
gameScreenInputProcessor.switchOutOfFullScreen();
}
agile.setScreen(agile.getHomeScreen());
Expand Down
26 changes: 26 additions & 0 deletions html/src/main/java/com/agifans/agile/gwt/GwtAgileRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,30 @@ private native boolean hasTouchScreenHtml() /*-{
return false;
}
}-*/;

@Override
public boolean isMobile() {
return isMobileHtml();
}

private native boolean isMobileHtml() /*-{
if (navigator.userAgentData) {
return navigator.userAgentData.mobile;
} else {
// Fall back to user-agent parsing, as some browsers don't support above yet.
if (navigator.platform.indexOf("Win") != -1) return false;
if (navigator.platform.indexOf("Mac") != -1) return false;
if (navigator.platform.indexOf("Android") != -1) return true;
if (navigator.platform.indexOf("iPhone") != -1) return true;
if (navigator.platform.indexOf("iPad") != -1) return true;
// For other devices, we'll use touch screen logic.
if ("maxTouchPoints" in navigator) {
return navigator.maxTouchPoints > 0;
} else if ("msMaxTouchPoints" in navigator) {
return navigator.msMaxTouchPoints > 0;
} else {
return false;
}
}
}-*/;
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ public boolean hasTouchScreen() {
// We don't check this for Desktop.
return false;
}

@Override
public boolean isMobile() {
// Desktop/Java/LWJGL platform is obviously not mobile.
return false;
}
}

0 comments on commit f91174d

Please sign in to comment.