Esempio n. 1
0
    private void TaskInputSection(VisualElement root)
    {
        VisualContainer row = new VisualContainer {
            name = "newTaskRow"
        };

        root.Add(row);
        if (_newTaskName == null)
        {
            _newTaskName = new TextField()
            {
                name = "newTaskNameInput"
            };
            _newTaskName.RegisterCallback <KeyUpEvent>(TaskNameKeyDownCallback);
        }

        row.Add(_newTaskName);

        Button newTaskButton = new Button(NewTodoTask)
        {
            name = "newTaskButton", text = "Add Task"
        };

        row.Add(newTaskButton);
    }
Esempio n. 2
0
        public VisualContainer CreateTask(string name)
        {
            var task = new VisualContainer();

            task.focusIndex = 0;
            task.name       = name;
            task.AddToClassList("task");

            task.RegisterCallback <KeyDownEvent, VisualContainer>(DeleteTask, task);

            var taskName = new Toggle(() => {})
            {
                text = name, name = "checkbox"
            };

            task.Add(taskName);

            var taskDelete = new Button(() => task.parent.Remove(task))
            {
                name = "delete", text = "Delete"
            };

            task.Add(taskDelete);

            return(task);
        }
Esempio n. 3
0
    public void OnEnable()
    {
        var root = this.GetRootVisualContainer();

        //添加style.uss样式
        root.AddStyleSheetPath("style");

        var boxes = new VisualContainer();

        //设置自动换行
        boxes.style.flexDirection = FlexDirection.Row;
        boxes.style.flexWrap      = Wrap.Wrap;
        for (int i = 0; i < 20; i++)
        {
            TextField mTextField = new TextField();
            boxes.Add(mTextField);
            Button button = new Button(delegate() { Debug.LogFormat("Click"); })
            {
                text = "我是按钮我要自适应"
            };

            boxes.Add(button);
        }
        root.Add(boxes);
    }
Esempio n. 4
0
        public UdonProgramSourceView()
        {
            // Create and add container and children to display latest Assembly
            _assemblyContainer = new VisualContainer()
            {
                name = "Container",
            };
            _assemblyHeader = new Label("Udon Assembly")
            {
                name = "Header",
            };

            _scrollView = new ScrollView();

            _assemblyField = new TextElement()
            {
                name = "AssemblyField",
            };

            _assemblyContainer.Add(_assemblyHeader);
            _assemblyContainer.Add(_scrollView);
            _assemblyContainer.Add(_assemblyField);
            _scrollView.SetContents(_assemblyField);

            Add(_assemblyContainer);
        }
Esempio n. 5
0
        public void OnEnable()
        {
            var root = this.GetRootVisualContainer();

            root.AddStyleSheetPath("styles");

            // Here we just take all layout properties and other to extract them in USS!
            var boxes = new VisualContainer()
            {
                name = "boxesContainer"
            };

            boxes.AddToClassList("horizontalContainer");
            root.Add(boxes);

            for (int i = 0; i < m_Colors.Length; i++)
            {
                Color c = m_Colors[i];

                // inform layout system of desired width for each box
                boxes.Add(new VisualElement()
                {
                    style =
                    {
                        backgroundColor = c
                    }
                });
            }

            // Some more advanced layout now!
            var twoPlusOneContainer = new VisualContainer()
            {
                name = "2Plus1Container"
            };

            twoPlusOneContainer.AddToClassList("horizontalContainer");
            root.Add(twoPlusOneContainer);
            twoPlusOneContainer.Add(new VisualElement()
            {
                name = "large"
            });
            twoPlusOneContainer.Add(new VisualElement()
            {
                name = "small"
            });

            var wrapContainer = new VisualContainer()
            {
                name = "wrapContainer"
            };

            wrapContainer.AddToClassList("horizontalContainer");
            root.Add(wrapContainer);

            for (int i = 0; i < 20; i++)
            {
                wrapContainer.Add(new VisualElement());
            }
        }
Esempio n. 6
0
        public void AddNormal(string text)
        {
            var entry = _labels.AddOne();

            entry.CheapEnable();
            entry.text = text;
            entry.RemoveFromClassList(_highlightClass);
            _container.Add(entry);
        }
Esempio n. 7
0
 public SingleHighlightText(string highlightClass, string labelClass)
 {
     Container = new VisualContainer();
     Container.style.flexDirection = FlexDirection.Row;
     Container.WithClass("highlight-container");
     FirstPart  = new Label().WithClass(labelClass);
     SecondPart = new Label().WithClass(highlightClass).WithClass(labelClass);
     ThirdPart  = new Label().WithClass(labelClass);
     Container.Add(FirstPart);
     Container.Add(SecondPart);
     Container.Add(ThirdPart);
 }
        private void OnEnable()
        {
            _rootView = this.GetRootVisualContainer();
            _rootView.Add(new Label("Midi Settings")
            {
                style =
                {
                    fontSize     = 18,
                    marginTop    = 10,
                    marginBottom = 10,
                }
            });

            // Container for Device Name label and field
            VisualContainer deviceNameContainer = new VisualContainer()
            {
                style = { flexDirection = FlexDirection.Row }
            };

            _rootView.Add(deviceNameContainer);

            // Label for Field
            deviceNameContainer.Add(new Label("Device Name"));

            // Input Name Field
            _deviceNameField = new TextField()
            {
                isDelayed = true,
                value     = EditorPrefs.GetString(DEVICE_NAME_STRING),
                style     = { flexGrow = 1 },
            };
            _deviceNameField.OnValueChanged(evt => EditorPrefs.SetString(DEVICE_NAME_STRING, evt.newValue));
            //deviceNameContainer.Add(_deviceNameField);

            // Get available device names
            VRCPortMidiInput midi = new VRCPortMidiInput();
            var deviceNames       = midi.GetDeviceNames().ToList();

            // Add blank device name to use if specified device not found
            deviceNames.Insert(0, "");
            string currentDeviceValue = EditorPrefs.GetString(DEVICE_NAME_STRING);
            string defaultValue       = deviceNames.Contains(currentDeviceValue) ? currentDeviceValue : "";

            // Create and add device popup
            var deviceNamePopupField = new PopupField <string>(deviceNames, defaultValue)
            {
                style = { flexGrow = 1 },
                name  = "midiDevicePopUp",
            };

            deviceNamePopupField.OnValueChanged(evt => EditorPrefs.SetString(DEVICE_NAME_STRING, evt.newValue));
            deviceNameContainer.Add(deviceNamePopupField);
        }
