Autopan to last sector

This commit is contained in:
Anuken
2020-07-29 23:36:59 -04:00
parent 9bf3074aee
commit 66c0c9baa2
4 changed files with 22 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ public class Planets implements ContentList{
generator = new TODOPlanetGenerator();
meshLoader = () -> new HexMesh(this, 6);
atmosphereColor = Color.valueOf("3c1b8f");
startSector = 15;
}};
}
}

View File

@@ -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{

View File

@@ -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;
}

View File

@@ -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