예제 #1
0
        protected virtual void OnEnable()
        {
            // Reference to the root of the window.
            rootElement = rootVisualElement;

            controlParent = new VisualElement();
            controlParent.Add(toggleRecording = new Button(ToggleRecording)
            {
                text = "--"
            });
            buttonParent = new VisualElement();
            buttonParent.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
            buttonParent.Add(togglePlayback  = new Button(TogglePlayback)
            {
                text = "--"
            });
            buttonParent.Add(playbackPauseGame = new Toggle("Pause game on playback ?")
            {
                viewDataKey = "playbackPauseGame"
            });
            controlParent.Add(new Label(" "));
            controlParent.Add(buttonParent);
            controlParent.Add(playbackPauseGame);
            controlParent.Add(new Label(" "));
            rootElement.Add(controlParent);

            framesParent = new VisualElement();
            var textParent = new VisualElement();

            textParent.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
            textParent.style.alignContent  = new StyleEnum <Align>(Align.Center);
            textParent.Add(recordedFrames  = new Label("Recordered --/--"));
            textParent.Add(previewedFrames = new Label("Previewing --/--"));
            framesParent.Add(textParent);
            var recordParent = new VisualElement();

            recordParent.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
            recordParent.style.alignContent  = new StyleEnum <Align>(Align.Center);
            recordParent.Add(frameCapacity   = new IntegerField("Frame capacity: ")
            {
                value = 50, viewDataKey = "frameCapacity"
            });
            recordParent.Add(showMultipleFrames = new Toggle("Show multiple frames ?")
            {
                viewDataKey = "showMultipleFrames"
            });
            framesParent.Add(recordParent);
            rootElement.Add(framesParent);

            playbackParent = new VisualElement();
            playbackParent.Add(playbackSingle = new SliderInt(0, 100)
            {
                viewDataKey = "playbackSingle"
            });
            playbackParent.Add(playbackMultiple = new MinMaxSlider(0, 100, 0, 100)
            {
                viewDataKey = "playbackMultiple"
            });
            rootElement.Add(playbackParent);
        }
    private void ShowFoodItemEditor()
    {
        rootVisualElement.Clear();

        var visualTree = Resources.Load <VisualTreeAsset>(foodItemTreePath);

        visualTree.CloneTree(rootVisualElement);

        // Setup food item editor screen
        Button       createItemButton = rootVisualElement.Q(name: "base-item-data-create-button") as Button;
        TextField    itemNameField    = rootVisualElement.Q(name: "item-data-name") as TextField;
        IntegerField itemValueField   = rootVisualElement.Q(name: "item-data-value") as IntegerField;
        TextField    itemDescField    = rootVisualElement.Q(name: "item-data-desc") as TextField;

        EnumField itemTypeField = rootVisualElement.Q(name: "item-data-type") as EnumField;

        itemTypeField.Init(workingItemType);

        EnumField itemRarityField = rootVisualElement.Q(name: "item-data-rarity") as EnumField;

        itemRarityField.Init(RarityType.Common);

        ObjectField itemIconField = rootVisualElement.Q(name: "item-data-icon") as ObjectField;

        itemIconField.objectType = typeof(Sprite); // Set the object fields type.

        if (createItemButton != null)
        {
            createItemButton.clickable.clicked += () =>
            {
                FoodItemData itemData = new FoodItemData(itemNameField.value, itemDescField.value, itemValueField.value, workingItemType, (RarityType)itemRarityField.value, (Sprite)itemIconField.value);
                CreateFoodItem(itemData);
            };
        }
    }
 public void BindElements()
 {
     m_BoneNameField  = this.Q <TextField>("BoneNameField");
     m_BoneDepthField = this.Q <IntegerField>("BoneDepthField");
     m_BoneNameField.OnValueChanged(BoneNameChanged);
     m_BoneDepthField.OnValueChanged(BoneDepthChanged);
 }