Esempio n. 9
0
        private void ResizeTo(int newValue)
        {
            _sizeField.value = newValue;

            // Create from scratch if currentFields are null
            if (_fields == null)
            {
                Debug.Log($"Creating from Scratch");
                _fields = new List <VisualElement>();
                for (int i = 0; i < newValue; i++)
                {
                    var field = GetValueField(null);
                    _fields.Add(field);
                    _container.Add(field as VisualElement);
                }
                return;
            }

            // Shrink list if new value is less than old one
            if (newValue < _fields.Count)
            {
                for (int i = _fields.Count - 1; i >= newValue; i--)
                {
                    (_fields[i] as VisualElement).RemoveFromHierarchy();
                    _fields.RemoveAt(i);
                }
                MarkDirtyRepaint();
                return;
            }

            // Expand list if new value is more than old one.
            if (newValue > _fields.Count)
            {
                int numberToAdd = newValue - _fields.Count;
                for (int i = 0; i < numberToAdd; i++)
                {
                    var field = GetValueField(null);
                    if (field == null)
                    {
                        Debug.LogWarning($"Sorry, can't edit object of type {typeof(T).ToString()} yet.");
                        return;
                    }
                    _fields.Add(field);

                    _container.Add(field as VisualElement);
                }
                MarkDirtyRepaint();
                return;
            }
        }
Esempio n. 10
0
        public ConstantPadNode(string titleLabel = "Constant Padding")
        {
            SetSize(new Vector2(224, 100 + style.marginTop));
            inputContainer.style.width = 84;

            // hardcode 1x1 padding for now.  TODO - make this have a UI
            pad = new Padding(1);

            title = titleLabel;
            var pixelType = typeof(T);

            m_ImageDataType = typeof(Image <T>);
            m_PortLabel     = string.Format("Image<{0}>", pixelType.Name);

            input           = VisionPort.Create <Edge, Image <T> >(Orientation.Horizontal, Direction.Input, Port.Capacity.Single);
            input.onUpdate += OnInputUpdate;

            input.portName = m_PortLabel;
            inputContainer.Add(input);

            output = VisionPort.Create <Edge, Image <T> >(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi);

            output.portName                     = m_PortLabel;
            outputContainer.style.width         = 84;
            outputContainer.style.flexDirection = FlexDirection.Row;
            outputContainer.style.alignItems    = Align.Center;

            outputContainer.Add(output);

            var sizeField = new Vector2IntField();
            var sizeLabel = new Label("Pad Size");

            sizeLabel.style.minWidth = 92;

            var sizeContainer = new VisualContainer();

            sizeContainer.style.flexDirection = FlexDirection.Row;
            sizeContainer.style.flexWrap      = Wrap.NoWrap;
            sizeField.style.flexDirection     = FlexDirection.Row;
            sizeField.style.flexWrap          = Wrap.NoWrap;
            sizeField.style.maxWidth          = 128;
            sizeContainer.Add(sizeLabel);
            sizeContainer.Add(sizeField);

            extensionContainer.Add(sizeContainer);

            titleButtonContainer.style.visibility = Visibility.Hidden;
            RefreshExpandedState();
        }
Esempio n. 11
0
        public void UpdateRevisions(IEnumerable <RevisionData> datas, string tip, int totalRevisions, int currentPage)
        {
            var elements           = new List <VisualElement>();
            var isFullDateObtained = false; // Has everything from this date been obtained?

            m_HistoryItems.Clear();

            if (datas != null)
            {
                DateTime currentDate = DateTime.MinValue;
                foreach (var data in datas)
                {
                    if (data.timeStamp.Date != currentDate.Date)
                    {
                        elements.Add(new CollabHistoryRevisionLine(data.timeStamp, isFullDateObtained));
                        currentDate = data.timeStamp;
                    }

                    var item = new CollabHistoryItem(data);
                    m_HistoryItems.Add(item);

                    var container = new VisualContainer();
                    container.style.flexDirection = FlexDirection.Row;
                    if (data.current)
                    {
                        isFullDateObtained = true;
                        container.AddToClassList("currentRevision");
                        container.AddToClassList("obtainedRevision");
                    }
                    else if (data.obtained)
                    {
                        container.AddToClassList("obtainedRevision");
                    }
                    else
                    {
                        container.AddToClassList("absentRevision");
                    }
                    // If we use the index as-is, the latest commit will become #1, but we want it to be last
                    container.Add(new CollabHistoryRevisionLine(data.index));
                    container.Add(item);
                    elements.Add(container);
                }
            }

            m_HistoryView.scrollOffset = new Vector2(0, 0);
            m_Pager.totalItems         = totalRevisions;
            m_Pager.curPage            = currentPage;
            m_Pager.items = elements;
        }
Esempio n. 12
0
        protected override void SetupInputFields(int width = 3, int height = 3)
        {
            style.alignContent  = new StyleValue <Align>(Align.Center);
            style.alignItems    = new StyleValue <Align>(Align.Center);
            style.flexDirection = new StyleValue <FlexDirection>(FlexDirection.Row);

            const int pad         = 4;
            var       fieldWidth  = (this.style.width / width) - pad - 2;
            var       fieldHeight = (this.style.height / height / 2) - pad;

            for (var i = 0; i < width; i++)
            {
                var x         = (fieldWidth + pad) * i;
                var container = new VisualContainer();
                container.style.width         = fieldWidth;
                container.style.flexDirection = FlexDirection.Row;
                for (var j = 0; j < height; j++)
                {
                    var input = new FloatField(6);
                    input.style.width        = fieldWidth - 16;
                    input.style.positionLeft = x;
                    input.style.positionTop  = fieldHeight * j;
                    input.style.positionType = PositionType.Absolute;
                    input.OnValueChanged(OnMatrixInputUpdate);
                    MatrixInputs[i, j] = input;
                    container.Add(input);
                }

                Add(container);
            }
        }
