Esempio n. 1
0
        /// <summary>
        /// Set new Controller number for this OpKeyBinder. See also <seealso cref="GetControllerForPlayer(int)"/>
        /// </summary>
        /// <param name="controller">New <see cref="BindController"/></param>
        public void SetController(BindController controller)
        {
            // if (this.bind == controller) { return; }
            string newValue = ChangeBind(this.value, this.bind, controller);

            this.bind  = controller;
            this.value = newValue;
        }
Esempio n. 2
0
        private static string ChangeBind(string oldKey, BindController oldBind, BindController newBind)
        {
            if (!IsJoystick(oldKey))
            {
                return(oldKey);
            }
            string btn = oldKey.Substring(oldBind != BindController.AnyController ? 9 : 8);
            int    b   = (int)newBind;

            return("Joystick" + (newBind != BindController.AnyController ? b.ToString() : "") + btn);
        }
Esempio n. 3
0
 public OpKeyBinder(Vector2 pos, Vector2 size, PartialityMod mod, string key, string defaultKey, bool collisionCheck = true, BindController ctrlerNo = BindController.AnyController)
     : this(pos, size, mod.ModID, key, defaultKey, collisionCheck, ctrlerNo)
 {
 }
Esempio n. 4
0
        public override void Update(float dt)
        {
            base.Update(dt);
            if (disabled)
            {
                return;
            }

            if (this.MouseOver && Input.GetMouseButton(0))
            {
                this.held = true;
            }

            this.lastAnyKeyDown = this.anyKeyDown;
            this.anyKeyDown     = Input.anyKey;

            if (this.held)
            {
                if (IsJoystick(this.value) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
                {
                    bool flag = false; BindController newBind = BindController.AnyController;
                    if (Input.GetKey("`") || Input.GetKey("0") || Input.GetKey(KeyCode.Escape))
                    {
                        flag = true; newBind = BindController.AnyController;
                    }
                    else if (Input.GetKey("1"))
                    {
                        flag = true; newBind = BindController.Controller1;
                    }
                    else if (Input.GetKey("2"))
                    {
                        flag = true; newBind = BindController.Controller2;
                    }
                    else if (Input.GetKey("3"))
                    {
                        flag = true; newBind = BindController.Controller3;
                    }
                    else if (Input.GetKey("4"))
                    {
                        flag = true; newBind = BindController.Controller4;
                    }
                    if (!flag)
                    {
                        return;
                    }
                    if (this.bind == newBind)
                    {
                        menu.PlaySound(SoundID.MENU_Error_Ping); this.held = false; return;
                    }
                    this.SetController(newBind);
                    this.held = false;
                    return;
                }
                if (!this.lastAnyKeyDown && this.anyKeyDown)
                {
                    if (Input.GetKey(KeyCode.Escape))
                    {
                        this.value = none; this.held = false; return;
                    }
                    foreach (object obj in Enum.GetValues(typeof(KeyCode)))
                    {
                        KeyCode keyCode = (KeyCode)((int)obj);
                        if (Input.GetKey(keyCode))
                        {
                            string text = keyCode.ToString();
                            if (text.Length > 4 && text.Substring(0, 5) == "Mouse")
                            {
                                if (!this.MouseOver)
                                {
                                    menu.PlaySound(SoundID.MENU_Error_Ping);
                                    this.held = false;
                                }
                                return;
                            }
                            if (this.value != text)
                            {
                                if (IsJoystick(text))
                                {
                                    if (this.bind != BindController.AnyController)
                                    {
                                        int b = (int)this.bind;
                                        text = text.Substring(0, 8) + b.ToString() + text.Substring(8);
                                    }
                                }

                                this.value = text;
                                this.held  = false;
                            }
                            break;
                        }
                    }
                }
            }
            else if (!this.held && this.MouseOver && Input.GetMouseButton(0))
            {
                this.held = true;
                menu.PlaySound(SoundID.MENU_Button_Standard_Button_Pressed);
                this.label.label.text = "?";
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Simple Key Binder. Value is the <see cref="KeyCode"/> in string form.
        /// </summary>
        /// <param name="pos">LeftBottom Position of this UI</param>
        /// <param name="size">Size; minimum size is 30x30.</param>
        /// <param name="modID">Your <see cref="PartialityMod.ModID"/></param>
        /// <param name="key">Unique <see cref="UIconfig.key"/></param>
        /// <param name="defaultKey">Default <see cref="KeyCode"/> name. Set to empty to bind to <see cref="KeyCode.None"/> in default.</param>
        /// <param name="collisionCheck">Whether you will check the key is colliding with other <see cref="OpKeyBinder"/> or not</param>
        /// <param name="ctrlerNo">Which Controller this <see cref="OpKeyBinder"/> can bind</param>
        /// <exception cref="ElementFormatException">Thrown when defaultKey is null or empty</exception>
        public OpKeyBinder(Vector2 pos, Vector2 size, string modID, string key, string defaultKey, bool collisionCheck = true, BindController ctrlerNo = BindController.AnyController) : base(pos, size, key, defaultKey)
        {
            // if (string.IsNullOrEmpty(defaultKey)) { throw new ElementFormatException(this, "OpKeyBinderNull: defaultKey for this keyBinder is null.", key); }
            if (string.IsNullOrEmpty(defaultKey))
            {
                this._value = none;
            }
            this.controlKey     = !this.cosmetic ? string.Concat(modID, "_", key) : "_";
            this.modID          = modID;
            this._size          = new Vector2(Mathf.Max(30f, size.x), Mathf.Max(30f, size.y));
            this.collisionCheck = !this.cosmetic && collisionCheck;
            this.bind           = ctrlerNo;
            this.defaultValue   = this.value;

            if (!_init)
            {
                return;
            }
            this.colorEdge = Menu.Menu.MenuRGB(Menu.Menu.MenuColors.MediumGrey);
            this.colorFill = Color.black;
            this.Initalize(defaultKey);
        }
Esempio n. 6
0
        /// <summary>
        /// Simple Key Binder. Value is the KeyCode in string form.
        /// </summary>
        /// <param name="pos">LeftBottom Position of this UI</param>
        /// <param name="size">Size. minimum size is 30f*30f.</param>
        /// <param name="mod">Your PartialityMod</param>
        /// <param name="key">Unique Key for UIconfig</param>
        /// <param name="defaultKey">Default Keycode name</param>
        /// <param name="collisionCheck">Whether you will check the key is colliding with other KeyBinder or not</param>
        /// <param name="ctrlerNo">Which controller you want to bind to. The number is equal to RW control config menu.</param>
        public OpKeyBinder(Vector2 pos, Vector2 size, PartialityMod mod, string key, string defaultKey, bool collisionCheck = true, BindController ctrlerNo = BindController.AnyController) : this(pos, size, mod.ModID, key, defaultKey)
        {
            if (string.IsNullOrEmpty(defaultKey))
            {
                throw new ElementFormatException(this, "OpKeyBinderNull: defaultKey for this keyBinder is null.", key);
            }
            this.controlKey = string.Concat(modID, "_", key);
            this.modID      = mod.ModID;
            Vector2 minSize = new Vector2(Mathf.Max(30f, size.x), Mathf.Max(30f, size.y));

            this._size = minSize;
            this.check = collisionCheck;
            this.bind  = ctrlerNo;

            if (!_init)
            {
                return;
            }
            this.Initalize(defaultKey);
        }
Esempio n. 7
0
 public void SetController(BindController controller)
 {
     this.bind = controller;
 }