예제 #1
0
 public void DeleteSave()
 {
     Debug.Log("Delete save");
     // querry toggle group for currently selected toggle
     selectedToggle = savesMenu.GetComponent <TextToggleGroup>().GetSelectedToggle();
     // verify if there is any toggle selected now
     if (selectedToggle == null)
     {
         // no any save available
         // show error message
         string errMsg = "Error: no any save.";
         NotificationPopUp.Instance().DisplayMessage(errMsg);
     }
     else
     {
         // toggle is selected
         //  get file name from selected save
         string fileName = selectedToggle.GetComponent <Save>().SaveName;
         // verify if file name is set
         if (fileName == "")
         {
             // file name is empty
             string errMsg = "Error: file name is empty.";
             NotificationPopUp.Instance().DisplayMessage(errMsg);
         }
         else
         {
             //  construct full file name
             fullFilePath = ConfigManager.Instance.GameSaveConfig.GetSaveFullNameByFileName(fileName); // Application.persistentDataPath + "/" + fileName + fileExtension;
             Debug.Log("File name is " + fullFilePath + "");
             // verify if file exists
             if (File.Exists(fullFilePath))
             {
                 // file exists
                 // Ask user whether he wants to delete save
                 ConfirmationPopUp confirmationPopUp = ConfirmationPopUp.Instance();
                 // set actions
                 UnityAction YesAction = new UnityAction(OnDeleteSaveYesConfirmation);
                 UnityAction NoAction  = new UnityAction(OnDeleteSaveNoConfirmation);
                 // set message
                 string confirmationMessage = "Do you want to delete '" + selectedToggle.name + "' save?";
                 // send actions to Confirmation popup, so he knows how to react on no and yes btn presses
                 confirmationPopUp.Choice(confirmationMessage, YesAction, NoAction);
             }
             else
             {
                 // display error message
                 string errMsg = "Error: [" + fullFilePath + "] file not found. Please try to exit 'Load' menu and open it again.";
                 NotificationPopUp.Instance().DisplayMessage(errMsg);
                 // remove UI element
                 Destroy(selectedToggle.gameObject);
             }
         }
     }
 }
예제 #2
0
    public void AskQuitToTheMainMenuConfirmation()
    {
        // ask for confirmation
        // Ask user whether he wants to delete save
        ConfirmationPopUp confirmationPopUp = ConfirmationPopUp.Instance();
        // set actions
        UnityAction YesAction = new UnityAction(OnQuitToTheMainMenuYesConfirmation);
        UnityAction NoAction  = new UnityAction(OnQuitToTheMainMenuNoConfirmation);
        // set message
        string confirmationMessage = "Do you want to terminate current game? Not saved progress will be lost.";

        // send actions to Confirmation popup, so he knows how to react on no and yes btn presses
        confirmationPopUp.Choice(confirmationMessage, YesAction, NoAction);
    }
예제 #3
0
    public void Save()
    {
        // Open file
        //  get file name from input field
        string fileName = saveNameInputField.text;

        // verify if file name is set
        if (fileName == "")
        {
            // file name is not set
            // show error message
            string errMsg = "Error: the name of save is not set. Please type new save name or select existing save to overwrite it.";
            NotificationPopUp.Instance().DisplayMessage(errMsg);
        }
        else
        {
            //  construct full file name
            fullFilePath = ConfigManager.Instance.GameSaveConfig.GetSaveFullNameByFileName(fileName);
            Debug.Log("File name is " + fullFilePath + "");
            // verify if file exists
            if (File.Exists(fullFilePath))
            {
                // file exists
                // Ask user whether he wants to overwrite previous save
                ConfirmationPopUp confirmationPopUp = ConfirmationPopUp.Instance();
                // set actions
                UnityAction YesAction = new UnityAction(OnOverwriteSaveYesConfirmation);
                UnityAction NoAction  = new UnityAction(OnOverwriteSaveNoConfirmation);
                // set message
                string confirmationMessage = "Do you want to overwrite existing save with new data?";
                // send actions to Confirmation popup, so he knows how to react on no and yes btn presses
                confirmationPopUp.Choice(confirmationMessage, YesAction, NoAction);
            }
            else
            {
                // create file
                FileStream file = File.Create(fullFilePath);
                // write to a file and close it
                SaveGameData(file);
            }
        }
    }
예제 #4
0
    public void Load()
    {
        Debug.Log("Load save");
        // querry toggle group for currently selected toggle
        TextToggle selectedToggle = savesMenu.GetComponent <TextToggleGroup>().GetSelectedToggle();

        // verify if there is any toggle selected now
        if (selectedToggle == null)
        {
            // no any save available
            // show error message
            string errMsg = "Error: no any save.";
            NotificationPopUp.Instance().DisplayMessage(errMsg);
        }
        else
        {
            // toggle is selected
            //  get file name from selected save
            string fileName = selectedToggle.GetComponent <Save>().SaveName;
            // verify if file name is set
            if (fileName == "")
            {
                // file name is empty
                string errMsg = "Error: file name is empty.";
                NotificationPopUp.Instance().DisplayMessage(errMsg);
            }
            else
            {
                //  construct full file name
                fullFilePath = ConfigManager.Instance.GameSaveConfig.GetSaveFullNameByFileName(fileName); // Application.persistentDataPath + "/" + fileName + fileExtension;
                //Debug.Log("File name is " + fullFilePath + "");
                // verify if file exists
                if (File.Exists(fullFilePath))
                {
                    // file exists
                    // verify if game is already running
                    // check if there is a Chapter in World
                    if (World.Instance.GetComponentInChildren <Chapter>(true) != null)
                    {
                        // game is already running
                        // Ask user whether he wants to load new game
                        ConfirmationPopUp confirmationPopUp = ConfirmationPopUp.Instance();
                        // set actions
                        UnityAction YesAction = new UnityAction(OnLoadSaveYesConfirmation);
                        UnityAction NoAction  = new UnityAction(OnLoadSaveNoConfirmation);
                        // set message
                        string confirmationMessage = "Do you want to terminate current game and load saved game? Not saved progress will be lost.";
                        // send actions to Confirmation popup, so he knows how to react on no and yes btn presses
                        confirmationPopUp.Choice(confirmationMessage, YesAction, NoAction);
                    }
                    else
                    {
                        // game is not running yet
                        // Load game data
                        LoadGameData();
                    }
                }
                else
                {
                    string errMsg = "Error: [" + fullFilePath + "] file not found. Please verify if file is present on disk drive.";
                    NotificationPopUp.Instance().DisplayMessage(errMsg);
                }
            }
        }
    }