Skip to content

Commit

Permalink
Merge branch 'fix/load-image-size-too-large'
Browse files Browse the repository at this point in the history
  • Loading branch information
eeropomell committed May 29, 2024
2 parents d6fef9f + a66aa96 commit df2527d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 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
22 changes: 18 additions & 4 deletions Assets/Scripts/GUI/LoadReferenceImageButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public class LoadReferenceImageButton : BaseButton

[SerializeField] private LocalizedString m_ErrorHelpText;



public void RefreshDescription()
{
if (ReferenceImage != null)
{

if (!ReferenceImage.Valid)
// Problem: image can have error for other reasons too, not just for being too large
// displays "Image too large to load" under the file name.
if (ReferenceImage.Icon == ReferenceImageCatalog.m_Instance.ErrorImage)
{
SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName), ImageErrorExtraDescription());
}
Expand All @@ -45,7 +45,7 @@ public void RefreshDescription()

override protected void OnButtonPressed()
{
if (ReferenceImage == null || !ReferenceImage.Valid)
if (ReferenceImage == null)
{
return;
}
Expand All @@ -72,6 +72,20 @@ override protected void OnButtonPressed()
override public void ResetState()
{
base.ResetState();

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

if (available != IsAvailable())
{
SetButtonAvailable(available);
}

RefreshDescription();
}

public string ImageErrorExtraDescription()
Expand Down
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 df2527d

Please sign in to comment.