예제 #4
0
        public void CleanTest()
        {
            IntegerField target = new IntegerField();

            // Default test
            Assert.AreEqual(5, (int?)target.Clean("5"));
            Assert.AreEqual(-5, (int?)target.Clean("-5"));

            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean(null);
            }).WithMessage("This field is required.");
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("abc");
            }).WithMessage("Enter a whole number.");
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("4.1");
            }).WithMessage("Enter a whole number.");

            target.MinValue = (int?)5;
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("3");
            }).WithMessage("Ensure this value is greater than or equal to 5.");
            Assert.AreEqual(6, (int?)target.Clean("6"));

            target.MaxValue = (int?)24;
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("27");
            }).WithMessage("Ensure this value is less than or equal to 24.");
            Assert.AreEqual(23, (int?)target.Clean("23"));

            target.Required = false;
            Assert.IsNull(target.Clean(null));
            Assert.IsNull(target.Clean(""));
            Assert.IsNull(target.Clean(" "));
        }
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            var field = new UIntField
            {
                label = property.displayName,
                value = (uint)property.longValue
            };

            //Binding does not work on this custom UI Element field that we have created, so we need to use the change event
            field.RegisterValueChangedCallback(evt =>
            {
                field.value        = evt.newValue;
                property.longValue = evt.newValue;
                property.serializedObject.ApplyModifiedProperties();
            });

            // Create a surrogate integer field to detect and pass along external change events (non UI event) on the underlying serialized property.
            var surrogateField = new IntegerField();

            field.Add(surrogateField);
            surrogateField.style.display = DisplayStyle.None;
            surrogateField.bindingPath   = property.propertyPath;
            surrogateField.RegisterValueChangedCallback(evt =>
            {
                evt.StopImmediatePropagation();
                field.value = UIntField.ClampInput(property.longValue);
            });

            return(field);
        }
예제 #6
0
        public SliderIntControl(int value, int min, int max)
        {
            _slider = new SliderInt(min, max);
            _text   = new IntegerField();

            Setup(value);
        }
 public UnifiedField(IntegerField field)
 {
     Name = field.Name;
     NewValue = field.NewValue.ToString();
     OldValue = field.OldValue.ToString();
     ReferenceName = field.ReferenceName;
 }
예제 #8
0
        public static VisualElement CreateIntegerInput(string label, int minValue, int maxValue, Action <int> onValueChange, out Slider slider, out IntegerField field)
        {
            VisualElement container = new VisualElement();

            container.style.flexDirection = FlexDirection.Row;
            container.style.marginLeft    = container.style.marginRight = 5;

            var valueLabel = new Label(label);

            valueLabel.style.unityTextAlign = TextAnchor.MiddleLeft;
            container.Add(valueLabel);

            slider             = new Slider(minValue, maxValue);
            slider.style.width = 60;
            slider.RegisterCallback <ChangeEvent <float> >(e => onValueChange((int)e.newValue));
            slider.style.marginLeft = 5;

            field             = new IntegerField();
            field.style.width = 30;
            field.RegisterCallback <ChangeEvent <int> >(e => onValueChange(e.newValue));

            container.Add(SnapRightContainer(slider, field));

            return(container);
        }
예제 #9
0
            public ContentBox()
            {
                m_TextContainer = new VisualElement();
                m_TextContainer.AddToClassList("box-model-content-text-container");

                m_WidthTextField = new IntegerField();
                m_WidthTextField.AddToClassList("box-model-textfield");

                m_HeightTextField = new IntegerField();
                m_HeightTextField.AddToClassList("box-model-textfield");

                m_XLabel = new Label("x");

                m_TextContainer.Add(m_WidthTextField);
                m_TextContainer.Add(m_XLabel);
                m_TextContainer.Add(m_HeightTextField);

                m_WidthTextField.value  = 0;
                m_HeightTextField.value = 0;

                m_WidthTextField.RegisterValueChangedCallback(OnWidthChanged);
                m_HeightTextField.RegisterValueChangedCallback(OnHeightChanged);

                Add(m_TextContainer);

                // Sync styles values
                schedule.Execute(SyncValues).Every(100);
            }
