Moves "Current_Deck" from Quest Preferences to Quest Data.

Without this, the selected deck name was global for all quests - switching to another quest retained the deck name from the previous quest
and if the new quest had a deck with the identical name, selected that one, otherwise selected nothing. (in one weird case, this resulted in quest data that crashed caused bugs when loading forge - as quest was saved with a selected deck from another quest data.)
Preferred behavior is to select the deck that was last selected in THAT QUEST when switching to another quest.
This commit is contained in:
Seravy
2018-02-13 01:32:18 +01:00
parent 67e8046af6
commit 56983b2553
8 changed files with 26 additions and 11 deletions

View File

@@ -62,7 +62,7 @@ public class SEditorIO {
VAllDecks.SINGLETON_INSTANCE.getLstDecks().setSelectedString(deckStr); VAllDecks.SINGLETON_INSTANCE.getLstDecks().setSelectedString(deckStr);
// Set current quest deck to selected // Set current quest deck to selected
if (Singletons.getControl().getCurrentScreen() == FScreen.DECK_EDITOR_QUEST) { if (Singletons.getControl().getCurrentScreen() == FScreen.DECK_EDITOR_QUEST) {
FModel.getQuestPreferences().setPref(QPref.CURRENT_DECK, name); FModel.getQuest().setCurrentDeck(name);
} }
} }

View File

