Skip to content

Commit

Permalink
Changed error description behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Pespiri committed Mar 26, 2020
1 parent 80cad31 commit 96775ac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
19 changes: 11 additions & 8 deletions CustomWalls/Data/CustomMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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";
}
Expand Down Expand Up @@ -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";
}
Expand Down
22 changes: 21 additions & 1 deletion CustomWalls/Settings/UI/MaterialPreviewViewController.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
12 changes: 10 additions & 2 deletions CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ public void Awake()
if (!materialsListView)
{
materialsListView = BeatSaberUI.CreateViewController<MaterialListViewController>();
materialsListView.customMaterialChanged += materialsDescriptionView.OnMaterialWasChanged;

if (materialsDescriptionView)
{
materialsListView.customMaterialChanged += materialsDescriptionView.OnMaterialWasChanged;
}

if (materialsPreviewView)
{
materialsListView.customMaterialChanged += materialsPreviewView.OnMaterialWasChanged;
}
}
}

Expand All @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions CustomWalls/Settings/UI/Views/materialPreview.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<horizontal bg='panel-top' pad-left='10' pad-right='10' horizontal-fit='PreferredSize'>
<text text='Wall Preview' align='Center' font-size='10' />
</horizontal>
<horizontal pref-width='100' pref-height='45'>
<text-page id='error-description' />
</horizontal>
</vertical>

0 comments on commit 96775ac

Please sign in to comment.