v2.0.2: improved error handling in WndRanking, now shows some info

This commit is contained in:
Evan Debenham
2023-04-11 12:48:10 -04:00
parent b69240ce4f
commit a81131d255
4 changed files with 109 additions and 79 deletions
@@ -242,6 +242,11 @@ public enum Rankings {
public static final String DAILY_REPLAY = "daily_replay"; public static final String DAILY_REPLAY = "daily_replay";
public void saveGameData(Record rec){ public void saveGameData(Record rec){
if (Dungeon.hero == null){
rec.gameData = null;
return;
}
rec.gameData = new Bundle(); rec.gameData = new Bundle();
Belongings belongings = Dungeon.hero.belongings; Belongings belongings = Dungeon.hero.belongings;
@@ -316,6 +321,8 @@ public enum Rankings {
QuickSlotButton.reset(); QuickSlotButton.reset();
Toolbar.swappedQuickslots = false; Toolbar.swappedQuickslots = false;
if (data == null) return;
Bundle handler = data.getBundle(HANDLERS); Bundle handler = data.getBundle(HANDLERS);
Scroll.restore(handler); Scroll.restore(handler);
Potion.restore(handler); Potion.restore(handler);
@@ -336,11 +336,7 @@ public class RankingsScene extends PixelScene {
@Override @Override
protected void onClick() { protected void onClick() {
if (rec.gameData != null) {
parent.add( new WndRanking( rec ) ); parent.add( new WndRanking( rec ) );
} else {
parent.add( new WndError( Messages.get(RankingsScene.class, "no_info") ) );
}
} }
} }
} }
@@ -246,8 +246,8 @@ public class WelcomeScene extends PixelScene {
Rankings.INSTANCE.loadGameData(rec); Rankings.INSTANCE.loadGameData(rec);
Rankings.INSTANCE.saveGameData(rec); Rankings.INSTANCE.saveGameData(rec);
} catch (Exception e) { } catch (Exception e) {
//if we encounter a fatal per-record error, then clear that record //if we encounter a fatal per-record error, then clear that record's data
Rankings.INSTANCE.records.remove(rec); rec.gameData = null;
ShatteredPixelDungeon.reportException(e); ShatteredPixelDungeon.reportException(e);
} }
} }
@@ -256,8 +256,8 @@ public class WelcomeScene extends PixelScene {
Rankings.INSTANCE.loadGameData(Rankings.INSTANCE.latestDaily); Rankings.INSTANCE.loadGameData(Rankings.INSTANCE.latestDaily);
Rankings.INSTANCE.saveGameData(Rankings.INSTANCE.latestDaily); Rankings.INSTANCE.saveGameData(Rankings.INSTANCE.latestDaily);
} catch (Exception e) { } catch (Exception e) {
//if we encounter a fatal per-record error, then clear that record //if we encounter a fatal per-record error, then clear that record's data
Rankings.INSTANCE.latestDaily = null; Rankings.INSTANCE.latestDaily.gameData = null;
ShatteredPixelDungeon.reportException(e); ShatteredPixelDungeon.reportException(e);
} }
} }
@@ -86,14 +86,11 @@ public class WndRanking extends WndTabbed {
try { try {
Badges.loadGlobal(); Badges.loadGlobal();
Rankings.INSTANCE.loadGameData( rec ); Rankings.INSTANCE.loadGameData( rec );
if (Dungeon.hero != null) {
createControls(); createControls();
} else {
hide();
}
} catch ( Exception e ) { } catch ( Exception e ) {
hide(); Game.reportException(e);
Game.scene().addToFront( new WndError( Messages.get(WndRanking.class, "error" ))); Dungeon.hero = null;
createControls();
} }
} }
@@ -107,6 +104,7 @@ public class WndRanking extends WndTabbed {
private void createControls() { private void createControls() {
if (Dungeon.hero != null) {
Icons[] icons = Icons[] icons =
{Icons.RANKINGS, Icons.TALENT, Icons.BACKPACK_LRG, Icons.BADGES, Icons.CHALLENGE_ON}; {Icons.RANKINGS, Icons.TALENT, Icons.BACKPACK_LRG, Icons.BADGES, Icons.CHALLENGE_ON};
Group[] pages = Group[] pages =
@@ -129,6 +127,11 @@ public class WndRanking extends WndTabbed {
layoutTabs(); layoutTabs();
select(0); select(0);
} else {
StatsTab tab = new StatsTab();
add(tab);
}
} }
private class RankingTab extends IconTab { private class RankingTab extends IconTab {
@@ -156,16 +159,19 @@ public class WndRanking extends WndTabbed {
public StatsTab() { public StatsTab() {
super(); super();
String heroClass = Dungeon.hero.className(); String heroClass = record.heroClass.name();
if (Dungeon.hero != null){
heroClass = Dungeon.hero.className();
}
IconTitle title = new IconTitle(); IconTitle title = new IconTitle();
title.icon( HeroSprite.avatar( Dungeon.hero.heroClass, Dungeon.hero.tier() ) ); title.icon( HeroSprite.avatar( record.heroClass, record.armorTier ) );
title.label( Messages.get(this, "title", Dungeon.hero.lvl, heroClass ).toUpperCase( Locale.ENGLISH ) ); title.label( Messages.get(this, "title", record.herolevel, heroClass ).toUpperCase( Locale.ENGLISH ) );
title.color(Window.TITLE_COLOR); title.color(Window.TITLE_COLOR);
title.setRect( 0, 0, WIDTH, 0 ); title.setRect( 0, 0, WIDTH, 0 );
add( title ); add( title );
if (Dungeon.seed != -1){ if (Dungeon.hero != null && Dungeon.seed != -1){
GAP--; GAP--;
} }
@@ -184,6 +190,22 @@ public class WndRanking extends WndTabbed {
pos = date.bottom()+5; pos = date.bottom()+5;
NumberFormat num = NumberFormat.getInstance(Locale.US); NumberFormat num = NumberFormat.getInstance(Locale.US);
if (Dungeon.hero == null){
pos = statSlot( this, Messages.get(this, "score"), num.format( record.score ), pos );
pos += GAP;
Image errorIcon = Icons.WARNING.get();
errorIcon.y = pos;
add(errorIcon);
RenderedTextBlock errorText = PixelScene.renderTextBlock(Messages.get(WndRanking.class, "error"), 6);
errorText.maxWidth((int)(WIDTH-errorIcon.width()-GAP));
errorText.setPos(errorIcon.width()+GAP, pos + (errorIcon.height()-errorText.height())/2);
add(errorText);
} else {
pos = statSlot(this, Messages.get(this, "score"), num.format(Statistics.totalScore), pos); pos = statSlot(this, Messages.get(this, "score"), num.format(Statistics.totalScore), pos);
IconButton scoreInfo = new IconButton(Icons.get(Icons.INFO)) { IconButton scoreInfo = new IconButton(Icons.get(Icons.INFO)) {
@@ -196,12 +218,16 @@ public class WndRanking extends WndTabbed {
scoreInfo.setSize(16, 16); scoreInfo.setSize(16, 16);
scoreInfo.setPos(WIDTH - scoreInfo.width(), pos - 10 - GAP); scoreInfo.setPos(WIDTH - scoreInfo.width(), pos - 10 - GAP);
add(scoreInfo); add(scoreInfo);
pos += GAP; pos += GAP;
int strBonus = Dungeon.hero.STR() - Dungeon.hero.STR; int strBonus = Dungeon.hero.STR() - Dungeon.hero.STR;
if (strBonus > 0) pos = statSlot(this, Messages.get(this, "str"), Dungeon.hero.STR + " + " + strBonus, pos); if (strBonus > 0)
else if (strBonus < 0) pos = statSlot(this, Messages.get(this, "str"), Dungeon.hero.STR + " - " + -strBonus, pos ); pos = statSlot(this, Messages.get(this, "str"), Dungeon.hero.STR + " + " + strBonus, pos);
else pos = statSlot(this, Messages.get(this, "str"), Integer.toString(Dungeon.hero.STR), pos); else if (strBonus < 0)
pos = statSlot(this, Messages.get(this, "str"), Dungeon.hero.STR + " - " + -strBonus, pos);
else
pos = statSlot(this, Messages.get(this, "str"), Integer.toString(Dungeon.hero.STR), pos);
pos = statSlot(this, Messages.get(this, "duration"), num.format((int) Statistics.duration), pos); pos = statSlot(this, Messages.get(this, "duration"), num.format((int) Statistics.duration), pos);
if (Statistics.highestAscent == 0) { if (Statistics.highestAscent == 0) {
pos = statSlot(this, Messages.get(this, "depth"), num.format(Statistics.deepestFloor), pos); pos = statSlot(this, Messages.get(this, "depth"), num.format(Statistics.deepestFloor), pos);
@@ -230,10 +256,11 @@ public class WndRanking extends WndTabbed {
pos = statSlot(this, Messages.get(this, "gold"), num.format(Statistics.goldCollected), pos); pos = statSlot(this, Messages.get(this, "gold"), num.format(Statistics.goldCollected), pos);
pos = statSlot(this, Messages.get(this, "food"), num.format(Statistics.foodEaten), pos); pos = statSlot(this, Messages.get(this, "food"), num.format(Statistics.foodEaten), pos);
pos = statSlot(this, Messages.get(this, "alchemy"), num.format(Statistics.itemsCrafted), pos); pos = statSlot(this, Messages.get(this, "alchemy"), num.format(Statistics.itemsCrafted), pos);
}
int buttontop = HEIGHT - 16; int buttontop = HEIGHT - 16;
if (Dungeon.seed != -1 && !Dungeon.daily && if (Dungeon.hero != null && Dungeon.seed != -1 && !Dungeon.daily &&
(DeviceCompat.isDebug() || Badges.isUnlocked(Badges.Badge.VICTORY))){ (DeviceCompat.isDebug() || Badges.isUnlocked(Badges.Badge.VICTORY))){
final Image icon = Icons.get(Icons.SEED); final Image icon = Icons.get(Icons.SEED);
RedButton btnSeed = new RedButton(Messages.get(this, "copy_seed")){ RedButton btnSeed = new RedButton(Messages.get(this, "copy_seed")){