Пример #1
0
        /// <summary>
        /// Kuuntelee analogisen kontrollin (tatin tai liipaisimen) liikettä.
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <param name="control">Kuunneltava kontrolli</param>
        /// <param name="trigger">Raja jonka liikkeen tulee ylittää</param>
        /// <param name="handler">Kuuntelija-aliohjelma</param>
        /// <param name="helpText">Ohjeteksti</param>
        /// <param name="p1">1. parametri</param>
        /// <param name="p2">2. parametri</param>
        /// <param name="p3">3. parametri</param>
        /// <returns></returns>
        public Listener ListenAnalog <T1, T2, T3>(AnalogControl control, double trigger, Action <AnalogState, T1, T2, T3> handler, string helpText, T1 p1, T2 p2, T3 p3)
        {
            ChangePredicate <GamePadState> rule = MakeTriggerRule(control, trigger);
            Action analogHandler = delegate { handler(GenerateAnalogState(control), p1, p2, p3); };

            return(AddListener(rule, control, GetAnalogName(control), helpText, analogHandler));
        }
Пример #2
0
        private ChangePredicate <GamePadState> MakeTriggerRule(AnalogControl control, double moveTrigger)
        {
            switch (control)
            {
            case AnalogControl.LeftStick:
                return(delegate(GamePadState prev, GamePadState curr)
                {
                    double xdist = curr.ThumbSticks.Left.X - prev.ThumbSticks.Left.X;
                    double ydist = curr.ThumbSticks.Left.Y - prev.ThumbSticks.Left.Y;
                    return xdist * xdist + ydist * ydist > moveTrigger * moveTrigger;
                });

            case AnalogControl.RightStick:
                return(delegate(GamePadState prev, GamePadState curr)
                {
                    double xdist = curr.ThumbSticks.Right.X - prev.ThumbSticks.Right.X;
                    double ydist = curr.ThumbSticks.Right.Y - prev.ThumbSticks.Right.Y;
                    return xdist * xdist + ydist * ydist > moveTrigger * moveTrigger;
                });

            case AnalogControl.LeftTrigger:
                return(delegate(GamePadState prev, GamePadState curr)
                {
                    return Math.Abs(curr.Triggers.Left - prev.Triggers.Left) > moveTrigger;
                });

            case AnalogControl.RightTrigger:
                return(delegate(GamePadState prev, GamePadState curr)
                {
                    return Math.Abs(curr.Triggers.Right - prev.Triggers.Right) > moveTrigger;
                });
            }

            throw new ArgumentException(control.ToString() + " is not a valid analog control for a GamePad");
        }
Пример #3
0
        private void AnalogControl_ValueChanged(object sender, EventArgs e)
        {
            AnalogControl AC = (AnalogControl)sender;

            if (AC.IOTypeOutput)
            {
                int    index = this.Controls.IndexOf(AC);
                double val   = AC.Value;
                ((IAnalogOutput)ioObjList[index]).Set(val);
            }
        }
Пример #4
0
        public void AddIO(IAnalogInput anIn, string label)
        {
            SetType(IOType.Analog);
            AnalogControl newAC = new AnalogControl();

            newAC.Value        = anIn.Get();
            newAC.IOTypeOutput = false;
            newAC.Label        = label;
            newAC.Units        = anIn.Unit;
            this.ioObjList.Add(anIn);
            this.Controls.Add(newAC);
        }
Пример #5
0
        private GamePadAnalogState GenerateAnalogState(AnalogControl control)
        {
            switch (control)
            {
            case AnalogControl.LeftStick:
                return(new GamePadAnalogState(LeftThumbDirection.Magnitude, LeftThumbChange.Magnitude, LeftThumbDirection, LeftThumbChange));

            case AnalogControl.RightStick:
                return(new GamePadAnalogState(RightThumbDirection.Magnitude, RightThumbChange.Magnitude, RightThumbDirection, RightThumbChange));

            default:
                throw new NotImplementedException("Unsupported Controller / GamePad control for ListenAnalog: " + control.ToString());
            }
        }
Пример #6
0
        public void AddIO(IAnalogOutput anOut, string label)
        {
            SetType(IOType.Analog);
            AnalogControl newAC = new AnalogControl();

            newAC.Value         = anOut.Get();
            newAC.IOTypeOutput  = true;
            newAC.OutputMin     = anOut.LimitMin;
            newAC.OutputMax     = anOut.LimitMax;
            newAC.ValueChanged += new EventHandler(this.AnalogControl_ValueChanged);
            newAC.Label         = label;
            newAC.Units         = anOut.Unit;
            this.ioObjList.Add(anOut);
            this.Controls.Add(newAC);
        }
Пример #7
0
        /// <summary>
        /// Add a controller. This has to be called as many times as the control count specified in the Init function.
        /// </summary>
        /// <param name="baseRectangle">Texture coordinates for this element.</param>
        /// <param name="baseCenter">Texture coordinates for this element.</param>
        /// <param name="stickRectangle">Texture coordinates for this element.</param>
        /// <param name="stickCenter">Texture coordinates for this element.</param>
        /// <param name="activeArea">Screen area interested by this controller.</param>
        /// <returns></returns>
        public int addController(
            Rectangle baseRectangle,
            Vector2 baseCenter,
            Rectangle stickRectangle,
            Vector2 stickCenter,
            RectF activeArea)
        {
            int i = 0;

            while(true)
            {
                if(i >= _control_count)
                    return -1;

                if((Object)_control[i] == null)
                    break;

                i++;
            }

            _control[i] = new AnalogControl();

            _control[i].base_rect = baseRectangle;
            _control[i].base_center = baseCenter;

            _control[i].stick_rect = stickRectangle;
            _control[i].stick_center = stickCenter;

            _control[i].active_area = activeArea;

            return i;
        }
Пример #8
0
 private string GetAnalogName(AnalogControl a)
 {
     return(String.Format("GamePad{0} {1}", playerIndex.ToString(), a.ToString()));
 }
Пример #9
0
 /// <summary>
 /// Set the control state of a ped
 /// </summary>
 public bool SetControlState(AnalogControl control, bool state)
 {
     return(MtaClient.SetPedControlState(element, control.ToString(), state));
 }
Пример #10
0
 /// <summary>
 /// Checks wheter a ped has a certain control pressed
 /// </summary>
 public bool GetControlState(AnalogControl control)
 {
     return(MtaClient.GetPedControlState(element, control.ToString()));
 }
Пример #11
0
 /// <summary>
 /// Retrieve the analog control state of a certain control
 /// </summary>
 public float GetAnalogControlState(AnalogControl control)
 {
     return(MtaClient.GetPedAnalogControlState(element, control.ToString()));
 }