Newer
Older
Björn Eßwein
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using REST_JSON_API;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using static CommunicationEvents;
public class ScrollDetails : ScrollView
{
public static ScrollDetails Instance
{
get => _Instance;
set
{
if (_Instance != value)
Destroy(_Instance);
_Instance = value;
}
}
private static ScrollDetails _Instance;
public WorldCursor cursor;
public GameObject parameterDisplayPrefab;
public GameObject mmtAnswerPopUp;
private PopupBehavior Popup;
public static List<RenderedScrollFact> ParameterDisplays { get; private set; }
void Awake()
{
Instance = this;
if (cursor == null)
cursor = FindObjectOfType<WorldCursor>();
Popup = mmtAnswerPopUp.GetComponent<PopupBehavior>();
Popup.gameObject.SetActive(true); // force Awake
}
private void OnEnable()
{
ActiveScroll.OnScrollChanged.AddListener(ShowScroll);
ActiveScroll.OnFactAssignmentUpdated.AddListener(OnFactAssignmentUpdated);
ActiveScroll.OnScrollDynamicInfoUpdated.AddListener(UpdateScrollDescription);
}
private void OnDisable()
{
ActiveScroll.OnScrollChanged.RemoveListener(ShowScroll);
ActiveScroll.OnFactAssignmentUpdated.RemoveListener(OnFactAssignmentUpdated);
ActiveScroll.OnScrollDynamicInfoUpdated.RemoveListener(UpdateScrollDescription);
}
private void OnDestroy()
{
_Instance = null;
}
/// <summary>
/// Update the scroll details screen to display the currently active scroll
/// </summary>
/// <param name="activeScroll"></param>
private void ShowScroll(ActiveScroll activeScroll)
{
Transform originalScroll = gameObject.transform.GetChild(1);
Transform originalScrollView = originalScroll.GetChild(1);
Transform originalViewport = originalScrollView.GetChild(0);
//Clear all current ScrollFacts
originalViewport.GetChild(0).gameObject.DestroyAllChildren();
Scroll scroll = activeScroll.Scroll;
originalScroll.GetChild(0).GetComponent<TextMeshProUGUI>().text = scroll.description;
//ParameterDisplays.ForEach(gameObj => Destroy(gameObj));
ParameterDisplays = new();
// generate parameter display slots
foreach (var slot in activeScroll.Assignments)
{
GameObject originalObj =
Instantiate(parameterDisplayPrefab, originalViewport.GetChild(0));
RenderedScrollFact originalRSF =
originalObj.GetComponentInChildren<RenderedScrollFact>();
ParameterDisplays.Add(originalRSF);
originalRSF.Populate(scroll, slot.Key);
originalRSF.transform.parent.gameObject.SetActive(slot.Value.IsVisible);
}
}
private void UpdateScrollDescription(Scroll rendered)
{
if (ActiveScroll.Instance.DynamicScrollDescriptionsActive)
{ // Update scroll-description
Transform scroll = gameObject.transform.GetChild(1).transform;
scroll.GetChild(0).GetComponent<TextMeshProUGUI>().text = rendered.description;
}
}
private void OnFactAssignmentUpdated(string slotUri, ActiveScroll.SlotAssignment slotAssignment)
{
RenderedScrollFact changed = ParameterDisplays.Find(RSF => RSF.ScrollFactURI == slotUri);
if (changed != null)
{
changed.Fact = slotAssignment.fact;
}
}
}