Esempio n. 13
0
    void OnMouseUp()
    {
        if (draggingThis)
        {
            dragging     = false;
            draggingThis = false;
            StartCoroutine(DelayPreviews());  // re-enable previews after 0.25 seconds (so previews don't immediately pop up when releasing a card)
            string cardName         = GetComponent <CardInfo>().cardName;
            bool   targetsPlayers   = GetComponent <CardInfo>().targetsPlayers;
            bool   canTargetSelf    = GetComponent <CardInfo>().canTargetSelf;
            string hit              = DetectHit(targetsPlayers, canTargetSelf);
            bool   returnToPosition = true;

            // if it's your main step
            if (Logic.Instance.currentPlayer == Player.localPlayer && Logic.Instance.mainStepActive && Logic.Instance.currentEvent == null)
            {
                if (cardName == "shootSpring" && hit != null)
                {
                    Player.localPlayer.CmdShoot(hit, transform.GetSiblingIndex());
                    returnToPosition = false;
                }
            }
            // if you're reacting to an event
            else if (Logic.Instance.currentEvent != null)
            {
                VisualContainer vcHand       = Player.localPlayer.visual.transform.Find("Hand").GetComponent <VisualContainer>();
                VisualContainer vcIntentArea = GameObject.Find("Visual/IntentArea").GetComponent <VisualContainer>();

                if (cardName == "grazeSpring" && hit == "PlayArea" && transform.parent.name == "Hand")
                {
                    Player.localPlayer.CmdIntendGraze();
                    transform.GetComponent <HoverPreview>().ThisPreviewEnabled = false;

                    vcHand.Remove(transform);
                    vcHand.Adjust(transform.childCount);
                    vcIntentArea.Add(transform);
                    vcIntentArea.Adjust(transform.childCount);

                    returnToPosition = false;
                }

                if (cardName == "grazeSpring" && hit == "HandArea" && transform.parent.name == "IntentArea")
                {
                    vcIntentArea.Remove(transform);
                    vcIntentArea.Adjust(transform.childCount);
                    vcHand.Add(transform);
                    vcHand.Adjust(transform.childCount);

                    returnToPosition = false;
                }
            }

            if (returnToPosition)
            {
                StartCoroutine(PlayAnimation("ReturnToPosition"));
            }
        }
    }
Esempio n. 14
0
        public UdonArrayInspector(System.Action <object> valueChangedAction, object value)
        {
            _setValueCallback = valueChangedAction;

            AddToClassList("input-inspector");
            var resizeContainer = new VisualElement()
            {
                name = "resize-container",
            };

            resizeContainer.Add(new Label("size"));

            _sizeField           = new IntegerField();
            _sizeField.isDelayed = true;
            _sizeField.OnValueChanged((evt) =>
            {
                ResizeTo(evt.newValue);
            });
            resizeContainer.Add(_sizeField);
            Add(resizeContainer);

            _scroller = new ScrollView()
            {
                name = "array-scroll",
            };
            Add(_scroller);

            _container = new VisualContainer();
            _scroller.SetContents(_container);

            if (value == null)
            {
                // Can't show if array is empty
                _sizeField.value = 0;
                return;
            }
            else
            {
                IEnumerable <T> values = (value as IEnumerable <T>);
                if (values == null)
                {
                    Debug.LogError($"Couldn't convert {value} to {typeof(T).ToString()} Array");
                    return;
                }

                // Populate fields and their values from passed-in array
                _fields = new List <VisualElement>();
                foreach (var item in values)
                {
                    var field = GetValueField(item);
                    _fields.Add(field);

                    _container.Add(field);
                }

                _sizeField.value = values.Count();
            }
        }
Esempio n. 15
0
    private void TaskListSection(VisualElement root)
    {
        VisualContainer list = new VisualContainer {
            name = "taskList"
        };

        root.Add(list);
        foreach (string task in _selectedTodo.GetAllTasks())
        {
            VisualContainer row = new VisualContainer();
            row.AddToClassList("taskRow");
            list.Add(row);

            Label taskNameLabel = new Label(task);
            taskNameLabel.AddToClassList("taskNameLabel");

            if (_selectedTodo.GetTask(task) ?? true)
            {
                taskNameLabel.AddToClassList("taskDone");
            }

            row.Add(taskNameLabel);

            Button taskUpdateButton = new Button(() => UpdateTodoTask(task));
            taskUpdateButton.AddToClassList("taskUpdateButton");
            if (_selectedTodo.GetTask(task) ?? true)
            {
                taskNameLabel.AddToClassList("taskDone");
                taskUpdateButton.text = "Not Done";
            }
            else
            {
                taskUpdateButton.text = "Done";
            }

            row.Add(taskUpdateButton);

            Button taskDeleteButton = new Button(() => DeleteTodoTask(task))
            {
                text = "Delete"
            };
            taskDeleteButton.AddToClassList("taskDeleteButton");
            row.Add(taskDeleteButton);
        }
    }
Esempio n. 16
0
 public ReuseList(System.Func <T> spawner)
 {
     _parent  = new VisualContainer();
     _entries = new List <T>();
     _pool    = ListPool.New(() =>
     {
         var entry = spawner();
         _parent.Add(entry.Element);
         return(entry);
     }
                             );
 }
