From b68bee63c64b309631971493d8e10b33e0ee2821 Mon Sep 17 00:00:00 2001 From: Jacktheholdy <jakob.holdinghausen@fau.de> Date: Fri, 10 Mar 2023 11:45:21 +0100 Subject: [PATCH] Fixed a Bug where Facts stay assigned in scroll even when deleted in the world. Now they also are deleted in the scoll. There are still issues with the dynamic scroll assignment however. Removed some unused functions implemented for the invalid assigned fact animations. Added some comments to popupbehavior script --- .gitignore | 2 + .../Scripts/InventoryStuff/ScrollDetails.cs | 27 ++++++++----- Assets/Scripts/UI/HideUI_mobile.cs | 6 ++- Assets/Scripts/UI/InGame/PopupBehavior.cs | 39 +++++++++++++------ 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 49aab4c2..0c70a879 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,5 @@ crashlytics-build.properties # Ignore UserSettings UserSettings/ +/Assets/Images/frameit_logo_512x512.png.meta +/Assets/Images/ScreenCapture_1024x500.png.meta diff --git a/Assets/Scripts/InventoryStuff/ScrollDetails.cs b/Assets/Scripts/InventoryStuff/ScrollDetails.cs index 4106ffad..15d3cf02 100644 --- a/Assets/Scripts/InventoryStuff/ScrollDetails.cs +++ b/Assets/Scripts/InventoryStuff/ScrollDetails.cs @@ -29,6 +29,7 @@ void Start() ScrollFactHintEvent.AddListener(animateHint); NewAssignmentEvent.AddListener(newAssignmentTrigger); + RemoveFactEvent.AddListener(removeFactFromAssignment); mmtAnswerPopUp.GetComponent<PopupBehavior>().hidePopUp(); } @@ -309,16 +310,22 @@ public void animateHint(GameObject scrollParameter, string scrollParameterUri) { } } } + + //this is called whenever a Fact is Deleted in the world, to make sure it is removed from the scroll + public void removeFactFromAssignment(Fact fact) + { + Transform originalScroll = gameObject.transform.GetChild(1).transform; + Transform originalScrollView = originalScroll.GetChild(1); + Transform originalViewport = originalScrollView.GetChild(0); - public void animateInvalidAssignedFact(GameObject scrollParameter) - { - //Animate ScrollParameter - scrollParameter.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger(); - } - - public void animateScrollParameter(string label) - { - var obj = ParameterDisplays.Find(x => x.transform.GetChild(0).GetComponent<RenderedScrollFact>().Label == label); - obj.GetComponentInChildren<Animator>().SetTrigger("animateHint"); + for (int i = 0; i < originalViewport.GetChild(0).childCount; i++) + { + RenderedScrollFact scrollFact = originalViewport.GetChild(0).transform.GetChild(i).GetChild(0).gameObject.GetComponent<RenderedScrollFact>(); + if (scrollFact.Label == fact.Label) + { + DropHandling dropHandling = originalViewport.GetChild(0).transform.GetChild(i).GetChild(0).gameObject.GetComponent<DropHandling>(); + dropHandling.OnPointerClick(null); + } + } } } diff --git a/Assets/Scripts/UI/HideUI_mobile.cs b/Assets/Scripts/UI/HideUI_mobile.cs index ea14e4c2..d7c5af05 100644 --- a/Assets/Scripts/UI/HideUI_mobile.cs +++ b/Assets/Scripts/UI/HideUI_mobile.cs @@ -126,8 +126,6 @@ void Start() } UICanvas.enabled = false; } - - } @@ -289,6 +287,10 @@ void CheckIf() UIconfig.CanvasOnOff_Array[16] = 1; UIconfig.CanvasOnOff_Array[20] = 0; + + //Maybe shift somewhere else. This fixes issues with the dynamic scroll application + //whenever the player opens the MathMode Menu, send new assignment, facts could have been deleted + CommunicationEvents.NewAssignmentEvent.Invoke(); return; } diff --git a/Assets/Scripts/UI/InGame/PopupBehavior.cs b/Assets/Scripts/UI/InGame/PopupBehavior.cs index 48beb882..28fe96da 100644 --- a/Assets/Scripts/UI/InGame/PopupBehavior.cs +++ b/Assets/Scripts/UI/InGame/PopupBehavior.cs @@ -61,13 +61,18 @@ public void hidePopUp() canvas.SetActive(false); } + /// <summary> + /// this method creates a helpful error message and shows the popup. For it to work properly, the setScroll and setParameterDisplays must have been set. + /// </summary> + /// <param name="startfact"></param> + /// <param name="errorInfo"></param> public void onFailedScrollInput(Fact startfact, Scroll.ScrollApplicationInfo errorInfo) { - setMessage(generateHelpfulMessage(errorInfo)); + setMessage(generateHelpfulMessageAndAnimateScrollParam(errorInfo)); showPopUp(); } - private string generateHelpfulMessage(Scroll.ScrollApplicationInfo errorInfo) + private string generateHelpfulMessageAndAnimateScrollParam(Scroll.ScrollApplicationInfo errorInfo) { if(errorInfo == null) { @@ -77,7 +82,8 @@ private string generateHelpfulMessage(Scroll.ScrollApplicationInfo errorInfo) errorMessage = ""; for (int i = 0; i < errorInfo.errors.Length; i++) { Scroll.ScrollApplicationCheckingError error = errorInfo.errors[i]; - + + //check which error ocurred and set Message to a helpful error message. if (error.kind == "nonTotal") { errorMessage += NonTotalMessage; @@ -86,13 +92,21 @@ private string generateHelpfulMessage(Scroll.ScrollApplicationInfo errorInfo) { invAssCount++; Scroll.ScrollFact fact = parseFactFromError(error); - foreach (GameObject g in parameterDisplays) + + //animate all invalidly assigned facts + if (parameterDisplays != null && fact != null) { - RenderedScrollFact scrollfact = g.transform.GetChild(0).GetComponent<RenderedScrollFact>(); - if(scrollfact.factUri == fact.@ref.uri) + foreach (GameObject g in parameterDisplays) { - scrollfact.ScrollParameterObject.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger(); + RenderedScrollFact scrollfact = g.transform.GetChild(0).GetComponent<RenderedScrollFact>(); + if (scrollfact.factUri == fact.@ref.uri) + { + scrollfact.ScrollParameterObject.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger(); + } } + } else + { + Debug.Log("PopupBehavior: Error: scroll or parameterDisplays not set."); } } else if (error.kind == "unknown") { @@ -137,15 +151,16 @@ private Scroll.ScrollFact parseFactFromError(Scroll.ScrollApplicationCheckingErr int factNameLength = rest.IndexOf('?') - 2; string factLabel = rest.Substring(2, factNameLength); - //add ?factName URI + //add ?factName to URI factUri += "?" + factLabel; - //Debug.Log("Parsed URI: " + factUri + " parsed fact label: " + factLabel); - + //find the required fact in the active scroll thats invalidly assigned + if((activeScroll == null)) + { + return null; + } foreach (Scroll.ScrollFact f in activeScroll.requiredFacts) { - //Debug.Log("KIND: " + f.kind + " Label: " + f.label + " Uri: " + f.@ref.uri); - //Debug.Log("Uri: " + f.@ref.uri); if (f.@ref.uri.Equals(factUri)) { return f; -- GitLab