Setting values from IList / IDictionary to source

This commit is contained in:
Sinai
2021-05-06 20:28:04 +10:00
parent 9e8a18a5e1
commit 1ee10c2507
9 changed files with 175 additions and 106 deletions

View File

@ -26,7 +26,7 @@ namespace UnityExplorer.UI.CacheObject
public override bool ShouldAutoEvaluate => true;
public override bool HasArguments => false;
public override bool CanWrite => false; // TODO Parent.CanWrite;
public override bool CanWrite => Owner.CanWrite;
public void SetDictOwner(InteractiveDictionary dict, int index)
{
@ -84,7 +84,7 @@ namespace UnityExplorer.UI.CacheObject
public override void TrySetUserValue(object value)
{
throw new NotImplementedException("TODO");
(Owner as InteractiveDictionary).TrySetValueToKey(DictKey, value, DictIndex);
}

View File

@ -33,7 +33,7 @@ namespace UnityExplorer.UI.CacheObject
public override void TrySetUserValue(object value)
{
throw new NotImplementedException("TODO");
(Owner as InteractiveList).TrySetValueToIndex(value, this.ListIndex);
}

View File

@ -100,6 +100,7 @@ namespace UnityExplorer.UI.CacheObject
ReflectionProvider.Instance.BoxStringToType(ref value, FallbackType);
else
value = value.TryCast(FallbackType);
TrySetUserValue(value);
}
@ -283,62 +284,6 @@ namespace UnityExplorer.UI.CacheObject
cell.SubContentButton.Button.gameObject.SetActive(args.subContentButtonActive);
}
// IValues
internal static GameObject InactiveIValueHolder
{
get
{
if (!inactiveIValueHolder)
{
inactiveIValueHolder = new GameObject("Temp_IValue_Holder");
GameObject.DontDestroyOnLoad(inactiveIValueHolder);
inactiveIValueHolder.transform.parent = UIManager.PoolHolder.transform;
inactiveIValueHolder.SetActive(false);
}
return inactiveIValueHolder;
}
}
private static GameObject inactiveIValueHolder;
public virtual void OnCellSubContentToggle()
{
if (this.IValue == null)
{
var ivalueType = InteractiveValue.GetIValueTypeForState(State);
IValue = (InteractiveValue)Pool.Borrow(ivalueType);
CurrentIValueType = ivalueType;
IValue.OnBorrowed(this);
IValue.SetValue(this.Value);
IValue.UIRoot.transform.SetParent(CellView.SubContentHolder.transform, false);
CellView.SubContentHolder.SetActive(true);
SubContentShowWanted = true;
// update our cell after creating the ivalue (the value may have updated, make sure its consistent)
this.ProcessOnEvaluate();
this.SetDataToCell(this.CellView);
}
else
{
SubContentShowWanted = !SubContentShowWanted;
CellView.SubContentHolder.SetActive(SubContentShowWanted);
}
CellView.RefreshSubcontentButton();
}
public virtual void ReleaseIValue()
{
if (IValue == null)
return;
IValue.ReleaseFromOwner();
Pool.Return(CurrentIValueType, IValue);
IValue = null;
}
// CacheObjectCell Apply
public virtual void OnCellApplyClicked()
@ -368,6 +313,76 @@ namespace UnityExplorer.UI.CacheObject
SetDataToCell(this.CellView);
}
// IValues
public virtual void OnCellSubContentToggle()
{
if (this.IValue == null)
{
var ivalueType = InteractiveValue.GetIValueTypeForState(State);
IValue = (InteractiveValue)Pool.Borrow(ivalueType);
CurrentIValueType = ivalueType;
IValue.OnBorrowed(this);
IValue.SetValue(this.Value);
IValue.UIRoot.transform.SetParent(CellView.SubContentHolder.transform, false);
CellView.SubContentHolder.SetActive(true);
SubContentShowWanted = true;
// update our cell after creating the ivalue (the value may have updated, make sure its consistent)
this.ProcessOnEvaluate();
this.SetDataToCell(this.CellView);
}
else
{
SubContentShowWanted = !SubContentShowWanted;
CellView.SubContentHolder.SetActive(SubContentShowWanted);
}
CellView.RefreshSubcontentButton();
}
public virtual void SetValueFromIValue(object value)
{
if (CellView == null)
{
ExplorerCore.LogWarning("Trying to set value from IValue but CellView is null!?");
return;
}
SetUserValue(value);
SetDataToCell(CellView);
}
public virtual void ReleaseIValue()
{
if (IValue == null)
return;
IValue.ReleaseFromOwner();
Pool.Return(CurrentIValueType, IValue);
IValue = null;
}
internal static GameObject InactiveIValueHolder
{
get
{
if (!inactiveIValueHolder)
{
inactiveIValueHolder = new GameObject("Temp_IValue_Holder");
GameObject.DontDestroyOnLoad(inactiveIValueHolder);
inactiveIValueHolder.transform.parent = UIManager.PoolHolder.transform;
inactiveIValueHolder.SetActive(false);
}
return inactiveIValueHolder;
}
}
private static GameObject inactiveIValueHolder;
// Value state args helper
public struct ValueStateArgs
{
public ValueStateArgs(bool valueActive = true, bool valueRichText = true, Color? valueColor = null,

View File

@ -84,10 +84,5 @@ namespace UnityExplorer.UI.CacheObject.Views
{
// not used
}
//protected override void ConstructUpdateToggle(GameObject parent)
//{
// // not used
//}
}
}

