diff --git a/CustomWalls/Data/CustomMaterial.cs b/CustomWalls/Data/CustomMaterial.cs index 8dcdddb..195f6f8 100644 --- a/CustomWalls/Data/CustomMaterial.cs +++ b/CustomWalls/Data/CustomMaterial.cs @@ -13,6 +13,7 @@ public class CustomMaterial public MaterialDescriptor Descriptor { get; } public GameObject GameObject { get; } public Renderer MaterialRenderer { get; } + public string ErrorMessage { get; } = string.Empty; public CustomMaterial(string fileName) { @@ -37,13 +38,14 @@ public CustomMaterial(string fileName) { MaterialName = "Invalid Wall (Delete it!)", AuthorName = fileName, - Description = $"File: '{fileName}'" + + Icon = Utils.GetErrorIcon() + }; + + ErrorMessage = $"File: '{fileName}'" + "\n\nThis file failed to load." + "\n\nThis may have been caused by having duplicated files," + " another wall with the same name already exists or that the custom wall is simply just broken." + - "\n\nThe best thing is probably just to delete it!", - Icon = Utils.GetErrorIcon() - }; + "\n\nThe best thing is probably just to delete it!"; FileName = "DefaultMaterials"; } @@ -82,13 +84,14 @@ public CustomMaterial(byte[] materialObject, string name) { MaterialName = "Internal Error (Report it!)", AuthorName = $@"internalResource\{name}", - Description = $@"File: 'internalResource\\{name}'" + + Icon = Utils.GetErrorIcon() + }; + + ErrorMessage = $@"File: 'internalResource\\{name}'" + "\n\nAn internal asset has failed to load." + "\n\nThis shouldn't have happened and should be reported!" + " Remember to include the log related to this incident." + - "\n\nDiscord: Pespiri#5919", - Icon = Utils.GetErrorIcon() - }; + "\n\nDiscord: Pespiri#5919"; FileName = "DefaultMaterials"; } diff --git a/CustomWalls/Settings/UI/MaterialPreviewViewController.cs b/CustomWalls/Settings/UI/MaterialPreviewViewController.cs index 4bb1a04..0d3201f 100644 --- a/CustomWalls/Settings/UI/MaterialPreviewViewController.cs +++ b/CustomWalls/Settings/UI/MaterialPreviewViewController.cs @@ -1,9 +1,29 @@ -using BeatSaberMarkupLanguage.ViewControllers; +using BeatSaberMarkupLanguage.Attributes; +using BeatSaberMarkupLanguage.ViewControllers; +using CustomWalls.Data; +using CustomWalls.Utilities; +using HMUI; namespace CustomWalls.Settings.UI { internal class MaterialPreviewViewController : BSMLResourceViewController { public override string ResourceName => "CustomWalls.Settings.UI.Views.materialPreview.bsml"; + + [UIComponent("error-description")] + public TextPageScrollView errorDescription; + + public void OnMaterialWasChanged(CustomMaterial customMaterial) + { + if (!string.IsNullOrWhiteSpace(customMaterial?.ErrorMessage)) + { + errorDescription.gameObject.SetActive(true); + errorDescription.SetText($"{customMaterial.Descriptor?.MaterialName}:\n\n{Utils.SafeUnescape(customMaterial.ErrorMessage)}"); + } + else + { + errorDescription.gameObject.SetActive(false); + } + } } } diff --git a/CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs b/CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs index d3b1228..dacf9b7 100644 --- a/CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs +++ b/CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs @@ -25,7 +25,16 @@ public void Awake() if (!materialsListView) { materialsListView = BeatSaberUI.CreateViewController(); - materialsListView.customMaterialChanged += materialsDescriptionView.OnMaterialWasChanged; + + if (materialsDescriptionView) + { + materialsListView.customMaterialChanged += materialsDescriptionView.OnMaterialWasChanged; + } + + if (materialsPreviewView) + { + materialsListView.customMaterialChanged += materialsPreviewView.OnMaterialWasChanged; + } } } @@ -48,7 +57,6 @@ protected override void DidActivate(bool firstActivation, ActivationType activat protected override void BackButtonWasPressed(ViewController topViewController) { - // Dismiss ourselves BeatSaberUI.MainFlowCoordinator.DismissFlowCoordinator(this, null, false); } } diff --git a/CustomWalls/Settings/UI/Views/materialPreview.bsml b/CustomWalls/Settings/UI/Views/materialPreview.bsml index f5607f6..47c7e7b 100644 --- a/CustomWalls/Settings/UI/Views/materialPreview.bsml +++ b/CustomWalls/Settings/UI/Views/materialPreview.bsml @@ -2,4 +2,7 @@ + + + \ No newline at end of file