v1.4.0: added date and version to rankings pages

This commit is contained in:
Evan Debenham
2022-09-15 14:11:20 -04:00
parent 7f14fc697b
commit 900c689ad3
2 changed files with 53 additions and 4 deletions

View File

@@ -44,11 +44,16 @@ import com.watabou.utils.Bundle;
import com.watabou.utils.FileUtils;
import java.io.IOException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public enum Rankings {
@@ -76,7 +81,19 @@ public enum Rankings {
load();
Record rec = new Record();
//we trim version to just the numbers, ignoring alpha/beta, etc.
Pattern p = Pattern.compile("\\d+\\.\\d+\\.\\d+");
Matcher m = p.matcher(ShatteredPixelDungeon.version);
if (m.find()) {
rec.version = "v" + m.group();
} else {
rec.version = "";
}
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ROOT);
rec.date = format.format(new Date(Game.realTime));
rec.cause = cause;
rec.win = win;
rec.heroClass = Dungeon.hero.heroClass;
@@ -433,6 +450,9 @@ public enum Rankings {
private static final String SEED = "custom_seed";
private static final String DAILY = "daily";
private static final String DATE = "date";
private static final String VERSION = "version";
public Class cause;
public boolean win;
@@ -451,6 +471,9 @@ public enum Rankings {
public String customSeed;
public boolean daily;
public String date;
public String version;
public String desc(){
if (win){
if (ascending){
@@ -474,7 +497,7 @@ public enum Rankings {
public void restoreFromBundle( Bundle bundle ) {
if (bundle.contains( CAUSE )) {
cause = bundle.getClass( CAUSE );
cause = bundle.getClass( CAUSE );
} else {
cause = null;
}
@@ -490,6 +513,13 @@ public enum Rankings {
depth = bundle.getInt( DEPTH );
ascending = bundle.getBoolean( ASCEND );
if (bundle.contains( DATE )){
date = bundle.getString( DATE );
version = bundle.getString( VERSION );
} else {
date = version = null;
}
if (bundle.contains(DATA)) gameData = bundle.getBundle(DATA);
if (bundle.contains(ID)) gameID = bundle.getString(ID);
@@ -513,6 +543,9 @@ public enum Rankings {
bundle.put( DEPTH, depth );
bundle.put( ASCEND, ascending );
bundle.put( DATE, date );
bundle.put( VERSION, version );
if (gameData != null) bundle.put( DATA, gameData );
bundle.put( ID, gameID );
}

View File

@@ -164,8 +164,24 @@ public class WndRanking extends WndTabbed {
title.color(Window.TITLE_COLOR);
title.setRect( 0, 0, WIDTH, 0 );
add( title );
if (Dungeon.seed != -1){
GAP--;
}
float pos = title.bottom() + GAP + 1;
float pos = title.bottom() + 1;
RenderedTextBlock date = PixelScene.renderTextBlock(record.date, 7);
date.hardlight(0xCCCCCC);
date.setPos(0, pos);
add(date);
RenderedTextBlock version = PixelScene.renderTextBlock(record.version, 7);
version.hardlight(0xCCCCCC);
version.setPos(WIDTH-version.width(), pos);
add(version);
pos = date.bottom()+5;
NumberFormat num = NumberFormat.getInstance(Locale.US);
pos = statSlot( this, Messages.get(this, "score"), num.format( Statistics.totalScore ), pos );
@@ -178,7 +194,7 @@ public class WndRanking extends WndTabbed {
}
};
scoreInfo.setSize(16, 16);
scoreInfo.setPos(WIDTH-scoreInfo.width(), pos-14);
scoreInfo.setPos(WIDTH-scoreInfo.width(), pos-10-GAP);
add(scoreInfo);
pos += GAP;