예제 #1
0
        /// <summary>
        /// Simple TextBox.
        /// </summary>
        /// <param name="pos">LeftBottom <see cref="UIelement.pos"/>.</param>
        /// <param name="sizeX">Horizontal size (min = 30 pxl). The height is fixed to 24 pxl.</param>
        /// <param name="key">Unique <see cref="UIconfig.key"/></param>
        /// <param name="defaultValue">Default string value</param>
        /// <param name="accept">Which type of text you want to <see cref="Accept"/></param>
        public OpTextBox(Vector2 pos, float sizeX, string key, string defaultValue = "TEXT", Accept accept = Accept.StringASCII) : base(pos, new Vector2(30f, 24f), key, defaultValue)
        {
            this._size       = new Vector2(Mathf.Max(IsUpdown ? 40f : 30f, sizeX), IsUpdown ? 30f : 24f);
            this.description = InternalTranslator.Translate("Click and Type text");

            this.accept       = accept;
            this._value       = defaultValue;
            this._lastValue   = defaultValue;
            this.defaultValue = this.value;
            this.maxLength    = Mathf.FloorToInt((size.x - 20f) / 6f);
            if (this.accept == Accept.Float || this.accept == Accept.Int)
            {
                this.allowSpace = float.Parse(defaultValue) < 0f;
            }
            else
            {
                this.allowSpace = defaultValue.Contains(" ");
            }
            this.password  = false;
            this.mouseDown = false;

            if (!_init)
            {
                return;
            }

            //this.keyboardOn = false;
            this.colorEdge = Menu.Menu.MenuRGB(Menu.Menu.MenuColors.MediumGrey);
            this.colorText = Menu.Menu.MenuRGB(Menu.Menu.MenuColors.MediumGrey);
            this.colorFill = Color.black;
            this.rect      = new DyeableRect(menu, owner, this.pos, this.size, true)
            {
                fillAlpha = 0.5f
            };
            this.subObjects.Add(this.rect);

            this.label = new MenuLabel(menu, owner, defaultValue, this.pos + new Vector2(5f - this._size.x * 0.5f, IsUpdown ? 13f : 10f), new Vector2(this._size.x, 20f), false);
            this.label.label.alignment = FLabelAlignment.Left;
            this.label.label.SetAnchor(0f, 1f);
            this.label.label.color = this.colorText;
            //this.label.label.SetPosition(new Vector2(5f, 3f) - (this._size * 0.5f));
            this.subObjects.Add(this.label);

            this.cursor = new FCursor();
            cursor.SetPosition(LabelTest.GetWidth(value, false) + LabelTest.CharMean(false), this.size.y * 0.5f - 7f);
            this.myContainer.AddChild(this.cursor);
        }
예제 #2
0
        public override void Update(float dt)
        {
            this.col = this.bumpBehav.col;
            base.Update(dt);
            this.bumpBehav.col = this.col;
            if (disabled)
            {
                return;
            }

            if (KeyboardOn)
            {
                cursor.alpha = Mathf.Clamp(cursorAlpha, 0f, 1f);
                cursorAlpha -= 0.05f;
                if (cursorAlpha < -0.5f)
                {
                    cursorAlpha = 2f;
                }

                //input spotted! ->cursorAlpha = 2.5f;
                foreach (char c in Input.inputString)
                {
                    //Debug.Log(string.Concat("input: ", c));
                    if (c == '\b')
                    {
                        cursorAlpha = 2.5f; this.bumpBehav.flash = 2.5f;
                        if (this.value.Length > 0)
                        {
                            this._value = this.value.Substring(0, this.value.Length - 1);
                            if (!_soundFilled)
                            {
                                _soundFill += 12;
                                menu.PlaySound(SoundID.MENY_Already_Selected_MultipleChoice_Clicked);
                            }
                            OnChange();
                        }
                        break;
                    }
                    else if ((c == '\n') || (c == '\r')) // enter/return
                    {
                        KeyboardOn = false;
                        menu.PlaySound(SoundID.MENU_Checkbox_Check);
                        break;
                    }
                    else
                    {
                        cursorAlpha          = 2.5f;
                        this.bumpBehav.flash = 2.5f;
                        this.value          += c;
                    }
                }
            }
            else
            {
                cursorAlpha = 0f;
            }
            if (Input.GetMouseButton(0) && !mouseDown)
            {
                if (this is OpUpdown ud && ud.mouseOverArrow)
                {
                    return;
                }
                mouseDown = true;
                if (MouseOver && !KeyboardOn)
                { //Turn on
                    menu.PlaySound(SoundID.MENU_Button_Select_Gamepad_Or_Keyboard);
                    KeyboardOn            = true;
                    this.cursor.isVisible = true;
                    this.cursorAlpha      = 1f;
                    cursor.SetPosition(LabelTest.GetWidth(this.label.text, false) + LabelTest.CharMean(false), this.size.y * 0.5f - 7f);
                }
                else if (!MouseOver && KeyboardOn)
                { //Shutdown
                    KeyboardOn = false;
                    menu.PlaySound(SoundID.MENU_Checkbox_Uncheck);
                }
            }
            else if (!Input.GetMouseButton(0))
            {
                mouseDown = false;
            }
        }