Skip to content

Commit

Permalink
Add image load size informative error message to background images panel
Browse files Browse the repository at this point in the history
  • Loading branch information
eeropomell committed May 28, 2024
1 parent 85bedb9 commit 1745ab4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ MonoBehaviour:
m_HoverScale: 1.2
m_HoverBoxColliderGrow: 0.2
m_AddOverlay: 0
m_ErrorHelpText:
m_TableReference:
m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86
m_TableEntryReference:
m_KeyId: 238935604850335744
m_Key:
m_FallbackState: 0
m_WaitForCompletion: 0
m_LocalVariables: []
references:
version: 2
RefIds: []
47 changes: 35 additions & 12 deletions Assets/Scripts/GUI/LoadBackgroundImageButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,39 @@
// limitations under the License.

using UnityEngine;
using UnityEngine.Localization;

namespace TiltBrush
{

public class LoadBackgroundImageButton : BaseButton
{
public ReferenceImage ReferenceImage { get; set; }

[SerializeField] private LocalizedString m_ErrorHelpText;

// this is commented out and moved into ResetState() because
// for a new image (ie., one that isn't in the cache yet), !ReferenceImage.Valid, even if the size is valid (ie less than the max size)
// TODO: figure out if it's bad to move this into ResetState()
public void RefreshDescription()
{
if (ReferenceImage != null)
{
SetDescriptionText(ReferenceImage.FileName);
}
}
/* if (ReferenceImage != null)
{
if (!ReferenceImage.Valid)
{
SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName), ImageErrorExtraDescription());
}
else
{
SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName));
}
}*/
}
override protected void OnButtonPressed()
{
if (ReferenceImage == null)
if (ReferenceImage == null || !ReferenceImage.Valid)
{
return;
}
Expand All @@ -41,16 +56,18 @@ override public void ResetState()
{
base.ResetState();

// Make ourselves unavailable if our image has an error.
bool available = false;
if (ReferenceImage != null)
if (ReferenceImage == null)
{
available = ReferenceImage.NotLoaded || ReferenceImage.Valid;
return;
}

if (available != IsAvailable())
if (!ReferenceImage.Valid)
{
SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName), ImageErrorExtraDescription());
}
else
{
SetButtonAvailable(available);
SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName));
}
}

Expand All @@ -62,5 +79,11 @@ public void Set360ButtonTexture(Texture2D rTexture, float aspect = -1)
m_ButtonRenderer.material.SetFloat("_Stereoscopic", isStereo);
}


public string ImageErrorExtraDescription()
{
return m_ErrorHelpText.GetLocalizedStringAsync().Result;
}

}
} // namespace TiltBrush
Original file line number Diff line number Diff line change
Expand Up @@ -3319,6 +3319,10 @@ MonoBehaviour:
m_Key: PANEL_REFERENCE_ICONIMAGE_LOADERRORTEXT
m_Metadata:
m_Items: []
- m_Id: 238935604850335744
m_Key: PANEL_REFERENCE_ICONBACKGROUNDIMAGE_LOADERRORTEXT
m_Metadata:
m_Items: []
m_Metadata:
m_Items: []
m_KeyGenerator:
Expand Down
4 changes: 4 additions & 0 deletions Assets/Settings/Localization/Strings/Strings_en.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3516,6 +3516,10 @@ MonoBehaviour:
m_Localized: Image too large to load
m_Metadata:
m_Items: []
- m_Id: 238935604850335744
m_Localized: Image too large to load
m_Metadata:
m_Items: []
references:
version: 2
RefIds: []

0 comments on commit 1745ab4

Please sign in to comment.