// Attached to the Accept button // Starts the button sequence to create or delete a save file public void ButtonCreateDeleteTransition() { switch (MainMenuManager.Instance.State) { case MainMenuManager.MainMenuState.creatingSaveFile: if (!inputSaveName.IsActive()) { inputSaveName.gameObject.SetActive(true); dropdownDifficulty.gameObject.SetActive(true); panelCreateNewSave.SetActive(false); } else { CreateUserSaveFile(); MainMenuManager.Instance.HandleBackInput(true); } break; case MainMenuManager.MainMenuState.loadDeleteMenu: if (layoutAcceptDecline.IsActive()) { DeleteUserSaveFile(); CheckForSaveFile(); UIUtilities.ChangeButtonVisual(saveButton, emptySaveButtonColors); UIUtilities.RenameButton(saveButton, "Empty Save", TextAnchor.MiddleCenter, 18); MainMenuManager.Instance.HandleBackInput(true); } break; } }
// Save a SaveFile at path and reshape/rename linked button private void CreateUserSaveFile() { var path = Application.persistentDataPath; var newSave = new SaveFileTemplate(inputSaveName.text, (int)GameManager.Instance.difficulty, saveButtonId); XMLFilHelper.CreateXmlFile(path + saveButtonId, newSave); UIUtilities.ChangeButtonVisual(saveButton, saveButtonColors); string buttonText = "Name : " + newSave.Name + "\n" + GetDifficultyString(); UIUtilities.RenameButton(saveButton, buttonText, TextAnchor.MiddleCenter, 18); }
// Look for existing save file in the Save Files document and change save buttons accordingly public void CheckForSaveFile() { var path = Application.persistentDataPath; for (int i = 1; i < 4; i++) { if (File.Exists(path + i)) { var button = MainMenuManager.Instance.saveMenu.saveButtons[i - 1]; var currentSaveFile = XMLFilHelper.LoadFile(path + i, typeof(SaveFileTemplate)) as SaveFileTemplate; string buttonText = "Name : " + currentSaveFile.Name + "\n" + GetDifficultyString(); UIUtilities.ChangeButtonVisual(button, saveButtonColors); UIUtilities.RenameButton(button, buttonText, TextAnchor.MiddleCenter, 18); } } }