Esempio n. 17
0
        public void UpdateRevisions(IEnumerable <RevisionData> datas, string tip, int totalRevisions)
        {
            List <VisualElement> list = new List <VisualElement>();
            bool isFullDateObtained   = false;

            this.m_HistoryItems.Clear();
            DateTime dateTime = DateTime.MinValue;

            foreach (RevisionData current in datas)
            {
                if (current.timeStamp.Date != dateTime.Date)
                {
                    list.Add(new CollabHistoryRevisionLine(current.timeStamp, isFullDateObtained));
                    dateTime = current.timeStamp;
                }
                CollabHistoryItem collabHistoryItem = new CollabHistoryItem(current);
                this.m_HistoryItems.Add(collabHistoryItem);
                VisualContainer visualContainer = new VisualContainer();
                visualContainer.style.flexDirection = FlexDirection.Row;
                if (current.current)
                {
                    isFullDateObtained = true;
                    visualContainer.AddToClassList("currentRevision");
                    visualContainer.AddToClassList("obtainedRevision");
                }
                else if (current.obtained)
                {
                    visualContainer.AddToClassList("obtainedRevision");
                }
                else
                {
                    visualContainer.AddToClassList("absentRevision");
                }
                visualContainer.Add(new CollabHistoryRevisionLine(current.index));
                visualContainer.Add(collabHistoryItem);
                list.Add(visualContainer);
            }
            this.m_Pager.totalItems = totalRevisions;
            this.m_Pager.items      = list;
        }
 private void CreateScrollViewContainer(Rect position)
 {
     scrollViewContent = new VisualContainer()
     {
         style =
         {
             width           = position.width * zoomSize / minZoomSize,
             height          = position.height * zoomSize / minZoomSize,
             backgroundColor = Color.clear,
         }
     };
     scrollViewContent.Add(content);
 }
Esempio n. 19
0
        public void OnEnable()
        {
            // Each editor window contains a root VisualContainer object
            VisualElement root = this.GetRootVisualContainer();

            // VisualContainer objects can contain VisualElement objects,
            // which is the base class for VisualContainer and other controls
            VisualContainer boxes = new VisualContainer();

            root.Add(boxes);

            // The most basic way to place an element is to assign its rect
            // although you should prefer layout in most cases
            boxes.layout = new Rect(
                kMargin,
                kMargin,
                kPadding * 2 + kBoxSize * m_Colors.Length,
                kPadding * 2 + kBoxSize
                );

            // The VisualTree is painted back-to-front following depth first traversal
            // thus a parent paints before its children
            boxes.style.backgroundColor = Color.grey;

            // A VisualContainer will clip its descendants outside of its own
            // rect based on this property
            boxes.clippingOptions = VisualElement.ClippingOptions.ClipContents;

            for (int i = 0; i < m_Colors.Length; i++)
            {
                Color c = m_Colors[i];
                // position rects are relative to the parent rect
                boxes.Add(new VisualElement()
                {
                    layout = new Rect(kPadding + i * kBoxSize, kPadding, kBoxSize, kBoxSize),
                    style  = { backgroundColor = c }
                });
            }
        }
Esempio n. 20
0
        public ConfirmWindow(string text, Action <bool> callback, ContainerStyle style = null,
                             ButtonStyle yesButtonStyle = null, ButtonStyle noButtonStyle = null)
            : base(0, 0, 0, 0)
        {
            ConfirmCallback = callback ?? throw new ArgumentNullException(nameof(callback));

            SetAlignmentInParent(Alignment.Center);
            SetFullSize(FullSize.Both);

            Container = Add(new VisualContainer(style ?? new ContainerStyle()
            {
                Wall = 165, WallColor = 27
            })) as VisualContainer;
            Container.SetAlignmentInParent(Alignment.Center)
            .SetFullSize(FullSize.Horizontal)
            .SetupLayout(Alignment.Center, Direction.Down, childIndent: 0);

            int lines = (text?.Count(c => c == '\n') ?? 0) + 1;

            Label = Container.AddToLayout(new Label(0, 0, 0, 1 + lines * 3, text, null,
                                                    new LabelStyle()
            {
                TextIndent = new Indent()
                {
                    Horizontal = 1, Vertical = 1
                }
            }))
                    .SetFullSize(FullSize.Horizontal) as Label;

            VisualContainer yesno = Container.AddToLayout(new VisualContainer(0, 0, 24, 4)) as VisualContainer;

            yesButtonStyle = yesButtonStyle ?? new ButtonStyle()
            {
                WallColor  = PaintID.DeepGreen,
                BlinkStyle = ButtonBlinkStyle.Full,
                BlinkColor = PaintID.White
            };
            yesButtonStyle.TriggerStyle = ButtonTriggerStyle.TouchEnd;
            YesButton = yesno.Add(new Button(0, 0, 12, 4, "yes", null, yesButtonStyle,
                                             ((self, touch) =>
            {
                self.Root.HidePopUp();
                callback.Invoke(true);
            }))) as Button;

            noButtonStyle = noButtonStyle ?? new ButtonStyle()
            {
                WallColor  = PaintID.DeepRed,
                BlinkStyle = ButtonBlinkStyle.Full,
                BlinkColor = PaintID.White
            };
            noButtonStyle.TriggerStyle = ButtonTriggerStyle.TouchEnd;
            NoButton = yesno.Add(new Button(12, 0, 12, 4, "no", null, noButtonStyle,
                                            ((self, touch) =>
            {
                self.Root.HidePopUp();
                callback.Invoke(false);
            }))) as Button;

            Callback = CancelCallback;
            Container.SetWH(0, Label.Height + yesno.Height);
        }
        public PreConvolutionPadNode(string titleLabel = "Pre-Convolution Padding")
        {
            SetSize(new Vector2(224, 100 + style.marginTop));
            inputContainer.style.width = 84;

            title = titleLabel;
            var pixelType = typeof(T);

            m_ImageDataType = typeof(Image <T>);
            m_PortLabel     = string.Format("Image<{0}>", pixelType.Name);

            var input1 = VisionPort.Create <Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single,
                                                  m_ImageDataType);

            input1.portName = m_PortLabel;

            inputContainer.Add(input1);

            output = VisionPort.Create <Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi,
                                              m_ImageDataType);

            output.portName                     = m_PortLabel;
            outputContainer.style.width         = 84;
            outputContainer.style.flexDirection = FlexDirection.Row;
            outputContainer.style.alignItems    = Align.Center;

            outputContainer.Add(output);

            var modeField = new EnumField(ConvolutionPadMode.Same);
            var sizeField = new Vector2IntField();
            var sizeLabel = new Label("Convolution Size");

            sizeLabel.style.minWidth = 92;


            var modeContainer = new VisualContainer();

            modeContainer.style.flexDirection = FlexDirection.Row;
            modeContainer.style.flexWrap      = Wrap.NoWrap;

            /*
             * var sizeContainer = new VisualContainer();
             * sizeContainer.style.flexDirection = FlexDirection.Row;
             * sizeContainer.style.flexWrap = Wrap.NoWrap;
             * sizeField.style.flexDirection = FlexDirection.Row;
             * sizeField.style.flexWrap = Wrap.NoWrap;
             * sizeField.style.maxWidth = 128;
             * sizeContainer.Add(sizeLabel);
             * sizeContainer.Add(sizeField);
             */

            modeField.style.minWidth = 64;
            var padLabel = new Label("Pad Mode");

            padLabel.style.minWidth = 96;
            modeContainer.Add(padLabel);
            modeContainer.Add(modeField);

            //extensionContainer.Add(sizeContainer);
            extensionContainer.Add(modeContainer);

            titleButtonContainer.style.visibility = Visibility.Hidden;
            RefreshExpandedState();
        }