예제 #10
0
        internal VisualElement CreateGUI(
            ValueChangedCallback valueChangedCallback,
            int fieldToDraw,
            string labelName,
            out VisualElement propertyFloatField,
            int indentLevel = 0)
        {
            var integerField = new IntegerField {
                value = fieldToDraw
            };

            if (valueChangedCallback != null)
            {
                integerField.RegisterValueChangedCallback(evt => { valueChangedCallback(evt.newValue); });
            }

            propertyFloatField = integerField;

            var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));

            defaultRow.Add(propertyFloatField);

            defaultRow.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyRow"));
            return(defaultRow);
        }
 public void BindElements()
 {
     m_BoneNameField  = this.Q <TextField>("BoneNameField");
     m_BoneDepthField = this.Q <IntegerField>("BoneDepthField");
     m_BoneNameField.RegisterValueChangedCallback(BoneNameChanged);
     m_BoneDepthField.RegisterValueChangedCallback(BoneDepthChanged);
 }
    }//generar la barra de botones de la ventana del editor

    private void GenerateSecondaryToolbar()
    {
        Toolbar l_secondaryToolbar = new Toolbar();

        Button l_generateRandomDungeonButton = new Button();

        l_generateRandomDungeonButton.text = "Generate Random Dungeon";
        l_generateRandomDungeonButton.clickable.clicked += () => GenerateRandomDungeon();
        l_secondaryToolbar.Add(l_generateRandomDungeonButton);

        IntegerField l_maxNumberOfRoomsIntField = new IntegerField();

        l_maxNumberOfRoomsIntField.tooltip = "Max Number of Rooms instantiated on the dungeon";
        l_maxNumberOfRoomsIntField.label   = "Max number of rooms";
        l_maxNumberOfRoomsIntField.RegisterValueChangedCallback(evt => m_numberOfRoomsToGenerate = evt.newValue);
        l_secondaryToolbar.Add(l_maxNumberOfRoomsIntField);

        IntegerField l_maxNumberOfFloorsField = new IntegerField();

        l_maxNumberOfFloorsField.tooltip = "Max Number of floors on the dungeon";
        l_maxNumberOfFloorsField.label   = "Max number of floors";
        l_maxNumberOfFloorsField.RegisterValueChangedCallback(evt => m_numberOfFloorsToGenerate = evt.newValue);
        l_secondaryToolbar.Add(l_maxNumberOfFloorsField);

        Button l_clearAllNodesOnGrapButton = new Button();

        l_clearAllNodesOnGrapButton.text = "Clear All";
        l_clearAllNodesOnGrapButton.clickable.clicked += () => ClearAllNodesOnGraph();
        l_secondaryToolbar.Add(l_clearAllNodesOnGrapButton);

        rootVisualElement.Add(l_secondaryToolbar);
    }//barra generacion aleatoria
        public IListElement()
        {
            Resources.Templates.ListElement.Clone(this);
            Resources.Templates.ListElementDefaultStyling.AddStyles(this);
            binding = this;

            m_Size = new IntegerField();
            m_Size.AddToClassList(UssClasses.ListElement.Size);
            m_Size.RegisterValueChangedCallback(CountChanged);
            m_Size.RegisterCallback <KeyDownEvent>(TrapKeys);
            m_Size.isDelayed = true;

            var toggle      = this.Q <Toggle>();
            var toggleInput = toggle.Q(className: UssClasses.Unity.ToggleInput);

            toggleInput.AddToClassList(UssClasses.ListElement.ToggleInput);
            toggle.Add(m_Size);

            m_AddItemButton = new Button(OnAddItem)
            {
                text = "+ Add Element"
            };
            m_AddItemButton.AddToClassList(UssClasses.ListElement.AddItemButton);

            m_ContentRoot       = new VisualElement();
            m_ContentRoot.name  = "properties-list-content";
            m_PaginationElement = new PaginationElement();
            Add(m_PaginationElement);
            Add(m_ContentRoot);
            Add(m_AddItemButton);
        }
