Exemple #1
0
		public override void initialize( Table table, Skin skin )
		{
			var button = new TextButton( _name, skin );
			button.onClicked += onButtonClicked;

			// we could have zero or 1 param
			var parameters = ( _memberInfo as MethodInfo ).GetParameters();
			if( parameters.Length == 0 )
			{
				table.add( button );
				return;
			}

			var parameter = parameters[0];
			_parameterType = parameter.ParameterType;

			_textField = new TextField( _parameterType.GetTypeInfo().IsValueType ? Activator.CreateInstance( _parameterType ).ToString() : "", skin );
			_textField.shouldIgnoreTextUpdatesWhileFocused = false;

			// add a filter for float/int
			if( _parameterType == typeof( float ) )
				_textField.setTextFieldFilter( new FloatFilter() );
			if( _parameterType == typeof( int ) )
				_textField.setTextFieldFilter( new DigitsOnlyFilter() );
			if( _parameterType == typeof( bool ) )
				_textField.setTextFieldFilter( new BoolFilter() );

			table.add( button );
			table.add( _textField ).setMaxWidth( 70 );
		}
Exemple #2
0
 public bool acceptChar( TextField textField, char c )
 {
     // only allow one .
     if( c == '.' )
         return !textField.getText().Contains( "." );
     return Char.IsDigit( c ) || c == '-';
 }
Exemple #3
0
        public bool acceptChar( TextField textField, char c )
        {
            if( c == 't' || c == 'T' )
                textField.setTextForced( "true" );

            if( c == 'f' || c == 'F' )
                textField.setTextForced( "false" );

            return false;
        }
Exemple #4
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            var label = CreateNameLabel(table, skin, leftCellWidth);

            _textField = new UI.TextField(GetValue <string>(), skin);
            _textField.SetTextFieldFilter(new FloatFilter());
            _textField.OnTextChanged += (field, str) => { SetValue(str); };

            table.Add(label);
            table.Add(_textField).SetMaxWidth(70);
        }
Exemple #5
0
		public override void initialize( Table table, Skin skin )
		{
			var label = createNameLabel( table, skin );
			_textField = new TextField( getValue<string>(), skin );
			_textField.setTextFieldFilter( new FloatFilter() );
			_textField.onTextChanged += ( field, str ) =>
			{
				setValue( str );
			};

			table.add( label );
			table.add( _textField ).setMaxWidth( 70 );
		}
Exemple #6
0
		void setupTextField( Table table, Skin skin )
		{
			var label = createNameLabel( table, skin );
			_textField = new TextField( getValue<float>().ToString(), skin );
			_textField.setTextFieldFilter( new FloatFilter() );
			_textField.onTextChanged += ( field, str ) =>
			{
				float newValue;
				if( float.TryParse( str, out newValue ) )
					setValue( newValue );
			};

			table.add( label );
			table.add( _textField ).setMaxWidth( 70 );
		}
Exemple #7
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            var value = GetValue <Vector2>();
            var label = CreateNameLabel(table, skin, leftCellWidth);

            var labelX = new Label("x", skin);

            _textFieldX = new UI.TextField(value.X.ToString(CultureInfo.InvariantCulture), skin);
            _textFieldX.SetTextFieldFilter(new FloatFilter()).SetPreferredWidth(50);
            _textFieldX.OnTextChanged += (field, str) =>
            {
                float newX;
                if (float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out newX))
                {
                    var newValue = GetValue <Vector2>();
                    newValue.X = newX;
                    SetValue(newValue);
                }
            };

            var labelY = new Label("y", skin);

            _textFieldY = new UI.TextField(value.Y.ToString(CultureInfo.InvariantCulture), skin);
            _textFieldY.SetTextFieldFilter(new FloatFilter()).SetPreferredWidth(50);
            _textFieldY.OnTextChanged += (field, str) =>
            {
                float newY;
                if (float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out newY))
                {
                    var newValue = GetValue <Vector2>();
                    newValue.Y = newY;
                    SetValue(newValue);
                }
            };

            var hBox = new HorizontalGroup(5);

            hBox.AddElement(labelX);
            hBox.AddElement(_textFieldX);
            hBox.AddElement(labelY);
            hBox.AddElement(_textFieldY);

            table.Add(label);
            table.Add(hBox);
        }