Esempio n. 22
0
        public CollabHistoryItem(RevisionData data)
        {
            m_RevisionId  = data.id;
            m_TimeStamp   = data.timeStamp;
            name          = "HistoryItem";
            m_ActionsTray = new VisualContainer {
                name = "HistoryItemActionsTray"
            };
            m_ProgressSpinner = new HistoryProgressSpinner();
            m_Details         = new VisualElement {
                name = "HistoryDetail"
            };
            var author = new Label(data.authorName)
            {
                name = "Author"
            };

            m_TimeAgo         = new Label(TimeAgo.GetString(m_TimeStamp));
            m_FullDescription = data.comment;
            var shouldTruncate = ShouldTruncateDescription(m_FullDescription);

            if (shouldTruncate)
            {
                m_Description = new Label(GetTruncatedDescription(m_FullDescription));
            }
            else
            {
                m_Description = new Label(m_FullDescription);
            }
            m_Description.name = "RevisionDescription";
            var dropdown = new CollabHistoryDropDown(data.changes, data.changesTotal, data.changesTruncated, data.id);

            if (data.current)
            {
                m_Button = new Button(Restore)
                {
                    name = "ActionButton", text = "Restore"
                };
            }
            else if (data.obtained)
            {
                m_Button = new Button(GoBackTo)
                {
                    name = "ActionButton", text = "Go back to..."
                };
            }
            else
            {
                m_Button = new Button(UpdateTo)
                {
                    name = "ActionButton", text = "Update"
                };
            }
            m_Button.SetEnabled(data.enabled);
            m_ProgressSpinner.ProgressEnabled = data.inProgress;

            m_ActionsTray.Add(m_ProgressSpinner);
            m_ActionsTray.Add(m_Button);

            m_Details.Add(author);
            m_Details.Add(m_TimeAgo);
            m_Details.Add(m_Description);

            if (shouldTruncate)
            {
                m_ExpandCollapseButton = new Button(ToggleDescription)
                {
                    name = "ToggleDescription", text = "Show More"
                };
                m_Details.Add(m_ExpandCollapseButton);
            }

            if (data.buildState != BuildState.None)
            {
                BuildStatusButton buildButton;
                if (data.buildState == BuildState.Configure)
                {
                    buildButton = new BuildStatusButton(ShowServicePage);
                }
                else
                {
                    buildButton = new BuildStatusButton(ShowBuildForCommit, data.buildState, data.buildFailures);
                }

                m_Details.Add(buildButton);
            }

            m_Details.Add(m_ActionsTray);
            m_Details.Add(dropdown);

            Add(m_Details);

            this.schedule.Execute(UpdateTimeAgo).Every(1000 * 20);
        }
Esempio n. 23
0
        public override void Initialize()
        {
            // Determine the position and size of the interface.
            int x = 0, y = 0, w = 50, h = 40;
            // Pass an empty provider to the panel (the interface will be drawn on Main.tile).
            object provider = null;
            // Although we can use as a provider, for example, FakeTileRectangle from FakeManager:
            //object provider = FakeManager.FakeManager.Common.Add("TestPanelProvider", x, y, w, h);

            // Create a panel with a wall of diamond gemspark wall with black paint.
            Panel root = TUI.TUI.Create(new Panel("TestPanel", x, y, w, h, null,
                                                  new ContainerStyle()
            {
                Wall = WallID.DiamondGemspark, WallColor = PaintID.Black
            }, provider)) as Panel;
            // Create a Label widget (text display) with white characters.
            Label label1 = new Label(1, 1, 17, 2, "some text", new LabelStyle()
            {
                TextColor = PaintID.White
            });

            // Add to panel
            root.Add(label1);

            // Create a container that occupies the lower (larger) half of our panel, painted over with white paint.
            // The Add function returns the newly added object in the VisualObject type,
            // so adding an element can be implemented as follows:
            VisualContainer node = root.Add(
                new VisualContainer(0, 15, w, 25, null, new ContainerStyle()
            {
                WallColor = PaintID.White
            })
                ) as VisualContainer;

            // Add a button to this container, which, when clicked, will send the clicker to the chat.

            /*node.Add(new Button(5, 0, 12, 4, "lol", null, new ButtonStyle()
             * { Wall = 165, WallColor = PaintID.DeepGreen }, (self, touch) =>
             *    touch.Player().SendInfoMessage("You pressed lol button!")));*/

            if (false)
            {
                // Set the layout configuration.
                node.SetupLayout(Alignment.Center, Direction.Right, Side.Center, null, 3, false);
                // Add the InputLabel widget to the layout that allows you to input text.
                node.AddToLayout(new InputLabel(0, 0, new InputLabelStyle()
                {
                    TextColor = PaintID.Black, Type = InputLabelType.All, TextUnderline = LabelUnderline.None
                },
                                                new Input <string>("000", "000")));
                // Add to the layout one more ItemRack widget that corresponds to the Weapon rack: displaying an item
                // on a 3x3 rack. By clicking displays the relative and absolute coordinates of this click.
                node.AddToLayout(new ItemRack(0, 0, new ItemRackStyle()
                {
                    Type = 200, Left = true
                }, (self, touch) =>
                                              Console.WriteLine($"Touch: {touch.X}, {touch.Y}; absolute: {touch.AbsoluteX}, {touch.AbsoluteY}")));
                ItemRack irack1 = node.AddToLayout(new ItemRack(0, 0,
                                                                new ItemRackStyle()
                {
                    Type = 201, Left = true
                })) as ItemRack;
                // ItemRack allows you to add text on top using a sign:
                irack1.SetText("lololo\nkekeke");
                // Finally, add the slider to the layout.
                node.AddToLayout(new Slider(0, 0, 10, 2, new SliderStyle()
                {
                    Wall = WallID.AmberGemsparkOff, WallColor = PaintID.White
                }));
            }

            if (false)
            {
                // Set up the grid configuration. Specify that it has to fill all the cells automatically.
                // Two columns (right size of 15, left - everything else) and two lines, occupying the same amount of space.
                node.SetupGrid(
                    new ISize[] { new Relative(100), new Absolute(15) }, // Размеры колонок
                    new ISize[] { new Relative(50), new Relative(50) },  // Размеры линий
                    null, true);
                // In the top left cell (at the intersection of the first column and the first line), set the background color to orange.
                node[0, 0].Style.WallColor = PaintID.DeepOrange;
                // At the top right, we put a sapphire (blue) wall without paint.
                node[1, 0].Style.Wall      = WallID.SapphireGemspark;
                node[1, 0].Style.WallColor = PaintID.None;
                // In the bottom left cell, you can place the Label widget with the SandStoneSlab block.
                // Although the coordinates and sizes are specified as 0, they will automatically be
                // set, since the object is in the Grid.
                node[0, 1] = new Label(0, 0, 0, 0, "testing", null, new LabelStyle()
                {
                    Tile      = TileID.SandStoneSlab,
                    TileColor = PaintID.Red,
                    TextColor = PaintID.Black
                });
            }

            if (false)
            {
                // Install a large and complex grid.
                node.SetupGrid(new ISize[] { new Absolute(3), new Relative(50), new Absolute(6), new Relative(50) },
                               new ISize[] { new Relative(20), new Absolute(5), new Relative(80) });
                // Although we set the grid on the node, we can still add objects as before.
                // Add a button that draws the grid by pressing, and hides it when released.
                node.Add(new Button(3, 3, 10, 4, "show", null, new ButtonStyle()
                {
                    WallColor    = PaintID.DeepBlue,
                    BlinkStyle   = ButtonBlinkStyle.Full,
                    TriggerStyle = ButtonTriggerStyle.Both
                }, (self, touch) =>
                {
                    if (touch.State == TouchState.Begin)
                    {
                        node.ShowGrid();
                    }
                    else
                    {
                        node.Apply().Draw();
                    }
                }));
            }

            if (false)
            {
                // Add a label and immediately set Alignment.DownRight with indent 3 blocks to the right and 1 below.
                node.Add(new Label(0, 0, 16, 6, "test", new LabelStyle()
                {
                    WallColor = PaintID.DeepPink
                }))
                .SetAlignmentInParent(Alignment.DownRight, new ExternalIndent()
                {
                    Right = 3, Down = 1
                });
            }

            if (false)
            {
                // Let's make our node container the size of the root in width.
                node.SetFullSize(true, false);
            }

            node.SetupLayout(Alignment.Center, Direction.Down, Side.Center, null, 1, false);

            // VisualObject
            VisualObject obj = node.AddToLayout(new VisualObject(5, 5, 8, 4, null, new UIStyle()
            {
                Wall      = WallID.AmethystGemspark,
                WallColor = PaintID.DeepPurple
            }, (self, touch) =>
                                                                 TSPlayer.All.SendInfoMessage($"Relative: ({touch.X}, {touch.Y}); Absolute: ({touch.AbsoluteX}, {touch.AbsoluteY})")));

            // VisualContainer
            //VisualContainer node2 = node.Add(
            //    new VisualContainer(5, 5, 20, 10, null, new ContainerStyle() { WallColor = PaintID.Black })
            //) as VisualContainer;

            // Label
            Label label = node.AddToLayout(new Label(15, 5, 19, 4, "some text", new LabelStyle()
            {
                WallColor = PaintID.DeepLime,
                TextColor = PaintID.DeepRed
            })) as Label;

            // Button
            Button button = node.AddToLayout(new Button(15, 5, 12, 4, "lol", null, new ButtonStyle()
            {
                WallColor    = PaintID.DeepGreen,
                BlinkColor   = PaintID.Shadow,
                TriggerStyle = ButtonTriggerStyle.TouchEnd
            }, (self, touch) => touch.Player().SendInfoMessage("You released lol button!"))) as Button;

            // Slider
            Slider slider = node.AddToLayout(new Slider(15, 5, 10, 2, new SliderStyle()
            {
                Wall           = WallID.EmeraldGemspark,
                WallColor      = PaintID.White,
                SeparatorColor = PaintID.Black,
                UsedColor      = PaintID.DeepOrange
            }, new Input <int>(0, 0, (self, value, playerIndex) =>
                               TShock.Players[playerIndex].SendInfoMessage("Slider value: " + value)))) as Slider;

            // Checkbox
            Checkbox checkbox = node.AddToLayout(new Checkbox(15, 5, 2, new CheckboxStyle()
            {
                Wall         = WallID.EmeraldGemspark,
                WallColor    = PaintID.White,
                CheckedColor = PaintID.DeepRed
            }, new Input <bool>(false, false, (self, value, playerIndex) =>
                                TSPlayer.All.SendInfoMessage("Checkbox value: " + value)))) as Checkbox;

            // Separator
            Separator separator = node.AddToLayout(new Separator(6, new UIStyle()
            {
                Wall      = 156,
                WallColor = PaintID.DeepRed
            })) as Separator;

            // InputLabel
            InputLabel input = node.AddToLayout(new InputLabel(15, 5, new InputLabelStyle()
            {
                Type               = InputLabelType.All,
                TextUnderline      = LabelUnderline.Underline,
                TextColor          = PaintID.DeepRed,
                TextUnderlineColor = PaintID.Black // Этот параметр из LabelStyle
            }, new Input <string>("12345", "12345", (self, value, playerIndex) =>
                                  TSPlayer.All.SendInfoMessage("InputLabel value: " + value)))) as InputLabel;

            // ItemRack
            ItemRack irack = node.AddToLayout(new ItemRack(15, 5, new ItemRackStyle()
            {
                Type = ItemID.LargeDiamond,
                Size = ItemSize.Biggest,
                Left = true
            })) as ItemRack;
            ItemRack irack2 = node.AddToLayout(new ItemRack(20, 5, new ItemRackStyle()
            {
                Type = ItemID.SnowmanCannon,
                Size = ItemSize.Smallest,
                Left = true
            })) as ItemRack;

            irack2.SetText("This is a snowman cannon.");

            // VisualSign
            VisualSign vsign  = node.AddToLayout(new VisualSign(0, 0, "lmfao sosi(te pozhaluista)")) as VisualSign;
            VisualSign vsign2 = node.AddToLayout(new VisualSign(0, 0, "This is an example of what can happen " +
                                                                "if you use signs in TUI without FakeManager (only $399!)." +
                                                                "Text above would be empty. Even tho it has to have it...")) as VisualSign;

            // FormField
            FormField ffield = node.AddToLayout(new FormField(
                                                    new Checkbox(0, 0, 2, new CheckboxStyle()
            {
                Wall         = WallID.AmberGemspark,
                WallColor    = PaintID.White,
                CheckedColor = PaintID.DeepRed
            }), 15, 5, 20, 2, "check me", new LabelStyle()
            {
                TextColor     = PaintID.Shadow,
                TextAlignment = Alignment.Left
            }, new ExternalIndent()
            {
                Right = 1
            })) as FormField;

            // Image
            Image image = node.AddToLayout(new Image(15, 5, "Media\\Image.TEditSch")) as Image;

            // Video
            Video video = node.AddToLayout(new Video(15, 5, null, new VideoStyle()
            {
                Path      = "Media\\Animation-1",
                Delay     = 100,
                TileColor = PaintID.DeepTeal
            }, (self, touch) => (self as Video).ToggleStart())) as Video;

            // AlertWindow
            Button alertButton = node.AddToLayout(new Button(15, 10, 16, 4, "alert", null, new ButtonStyle()
            {
                Wall      = WallID.AmberGemspark,
                WallColor = PaintID.DeepOrange
            }, (self, touch) => node.Root.Alert("Hello world"))) as Button;

            // ConfirmWindow
            Button confirmButton = node.AddToLayout(new Button(15, 13, 20, 4, "confirm\npls", null, new ButtonStyle()
            {
                Wall      = WallID.AmberGemspark,
                WallColor = PaintID.DeepTeal
            }, (self, touch) => node.Root.Confirm("Very nice", value => TSPlayer.All.SendInfoMessage("Confirmed? " + value)))) as Button;

            // ScrollBackground
            // <Adding a lot of widgets to layout>
            // Specifying layer value as Int32.MinValue so that this widget would be under all other child objects,
            // although ScrollBackground specifies this layer by default in custructor so we don't have to do it manually.
            ScrollBackground scrollbg = node.Add(new ScrollBackground(true, true, true), Int32.MinValue) as ScrollBackground;

            // ScrollBar
            ScrollBar scrollbar = node.Add(new ScrollBar(Direction.Right)) as ScrollBar;

            // Arrow
            Arrow arrow = node.AddToLayout(new Arrow(15, 5, new ArrowStyle()
            {
                TileColor = PaintID.DeepBlue,
                Direction = Direction.Left
            })) as Arrow;
        }
Esempio n. 24
0
        public void OnEnable()
        {
            var root = this.GetRootVisualContainer();

            // Let's now try to do an example similar to the 1st example
            var boxes = new VisualContainer()
            {
                style =
                {
                    marginLeft   = kMargin,
                    marginTop    = kMargin,
                    marginRight  = kMargin,
                    marginBottom = kMargin,
                    // By control layout parameters we can simply stack boxes horizontally
                    backgroundColor = Color.grey,
                    paddingLeft     = kPadding,
                    paddingTop      = kPadding,
                    paddingRight    = kPadding,
                    paddingBottom   = kPadding,
                    alignSelf       = Align.FlexStart,
                    flexDirection   = FlexDirection.Row // makes the container horizontal
                }
            };

            root.Add(boxes);

            for (int i = 0; i < m_Colors.Length; i++)
            {
                Color c = m_Colors[i];

                // inform layout system of desired width for each box
                boxes.Add(new VisualElement()
                {
                    style =
                    {
                        width           = kBoxSize,
                        height          = kBoxSize,
                        backgroundColor = c
                    }
                });
            }

            // Some more advanced layout now!
            var twoPlusOneContainer = new VisualContainer()
            {
                style =
                {
                    marginLeft   = kMargin,
                    marginTop    = kMargin,
                    marginRight  = kMargin,
                    marginBottom = kMargin,
                    // Example of flexibles elements with 70%-30% distribution
                    // this is possible thanks to the "flex" property
                    height        =             100,
                    alignSelf     = Align.FlexStart,
                    flexDirection = FlexDirection.Row
                }
            };

            root.Add(twoPlusOneContainer);

            twoPlusOneContainer.Add(new VisualElement()
            {
                style =
                {
                    flex            = 0.7f,
                    backgroundColor = Color.red
                }
            });
            twoPlusOneContainer.Add(new VisualElement()
            {
                style =
                {
                    flex            = 0.3f,
                    backgroundColor = Color.blue
                }
            });

            var wrapContainer = new VisualContainer()
            {
                style =
                {
                    marginLeft   = kMargin,
                    marginTop    = kMargin,
                    marginRight  = kMargin,
                    marginBottom = kMargin,
                    // Example of an horizontal container that wraps its contents
                    // over several lines depending on available space
                    flexWrap      = Wrap.Wrap,
                    flexDirection = FlexDirection.Row
                }
            };

            root.Add(wrapContainer);

            for (int i = 0; i < 20; i++)
            {
                wrapContainer.Add(new VisualElement()
                {
                    style =
                    {
                        width           = 20,
                        height          = 20,
                        marginLeft      =  5,
                        marginTop       =  5,
                        marginRight     =  5,
                        marginBottom    =  5,
                        backgroundColor = Color.blue
                    }
                });
            }
        }