View File

@ -19,7 +19,7 @@ namespace UnityExplorer.UI.IValues
object ICacheObjectController.Target => this.CurrentOwner.Value;
public Type TargetType { get; private set; }
public override bool CanWrite => false;// TODO RefIDictionary != null && !RefIDictionary.IsReadOnly;
public override bool CanWrite => base.CanWrite && RefIDictionary != null && !RefIDictionary.IsReadOnly;
public Type KeyType;
public Type ValueType;
@ -149,6 +149,24 @@ namespace UnityExplorer.UI.IValues
}
}
// Setting value to dictionary
public void TrySetValueToKey(object key, object value, int keyIndex)
{
try
{
RefIDictionary[key] = value;
var entry = cachedEntries[keyIndex];
entry.SetValueFromSource(value);
entry.SetDataToCell(entry.CellView);
}
catch (Exception ex)
{
ExplorerCore.LogWarning($"Exception setting IDictionary key! {ex}");
}
}
// KVP entry scroll pool
public void OnCellBorrowed(CacheKeyValuePairCell cell)

View File

@ -19,7 +19,7 @@ namespace UnityExplorer.UI.IValues
object ICacheObjectController.Target => this.CurrentOwner.Value;
public Type TargetType { get; private set; }
public override bool CanWrite => RefIList != null && !RefIList.IsReadOnly;
public override bool CanWrite => base.CanWrite && RefIList != null && !RefIList.IsReadOnly;
public Type EntryType;
public IEnumerable RefIEnumerable;
@ -60,6 +60,7 @@ namespace UnityExplorer.UI.IValues
cachedEntries.Clear();
}
// Setting the List value itself to this model
public override void SetValue(object value)
{
if (value == null)
@ -100,6 +101,8 @@ namespace UnityExplorer.UI.IValues
int idx = 0;
foreach (var entry in RefIEnumerable)
{
// var entry = item.TryCast();
values.Add(entry);
// If list count increased, create new cache entries
@ -133,6 +136,24 @@ namespace UnityExplorer.UI.IValues
}
}
// Setting the value of an index to the list
public void TrySetValueToIndex(object value, int index)
{
try
{
RefIList[index] = value;
var entry = cachedEntries[index];
entry.SetValueFromSource(value);
entry.SetDataToCell(entry.CellView);
}
catch (Exception ex)
{
ExplorerCore.LogWarning($"Exception setting IList value: {ex}");
}
}
// List entry scroll pool
public override void SetLayout()

View File

@ -17,10 +17,10 @@ namespace UnityExplorer.UI.IValues
public virtual bool CanWrite => this.CurrentOwner.CanWrite;
public CacheObjectBase CurrentOwner { get; }
public CacheObjectBase CurrentOwner => m_owner;
private CacheObjectBase m_owner;
public object EditedValue { get; private set; }
//public object EditedValue { get; private set; }
public virtual void SetLayout() { }
@ -53,12 +53,6 @@ namespace UnityExplorer.UI.IValues
}
this.m_owner = owner;
// ...
}
public virtual void SetValue(object value)
{
this.EditedValue = value;
}
public virtual void ReleaseFromOwner()
@ -69,6 +63,13 @@ namespace UnityExplorer.UI.IValues
this.m_owner = null;
}
public virtual void SetValue(object value) { }
//public virtual void SetValue(object value)
//{
// this.EditedValue = value;
//}
public virtual GameObject CreateContent(GameObject parent)
{
UIRoot = UIFactory.CreateUIObject(this.GetType().Name, parent);