diff --git a/Assets/Resources/Prefabs/Stage_Default.prefab b/Assets/Resources/Prefabs/Stage_Default.prefab index c3052a2dd566473223f70fbcea5c68ffbcdaf429..058f03a9948813b0fd22dfb47e1163a25ad8dec2 100644 --- a/Assets/Resources/Prefabs/Stage_Default.prefab +++ b/Assets/Resources/Prefabs/Stage_Default.prefab @@ -2368,6 +2368,11 @@ PrefabInstance: propertyPath: m_AnchorMin.x value: 0 objectReference: {fileID: 0} + - target: {fileID: 861183263081594858, guid: b996060e27da25c498842defc1996d84, + type: 3} + propertyPath: m_RootOrder + value: 9 + objectReference: {fileID: 0} - target: {fileID: 947958301574655299, guid: b996060e27da25c498842defc1996d84, type: 3} propertyPath: m_IsActive diff --git a/Assets/Resources/Prefabs/UI/FrameITUI.prefab b/Assets/Resources/Prefabs/UI/FrameITUI.prefab index 0a25a451f448fe6f022702696b76d7880bfe9769..3b1ab2046795ab96df86a52929609c25c436a09c 100644 --- a/Assets/Resources/Prefabs/UI/FrameITUI.prefab +++ b/Assets/Resources/Prefabs/UI/FrameITUI.prefab @@ -406,12 +406,12 @@ PrefabInstance: - target: {fileID: 8553388048532215990, guid: 884ac57de337c364391b247761071fb1, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8553388048532215990, guid: 884ac57de337c364391b247761071fb1, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8553388048532215990, guid: 884ac57de337c364391b247761071fb1, type: 3} @@ -503,6 +503,11 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 573039479540912931, guid: 292834880e6f0e54186b873acc62d3f2, + type: 3} + propertyPath: m_PresetInfoIsWorld + value: 1 + objectReference: {fileID: 0} - target: {fileID: 3716020922907832516, guid: 292834880e6f0e54186b873acc62d3f2, type: 3} propertyPath: m_SizeDelta.y @@ -556,7 +561,7 @@ PrefabInstance: - target: {fileID: 6500467619489830996, guid: 292834880e6f0e54186b873acc62d3f2, type: 3} propertyPath: m_AnchoredPosition.y - value: 506520 + value: 604800 objectReference: {fileID: 0} - target: {fileID: 7849991042685492731, guid: 292834880e6f0e54186b873acc62d3f2, type: 3} @@ -606,7 +611,7 @@ PrefabInstance: - target: {fileID: 7989559431199338490, guid: 292834880e6f0e54186b873acc62d3f2, type: 3} propertyPath: m_AnchoredPosition.y - value: -28140 + value: -33600 objectReference: {fileID: 0} - target: {fileID: 8004702056544321748, guid: 292834880e6f0e54186b873acc62d3f2, type: 3} diff --git a/Assets/Resources/Prefabs/UI/Ingame/FrameITUI_mobile.prefab b/Assets/Resources/Prefabs/UI/Ingame/FrameITUI_mobile.prefab index 4f103c2a87f42fc0c1b6d7d5d77d3e1b80155b41..d789848f1792a669a3e2061c919f159aea604fca 100644 --- a/Assets/Resources/Prefabs/UI/Ingame/FrameITUI_mobile.prefab +++ b/Assets/Resources/Prefabs/UI/Ingame/FrameITUI_mobile.prefab @@ -4952,7 +4952,7 @@ PrefabInstance: - target: {fileID: 7989559431199338490, guid: 292834880e6f0e54186b873acc62d3f2, type: 3} propertyPath: m_AnchoredPosition.y - value: -2000 + value: -2400 objectReference: {fileID: 0} - target: {fileID: 8004702056544321748, guid: 292834880e6f0e54186b873acc62d3f2, type: 3} diff --git a/Assets/Resources/Prefabs/UI/Ingame/HidingCanvas.prefab b/Assets/Resources/Prefabs/UI/Ingame/HidingCanvas.prefab index e1fc2e4ba6b4d00a93d4de96e012abe8fd9bdea4..846b8783720d879dc70688617a77c180daa49a78 100644 --- a/Assets/Resources/Prefabs/UI/Ingame/HidingCanvas.prefab +++ b/Assets/Resources/Prefabs/UI/Ingame/HidingCanvas.prefab @@ -2826,6 +2826,7 @@ GameObject: - component: {fileID: 8004702057932254679} - component: {fileID: 8004702057932254676} - component: {fileID: 3671007757941716709} + - component: {fileID: 582397463733288183} m_Layer: 5 m_Name: HidingCanvas m_TagString: Untagged @@ -2937,6 +2938,20 @@ MonoBehaviour: m_EditorClassIdentifier: ScrollShowUI: {fileID: 8004702057540368332} ScrollWebView: {fileID: 5843063412347785762} +--- !u!114 &582397463733288183 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8004702057932254674} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ae310511ad607a64e891bcb46517277b, type: 3} + m_Name: + m_EditorClassIdentifier: + DynamicScrollDescriptionsActive: 1 + AutomaticHintGenerationActive: 1 --- !u!1 &8004702058016740896 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Worlds/RiverWorld.unity b/Assets/Scenes/Worlds/RiverWorld.unity index 67c9fecf6c840a9b3d4ca735eadd035c698042fa..a00e7532d70eacefb985ddff18aa872aa7df011a 100644 --- a/Assets/Scenes/Worlds/RiverWorld.unity +++ b/Assets/Scenes/Worlds/RiverWorld.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44084534, g: 0.48955458, b: 0.56959116, a: 1} + m_IndirectSpecularColor: {r: 0.4410664, g: 0.4898227, b: 0.5699191, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -39524,6 +39524,18 @@ Transform: type: 3} m_PrefabInstance: {fileID: 1858641942} m_PrefabAsset: {fileID: 0} +--- !u!114 &1860195005 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 5465760683304490972, guid: b07552db700124a4680401e6fb94c186, + type: 3} + m_PrefabInstance: {fileID: 3020720018843181009} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ae310511ad607a64e891bcb46517277b, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &1862008647 PrefabInstance: m_ObjectHideFlags: 0 @@ -63196,6 +63208,11 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 8063809797576254706, guid: b07552db700124a4680401e6fb94c186, + type: 3} + propertyPath: activeScroll + value: + objectReference: {fileID: 1860195005} - target: {fileID: 8111165885733284748, guid: b07552db700124a4680401e6fb94c186, type: 3} propertyPath: m_AnchorMax.y diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactWrapper/RenderedScrollFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactWrapper/RenderedScrollFact.cs index a52dff62b83a48138d8df0498654c1ccd5e3ec7f..cb0f1d45327d6e11bd74542ba5cd986af97ec388 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactWrapper/RenderedScrollFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactWrapper/RenderedScrollFact.cs @@ -69,6 +69,7 @@ protected override void FactUpdated() ResetPayload(); base.FactUpdated(); + SwitchScrollUI.activeScrollData.AssignFact(ScrollFactURI, Fact); } private void ResetPayload() @@ -97,21 +98,21 @@ protected override void _DeleteFactEvent(Fact fact) protected override void _OnEnable() { - ActiveScroll.HintAvailableEvent.AddListener(OnHintAvailable); - ActiveScroll.OnScrollDynamicInfoUpdated.AddListener(OnScrollUpdated); + SwitchScrollUI.activeScrollData.HintAvailableEvent.AddListener(OnHintAvailable); + SwitchScrollUI.activeScrollData.OnScrollDynamicInfoUpdated.AddListener(OnScrollUpdated); ResetPayload(); } protected override void _OnDisable() { - ActiveScroll.HintAvailableEvent.RemoveListener(OnHintAvailable); - ActiveScroll.OnScrollDynamicInfoUpdated.RemoveListener(OnScrollUpdated); + SwitchScrollUI.activeScrollData.HintAvailableEvent.RemoveListener(OnHintAvailable); + SwitchScrollUI.activeScrollData.OnScrollDynamicInfoUpdated.RemoveListener(OnScrollUpdated); } public void Populate(Scroll scroll, string scroll_fact_uri) { - _Scroll = scroll; - _ScrollFactURI = scroll_fact_uri; + ScrollFactURI = scroll_fact_uri; + Scroll = scroll; _URI = ScrollFactURI; ResetPayload(); @@ -124,7 +125,7 @@ private void SetLabel(string label) private void OnScrollUpdated(Scroll rendered) { // this if has been copied during refactoring, I don't know if we need it^^ - if(ActiveScroll.Instance.DynamicScrollDescriptionsActive && + if(SwitchScrollUI.activeScrollData.DynamicScrollDescriptionsActive && rendered.requiredFacts.Any(rf => rf.@ref.uri == ScrollFactURI)) { // Update ScrollParameter label (side effect of setting the property "Scroll") @@ -134,7 +135,7 @@ private void OnScrollUpdated(Scroll rendered) { public void OnClickHintButton() { - ActiveScroll.Instance.ButtonClicked(new HintScrollButton(URI)); + SwitchScrollUI.activeScrollData.ButtonClicked(new HintScrollButton(URI)); } private void OnHintAvailable(IReadOnlyList<string> uris) diff --git a/Assets/Scripts/InteractionEngine/ShinyThings.cs b/Assets/Scripts/InteractionEngine/ShinyThings.cs index cb0ff2154c45d801a57fff2742ac9fed1185a151..4d33baf625a1d63c964ca9ef048aacb508b1854f 100644 --- a/Assets/Scripts/InteractionEngine/ShinyThings.cs +++ b/Assets/Scripts/InteractionEngine/ShinyThings.cs @@ -28,13 +28,19 @@ public GameObject private void OnEnable() { - ActiveScroll.OnScrollApplicationError.AddListener(LetItRain); + SwitchScrollUI.OnActiveScrollDataInitialized.AddListener(OnActiveScrollDataInitialized); CommunicationEvents.AnimateExistingAsSolutionEvent.AddListener(HighlightWithFireworks); } + private void OnActiveScrollDataInitialized() + { + SwitchScrollUI.activeScrollData.OnScrollApplicationError.AddListener(LetItRain); + SwitchScrollUI.OnActiveScrollDataInitialized.RemoveListener(OnActiveScrollDataInitialized); + } + private void OnDisable() { - ActiveScroll.OnScrollApplicationError.RemoveListener(LetItRain); + SwitchScrollUI.activeScrollData.OnScrollApplicationError.RemoveListener(LetItRain); CommunicationEvents.AnimateExistingAsSolutionEvent.RemoveListener(HighlightWithFireworks); } diff --git a/Assets/Scripts/InventoryStuff/ActiveScroll.cs b/Assets/Scripts/InventoryStuff/ActiveScroll.cs index 67fc90f75ba1d3d6d59159d2d027c3e0a061f410..20d585471bd178177af92e3ca9dec507ce3c934e 100644 --- a/Assets/Scripts/InventoryStuff/ActiveScroll.cs +++ b/Assets/Scripts/InventoryStuff/ActiveScroll.cs @@ -11,74 +11,33 @@ #nullable enable annotations /// <summary> -/// This class is a singleton that keeps track of the currently active scroll and comunicates with the FrameIT Server. +/// This class keeps track of the currently active scroll and comunicates with the FrameIT Server. /// It represents the model of the Model-View-Controler pattern. /// </summary> +[Serializable] public class ActiveScroll : MonoBehaviour { - #region static part - - /// <summary> - /// Static property to access the singleton instance of ActiveScroll - /// </summary> - public static ActiveScroll Instance - { - get => _Instance; - set - { - if (_Instance != value) - Destroy(_Instance); - - _Instance = value; - } - } - private static ActiveScroll _Instance; /** <summary>Event that is invoked when a scroll button is clicked, e.g. magic button. You can use it to handle custom buttons.</summary> */ - public static UnityEvent<ScrollButton> OnButtonClick = new(); + public UnityEvent<ScrollButton> OnButtonClick = new(); /** <summary>Notifies about availible hints.</summary> */ - public static UnityEvent<IReadOnlyList<string>> HintAvailableEvent = new(); + public UnityEvent<IReadOnlyList<string>> HintAvailableEvent = new(); /** <summary>Event that is invoked when a fact has been assigned to a slot and the ui needs to update.</summary> */ - public static UnityEvent<string,SlotAssignment> OnFactAssignmentUpdated = new(); + public UnityEvent<string,SlotAssignment> OnFactAssignmentUpdated = new(); /** <summary>Event that is invoked when the MMT server returned an error.</summary> */ - public static UnityEvent<string> OnMMTServerComunicationError = new(); + public UnityEvent<string> OnMMTServerComunicationError = new(); /** <summary>Event that is invoked when the scroll dynamic info returned errors in the current scroll assignment.</summary> */ - public static UnityEvent<ScrollApplicationCheckingError[]> OnScrollDynamicInfoError = new(); + public UnityEvent<ScrollApplicationCheckingError[]> OnScrollDynamicInfoError = new(); /** <summary>Event that is invoked when the scroll application returned errors in the current assignment.</summary> */ - public static UnityEvent<ScrollApplicationCheckingError[]> OnScrollApplicationError = new(); + public UnityEvent<ScrollApplicationCheckingError[]> OnScrollApplicationError = new(); /** <summary>Event that is invoked when the OnMMTServerError or OnScrollApplicationFailed error state has been resolved and e.g. the error popup can be cloesed.</summary> */ - public static UnityEvent OnCancelErrorState = new(); + public UnityEvent OnCancelErrorState = new(); /** <summary>Event that is invoked when the scroll has been solved.</summary> */ - public static UnityEvent<IReadOnlyList<Fact>> OnScrollSolved = new(); + public UnityEvent<IReadOnlyList<Fact>> OnScrollSolved = new(); /** <summary>Event that is invoked when an other scroll has been selected.</summary> */ - public static UnityEvent<ActiveScroll> OnScrollChanged = new(); + public UnityEvent<Scroll> OnScrollChanged = new(); /** <summary>Event that is invoked when the dynamic info of the scroll has been updated e.g. because a fact has been assigned.</summary> */ - public static UnityEvent<Scroll> OnScrollDynamicInfoUpdated = new(); - - void Awake() - { - Instance = this; - } - private void OnDestroy() - { - _Instance = null; - } - - - /// <summary> - /// Creates a new instance and sets the scroll - /// </summary> - public static void SetScroll(Scroll scroll_to_set) - { - Instance = new ActiveScroll - { - Scroll = scroll_to_set - }; - // notify the observers that the scroll has changed - OnScrollChanged.Invoke(Instance); - } - - #endregion static part + public UnityEvent<Scroll> OnScrollDynamicInfoUpdated = new(); public bool DynamicScrollDescriptionsActive = true; @@ -116,7 +75,7 @@ public static void SetScroll(Scroll scroll_to_set) public Scroll Scroll { get => _Scroll; - private set { + set { _Scroll = value; // initialize the assignments dictionary with the references to the required fact slots as keys @@ -136,6 +95,8 @@ private set { _Assignments[key].IsVisible = show; } } + // notify the observers that the scroll has changed + OnScrollChanged.Invoke(value); } } /// <summary> @@ -191,9 +152,14 @@ public void AssignFact(string slotUri, Fact fact) if (Assignments.ContainsKey(slotUri)) { var slot = _Assignments[slotUri]; + + // return if the slot is already assigned to the given value (avoid unnecessary ui updates and frameit Server requests) + //if ((fact is null && !slot.IsSet) || (slot.IsSet && slot.fact.Id == fact.Id)) return; + if (fact is null && !slot.IsSet) return; + slot.fact = fact; - OnFactAssignmentUpdated.Invoke(slotUri, slot); SendCurrentFactAssignments(); + OnFactAssignmentUpdated.Invoke(slotUri, slot); } else { throw new ArgumentException($"Can't assign fact, the given slot doesn't exist on the current scroll: '{slotUri}'"); } @@ -218,7 +184,7 @@ public void AssignFact(string slotUri, Fact fact) // find the first empty slot and assign the fact to it try { - KeyValuePair<string, SlotAssignment> emptySlot = _Assignments.First(pair => pair.Value.IsSet); + KeyValuePair<string, SlotAssignment> emptySlot = _Assignments.First(pair => !pair.Value.IsSet); AssignFact(emptySlot.Key, fact); return emptySlot.Key; } catch (Exception) { @@ -266,11 +232,15 @@ private IEnumerator SendScrollApplication() OnCancelErrorState.Invoke(); } - yield return __GenerateUnityFactsForAcquiredMMTFacts(scrollApplication.acquiredFacts); + var new_facts = __GenerateUnityFactsForAcquiredMMTFacts(scrollApplication.acquiredFacts); + if (scrollApplication.acquiredFacts.Count >= 0 || scrollApplication.errors.Length == 0) + { + OnScrollSolved.Invoke(new_facts); + } } } - private IEnumerator __GenerateUnityFactsForAcquiredMMTFacts(List<MMTFact> pushoutFacts) + private List<Fact> __GenerateUnityFactsForAcquiredMMTFacts(List<MMTFact> pushoutFacts) { List<Fact> new_facts = new(); Dictionary<string, string> old_to_new = new(); @@ -289,7 +259,7 @@ private IEnumerator __GenerateUnityFactsForAcquiredMMTFacts(List<MMTFact> pushou foreach (Fact new_fact in new_list) { - Fact added = FactAdder.AddFactIfNotFound(new_fact, out bool exists, samestep, null, ActiveScroll.Instance.Scroll.label); + Fact added = FactAdder.AddFactIfNotFound(new_fact, out bool exists, samestep, null, Scroll.label); if (!exists) { new_facts.Add(added); @@ -307,8 +277,7 @@ private IEnumerator __GenerateUnityFactsForAcquiredMMTFacts(List<MMTFact> pushou } Debug.Log($"Facts parsed within {(System.DateTime.UtcNow - parseTime).TotalMilliseconds}ms"); - OnScrollSolved.Invoke(new_facts); - yield break; + return new_facts; } #endregion MagicButton @@ -411,8 +380,7 @@ private IEnumerator _SendAssignments() .Where(err => err.kind != "nonTotal") // expected .ToArray(); - if (errors.Length > 0) - OnScrollDynamicInfoError.Invoke(errors); + if (errors.Length > 0) OnScrollDynamicInfoError.Invoke(errors); _ProcessScrollDynamicInfo(scrollDynamicInfo); } @@ -513,8 +481,8 @@ private IEnumerator SendView(string endpoint) /// Returns json serialized ScrollApplication containing the list of ScrollAssignments.</summary> string prepareScrollAssignments() { - List<ScrollAssignment> assignmentList = Assignments.Where(assignment => assignment.Value is not null) - .Select(assignment => new ScrollAssignment(assignment.Key, assignment.Value.fact.ScalaFact.@ref)) + List<ScrollAssignment> assignmentList = Assignments.Where(assignment => assignment.Value.IsSet) + .Select(assignment => new ScrollAssignment(assignment.Key, assignment.Value.fact.ServerDefinition)) .ToList(); return JsonConvert.SerializeObject(new ScrollApplication(Scroll.ScrollReference, assignmentList)); diff --git a/Assets/Scripts/InventoryStuff/DisplayScrolls.cs b/Assets/Scripts/InventoryStuff/DisplayScrolls.cs index 2ce0a98a0e6c735d625366e0e681cb2590d90a40..d9c6616d47d2496ff554d8d38d969dc5d2d3845b 100644 --- a/Assets/Scripts/InventoryStuff/DisplayScrolls.cs +++ b/Assets/Scripts/InventoryStuff/DisplayScrolls.cs @@ -39,6 +39,6 @@ void BuildScrollGUI() } REST_JSON_API.Scroll preferredStartScroll = AllowedScrolls.Find(x => x.label.Equals(preferredStartScrollName)); - if (preferredStartScroll != null) ActiveScroll.SetScroll(preferredStartScroll); + if (preferredStartScroll != null) SwitchScrollUI.activeScrollData.Scroll = preferredStartScroll; } } diff --git a/Assets/Scripts/InventoryStuff/ScrollClickedScript.cs b/Assets/Scripts/InventoryStuff/ScrollClickedScript.cs index 45c8f5b269cf89eb43794e0b82445eec5b018046..7936ebbe44968473174c1e9e2f5707ec5a86d89d 100644 --- a/Assets/Scripts/InventoryStuff/ScrollClickedScript.cs +++ b/Assets/Scripts/InventoryStuff/ScrollClickedScript.cs @@ -8,6 +8,6 @@ public class ScrollClickedScript : MonoBehaviour, IPointerDownHandler public void OnPointerDown(PointerEventData eventData) { - ActiveScroll.SetScroll(this.scroll); + SwitchScrollUI.activeScrollData.Scroll = this.scroll; } } diff --git a/Assets/Scripts/UI/FactExplorer/OpenFactExplorer.cs b/Assets/Scripts/UI/FactExplorer/OpenFactExplorer.cs index ff1434fe3a8ab318bf698f866e240077b2ff93b1..f407a6c7723059f5a1123af6b129e17aaad7161a 100644 --- a/Assets/Scripts/UI/FactExplorer/OpenFactExplorer.cs +++ b/Assets/Scripts/UI/FactExplorer/OpenFactExplorer.cs @@ -109,7 +109,7 @@ private void DoOpenFactExplorer() } private bool DoSetActive() - => ActiveScroll.Instance.AssignOrRemoveFactToNextEmptySlot(CachedFactWrapper.Fact) is not null; + => SwitchScrollUI.activeScrollData.AssignOrRemoveFactToNextEmptySlot(CachedFactWrapper.Fact) is not null; #endregion Implementation } diff --git a/Assets/Scripts/UI/InGame/PopupBehavior.cs b/Assets/Scripts/UI/InGame/PopupBehavior.cs index 6f1826ff6073717298747de548efd3b74e51477d..6ef35929273be86489540383caf4c3b4ff452e16 100644 --- a/Assets/Scripts/UI/InGame/PopupBehavior.cs +++ b/Assets/Scripts/UI/InGame/PopupBehavior.cs @@ -27,18 +27,18 @@ public string MessageText void OnEnable() { - ActiveScroll.OnMMTServerComunicationError.AddListener(OnShowErrorMessage); - ActiveScroll.OnScrollDynamicInfoError.AddListener(OnFailedScrollInput); - ActiveScroll.OnScrollApplicationError.AddListener(OnFailedScrollInput); - ActiveScroll.OnCancelErrorState.AddListener(HidePopUp); + SwitchScrollUI.activeScrollData.OnMMTServerComunicationError.AddListener(OnShowErrorMessage); + SwitchScrollUI.activeScrollData.OnScrollDynamicInfoError.AddListener(OnFailedScrollInput); + SwitchScrollUI.activeScrollData.OnScrollApplicationError.AddListener(OnFailedScrollInput); + SwitchScrollUI.activeScrollData.OnCancelErrorState.AddListener(HidePopUp); } void OnDisable() { - ActiveScroll.OnMMTServerComunicationError.RemoveListener(OnShowErrorMessage); - ActiveScroll.OnScrollDynamicInfoError.RemoveListener(OnFailedScrollInput); - ActiveScroll.OnScrollApplicationError.RemoveListener(OnFailedScrollInput); - ActiveScroll.OnCancelErrorState.RemoveListener(HidePopUp); + SwitchScrollUI.activeScrollData.OnMMTServerComunicationError.RemoveListener(OnShowErrorMessage); + SwitchScrollUI.activeScrollData.OnScrollDynamicInfoError.RemoveListener(OnFailedScrollInput); + SwitchScrollUI.activeScrollData.OnScrollApplicationError.RemoveListener(OnFailedScrollInput); + SwitchScrollUI.activeScrollData.OnCancelErrorState.RemoveListener(HidePopUp); } void Awake() @@ -165,7 +165,7 @@ private MMTFact parseFactFromError(ScrollApplicationCheckingError error) factUri += "?" + factLabel; //find the required fact in the active scroll thats invalidly assigned - return ActiveScroll.Instance.Scroll.requiredFacts + return SwitchScrollUI.activeScrollData.Scroll.requiredFacts .Find(decl => decl.@ref.uri == error.fact.uri); } } diff --git a/Assets/Scripts/UI/InGame/ScrollDetails.cs b/Assets/Scripts/UI/InGame/ScrollDetails.cs index 85f4e63f8b475426df25eed5b1b72e587703a98d..1302849c22589533a0d97e4b61d1f9f77450ec83 100644 --- a/Assets/Scripts/UI/InGame/ScrollDetails.cs +++ b/Assets/Scripts/UI/InGame/ScrollDetails.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using TMPro; using UnityEngine; -using static CommunicationEvents; public class ScrollDetails : ScrollView { @@ -30,8 +29,7 @@ void Awake() { Instance = this; - if (cursor == null) - cursor = FindObjectOfType<WorldCursor>(); + if (cursor == null) cursor = FindObjectOfType<WorldCursor>(); Popup = mmtAnswerPopUp.GetComponent<PopupBehavior>(); Popup.gameObject.SetActive(true); // force Awake @@ -39,16 +37,16 @@ void Awake() private void OnEnable() { - ActiveScroll.OnScrollChanged.AddListener(ShowScroll); - ActiveScroll.OnFactAssignmentUpdated.AddListener(OnFactAssignmentUpdated); - ActiveScroll.OnScrollDynamicInfoUpdated.AddListener(UpdateScrollDescription); + SwitchScrollUI.activeScrollData.OnScrollChanged.AddListener(ShowScroll); + SwitchScrollUI.activeScrollData.OnFactAssignmentUpdated.AddListener(OnFactAssignmentUpdated); + SwitchScrollUI.activeScrollData.OnScrollDynamicInfoUpdated.AddListener(UpdateScrollDescription); } private void OnDisable() { - ActiveScroll.OnScrollChanged.RemoveListener(ShowScroll); - ActiveScroll.OnFactAssignmentUpdated.RemoveListener(OnFactAssignmentUpdated); - ActiveScroll.OnScrollDynamicInfoUpdated.RemoveListener(UpdateScrollDescription); + SwitchScrollUI.activeScrollData.OnScrollChanged.RemoveListener(ShowScroll); + SwitchScrollUI.activeScrollData.OnFactAssignmentUpdated.RemoveListener(OnFactAssignmentUpdated); + SwitchScrollUI.activeScrollData.OnScrollDynamicInfoUpdated.RemoveListener(UpdateScrollDescription); } private void OnDestroy() @@ -60,7 +58,7 @@ private void OnDestroy() /// Update the scroll details screen to display the currently active scroll /// </summary> /// <param name="activeScroll"></param> - private void ShowScroll(ActiveScroll activeScroll) + private void ShowScroll(Scroll newScroll) { Transform originalScroll = gameObject.transform.GetChild(1); Transform originalScrollView = originalScroll.GetChild(1); @@ -68,14 +66,13 @@ private void ShowScroll(ActiveScroll activeScroll) //Clear all current ScrollFacts originalViewport.GetChild(0).gameObject.DestroyAllChildren(); - Scroll scroll = activeScroll.Scroll; - originalScroll.GetChild(0).GetComponent<TextMeshProUGUI>().text = scroll.description; + originalScroll.GetChild(0).GetComponent<TextMeshProUGUI>().text = newScroll.description; //ParameterDisplays.ForEach(gameObj => Destroy(gameObj)); ParameterDisplays = new(); // generate parameter display slots - foreach (var slot in activeScroll.Assignments) + foreach (var slot in SwitchScrollUI.activeScrollData.Assignments) { GameObject originalObj = Instantiate(parameterDisplayPrefab, originalViewport.GetChild(0)); @@ -85,14 +82,14 @@ private void ShowScroll(ActiveScroll activeScroll) ParameterDisplays.Add(originalRSF); - originalRSF.Populate(scroll, slot.Key); + originalRSF.Populate(newScroll, slot.Key); originalRSF.transform.parent.gameObject.SetActive(slot.Value.IsVisible); } } private void UpdateScrollDescription(Scroll rendered) { - if (ActiveScroll.Instance.DynamicScrollDescriptionsActive) + if (SwitchScrollUI.activeScrollData.DynamicScrollDescriptionsActive) { // Update scroll-description Transform scroll = gameObject.transform.GetChild(1).transform; scroll.GetChild(0).GetComponent<TextMeshProUGUI>().text = rendered.description; @@ -103,7 +100,13 @@ private void OnFactAssignmentUpdated(string slotUri, ActiveScroll.SlotAssignment { RenderedScrollFact changed = ParameterDisplays.Find(RSF => RSF.ScrollFactURI == slotUri); - if (changed != null) + // check if the RenderedScrollFact already contains the assigend fact + // this is to prevent an endless loop because updating the Fact property will trigger the NewAssignmentEvent + // TODO: BE: find an other solution beacause this results in requesting the scroll dynamic update twice from the server + if (changed != null && ( + (!slotAssignment.IsSet && changed.IsSet) || + (slotAssignment.IsSet && changed.URI != slotAssignment.fact?.Id) + )) { changed.Fact = slotAssignment.fact; } diff --git a/Assets/Scripts/UI/InGame/SwitchScrollUI.cs b/Assets/Scripts/UI/InGame/SwitchScrollUI.cs index b25756019eb3242364856f300111d63166f1f706..b9b20bcf2aae1f79deb1c145ca2d244c023d1097 100644 --- a/Assets/Scripts/UI/InGame/SwitchScrollUI.cs +++ b/Assets/Scripts/UI/InGame/SwitchScrollUI.cs @@ -1,11 +1,24 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Events; public class SwitchScrollUI : MonoBehaviour { + /// <summary> + /// Reference to the data of the active scroll displayed in the scroll UI + /// </summary> + public static ActiveScroll activeScrollData; + public static UnityEvent OnActiveScrollDataInitialized = new(); + public GameObject ScrollShowUI; public GameObject ScrollWebView; + + private void Awake() + { + activeScrollData = GetComponent<ActiveScroll>(); + OnActiveScrollDataInitialized.Invoke(); + } void OnEnable() { switch (UIconfig.scrollViewVersion)