From 9ad0b51f86bc1d0dce4583ac7ef01482c9fb7ba0 Mon Sep 17 00:00:00 2001
From: Jacktheholdy <jakob.holdinghausen@fau.de>
Date: Wed, 22 Feb 2023 11:09:56 +0100
Subject: [PATCH] Added Gadget Name Display and a popup window showing scroll
 application errors.

Added an animation at the wrongly assigned fact conteiners in scroll
---
 .../InteractionEngine/CommunicationEvents.cs  |  5 ++--
 .../Scripts/InteractionEngine/ShinyThings.cs  | 26 +++++++++++++------
 Assets/Scripts/InventoryStuff/DisplayFacts.cs |  2 +-
 Assets/Scripts/Loading/Stage.cs               |  2 +-
 Assets/Scripts/StageStatic.cs                 | 20 +++++++-------
 5 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs
index be559e69..d5a27cf2 100644
--- a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs
+++ b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs
@@ -16,16 +16,17 @@ public static class CommunicationEvents
     public static UnityEvent<Fact> RemoveFactEvent = new();
 
     public static UnityEvent<Fact, FactObject.FactMaterials> PushoutFactEvent = new();
-    public static UnityEvent<Fact> PushoutFactFailEvent = new();
+    public static UnityEvent<Fact, Scroll.ScrollApplicationInfo> PushoutFactFailEvent = new();
 
     public static UnityEvent gameSucceededEvent = new();
     public static UnityEvent gameNotSucceededEvent = new();
     public static UnityEvent NewAssignmentEvent = new();
 
     public static UnityEvent<GameObject, string> ScrollFactHintEvent = new();
-    public static UnityEvent<Fact> AnimateExistingFactEvent = new();
+    public static UnityEvent<Fact, FactObject.FactMaterials> AnimateExistingFactEvent = new();
     public static UnityEvent<Fact> AnimateNonExistingFactEvent = new();
     public static UnityEvent<List<string>> HintAvailableEvent = new();
+    
 
 
     //------------------------------------------------------------------------------------
diff --git a/Assets/Scripts/InteractionEngine/ShinyThings.cs b/Assets/Scripts/InteractionEngine/ShinyThings.cs
index 9c8c7038..6266f018 100644
--- a/Assets/Scripts/InteractionEngine/ShinyThings.cs
+++ b/Assets/Scripts/InteractionEngine/ShinyThings.cs
@@ -1,6 +1,5 @@
 using System.Collections;
 using System.Collections.Generic;
-using System.Linq;
 using UnityEngine;
 
 public class ShinyThings : MonoBehaviour
@@ -17,7 +16,7 @@ public class ShinyThings : MonoBehaviour
     private IEnumerator rain;
 
     public Light directionalLight;
-    private Color darkColor = new (0.2f, 0.2f, 0.2f);
+    private Color darkColor = new(0.2f, 0.2f, 0.2f);
     private Color light_colour;
     private GameObject active_rainwork;
 
@@ -29,8 +28,10 @@ public GameObject
     private void Awake()
     {
         CommunicationEvents.PushoutFactEvent.AddListener(HighlightFact);
+        CommunicationEvents.PushoutFactEvent.AddListener(HighlightWithFireworks);
+        CommunicationEvents.AnimateExistingFactEvent.AddListener(HighlightFact);
         CommunicationEvents.PushoutFactFailEvent.AddListener(LetItRain);
-        CommunicationEvents.AnimateExistingFactEvent.AddListener(HighlightWithFireworks);
+        //CommunicationEvents.AnimateExistingAsSolutionEvent.AddListener(HighlightWithFireworks);
 
         rain = rain_wait = 0f.LerpInTime(0, 0, -1); // yield return break
     }
@@ -83,7 +84,13 @@ void ApplyMaterial(FactObject root, Material new_mat) =>
     }
 
     public static void HighlightFact(Fact startFact, FactObject.FactMaterials tmp_mat)
