Center sectors map on most recently saved (played and not abandoned) sector (#375)
This commit is contained in:
committed by
Anuken
parent
18ddc040d1
commit
54dd67a435
@@ -17,6 +17,8 @@ import io.anuke.ucore.util.Strings;
|
|||||||
import io.anuke.ucore.util.ThreadArray;
|
import io.anuke.ucore.util.ThreadArray;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -186,8 +188,12 @@ public class Saves{
|
|||||||
return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed);
|
return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getTimestamp(){
|
||||||
|
return meta.timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDate(){
|
public String getDate(){
|
||||||
return meta.date;
|
return SimpleDateFormat.getDateTimeInstance().format(new Date(meta.timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getMap(){
|
public Map getMap(){
|
||||||
|
|||||||
@@ -4,15 +4,12 @@ import io.anuke.mindustry.game.Difficulty;
|
|||||||
import io.anuke.mindustry.game.GameMode;
|
import io.anuke.mindustry.game.GameMode;
|
||||||
import io.anuke.mindustry.maps.Map;
|
import io.anuke.mindustry.maps.Map;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.world;
|
import static io.anuke.mindustry.Vars.world;
|
||||||
|
|
||||||
public class SaveMeta{
|
public class SaveMeta{
|
||||||
public int version;
|
public int version;
|
||||||
public int build;
|
public int build;
|
||||||
public String date;
|
public long timestamp;
|
||||||
public long timePlayed;
|
public long timePlayed;
|
||||||
public int sector;
|
public int sector;
|
||||||
public GameMode mode;
|
public GameMode mode;
|
||||||
@@ -20,10 +17,10 @@ public class SaveMeta{
|
|||||||
public int wave;
|
public int wave;
|
||||||
public Difficulty difficulty;
|
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.version = version;
|
||||||
this.build = build;
|
this.build = build;
|
||||||
this.date = SimpleDateFormat.getDateTimeInstance().format(new Date(date));
|
this.timestamp = timestamp;
|
||||||
this.timePlayed = timePlayed;
|
this.timePlayed = timePlayed;
|
||||||
this.sector = sector;
|
this.sector = sector;
|
||||||
this.mode = GameMode.values()[mode];
|
this.mode = GameMode.values()[mode];
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ public class Sectors{
|
|||||||
return grid.get(Bits.getLeftShort(position), Bits.getRightShort(position));
|
return grid.get(Bits.getLeftShort(position), Bits.getRightShort(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterable<Sector> getSectors(){
|
||||||
|
return grid.values();
|
||||||
|
}
|
||||||
|
|
||||||
public Difficulty getDifficulty(Sector sector){
|
public Difficulty getDifficulty(Sector sector){
|
||||||
if(sector.difficulty == 0){
|
if(sector.difficulty == 0){
|
||||||
return Difficulty.hard;
|
return Difficulty.hard;
|
||||||
|
|||||||
@@ -159,6 +159,26 @@ public class SectorsDialog extends FloatingDialog{
|
|||||||
});
|
});
|
||||||
|
|
||||||
clicked(() -> clicked = true);
|
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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user