private void DrawLinkUI(AILinkView linkView)
        {
            HeaderHandler headerRects;

            if (EditorApplication.isPlaying)
            {
                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))
                {
                    ShowChangeLinkMenu(linkView);
                }
            }

            GUI.Label(headerRects.Next, "AI Link | APEX AI", EditorStyling.Skinned.inspectorTitle);

            EditorGUILayout.Separator();

            DrawViewSharedUI(linkView);
        }
Exemple #2
0
        internal void ChangeAILink(AILinkView alv, Guid newAiId, bool recordUndo = true)
        {
            if (newAiId == this._ai.id)
            {
                EditorUtility.DisplayDialog("Invalid Action", "You cannot add a link between an AI and itself.", "Ok");
                return;
            }

            var refActions = GetReferencingActions(alv).ToArray();

            if (recordUndo)
            {
                _undoRedo.Do(new ReplaceAILinkOperation(this, alv.aiId, newAiId, alv));
            }

            alv.aiId = newAiId;

            foreach (var av in refActions)
            {
                var la = av.action as AILinkAction;
                if (la != null)
                {
                    la.aiId = newAiId;
                }
            }

            this.isDirty = true;
            RefreshActiveEditor();
        }
Exemple #3
0
        internal AILinkView AddAILink(Vector2 position, string aiId, bool recordUndo = true)
        {
            var aiGuid = new Guid(aiId);

            if (aiGuid == this._ai.id)
            {
                EditorUtility.DisplayDialog("Invalid Action", "You cannot add a link between an AI and itself.", "Ok");
                return(null);
            }

            var viewRect = this.canvas.SnapToGrid(new Rect(position.x, position.y, 200f * this.canvas.zoom, 0f));
            var ail      = new AILinkView(aiGuid, viewRect)
            {
                parent = this
            };

            this.canvas.views.Add(ail);
            Select(ail);

            this.isDirty = true;

            if (recordUndo)
            {
                _undoRedo.Do(new AddAILinkOperation(this, ail));
            }

            RefreshActiveEditor();
            return(ail);
        }
Exemple #4
0
        internal AILinkLayout(AILinkView linkView, float windowTop, ScaleSettings scaling)
            : base(linkView, windowTop, scaling)
        {
            var zoom = scaling.scale;

            _containerHeight = scaling.aiLinkBodyHeight;
            _nameArea        = new XRange(_localViewRange.xMin + (10f * zoom), _localViewRange.width - ((_showAreaWidth + 10f) * zoom));
            _showArea        = new XRange(_nameArea.xMax, _showAreaWidth * zoom);
        }
        private static StageElement WriteAILinkView(AILinkView lv)
        {
            var lve = new StageElement(
                ElementName.AILinkView,
                SerializationMaster.Stage(ElementName.ViewArea, lv.viewArea),
                SerializationMaster.ToStageAttribute(AttributeName.Id, lv.aiId));

            lve.AddTextValue(ElementName.Name, lv.name);
            lve.AddTextValue(ElementName.Description, lv.description);

            return(lve);
        }
Exemple #6
0
        private void ResetSingleSelection(bool resfreshState)
        {
            _currentAILink    = null;
            _currentSelector  = null;
            _currentQualifier = null;
            _currentAction    = null;

            if (resfreshState)
            {
                this.inspectorState.Refresh();
            }
        }
        private static AILinkView ReadAILinkView(StageElement lve, AIUI parent)
        {
            var lv = new AILinkView
            {
                name        = lve.ValueOrDefault <string>(ElementName.Name),
                description = lve.ValueOrDefault <string>(ElementName.Description),
                viewArea    = lve.ValueOrDefault <Rect>(ElementName.ViewArea),
                aiId        = lve.AttributeValue <Guid>(AttributeName.Id),
                parent      = parent
            };

            return(lv);
        }
        private void ShowChangeLinkMenu(AILinkView lv)
        {
            Action <AIStorage> cb = (ai) =>
            {
                lv.parent.ChangeAILink(lv, new Guid(ai.aiId));
            };

            // We do not want the button click itself to count as a change.
            GUI.changed = false;

            var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition);

            AISelectorWindow.Get(screenPos, cb);
        }
Exemple #9
0
        internal void Select(AILinkView alv)
        {
            _currentAILink = alv;
            _selectedViews.Clear();
            if (alv != null)
            {
                _selectedViews.Add(alv);
            }

            _currentSelector  = null;
            _currentQualifier = null;
            _currentAction    = null;

            this.inspectorState.Refresh();
        }
Exemple #10
0
        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();
        }
Exemple #11
0
        private IEnumerable <ActionView> GetReferencingActions(AILinkView alv)
        {
            foreach (var selectorView in this.canvas.selectorViews)
            {
                foreach (var qualifierView in selectorView.qualifierViews)
                {
                    var actionView     = qualifierView.actionView as AILinkActionView;
                    var compActionView = qualifierView.actionView as CompositeActionView;
                    if (actionView != null)
                    {
                        var action = (AILinkAction)actionView.action;
                        if (action.aiId == alv.aiId)
                        {
                            yield return(actionView);
                        }
                    }
                    else if (compActionView != null)
                    {
                        var action = compActionView.connectorAction as AILinkAction;
                        if (action != null && action.aiId == alv.aiId)
                        {
                            yield return(compActionView);
                        }
                    }
                }

                var defaultQualifier    = selectorView.defaultQualifierView;
                var defActionView       = defaultQualifier.actionView as AILinkActionView;
                var compositeActionView = defaultQualifier.actionView as CompositeActionView;
                if (defActionView != null)
                {
                    var action = (AILinkAction)defActionView.action;
                    if (action.aiId == alv.aiId)
                    {
                        yield return(defActionView);
                    }
                }
                else if (compositeActionView != null)
                {
                    var action = compositeActionView.connectorAction as AILinkAction;
                    if (action != null && action.aiId == alv.aiId)
                    {
                        yield return(compositeActionView);
                    }
                }
            }
        }
Exemple #12
0
        internal void RemoveAILink(AILinkView alv, bool recordUndo = true)
        {
            if (alv == _currentAILink)
            {
                _currentAILink = null;
                this.inspectorState.Refresh();
            }

            RemoveTopLevelViewOperation undoOp = null;

            if (recordUndo)
            {
                undoOp = new RemoveAILinkOperation(this, alv);
                _undoRedo.Do(undoOp);
            }

            var refActions = GetReferencingActions(alv);

            foreach (var av in refActions)
            {
                if (recordUndo)
                {
                    undoOp.LogReferencingActionRemoval(av);
                }

                //References from composite actions must be treated differently
                var cav = av as CompositeActionView;
                if (cav != null)
                {
                    ResetConnection(cav, false);
                }
                else
                {
                    RemoveAction(av, false);
                }
            }

            this.canvas.views.Remove(alv);
            _selectedViews.Remove(alv);
            this.isDirty = true;
        }
Exemple #13
0
        internal void MultiSelectView(TopLevelView view)
        {
            if (!_selectedViews.Contains(view))
            {
                _selectedViews.Add(view);
            }
            else
            {
                _selectedViews.Remove(view);
            }

            if (_selectedViews.Count == 1)
            {
                view             = _selectedViews[0];
                _currentSelector = view as SelectorView;
                _currentAILink   = view as AILinkView;
            }
            else
            {
                ResetSingleSelection(false);
            }

            this.inspectorState.Refresh();
        }