From 54dd67a4355cabe0ed710890cdeaac85e8d5ac35 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Thu, 13 Dec 2018 14:35:24 -0800 Subject: [PATCH] Center sectors map on most recently saved (played and not abandoned) sector (#375) --- core/src/io/anuke/mindustry/game/Saves.java | 8 +++++++- core/src/io/anuke/mindustry/io/SaveMeta.java | 9 +++------ core/src/io/anuke/mindustry/maps/Sectors.java | 4 ++++ .../mindustry/ui/dialogs/SectorsDialog.java | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/core/src/io/anuke/mindustry/game/Saves.java b/core/src/io/anuke/mindustry/game/Saves.java index 0a2f2fcf28..9e40b65e3c 100644 --- a/core/src/io/anuke/mindustry/game/Saves.java +++ b/core/src/io/anuke/mindustry/game/Saves.java @@ -17,6 +17,8 @@ import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.ThreadArray; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; import static io.anuke.mindustry.Vars.*; @@ -186,8 +188,12 @@ public class Saves{ return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed); } + public long getTimestamp(){ + return meta.timestamp; + } + public String getDate(){ - return meta.date; + return SimpleDateFormat.getDateTimeInstance().format(new Date(meta.timestamp)); } public Map getMap(){ diff --git a/core/src/io/anuke/mindustry/io/SaveMeta.java b/core/src/io/anuke/mindustry/io/SaveMeta.java index 1abe1816e6..61e035a356 100644 --- a/core/src/io/anuke/mindustry/io/SaveMeta.java +++ b/core/src/io/anuke/mindustry/io/SaveMeta.java @@ -4,15 +4,12 @@ import io.anuke.mindustry.game.Difficulty; import io.anuke.mindustry.game.GameMode; import io.anuke.mindustry.maps.Map; -import java.text.SimpleDateFormat; -import java.util.Date; - import static io.anuke.mindustry.Vars.world; public class SaveMeta{ public int version; public int build; - public String date; + public long timestamp; public long timePlayed; public int sector; public GameMode mode; @@ -20,10 +17,10 @@ public class SaveMeta{ public int wave; public Difficulty difficulty; - public SaveMeta(int version, long date, long timePlayed, int build, int sector, int mode, String map, int wave, Difficulty difficulty){ + public SaveMeta(int version, long timestamp, long timePlayed, int build, int sector, int mode, String map, int wave, Difficulty difficulty){ this.version = version; this.build = build; - this.date = SimpleDateFormat.getDateTimeInstance().format(new Date(date)); + this.timestamp = timestamp; this.timePlayed = timePlayed; this.sector = sector; this.mode = GameMode.values()[mode]; diff --git a/core/src/io/anuke/mindustry/maps/Sectors.java b/core/src/io/anuke/mindustry/maps/Sectors.java index 0d94ff6d6b..01347a4bda 100644 --- a/core/src/io/anuke/mindustry/maps/Sectors.java +++ b/core/src/io/anuke/mindustry/maps/Sectors.java @@ -86,6 +86,10 @@ public class Sectors{ return grid.get(Bits.getLeftShort(position), Bits.getRightShort(position)); } + public Iterable getSectors(){ + return grid.values(); + } + public Difficulty getDifficulty(Sector sector){ if(sector.difficulty == 0){ return Difficulty.hard; diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java index 1ea6ed5d04..c38cfc31f6 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java @@ -159,6 +159,26 @@ public class SectorsDialog extends FloatingDialog{ }); clicked(() -> clicked = true); + + this.focus(); + } + + private void focus(){ + Sector focusSector = null; + long newestTimestamp = 0; + for(Sector sector : world.sectors.getSectors()){ + if(sector.hasSave()){ + long timestamp = sector.getSave().getTimestamp(); + if(timestamp > newestTimestamp){ + focusSector = sector; + newestTimestamp = timestamp; + } + } + } + if(focusSector != null) { + panX = (focusSector.x + 0.5f) * sectorSize; + panY = (focusSector.y + 0.5f) * sectorSize; + } } @Override