mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-18 23:32:08 -08:00
Center sectors map on most recently saved (played and not abandoned) sector (#375)
This commit is contained in:
parent
18ddc040d1
commit
54dd67a435
4 changed files with 34 additions and 7 deletions
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -86,6 +86,10 @@ public class Sectors{
|
|||
return grid.get(Bits.getLeftShort(position), Bits.getRightShort(position));
|
||||
}
|
||||
|
||||
public Iterable<Sector> getSectors(){
|
||||
return grid.values();
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty(Sector sector){
|
||||
if(sector.difficulty == 0){
|
||||
return Difficulty.hard;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue