Exemple #1
0
        public static bool IsCompatibleWith(this DlogPort port, DlogPort other)
        {
            if (other.Type == PortType.Fake || port.Type == PortType.Fake)
            {
                return(true);
            }
            switch (port.Type)
            {
            case PortType.Check:
                return(other.Type == PortType.Check || other.Type == PortType.Combiner);

            case PortType.Trigger:
                return(other.Type == PortType.Trigger);

            case PortType.Actor:
                return(other.Type == PortType.Actor);

            case PortType.Branch:
                return(other.Type == PortType.Branch);

            case PortType.Combiner:
                return(other.Type == PortType.Check || other.Type == PortType.Combiner);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
        public static void InjectCustomStyle(this DlogPort port)
        {
            var cap   = port.Q("cap");
            var width = cap.style.width;

            width.value     = new Length(8, LengthUnit.Pixel);
            cap.style.width = width;
            var height = cap.style.height;

            height.value     = new Length(12, LengthUnit.Pixel);
            cap.style.height = height;

            // Border color
            var bLColor = cap.style.borderLeftColor;

            bLColor.value             = port.portColor;
            cap.style.borderLeftColor = bLColor;

            var bTColor = cap.style.borderTopColor;

            bTColor.value            = port.portColor;
            cap.style.borderTopColor = bTColor;

            var bRColor = cap.style.borderRightColor;

            bRColor.value = port.portColor;
            cap.style.borderRightColor = bRColor;

            var bBColor = cap.style.borderBottomColor;

            bBColor.value = port.portColor;
            cap.style.borderBottomColor = bBColor;
        }
Exemple #3
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();
        }
Exemple #4
0
        public static Color PortColor(DlogPort port)
        {
            switch (port.Type)
            {
            case PortType.Check:
                if (port.direction == Direction.Input)
                {
                    return(new Color(0.2f, 0.73f, 1f));
                }
                return(new Color(0.5f, 0.98f, 1f));

            case PortType.Trigger:
                if (port.direction == Direction.Input)
                {
                    return(new Color(1f, 0.15f, 0.26f));
                }
                return(new Color(0.84f, 0.26f, 0.16f));

            case PortType.Actor:
                if (port.direction == Direction.Input)
                {
                    return(new Color(0.55f, 1f, 0.3f));
                }
                return(new Color(0.75f, 1f, 0.36f));

            case PortType.Branch:
                if (port.direction == Direction.Input)
                {
                    return(new Color(0.9f, 1f, 0.99f));
                }
                return(new Color(0.91f, 0.93f, 1f));

            case PortType.Combiner:
                if (port.direction == Direction.Input)
                {
                    return(new Color(0.45f, 0.25f, 1f));
                }
                return(new Color(0.45f, 0.25f, 1f));

            case PortType.Fake:
                return(Color.clear);

            default:
                throw new ArgumentOutOfRangeException(nameof(port), port, "Undefined color for port type.");
            }
        }
Exemple #5
0
        public static DlogPort Create(string name, Orientation portOrientation, Direction portDirection, Capacity portCapacity, PortType type, bool required, EdgeConnectorListener edgeConnectorListener, bool hideLabel = false)
        {
            var port = new DlogPort(portOrientation, portDirection, portCapacity);

            if (edgeConnectorListener != null)
            {
                port.m_EdgeConnector = new EdgeConnector <Edge>(edgeConnectorListener);
                port.AddManipulator(port.m_EdgeConnector);
            }

            port.AddStyleSheet("Styles/Node/Port");
            if (!required)
            {
                port.AddToClassList("optional");
            }

            port.type        = type;
            port.portColor   = PortHelper.PortColor(port);
            port.viewDataKey = Guid.NewGuid().ToString();
            port.portName    = name;

            if (hideLabel)
            {
                var label = port.Q <Label>();
                var fs    = label.style.fontSize;
                fs.value             = -1;
                label.style.fontSize = fs;
                var color = label.style.color;
                color.value       = Color.clear;
                label.style.color = color;
            }


            port.InjectCustomStyle();

            return(port);
        }
Exemple #6
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();
        }