2020-11-16 00:50:06 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
using System.Reflection;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
using UnityEngine;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.Helpers;
|
|
|
|
|
using UnityExplorer.UI;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Inspectors.Reflection
|
|
|
|
|
{
|
|
|
|
|
public class InteractiveString : InteractiveValue
|
|
|
|
|
{
|
2020-11-16 01:32:58 +11:00
|
|
|
|
public InteractiveString(object value, Type valueType) : base(value, valueType) { }
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
2020-11-23 18:23:25 +11:00
|
|
|
|
public override bool HasSubContent => true;
|
|
|
|
|
public override bool SubContentWanted => true;
|
|
|
|
|
|
2020-11-16 00:50:06 +11:00
|
|
|
|
public override bool WantInspectBtn => false;
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
public override void OnValueUpdated()
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
base.OnValueUpdated();
|
|
|
|
|
}
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
public override void OnException(CacheMember member)
|
|
|
|
|
{
|
|
|
|
|
base.OnException(member);
|
|
|
|
|
|
2020-11-23 18:23:25 +11:00
|
|
|
|
if (m_subContentConstructed && m_hiddenObj.gameObject.activeSelf)
|
2020-11-16 21:21:04 +11:00
|
|
|
|
m_hiddenObj.gameObject.SetActive(false);
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
m_labelLayout.minWidth = 200;
|
|
|
|
|
m_labelLayout.flexibleWidth = 5000;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
public override void RefreshUIForValue()
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
GetDefaultLabel(false);
|
|
|
|
|
|
|
|
|
|
if (!Owner.HasEvaluated)
|
|
|
|
|
{
|
|
|
|
|
m_baseLabel.text = DefaultLabel;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_baseLabel.text = m_richValueType;
|
|
|
|
|
|
2020-11-23 18:23:25 +11:00
|
|
|
|
if (m_subContentConstructed)
|
|
|
|
|
{
|
|
|
|
|
if (!m_hiddenObj.gameObject.activeSelf)
|
|
|
|
|
m_hiddenObj.gameObject.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty((string)Value))
|
2020-11-16 21:21:04 +11:00
|
|
|
|
{
|
2020-11-23 18:23:25 +11:00
|
|
|
|
var toString = (string)Value;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
if (toString.Length > 15000)
|
|
|
|
|
toString = toString.Substring(0, 15000);
|
|
|
|
|
|
2020-11-23 18:23:25 +11:00
|
|
|
|
m_readonlyInput.text = toString;
|
|
|
|
|
|
|
|
|
|
if (m_subContentConstructed)
|
|
|
|
|
{
|
|
|
|
|
m_valueInput.text = toString;
|
|
|
|
|
m_placeholderText.text = toString;
|
|
|
|
|
}
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-11-23 18:23:25 +11:00
|
|
|
|
string s = Value == null
|
|
|
|
|
? "null"
|
|
|
|
|
: "empty";
|
|
|
|
|
|
|
|
|
|
m_readonlyInput.text = $"<i><color=grey>{s}</color></i>";
|
|
|
|
|
|
|
|
|
|
if (m_subContentConstructed)
|
|
|
|
|
{
|
|
|
|
|
m_valueInput.text = "";
|
|
|
|
|
m_placeholderText.text = s;
|
|
|
|
|
}
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_labelLayout.minWidth = 50;
|
|
|
|
|
m_labelLayout.flexibleWidth = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void OnApplyClicked()
|
|
|
|
|
{
|
|
|
|
|
Value = m_valueInput.text;
|
|
|
|
|
Owner.SetValue();
|
2020-11-23 18:23:25 +11:00
|
|
|
|
RefreshUIForValue();
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 18:23:25 +11:00
|
|
|
|
// for the default label
|
2020-11-16 21:21:04 +11:00
|
|
|
|
internal LayoutElement m_labelLayout;
|
2020-11-23 18:23:25 +11:00
|
|
|
|
|
|
|
|
|
//internal InputField m_readonlyInput;
|
|
|
|
|
internal Text m_readonlyInput;
|
|
|
|
|
|
|
|
|
|
// for input
|
|
|
|
|
internal InputField m_valueInput;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
internal GameObject m_hiddenObj;
|
|
|
|
|
internal Text m_placeholderText;
|
|
|
|
|
|
|
|
|
|
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
|
|
|
|
{
|
|
|
|
|
base.ConstructUI(parent, subGroup);
|
|
|
|
|
|
|
|
|
|
GetDefaultLabel(false);
|
|
|
|
|
m_richValueType = UISyntaxHighlight.ParseFullSyntax(FallbackType, false);
|
|
|
|
|
|
|
|
|
|
m_labelLayout = m_baseLabel.gameObject.GetComponent<LayoutElement>();
|
|
|
|
|
|
2020-11-23 18:23:25 +11:00
|
|
|
|
var readonlyInputObj = UIFactory.CreateLabel(m_valueContent, TextAnchor.MiddleLeft);
|
|
|
|
|
m_readonlyInput = readonlyInputObj.GetComponent<Text>();
|
|
|
|
|
m_readonlyInput.horizontalOverflow = HorizontalWrapMode.Overflow;
|
|
|
|
|
|
|
|
|
|
var testFitter = readonlyInputObj.AddComponent<ContentSizeFitter>();
|
|
|
|
|
testFitter.verticalFit = ContentSizeFitter.FitMode.MinSize;
|
|
|
|
|
|
|
|
|
|
var labelLayout = readonlyInputObj.AddComponent<LayoutElement>();
|
|
|
|
|
labelLayout.minHeight = 25;
|
|
|
|
|
labelLayout.preferredHeight = 25;
|
|
|
|
|
labelLayout.flexibleHeight = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConstructSubcontent()
|
|
|
|
|
{
|
|
|
|
|
base.ConstructSubcontent();
|
|
|
|
|
|
|
|
|
|
var groupObj = UIFactory.CreateVerticalGroup(m_subContentParent, new Color(1, 1, 1, 0));
|
|
|
|
|
var group = groupObj.GetComponent<VerticalLayoutGroup>();
|
|
|
|
|
group.spacing = 4;
|
|
|
|
|
group.padding.top = 3;
|
|
|
|
|
group.padding.left = 3;
|
|
|
|
|
group.padding.right = 3;
|
|
|
|
|
group.padding.bottom = 3;
|
|
|
|
|
|
|
|
|
|
m_hiddenObj = UIFactory.CreateLabel(groupObj, TextAnchor.MiddleLeft);
|
2020-11-16 21:21:04 +11:00
|
|
|
|
m_hiddenObj.SetActive(false);
|
|
|
|
|
var hiddenText = m_hiddenObj.GetComponent<Text>();
|
|
|
|
|
hiddenText.color = Color.clear;
|
|
|
|
|
hiddenText.fontSize = 14;
|
|
|
|
|
hiddenText.raycastTarget = false;
|
2020-11-23 18:23:25 +11:00
|
|
|
|
hiddenText.supportRichText = false;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
var hiddenFitter = m_hiddenObj.AddComponent<ContentSizeFitter>();
|
|
|
|
|
hiddenFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
|
|
|
|
var hiddenLayout = m_hiddenObj.AddComponent<LayoutElement>();
|
|
|
|
|
hiddenLayout.minHeight = 25;
|
|
|
|
|
hiddenLayout.flexibleHeight = 500;
|
|
|
|
|
hiddenLayout.minWidth = 250;
|
|
|
|
|
hiddenLayout.flexibleWidth = 9000;
|
|
|
|
|
var hiddenGroup = m_hiddenObj.AddComponent<HorizontalLayoutGroup>();
|
|
|
|
|
hiddenGroup.childForceExpandWidth = true;
|
|
|
|
|
hiddenGroup.childControlWidth = true;
|
|
|
|
|
hiddenGroup.childForceExpandHeight = true;
|
|
|
|
|
hiddenGroup.childControlHeight = true;
|
|
|
|
|
|
|
|
|
|
var inputObj = UIFactory.CreateInputField(m_hiddenObj, 14, 3);
|
|
|
|
|
var inputLayout = inputObj.AddComponent<LayoutElement>();
|
|
|
|
|
inputLayout.minWidth = 120;
|
|
|
|
|
inputLayout.minHeight = 25;
|
|
|
|
|
inputLayout.flexibleWidth = 5000;
|
|
|
|
|
inputLayout.flexibleHeight = 5000;
|
|
|
|
|
|
|
|
|
|
m_valueInput = inputObj.GetComponent<InputField>();
|
|
|
|
|
m_valueInput.lineType = InputField.LineType.MultiLineNewline;
|
|
|
|
|
|
|
|
|
|
m_placeholderText = m_valueInput.placeholder.GetComponent<Text>();
|
|
|
|
|
|
2020-11-23 18:23:25 +11:00
|
|
|
|
m_placeholderText.supportRichText = false;
|
|
|
|
|
m_valueInput.textComponent.supportRichText = false;
|
|
|
|
|
|
|
|
|
|
m_valueInput.onValueChanged.AddListener((string val) =>
|
2020-11-16 21:21:04 +11:00
|
|
|
|
{
|
2020-11-23 18:23:25 +11:00
|
|
|
|
hiddenText.text = val ?? "";
|
2020-11-16 21:21:04 +11:00
|
|
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(Owner.m_mainRect);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (Owner.CanWrite)
|
|
|
|
|
{
|
2020-11-23 18:23:25 +11:00
|
|
|
|
var applyBtnObj = UIFactory.CreateButton(groupObj, new Color(0.2f, 0.2f, 0.2f));
|
2020-11-16 21:21:04 +11:00
|
|
|
|
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
|
|
|
|
applyLayout.minWidth = 50;
|
|
|
|
|
applyLayout.minHeight = 25;
|
|
|
|
|
applyLayout.flexibleWidth = 0;
|
2020-11-23 18:23:25 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
var applyBtn = applyBtnObj.GetComponent<Button>();
|
|
|
|
|
applyBtn.onClick.AddListener(OnApplyClicked);
|
|
|
|
|
|
|
|
|
|
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
|
|
|
|
applyText.text = "Apply";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_valueInput.readOnly = true;
|
|
|
|
|
}
|
2020-11-23 18:23:25 +11:00
|
|
|
|
|
|
|
|
|
RefreshUIForValue();
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|