public void OnExitClick()
 {
     if (DeckBuilderDeck.instance.unsavedChanges)
     {
         glassBackground.SetActive(true);
         YesNoBox yesNoBox = Instantiate(yesNoBoxPrefab);
         yesNoBox.setUp(switchToMainMenu, setGlassBackgroundActiveFalse, "Unsaved changes", "There are unsaved changes to your deck. Are you sure you want to exit?");
     }
     else
     {
         SceneManager.LoadScene(ScenesEnum.MainMenu);
     }
 }
Exemple #2
0
    public void save(string deckName)
    {
        if (deckName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
        {
            YesNoBox yesNoBox = Instantiate(yesNoBoxPrefab);
            yesNoBox.setUp(null, "Invalid Deck Name", "The deck name " + deckName + " contains illegal characters. Please choose a different name.");
            yesNoBox.setNoButtonActive(false);
            yesNoBox.setYesButtonText("Okay");
            return;
        }

        if (deckName.Length == 0)
        {
            Toaster.Instance.DoToast("Deck name cannot be empty");
            return;
        }

        // put together string that will be the deck file
        string filePath = Application.persistentDataPath + "/decks/" + deckName + ".dek";

        // create deck folder if needed
        string directoryPath = Application.persistentDataPath + "/decks";

        if (!Directory.Exists(filePath))
        {
            Directory.CreateDirectory(directoryPath);
        }

        Dictionary <int, int> idToAmountMap = new Dictionary <int, int>();

        foreach (CardAmountPair pair in cardList)
        {
            int id     = pair.cardId;
            int amount = pair.amount;
            idToAmountMap.Add(id, amount);
        }
        // save the map as a file
        BinaryFormatter bf = new BinaryFormatter();
        FileStream      fs = File.Open(filePath, FileMode.Create);

        bf.Serialize(fs, idToAmountMap);
        fs.Close();

        // do on save stuff
        unsavedChanges = false;
        Toaster.Instance.DoToast("Deck Saved");
        int dropdownIndex = deckNameDropdown.value;

        loadDeckPopUp.setup();
        deckNameDropdown.SetValueWithoutNotify(dropdownIndex);
    }
Exemple #3
0
 public void loadWithSavedChangesCheck(string deckName)
 {
     if (unsavedChanges)
     {
         glassBackground.SetActive(true);
         YesNoBox yesNoBox = Instantiate(yesNoBoxPrefab);
         LoadWithSavedChangesHandler handler = new LoadWithSavedChangesHandler();
         handler.deckBuilderDeck = this;
         handler.deckName        = deckName;
         yesNoBox.setUp(handler, "Unsaved Changes", "There are unsaved changes to the current deck. Are you sure you want to load a new deck without saving?");
     }
     else
     {
         load(deckName);
     }
 }
Exemple #4
0
    public void delete()
    {
        //string deckName = deckNameField.text;
        string deckName = deckNameDropdown.options[deckNameDropdown.value].text;
        string filePath = Application.persistentDataPath + "/decks/" + deckName + ".dek";

        if (File.Exists(filePath))
        {
            // show confirm dialouge
            YesNoBox             yesNoBox = Instantiate(yesNoBoxPrefab);
            DeleteConfirmHandler handler  = new DeleteConfirmHandler();
            handler.deckName    = deckName;
            handler.deckBuilder = this;
            yesNoBox.setUp(handler, "Delete Confirmation", "Are you sure you want to delete " + deckName + "?");
            glassBackground.SetActive(true);
        }
        else
        {
            // do nothing (maybe change to error dialouge later)
            Debug.LogError("Deck not found " + filePath);
        }
    }
Exemple #5
0
    public void saveAs()
    {
        // use the deckName from the text field box
        string deckName = deckNameField.text.Trim();

        // check if deck is legal size
        if (cardCount < minNumerOfCardsInDeck)
        {
            Toaster.Instance.DoToast("Deck must contain at least " + minNumerOfCardsInDeck + " cards");
            return;
        }
        else if (cardCount > maxNumberOfCardsInDeck)
        {
            Toaster.Instance.DoToast("Deck must be under " + maxNumberOfCardsInDeck + " cards");
            return;
        }

        // check to see if the deck already exists
        string filePath = Application.persistentDataPath + "/decks/" + deckName + ".dek";

        if (File.Exists(filePath))
        {
            glassBackground.SetActive(true);
            // if it does display a yes/no box
            YesNoBox           yesNoBox = Instantiate(yesNoBoxPrefab);
            SaveConfirmHandler handler  = new SaveConfirmHandler();
            handler.deckBuilderDeck = this;
            handler.deckName        = deckName;
            yesNoBox.setUp(handler, "Overwrite Confimation", "A deck with the name " + deckName + " already exists. Would you like to overwrite the saved deck?");
        }
        else
        {
            // otherwise just save
            save(deckName);
            loadDeckPopUp.setToValue(deckName);
        }
    }