From 72c6c77d1172c734a345fbe43a5aaf4c2bdea8b6 Mon Sep 17 00:00:00 2001
From: unknown <john.schihada@hotmail.com>
Date: Mon, 26 Oct 2020 19:02:10 +0100
Subject: [PATCH] Fixed Scroll-Selection-Bug

---
 Assets/Scripts/InventoryStuff/Scroll.cs       | 78 -------------------
 .../Scripts/InventoryStuff/ScrollDetails.cs   | 13 ++--
 2 files changed, 7 insertions(+), 84 deletions(-)

diff --git a/Assets/Scripts/InventoryStuff/Scroll.cs b/Assets/Scripts/InventoryStuff/Scroll.cs
index 8ccdd976..5be3eb98 100644
--- a/Assets/Scripts/InventoryStuff/Scroll.cs
+++ b/Assets/Scripts/InventoryStuff/Scroll.cs
@@ -7,38 +7,6 @@
 using JsonSubTypes;
 using Newtonsoft.Json;
 
-
-/*
-[Serializable]
-public class Declaration
-{
-    public string name;
-    public string isProof;
-    public string value;
-    public string identifier;
-    public string description;
-}
-
-
-[Serializable]
-public class Scroll
-{
-    public string problemTheory;
-    public string solutionTheory;
-    public string label;
-    public string description;
-    public Declaration[] declarations;
-    //public string output;
-
-    public static Scroll generateFromJson(string json) {
-       return JsonUtility.FromJson<Scroll>(json);
-    }
-
-    public string toJson() {
-        return JsonUtility.ToJson(this);
-    } 
-}
-*/
 public class Scroll : LightScroll
 {
     public string label;
@@ -65,52 +33,6 @@ public static void InitDynamicScroll(int n)
         FactOccurences = new List<KeyValuePair<int, int>>[n];
     }
 
-
-    //also collects occurences to be changed later
-    public static string ParseString(int stringId, string raw, List<ScrollFact> scrollFacts)
-    {
-       
-        int i = 0;
-        while(true)
-        {
-            char[] rawChars = raw.ToCharArray();
-            i = Array.FindIndex(rawChars,i, c => c == '$');
-            if (i == -1) break;
-           // Debug.Log(i);
-
-            //id of Fact, specified after the $
-            int toChange = (int) Char.GetNumericValue(raw[i + 1]);
-
-            //label of this Fact
-            string label = scrollFacts[toChange].label;
-
-            raw = raw.Remove(i,2);
-            raw = raw.Insert(i,label);
-
-            if(FactOccurences[toChange] == null)
-            {
-                FactOccurences[toChange] = new List<KeyValuePair<int, int>>();
-            }
-            //if (toChange >= 0) Debug.Log(stringId);
-            FactOccurences[toChange].Add(new KeyValuePair<int, int>(stringId,i));
-
-        
-        }
-
-        return raw;
-    }
-
-  
-
-
-
-/*
-    public class ScrollList
-    {
-        public List<Scroll> scrolls;
-       
-    }*/
-
     public class ScrollAssignment
     {
        public KeyValuePair<string, JSONManager.MMTTerm> assignment;
diff --git a/Assets/Scripts/InventoryStuff/ScrollDetails.cs b/Assets/Scripts/InventoryStuff/ScrollDetails.cs
index f0840680..cb40cbbf 100644
--- a/Assets/Scripts/InventoryStuff/ScrollDetails.cs
+++ b/Assets/Scripts/InventoryStuff/ScrollDetails.cs
@@ -56,7 +56,11 @@ public void setScroll(Scroll s)
         Transform scrollView = gameObject.transform.GetChild(2);
         Transform viewport = scrollView.GetChild(0);
         this.scroll = s;
-      
+
+        //Clear all current ScrollFacts
+        foreach (Transform child in viewport.GetChild(0).transform)
+            GameObject.Destroy(child.gameObject);
+
         ParameterDisplays = new List<GameObject>();
         Scroll.InitDynamicScroll(s.requiredFacts.Count);
         for (int i = 0; i < s.requiredFacts.Count; i++)
@@ -67,15 +71,12 @@ public void setScroll(Scroll s)
 
             scrollFact.ID = i;
             //obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
-            scrollFact.Label = Scroll.ParseString(i,s.requiredFacts[i].label,s.requiredFacts);
+            scrollFact.Label = s.requiredFacts[i].label;
             obj.transform.SetParent(viewport.GetChild(0));
-            //this is from benni, I dont know if the hack is the commented line below or the line above....
-            //TODO: Remvoe this reaaaaly bad hack
-            //obj.transform.localScale = Vector3.one;
             ParameterDisplays.Add(obj);
         }
         //scroll description
-        ScrollDescription = Scroll.ParseString(-1, s.description, s.requiredFacts);
+        ScrollDescription = s.description;
        
     }
 
-- 
GitLab