Esempio n. 25
0
        private void Initialize(AttachToPanelEvent evt)
        {
            // switch event to do some UI updates instead of initialization from here on out
            UnregisterCallback <AttachToPanelEvent>(Initialize);
            //    this.RegisterCallback<AttachToPanelEvent>(OnAttach);

            // Add Header
            Add(new TextElement()
            {
                name = "intro",
                text = "Udon Graph",
            });

            Add(new TextElement()
            {
                name = "header-message",
                text = "The Udon Graph is your gateway to creating amazing things in VRChat.\nCheck out the Readme and UdonExampleScene in the VRChat Examples folder to get started."
            });

            var mainContainer = new VisualElement()
            {
                name = "main",
            };

            Add(mainContainer);

            var template  = EditorGUIUtility.Load("Assets/Udon/Editor/Resources/UdonChangelog.uxml") as VisualTreeAsset;
            var changelog = template.CloneTree(null);

            changelog.name = "changelog";
            mainContainer.Add(changelog);

            var column2 = new VisualContainer()
            {
                name = "column-2"
            };

            mainContainer.Add(column2);

            // Add Button for Last Graph
            if (!string.IsNullOrEmpty(Settings.LastGraphGuid))
            {
                _openLastGraphButton = new Button(() =>
                {
                    var assetPath = AssetDatabase.GUIDToAssetPath(Settings.LastGraphGuid);
                    var graphName = assetPath.Substring(assetPath.LastIndexOf("/") + 1).Replace(".asset", "");

                    // Find actual asset from guid
                    var asset = AssetDatabase.LoadAssetAtPath <UdonGraphProgramAsset>(assetPath);
                    if (asset != null)
                    {
                        var w = EditorWindow.GetWindow <UdonGraphWindow>("Udon Graph", true, typeof(SceneView));
                        // get reference to saved UdonBehaviour if possible
                        UdonBehaviour udonBehaviour = null;
                        string gPath = Settings.LastUdonBehaviourPath;
                        string sPath = Settings.LastUdonBehaviourScenePath;
                        if (!string.IsNullOrEmpty(gPath) && !string.IsNullOrEmpty(sPath))
                        {
                            var targetScene = UnityEditor.SceneManagement.EditorSceneManager.GetSceneByPath(sPath);
                            if (targetScene != null && targetScene.isLoaded && targetScene.IsValid())
                            {
                                var targetObject = UnityEngine.GameObject.Find(gPath);
                                if (targetObject != null)
                                {
                                    udonBehaviour = targetObject.GetComponent <UdonBehaviour>();
                                }
                            }
                        }

                        // Initialize graph with restored udonBehaviour or null if not found / not saved
                        w.InitializeGraph(asset, udonBehaviour);
                    }
                });

                UpdateLastGraphButtonLabel();
                column2.Add(_openLastGraphButton);
            }

            var settingsTemplate = EditorGUIUtility.Load("Assets/Udon/Editor/Resources/UdonSettings.uxml") as VisualTreeAsset;
            var settings         = settingsTemplate.CloneTree(null);

            settings.name = "settings";
            column2.Add(settings);

            // get reference to first settings section
            var section = settings.Q("section");

            // Add Grid Snap setting
            var gridSnapContainer = new VisualElement();

            gridSnapContainer.AddToClassList("settings-item-container");
            var gridSnapField = new IntegerField(3)
            {
                value = Settings.GridSnapSize
            };

            gridSnapField.OnValueChanged(e =>
            {
                Settings.GridSnapSize = e.newValue;
            });
            gridSnapContainer.Add(new Label("Grid Snap Size"));
            gridSnapContainer.Add(gridSnapField);
            section.Add(gridSnapContainer);
            var gridSnapLabel = new Label("Snap elements to a grid as you move them. 0 for No Snapping.");

            gridSnapLabel.AddToClassList("settings-label");
            section.Add(gridSnapLabel);

            // Add Search On Selected Node settings
            var searchOnSelectedNode = (new Toggle()
            {
                text = "Focus Search On Selected Node",
                value = Settings.SearchOnSelectedNodeRegistry,
            });

            searchOnSelectedNode.OnValueChanged((toggleEvent) =>
            {
                Settings.SearchOnSelectedNodeRegistry = toggleEvent.newValue;
            });
            section.Add(searchOnSelectedNode);
            var searchOnLabel = new Label("Highlight a node and press Spacebar to open a Search Window focused on nodes for that type. ");

            searchOnLabel.AddToClassList("settings-label");
            section.Add(searchOnLabel);

            // Add Search On Noodle Drop settings
            var searchOnNoodleDrop = (new Toggle()
            {
                text = "Search On Noodle Drop",
                value = Settings.SearchOnNoodleDrop,
            });

            searchOnNoodleDrop.OnValueChanged((toggleEvent) =>
            {
                Settings.SearchOnNoodleDrop = toggleEvent.newValue;
            });
            section.Add(searchOnNoodleDrop);
            var searchOnDropLabel = new Label("Drop a noodle into empty space to search for anything that can be connected.");

            searchOnDropLabel.AddToClassList("settings-label");
            section.Add(searchOnDropLabel);

            // Add UseNeonStyle setting
            var useNeonStyle = (new Toggle()
            {
                text = "Use Neon Style",
                value = Settings.UseNeonStyle,
            });

            useNeonStyle.OnValueChanged((toggleEvent) =>
            {
                Settings.UseNeonStyle = toggleEvent.newValue;
            });
            section.Add(useNeonStyle);
            var useNeonStyleLabel = new Label("Try out an experimental Neon Style. We will support User Styles in an upcoming version.");

            useNeonStyleLabel.AddToClassList("settings-label");
            section.Add(useNeonStyleLabel);
        }