Exemplo n.º 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);
             }
         }
     }
 }
Exemplo n.º 2
0
 void SetSelectedSave(TextToggle saveToggle)
 {
     //// verify if we already have any save selected
     //if (selectedSave != null)
     //{
     //    // deleselect prevoius save
     //    DeselectSave();
     //}
     // select new save
     SelectSave(saveToggle.GetComponent <Save>());
 }
    TextToggle CreateNewAbilityToggle(UniqueAbilityConfig uniqueAbilityConfig)
    {
        // create toggle in UI
        TextToggle uniqueAbilityToggle = Instantiate(uniqueAbilityToggleTemplate.gameObject, uniqueAbilitiesToggleGroup.transform).GetComponent <TextToggle>();

        // set toggle group
        uniqueAbilityToggle.toggleGroup = uniqueAbilitiesToggleGroup;
        // set unique ability name
        uniqueAbilityToggle.GetComponent <Text>().text = uniqueAbilityConfig.displayName;
        // Set unique ability description
        foreach (Text text in uniqueAbilityToggle.GetComponentsInChildren <Text>())
        {
            // verify if we are not getting toggle = we are getting description
            if (text.gameObject != uniqueAbilityToggle.gameObject)
            {
                text.text = uniqueAbilityConfig.description;
            }
        }
        // set unique ability reference
        uniqueAbilityToggle.GetComponent <UniqueAbilitySelector>().UniqueAbilityConfig = uniqueAbilityConfig;
        // return reference to the new toggle
        return(uniqueAbilityToggle);
    }
 void SetUniqueAbilitiesActive(bool doActivate)
 {
     // verify if we need to activate or deactivate abilities list
     if (doActivate)
     {
         // loop through all possible unique abilities configs
         foreach (UniqueAbilityConfig uniqueAbilityConfig in ConfigManager.Instance.UniqueAbilityConfigs)
         {
             // verify this ability is applicable only to specific factions
             if (uniqueAbilityConfig.doLimitUsageByFaction)
             {
                 // verify if that ability is allowed for this Faction
                 if (Array.Exists(uniqueAbilityConfig.applicableToFactions, element => element == factionSelectionGroup.GetSelectedFaction()))
                 {
                     TextToggle uniqueAbilityToggle = CreateNewAbilityToggle(uniqueAbilityConfig);
                     // adjust text color and toggle color schema to represent Faction-specific ability
                     uniqueAbilityToggle.GetComponent <Text>().color = factionSpecificAbilityNormalColor;
                     uniqueAbilityToggle.NormalColor      = factionSpecificAbilityNormalColor;
                     uniqueAbilityToggle.HighlightedColor = factionSpecificAbilityHighlightedColor;
                     uniqueAbilityToggle.PressedColor     = factionSpecificAbilityPressedColor;
                 }
             }
             else
             {
                 CreateNewAbilityToggle(uniqueAbilityConfig);
             }
         }
         // preselect first toggle
         uniqueAbilitiesToggleGroup.GetComponentsInChildren <TextToggle>()[0].ActOnLeftMouseClick();
     }
     else
     {
         // remove all previus abilities
         RecycleBin.RecycleChildrenOf(uniqueAbilitiesToggleGroup.gameObject);
         //// loop through all abilities in UI
         //foreach(Transform t in uniqueAbilitiesToggleGroup.transform)
         //{
         //    // move toggle to recycle bin and destroy it (move is required, because actual destroy is being done at the end of the frame,
         //    // but we need to preselect new toggle on reset SetUniqueAbilitiesActive(false/true)
         //    t.SetParent(RecycleBin.Instance.transform);
         //    Debug.Log("Destroy " + t.name);
         //    Destroy(t.gameObject);
         //}
     }
 }
Exemplo n.º 5
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);
                }
            }
        }
    }