コード例 #1
0
    public bool GetControllerButton(ControllerCode buttonCode, int gamePadIndex, ButtonStateType buttonState = ButtonStateType.Down)
    {
        string buttonName = GetGamePadControllerCodeName(buttonCode, gamePadIndex);

        if (ControllerMap.ContainsKey(buttonName))
        {
            ControllerMappedInput mappedInput = ControllerMap[buttonName];
            if (!mappedInput.IsAxis)
            {
                if (mappedInput.Key != KeyCode.None)
                {
                    switch (buttonState)
                    {
                    case ButtonStateType.Down:
                        return(Input.GetKeyDown(mappedInput.Key));

                    case ButtonStateType.Up:
                        return(Input.GetKeyUp(mappedInput.Key));

                    case ButtonStateType.Constant:
                        return(Input.GetKey(mappedInput.Key));
                    }
                }
            }
        }

        return(false);
    }
コード例 #2
0
 /* methods */
 /// <summary>
 /// 更新星魂仓库列表.
 /// </summary>
 public void UpdateSoul(StarSoul starSoul, ButtonStateType type, bool isAutoSelect)
 {
     this.stateType = type;
     this.starSoul  = starSoul;
     isSelect       = isAutoSelect;
     storeButton.setFatherWindow(fatherWindow);
     UpdateIU();
 }
コード例 #3
0
        /// <summary>
        /// Creates a new Pushbutton-objekt
        /// </summary>
        /// <param name="_position">where the button is drawn, upper left corner</param>
        /// <param name="idletex">texture of idlebutton</param>
        /// <param name="hoovertex">texture of hoovering button</param>
        /// <param name="presstex">texture of pressed button</param>
        public Pushbutton(Vector2 _position, Texture2D idletex, Texture2D hoovertex, Texture2D presstex, string _text, Color _color, TileMenuFunction _buttonFunction)
        {
            state    = ButtonStateType.idle;
            position = _position;

            textures.Add(ButtonStateType.idle, idletex);
            textures.Add(ButtonStateType.hoover, hoovertex);
            textures.Add(ButtonStateType.pressed, presstex);

            bounds = new Rectangle(Convert.ToInt32(position.X), Convert.ToInt32(position.Y), textures[0].Width, textures[0].Height);

            text           = _text;
            color          = _color;
            buttonFunction = _buttonFunction;
        }
コード例 #4
0
        /// <summary>
        /// Creates a new Pushbutton-objekt
        /// </summary>
        /// <param name="_position">where the button is drawn, upper left corner</param>
        /// <param name="_textures">dictionary of statetype and textures</param>
        public Pushbutton(Vector2 _position, Dictionary <ButtonStateType, Texture2D> _textures, string _text, Color _color, TileMenuFunction _buttonFunction)
        {
            state    = ButtonStateType.idle;
            position = _position;

            foreach (KeyValuePair <ButtonStateType, Texture2D> tex in _textures)
            {
                textures.Add(tex.Key, tex.Value);
            }

            bounds = new Rectangle(Convert.ToInt32(position.X), Convert.ToInt32(position.Y), textures[0].Width, textures[0].Height);

            text           = _text;
            color          = _color;
            buttonFunction = _buttonFunction;
        }
コード例 #5
0
        /// <summary>
        /// Get Texture of small button for a buttonstate
        /// </summary>
        /// <param name="GraphicsDevice"></param>
        /// <param name="position"></param>
        /// <param name="buttonStateType"></param>
        /// <returns></returns>
        private Texture2D GetTexture(SmallButtonNumber position, ButtonStateType buttonStateType)
        {
            Texture2D return_tex;

            Color[]   data;
            Rectangle rect = GetTileSpritePosition(position, buttonStateType);

            return_tex = new Texture2D(Globals.GraphicsDevice, rect.Width, rect.Height);
            data       = new Color[rect.Width * rect.Height];

            Globals.buttons_small.GetData(0, rect, data, 0, data.Length);
            return_tex.SetData(data);


            return(return_tex);
        }
コード例 #6
0
    public bool GetKeyboardButton(KeyCode buttonCode, ButtonStateType buttonState = ButtonStateType.Down)
    {
        if (buttonCode != KeyCode.None)
        {
            switch (buttonState)
            {
            case ButtonStateType.Down:
                return(Input.GetKeyDown(buttonCode));

            case ButtonStateType.Up:
                return(Input.GetKeyUp(buttonCode));

            case ButtonStateType.Constant:
                return(Input.GetKey(buttonCode));
            }
        }

        return(false);
    }
コード例 #7
0
        public void Update(MouseState mouseState)
        {
            if (visible && !locked)
            {
                if (mouseState.LeftButton == ButtonState.Pressed && old_mouseState.LeftButton == ButtonState.Released && Utility.mouseInBounds(bounds, new Vector2(mouseState.X, mouseState.Y)))
                {
                    state = ButtonStateType.pressed;
                    onClick?.Invoke(buttonFunction);
                }
                else if (mouseState.LeftButton == ButtonState.Released && Utility.mouseInBounds(bounds, new Vector2(mouseState.X, mouseState.Y)))
                {
                    state = ButtonStateType.hoover;
                }
                else
                {
                    state = ButtonStateType.idle;
                }

                bounds = new Rectangle(Convert.ToInt32(position.X), Convert.ToInt32(position.Y), textures[0].Width, textures[0].Height);
            }

            old_mouseState = mouseState;
        }
コード例 #8
0
 private static void Button_StateChanged(Button sender, ButtonStateType state)
 {
     Console.WriteLine($"Button value: {state}");
 }
コード例 #9
0
 private void UpdateButtonState()
 {
     State = InputPin.CurrentValue ? ButtonStateType.NotPressed : ButtonStateType.Pressed;
 }
コード例 #10
0
 /// <summary>
 ///  Returns a Rectangle descriping position and dimension of sprite on a spritemap
 /// </summary>
 /// <param name="position"></param>
 /// <param name="buttonStateType"></param>
 /// <returns></returns>
 private Rectangle GetTileSpritePosition(SmallButtonNumber position, ButtonStateType buttonStateType)
 {
     return(new Rectangle(((int)buttonStateType) * Constants.small_button_diameter, ((int)position) * Constants.small_button_diameter, Constants.small_button_diameter, Constants.small_button_diameter));
 }
コード例 #11
0
    public bool GetCompDevInputButton(CompDevInput compDevInputButton, int playerIndex = 0, ButtonStateType buttonState = ButtonStateType.Down)
    {
        if (CompDevInputMap.ContainsKey(compDevInputButton))
        {
            CompDevMappedInput mappedInput = CompDevInputMap[compDevInputButton];
            if (PlayerInputMode == InputMode.Keyboard)
            {
                if (!mappedInput.IsKeyboardAxis)
                {
                    return(GetKeyboardButton(mappedInput.KeyboardKeys[playerIndex], buttonState));
                }
            }
            else if (PlayerInputMode == InputMode.Controller)
            {
                if (!mappedInput.IsControllerAxis)
                {
                    return(GetControllerButton(mappedInput.ControllerInput, playerIndex, buttonState));
                }
            }
        }

        return(false);
    }