2021-05-03 01:29:02 +10:00
|
|
|
|
using System;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.CacheObject.IValues;
|
|
|
|
|
using UnityExplorer.CacheObject.Views;
|
2021-12-02 18:35:46 +11:00
|
|
|
|
using UniverseLib;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.Utility;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
2021-06-30 07:49:58 +10:00
|
|
|
|
namespace UnityExplorer.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();
|
|
|
|
|
|
2022-04-12 05:20:35 +10:00
|
|
|
|
Type type = DisplayedKey.GetType();
|
2021-05-09 02:22:03 +10:00
|
|
|
|
if (ParseUtility.CanParse(type))
|
2021-05-03 01:29:02 +10:00
|
|
|
|
{
|
|
|
|
|
KeyInputWanted = true;
|
2021-05-09 02:22:03 +10:00
|
|
|
|
KeyInputText = ParseUtility.ToStringForInput(DisplayedKey, type);
|
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
|
|
|
|
|
2022-04-12 05:20:35 +10:00
|
|
|
|
CacheKeyValuePairCell kvpCell = cell as CacheKeyValuePairCell;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
|
|
|
|
kvpCell.NameLabel.text = $"{DictIndex}:";
|
2021-08-23 18:35:08 +10:00
|
|
|
|
kvpCell.HiddenNameLabel.Text = "";
|
2021-05-03 01:29:02 +10:00
|
|
|
|
kvpCell.Image.color = DictIndex % 2 == 0 ? CacheListEntryCell.EvenColor : CacheListEntryCell.OddColor;
|
|
|
|
|
|
|
|
|
|
if (KeyInputWanted)
|
|
|
|
|
{
|
2021-05-07 17:06:56 +10:00
|
|
|
|
kvpCell.KeyInputField.UIRoot.SetActive(true);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
kvpCell.KeyInputTypeLabel.gameObject.SetActive(true);
|
|
|
|
|
kvpCell.KeyLabel.gameObject.SetActive(false);
|
2021-05-11 19:18:27 +10:00
|
|
|
|
kvpCell.KeyInspectButton.Component.gameObject.SetActive(false);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
2021-05-07 17:06:56 +10:00
|
|
|
|
kvpCell.KeyInputField.Text = KeyInputText;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
kvpCell.KeyInputTypeLabel.text = KeyInputTypeText;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-05-07 17:06:56 +10:00
|
|
|
|
kvpCell.KeyInputField.UIRoot.SetActive(false);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
kvpCell.KeyInputTypeLabel.gameObject.SetActive(false);
|
|
|
|
|
kvpCell.KeyLabel.gameObject.SetActive(true);
|
2021-05-11 19:18:27 +10:00
|
|
|
|
kvpCell.KeyInspectButton.Component.gameObject.SetActive(InspectWanted);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-01-18 20:19:20 +11:00
|
|
|
|
protected override bool TryAutoEvaluateIfUnitialized(CacheObjectCell cell) => true;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
}
|
|
|
|
|
}
|