v2.0.2: improved error handling in WndRanking, now shows some info
This commit is contained in:
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,29 +103,35 @@ public class WndRanking extends WndTabbed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createControls() {
|
private void createControls() {
|
||||||
|
|
||||||
Icons[] icons =
|
|
||||||
{Icons.RANKINGS, Icons.TALENT, Icons.BACKPACK_LRG, Icons.BADGES, Icons.CHALLENGE_ON};
|
|
||||||
Group[] pages =
|
|
||||||
{new StatsTab(), new TalentsTab(), new ItemsTab(), new BadgesTab(), null};
|
|
||||||
|
|
||||||
if (Dungeon.challenges != 0) pages[4] = new ChallengesTab();
|
if (Dungeon.hero != null) {
|
||||||
|
Icons[] icons =
|
||||||
for (int i=0; i < pages.length; i++) {
|
{Icons.RANKINGS, Icons.TALENT, Icons.BACKPACK_LRG, Icons.BADGES, Icons.CHALLENGE_ON};
|
||||||
|
Group[] pages =
|
||||||
|
{new StatsTab(), new TalentsTab(), new ItemsTab(), new BadgesTab(), null};
|
||||||
|
|
||||||
if (pages[i] == null) {
|
if (Dungeon.challenges != 0) pages[4] = new ChallengesTab();
|
||||||
break;
|
|
||||||
|
for (int i = 0; i < pages.length; i++) {
|
||||||
|
|
||||||
|
if (pages[i] == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
add(pages[i]);
|
||||||
|
|
||||||
|
Tab tab = new RankingTab(icons[i], pages[i]);
|
||||||
|
add(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
add( pages[i] );
|
|
||||||
|
|
||||||
Tab tab = new RankingTab( icons[i], pages[i] );
|
|
||||||
add( tab );
|
|
||||||
}
|
|
||||||
|
|
||||||
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,56 +190,77 @@ 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);
|
||||||
pos = statSlot( this, Messages.get(this, "score"), num.format( Statistics.totalScore ), pos );
|
|
||||||
|
|
||||||
IconButton scoreInfo = new IconButton(Icons.get(Icons.INFO)){
|
if (Dungeon.hero == null){
|
||||||
@Override
|
pos = statSlot( this, Messages.get(this, "score"), num.format( record.score ), pos );
|
||||||
protected void onClick() {
|
pos += GAP;
|
||||||
super.onClick();
|
|
||||||
ShatteredPixelDungeon.scene().addToFront(new WndScoreBreakdown());
|
Image errorIcon = Icons.WARNING.get();
|
||||||
}
|
errorIcon.y = pos;
|
||||||
};
|
add(errorIcon);
|
||||||
scoreInfo.setSize(16, 16);
|
|
||||||
scoreInfo.setPos(WIDTH-scoreInfo.width(), pos-10-GAP);
|
RenderedTextBlock errorText = PixelScene.renderTextBlock(Messages.get(WndRanking.class, "error"), 6);
|
||||||
add(scoreInfo);
|
errorText.maxWidth((int)(WIDTH-errorIcon.width()-GAP));
|
||||||
pos += GAP;
|
errorText.setPos(errorIcon.width()+GAP, pos + (errorIcon.height()-errorText.height())/2);
|
||||||
|
add(errorText);
|
||||||
|
|
||||||
int strBonus = Dungeon.hero.STR() - Dungeon.hero.STR;
|
|
||||||
if (strBonus > 0) pos = statSlot(this, Messages.get(this, "str"), Dungeon.hero.STR + " + " + strBonus, 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 );
|
|
||||||
if (Statistics.highestAscent == 0) {
|
|
||||||
pos = statSlot(this, Messages.get(this, "depth"), num.format(Statistics.deepestFloor), pos);
|
|
||||||
} else {
|
} else {
|
||||||
pos = statSlot(this, Messages.get(this, "ascent"), num.format(Statistics.highestAscent), pos);
|
|
||||||
}
|
pos = statSlot(this, Messages.get(this, "score"), num.format(Statistics.totalScore), pos);
|
||||||
if (Dungeon.seed != -1) {
|
|
||||||
if (Dungeon.daily){
|
IconButton scoreInfo = new IconButton(Icons.get(Icons.INFO)) {
|
||||||
if (Dungeon.dailyReplay) {
|
@Override
|
||||||
pos = statSlot(this, Messages.get(this, "replay_for"), "_" + Dungeon.customSeedText + "_", pos);
|
protected void onClick() {
|
||||||
} else {
|
super.onClick();
|
||||||
pos = statSlot(this, Messages.get(this, "daily_for"), "_" + Dungeon.customSeedText + "_", pos);
|
ShatteredPixelDungeon.scene().addToFront(new WndScoreBreakdown());
|
||||||
}
|
}
|
||||||
} else if (!Dungeon.customSeedText.isEmpty()){
|
};
|
||||||
pos = statSlot(this, Messages.get(this, "custom_seed"), "_" + Dungeon.customSeedText + "_", pos);
|
scoreInfo.setSize(16, 16);
|
||||||
|
scoreInfo.setPos(WIDTH - scoreInfo.width(), pos - 10 - GAP);
|
||||||
|
add(scoreInfo);
|
||||||
|
|
||||||
|
pos += GAP;
|
||||||
|
|
||||||
|
int strBonus = Dungeon.hero.STR() - Dungeon.hero.STR;
|
||||||
|
if (strBonus > 0)
|
||||||
|
pos = statSlot(this, Messages.get(this, "str"), Dungeon.hero.STR + " + " + strBonus, 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);
|
||||||
|
if (Statistics.highestAscent == 0) {
|
||||||
|
pos = statSlot(this, Messages.get(this, "depth"), num.format(Statistics.deepestFloor), pos);
|
||||||
} else {
|
} else {
|
||||||
pos = statSlot(this, Messages.get(this, "seed"), DungeonSeed.convertToCode(Dungeon.seed), pos);
|
pos = statSlot(this, Messages.get(this, "ascent"), num.format(Statistics.highestAscent), pos);
|
||||||
}
|
}
|
||||||
} else {
|
if (Dungeon.seed != -1) {
|
||||||
pos += GAP + 5;
|
if (Dungeon.daily) {
|
||||||
|
if (Dungeon.dailyReplay) {
|
||||||
|
pos = statSlot(this, Messages.get(this, "replay_for"), "_" + Dungeon.customSeedText + "_", pos);
|
||||||
|
} else {
|
||||||
|
pos = statSlot(this, Messages.get(this, "daily_for"), "_" + Dungeon.customSeedText + "_", pos);
|
||||||
|
}
|
||||||
|
} else if (!Dungeon.customSeedText.isEmpty()) {
|
||||||
|
pos = statSlot(this, Messages.get(this, "custom_seed"), "_" + Dungeon.customSeedText + "_", pos);
|
||||||
|
} else {
|
||||||
|
pos = statSlot(this, Messages.get(this, "seed"), DungeonSeed.convertToCode(Dungeon.seed), pos);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pos += GAP + 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos += GAP;
|
||||||
|
|
||||||
|
pos = statSlot(this, Messages.get(this, "enemies"), num.format(Statistics.enemiesSlain), 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, "alchemy"), num.format(Statistics.itemsCrafted), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += GAP;
|
|
||||||
|
|
||||||
pos = statSlot( this, Messages.get(this, "enemies"), num.format( Statistics.enemiesSlain ), 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, "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")){
|
||||||
|
|||||||
Reference in New Issue
Block a user