public DictionaryInspector() { AddElementCommand = new CRelayCommand((arg) => { if (m_addKeyValue == null) { LogUtility.Log("The dictionary {0}", PropertyInfo.Name); return; } if (m_displayedList.Any(vm => SafeEquals(m_addKeyValue, vm.Key))) { LogUtility.Log("The dictionary {0} already contains an element with a default key! You cannot add a new element as long as the default key exists.", PropertyInfo.Name); return; } object defaultValueObject = EditorKlaxScriptUtility.GetTypeDefault(m_valueType); m_displayedList.Add(new CDictionaryEntryViewModel(m_displayedList.Count, m_addKeyValue, defaultValueObject, m_keyType, m_valueType)); if (PropertyInfo.Value == null) { IDictionary newDictionary = (IDictionary)Activator.CreateInstance(PropertyInfo.ValueType); foreach (var viewModel in m_displayedList) { newDictionary.Add(viewModel.Key, viewModel.Value); } SetInspectorValue(PropertyInfo, null, newDictionary, true); } else { if (m_inspector.DispatchSetter) { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { IDictionary dictionary = PropertyInfo.GetOriginalValue <IDictionary>(); dictionary.Add(m_addKeyValue, defaultValueObject); }); } else { IDictionary dictionary = PropertyInfo.GetOriginalValue <IDictionary>(); dictionary.Add(m_addKeyValue, defaultValueObject); } } CollectionList.ItemsSource = null; CollectionList.ItemsSource = m_displayedList; HeaderText = m_displayedList.Count + " Elements"; }); ClearCommand = new CRelayCommand(arg => { ClearCollection(); }); InitializeComponent(); }
public CInputPinViewModel(CInputPin inputPin, CScriptNodeViewmodel nodeViewModel, int pinIndex) : base(nodeViewModel, pinIndex) { m_pin = inputPin; Name = inputPin.Name; Tooltip = EditorKlaxScriptUtility.GetTypeName(inputPin.Type); m_pinColor = PinColorHelpers.GetColorForType(inputPin.Type); m_nodeViewmodel = nodeViewModel; m_literal = inputPin.Literal; m_valueType = inputPin.Type; m_bIsLiteralOnly = inputPin.bIsLiteralOnly; }
public ListInspector() { InitializeComponent(); AddElementCommand = new CRelayCommand((arg) => { object defaultObject = EditorKlaxScriptUtility.GetTypeDefault(m_collectionElementType); m_displayedList.Add(new CListEntryViewModel(m_displayedList.Count, defaultObject, m_collectionElementType)); if (PropertyInfo.Value == null) { IList newList = (IList)Activator.CreateInstance(PropertyInfo.ValueType); foreach (var value in m_displayedList) { newList.Add(value.Value); } SetInspectorValue(PropertyInfo, null, newList, true); } else { if (m_inspector.DispatchSetter) { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { IList list = PropertyInfo.GetOriginalValue <IList>(); list.Add(defaultObject); }); } else { IList list = PropertyInfo.GetOriginalValue <IList>(); list.Add(defaultObject); } } CollectionList.ItemsSource = null; CollectionList.ItemsSource = m_displayedList; ListExpander.Header = m_displayedList.Count + " Elements"; }); ClearCommand = new CRelayCommand(arg => { ClearCollection(); }); }
public override bool CanConnect(CPinViewModel pinToCheck, out string failReason) { if (pinToCheck == null) { failReason = "Source not existing"; return(false); } if (pinToCheck.NodeViewModel == NodeViewModel) { failReason = "Cannot connect to a pin on the same node"; return(false); } if (pinToCheck is COutputPinViewModel) { failReason = "Output is not compatible with another output"; return(false); } if (pinToCheck is CExecutionPinViewModel) { failReason = "Output is not compatible with execution"; return(false); } if (pinToCheck is CInputPinViewModel inputPin) { if (inputPin.IsLiteralOnly) { failReason = $"Input pin {inputPin.Name} can only be assigned a value by changing its literal value"; return(false); } if (!inputPin.ValueType.IsAssignableFrom(ValueType)) { failReason = "Output of type " + EditorKlaxScriptUtility.GetTypeName(ValueType) + " is not compatible with input of type " + EditorKlaxScriptUtility.GetTypeName(inputPin.ValueType); return(false); } } failReason = ""; return(true); }