Skip to content

Commit

Permalink
Added automatic switch to full screen for web mobile when game is sta…
Browse files Browse the repository at this point in the history
…rted.
  • Loading branch information
lanceewing committed Mar 23, 2024
1 parent 99eea40 commit b9ffd0b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/com/agifans/agile/AgileRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,5 @@ private void updateGameClock() {

public abstract void saveScreenshot(Agile agile, AppConfigItem appConfigItem, Pixmap pixmap);

public abstract boolean hasTouchScreen();
}
9 changes: 8 additions & 1 deletion core/src/main/java/com/agifans/agile/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public void show() {
Gdx.input.setInputProcessor(landscapeInputProcessor);
}

if (agileRunner.hasTouchScreen() && !Gdx.graphics.isFullscreen()) {
gameScreenInputProcessor.switchIntoFullScreen();
}

agileRunner.start(appConfigItem.getFilePath());
}

Expand All @@ -207,7 +211,10 @@ 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();
agile.setScreen(agile.getHomeScreen());;
if (agileRunner.hasTouchScreen() && Gdx.graphics.isFullscreen()) {
gameScreenInputProcessor.switchOutOfFullScreen();
}
agile.setScreen(agile.getHomeScreen());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,9 @@ else if ((touchXY.y > 0) && (touchXY.y < 128)) {
if (fullScreenClicked) {
Boolean fullScreen = Gdx.graphics.isFullscreen();
if (fullScreen == true) {
if (screenWidthBeforeFullScreen > screenHeightBeforeFullScreen) {
keyboardType = KeyboardType.OFF;
}
switchOutOfFullScreen();
}
else {
keyboardType = KeyboardType.OFF;
switchIntoFullScreen();
}
}
Expand All @@ -427,7 +423,8 @@ public void no() {
* Switches to full screen mode, storing the width and height beforehand so
* that it can be restored when switching back.
*/
private void switchIntoFullScreen() {
public void switchIntoFullScreen() {
keyboardType = KeyboardType.OFF;
Graphics.DisplayMode currentMode = Gdx.graphics.getDisplayMode();
screenWidthBeforeFullScreen = Gdx.graphics.getWidth();
screenHeightBeforeFullScreen = Gdx.graphics.getHeight();
Expand All @@ -438,7 +435,10 @@ private void switchIntoFullScreen() {
* Switches out of full screen mode back to the windowed mode, restoring the
* saved width and height.
*/
private void switchOutOfFullScreen() {
public void switchOutOfFullScreen() {
if (screenWidthBeforeFullScreen > (screenHeightBeforeFullScreen * 1.32f)) {
keyboardType = KeyboardType.OFF;
}
Gdx.graphics.setWindowedMode(screenWidthBeforeFullScreen, screenHeightBeforeFullScreen);
}

Expand Down
15 changes: 15 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 @@ -277,4 +277,19 @@ public void saveScreenshot(Agile agile, AppConfigItem appConfigItem, Pixmap pixm
// TODO Auto-generated method stub

}

@Override
public boolean hasTouchScreen() {
return hasTouchScreenHtml();
}

private native boolean hasTouchScreenHtml() /*-{
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 @@ -132,4 +132,10 @@ public void saveScreenshot(Agile agile, AppConfigItem appConfigItem, Pixmap scre
}
}
}

@Override
public boolean hasTouchScreen() {
// We don't check this for Desktop.
return false;
}
}

0 comments on commit b9ffd0b

Please sign in to comment.