You need to sign in or sign up before continuing.
Newer
Older
using REST_JSON_API;
using TMPro;
using static CommunicationEvents;
[RequireComponent(typeof(TMP_InputField))]
public class RenderedScrollFact : FactObjectUI, IDropHandler
=> Scroll.requiredFacts.FindIndex(f => f.@ref.uri == ScrollFactURI);
{
get => _ScrollFactURI;
set
{
_ScrollFactURI = value;
SetLabel(null);
}
}
private string _ScrollFactURI;
private TMP_InputField _InputField;
public string RequiredType
=> Scroll.requiredFacts[ID].getType();
protected override void _Awake()
_InputField = gameObject.GetComponent<TMP_InputField>();
_InputField.textComponent.gameObject.SetActive(true);
}
protected override void FactUpdated()
{
_URI ??= ScrollFactURI;
if (VerboseURI)
Debug.Log(nameof(RenderedScrollFact) + " recieved Fact: " + URI);
NewAssignmentEvent.Invoke();
ResetPayload();
private void ResetPayload()
{
Destroy(_Payload);
_InputField.enabled = _InputField.textComponent.enabled =
!IsSet
&& (RequiredType == MMTConstants.RealLit
|| string.IsNullOrEmpty(RequiredType));
_InputField.SetTextWithoutNotify("R");
if (DisplayFacts.displayedFacts.TryGetValue(URI, out GameObject fact_display))
{
_Payload = // has to be: ..., Vector3.zero, Quaternion.identity => SetParent
Instantiate(fact_display, Vector3.zero, Quaternion.identity);
_Payload.transform.SetParent(gameObject.transform, worldPositionStays: false);
_Payload.GetComponent<CanvasGroup>().blocksRaycasts = true; // Reverse drag effect, if any
}
}
protected override void _DeleteFactEvent(Fact fact)
=> Fact = null; // calls NewAssignmentEvent.Invoke();
{
HintAvailableEvent.AddListener(OnHintAvailable);
{
HintAvailableEvent.RemoveListener(OnHintAvailable);
}
public void Populate(Scroll scroll, string scroll_fact_uri)
_Scroll = scroll;
_ScrollFactURI = scroll_fact_uri;
ResetPayload();
}
private void SetLabel(string label)
{
LabelMesh.text = label ?? Scroll?.requiredFacts[ID].label ?? "Err";
}
public void OnClickHintButton()
{
public void OnHintAvailable(List<string> uris)
{
HintButton.SetActive(uris.Contains(ScrollFactURI));
public void OnTextChange()
{
if (!float.TryParse(_InputField.text, out float input))
return;
Fact = FactAdder.AddFactIfNotFound(new RealLitFact(input), out _, false, null, "Manual User Input");
}
=> _Payload == null ? null : _Payload.GetComponent<FactObjectUI>();
private GameObject _Payload;
if (eventData.pointerDrag.TryGetComponent(out FactObjectUI factObject))
SetByFactObject(factObject);
}
public void SetByFactObject(FactObjectUI fOUI)
{
Fact = fOUI.Fact;
Debug.Log(Fact.GetLabel(StageStatic.stage.factState) + " was dropped on "
+ gameObject.name + " " + (ID + 1) + "/" +
ScrollDetails.ParameterDisplays.Count + " label: " + ScrollFactLabel);
}
#endregion DropHandling