Skip to content

Commit

Permalink
Start reworking FinishOverlay in championship mode
Browse files Browse the repository at this point in the history
Fix #341
  • Loading branch information
agateau committed Aug 7, 2023
1 parent 84f58b6 commit 5d5501a
Showing 1 changed file with 9 additions and 49 deletions.
58 changes: 9 additions & 49 deletions core/src/com/agateau/pixelwheels/racescreen/FinishedOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,9 @@ enum RaceColumn {
RACER,
BEST_LAP_TIME,
TOTAL_TIME,
POINTS // Championship race only
}

private final TableRowCreator mQuickRaceRowCreator =
// - 1 because we don't show the Points column in quick race mode
new TableRowCreator(RaceColumn.values().length - 1) {
@Override
protected Cell<Label> createCell(
Table table, int columnIdx, String value, String style) {
Cell<Label> cell = table.add(value, style);
RaceColumn column = RaceColumn.values()[columnIdx];
switch (column) {
case RACER:
cell.left().expandX();
break;
case BEST_LAP_TIME:
case TOTAL_TIME:
cell.padLeft(mBestIndicatorWidth + mBestIndicatorMargin);
cell.right();
break;
default:
cell.right();
break;
}
return cell;
}
};

private final TableRowCreator mChampionshipRaceRowCreator =
private final TableRowCreator mRaceRowCreator =
new TableRowCreator(RaceColumn.values().length) {
@Override
protected Cell<Label> createCell(
Expand Down Expand Up @@ -390,9 +364,8 @@ public void triggered() {
private TableRowCreator getRowCreatorForTable(TableType tableType) {
switch (tableType) {
case QUICK_RACE:
return mQuickRaceRowCreator;
case CHAMPIONSHIP_RACE:
return mChampionshipRaceRowCreator;
return mRaceRowCreator;
case CHAMPIONSHIP_TOTAL:
return mChampionshipTotalRowCreator;
}
Expand All @@ -412,11 +385,8 @@ private void fillTable(Table table, TableType tableType, HashMap<Racer, Integer>
// Create header row
switch (tableType) {
case QUICK_RACE:
rowCreator.addHeaderRow(tr("#"), tr("Racer"), tr("Best lap"), tr("Total time"));
break;
case CHAMPIONSHIP_RACE:
rowCreator.addHeaderRow(
tr("#"), tr("Racer"), tr("Best lap"), tr("Total time"), tr("Points"));
rowCreator.addHeaderRow(tr("#"), tr("Racer"), tr("Best lap"), tr("Total time"));
break;
case CHAMPIONSHIP_TOTAL:
rowCreator.addHeaderRow(tr("#"), tr("Racer"), "", tr("Race time"), tr("Points"));
Expand All @@ -439,18 +409,14 @@ private void fillTable(Table table, TableType tableType, HashMap<Racer, Integer>
break;
}

if (tableType != TableType.QUICK_RACE) {
if (tableType == TableType.CHAMPIONSHIP_TOTAL) {
// add PointsAnimInfo for row
// -1 is the last column: the Points column
Cell<Label> pointsCell = rowCreator.getCreatedRowCell(-1);
PointsAnimInfo info = new PointsAnimInfo();
info.label = pointsCell.getActor();
if (tableType == TableType.CHAMPIONSHIP_RACE) {
info.delta = entrant.getLastRacePoints();
info.points = entrant.getPoints() - info.delta;
} else {
info.points = entrant.getPoints();
}
info.delta = entrant.getLastRacePoints();
info.points = entrant.getPoints() - info.delta;
mPointsAnimInfos.add(info);
}

Expand All @@ -473,11 +439,9 @@ private void fillTable(Table table, TableType tableType, HashMap<Racer, Integer>
}

// Animate points if needed
if (tableType != TableType.QUICK_RACE) {
if (tableType == TableType.CHAMPIONSHIP_TOTAL) {
updatePointsLabels();
if (tableType == TableType.CHAMPIONSHIP_RACE) {
schedulePointsIncrease(mFirstPointsIncreaseInterval);
}
schedulePointsIncrease(mFirstPointsIncreaseInterval);
}
}

Expand All @@ -497,11 +461,7 @@ private void createRaceRow(
totalTime = StringUtils.formatRaceTime(lapPositionComponent.getTotalTime());
}

if (tableType == TableType.QUICK_RACE) {
rowCreator.addRow(rank, name, bestLapTime, totalTime);
} else {
rowCreator.addRow(rank, name, bestLapTime, totalTime, "" /* points */);
}
rowCreator.addRow(rank, name, bestLapTime, totalTime);
}

private void createChampionshipTotalRow(
Expand Down

0 comments on commit 5d5501a

Please sign in to comment.