/// <summary> /// Saves the selected affix type to disk and updates the entry in the AffixInfo dictionary. /// </summary> /// <returns>Whether or not there were any problems saving. Also true if there were no changes.</returns> public async Task <bool> SaveSelectedType() { if (selectedType == AffixType.None) { return(false); } if (!AffixInfoDisplay.IsValid) { await DialogBasic.Show("Some inputs are invalid! Make sure no fields are empty.").result; return(false); } if (AffixInfoDisplay.IsChanged) { var newInfo = AffixInfoDisplay.Info; AffixInfo.Deregister(selectedType); AffixInfo.Register(newInfo); Serializer.SaveAffixInfoToDisk(newInfo); // Updates all the changed variables AffixInfoDisplay.SetType(newInfo.Type); } return(true); }
public async Task RenameSelectedType() { if (selectedType == AffixType.None) { return; } if (!AffixInfoDisplay.IsValid) { DialogBasic.Show("Renaming requires that all changes are saved first, but there are invalid entries. Please fix all errors before trying again."); return; } if (AffixInfoDisplay.IsChanged) { if ((await DialogCancellable.Show("Renaming requires that all changes be saved first. Save now?").result).IsCancelled) { return; } if (await SaveSelectedType() == false) { DialogBasic.Show("There was a problem saving. Please recheck the values and try again."); return; } } var result = await DialogStringInput.ShowBlocking($"Enter a new name for '{selectedType.Name}'", name => !AffixType.Exists(name) && AffixType.IsValidName(name), ShowInvalidNameMessage).result; if (result.IsOK) { string name = result.Value; var oldInfo = AffixInfo.GetAffixInfo(selectedType); AffixInfo.Deregister(selectedType); Serializer.DeleteAffixInfo(oldInfo.Type); var newType = AffixType.Replace(selectedType.ID, name); var newInfo = new AffixInfo(newType, oldInfo.ValueInfo, oldInfo.Description); AffixInfo.Register(newInfo); Serializer.SaveAffixInfoToDisk(newInfo); var display = displays[selectedType]; displays.Remove(selectedType); displays.Add(newType, display); display.SetAffixType(newType); SelectType(newType); } }
/// <summary> /// Delets the selected affix type. /// </summary> /// <returns>A task that returns whether or not the affix type was deleted.</returns> public async Task <bool> DeleteSelectedType() { if (selectedType == AffixType.None) { return(false); } if (await DialogCancellable.ShowBlocking($"Are you sure you want to delete {selectedType.Name}?").result == DialogResult.OK) { AffixInfo.Deregister(selectedType); AffixType.Remove(selectedType); Destroy(displays[selectedType].gameObject); displays.Remove(selectedType); Serializer.DeleteAffixInfo(selectedType); selectedType = AffixType.None; UpdateHeight(); return(true); } return(false); }