diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java index f42693a37..21876da76 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java @@ -958,7 +958,7 @@ public class Badges { private static void displayBadge( Badge badge ) { - if (badge == null || Dungeon.usingCustomSeed) { + if (badge == null || !Dungeon.customSeedText.isEmpty()) { return; } @@ -995,7 +995,7 @@ public class Badges { } public static void unlock( Badge badge ){ - if (!isUnlocked(badge) && !Dungeon.usingCustomSeed){ + if (!isUnlocked(badge) && Dungeon.customSeedText.isEmpty()){ global.add( badge ); saveNeeded = true; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Bones.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Bones.java index 1ce2f68c6..09cb7431c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Bones.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Bones.java @@ -51,7 +51,7 @@ public class Bones { depth = Dungeon.depth; //heroes drop no bones if they have the amulet, die far above their farthest depth, are challenged, or are playing with a custom seed. - if (Statistics.amuletObtained || (Statistics.deepestFloor - 5) >= depth || Dungeon.challenges > 0 || Dungeon.usingCustomSeed) { + if (Statistics.amuletObtained || (Statistics.deepestFloor - 5) >= depth || Dungeon.challenges > 0 || !Dungeon.customSeedText.isEmpty()) { depth = -1; return; } @@ -142,7 +142,7 @@ public class Bones { } else { //heroes who are challenged or on a seeded run cannot find bones - if (depth == Dungeon.depth && Dungeon.challenges == 0 && !Dungeon.usingCustomSeed) { + if (depth == Dungeon.depth && Dungeon.challenges == 0 && Dungeon.customSeedText.isEmpty()) { Bundle emptyBones = new Bundle(); emptyBones.put(LEVEL, 0); try { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index f983ccf94..38fc0951a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -179,6 +179,7 @@ public class Dungeon { public static int initialVersion; public static int version; + public static String customSeedText; public static long seed; public static boolean usingCustomSeed; @@ -188,12 +189,12 @@ public class Dungeon { challenges = SPDSettings.challenges(); mobsToChampion = -1; - if (SPDSettings.customSeed() != -1){ - seed = SPDSettings.customSeed(); - usingCustomSeed = true; + if (SPDSettings.customSeed() != ""){ + customSeedText = SPDSettings.customSeed(); + seed = DungeonSeed.convertFromText(customSeedText); } else { + customSeedText = ""; seed = DungeonSeed.randomSeed(); - usingCustomSeed = false; } Actor.clear(); @@ -495,7 +496,7 @@ public class Dungeon { bundle.put( INIT_VER, initialVersion ); bundle.put( VERSION, version = Game.versionCode ); bundle.put( SEED, seed ); - bundle.put( CUSTOM_SEED, usingCustomSeed ); + bundle.put( CUSTOM_SEED, customSeedText ); bundle.put( CHALLENGES, challenges ); bundle.put( MOBS_TO_CHAMPION, mobsToChampion ); bundle.put( HERO, hero ); @@ -573,7 +574,7 @@ public class Dungeon { saveGame( GamesInProgress.curSlot ); saveLevel( GamesInProgress.curSlot ); - GamesInProgress.set( GamesInProgress.curSlot, depth, challenges, seed, usingCustomSeed, hero ); + GamesInProgress.set( GamesInProgress.curSlot, depth, challenges, seed, customSeedText, hero ); } } @@ -596,7 +597,7 @@ public class Dungeon { version = bundle.getInt( VERSION ); seed = bundle.contains( SEED ) ? bundle.getLong( SEED ) : DungeonSeed.randomSeed(); - usingCustomSeed = bundle.getBoolean( CUSTOM_SEED ); + customSeedText = bundle.getString( CUSTOM_SEED ); Actor.clear(); Actor.restoreNextID( bundle ); @@ -729,7 +730,7 @@ public class Dungeon { info.version = bundle.getInt( VERSION ); info.challenges = bundle.getInt( CHALLENGES ); info.seed = bundle.getLong( SEED ); - info.customSeed = bundle.getBoolean( CUSTOM_SEED ); + info.customSeed = bundle.getString( CUSTOM_SEED ); Hero.preview( info, bundle.getBundle( HERO ) ); Statistics.preview( info, bundle ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/GamesInProgress.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/GamesInProgress.java index b1c26969d..56c8d25df 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/GamesInProgress.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/GamesInProgress.java @@ -126,7 +126,7 @@ public class GamesInProgress { } } - public static void set(int slot, int depth, int challenges, long seed, boolean customSeed, + public static void set(int slot, int depth, int challenges, long seed, String customSeed, Hero hero) { Info info = new Info(); info.slot = slot; @@ -170,7 +170,7 @@ public class GamesInProgress { public int challenges; public long seed; - public boolean customSeed; + public String customSeed; public int level; public int str; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java index b6a4ea87c..21edf1dae 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java @@ -63,7 +63,7 @@ public enum Rankings { public void submit( boolean win, Class cause ) { //games with custom seeds do not appear in rankings - if (Dungeon.usingCustomSeed) return; + if (!Dungeon.customSeedText.isEmpty()) return; load(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java index bba62b03e..e5946ad95 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java @@ -209,12 +209,12 @@ public class SPDSettings extends GameSettings { return getInt( KEY_CHALLENGES, 0, 0, Challenges.MAX_VALUE ); } - public static void customSeed( long value ){ + public static void customSeed( String value ){ put( KEY_CUSTOM_SEED, value ); } - public static long customSeed() { - return getLong( KEY_CUSTOM_SEED, -1, -1, DungeonSeed.TOTAL_SEEDS-1); + public static String customSeed() { + return getString( KEY_CUSTOM_SEED, "", 20); } public static void supportNagged( boolean value ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/HeroSelectScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/HeroSelectScene.java index 0d50ef4f1..241fb21ed 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/HeroSelectScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/HeroSelectScene.java @@ -199,22 +199,23 @@ public class HeroSelectScene extends PixelScene { seedButton = new IconButton( Icons.get(Icons.SEED)){ @Override protected void onClick() { - String existingSeedtext = SPDSettings.customSeed() == -1 ? "" : DungeonSeed.convertToCode(SPDSettings.customSeed()); + String existingSeedtext = SPDSettings.customSeed(); ShatteredPixelDungeon.scene().addToFront( new WndTextInput(Messages.get(HeroSelectScene.class, "custom_seed_title"), Messages.get(HeroSelectScene.class, "custom_seed_desc"), existingSeedtext, - 30, + 20, false, Messages.get(HeroSelectScene.class, "custom_seed_set"), Messages.get(HeroSelectScene.class, "custom_seed_clear")){ @Override public void onSelect(boolean positive, String text) { + text = DungeonSeed.formatText(text); long seed = DungeonSeed.convertFromText(text); if (positive && seed != -1){ - SPDSettings.customSeed(seed); + SPDSettings.customSeed(text); icon.hardlight(1f, 1.5f, 0.67f); } else { - SPDSettings.customSeed(-1); + SPDSettings.customSeed(""); icon.resetColor(); } } @@ -223,7 +224,7 @@ public class HeroSelectScene extends PixelScene { @Override protected void onPointerUp() { - if (SPDSettings.customSeed() != -1){ + if (!SPDSettings.customSeed().isEmpty()){ icon.hardlight(1f, 1.5f, 0.67f); } else { icon.resetColor(); @@ -243,7 +244,7 @@ public class HeroSelectScene extends PixelScene { return Messages.get(HeroSelectScene.class, "custom_seed_title"); } }; - if (SPDSettings.customSeed() != -1) seedButton.icon().hardlight(1f, 1.5f, 0.67f); + if (!SPDSettings.customSeed().isEmpty()) seedButton.icon().hardlight(1f, 1.5f, 0.67f); seedButton.setRect(challengeButton.left()-16, challengeButton.top(), 16, 21); seedButton.visible = false; @@ -253,7 +254,7 @@ public class HeroSelectScene extends PixelScene { } else { Dungeon.challenges = 0; SPDSettings.challenges(0); - SPDSettings.customSeed(-1); + SPDSettings.customSeed(""); } btnExit = new ExitButton(); 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 385df840b..60211467c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java @@ -203,7 +203,7 @@ public class StartScene extends PixelScene { level.resetColor(); } - if (info.customSeed){ + if (!info.customSeed.isEmpty()){ steps.hardlight(1f, 1.5f, 0.67f); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java index 84ca5e424..6eda55445 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java @@ -295,28 +295,28 @@ public enum Icons { icon.frame( icon.texture.uvRectBySize( 40, 72, 8, 8 ) ); break; case DEPTH: - icon.frame( icon.texture.uvRectBySize( 48, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 6, 7 ) ); + icon.frame( icon.texture.uvRectBySize( 48, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 6, 7 ) ); break; case DEPTH_CHASM: - icon.frame( icon.texture.uvRectBySize( 56, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); + icon.frame( icon.texture.uvRectBySize( 56, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) ); break; case DEPTH_WATER: - icon.frame( icon.texture.uvRectBySize( 64, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); + icon.frame( icon.texture.uvRectBySize( 64, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) ); break; case DEPTH_GRASS: - icon.frame( icon.texture.uvRectBySize( 72, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); + icon.frame( icon.texture.uvRectBySize( 72, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) ); break; case DEPTH_DARK: - icon.frame( icon.texture.uvRectBySize( 80, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); + icon.frame( icon.texture.uvRectBySize( 80, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) ); break; case DEPTH_LARGE: - icon.frame( icon.texture.uvRectBySize( 88, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); + icon.frame( icon.texture.uvRectBySize( 88, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) ); break; case DEPTH_TRAPS: - icon.frame( icon.texture.uvRectBySize( 96, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); + icon.frame( icon.texture.uvRectBySize( 96, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) ); break; case DEPTH_SECRETS: - icon.frame( icon.texture.uvRectBySize( 104, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); + icon.frame( icon.texture.uvRectBySize( 104, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) ); break; case CHAL_COUNT: icon.frame( icon.texture.uvRectBySize( 112, 64, 7, 7 ) ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/utils/DungeonSeed.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/utils/DungeonSeed.java index 9e49df047..bc2a9050b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/utils/DungeonSeed.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/utils/DungeonSeed.java @@ -23,6 +23,8 @@ package com.shatteredpixel.shatteredpixeldungeon.utils; import com.watabou.utils.Random; +import java.util.Locale; + //This class defines the parameters for seeds in ShatteredPD and contains a few convenience methods public class DungeonSeed { @@ -122,4 +124,15 @@ public class DungeonSeed { return total; } + + public static String formatText( String inputText ){ + try { + //if the seed matches a code, then just convert it to using the code system + return convertToCode(convertFromCode(inputText)); + } catch (IllegalArgumentException e){ + //otherwise just return the input text + return inputText; + } + } + } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndGameInProgress.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndGameInProgress.java index 996c00ee2..e3886f7d6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndGameInProgress.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndGameInProgress.java @@ -103,8 +103,8 @@ public class WndGameInProgress extends Window { pos += GAP; statSlot( Messages.get(this, "gold"), info.goldCollected ); statSlot( Messages.get(this, "depth"), info.maxDepth ); - if (info.customSeed){ - statSlot( Messages.get(this, "custom_seed"), "_" + DungeonSeed.convertToCode(info.seed) + "_" ); + if (!info.customSeed.isEmpty()){ + statSlot( Messages.get(this, "custom_seed"), "_" + info.customSeed + "_" ); } else { statSlot( Messages.get(this, "dungeon_seed"), DungeonSeed.convertToCode(info.seed) ); } @@ -162,9 +162,12 @@ public class WndGameInProgress extends Window { RenderedTextBlock txt = PixelScene.renderTextBlock( label, 8 ); txt.setPos(0, pos); add( txt ); - - txt = PixelScene.renderTextBlock( value, 8 ); - txt.setPos(WIDTH * 0.55f, pos); + + int size = 8; + if (value.length() >= 14) size -=2; + if (value.length() >= 18) size -=1; + txt = PixelScene.renderTextBlock( value, size ); + txt.setPos(WIDTH * 0.55f, pos + (6 - txt.height())/2); PixelScene.align(txt); add( txt ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndHero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndHero.java index 7d01ae22a..3c3fb4a74 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndHero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndHero.java @@ -185,8 +185,8 @@ public class WndHero extends WndTabbed { statSlot( Messages.get(this, "gold"), Statistics.goldCollected ); statSlot( Messages.get(this, "depth"), Statistics.deepestFloor ); - if (Dungeon.usingCustomSeed){ - statSlot( Messages.get(this, "custom_seed"), "_" + DungeonSeed.convertToCode(Dungeon.seed) + "_" ); + if (!Dungeon.customSeedText.isEmpty()){ + statSlot( Messages.get(this, "custom_seed"), "_" + Dungeon.customSeedText + "_" ); } else { statSlot( Messages.get(this, "dungeon_seed"), DungeonSeed.convertToCode(Dungeon.seed) ); }