2021-05-03 01:29:02 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
using UnityExplorer.UI.CacheObject.Views;
|
|
|
|
|
using UnityExplorer.UI.IValues;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
using UnityExplorer.UI.Utility;
|
|
|
|
|
|
2021-05-05 21:27:09 +10:00
|
|
|
|
namespace UnityExplorer.UI.CacheObject
|
2021-05-03 01:29:02 +10:00
|
|
|
|
{
|
|
|
|
|
public class CacheKeyValuePair : CacheObjectBase
|
|
|
|
|
{
|
|
|
|
|
//public InteractiveList CurrentList { get; set; }
|
|
|
|
|
|
|
|
|
|
public int DictIndex;
|
|
|
|
|
public object DictKey;
|
2021-05-07 06:27:23 +10:00
|
|
|
|
public object DisplayedKey;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
|
|
|
|
public bool KeyInputWanted;
|
|
|
|
|
public bool InspectWanted;
|
|
|
|
|
public string KeyLabelText;
|
|
|
|
|
public string KeyInputText;
|
|
|
|
|
public string KeyInputTypeText;
|
|
|
|
|
|
|
|
|
|
public float DesiredKeyWidth;
|
|
|
|
|
public float DesiredValueWidth;
|
|
|
|
|
|
|
|
|
|
public override bool ShouldAutoEvaluate => true;
|
|
|
|
|
public override bool HasArguments => false;
|
2021-05-06 20:28:04 +10:00
|
|
|
|
public override bool CanWrite => Owner.CanWrite;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
|
|
|
|
public void SetDictOwner(InteractiveDictionary dict, int index)
|
|
|
|
|
{
|
|
|
|
|
this.Owner = dict;
|
|
|
|
|
this.DictIndex = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetKey(object key)
|
|
|
|
|
{
|
|
|
|
|
this.DictKey = key;
|
2021-05-07 06:27:23 +10:00
|
|
|
|
this.DisplayedKey = key.TryCast();
|
|
|
|
|
|
|
|
|
|
var type = DisplayedKey.GetType();
|
|
|
|
|
if (type == typeof(string) || (type.IsPrimitive && !(type == typeof(bool))))
|
2021-05-03 01:29:02 +10:00
|
|
|
|
{
|
|
|
|
|
KeyInputWanted = true;
|
2021-05-07 06:27:23 +10:00
|
|
|
|
KeyInputText = DisplayedKey.ToString();
|
2021-05-06 04:02:42 +10:00
|
|
|
|
KeyInputTypeText = SignatureHighlighter.Parse(type, false);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
KeyInputWanted = false;
|
|
|
|
|
InspectWanted = type != typeof(bool) && !type.IsEnum;
|
2021-05-07 06:27:23 +10:00
|
|
|
|
KeyLabelText = ToStringUtility.ToStringWithType(DisplayedKey, type, true);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 21:27:09 +10:00
|
|
|
|
public override void SetDataToCell(CacheObjectCell cell)
|
2021-05-03 01:29:02 +10:00
|
|
|
|
{
|
2021-05-05 21:27:09 +10:00
|
|
|
|
base.SetDataToCell(cell);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
|
|
|
|
var kvpCell = cell as CacheKeyValuePairCell;
|
|
|
|
|
|
|
|
|
|
kvpCell.NameLabel.text = $"{DictIndex}:";
|
|
|
|
|
kvpCell.Image.color = DictIndex % 2 == 0 ? CacheListEntryCell.EvenColor : CacheListEntryCell.OddColor;
|
|
|
|
|
|
|
|
|
|
if (KeyInputWanted)
|
|
|
|
|
{
|
|
|
|
|
kvpCell.KeyInputField.gameObject.SetActive(true);
|
|
|
|
|
kvpCell.KeyInputTypeLabel.gameObject.SetActive(true);
|
|
|
|
|
kvpCell.KeyLabel.gameObject.SetActive(false);
|
|
|
|
|
kvpCell.KeyInspectButton.Button.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
kvpCell.KeyInputField.text = KeyInputText;
|
|
|
|
|
kvpCell.KeyInputTypeLabel.text = KeyInputTypeText;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
kvpCell.KeyInputField.gameObject.SetActive(false);
|
|
|
|
|
kvpCell.KeyInputTypeLabel.gameObject.SetActive(false);
|
|
|
|
|
kvpCell.KeyLabel.gameObject.SetActive(true);
|
|
|
|
|
kvpCell.KeyInspectButton.Button.gameObject.SetActive(InspectWanted);
|
|
|
|
|
|
|
|
|
|
kvpCell.KeyLabel.text = KeyLabelText;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-06 06:36:39 +10:00
|
|
|
|
public override void TrySetUserValue(object value)
|
2021-05-03 01:29:02 +10:00
|
|
|
|
{
|
2021-05-06 20:28:04 +10:00
|
|
|
|
(Owner as InteractiveDictionary).TrySetValueToKey(DictKey, value, DictIndex);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override bool SetCellEvaluateState(CacheObjectCell cell)
|
|
|
|
|
{
|
|
|
|
|
// not needed
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|