Esempio n. 1
0
        protected override void OnDraw()
        {
            base.OnDraw();

            Vector2 drawPos = new Vector2(150, 200);

            //Draw the bars
            //Draw the middle
            SpriteRenderer.Instance.DrawUI(BarMiddle.Tex, drawPos, BarMiddle.SourceRect, Color.White, 0f, Vector2.Zero, new Vector2(BarScale, 1f), false, false, .39f);

            //Draw the ends
            SpriteRenderer.Instance.DrawUI(BarEnd.Tex, drawPos - new Vector2(BarEnd.SourceRect.Value.Width, 0f), BarEnd.SourceRect, Color.White, 0f, Vector2.Zero, Vector2.One, false, false, .39f);
            SpriteRenderer.Instance.DrawUI(BarEnd.Tex, drawPos + new Vector2(BarScale, 0f), BarEnd.SourceRect, Color.White, 0f, Vector2.Zero, Vector2.One, true, false, .39f);

            //Draw the cursor
            //Regardless of MaxBarVal, needs to be rendered within the range
            float barValScaleFactor = BarScale / MaxBarVal;

            SpriteRenderer.Instance.DrawUI(MovingCursor.Tex, drawPos + new Vector2(CurBarVal * barValScaleFactor, 0f), MovingCursor.SourceRect, Color.White, 0f, new Vector2(.5f, 1f), Vector2.One, false, false, .4f);

            //Draw the values of the bar sections
            if (BarRanges != null)
            {
                for (int i = 0; i < BarRanges.Length; i++)
                {
                    BarRangeData barRange = BarRanges[i];
                    Vector2      scale    = new Vector2((barRange.EndBarVal - barRange.StartBarVal) * barValScaleFactor, 18f);

                    Vector2 pos = new Vector2(drawPos.X + (barRange.StartBarVal * barValScaleFactor), drawPos.Y + 5f);
                    SpriteRenderer.Instance.DrawUI(Box, pos, null, barRange.SegmentColor, 0f, Vector2.Zero, scale, false, false, .41f);
                }
            }
        }
        protected override void ReadInput()
        {
            //If the time passed or there's no valid data, end with a failure
            if (ElapsedTime >= CommandTime || UtilityGlobals.IListIsNullOrEmpty(BarRanges) == true)
            {
                OnComplete(CommandResults.Failure);
                return;
            }

            ElapsedTime   += Time.ElapsedMilliseconds;
            CursorTimeVal += Time.ElapsedMilliseconds;

            //The cursor value updates before accepting input - this is evident if you press A when doing Shell Shield with frame advance
            UpdateCursorVal();

            if (AutoComplete == true)
            {
                //Assume the last one is the highest value
                BarRangeData rangeData = BarRanges[BarRanges.Length - 1];
                if (rangeData.IsValueInRange(CurBarVal) == true)
                {
                    //Send the response and rank, and complete with a Success
                    SendResponse(rangeData.Value);
                    SendCommandRank(rangeData.Rank);

                    OnComplete(CommandResults.Success);
                }
                return;
            }

            if (Input.GetKeyDown(ButtonToPress) == true)
            {
                //Check the range the cursor is in
                for (int i = 0; i < BarRanges.Length; i++)
                {
                    BarRangeData rangeData = BarRanges[i];

                    //Check for the range
                    if (rangeData.IsValueInRange(CurBarVal) == true)
                    {
                        //Send the response and rank, and complete with a Success
                        SendResponse(rangeData.Value);
                        SendCommandRank(rangeData.Rank);

                        OnComplete(CommandResults.Success);
                        break;
                    }
                }
            }
        }