v0.8.0: added window size/fullscreen support to desktop, refactored landscape code

This commit is contained in:
Evan Debenham
2019-10-29 13:04:14 -04:00
parent f038bde5cc
commit b88036da0b
27 changed files with 182 additions and 85 deletions

View File

@@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.watabou.noosa.Game;
import com.watabou.utils.FileUtils;
import com.watabou.utils.Point;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -94,8 +95,14 @@ public class DesktopLauncher {
SPDSettings.set( new Lwjgl3Preferences( "pd-prefs", basePath) );
FileUtils.setDefaultFileProperties( Files.FileType.External, basePath );
config.setWindowSizeLimits( 800, 450, -1, -1 );
config.setWindowedMode( 1920, 1080 );
config.setWindowSizeLimits( 960, 640, -1, -1 );
Point p = SPDSettings.windowResolution();
config.setWindowedMode( p.x, p.y );
config.setAutoIconify( true );
//we set fullscreen/maximized in the listener as doing it through the config seems to be buggy
DesktopWindowListener listener = new DesktopWindowListener();
config.setWindowListener( listener );
new Lwjgl3Application(new ShatteredPixelDungeon(new DesktopPlatformSupport()), config);
}

View File

@@ -26,8 +26,10 @@ import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.watabou.noosa.Game;
import com.watabou.utils.PlatformSupport;
import com.watabou.utils.Point;
import java.util.HashMap;
import java.util.regex.Pattern;
@@ -36,12 +38,24 @@ public class DesktopPlatformSupport extends PlatformSupport {
@Override
public void updateDisplaySize() {
if (!SPDSettings.fullscreen()) {
SPDSettings.windowResolution( new Point( Game.width, Game.height ) );
}
}
@Override
public void updateSystemUI() {
Gdx.app.postRunnable( new Runnable() {
@Override
public void run () {
if (SPDSettings.fullscreen()){
Gdx.graphics.setFullscreenMode( Gdx.graphics.getDisplayMode() );
} else {
Point p = SPDSettings.windowResolution();
Gdx.graphics.setWindowedMode( p.x, p.y );
}
}
} );
}
@Override

View File

@@ -0,0 +1,58 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.desktop;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowListener;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
public class DesktopWindowListener implements Lwjgl3WindowListener {
@Override
public void created ( Lwjgl3Window lwjgl3Window ) {
if (SPDSettings.fullscreen()){
lwjgl3Window.postRunnable( new Runnable() {
@Override
public void run () {
Gdx.graphics.setFullscreenMode( Gdx.graphics.getDisplayMode() );
}
} );
}
if (SPDSettings.windowMaximized()) {
lwjgl3Window.maximizeWindow();
}
}
@Override
public void maximized ( boolean b ) {
SPDSettings.windowMaximized( b );
}
@Override
public void iconified ( boolean b ) { }
public void focusLost () { }
public void focusGained () { }
public boolean closeRequested () { return true; }
public void filesDropped ( String[] strings ) { }
public void refreshRequested () { }
}