-    {
+        {
+        //this happens, but it should not! TODO: Fix Fact Hint creation
+        if (startFact == null)
+        {
+            Debug.Log("FEHLER! fact = null");
+            return;
+        }
         if (startFact.Representation == null)
             return;
         FactObject selected_fact_obj = startFact.Representation.GetComponentInChildren<FactObject>();
@@ -97,7 +104,8 @@ public static void HighlightFact(Fact startFact, FactObject.FactMaterials tmp_ma
             );
     }
 
-    public void HighlightWithFireworks(Fact fact)
+    //Highlight winning fact with fireworks. material is not used;
+    public void HighlightWithFireworks(Fact fact, FactObject.FactMaterials material) 
     {
         while (rain_wait.MoveNext()) ; //stop rain
 
@@ -107,7 +115,7 @@ public void HighlightWithFireworks(Fact fact)
         IEnumerator BlossomAndDie()
         {
             GameObject firework = GameObject.Instantiate
-                ( Fireworks_Animation
+                (Fireworks_Animation
                 , fact.Representation.transform
                 );
 
@@ -127,11 +135,13 @@ IEnumerator BlossomAndDie()
         }
     }
 
-    public void LetItRain(Fact startFact)
+    public void LetItRain(Fact startFact, Scroll.ScrollApplicationInfo info)
     {
+        //-----------------
         bool restart = !rain_wait.MoveNext();
 
-        if (restart) {
+        if (restart)
+        {
             StopCoroutine(rain);
             StartCoroutine(rain = BlossomAndDie());
         }
diff --git a/Assets/Scripts/InventoryStuff/DisplayFacts.cs b/Assets/Scripts/InventoryStuff/DisplayFacts.cs
index b077f746..f8fbf04f 100644
--- a/Assets/Scripts/InventoryStuff/DisplayFacts.cs
+++ b/Assets/Scripts/InventoryStuff/DisplayFacts.cs
@@ -85,7 +85,7 @@ void Start()
 
         AddFactEvent.AddListener(AddFact);
         RemoveFactEvent.AddListener(RemoveFact);
-        AnimateExistingFactEvent.AddListener(AnimateFact);
+        //AnimateExistingFactEvent.AddListener(AnimateFact);
     }
 
     public void AddFact(Fact fact) {
diff --git a/Assets/Scripts/Loading/Stage.cs b/Assets/Scripts/Loading/Stage.cs
index 9d2ebd23..76713274 100644
--- a/Assets/Scripts/Loading/Stage.cs
+++ b/Assets/Scripts/Loading/Stage.cs
@@ -438,7 +438,7 @@ public bool CheckSolved()
         {
             foreach (var hitlist in hits)
                 foreach (var hit in hitlist)
-                    AnimateExistingFactEvent.Invoke(factState[hit]);
+                    AnimateExistingFactEvent.Invoke(factState[hit], FactObject.FactMaterials.Solution);
 
             player_record.solved = true;
             push_record(time_s);
diff --git a/Assets/Scripts/StageStatic.cs b/Assets/Scripts/StageStatic.cs
index c1427d5f..f0bdcbad 100644
--- a/Assets/Scripts/StageStatic.cs
+++ b/Assets/Scripts/StageStatic.cs
@@ -194,17 +194,19 @@ public StageErrorStruct(bool category, bool id, bool name, bool description, boo
     /// <param name="gameObject"> which children will be checked</param>
     public static void SetMode(Mode mode, GameObject gameObject = null)
     {
-        gameObject ??= new GameObject();
+        //gameObject ??= new GameObject();
 
         // handle StageStatic.mode
-        switch (StageStatic.mode = mode)
-        {
-            case Mode.Play:
-                gameObject.SetActiveByTagRecursive("CreatorMode", false);
-                break;
-            case Mode.Create:
-                gameObject.SetActiveByTagRecursive("CreatorMode", true);
-                break;
+        if(gameObject != null) {
+            switch (StageStatic.mode = mode)
+            {
+                case Mode.Play:
+                    gameObject.SetActiveByTagRecursive("CreatorMode", false);
+                    break;
+                case Mode.Create:
+                    gameObject.SetActiveByTagRecursive("CreatorMode", true);
+                    break;
+            }
         }
 
         // handle stage mode
-- 
GitLab