Fix issue with creating multiple new gauntlets in the same session

This commit is contained in:
drdev
2014-08-09 02:49:38 +00:00
parent 55dc9949a7
commit a169f50861
3 changed files with 31 additions and 18 deletions

View File

@@ -104,15 +104,13 @@ public class GauntletScreen extends LaunchScreen {
} }
lstGauntlets.setGauntlets(data); lstGauntlets.setGauntlets(data);
}
if (lstGauntlets.isEmpty()) { private void updateButtons() {
btnRenameGauntlet.setEnabled(false); boolean enabled = !lstGauntlets.isEmpty();
btnDeleteGauntlet.setEnabled(false); btnRenameGauntlet.setEnabled(enabled);
btnStart.setEnabled(false); btnDeleteGauntlet.setEnabled(enabled);
} btnStart.setEnabled(enabled);
else {
lstGauntlets.setSelectedIndex(0);
}
} }
@Override @Override
@@ -268,7 +266,7 @@ public class GauntletScreen extends LaunchScreen {
GauntletIO.getGauntletFile(gauntlet).delete(); GauntletIO.getGauntletFile(gauntlet).delete();
lstGauntlets.removeItem(gauntlet); lstGauntlets.removeGauntlet(gauntlet);
} }
}); });
} }
@@ -340,6 +338,8 @@ public class GauntletScreen extends LaunchScreen {
public void setGauntlets(List<GauntletData> gauntlets0) { public void setGauntlets(List<GauntletData> gauntlets0) {
gauntlets = gauntlets0; gauntlets = gauntlets0;
refresh(); refresh();
setSelectedIndex(0);
updateButtons();
} }
public void addGauntlet(GauntletData gauntlet) { public void addGauntlet(GauntletData gauntlet) {
@@ -347,6 +347,17 @@ public class GauntletScreen extends LaunchScreen {
gauntlets.add(gauntlet); gauntlets.add(gauntlet);
refresh(); refresh();
setSelectedGauntlet(gauntlet); setSelectedGauntlet(gauntlet);
updateButtons();
}
public void removeGauntlet(GauntletData gauntlet) {
if (gauntlets == null) { return; }
removeItem(gauntlet);
gauntlets.remove(gauntlet);
if (selectedIndex == gauntlets.size()) {
selectedIndex--;
}
updateButtons();
} }
public void refresh() { public void refresh() {

View File

@@ -15,11 +15,15 @@ public class GauntletUtil {
public static GauntletData createQuickGauntlet(final Deck userDeck, final int numOpponents, final List<DeckType> allowedDeckTypes) { public static GauntletData createQuickGauntlet(final Deck userDeck, final int numOpponents, final List<DeckType> allowedDeckTypes) {
final File[] arrFiles = GauntletIO.getGauntletFilesQuick(); final File[] arrFiles = GauntletIO.getGauntletFilesQuick();
final Set<String> setNames = new HashSet<String>(); final Set<String> setNames = new HashSet<String>();
for (File f : arrFiles) { setNames.add(f.getName()); } for (File f : arrFiles) {
setNames.add(f.getName());
}
int num = 1; int num = 1;
while (setNames.contains(GauntletIO.PREFIX_QUICK + num + GauntletIO.SUFFIX_DATA)) { num++; } while (setNames.contains(GauntletIO.PREFIX_QUICK + num + GauntletIO.SUFFIX_DATA)) { num++; }
FModel.getGauntletData().setName(GauntletIO.PREFIX_QUICK + num); GauntletData gauntlet = new GauntletData();
gauntlet.setName(GauntletIO.PREFIX_QUICK + num);
FModel.setGauntletData(gauntlet);
// Generate gauntlet decks // Generate gauntlet decks
final List<String> lstEventNames = new ArrayList<String>(); final List<String> lstEventNames = new ArrayList<String>();
@@ -55,13 +59,12 @@ public class GauntletUtil {
lstGauntletDecks.add(tempDeck); lstGauntletDecks.add(tempDeck);
} }
final GauntletData gd = FModel.getGauntletData(); gauntlet.setDecks(lstGauntletDecks);
gd.setDecks(lstGauntletDecks); gauntlet.setEventNames(lstEventNames);
gd.setEventNames(lstEventNames); gauntlet.setUserDeck(userDeck);
gd.setUserDeck(userDeck);
// Reset all variable fields to 0, stamps and saves automatically. // Reset all variable fields to 0, stamps and saves automatically.
gd.reset(); gauntlet.reset();
return gd; return gauntlet;
} }
} }

View File

@@ -134,7 +134,6 @@ public class FModel {
formats = new GameFormat.Collection(new GameFormat.Reader(new File(ForgeConstants.BLOCK_DATA_DIR + "formats.txt"))); formats = new GameFormat.Collection(new GameFormat.Reader(new File(ForgeConstants.BLOCK_DATA_DIR + "formats.txt")));
blocks = new StorageBase<CardBlock>("Block definitions", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "blocks.txt", magicDb.getEditions())); blocks = new StorageBase<CardBlock>("Block definitions", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "blocks.txt", magicDb.getEditions()));
questPreferences = new QuestPreferences(); questPreferences = new QuestPreferences();
gauntletData = new GauntletData();
fantasyBlocks = new StorageBase<CardBlock>("Custom blocks", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "fantasyblocks.txt", magicDb.getEditions())); fantasyBlocks = new StorageBase<CardBlock>("Custom blocks", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "fantasyblocks.txt", magicDb.getEditions()));
worlds = new StorageBase<QuestWorld>("Quest worlds", new QuestWorld.Reader(ForgeConstants.QUEST_WORLD_DIR + "worlds.txt")); worlds = new StorageBase<QuestWorld>("Quest worlds", new QuestWorld.Reader(ForgeConstants.QUEST_WORLD_DIR + "worlds.txt"));