예제 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Property"/> class.
        /// </summary>
        protected Property()
        {
            _raw_data = new byte[POIFSConstants.PROPERTY_SIZE];
            for (int i = 0; i < this._raw_data.Length; i++)
            {
                this._raw_data[i] = _default_fill;
            }
            _name_size     = new ShortField(_name_size_offset);
            _property_type =
                new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET);
            _node_color        = new ByteField(_node_color_offset);
            _previous_property = new IntegerField(_previous_property_offset,
                                                  _NO_INDEX, _raw_data);
            _next_property = new IntegerField(_next_property_offset,
                                              _NO_INDEX, _raw_data);
            _child_property = new IntegerField(_child_property_offset,
                                               _NO_INDEX, _raw_data);
            _storage_clsid = new ClassID(_raw_data, _storage_clsid_offset);
            _user_flags    = new IntegerField(_user_flags_offset, 0, _raw_data);
            _seconds_1     = new IntegerField(_seconds_1_offset, 0,
                                              _raw_data);
            _days_1    = new IntegerField(_days_1_offset, 0, _raw_data);
            _seconds_2 = new IntegerField(_seconds_2_offset, 0,
                                          _raw_data);
            _days_2      = new IntegerField(_days_2_offset, 0, _raw_data);
            _start_block = new IntegerField(_start_block_offset);
            _size        = new IntegerField(_size_offset, 0, _raw_data);
            _index       = _NO_INDEX;

            this.Name          = "";
            this.NextChild     = null;
            this.PreviousChild = null;
        }
 static void ClampEditingValue(ChangeEvent <int> evt, IntegerField field)
 {
     if (evt.newValue < 0)
     {
         field.SetValueWithoutNotify(0);
     }
 }
예제 #16
0
        private void OnEnable()
        {
#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
            string windowLayoutPath = "Packages/com.utj.profilerlogsplit/Editor/UI/UXML/ProfilerLogSplit.uxml";
#else
            string windowLayoutPath = "Packages/com.utj.profilerlogsplit/Editor/UI/UXML2018/ProfilerLogSplit.uxml";
#endif
            var tree          = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(windowLayoutPath);
            var visualElement = CloneTree(tree);
            this.rootVisualElement.Add(visualElement);

            this.FileNameLabel = this.rootVisualElement.Q <Label>("FileName");
            this.rootVisualElement.Q <Button>("SelFileBtn").clickable.clicked += OnClickFileSelectBtn;
            afterPrepareElement         = this.rootVisualElement.Q <VisualElement>("AfterAnalyze");
            afterPrepareElement.visible = false;
            afterPrepareElement.Q <Button>("SendProfilerBtn").clickable.clicked += OnClickSendToProfiler;

            afterPrepareElement.Q <Button>("NextBlockBtn").clickable.clicked += OnClickNextBtn;

            this.frameSlider   = afterPrepareElement.Q <MinMaxSlider>("ProfilerFrame");
            this.minFrame      = afterPrepareElement.Q <IntegerField>("ProfilerMinFrame");
            this.maxFrame      = afterPrepareElement.Q <IntegerField>("ProfilerMaxFrame");
            this.FileInfoLabel = afterPrepareElement.Q <Label>("Result");

            this.frameSlider.RegisterCallback <ChangeEvent <Vector2> >(OnChangeSlider);
            this.minFrame.RegisterCallback <ChangeEvent <int> >(OnChangeMinValue);
            this.maxFrame.RegisterCallback <ChangeEvent <int> >(OnChangeMaxValue);

            this.progressUI = new PrepareProgressUI();
        }
