diff --git a/Assets/Prefabs/Panels/ReferencePanel/ReferencePanelIconBackgroundImage.prefab b/Assets/Prefabs/Panels/ReferencePanel/ReferencePanelIconBackgroundImage.prefab index 03cd6dfe23..8ebc10ae21 100644 --- a/Assets/Prefabs/Panels/ReferencePanel/ReferencePanelIconBackgroundImage.prefab +++ b/Assets/Prefabs/Panels/ReferencePanel/ReferencePanelIconBackgroundImage.prefab @@ -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: [] diff --git a/Assets/Prefabs/Panels/ReferencePanel/ReferencePanelTabImage.prefab b/Assets/Prefabs/Panels/ReferencePanel/ReferencePanelTabImage.prefab index 07682e8512..c827c25db0 100644 --- a/Assets/Prefabs/Panels/ReferencePanel/ReferencePanelTabImage.prefab +++ b/Assets/Prefabs/Panels/ReferencePanel/ReferencePanelTabImage.prefab @@ -121,6 +121,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] @@ -207,6 +225,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] @@ -262,6 +298,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] @@ -317,6 +371,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] @@ -372,6 +444,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] @@ -427,6 +517,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] @@ -482,6 +590,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] @@ -537,6 +663,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] @@ -592,6 +736,24 @@ MonoBehaviour: m_HoverScale: 1.2 m_HoverBoxColliderGrow: 0.2 m_AddOverlay: 0 + m_LoadHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238555522805800960 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] + m_ErrorHelpText: + m_TableReference: + m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86 + m_TableEntryReference: + m_KeyId: 238556149774557184 + m_Key: + m_FallbackState: 0 + m_WaitForCompletion: 0 + m_LocalVariables: [] references: version: 2 RefIds: [] diff --git a/Assets/Scripts/GUI/LoadBackgroundImageButton.cs b/Assets/Scripts/GUI/LoadBackgroundImageButton.cs index e4af884b2e..d5c0e46b85 100644 --- a/Assets/Scripts/GUI/LoadBackgroundImageButton.cs +++ b/Assets/Scripts/GUI/LoadBackgroundImageButton.cs @@ -13,6 +13,8 @@ // limitations under the License. using UnityEngine; +using UnityEngine.Localization; + namespace TiltBrush { @@ -24,10 +26,21 @@ public void RefreshDescription() { if (ReferenceImage != null) { - SetDescriptionText(ReferenceImage.FileName); + + // null if image doesn't have error + string errorMessage = ReferenceImage.ImageErrorExtraDescription(); + + if (errorMessage != null) + { + SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName), errorMessage); + } + else + { + SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName)); + } + } } - override protected void OnButtonPressed() { if (ReferenceImage == null) @@ -52,6 +65,8 @@ override public void ResetState() { SetButtonAvailable(available); } + + RefreshDescription(); } public void Set360ButtonTexture(Texture2D rTexture, float aspect = -1) diff --git a/Assets/Scripts/GUI/LoadReferenceImageButton.cs b/Assets/Scripts/GUI/LoadReferenceImageButton.cs index cbc222bfb3..6c0aa2da30 100644 --- a/Assets/Scripts/GUI/LoadReferenceImageButton.cs +++ b/Assets/Scripts/GUI/LoadReferenceImageButton.cs @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +using UnityEngine.Localization; +using UnityEngine; + namespace TiltBrush { @@ -23,7 +26,19 @@ public void RefreshDescription() { if (ReferenceImage != null) { - SetDescriptionText(ReferenceImage.FileName); + + // null if image doesn't have error + string errorMessage = ReferenceImage.ImageErrorExtraDescription(); + + if (errorMessage != null) + { + SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName), errorMessage); + } + else + { + SetDescriptionText(App.ShortenForDescriptionText(ReferenceImage.FileName)); + } + } } @@ -68,6 +83,8 @@ override public void ResetState() { SetButtonAvailable(available); } + + RefreshDescription(); } } } // namespace TiltBrush diff --git a/Assets/Scripts/ReferenceImage.cs b/Assets/Scripts/ReferenceImage.cs index 420b4fa2d8..75afa786fe 100644 --- a/Assets/Scripts/ReferenceImage.cs +++ b/Assets/Scripts/ReferenceImage.cs @@ -19,6 +19,8 @@ using Unity.VectorGraphics; using Superla.RadianceHDR; using UnityEngine; +using UnityEngine.Localization; +using UnityEngine.Localization.Settings; namespace TiltBrush { @@ -37,6 +39,10 @@ private enum ImageState // Same meaning as Future.State.Error // Invariant: m_coroutine == null Error, + // This is the only specific error message right now. ("Image too large to load") + // For other errors (e.g unknown format), we set Error state and display a generic error message "Image failed to load" + // ImageUtils.cs throws more specific errors, and we could implement them here as well in the future. + ErrorImageTooLarge = 31000 } // See ImageState for invariants @@ -49,6 +55,10 @@ private enum ImageState private string m_Path; private SVGParser.SceneInfo _SvgSceneInfo; + private LocalizedString m_ErrorImageTooLargeHelpText = new LocalizedString("Strings", "PANEL_REFERENCE_ICONIMAGE_LOADERRORTEXT"); + private LocalizedString m_ErrorGenericHelpText = new LocalizedString("Strings", "PANEL_REFERENCE_ICONIMAGE_GENERICERRORTEXT"); + + // public bool IsComposite => _SvgSceneInfo.Scene.Root.getsh public string FileName { get { return Path.GetFileName(m_Path); } } @@ -71,6 +81,23 @@ public float ImageAspect } } + // returns null if no error in image + public string ImageErrorExtraDescription() + { + if (m_State != ImageState.Error && m_State != ImageState.ErrorImageTooLarge) + { + return null; + } + else if (m_State == ImageState.Error) + { + return m_ErrorGenericHelpText.GetLocalizedStringAsync().Result; + } + else + { + return m_ErrorImageTooLargeHelpText.GetLocalizedStringAsync().Result; + } + } + public bool NotLoaded { get { return m_State == ImageState.Uninitialized || m_State == ImageState.NotReady; } @@ -93,7 +120,8 @@ public Texture2D Icon switch (m_State) { case ImageState.Ready: return m_Icon; - case ImageState.Error: return ReferenceImageCatalog.m_Instance.ErrorImage; + case ImageState.Error: + case ImageState.ErrorImageTooLarge: return ReferenceImageCatalog.m_Instance.ErrorImage; default: case ImageState.Uninitialized: case ImageState.NotReady: return null; @@ -290,7 +318,7 @@ public bool RequestLoad(bool allowMainThread = false) // If this file is too large for the platform, don't load it. if (!ValidateFileSize()) { - m_State = ImageState.Error; + m_State = ImageState.ErrorImageTooLarge; ControllerConsoleScript.m_Instance.AddNewLine( FileName + " is too large and could not be loaded.", true); @@ -550,6 +578,8 @@ IEnumerable RequestLoadCoroutine() else { // Problem reading the file? + // images with state ImageState.Error display a generic error message 'Image failed to load' when hovering over them in the reference panel + // TODO: use more specific error messages (e.g "Too large dimensions", "Unknown format") that are set in ImageUtils.cs? (that is called by ThreadedImageReader.cs) m_State = ImageState.Error; reader = null; yield break; diff --git a/Assets/Settings/Localization/Strings/Strings Shared Data.asset b/Assets/Settings/Localization/Strings/Strings Shared Data.asset index 82bf2e5130..c60ef0817e 100644 --- a/Assets/Settings/Localization/Strings/Strings Shared Data.asset +++ b/Assets/Settings/Localization/Strings/Strings Shared Data.asset @@ -3315,6 +3315,18 @@ MonoBehaviour: m_Key: DirectoryChooserPopupButton m_Metadata: m_Items: [] + - m_Id: 238556149774557184 + m_Key: PANEL_REFERENCE_ICONIMAGE_LOADERRORTEXT + m_Metadata: + m_Items: [] + - m_Id: 238935604850335744 + m_Key: PANEL_REFERENCE_ICONBACKGROUNDIMAGE_LOADERRORTEXT + m_Metadata: + m_Items: [] + - m_Id: 242372529028341760 + m_Key: PANEL_REFERENCE_ICONIMAGE_GENERICERRORTEXT + m_Metadata: + m_Items: [] m_Metadata: m_Items: [] m_KeyGenerator: diff --git a/Assets/Settings/Localization/Strings/Strings_en.asset b/Assets/Settings/Localization/Strings/Strings_en.asset index f85b1273b4..dc601834e7 100644 --- a/Assets/Settings/Localization/Strings/Strings_en.asset +++ b/Assets/Settings/Localization/Strings/Strings_en.asset @@ -11,7 +11,7 @@ MonoBehaviour: m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: e9620f8c34305754d8cc9a7e49e852d9, type: 3} m_Name: Strings_en - m_EditorClassIdentifier: + m_EditorClassIdentifier: m_LocaleId: m_Code: en m_SharedData: {fileID: 11400000, guid: c84355079ab3f3e4f8f3812258805f86, type: 2} @@ -3512,6 +3512,18 @@ MonoBehaviour: m_Localized: Pick a Subfolder m_Metadata: m_Items: [] + - m_Id: 238556149774557184 + 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: [] + - m_Id: 242372529028341760 + m_Localized: Image failed to load + m_Metadata: + m_Items: [] references: version: 2 RefIds: []