internal void ReplaceQualifier(QualifierView qv, IQualifier replacement, bool recordUndo = true) { var qualifiers = qv.parent.selector.qualifiers; var idx = qualifiers.IndexOf(qv.qualifier); if (idx < 0) { return; } if (recordUndo) { _undoRedo.Do(new ReplaceQualifierOperation(this, qv.qualifier, replacement, qv)); //We don't want to clone during undo/redo as the cloning is recorded TryClone(qv.qualifier, replacement); } replacement.action = qv.qualifier.action; qualifiers[idx] = replacement; qv.qualifier = replacement; //Need to refresh editor this.inspectorState.Refresh(); this.isDirty = true; }
internal void RemoveQualifier(QualifierView qv, bool recordUndo = true) { if (qv.isDefault) { return; } if (qv == _currentQualifier) { _currentQualifier = null; this.inspectorState.Refresh(); } var parent = qv.parent; int qidx = parent.qualifierViews.IndexOf(qv); parent.qualifierViews.RemoveAt(qidx); parent.selector.qualifiers.RemoveAt(qidx); this.isDirty = true; if (recordUndo) { _undoRedo.Do(new RemoveQualifierOperation(this, qv, qidx)); } }
internal void ReplaceDefaultQualifier(QualifierView newDefault, SelectorView parent, bool recordUndo = true) { if (!newDefault.isDefault) { throw new ArgumentException("Qualifier must be a Default Qualifier.", "newDefault"); } if (newDefault.parent != null && !object.ReferenceEquals(newDefault.parent, parent)) { throw new InvalidOperationException("Cannot add a qualifier that already has a parent Selector."); } if (recordUndo) { _undoRedo.Do(new ReplaceDefaultQualifierOperation(this, parent.defaultQualifierView, newDefault, parent)); } newDefault.parent = parent; parent.defaultQualifierView = newDefault; parent.selector.defaultQualifier = (IDefaultQualifier)newDefault.qualifier; Select(parent, newDefault, null); this.isDirty = true; }
internal static ActionView Create(Type actionType, QualifierView parent) { if (!typeof(IAction).IsAssignableFrom(actionType)) { throw new ArgumentException("The proposed type is not an Action.", "actionType"); } else if (actionType == typeof(SelectorAction) || actionType == typeof(AILinkAction)) { throw new ArgumentException("Connector type action cannot be added through this method.", "actionType"); } if (actionType == typeof(CompositeAction)) { return(new CompositeActionView { action = new CompositeAction(), parent = parent }); } return(new ActionView { action = Activator.CreateInstance(actionType) as IAction, parent = parent }); }
private static ActionView ReadActionView(StageElement ave, QualifierView parent) { var connectorType = ave.AttributeValueOrDefault <string>(AttributeName.ConnectorType, null); ActionView av; if (connectorType == ConnectorType.Selector) { av = new SelectorActionView(); } else if (connectorType == ConnectorType.AILink) { av = new AILinkActionView(); } else if (connectorType == ConnectorType.Composite) { av = new CompositeActionView(); } else { av = new ActionView(); } av.name = ave.ValueOrDefault <string>(ElementName.Name, null); av.description = ave.ValueOrDefault <string>(ElementName.Description, null); av.parent = parent; return(av); }
internal ActionView SetAction(ActionView av, QualifierView parent, bool recordUndo = true) { if (av.parent != null && !object.ReferenceEquals(av.parent, parent)) { throw new InvalidOperationException("Cannot add an action that already has a parent Qualifier."); } var oldAction = parent.actionView; av.parent = parent; parent.qualifier.action = av.action; parent.actionView = av; if (av.isSelectable) { Select(parent.parent, parent, av); } this.isDirty = true; if (recordUndo) { if (oldAction != null) { _undoRedo.Do(new SetActionOperation(this, oldAction, av)); } else { _undoRedo.Do(new SetActionOperation(this, av)); } } return(av); }
internal void ReplaceAction(QualifierView qv, IAction replacement, bool recordUndo = true) { var av = qv.actionView; if (av == null) { return; } if (recordUndo) { _undoRedo.Do(new ReplaceActionOperation(this, av.action, replacement, qv)); //We don't want to clone during undo/redo as the cloning is recorded TryClone(av.action, replacement); } if (av is CompositeActionView && !(replacement is CompositeAction)) { var tmp = new ActionView(); tmp.parent = qv; tmp.name = av.name; tmp.description = av.description; av = tmp; qv.actionView = av; } else if (!(av is CompositeActionView) && replacement is CompositeAction) { var tmp = new CompositeActionView(); tmp.parent = qv; tmp.name = av.name; tmp.description = av.description; av = tmp; qv.actionView = av; } else if (av is IConnectorActionView) { //For replacement of other connector views we need to reset to a normal ActionView. //Since it is not possible to replace an action with a connector, we don't handle the reverse. var tmp = new ActionView(); tmp.parent = qv; tmp.name = av.name; tmp.description = av.description; av = tmp; qv.actionView = av; } av.action = replacement; qv.qualifier.action = replacement; //Need to refresh editor this.inspectorState.Refresh(); this.isDirty = true; }
internal QualifierView AddQualifier(Type qualifierType, SelectorView parent, bool recordUndo = true) { if (qualifierType == null || parent == null) { return(null); } var qv = QualifierView.Create(qualifierType); return(AddQualifier(qv, parent)); }
private void ResetSingleSelection(bool resfreshState) { _currentAILink = null; _currentSelector = null; _currentQualifier = null; _currentAction = null; if (resfreshState) { this.inspectorState.Refresh(); } }
internal static QualifierView Create(Type qualifierType) { if (!typeof(IQualifier).IsAssignableFrom(qualifierType)) { throw new ArgumentException("The proposed type is not a Qualifier.", "qualifierType"); } var qv = new QualifierView(); qv.qualifier = Activator.CreateInstance(qualifierType) as IQualifier; return(qv); }
internal void Select(AILinkView alv) { _currentAILink = alv; _selectedViews.Clear(); if (alv != null) { _selectedViews.Add(alv); } _currentSelector = null; _currentQualifier = null; _currentAction = null; this.inspectorState.Refresh(); }
internal void Select(SelectorView sv, QualifierView qv, ActionView av) { _currentAILink = null; _currentSelector = sv; _selectedViews.Clear(); if (sv != null) { _selectedViews.Add(sv); } _currentQualifier = qv; _currentAction = av; this.inspectorState.Refresh(); }
private void DrawQualifierUI(QualifierView qualifierView) { HeaderHandler headerRects; if (EditorApplication.isPlaying || qualifierView.isDefault) { headerRects = HeaderHandler.GetHeaderRects(0); } else { headerRects = HeaderHandler.GetHeaderRects(2); if (GUI.Button(headerRects.Next, SharedStyles.deleteTooltip, SharedStyles.BuiltIn.deleteButtonSmall)) { GUI.changed = false; _state.currentAIUI.RemoveSelected(); return; } if (GUI.Button(headerRects.Next, EditorStyling.changeTypeTooltip, SharedStyles.BuiltIn.changeButtonSmall)) { ShowChangeTypeMenu(qualifierView.qualifier, (newQualifier) => _state.currentAIUI.ReplaceQualifier(qualifierView, newQualifier)); } } if (qualifierView.isDefault) { GUI.Label(headerRects.Next, string.Concat(_state.editedItem.name, " | APEX AI"), EditorStyling.Skinned.inspectorTitle); } else { var cbd = qualifierView.qualifier; var isDisabled = !EditorGUI.ToggleLeft(headerRects.Next, string.Concat(_state.editedItem.name, " | APEX AI"), !cbd.isDisabled, EditorStyling.Skinned.inspectorTitle); if (isDisabled != cbd.isDisabled) { cbd.isDisabled = isDisabled; _state.currentAIUI.undoRedo.Do(new DisableOperation(cbd)); } } EditorGUILayout.Separator(); DrawViewSharedUI(qualifierView); EditorGUILayout.Separator(); _state.editedItem.Render(_state); }
internal static string Serialize(QualifierView qualifier) { var aiPart = new StageElement(ElementName.AIPart); var uiPart = new StageElement(ElementName.UIPart); var root = new StageElement(ElementName.QualifierSnippet, aiPart, uiPart); root.AddTextAttribute(AttributeName.SnippetType, ElementName.QualifierSnippet); var aiItem = SerializationMaster.Stage(ElementName.Qualifier, qualifier.qualifier); aiPart.Add(aiItem); var viewItem = WriteQualifierView(qualifier); uiPart.Add(viewItem); return(SerializationMaster.Serialize(root)); }
private static StageElement WriteQualifierView(QualifierView qv) { var name = qv.isDefault ? ElementName.DefaultQualifier : ElementName.QualifierView; var qve = new StageElement(name); qve.AddTextValue(ElementName.Name, qv.name); qve.AddTextValue(ElementName.Description, qv.description); var av = qv.actionView; if (av != null) { var ae = WriteActionView(av); qve.Add(ae); } return(qve); }
private static QualifierView ReadQualifierView(StageElement qve, SelectorView parent) { var qv = new QualifierView { name = qve.ValueOrDefault <string>(ElementName.Name, null), description = qve.ValueOrDefault <string>(ElementName.Description, null), parent = parent }; var ave = qve.Element(ElementName.ActionView); if (ave != null) { qv.actionView = ReadActionView(ave, qv); } return(qv); }
internal ActionView SetAction(Type actionType, QualifierView parent) { if (actionType == null || parent == null) { return(null); } if (parent.actionView != null) { var action = Activator.CreateInstance(actionType) as IAction; if (action != null) { ReplaceAction(parent, action, true); return(parent.actionView); } } var av = ActionView.Create(actionType, parent); return(SetAction(av, parent)); }
internal QualifierView AddQualifier(QualifierView qv, SelectorView parent, bool recordUndo = true) { if (qv.parent != null && !object.ReferenceEquals(qv.parent, parent)) { throw new InvalidOperationException("Cannot add a qualifier that already has a parent Selector."); } qv.parent = parent; parent.qualifierViews.Add(qv); parent.selector.qualifiers.Add(qv.qualifier); Select(parent, qv, null); this.isDirty = true; if (recordUndo) { _undoRedo.Do(new AddQualifierOperation(this, qv)); } return(qv); }
internal bool Connect(QualifierView qv, TopLevelView targetView) { ActionView av = null; var sv = targetView as SelectorView; if (sv != null) { if (sv.selector.IsConnectedTo(qv.parent.selector)) { EditorUtility.DisplayDialog("Invalid Action", "Circular connections are not allowed.", "Ok"); return(false); } //Composite actions may also act as selectors as the last step var cav = qv.actionView as CompositeActionView; if (cav != null) { var ca = (CompositeAction)cav.action; var newConnector = new SelectorAction(sv.selector); _undoRedo.Do(new ConnectCompositeOperation(cav, ca.connectorAction, newConnector)); ca.connectorAction = newConnector; cav.targetView = null; return(true); } av = new SelectorActionView { targetSelector = sv, action = new SelectorAction(sv.selector), parent = qv }; } var lv = targetView as AILinkView; if (lv != null) { var cav = qv.actionView as CompositeActionView; if (cav != null) { var ca = (CompositeAction)cav.action; var newConnector = new AILinkAction(lv.aiId); _undoRedo.Do(new ConnectCompositeOperation(cav, ca.connectorAction, newConnector)); ca.connectorAction = newConnector; cav.targetView = null; return(true); } av = new AILinkActionView { targetAI = lv, action = new AILinkAction(lv.aiId), parent = qv }; } if (av != null) { SetAction(av, qv); return(true); } return(false); }