예제 #17
0
 /// <summary>
 /// Create a single instance initialized with default values
 /// </summary>
 public HeaderBlockWriter()
 {
     _data = new byte[POIFSConstants.BIG_BLOCK_SIZE];
     for (int i = 0; i < this._data.Length; i++)
     {
         this._data[i] = _default_value;
     }
     new LongField(HeaderBlockConstants._signature_offset, HeaderBlockConstants._signature, _data);
     new IntegerField(0x08, 0, _data);
     new IntegerField(0x0c, 0, _data);
     new IntegerField(0x10, 0, _data);
     new IntegerField(0x14, 0, _data);
     new ShortField(0x18, ( short )0x3b, ref _data);
     new ShortField(0x1a, ( short )0x3, ref _data);
     new ShortField(0x1c, ( short )-2, ref _data);
     new ShortField(0x1e, ( short )0x9, ref _data);
     new IntegerField(0x20, 0x6, _data);
     new IntegerField(0x24, 0, _data);
     new IntegerField(0x28, 0, _data);
     _bat_count      = new IntegerField(HeaderBlockConstants._bat_count_offset, 0, _data);
     _property_start = new IntegerField(HeaderBlockConstants._property_start_offset,
                                        POIFSConstants.END_OF_CHAIN,
                                        _data);
     new IntegerField(0x34, 0, _data);
     new IntegerField(0x38, 0x1000, _data);
     _sbat_start = new IntegerField(HeaderBlockConstants._sbat_start_offset,
                                    POIFSConstants.END_OF_CHAIN, _data);
     _sbat_block_count = new IntegerField(HeaderBlockConstants._sbat_block_count_offset, 0,
                                          _data);
     _xbat_start = new IntegerField(HeaderBlockConstants._xbat_start_offset,
                                    POIFSConstants.END_OF_CHAIN, _data);
     _xbat_count = new IntegerField(HeaderBlockConstants._xbat_count_offset, 0, _data);
 }
예제 #18
0
 public UnifiedField(IntegerField field)
 {
     Name          = field.Name;
     NewValue      = field.NewValue.ToString();
     OldValue      = field.OldValue.ToString();
     ReferenceName = field.ReferenceName;
 }
예제 #19
0
        protected override void DrawNode(ModuleGraphView graphView)
        {
            Debug.Log(Script.SceneIndex);
            var inputPort = graphView.GeneratePort <float>(this, Direction.Input, Port.Capacity.Multi);

            inputPort.portName = "Input";
            inputContainer.Add(inputPort);
            AddToClassList("action");

            var outputPort = graphView.GeneratePort <float>(this, Direction.Output);

            outputPort.portName = "Output";
            outputContainer.Add(outputPort);

            IntegerField intField = new IntegerField("Scene Index", 2);

            intField.value = Script.SceneIndex;
            intField.RegisterValueChangedCallback(evt =>
            {
                var temp = evt.newValue < 0 ? 0 : evt.newValue > 99 ? 99 : evt.newValue;
                intField.SetValueWithoutNotify(temp);
                Script.SceneIndex = temp;
                graphView.SetDirty();
            });

            extensionContainer.Add(intField);

            graphView.RefreshNode(this);
            graphView.AddElement(this);
        }
예제 #20
0
        private static IScriptCommand BuildBasicCommand(BasicCommand command)
        {
            switch (command.Name)
            {
            case "add":
                IField[] addFields = command.Fields.ToArray <IField>();
                return(new AddCommand(new Tuple(addFields)));

            case "take":
                IField[] takeFields = command.Fields.ToArray <IField>();
                return(new TakeCommand(new Schema(takeFields)));

            case "read":
                IField[] readFields = command.Fields.ToArray <IField>();
                return(new ReadCommand(new Schema(readFields)));

            case "wait":
                IntegerField waitField = (IntegerField)command.Fields[0];
                return(new WaitCommand(waitField));

            case "begin-repeat":
                IntegerField beginField = (IntegerField)command.Fields[0];
                return(new LoopStartCommand(beginField));

            case "end-repeat":
                return(new LoopEndCommand());
            }
            return(null);
        }
