예제 #1
0
        public override void InitializeNode(EdgeConnectorListener edgeConnectorListener)
        {
            base.InitializeNode(edgeConnectorListener);
            Initialize("Self", EditorView.DefaultNodePosition);

            lineLabel = new Label {
                name = "lineTitle", text = "Lines"
            };
            outputContainer.Add(lineLabel);

            var button = new Button(() => AddConversationPort(true))
            {
                text = "Create Dialogue Line"
            };

            extensionContainer.Add(button);
            var titleLabel   = this.Q <Label>("title-label");
            var titleElement = this.Q("title");
            var titleC       = UIElementsFactory.VisualElement <VisualElement>("title-container", null);

            titleLabel.RemoveFromHierarchy();
            titleC.Add(titleLabel);
            titleElement.Insert(0, titleC);

            var branchPort = DlogPort.Create("Branch", Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, PortType.Branch, true, edgeConnectorListener);

            branchPort.AddToClassList("square-circle");
            titleC.Insert(0, branchPort);
            AddPort(branchPort, false);
            Refresh();
        }
예제 #2
0
        private void AddConversationPort(bool create, int index = -1)
        {
            lineLabel.AddToClassList("visible");
            var conversationContainer = new VisualElement {
                name = "conversation-container"
            };

            if (create)
            {
                Owner.EditorView.DlogObject.RegisterCompleteObjectUndo("Created Dialogue Line");
                index = Lines.Count;
                Lines.Add(new LineDataNpc {
                    Line = ""
                });
            }

            var message = UIElementsFactory.TextField("conversation-item", "Line", new[] { "message" }, null, null, true);

            if (!create)
            {
                message.SetValueWithoutNotify(Lines[index].Line);
            }

            var branchPort = DlogPort.Create("Branch", Orientation.Horizontal, Direction.Output, Port.Capacity.Single, PortType.Branch, true, EdgeConnectorListener);

            branchPort.name = "conversation-item";
            branchPort.AddToClassList("branch-port");
            var triggerPort = DlogPort.Create("Trigger", Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, PortType.Trigger, false, EdgeConnectorListener);

            triggerPort.name = "conversation-item";
            triggerPort.AddToClassList("trigger-port");
            var checkPort = DlogPort.Create("Check", Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, PortType.Check, false, EdgeConnectorListener);

            checkPort.name = "conversation-item";
            checkPort.AddToClassList("check-port");

            var flexBreak = UIElementsFactory.FlexBreaker();

            if (create)
            {
                Lines[index].PortGuidA = branchPort.viewDataKey;
                Lines[index].PortGuidB = triggerPort.viewDataKey;
                Lines[index].PortGuidC = checkPort.viewDataKey;
            }
            else
            {
                branchPort.viewDataKey  = Lines[index].PortGuidA;
                triggerPort.viewDataKey = Lines[index].PortGuidB;
                checkPort.viewDataKey   = Lines[index].PortGuidC;
            }

            message.RegisterCallback <FocusOutEvent>(evt => {
                var lineIndex = Lines.FindIndex(data => data.PortGuidA == branchPort.viewDataKey);
                if (message.value != Lines[lineIndex].Line)
                {
                    Owner.EditorView.DlogObject.RegisterCompleteObjectUndo("Changed Dialogue Line");
                    Lines[lineIndex].Line = message.value;
                }
            });
            var removeButton = UIElementsFactory.Button("x", "conversation-item", "Remove line", new[] { "remove-button" }, () => { RemoveLine(Lines.FindIndex(data => data.PortGuidA == branchPort.viewDataKey)); });

            conversationContainer.Add(message);
            conversationContainer.Add(branchPort);
            conversationContainer.Add(flexBreak);
            conversationContainer.Add(checkPort);
            conversationContainer.Add(removeButton);
            conversationContainer.Add(triggerPort);

            var separator = new VisualElement {
                name = "divider"
            };

            separator.AddToClassList("horizontal");
            separator.AddToClassList("horizontal-divider");
            outputContainer.Add(separator);

            outputContainer.Add(conversationContainer);
            Ports.Add(branchPort);
            Ports.Add(triggerPort);
            Ports.Add(checkPort);
            if (create)
            {
                Owner.PortData.Add(branchPort.viewDataKey);
                Owner.PortData.Add(triggerPort.viewDataKey);
                Owner.PortData.Add(checkPort.viewDataKey);
                Owner.GuidPortDictionary.Add(branchPort.viewDataKey, branchPort);
                Owner.GuidPortDictionary.Add(triggerPort.viewDataKey, triggerPort);
                Owner.GuidPortDictionary.Add(checkPort.viewDataKey, checkPort);
            }

            Refresh();
        }