public void buildGameSaveList() { FileHandle storage = Gdx.files.external(TowerConsts.GAME_SAVE_DIRECTORY); FileHandle[] files = storage.list(".json"); if (files != null && files.length > 0) { for (FileHandle file : files) { Table fileRow = makeGameFileRow(file); if (fileRow != null) { row().fillX(); add(fileRow).expandX(); foundSaveFile = true; } } } if (!foundSaveFile) { add(FontManager.RobotoBold18.makeLabel("No saved games were found on this device.")); } else { shoveContentUp(); } progressDialog.dismiss(); }
private Table makeGameFileInfoBox( final Table fileRow, final FileHandle savedGameFile, GameSave towerData) { TextButton launchButton = FontManager.RobotoBold18.makeTextButton("Play"); launchButton.addListener( new VibrateClickListener() { @Override public void onClick(InputEvent event, float x, float y) { dismiss(); try { SceneManager.changeScene( LoadTowerSplashScene.class, GameSaveFactory.readFile(savedGameFile)); } catch (Exception e) { throw new RuntimeException(e); } } }); TextButton deleteButton = FontManager.RobotoBold18.makeTextButton("Delete"); deleteButton.addListener( new VibrateClickListener() { @Override public void onClick(InputEvent event, float x, float y) { new Dialog() .setTitle("Are you sure you want to delete this Tower?") .setMessage("If you delete this tower, it will disappear forever.\n\nAre you sure?") .addButton( "Yes, delete it", new OnClickCallback() { @Override public void onClick(Dialog dialog) { savedGameFile.delete(); content.getCell(fileRow).ignore(); content.removeActor(fileRow); content.invalidate(); dialog.dismiss(); } }) .addButton( "Keep it!", new OnClickCallback() { @Override public void onClick(Dialog dialog) { dialog.dismiss(); } }) .show(); } }); Table metadata = new Table(); metadata.defaults().top().left().fillX(); addLabelRow(metadata, towerData.getTowerName(), FontManager.RobotoBold18, Color.WHITE); addLabelRow( metadata, "Population: " + getNumberInstance().format(towerData.getPlayer().getTotalPopulation()), FontManager.Default, Color.GRAY); Date lastPlayed = towerData.getMetadata().lastPlayed; if (lastPlayed != null) { PrettyTime prettyTime = new PrettyTime(); addLabelRow( metadata, "Last played: " + prettyTime.format(lastPlayed), FontManager.Default, Color.GRAY); } Table box = new Table(); box.defaults().fillX().space(Display.devicePixel(5)); box.row().top().left().fillX(); box.add(metadata).top().left().expandX(); box.add(deleteButton).width(Display.devicePixel(80)); box.add(launchButton).width(Display.devicePixel(80)); return box; }