예제 #21
0
        public void TestReadFromBytes()
        {
            IntegerField field = new IntegerField(1);

            byte[] array = new byte[4];

            try
            {
                field.ReadFromBytes(array);
                Assert.Fail("should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            field = new IntegerField(0);
            for (int j = 0; j < _test_array.Length; j++)
            {
                array[0] = ( byte )(_test_array[j] % 256);
                array[1] = ( byte )((_test_array[j] >> 8) % 256);
                array[2] = ( byte )((_test_array[j] >> 16) % 256);
                array[3] = ( byte )((_test_array[j] >> 24) % 256);
                field.ReadFromBytes(array);
                Assert.AreEqual(_test_array[j], field.Value, "testing " + j);
            }
        }
        void LoadTemplate()
        {
            AddToClassList("timeField");
            m_FieldName = new Label();
            m_FieldName.AddToClassList("timeFieldNameLabel");
            Add(m_FieldName);
            var inputContainer = new VisualElement();

            inputContainer.AddToClassList("timeFieldInputContainer");
            Add(inputContainer);

            m_SecondsField = new FloatField("Seconds");
            m_SecondsField.AddToClassList("timeInput");
            m_SecondsField.RegisterValueChangedCallback(OnTimeInSecondsChanged);
            inputContainer.Add(m_SecondsField);

            m_FrameField = new IntegerField("Frame");
            m_FrameField.AddToClassList("timeInput");
            m_FrameField.RegisterValueChangedCallback(OnFrameChanged);
            inputContainer.Add(m_FrameField);

            SyncToViewModeSetting();

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);
        }
        public UdonArrayInspector(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;
            #if UNITY_2019_3_OR_NEWER
            _sizeField.RegisterValueChangedCallback((evt) =>
            #else
            _sizeField.OnValueChanged((evt) =>
            #endif
            {
                ResizeTo(evt.newValue);
            });
            resizeContainer.Add(_sizeField);
            Add(resizeContainer);

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

            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);

                    _scroller.contentContainer.Add(field);
                }

                _sizeField.value = values.Count();
            }
        }