@@ -30,10 +30,10 @@ public enum CSubmenuQuestDecks implements ICDoc {
public void run() { public void run() {
final DeckProxy deck = VSubmenuQuestDecks.SINGLETON_INSTANCE.getLstDecks().getSelectedItem(); final DeckProxy deck = VSubmenuQuestDecks.SINGLETON_INSTANCE.getLstDecks().getSelectedItem();
if (deck != null) { if (deck != null) {
FModel.getQuestPreferences().setPref(QPref.CURRENT_DECK, deck.toString()); FModel.getQuest().setCurrentDeck(deck.toString());
} }
else { else {
FModel.getQuestPreferences().setPref(QPref.CURRENT_DECK, QPref.CURRENT_DECK.getDefault()); FModel.getQuest().setCurrentDeck(QPref.CURRENT_DECK.getDefault());
} }
FModel.getQuestPreferences().save(); FModel.getQuestPreferences().save();
} }
@@ -84,7 +84,7 @@ public enum CSubmenuQuestDecks implements ICDoc {
view.getLstDecks().setup(ItemManagerConfig.QUEST_DECKS); view.getLstDecks().setup(ItemManagerConfig.QUEST_DECKS);
// Look through list for preferred deck from prefs // Look through list for preferred deck from prefs
final DeckProxy deck = hasQuest ? view.getLstDecks().stringToItem(FModel.getQuestPreferences().getPref(QPref.CURRENT_DECK)) : null; final DeckProxy deck = hasQuest ? view.getLstDecks().stringToItem(FModel.getQuest().getCurrentDeck()) : null;
if (deck != null) { if (deck != null) {
view.getLstDecks().setSelectedItem(deck); view.getLstDecks().setSelectedItem(deck);
} }

View File

@@ -1620,11 +1620,11 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
DeckPreferences.setSealedDeck(deckStr); DeckPreferences.setSealedDeck(deckStr);
break; break;
case Quest: case Quest:
FModel.getQuestPreferences().setPref(QPref.CURRENT_DECK, model.toString()); FModel.getQuest().setCurrentDeck(model.toString());
FModel.getQuest().save(); FModel.getQuest().save();
break; break;
case QuestDraft: case QuestDraft:
FModel.getQuestPreferences().setPref(QPref.CURRENT_DECK, model.toString()); FModel.getQuest().setCurrentDeck(model.toString());
FModel.getQuest().save(); FModel.getQuest().save();
break; break;
default: default:

View File

@@ -42,10 +42,10 @@ public class QuestDecksScreen extends FScreen {
public void handleEvent(FEvent e) { public void handleEvent(FEvent e) {
DeckProxy deck = lstDecks.getSelectedItem(); DeckProxy deck = lstDecks.getSelectedItem();
if (deck != null) { if (deck != null) {
FModel.getQuestPreferences().setPref(QPref.CURRENT_DECK, deck.toString()); FModel.getQuest().setCurrentDeck(deck.toString());
} }
else { else {
FModel.getQuestPreferences().setPref(QPref.CURRENT_DECK, QPref.CURRENT_DECK.getDefault()); FModel.getQuest().setCurrentDeck(QPref.CURRENT_DECK.getDefault());
} }
FModel.getQuestPreferences().save(); FModel.getQuestPreferences().save();
} }
@@ -135,7 +135,7 @@ public class QuestDecksScreen extends FScreen {
lstDecks.setup(ItemManagerConfig.QUEST_DECKS); lstDecks.setup(ItemManagerConfig.QUEST_DECKS);
// Look through list for preferred deck from prefs // Look through list for preferred deck from prefs
final DeckProxy deck = hasQuest ? lstDecks.stringToItem(FModel.getQuestPreferences().getPref(QPref.CURRENT_DECK)) : null; final DeckProxy deck = hasQuest ? lstDecks.stringToItem(FModel.getQuest().getCurrentDeck()) : null;
if (deck != null) { if (deck != null) {
lstDecks.setSelectedItem(deck); lstDecks.setSelectedItem(deck);
} }

View File

@@ -577,4 +577,12 @@ public class QuestController {
CardEdition randomLandSet = CardEdition.Predicates.getRandomSetWithAllBasicLands(availableEditions); CardEdition randomLandSet = CardEdition.Predicates.getRandomSetWithAllBasicLands(availableEditions);
return randomLandSet == null ? FModel.getMagicDb().getEditions().get("ZEN") : randomLandSet; return randomLandSet == null ? FModel.getMagicDb().getEditions().get("ZEN") : randomLandSet;
} }
public String getCurrentDeck() {
return model.currentDeck;
}
public void setCurrentDeck(String s) {
model.currentDeck = s;
}
} }

View File

@@ -443,7 +443,7 @@ public class QuestUtil {
if (FModel.getQuest().getAssets() != null) { if (FModel.getQuest().getAssets() != null) {
d = FModel.getQuest().getMyDecks().get( d = FModel.getQuest().getMyDecks().get(
FModel.getQuestPreferences().getPref(QPref.CURRENT_DECK)); FModel.getQuest().getCurrentDeck());
} }
return d; return d;

View File

@@ -42,7 +42,7 @@ import java.util.Map;
*/ */
public final class QuestData { public final class QuestData {
/** Holds the latest version of the Quest Data. */ /** Holds the latest version of the Quest Data. */
public static final int CURRENT_VERSION_NUMBER = 11; public static final int CURRENT_VERSION_NUMBER = 12;
// This field places the version number into QD instance, // This field places the version number into QD instance,
// but only when the object is created through the constructor // but only when the object is created through the constructor
@@ -68,6 +68,8 @@ public final class QuestData {
public HashSet<StarRating> Ratings = new HashSet<StarRating>(); public HashSet<StarRating> Ratings = new HashSet<StarRating>();
public String currentDeck = "DEFAULT";
public QuestData() { //needed for XML serialization public QuestData() { //needed for XML serialization
} }

View File

@@ -17,6 +17,7 @@
*/ */
package forge.quest.io; package forge.quest.io;
import forge.quest.data.QuestPreferences.QPref;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.MarshallingContext;
@@ -201,6 +202,10 @@ public class QuestDataIO {
newData.Ratings.clear(); newData.Ratings.clear();
} }
if (saveVersion < 12) { if (saveVersion < 12) {
// Current Deck moved from preferences to quest data - it should not be global for all quests!!!
QuestDataIO.setFinalField(QuestData.class, "currentDeck", newData, FModel.getQuestPreferences().getPref(QPref.CURRENT_DECK));
}
if (saveVersion < 13) {
// Migrate DraftTournaments to use new Tournament class // Migrate DraftTournaments to use new Tournament class
} }