Exemple #8
0
        void SetupTextField(Table table, Skin skin, float leftCellWidth)
        {
            var label = CreateNameLabel(table, skin, leftCellWidth);

            _textField = new UI.TextField(GetValue <float>().ToString(CultureInfo.InvariantCulture), skin);
            _textField.SetTextFieldFilter(new FloatFilter());
            _textField.OnTextChanged += (field, str) =>
            {
                float newValue;
                if (float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out newValue))
                {
                    SetValue(newValue);
                }
            };

            table.Add(label);
            table.Add(_textField).SetMaxWidth(70);
        }
Exemple #9
0
        void SetupTextField(Table table, Skin skin, float leftCellWidth)
        {
            var label = CreateNameLabel(table, skin, leftCellWidth);

            _textField = new UI.TextField(GetValue <byte>().ToString(), skin);
            _textField.SetTextFieldFilter(new FloatFilter());
            _textField.OnTextChanged += (field, str) =>
            {
                byte newValue;
                if (byte.TryParse(str, out newValue))
                {
                    SetValue(newValue);
                }
            };

            table.Add(label);
            table.Add(_textField).SetMaxWidth(70);
        }
Exemple #10
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            var button = new TextButton(_name, skin);

            button.OnClicked += OnButtonClicked;

            // we could have zero or 1 param
            var parameters = (_memberInfo as MethodInfo).GetParameters();

            if (parameters.Length == 0)
            {
                table.Add(button);
                return;
            }

            var parameter = parameters[0];

            _parameterType = parameter.ParameterType;

            _textField =
                new UI.TextField(
                    _parameterType.GetTypeInfo().IsValueType ? Activator.CreateInstance(_parameterType).ToString() : "",
                    skin);
            _textField.ShouldIgnoreTextUpdatesWhileFocused = false;

            // add a filter for float/int
            if (_parameterType == typeof(float))
            {
                _textField.SetTextFieldFilter(new FloatFilter());
            }
            if (_parameterType == typeof(int))
            {
                _textField.SetTextFieldFilter(new DigitsOnlyFilter());
            }
            if (_parameterType == typeof(bool))
            {
                _textField.SetTextFieldFilter(new BoolFilter());
            }

            table.Add(button);
            table.Add(_textField).SetMaxWidth(70);
        }
Exemple #11
0
		public override void initialize( Table table, Skin skin )
		{
			var value = getValue<Vector2>();
			var label = createNameLabel( table, skin );

			var labelX = new Label( "x", skin );
			_textFieldX = new TextField( value.X.ToString(), skin );
			_textFieldX.setTextFieldFilter( new FloatFilter() ).setPreferredWidth( 50 );
			_textFieldX.onTextChanged += ( field, str ) =>
			{
				float newX;
				if( float.TryParse( str, out newX ) )
				{
					var newValue = getValue<Vector2>();
					newValue.X = newX;
					setValue( newValue );
				}
			};

			var labelY = new Label( "y", skin );
			_textFieldY = new TextField( value.Y.ToString(), skin );
			_textFieldY.setTextFieldFilter( new FloatFilter() ).setPreferredWidth( 50 );
			_textFieldY.onTextChanged += ( field, str ) =>
			{
				float newY;
				if( float.TryParse( str, out newY ) )
				{
					var newValue = getValue<Vector2>();
					newValue.Y = newY;
					setValue( newValue );
				}
			};

			var hBox = new HorizontalGroup( 5 );
			hBox.addElement( labelX );
			hBox.addElement( _textFieldX );
			hBox.addElement( labelY );
			hBox.addElement( _textFieldY );

			table.add( label );
			table.add( hBox );
		}
Exemple #12
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            var value = GetValue <Direction>();
            var label = CreateNameLabel(table, skin, leftCellWidth);

            _selectBox = new SelectBox <string>(skin);
            //_selectBox.SetWidth(50);

            _textField = new UI.TextField(value.Value.ToString(CultureInfo.InvariantCulture), skin);
            _textField.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(50);
            _textField.OnTextChanged += (field, str) =>
            {
                int input;
                if (int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out input))
                {
                    Direction newValue = new Direction(input);
                    SetValue(newValue);
                }
            };

            var directions = new List <string>()
            {
                "S", "SE", "E", "NE", "N", "NW", "W", "SW"
            };

            _selectBox.SetItems(directions);

            _selectBox.OnChanged += selectedItem => { SetValue((Direction)directions.IndexOf(selectedItem)); };

            var hBox = new HorizontalGroup(5);

            hBox.AddElement(_selectBox);
            hBox.AddElement(_textField);

            table.Add(label);
            table.Add(hBox);
        }
Exemple #13
0
 public bool acceptChar( TextField textField, char c )
 {
     return Char.IsDigit( c ) || c == '-';
 }
Exemple #14
0
        TextField findNextTextField( List<Element> elements, TextField best, Vector2 bestCoords, Vector2 currentCoords, bool up )
        {
            bestCoords = Vector2.Zero;
            for( int i = 0, n = elements.Count; i < n; i++ )
            {
                var element = elements[i];
                if( element == this )
                    continue;

                if( element is TextField )
                {
                    var textField = (TextField)element;
                    if( textField.isDisabled() || !textField.focusTraversal )
                        continue;

                    var elementCoords = element.getParent().localToStageCoordinates( new Vector2( element.getX(), element.getY() ) );
                    if( ( elementCoords.Y < currentCoords.Y || ( elementCoords.Y == currentCoords.Y && elementCoords.X > currentCoords.X ) ) ^ up )
                    {
                        if( best == null
                            || ( elementCoords.Y > bestCoords.Y || ( elementCoords.Y == bestCoords.Y && elementCoords.X < bestCoords.X ) ) ^ up )
                        {
                            best = (TextField)element;
                            bestCoords = elementCoords;
                        }
                    }
                }
                else if( element is Group )
                {
                    best = findNextTextField( ( (Group)element ).getChildren(), best, bestCoords, currentCoords, up );
                }
            }

            return best;
        }
Exemple #15
0
		public override void initialize( Table table, Skin skin )
		{
			var value = getValue<Color>();
			var label = createNameLabel( table, skin );

			var labelR = new Label( "r", skin );
			_textFieldR = new TextField( value.R.ToString(), skin );
			_textFieldR.setMaxLength( 3 );
			_textFieldR.setTextFieldFilter( new DigitsOnlyFilter() ).setPreferredWidth( 28 );
			_textFieldR.onTextChanged += ( field, str ) =>
			{
				int newR;
				if( int.TryParse( str, out newR ) )
				{
					var newValue = getValue<Color>();
					newValue.R = (byte)newR;
					setValue( newValue );
				}
			};

			var labelG = new Label( "g", skin );
			_textFieldG = new TextField( value.G.ToString(), skin );
			_textFieldG.setMaxLength( 3 );
			_textFieldG.setTextFieldFilter( new DigitsOnlyFilter() ).setPreferredWidth( 28 );
			_textFieldG.onTextChanged += ( field, str ) =>
			{
				int newG;
				if( int.TryParse( str, out newG ) )
				{
					var newValue = getValue<Color>();
					newValue.G = (byte)newG;
					setValue( newValue );
				}
			};

			var labelB = new Label( "b", skin );
			_textFieldB = new TextField( value.B.ToString(), skin );
			_textFieldB.setMaxLength( 3 );
			_textFieldB.setTextFieldFilter( new DigitsOnlyFilter() ).setPreferredWidth( 28 );
			_textFieldB.onTextChanged += ( field, str ) =>
			{
				int newB;
				if( int.TryParse( str, out newB ) )
				{
					var newValue = getValue<Color>();
					newValue.B = (byte)newB;
					setValue( newValue );
				}
			};

			var labelA = new Label( "a", skin );
			_textFieldA = new TextField( value.A.ToString(), skin );
			_textFieldA.setMaxLength( 3 );
			_textFieldA.setTextFieldFilter( new DigitsOnlyFilter() ).setPreferredWidth( 28 );
			_textFieldA.onTextChanged += ( field, str ) =>
			{
				int newA;
				if( int.TryParse( str, out newA ) )
				{
					var newValue = getValue<Color>();
					newValue.A = (byte)newA;
					setValue( newValue );
				}
			};

			var hBox = new HorizontalGroup( 2 );
			hBox.addElement( labelR );
			hBox.addElement( _textFieldR );
			hBox.addElement( labelG );
			hBox.addElement( _textFieldG );
			hBox.addElement( labelB );
			hBox.addElement( _textFieldB );
			hBox.addElement( labelA );
			hBox.addElement( _textFieldA );

			table.add( label );
			table.add( hBox );
		}
Exemple #16
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            var value = GetValue <Color>();
            var label = CreateNameLabel(table, skin, leftCellWidth);

            var labelR = new Label("r", skin);

            _textFieldR = new UI.TextField(value.R.ToString(), skin);
            _textFieldR.SetMaxLength(3);
            _textFieldR.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(28);
            _textFieldR.OnTextChanged += (field, str) =>
            {
                int newR;
                if (int.TryParse(str, out newR))
                {
                    var newValue = GetValue <Color>();
                    newValue.R = (byte)newR;
                    SetValue(newValue);
                }
            };

            var labelG = new Label("g", skin);

            _textFieldG = new UI.TextField(value.G.ToString(), skin);
            _textFieldG.SetMaxLength(3);
            _textFieldG.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(28);
            _textFieldG.OnTextChanged += (field, str) =>
            {
                int newG;
                if (int.TryParse(str, out newG))
                {
                    var newValue = GetValue <Color>();
                    newValue.G = (byte)newG;
                    SetValue(newValue);
                }
            };

            var labelB = new Label("b", skin);

            _textFieldB = new UI.TextField(value.B.ToString(), skin);
            _textFieldB.SetMaxLength(3);
            _textFieldB.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(28);
            _textFieldB.OnTextChanged += (field, str) =>
            {
                int newB;
                if (int.TryParse(str, out newB))
                {
                    var newValue = GetValue <Color>();
                    newValue.B = (byte)newB;
                    SetValue(newValue);
                }
            };

            var labelA = new Label("a", skin);

            _textFieldA = new UI.TextField(value.A.ToString(), skin);
            _textFieldA.SetMaxLength(3);
            _textFieldA.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(28);
            _textFieldA.OnTextChanged += (field, str) =>
            {
                int newA;
                if (int.TryParse(str, out newA))
                {
                    var newValue = GetValue <Color>();
                    newValue.A = (byte)newA;
                    SetValue(newValue);
                }
            };

            var hBox = new HorizontalGroup(2);

            hBox.AddElement(labelR);
            hBox.AddElement(_textFieldR);
            hBox.AddElement(labelG);
            hBox.AddElement(_textFieldG);
            hBox.AddElement(labelB);
            hBox.AddElement(_textFieldB);
            hBox.AddElement(labelA);
            hBox.AddElement(_textFieldA);

            table.Add(label);
            table.Add(hBox);
        }
Exemple #17
0
 public bool acceptChar(TextField textField, char c)
 {
     return(Char.IsDigit(c) || c == '-');
 }