예제 #24
0
        public void TestConstructors()
        {
            try
            {
                new IntegerField(-1);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            IntegerField field = new IntegerField(2);

            Assert.AreEqual(0, field.Value);
            try
            {
                new IntegerField(-1, 1);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            field = new IntegerField(2, 0x12345678);
            Assert.AreEqual(0x12345678, field.Value);
            byte[] array = new byte[6];

            try
            {
                new IntegerField(-1, 1, array);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            field = new IntegerField(2, 0x12345678, array);
            Assert.AreEqual(0x12345678, field.Value);
            Assert.AreEqual(( byte )0x78, array[2]);
            Assert.AreEqual(( byte )0x56, array[3]);
            Assert.AreEqual(( byte )0x34, array[4]);
            Assert.AreEqual(( byte )0x12, array[5]);
            array = new byte[5];
            try
            {
                new IntegerField(2, 5, array);
                Assert.Fail("should have gotten IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            for (int j = 0; j < _test_array.Length; j++)
            {
                array = new byte[4];
                new IntegerField(0, _test_array[j], array);
                Assert.AreEqual(_test_array[j], new IntegerField(0, array).Value);
            }
        }
        void AddField(Vector4 initialValue, int index, string subLabel)
        {
            var dummy = new VisualElement {
                name = "dummy"
            };
            var label = new Label(subLabel);

            dummy.Add(label);
            Add(dummy);
            var field = new IntegerField {
                userData = index, value = (int)initialValue[index]
            };
            var dragger = new FieldMouseDragger <int>(field);

            dragger.SetDragZone(label);
            field.Q("unity-text-input").RegisterCallback <KeyDownEvent>(evt =>
            {
                // Record Undo for input field edit
                if (m_UndoGroup == -1)
                {
                    m_UndoGroup = Undo.GetCurrentGroup();
                    m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
                }
                // Handle scaping input field edit
                if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
                {
                    Undo.RevertAllDownToGroup(m_UndoGroup);
                    m_UndoGroup = -1;
                    evt.StopPropagation();
                }
                // Dont record Undo again until input field is unfocused
                m_UndoGroup++;
                this.MarkDirtyRepaint();
            });
            // Called after KeyDownEvent
            field.RegisterValueChangedCallback(evt =>
            {
                // Only true when setting value via FieldMouseDragger
                // Undo recorded once per dragger release
                if (m_UndoGroup == -1)
                {
                    m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
                }
                var value = m_Get();
                if (value[index] != (float)evt.newValue)
                {
                    value[index] = (float)evt.newValue;
                    m_Set(value);
                    m_Node.Dirty(ModificationScope.Node);
                }
            });
            // Reset UndoGroup when done editing input field & update title
            field.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt =>
            {
                m_Node.owner.owner.isDirty = true;
                m_UndoGroup = -1;
            });
            Add(field);
        }
            private VisualElement CreateSampleItemInt(SampleItemInt item)
            {
                var field = new IntegerField(nameof(SampleItemInt.IntValue));

                field.value = item.IntValue;
                field.RegisterValueChangedCallback(e => item.IntValue = e.newValue);
                return(field);
            }
        private VisualElement CreateInt(IDictionary dictionary, string key)
        {
            var field = new IntegerField(key);

            field.value = (int)dictionary[key];
            field.RegisterValueChangedCallback(e => dictionary[key] = e.newValue);
            return(field);
        }
예제 #28
0
        private VisualElement CreateInt(IList list, int index)
        {
            var field = new IntegerField();

            field.value = (int)list[index];
            field.RegisterValueChangedCallback(e => list[index] = e.newValue);
            return(field);
        }
        /// <summary>
        /// Returns true if EntityViewModel instances are equal
        /// </summary>
        /// <param name="other">Instance of EntityViewModel to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(EntityViewModel other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     StringField == other.StringField ||
                     StringField != null &&
                     StringField.Equals(other.StringField)
                 ) &&
                 (
                     RelationIdField == other.RelationIdField ||
                     RelationIdField != null &&
                     RelationIdField.Equals(other.RelationIdField)
                 ) &&
                 (
                     DictionaryField == other.DictionaryField ||
                     DictionaryField != null &&
                     DictionaryField.Equals(other.DictionaryField)
                 ) &&
                 (
                     IntegerField == other.IntegerField ||
                     IntegerField != null &&
                     IntegerField.Equals(other.IntegerField)
                 ) &&
                 (
                     DoubleField == other.DoubleField ||
                     DoubleField != null &&
                     DoubleField.Equals(other.DoubleField)
                 ) &&
                 (
                     DateField == other.DateField ||
                     DateField != null &&
                     DateField.Equals(other.DateField)
                 ) &&
                 (
                     ExampleType == other.ExampleType ||
                     ExampleType != null &&
                     ExampleType.Equals(other.ExampleType)
                 ) &&
                 (
                     ExampleStatus == other.ExampleStatus ||
                     ExampleStatus != null &&
                     ExampleStatus.Equals(other.ExampleStatus)
                 ));
        }
예제 #30
0
    public void SetData(WidgetDataLaunchCommandElement data)
    {
        _widgetData = data;

        _nameLabel.text     = data.GameConsoleInvokable.DisplayName;
        _activeToggle.value = data.Active;
        _paramsContainer.Clear();

        int paramIndex = 0;

        foreach (IGameConsoleParameter param in data.GameConsoleInvokable.Parameters)
        {
            if (param.Type == typeof(bool))
            {
                var field = new Toggle();
                bool.TryParse(TryPopParam(), out bool val);
                field.value = val;
                field.RegisterValueChangedCallback((evt) => OnParameterModified());
                _paramsContainer.Add(field);
            }
            else if (param.Type == typeof(int))
            {
                var field = new IntegerField();
                int.TryParse(TryPopParam(), out int val);
                field.value = val;
                field.RegisterValueChangedCallback((evt) => OnParameterModified());
                _paramsContainer.Add(field);
            }
            else if (param.Type == typeof(float))
            {
                var field = new FloatField();
                float.TryParse(TryPopParam(), out float val);
                field.value = val;
                field.RegisterValueChangedCallback((evt) => OnParameterModified());
                _paramsContainer.Add(field);
            }
            else
            {
                var field = new TextField();
                field.value = TryPopParam();
                field.RegisterValueChangedCallback((evt) => OnParameterModified());
                _paramsContainer.Add(field);
            }
        }

        _nameLabel.SetEnabled(data.Active);
        foreach (var item in _paramsContainer.Children())
        {
            item.SetEnabled(data.Active);
        }

        OnParameterModified();

        string TryPopParam()
        {
            if (data.Parameters == null)
            {
                return(default);
        public override VisualElement Build()
        {
            var root = new Foldout {
                text = DisplayName
            };
            var majorField = new IntegerField
            {
                bindingPath = nameof(Version.Major),
                label       = ObjectNames.NicifyVariableName(nameof(Version.Major))
            };

            majorField.RegisterCallback <ChangeEvent <int>, IntegerField>(ClampEditingValue, majorField);
            majorField.RegisterValueChangedCallback(OnMajorChanged);
            root.Add(majorField);

            var minorField = new IntegerField
            {
                bindingPath = nameof(Version.Minor),
                label       = ObjectNames.NicifyVariableName(nameof(Version.Minor))
            };

            minorField.RegisterCallback <ChangeEvent <int>, IntegerField>(ClampEditingValue, minorField);
            minorField.RegisterValueChangedCallback(OnMinorChanged);
            root.Add(minorField);

            var usage = GetAttribute <SystemVersionUsageAttribute>();

            if (usage?.IncludeBuild ?? true)
            {
                var buildField = new IntegerField
                {
                    bindingPath = nameof(Version.Build),
                    label       = ObjectNames.NicifyVariableName(nameof(Version.Build))
                };
                buildField.RegisterCallback <ChangeEvent <int>, IntegerField>(ClampEditingValue, buildField);
                buildField.RegisterValueChangedCallback(OnBuildChanged);
                root.Add(buildField);
            }

            if (usage?.IncludeRevision ?? true)
            {
                var revisionField = new IntegerField
                {
                    bindingPath = nameof(Version.Revision),
                    label       = ObjectNames.NicifyVariableName(nameof(Version.Revision))
                };
                revisionField.RegisterCallback <ChangeEvent <int>, IntegerField>(ClampEditingValue, revisionField);
                revisionField.RegisterValueChangedCallback(OnRevisionChanged);
                root.Add(revisionField);
            }

            if (IsReadOnly)
            {
                root.contentContainer.SetEnabled(false);
            }

            return(root);
        }
예제 #32
0
        public void IdentifierNodeTest()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            Field<string> retriever = new IntegerField<string>(s => int.Parse(s));
            ParameterExpression arg = Expression.Parameter(typeof(string), "arg");

            ValueNode sut = new IdentifierNode<string>("identifier", retriever, arg, expectedLocation);

            Assert.AreEqual(TNode.IDENTIFIER, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("IDENTIFIER"));
            Assert.AreEqual(FieldValueType.INTEGER, sut.ValueType);
            Assert.IsInstanceOfType(sut.SubExpression, typeof(UnaryExpression));
            Assert.AreEqual(ExpressionType.Convert, sut.SubExpression.NodeType);
            Assert.AreEqual(typeof(long?), sut.SubExpression.Type);
            {
                Expression invokeExpr = ((UnaryExpression)sut.SubExpression).Operand;
                Assert.IsInstanceOfType(invokeExpr, typeof(InvocationExpression));
                Assert.AreEqual(ExpressionType.Invoke, invokeExpr.NodeType);
                Assert.AreEqual(arg, ((InvocationExpression)invokeExpr).Arguments[0]);
            }
        }