diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Scene.java b/SPD-classes/src/main/java/com/watabou/noosa/Scene.java index 7eb4871a6..10542d3a3 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Scene.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Scene.java @@ -62,6 +62,10 @@ public class Scene extends Group { } + public static boolean landscape(){ + return Game.width > Game.height; + } + @Override public void update() { super.update(); diff --git a/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java b/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java index c3b36675a..92fc3a36d 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java +++ b/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java @@ -21,6 +21,7 @@ package com.watabou.utils; +import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; import com.watabou.noosa.Game; @@ -34,10 +35,14 @@ public class DeviceCompat { return Gdx.app.getVersion() >= 19; default: //TODO implement functionality for other platforms here - return false; + return true; } } + public static boolean isDesktop(){ + return Gdx.app.getType() == Application.ApplicationType.Desktop; + } + public static boolean legacyDevice(){ switch (Gdx.app.getType()){ case Android: diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java index 4ee0d702e..04cbe92f6 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java @@ -70,12 +70,10 @@ public class AndroidGame extends AndroidApplication { SPDSettings.set(instance.getPreferences("ShatteredPixelDungeon")); //set desired orientation (if it exists) before initializing the app. - if (SPDSettings.landscapeFromSettings() != null) { - if (SPDSettings.landscapeFromSettings()){ - instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); - } else { - instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); - } + if (SPDSettings.landscape() != null) { + AndroidGame.instance.setRequestedOrientation( SPDSettings.landscape() ? + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : + ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT ); } AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java index 07f219f63..f84b56c05 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java @@ -45,11 +45,11 @@ import java.util.regex.Pattern; public class AndroidPlatformSupport extends PlatformSupport { public void updateDisplaySize(){ - boolean landscape = SPDSettings.landscape(); - - AndroidGame.instance.setRequestedOrientation(landscape ? - ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : - ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); + if (SPDSettings.landscape() != null) { + AndroidGame.instance.setRequestedOrientation( SPDSettings.landscape() ? + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : + ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT ); + } if (AndroidGame.view.getMeasuredWidth() == 0 || AndroidGame.view.getMeasuredHeight() == 0) return; @@ -57,7 +57,7 @@ public class AndroidPlatformSupport extends PlatformSupport { Game.dispWidth = AndroidGame.view.getMeasuredWidth(); Game.dispHeight = AndroidGame.view.getMeasuredHeight(); - if ((Game.dispWidth > Game.dispHeight) != landscape){ + if ((Game.dispWidth >= Game.dispHeight) != PixelScene.landscape()){ int tmp = Game.dispWidth; Game.dispWidth = Game.dispHeight; Game.dispHeight = tmp; diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/windows/WndAndroidTextInput.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/windows/WndAndroidTextInput.java index cd0e9484c..12f5ebe77 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/windows/WndAndroidTextInput.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/windows/WndAndroidTextInput.java @@ -71,14 +71,14 @@ public class WndAndroidTextInput extends Window { super(); //need to offset to give space for the soft keyboard - if (SPDSettings.landscape()) { + if (PixelScene.landscape()) { offset( multiLine ? -45 : -45 ); } else { offset( multiLine ? -60 : -45 ); } final int width; - if (SPDSettings.landscape() && multiLine){ + if (PixelScene.landscape() && multiLine){ width = W_LAND_MULTI; //more editing space for landscape users } else { width = WIDTH; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java index ea884952c..5780249d7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java @@ -23,10 +23,11 @@ package com.shatteredpixel.shatteredpixeldungeon; import com.shatteredpixel.shatteredpixeldungeon.messages.Languages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; -import com.watabou.noosa.Game; +import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Sample; import com.watabou.utils.GameSettings; +import com.watabou.utils.Point; import java.util.Locale; @@ -69,13 +70,9 @@ public class SPDSettings extends GameSettings { ((ShatteredPixelDungeon)ShatteredPixelDungeon.instance).updateDisplaySize(); } - //FIXME in certain multi-window cases this can disagree with the actual screen size - //there should be an option to check for landscape the setting, and actual screen size - public static boolean landscape() { - return getBoolean(KEY_LANDSCAPE, Game.dispWidth > Game.dispHeight); - } - - public static Boolean landscapeFromSettings(){ + //can return null because we need to directly handle the case of landscape not being set + // as there are different defaults for different devices + public static Boolean landscape(){ if (contains(KEY_LANDSCAPE)){ return getBoolean(KEY_LANDSCAPE, false); } else { @@ -154,7 +151,7 @@ public class SPDSettings extends GameSettings { } public static String toolbarMode() { - return getString(KEY_BARMODE, !SPDSettings.landscape() ? "SPLIT" : "GROUP"); + return getString(KEY_BARMODE, PixelScene.landscape() ? "GROUP" : "SPLIT"); } //Game State @@ -257,4 +254,30 @@ public class SPDSettings extends GameSettings { (language() == Languages.KOREAN || language() == Languages.CHINESE || language() == Languages.JAPANESE)); } + //Window management (desktop only atm) + + public static final String KEY_WINDOW_WIDTH = "window_width"; + public static final String KEY_WINDOW_HEIGHT = "window_height"; + public static final String KEY_WINDOW_MAXIMIZED = "window_maximized"; + + public static void windowResolution( Point p ){ + put(KEY_WINDOW_WIDTH, p.x); + put(KEY_WINDOW_HEIGHT, p.y); + } + + public static Point windowResolution(){ + return new Point( + getInt( KEY_WINDOW_WIDTH, 960 ), + getInt( KEY_WINDOW_HEIGHT, 640 ) + ); + } + + public static void windowMaximized( boolean value ){ + put( KEY_WINDOW_MAXIMIZED, value ); + } + + public static boolean windowMaximized(){ + return getBoolean( KEY_WINDOW_MAXIMIZED, false ); + } + } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java index dd8e36c1d..d048718e1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.Flare; import com.shatteredpixel.shatteredpixeldungeon.ui.Archs; @@ -56,9 +55,9 @@ public class AboutScene extends PixelScene { public void create() { super.create(); - final float colWidth = Camera.main.width / (SPDSettings.landscape() ? 2 : 1); - final float colTop = (Camera.main.height / 2) - (SPDSettings.landscape() ? 30 : 90); - final float wataOffset = SPDSettings.landscape() ? colWidth : 0; + final float colWidth = Camera.main.width / (landscape() ? 2 : 1); + final float colTop = (Camera.main.height / 2) - (landscape() ? 30 : 90); + final float wataOffset = landscape() ? colWidth : 0; Image shpx = Icons.SHPX.get(); shpx.x = (colWidth - shpx.width()) / 2; @@ -103,9 +102,7 @@ public class AboutScene extends PixelScene { Image wata = Icons.WATA.get(); wata.x = wataOffset + (colWidth - wata.width()) / 2; - wata.y = SPDSettings.landscape() ? - colTop: - shpxlink.top() + wata.height + 20; + wata.y = landscape() ? colTop: shpxlink.top() + wata.height + 20; align(wata); add( wata ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java index 0f9c3b219..ea45cc25f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java @@ -25,7 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; @@ -258,7 +257,7 @@ public class AlchemyScene extends PixelScene { { WndJournal.AlchemyTab t = new WndJournal.AlchemyTab(); int w, h; - if (SPDSettings.landscape()) { + if (landscape()) { w = WndJournal.WIDTH_L; h = WndJournal.HEIGHT_L; } else { w = WndJournal.WIDTH_P; h = WndJournal.HEIGHT_P; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java index 755b3fed1..11e6a83f6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java @@ -23,7 +23,6 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Badges; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; @@ -83,8 +82,8 @@ public class BadgesScene extends PixelScene { blankBadges = Math.max(0, blankBadges); //guarantees a max of 5 rows in landscape, and 8 in portrait, assuming a max of 40 buttons - int nCols = SPDSettings.landscape() ? 7 : 4; - if (badges.size() + blankBadges > 32 && !SPDSettings.landscape()) nCols++; + int nCols = landscape() ? 7 : 4; + if (badges.size() + blankBadges > 32 && !landscape()) nCols++; int nRows = 1 + (blankBadges + badges.size())/nCols; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java index d16f5e32d..afacd6e6e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java @@ -74,7 +74,7 @@ public class PixelScene extends Scene { GameScene.scene = null; float minWidth, minHeight; - if (SPDSettings.landscape()) { + if (landscape()) { minWidth = MIN_WIDTH_L; minHeight = MIN_HEIGHT_L; } else { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java index bb73ff07c..97bf3e392 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java @@ -24,7 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.GamesInProgress; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass; import com.shatteredpixel.shatteredpixeldungeon.journal.Journal; @@ -80,12 +79,12 @@ public class StartScene extends PixelScene { ArrayList games = GamesInProgress.checkAll(); - int slotGap = SPDSettings.landscape() ? 5 : 10; + int slotGap = landscape() ? 5 : 10; int slotCount = Math.min(GamesInProgress.MAX_SLOTS, games.size()+1); int slotsHeight = slotCount*SLOT_HEIGHT + (slotCount-1)* slotGap; float yPos = (h - slotsHeight)/2f; - if (SPDSettings.landscape()) yPos += 8; + if (landscape()) yPos += 8; for (GamesInProgress.Info game : games) { SaveSlotButton existingGame = new SaveSlotButton(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java index ccc46f06f..efbb986b1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java @@ -24,7 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.GamesInProgress; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites; import com.shatteredpixel.shatteredpixeldungeon.effects.Fireball; @@ -69,7 +68,7 @@ public class TitleScene extends PixelScene { float topRegion = Math.max(title.height, h*0.45f); title.x = (w - title.width()) / 2f; - if (SPDSettings.landscape()) { + if (landscape()) { title.y = (topRegion - title.height()) / 2f; } else { title.y = 20 + (topRegion - title.height() - 20) / 2f; @@ -181,11 +180,11 @@ public class TitleScene extends PixelScene { add(btnAbout); final int BTN_HEIGHT = 21; - int GAP = (int)(h - topRegion - (SPDSettings.landscape() ? 3 : 4)*BTN_HEIGHT)/3; - GAP /= SPDSettings.landscape() ? 3 : 4; + int GAP = (int)(h - topRegion - (landscape() ? 3 : 4)*BTN_HEIGHT)/3; + GAP /= landscape() ? 3 : 4; GAP = Math.max(GAP, 2); - if (SPDSettings.landscape()) { + if (landscape()) { btnPlay.setRect(title.x-50, topRegion+GAP, ((title.width()+100)/2)-1, BTN_HEIGHT); align(btnPlay); btnSupport.setRect(btnPlay.right()+2, btnPlay.top(), btnPlay.width(), BTN_HEIGHT); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java index 4170d38eb..0659254d3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java @@ -68,7 +68,7 @@ public class WelcomeScene extends PixelScene { float topRegion = Math.max(title.height, h*0.45f); title.x = (w - title.width()) / 2f; - if (SPDSettings.landscape()) { + if (landscape()) { title.y = (topRegion - title.height()) / 2f; } else { title.y = 20 + (topRegion - title.height() - 20) / 2f; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index 737bd3c9a..24a262c8a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -23,7 +23,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; @@ -131,7 +130,7 @@ public class WndBag extends WndTabbed { lastMode = mode; lastBag = bag; - nCols = SPDSettings.landscape() ? COLS_L : COLS_P; + nCols = PixelScene.landscape() ? COLS_L : COLS_P; nRows = (int)Math.ceil((Belongings.BACKPACK_SIZE + 4) / (float)nCols); int slotsWidth = SLOT_WIDTH * nCols + SLOT_MARGIN * (nCols - 1); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndDocument.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndDocument.java index 81114bf51..f0a18b3dc 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndDocument.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndDocument.java @@ -22,7 +22,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.journal.Document; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; @@ -54,8 +53,8 @@ public class WndDocument extends Window { public WndDocument( Document doc ){ - int w = SPDSettings.landscape() ? WIDTH_L : WIDTH_P; - int h = SPDSettings.landscape() ? HEIGHT_L : HEIGHT_P; + int w = PixelScene.landscape() ? WIDTH_L : WIDTH_P; + int h = PixelScene.landscape() ? HEIGHT_L : HEIGHT_P; resize(w, h); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoItem.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoItem.java index 7cc2cceb7..644ad8c3b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoItem.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoItem.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; @@ -57,7 +56,7 @@ public class WndInfoItem extends Window { private void fillFields( Heap heap ) { - int width = SPDSettings.landscape() ? WIDTH_L : WIDTH_P; + int width = PixelScene.landscape() ? WIDTH_L : WIDTH_P; IconTitle titlebar = new IconTitle( heap ); titlebar.color( TITLE_COLOR ); @@ -81,7 +80,7 @@ public class WndInfoItem extends Window { color = ItemSlot.DEGRADED; } - int width = SPDSettings.landscape() ? WIDTH_L : WIDTH_P; + int width = PixelScene.landscape() ? WIDTH_L : WIDTH_P; IconTitle titlebar = new IconTitle( item ); titlebar.color( color ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndItem.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndItem.java index b30e0c8c5..fd9fc8755 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndItem.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndItem.java @@ -22,7 +22,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; @@ -65,7 +64,7 @@ public class WndItem extends Window { info.maxWidth(width); //info box can go out of the screen on landscape, so widen it - while (SPDSettings.landscape() + while (PixelScene.landscape() && info.height() > 100 && width < WIDTH_MAX){ width += 20; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java index a54384788..d02f661ac 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java @@ -22,7 +22,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.armor.ClassArmor; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; @@ -71,8 +70,8 @@ public class WndJournal extends WndTabbed { public WndJournal(){ - int width = SPDSettings.landscape() ? WIDTH_L : WIDTH_P; - int height = SPDSettings.landscape() ? HEIGHT_L : HEIGHT_P; + int width = PixelScene.landscape() ? WIDTH_L : WIDTH_P; + int height = PixelScene.landscape() ? HEIGHT_L : HEIGHT_P; resize(width, height); @@ -342,7 +341,7 @@ public class WndJournal extends WndTabbed { protected void layout() { super.layout(); - if (SPDSettings.landscape()){ + if (PixelScene.landscape()){ float buttonWidth = width()/pageButtons.length; for (int i = 0; i < NUM_BUTTONS; i++) { pageButtons[i].setRect(i*buttonWidth, 0, buttonWidth, ITEM_HEIGHT); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndLangs.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndLangs.java index 25c83db81..251143215 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndLangs.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndLangs.java @@ -94,18 +94,18 @@ public class WndLangs extends Window { } } btn.setSize(BTN_WIDTH, BTN_HEIGHT); - if (SPDSettings.landscape() && i % 2 == 1){ + if (PixelScene.landscape() && i % 2 == 1){ btn.setPos(BTN_WIDTH+1, y-(BTN_HEIGHT + 1)); } else { btn.setPos(0, y); y += BTN_HEIGHT; - if (SPDSettings.landscape()) y++; + if (PixelScene.landscape()) y++; } add(btn); } y = Math.max(MIN_HEIGHT, y); - resize(SPDSettings.landscape() ? WIDTH_L : WIDTH_P, y); + resize(PixelScene.landscape() ? WIDTH_L : WIDTH_P, y); int textLeft = width - 65; int textWidth = width - textLeft; @@ -155,7 +155,7 @@ public class WndLangs extends Window { String[] translators = currLang.translators(); boolean wide = false; - if (SPDSettings.landscape() && (reviewers.length + translators.length) > 10){ + if (PixelScene.landscape() && (reviewers.length + translators.length) > 10){ wide = true; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndMessage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndMessage.java index a4f9a90b2..0c3983782 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndMessage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndMessage.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; @@ -37,7 +36,7 @@ public class WndMessage extends Window { super(); RenderedTextBlock info = PixelScene.renderTextBlock( text, 6 ); - info.maxWidth((SPDSettings.landscape() ? WIDTH_L : WIDTH_P) - MARGIN * 2); + info.maxWidth((PixelScene.landscape() ? WIDTH_L : WIDTH_P) - MARGIN * 2); info.setPos(MARGIN, MARGIN); add( info ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndOptions.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndOptions.java index 45cd2266c..f8ccdfd1d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndOptions.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndOptions.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; @@ -38,7 +37,7 @@ public class WndOptions extends Window { public WndOptions( String title, String message, String... options ) { super(); - int width = SPDSettings.landscape() ? WIDTH_L : WIDTH_P; + int width = PixelScene.landscape() ? WIDTH_L : WIDTH_P; RenderedTextBlock tfTitle = PixelScene.renderTextBlock( title, 9 ); tfTitle.hardlight( TITLE_COLOR ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java index 53154c207..abcd84b4b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java @@ -37,6 +37,7 @@ import com.watabou.noosa.Group; import com.watabou.noosa.audio.Sample; import com.watabou.utils.DeviceCompat; +//TODO seeing as a fair bit of this is platform-dependant, might be better to have a per-platform wndsettings public class WndSettings extends WndTabbed { private static final int WIDTH = 112; @@ -154,18 +155,18 @@ public class WndSettings extends WndTabbed { add(chkSaver); } - RedButton btnOrientation = new RedButton( SPDSettings.landscape() ? + //TODO need to disable this in some situations. (desktop, android splitscreen) + RedButton btnOrientation = new RedButton( PixelScene.landscape() ? Messages.get(this, "portrait") : Messages.get(this, "landscape") ) { @Override protected void onClick() { - SPDSettings.landscape(!SPDSettings.landscape()); + SPDSettings.landscape(!PixelScene.landscape()); } }; btnOrientation.setRect(0, chkSaver.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT); add( btnOrientation ); - OptionSlider brightness = new OptionSlider(Messages.get(this, "brightness"), Messages.get(this, "dark"), Messages.get(this, "bright"), -2, 2) { @Override @@ -267,17 +268,20 @@ public class WndSettings extends WndTabbed { slots.setRect(0, chkFlipTags.bottom() + GAP_TINY, WIDTH, SLIDER_HEIGHT); add(slots); - CheckBox chkImmersive = new CheckBox( Messages.get(this, "nav_bar") ) { + CheckBox chkFullscreen = new CheckBox( Messages.get(this, "nav_bar") ) { @Override protected void onClick() { super.onClick(); SPDSettings.fullscreen(checked()); } }; - chkImmersive.setRect( 0, slots.bottom() + GAP_SML, WIDTH, BTN_HEIGHT ); - chkImmersive.checked(SPDSettings.fullscreen()); - chkImmersive.enable(DeviceCompat.supportsFullScreen()); - add(chkImmersive); + chkFullscreen.setRect( 0, slots.bottom() + GAP_SML, WIDTH, BTN_HEIGHT ); + chkFullscreen.checked(SPDSettings.fullscreen()); + if (DeviceCompat.isDesktop()){ + chkFullscreen.text( "Fullscreen" ); + } + chkFullscreen.enable(DeviceCompat.supportsFullScreen()); + add(chkFullscreen); CheckBox chkFont = new CheckBox(Messages.get(this, "system_font")){ @Override @@ -296,7 +300,7 @@ public class WndSettings extends WndTabbed { }); } }; - chkFont.setRect(0, chkImmersive.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT); + chkFont.setRect(0, chkFullscreen.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT); chkFont.checked(SPDSettings.systemFont()); add(chkFont); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndStory.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndStory.java index e4d7ab44a..8e6c53f2d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndStory.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndStory.java @@ -23,7 +23,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; @@ -67,7 +66,7 @@ public class WndStory extends Window { super( 0, 0, Chrome.get( Chrome.Type.SCROLL ) ); tf = PixelScene.renderTextBlock( text, 6 ); - tf.maxWidth(SPDSettings.landscape() ? + tf.maxWidth(PixelScene.landscape() ? WIDTH_L - MARGIN * 2: WIDTH_P - MARGIN *2); tf.invert(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTitledMessage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTitledMessage.java index 875968c94..4e63250b3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTitledMessage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTitledMessage.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; -import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; @@ -44,7 +43,7 @@ public class WndTitledMessage extends Window { super(); - int width = SPDSettings.landscape() ? WIDTH_L : WIDTH_P; + int width = PixelScene.landscape() ? WIDTH_L : WIDTH_P; titlebar.setRect( 0, 0, width, 0 ); add(titlebar); diff --git a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopLauncher.java b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopLauncher.java index d8933990a..cab2ef836 100644 --- a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopLauncher.java +++ b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopLauncher.java @@ -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); } diff --git a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java index 04df50feb..0b4e57d46 100644 --- a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java +++ b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java @@ -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 diff --git a/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopWindowListener.java b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopWindowListener.java new file mode 100644 index 000000000..551d6193c --- /dev/null +++ b/desktop/src/main/java/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopWindowListener.java @@ -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 + */ + +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 () { } +}