From 66c0c9baa2ba3210e245e65a0d585ddf8e0c5c66 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 29 Jul 2020 23:36:59 -0400 Subject: [PATCH] Autopan to last sector --- core/src/mindustry/content/Planets.java | 1 + core/src/mindustry/core/Control.java | 1 + core/src/mindustry/type/Planet.java | 11 +++++++++++ core/src/mindustry/ui/dialogs/PlanetDialog.java | 11 +++++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index e04c4bed27..37ffba70d8 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -36,6 +36,7 @@ public class Planets implements ContentList{ generator = new TODOPlanetGenerator(); meshLoader = () -> new HexMesh(this, 6); atmosphereColor = Color.valueOf("3c1b8f"); + startSector = 15; }}; } } diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index eecb79ade6..be5d8a1b59 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -277,6 +277,7 @@ public class Control implements ApplicationListener, Loadable{ ui.loadAnd(() -> { ui.planet.hide(); SaveSlot slot = sector.save; + sector.planet.setLastSector(sector); if(slot != null && !clearSectors){ try{ diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index f27fc0aace..e217b3431e 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -1,5 +1,6 @@ package mindustry.type; +import arc.*; import arc.files.*; import arc.func.*; import arc.graphics.*; @@ -50,6 +51,8 @@ public class Planet extends UnlockableContent{ public float sectorApproxRadius; /** Whether this planet is tidally locked relative to its parent - see https://en.wikipedia.org/wiki/Tidal_locking */ public boolean tidalLock = false; + /** The default starting sector displayed to the map dialog. */ + public int startSector = 0; /** Whether the bloom render effect is enabled. */ public boolean bloom = false; /** For suns, this is the color that shines on other planets. Does nothing for children. */ @@ -122,6 +125,14 @@ public class Planet extends UnlockableContent{ for(solarSystem = this; solarSystem.parent != null; solarSystem = solarSystem.parent); } + public @Nullable Sector getLastSector(){ + return sectors.get(Math.min(Core.settings.getInt(name + "-last-sector", startSector), sectors.size - 1)); + } + + public void setLastSector(Sector sector){ + Core.settings.put(name + "-last-sector", sector.id); + } + public void preset(int index, SectorPreset preset){ sectors.get(index).preset = preset; } diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index 842b11dcb5..ec1f9b9b8a 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -84,7 +84,10 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ public Dialog show(){ mode = look; selected = hovered = launchSector = null; - launching= false; + launching = false; + if(planets.planet.getLastSector() != null){ + lookAt(planets.planet.getLastSector()); + } return super.show(); } @@ -95,7 +98,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ launching = false; //update view to sector - planets.camPos.set(Tmp.v33.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation())); + lookAt(sector); zoom = 1f; planets.zoom = 2f; selectAlpha = 0f; @@ -107,6 +110,10 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ super.show(); } + private void lookAt(Sector sector){ + planets.camPos.set(Tmp.v33.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation())); + } + boolean canLaunch(Sector sector){ return mode == launch && (sector.tile.v.within(launchSector.tile.v, (launchRange + 0.5f) * planets.planet.sectorApproxRadius*2) //within range