Skip to content
Snippets Groups Projects
Commit e89e3bab authored by Richard Marcus's avatar Richard Marcus
Browse files

dynamic scrolls

parent 3697e791
No related branches found
No related tags found
No related merge requests found
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &6955576155660626993
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1288409225757860898}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f459496b7a023cb4c849ddddad2c3fc0, type: 3}
m_Name:
m_EditorClassIdentifier:
ID: 0
LabelMesh: {fileID: 7220552148984218067}
--- !u!1 &2471407562246470327
GameObject:
m_ObjectHideFlags: 0
......@@ -60,6 +74,7 @@ MonoBehaviour:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
......@@ -211,12 +226,13 @@ MonoBehaviour:
m_GameObject: {fileID: 8358525157842135574}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.9056604, g: 0.8992144, b: 0.004271993, a: 0.21568628}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
......@@ -229,6 +245,7 @@ MonoBehaviour:
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1001 &7153233524418283664
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -236,11 +253,6 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 8358525157842135573}
m_Modifications:
- target: {fileID: 8260792079148133554, guid: 1a3d2b3a09e7aa64ab57b0867d3b2307,
type: 3}
propertyPath: m_Name
value: ScollFactContainer
objectReference: {fileID: 0}
- target: {fileID: 7249550241351237421, guid: 1a3d2b3a09e7aa64ab57b0867d3b2307,
type: 3}
propertyPath: m_LocalPosition.x
......@@ -346,8 +358,19 @@ PrefabInstance:
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8260792079148133554, guid: 1a3d2b3a09e7aa64ab57b0867d3b2307,
type: 3}
propertyPath: m_Name
value: ScollFactContainer
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1a3d2b3a09e7aa64ab57b0867d3b2307, type: 3}
--- !u!1 &1288409225757860898 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8260792079148133554, guid: 1a3d2b3a09e7aa64ab57b0867d3b2307,
type: 3}
m_PrefabInstance: {fileID: 7153233524418283664}
m_PrefabAsset: {fileID: 0}
--- !u!224 &567154989861468093 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 7249550241351237421, guid: 1a3d2b3a09e7aa64ab57b0867d3b2307,
......
......@@ -41107,7 +41107,7 @@ PrefabInstance:
- target: {fileID: 2089306640899292912, guid: 4d99275c6663c25469ad3b65efcd4f5f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -0.000012699486
value: -0.000005722046
objectReference: {fileID: 0}
- target: {fileID: 2524590709578595355, guid: 4d99275c6663c25469ad3b65efcd4f5f,
type: 3}
......@@ -6,7 +6,18 @@
public abstract class Fact
{
public int Id;
private int _id;
public string Label;
public int Id
{
get { return _id; }
set
{
// if (_id == value) return;
_id = value;
Label= ((Char)(64 + _id + 1)).ToString();
}
}
public GameObject Representation;
public string backendURI;
public string backendValueURI; // supposed to be null, for Facts without values eg. Points, OpenLines, OnLineFacts...
......@@ -84,7 +95,7 @@ public PointFact(int i, Vector3 P, Vector3 N)
MMTTerm df = new OMA(new OMS(MMTURIs.Tuple), arguments);
//TODO: rework fact list + labeling
MMTDeclaration mmtDecl = new MMTDeclaration(((Char)(64 + Id + 1)).ToString(), tp, df);
MMTDeclaration mmtDecl = new MMTDeclaration(this.Label, tp, df);
string body = ToJson(mmtDecl);
AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress+"/fact/add", body);
......@@ -155,10 +166,14 @@ public LineFact(int i, int pid1, int pid2)
)
}
);
//github + predikate => -ded -eq
MMTTerm df = null;
//see point label
MMTDeclaration mmtDecl = new MMTDeclaration(((Char)(64 + Id + 1)).ToString(), tp, df);
MMTDeclaration mmtDecl = new MMTDeclaration(this.Label, tp, df);
string body = ToJson(mmtDecl);
AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body);
this.backendURI = res.uri;
......
......@@ -8,7 +8,7 @@
public class DisplayScrolls : MonoBehaviour
{
public Scroll[] scrolls;
public List<Scroll> scrolls;
public GameObject[] ScrollButtons;
public GameObject ScrollPrefab;
public GameObject DetailScreen;
......@@ -20,7 +20,7 @@ public class DisplayScrolls : MonoBehaviour
public int X_Pacece_Between_Items;
public int y_Pacece_Between_Items;
public int number_of_Column;
// Update is called once per frame
void Update()
......@@ -31,13 +31,13 @@ void Update()
public Vector3 GetPosition(int i)
{
return new Vector3(x_Start+ (X_Pacece_Between_Items * (i % number_of_Column)), y_Start + (-y_Pacece_Between_Items * (i / number_of_Column)), 0f);
return new Vector3(x_Start + (X_Pacece_Between_Items * (i % number_of_Column)), y_Start + (-y_Pacece_Between_Items * (i / number_of_Column)), 0f);
}
[System.Serializable]
class ScrollArrayWrapper{
/* [System.Serializable]
class ScrollArrayWrapper {
public Scroll[] Scrolls;
};
};*/
// Start is called before the first frame update
void Start()
......@@ -45,33 +45,62 @@ void Start()
var rect = GetComponent<RectTransform>();
x_Start = (int)(rect.rect.x + X_Pacece_Between_Items * .5f);
y_Start = (int)(-rect.rect.y - y_Pacece_Between_Items * .5f);//);
number_of_Column =Mathf.Max(1,(int)(rect.rect.width / ScrollPrefab.GetComponent<RectTransform>().rect.width) - 1);
number_of_Column = Mathf.Max(1, (int)(rect.rect.width / ScrollPrefab.GetComponent<RectTransform>().rect.width) - 1);
//get Scrolls from Backend;
//string path = "Mock-Scrolls.json";
//string jsonString = File.ReadAllText(path);
//buildScrollSelection(jsonString);
StartCoroutine(getScrollsfromServer());
}
IEnumerator getScrollsfromServer() {
UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAdress+"/scroll/list");
UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list");
request.method = UnityWebRequest.kHttpVerbGET;
yield return request.Send();
if (request.isNetworkError || request.isHttpError)
{
Debug.LogWarning(request.error);
string jsonString = File.ReadAllText(Application.dataPath + "/scrolls.json");
Debug.Log(jsonString);
BuildScrolls(jsonString);
}
else
{
CommunicationEvents.ServerRunning = true;
string jsonString = request.downloadHandler.text;
Debug.Log(jsonString);
//scroll display not yet implemented;
//scroll display not yet implemented;
//buildScrollSelection(jsonString);
BuildScrolls(jsonString);
}
}
//new Protocol
void BuildScrolls(string jsonString)
{
var scrolls = Scroll.FromJSON(jsonString);
this.scrolls = scrolls;
ScrollButtons = new GameObject[this.scrolls.Count];
//Build Selection-GUI of Scrolls
for (int i = 0; i < this.scrolls.Count; i++)
{
var obj = Instantiate(ScrollPrefab, Vector3.zero, Quaternion.identity, transform);
obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
obj.GetComponent<ScrollClickedScript>().scroll = this.scrolls[i];
obj.GetComponent<ScrollClickedScript>().DetailScreen = this.DetailScreen;
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = this.scrolls[i].label;
ScrollButtons[i] = obj;
}
this.DetailScreen.GetComponent<ScrollDetails>().setScroll(this.scrolls[0]);
}
//old Protocol
/*
void buildScrollSelection(string jsonString) {
jsonString = jsonString.Replace(System.Environment.NewLine, "");
jsonString = jsonString.Replace("\t", "");
......@@ -94,5 +123,5 @@ void buildScrollSelection(string jsonString) {
this.DetailScreen.GetComponent<ScrollDetails>().setScroll(this.scrolls[0]);
}
}*/
}
......@@ -8,7 +8,47 @@ public class DropHandling : MonoBehaviour, IDropHandler
GameObject current;
public Fact currentFact;
public void OnDrop(PointerEventData eventData){
Debug.Log(eventData.pointerDrag + "was dropped on "+ gameObject.name);
var scrollFact = gameObject.GetComponent<ScrollFact>();
Debug.Log(eventData.pointerDrag.GetComponent<FactWrapper>().fact.Label+ " was dropped on "
+ gameObject.name+ " " +scrollFact.ID + "/" +
ScrollDetails.ParameterDisplays.Count+" label: "+scrollFact.Label);
//TODO modularize this with functions when feature is approved
//changes assigned label, used for later processing, if this should not be changed, use another variable for rhs data
if (Scroll.FactOccurences[scrollFact.ID] != null)
{
scrollFact.Label = eventData.pointerDrag.GetComponent<FactWrapper>().fact.Label;
Debug.Log(Scroll.FactOccurences[scrollFact.ID].Count);
foreach (var id in Scroll.FactOccurences[scrollFact.ID])
{
//change occurences in scroll description
if (id.Key == -1)
{
string label = ScrollDetails.ScrollDescription;
label = label.Remove(id.Value, 1);
label = label.Insert(id.Value, scrollFact.Label);
ScrollDetails.ScrollDescription = label;
}
// and also in facts
else
{
var affectedFact = ScrollDetails.ParameterDisplays[id.Key].GetComponentInChildren<ScrollFact>();
string label = affectedFact.Label;
label = label.Remove(id.Value, 1);
label = label.Insert(id.Value, scrollFact.Label);
affectedFact.Label = label;
}
}
}
Destroy(current);
current = Instantiate(eventData.pointerDrag,Vector3.zero, Quaternion.identity);
current.transform.SetParent(gameObject.transform, false);
......
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
using UnityEngine;
/*
[Serializable]
public class Declaration
{
......@@ -32,4 +35,120 @@ public string toJson() {
return JsonUtility.ToJson(this);
}
}
*/
public class Scroll : LightScroll
{
public string label;
public string description;
public List<ScrollFact> requiredFacts;
public static List<Scroll> FromJSON(string json)
{
List<Scroll> scrolls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scroll>>(json);
return scrolls;
}
public static string ToJSON(FilledScroll scroll)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(scroll);
return json;
}
// id of fact, positions in Description
public static List<KeyValuePair<int,int>>[] FactOccurences;
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;
}
public class FilledScroll
{
LightScroll scroll;
List<ScrollAssignment> assignments;
public FilledScroll(LightScroll scroll, List<ScrollAssignment> assignments)
{
this.scroll = scroll;
this.assignments = assignments;
}
}
public class ScrollFact
{
public string uri;
public string label;
public FactBody tp;
public JSONManager.MMTTerm df;
}
public class FactBody
{
public JSONManager.MMTTerm original;
public JSONManager.MMTTerm simplified;
}
}
public class LightScroll
{
public string problemTheory;
public string solutionTheory;
}
......@@ -17,7 +17,18 @@ public class ScrollDetails : MonoBehaviour
public int y_Start;
public int y_Paece_Between_Items;
public GameObject[] ParameterDisplays;
public static List<GameObject> ParameterDisplays;
static TextMeshProUGUI _scrollDescriptionField;
static string _scrollDescription;
public static string ScrollDescription
{
get { return _scrollDescription; }
set
{
_scrollDescription = value;
_scrollDescriptionField.text = value;
}
}
public string situationTheory = "http://BenniDoes.Stuff?SituationTheory";
......@@ -29,6 +40,9 @@ public Vector3 GetPosition(int i)
void Start()
{
if (cursor == null) cursor = GameObject.FindObjectOfType<WorldCursor>();
_scrollDescriptionField = this.gameObject.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>();
}
// Update is called once per frame
......@@ -42,28 +56,31 @@ public void setScroll(Scroll s)
Transform scrollView = gameObject.transform.GetChild(2);
Transform viewport = scrollView.GetChild(0);
this.scroll = s;
//wipe out old Displays
for (int i = 0; i < this.ParameterDisplays.Length; i++)
{
Destroy(ParameterDisplays[i]);
}
this.ParameterDisplays = new GameObject[s.declarations.Length];
for (int i = 0; i < s.declarations.Length; i++)
ParameterDisplays = new List<GameObject>();
Scroll.InitDynamicScroll(s.requiredFacts.Count);
for (int i = 0; i < s.requiredFacts.Count; i++)
{
var obj = Instantiate(parameterDisplayPrefab, Vector3.zero, Quaternion.identity, transform);
var scrollFact = obj.transform.GetChild(0).GetComponent<ScrollFact>();
scrollFact.ID = i;
//obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = s.declarations[i].description;
scrollFact.Label = Scroll.ParseString(i,s.requiredFacts[i].label,s.requiredFacts);
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;
this.ParameterDisplays[i] = obj;
ParameterDisplays.Add(obj);
}
gameObject.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = s.description;
//scroll description
ScrollDescription = Scroll.ParseString(-1, s.description, s.requiredFacts);
}
public void magicButton()
{
string view = sendView2();
string view = sendView();
if (view.Equals(FAIL))
{
Debug.Log("DAS HAT NICHT GEKLAPPT");
......@@ -82,7 +99,34 @@ class ViewResponse
public string view;
}
private string sendView()
{
List<Scroll.ScrollAssignment> assignments = new List<Scroll.ScrollAssignment>();
Scroll.FilledScroll scroll = new Scroll.FilledScroll(this.scroll, assignments);
string body = Scroll.ToJSON(scroll);
UnityWebRequest www = UnityWebRequest.Put(CommunicationEvents.ServerAdress+"/scroll/apply", body);
www.method = UnityWebRequest.kHttpVerbPOST;
www.SetRequestHeader("Content-Type", "application/json");
var async = www.Send();
while (!async.isDone) { }
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
return FAIL;
}
else
{
string answer = www.downloadHandler.text;
return JsonUtility.FromJson<ViewResponse>(answer).view;
}
}
/*
* private string sendView()
{
string jsonRequest = @"{";
jsonRequest = jsonRequest + @" ""from"":""" + this.scroll.problemTheory + @""", ";
......@@ -121,7 +165,6 @@ private string sendView()
return JsonUtility.FromJson<ViewResponse>(answer).view;
}
}
private string sendView2()
{
Dictionary<Declaration, Fact[]> possibilities = new Dictionary<Declaration, Fact[]>();
......@@ -206,7 +249,7 @@ private string testVariant(Dictionary<Declaration, Fact> selection)
string answer = www.downloadHandler.text;
return JsonUtility.FromJson<ViewResponse>(answer).view;
}
}
}*/
class PushoutReturn
......
......@@ -86,13 +86,8 @@ public OMF(float f)
}
}
/*
class DeclarationBody : MMTTerm
{
MMTTerm original;
MMTTerm simplified;
string kind = "O/S";
}*/
public class MMTDeclaration
......@@ -109,6 +104,7 @@ public MMTDeclaration(string label, MMTTerm tp, MMTTerm df)
}
}
public static MMTDeclaration FromJson(string json)
{
MMTDeclaration mmtDecl = JsonConvert.DeserializeObject<MMTDeclaration>(json);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment