Beispiel #1
0
 public void BindValue(IDictionary <string, Object> values)
 {
     if (null != values && values.Count > 0)
     {
         RealText = Text;
         string          str   = @"\[#?%?(p{0,}/?\w){1,}%?#?\]";//@"\[#?%?(([\u4E00-\u9FFF]){0,}/?\w){1,}%?#?\]";
         Regex           regex = new Regex(str);
         MatchCollection mc    = regex.Matches(RealText);
         if (null != mc && mc.Count > 0)
         {
             foreach (Match m in mc)
             {
                 string key = m.Value.Remove(0, 1);
                 key = key.Remove(key.Length - 1, 1);
                 if (values.ContainsKey(key))
                 {
                     object value  = values[key];
                     string newStr = " ";
                     if (null != value)
                     {
                         newStr = value.ToString();
                     }
                     RealText = RealText.Replace(m.Value, newStr);
                 }
             }
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// 将变量绑定值
 /// </summary>
 /// <param name="values">将变量绑定值</param>
 public virtual void BindValue(IDictionary <string, Object> values)
 {
     if (null != values && values.Count > 0 && !string.IsNullOrEmpty(Var))
     {
         RealText = string.Format("[%{0}%]", Var);
         string          str   = @"\[#?%?(p{0,}/?\w){1,}%?#?\]";//@"\[#?%?(([\u4E00-\u9FFF]){0,}/?\w){1,}%?#?\]";
         Regex           regex = new Regex(str);
         MatchCollection mc    = regex.Matches(RealText);
         if (null != mc && mc.Count > 0)
         {
             foreach (Match m in mc)
             {
                 string key = m.Value.Remove(0, 1);
                 key = key.Remove(key.Length - 1, 1);
                 if (values.ContainsKey(key))
                 {
                     string newStr = values[key] as string;
                     if (string.IsNullOrEmpty(newStr))
                     {
                         newStr = " ";
                     }
                     RealText = RealText.Replace(m.Value, newStr);
                 }
             }
         }
     }
 }
        public override void HandleInput(IReadOnlyList <int> lastKeysPressed)
        {
            if (Input.IsKeyDown(InputKey.LeftControl) && Input.IsKeyPressed(InputKey.V))
            {
                return;
            }

            if (lastKeysPressed.Count > 0)
            {
                for (int i = 0; i < lastKeysPressed.Count; i++)
                {
                    int key = lastKeysPressed[i];
                    if (Enum.IsDefined(typeof(KeyCodes), key))
                    {
                        if (SettingType == SettingType.Float)
                        {
                            //Handle input for float types
                            if (key == (int)KeyCodes.Decimal)
                            {
                                if (RealText.Count('.') >= 1)
                                {
                                    continue;
                                }
                            }
                        }
                        else if (SettingType == SettingType.Int)
                        {
                            //Handle input for int types.
                            if (key == (int)KeyCodes.Decimal)
                            {
                                continue;
                            }
                        }
                        base.HandleInput(lastKeysPressed);
                        float value;
                        float.TryParse(RealText, out value);
                        float newVal = value;
                        if (value > MaxValue)
                        {
                            newVal = MaxValue;
                        }
                        else if (value < MinValue)
                        {
                            newVal = MinValue;
                        }
                        if (newVal != value)
                        {
                            string format = SettingType == SettingType.Int ? "0" : "0.00";
                            RealText = newVal.ToString(format);
                        }
                    }
                }
            }
        }
 protected override void OnCharacterEntered(char character)
 {
     if (character == '\b' && RealText.Length > 0)
     {
         RealText = RealText.Substring(0, RealText.Length - 1);
     }
     else if ((RealText.Length < MaxLength) && (char.IsLetter(character) || char.IsDigit(character) || (character == '_')))
     {
         RealText += character;
         Text     += IsHidden ? '*' : character;
         CaretPosition++;
     }
 }
Beispiel #5
0
 protected override void OnCharacterEntered(char character)
 {
     if (character == '\b' && CaretPosition > 0)
     {
         int cp = CaretPosition;
         RealText      = RealText.Substring(0, CaretPosition - 1) + RealText.Substring(CaretPosition);
         CaretPosition = cp - 1;
     }
     else if (character != '\b' && character != '\t' && character != '\n')
     {
         if (RealText == null)
         {
             RealText = "";
         }
         RealText = RealText.Substring(0, CaretPosition) + character + RealText.Substring(CaretPosition);
         CaretPosition++;
     }
 }
Beispiel #6
0
 /// <summary>
 /// 字段绑定值
 /// </summary>
 /// <param name="values"></param>
 public override void BindValue(IDictionary <string, object> values)
 {
     if (null != values && values.Count > 0)
     {
         RealText = Text;
         string          str   = @"\[#?%?(p{0,}/?\w){1,}%?#?\]";
         Regex           regex = new Regex(str);
         MatchCollection mc    = regex.Matches(RealText);
         if (null != mc && mc.Count > 0)
         {
             foreach (Match m in mc)
             {
                 string key = m.Value.Remove(0, 1);
                 key = key.Remove(key.Length - 1, 1);
                 if (values.ContainsKey(key))
                 {
                     string newStr = string.Empty;
                     object o      = values[key];
                     if (null != o)
                     {
                         if (string.IsNullOrEmpty(StrFormate))
                         {
                             newStr = o.ToString();
                         }
                         else
                         {
                             newStr = FormateToString(o);
                         }
                     }
                     if (newStr == string.Empty)
                     {
                         newStr = " ";
                     }
                     RealText = RealText.Replace(m.Value, newStr);
                 }
             }
         }
     }
 }
Beispiel #7
0
        protected override bool OnKeyPressed(Microsoft.Xna.Framework.Input.Keys keyCode)
        {
            switch (keyCode)
            {
            case Microsoft.Xna.Framework.Input.Keys.Left:
                CaretPosition = CaretPosition > 0 ? CaretPosition - 1 : 0;
                return(true);

            case Microsoft.Xna.Framework.Input.Keys.Right:
                CaretPosition = CaretPosition < RealText.Length ? CaretPosition + 1 : CaretPosition;
                return(true);

            case Microsoft.Xna.Framework.Input.Keys.Delete:
                if (CaretPosition < RealText.Length)
                {
                    RealText = RealText.Substring(0, CaretPosition) + RealText.Substring(CaretPosition + 1);
                }
                return(true);

            default:
                return(false);
            }
        }
        public override void HandleInput(IReadOnlyList <int> lastKeysPressed)
        {
            if (Input.IsKeyDown(InputKey.LeftControl) && Input.IsKeyPressed(InputKey.V))
            {
                base.HandleInput(lastKeysPressed);
                return;
            }

            if (lastKeysPressed.Count > 0)
            {
                foreach (var key in lastKeysPressed)
                {
                    if (SettingType == SettingType.String)
                    {
                        base.HandleInput(lastKeysPressed);
                    }
                    else if (Enum.IsDefined(typeof(KeyCodes), key))
                    {
                        if (key == (int)KeyCodes.Minus)
                        {
                            if (_editableWidget?.SelectedTextBegin != 0)
                            {
                                continue;
                            }
                        }
                        else if (SettingType == SettingType.Float)
                        {
                            // Handle input for float types
                            if (key == (int)KeyCodes.Decimal)
                            {
                                if (RealText.Any(ch => ch == '.'))
                                {
                                    continue;
                                }
                            }
                        }
                        else if (SettingType == SettingType.Int)
                        {
                            // Handle input for int types.
                            if (key == (int)KeyCodes.Decimal)
                            {
                                continue;
                            }
                        }
                        base.HandleInput(lastKeysPressed);

                        if (SettingType == SettingType.Float)
                        {
                            if (float.TryParse(RealText, out var value))
                            {
                                var newVal = value;
                                if (value > MaxValue)
                                {
                                    newVal = MaxValue;
                                }
                                else if (value < MinValue)
                                {
                                    newVal = MinValue;
                                }
                                if (newVal != value)
                                {
                                    var format = SettingType == SettingType.Int ? "0" : "0.00";
                                    RealText = newVal.ToString(format);
                                    _editableWidget?.SetCursorPosition(0, true);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                base.HandleInput(lastKeysPressed);
            }
        }