//
    // Coroutines
    //

    IEnumerator DisplayUpdate(Text display, string text, bool displayScores = true, ScreenColor state = ScreenColor.Neutral)
    {
        switch (state)
        {
        case ScreenColor.Neutral:
            display.color = Color.white;
            break;

        case ScreenColor.RightColor:
            display.color = rightColor;
            break;

        case ScreenColor.LeftColor:
            display.color = leftColor;
            break;
        }

        display.text = text;

        yield return(new WaitForSeconds(3f));

        if (displayScores)
        {
            DisplayScores();
        }
    }
Пример #2
0
 private void Clear(ScreenColor color)
 {
     for (int i = 0; i < _width * _height; i++)
     {
         _screenColors[i] = color;
     }
 }
Пример #3
0
 private void Awake()
 {
     //References
     screenColor      = Camera.main.GetComponent <ScreenColor>();
     playerController = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>();
     playerRb         = playerController.GetComponent <Rigidbody2D>();
     startRb          = playerRb.mass;
 }
Пример #4
0
 public override void PrintFile()
 {
     for (int i = 0; i < ScreenColor.GetLength(0); i++)      //lines
     {
         for (int j = 0; j < ScreenColor.GetLength(1); j++)  //columns
         {
             Console.WriteLine(ScreenColor[i, j]);
         }
     }
 }
Пример #5
0
        private Color ToColor(ScreenColor color)
        {
            switch (color)
            {
            case ScreenColor.White:
                return(Color.White);

            case ScreenColor.Black:
                return(Color.Black);

            default:
                throw new ArgumentOutOfRangeException(nameof(color), color, null);
            }
        }
Пример #6
0
        /**
         * compare two colors if they are the same
         * @param src First color
         * @param dest Second color for compare with
         * @return True if they have almost same color, i.e., the color
         *         differences are within than the ambiguous range.
         */
        public bool ColorCompare(ScreenColor src, ScreenColor dest)
        {
            bool result = ColorWithinRange(src.r, dest.r, mAmbiguousRange[0]) &&
                          ColorWithinRange(src.b, dest.b, mAmbiguousRange[1]) &&
                          ColorWithinRange(src.g, dest.g, mAmbiguousRange[2]);

            if (mChatty)
            {
                Log.D(TAG, "Source (" + src.r + ", " + src.g + ", " + src.b + "), " +
                      " Compare to (" + dest.r + ", " + dest.g + ", " + dest.b + ") ");
            }

            return(result);
        }
    protected override void OnPhaseStartedHandler(Phases phases)
    {
        string msg = "";

        switch (phases)
        {
        case Phases.WeaponSelection:
            msg = "Choosing Weapons";
            DisplayOnBothScreens(msg);
            break;

        case Phases.Parade:
            msg = "Ready!";
            DisplayOnBothScreens(msg);
            break;

        case Phases.Joust:
            DisplayScores();
            break;

        case Phases.Intermission:
            DisplayScores();
            break;

        case Phases.End:
            msg = ScoreManager.Instance.GetWinnerText();
            ScreenColor state = ScreenColor.Neutral;;

            switch (ScoreManager.Instance.winnerPlayerID)
            {
            case 0:
                state = ScreenColor.LeftColor;
                break;

            case 1:
                state = ScreenColor.RightColor;
                break;

            case 2:
                state = ScreenColor.Neutral;
                break;
            }

            DisplayOnBothScreens(msg, false, state);
            break;
        }
    }
Пример #8
0
        /**
         * Check if color at the point.coord is equal to point.color
         * @param point The point includes the coord to fetch color and determine if it's same as in color
         * @return True if color is the same or False if the colors are different
         * @throws InterruptedException When interrupted happened usually the signal from script
         * @throws ScreenshotErrorException When screenshot error happened
         */
        public bool ColorIs(ScreenPoint point)
        {
            bool refreshNeeded = false;

            if (point == null)
            {
                throw new NullReferenceException("point is null");
            }

            if (mScreenshotPolicy == POLICY_STRICT)
            {
                refreshNeeded = true;
            }

            ScreenColor currentColor = GetColorOnScreen(point.coord, refreshNeeded);

            return(ColorCompare(currentColor, point.color));
        }
Пример #9
0
        public ScreenColor GetColorOnScreen(int index, ScreenCoord src, bool refresh)
        {
            FileStream dumpFile;
            int        offset, ret = 0;

            byte[] colorInfo = new byte[4];

            offset = CalculateOffset(src);
            ScreenColor dest = new ScreenColor();

            try
            {
                if (refresh)
                {
                    ret = RequestRefresh();
                }

                dumpFile = mDevice.ScreenshotOpen(index);
                if (dumpFile == null)
                {
                    throw new Exception();
                }
                dumpFile.Seek(offset, SeekOrigin.Begin);
                dumpFile.Read(colorInfo, 0, 4);
                dest.r = colorInfo[0];
                dest.g = colorInfo[1];
                dest.b = colorInfo[2];
                dest.t = colorInfo[3];
            }
            catch (IOException e)
            {
                Log.E(TAG, "File operation failed: " + e.ToString());
                throw new JoshGameLibrary20.ScreenshotErrorException("screenshot error", ret);
            }
            catch (ThreadInterruptedException e)
            {
                Log.E(TAG, "File operation aborted by interrupt: " + e.ToString());
                throw e;
            }

            return(dest);
        }
Пример #10
0
        /**
         * Check if colors in the points array are the same as in the screen
         * @param points The point includes the coord to fetch color and determine if it's same as in color
         * @return True if colors are the same or False if at least one of the colors are different
         * @throws InterruptedException When interrupted happened usually the signal from script
         * @throws ScreenshotErrorException When screenshot error happened
         */
        public bool ColorsAre(ArrayList points)
        {
            if (points == null)
            {
                throw new NullReferenceException("point array is null");
            }

            // refresh first, we do not like to refresh every point we'd like to check
            if (mScreenshotPolicy == POLICY_STRICT)
            {
                RequestRefresh();
            }

            foreach (ScreenPoint point in points)
            {
                ScreenColor currentColor = GetColorOnScreen(point.coord, false);
                if (!ColorCompare(currentColor, point.color))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #11
0
        /// <summary>
        /// Renders the screen.
        /// </summary>
        /// <param name="target">The Direct2D drawing target.</param>
        public virtual void Render(TargetBase target)
        {
            Point drawingPosition = new Point(0, 0);
            SurfaceImageSourceTarget surfaceImageSourceTarget = target as SurfaceImageSourceTarget;

            if (surfaceImageSourceTarget != null)
            {
                drawingPosition = surfaceImageSourceTarget.DrawingPosition;
            }

            IRenderableScreenCopy screenCopy = this.screen.GetScreenCopy();

            var context2D = target.DeviceManager.ContextDirect2D;

            context2D.BeginDraw();
            context2D.Transform = Matrix.Identity;
            context2D.Clear(this.GetColor(ScreenColor.DefaultBackground));

            // 1. Paint backgrounds
            {
                RectangleF rect  = new RectangleF();
                var        lines = screenCopy.Cells;
                for (int y = 0; y < lines.Length; y++)
                {
                    var cols = lines[y];

                    rect.Top    = drawingPosition.Y + (y * this.physicalFontMetrics.CellHeight);
                    rect.Bottom = rect.Top + this.physicalFontMetrics.CellHeight;

                    ScreenColor currentBackgroundColor = cols.Length > 0 ? cols[0].BackgroundColor : ScreenColor.DefaultBackground;
                    ScreenColor cellBackgroundColor;
                    int         blockStart = 0;
                    for (int x = 0; x <= cols.Length; x++) // loop once above the upper bound
                    {
                        var cell = cols[x < cols.Length ? x : x - 1];

                        bool isCursor = !screenCopy.CursorHidden && y == screenCopy.CursorRow && x == screenCopy.CursorColumn;
                        cellBackgroundColor = isCursor ? ScreenColor.CursorBackground : cell.BackgroundColor;
                        if (cellBackgroundColor != currentBackgroundColor || x == cols.Length)
                        {
                            rect.Left  = drawingPosition.X + (blockStart * this.physicalFontMetrics.CellWidth);
                            rect.Right = drawingPosition.X + (x * this.physicalFontMetrics.CellWidth);

                            Brush backgroundBrush = this.GetBrush(context2D, this.GetColor(currentBackgroundColor));
                            if (currentBackgroundColor == ScreenColor.CursorBackground && !screenCopy.HasFocus)
                            {
                                rect.Right = rect.Right - 1.0f;
                                context2D.DrawRectangle(rect, backgroundBrush);
                            }
                            else
                            {
                                context2D.FillRectangle(rect, backgroundBrush);
                            }

                            blockStart = x;

                            currentBackgroundColor = cellBackgroundColor;
                        }
                    }
                }
            }

            // 2. Paint foregrounds
            {
                RectangleF rect  = new RectangleF();
                var        lines = screenCopy.Cells;
                for (int y = 0; y < lines.Length; y++)
                {
                    var cols = lines[y];

                    rect.Top    = drawingPosition.Y + (y * this.physicalFontMetrics.CellHeight);
                    rect.Bottom = rect.Top + this.physicalFontMetrics.CellHeight;

                    ScreenColor             currentForegroundColor   = cols.Length > 0 ? cols[0].ForegroundColor : ScreenColor.DefaultForeground;
                    ScreenCellModifications currentCellModifications = cols.Length > 0 ? cols[0].Modifications : ScreenCellModifications.None;
                    bool        currentCellUCSWIDE = cols.Length > 0 ? cols[0].Character == CjkWidth.UCSWIDE : false;
                    ScreenColor cellForegroundColor;
                    int         blockStart = 0;
                    for (int x = 0; x <= cols.Length; x++) // loop once above the upper bound
                    {
                        var cell = cols[x < cols.Length ? x : x - 1];

                        bool isCursor = !screenCopy.CursorHidden && y == screenCopy.CursorRow && x == screenCopy.CursorColumn;
                        cellForegroundColor = isCursor && screenCopy.HasFocus ? ScreenColor.CursorForeground : cell.ForegroundColor;
                        if (currentCellUCSWIDE || cellForegroundColor != currentForegroundColor || cell.Modifications != currentCellModifications || x == cols.Length)
                        {
                            rect.Left  = drawingPosition.X + (blockStart * this.physicalFontMetrics.CellWidth);
                            rect.Right = drawingPosition.X + (x * this.physicalFontMetrics.CellWidth);

                            Brush      foregroundBrush = this.GetBrush(context2D, this.GetColor(currentForegroundColor));
                            TextFormat textFormat      = this.textFormatNormal;
                            if (currentCellModifications.HasFlag(ScreenCellModifications.Bold))
                            {
                                textFormat = this.textFormatBold;
                            }

                            string text = new string(cols.Skip(blockStart).Take(x - blockStart).Select(c => char.IsWhiteSpace(c.Character) ? ' ' : c.Character).Where(ch => ch != CjkWidth.UCSWIDE).ToArray()).TrimEnd();

                            if (text.Length > 0)
                            {
                                context2D.DrawText(text, textFormat, rect, foregroundBrush, DrawTextOptions.Clip);
                            }

                            if (currentCellModifications.HasFlag(ScreenCellModifications.Underline))
                            {
                                var point1 = new Vector2(rect.Left, rect.Bottom - 1.0f) + drawingPosition;
                                var point2 = new Vector2(rect.Right, rect.Bottom - 1.0f) + drawingPosition;
                                context2D.DrawLine(point1, point2, foregroundBrush);
                            }

                            blockStart = x;

                            currentForegroundColor = cellForegroundColor;
                        }
                        currentCellUCSWIDE = cell.Character == CjkWidth.UCSWIDE;
                    }
                }
            }

            context2D.EndDraw();
        }
Пример #12
0
 public void SetPixel(int x, int y, ScreenColor screenColor)
 {
     _screenColors[y * _width + x] = screenColor;
 }
Пример #13
0
 public ScreenPixel(byte x, byte y, ScreenColor color)
 {
     X     = x;
     Y     = y;
     Color = color;
 }
Пример #14
0
        /**
         * Check if all colors in the array are all in the specific region rect
         * Note that the colors in the array in unordered
         * @param rectLeftTop The LT of rect
         * @param rectRightBottom The RB of rect
         * @param colors The set of {@link ScreenColor} in match
         * @return True if all colors are in the rect. False if at least one color is not in the rect.
         * @throws InterruptedException When interrupted happened usually the signal from script
         * @throws ScreenshotErrorException When screenshot error happened
         */
        public bool ColorsAreInRect(ScreenCoord rectLeftTop, ScreenCoord rectRightBottom, ArrayList colors)
        {
            ArrayList coordList = new ArrayList();
            ArrayList colorsReturned;
            ArrayList checkList = new ArrayList();
            int       colorCount, orientation;
            int       x_start, x_end, y_start, y_end;

            // sanity check
            if (colors == null || rectLeftTop == null || rectRightBottom == null)
            {
                Log.W(TAG, "checkColorIsInRegion: colors cannot be null");
                throw new NullReferenceException("checkColorIsInRegion: colors cannot be null");
            }
            else
            {
                orientation = rectLeftTop.orientation;
                colorCount  = colors.Count;
            }

            if (rectLeftTop.orientation != rectRightBottom.orientation)
            {
                Log.W(TAG, "checkColorIsInRegion: Src and Dest must in same orientation");
                throw new ArgumentException("checkColorIsInRegion: Src and Dest must in same orientation");
            }

            if (colorCount < 1 || colorCount > mMaxColorFinding)
            {
                Log.W(TAG, "checkColorIsInRegion: colors size should be bigger than 0 and smaller than " +
                      mMaxColorFinding);
                throw new ArgumentException("checkColorIsInRegion: colors size should be bigger than 0 and smaller than " +
                                            mMaxColorFinding);
            }

            for (int i = 0; i < colorCount; i++)
            {
                checkList.Add(false);
            }

            if (rectLeftTop.x > rectRightBottom.x)
            {
                x_start = rectRightBottom.x;
                x_end   = rectLeftTop.x;
            }
            else
            {
                x_start = rectLeftTop.x;
                x_end   = rectRightBottom.x;
            }

            if (rectLeftTop.y > rectRightBottom.y)
            {
                y_start = rectRightBottom.y;
                y_end   = rectLeftTop.y;
            }
            else
            {
                y_start = rectLeftTop.y;
                y_end   = rectRightBottom.y;
            }

            for (int x = x_start; x <= x_end; x++)
            {
                for (int y = y_start; y <= y_end; y++)
                {
                    coordList.Add(new ScreenCoord(x, y, orientation));
                }
            }

            if (mChatty)
            {
                Log.D(TAG, "FindColorInRange: now checking total " + coordList.Count + " points");
            }

            colorsReturned = GetMultiColorOnScreen(coordList, true);
            foreach (ScreenColor color in colorsReturned)
            {
                for (int i = 0; i < colorCount; i++)
                {
                    ScreenColor sc = (ScreenColor)colors[i];

                    if ((bool)checkList[i])
                    {
                        continue;
                    }

                    if (ColorCompare(color, sc))
                    {
                        if (mChatty)
                        {
                            Log.D(TAG, "FindColorInRange: Found color " + color.ToString());
                        }
                        checkList.Insert(i, true);
                    }
                }
            }

            foreach (bool b in checkList)
            {
                if (!b)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #15
0
 public Screen(decimal size, ScreenColor colorConfiguration = ScreenColor.Color)
 {
     Size = size;
     ColorConfiguration = colorConfiguration;
 }
    //
    // Feedback Functions
    //

    private void DisplayOnBothScreens(string msg, bool displayScores = true, ScreenColor state = ScreenColor.Neutral)
    {
        StartCoroutine(DisplayUpdate(displayLeft, msg, displayScores, state));
        StartCoroutine(DisplayUpdate(displayRight, msg, displayScores, state));
    }
Пример #17
0
        /// <summary>
        /// Transforms a <see cref="ScreenColor"/> to the actual <see cref="Color"/> through the theme.
        /// </summary>
        /// <param name="screenColor">The screen color.</param>
        /// <returns>The actual <see cref="Color"/> to use.</returns>
        private Color GetColor(ScreenColor screenColor)
        {
            var color = this.screenDisplay.ColorTheme.ColorTable[screenColor];

            return(new Color(color.R, color.G, color.B, color.A));
        }
Пример #18
0
        /// <summary>
        /// Generates the RTF for the currently displayed terminal screen content.
        /// </summary>
        /// <param name="screenCopy">The currently displayed terminal screen content.</param>
        /// <returns>The generate RTF async operation.</returns>
        private async Task <Tuple <InMemoryRandomAccessStream, float> > GenerateRtf(IRenderableScreenCopy screenCopy)
        {
            int      rightmostNonSpace = -1;
            int      columnCount       = -1;
            Encoding codepage1252      = Encoding.GetEncoding("Windows-1252");
            var      rtfStream         = new InMemoryRandomAccessStream();

            using (DataWriter rtf = new DataWriter(rtfStream))
            {
                rtf.WriteString(@"{");
                rtf.WriteString(@"\rtf1");
                rtf.WriteString(@"\ansi");
                rtf.WriteString(@"\ansicpg1252");
                rtf.WriteString(@"{\fonttbl{\f0\fmodern " + this.screenDisplay.ColorTheme.FontFamily + ";}}");
                rtf.WriteString(Environment.NewLine);

                rtf.WriteString(@"{\colortbl ;");
                var colorTable = this.screenDisplay.ColorTheme.ColorTable;
                for (ScreenColor screenColor = ScreenColor.DefaultBackground; screenColor <= ScreenColor.WhiteBright; screenColor++)
                {
                    var color = colorTable[screenColor];
                    rtf.WriteString(@"\red" + color.R + @"\green" + color.G + @"\blue" + color.B + ";");
                }
                rtf.WriteString(@"}");
                rtf.WriteString(Environment.NewLine);

                int fontSize = (int)(ScreenDisplay.BaseLogicalFontMetrics[this.screenDisplay.ColorTheme.FontFamily].FontSize * (1 + (ScreenDisplay.FontSizeScalingFactor * (float)this.screenDisplay.ColorTheme.FontSize)));
                rtf.WriteString(@"\pard\ltrpar\f0\fs" + fontSize);
                rtf.WriteString(Environment.NewLine);

                StringBuilder formatCodes = new StringBuilder();
                for (int y = 0; y < screenCopy.Cells.Length; y++)
                {
                    var    line             = screenCopy.Cells[y];
                    string lineString       = new string(line.Select(c => c.Character).ToArray());
                    var    hyperlinkMatches = hyperlinkRegex.Value.Matches(lineString).Cast <Match>();

                    for (int x = 0; x < line.Length; x++)
                    {
                        Match startingMatch = hyperlinkMatches.Where(m => m.Index == x).SingleOrDefault();
                        if (startingMatch != null)
                        {
                            rtf.WriteString(@"{\field{\*\fldinst HYPERLINK """ + RtfEscape(startingMatch.Value) + @"""}{\fldrslt ");
                        }

                        if (x == 0 || line[x - 1].BackgroundColor != line[x].BackgroundColor)
                        {
                            formatCodes.Append(@"\chshdng0\chcbpat" + (line[x].BackgroundColor - ScreenColor.DefaultBackground + 1));
                        }

                        if (x == 0 || line[x - 1].ForegroundColor != line[x].ForegroundColor)
                        {
                            formatCodes.Append(@"\cf" + (line[x].ForegroundColor - ScreenColor.DefaultBackground + 1));
                        }

                        if (x == 0 || line[x - 1].Modifications.HasFlag(ScreenCellModifications.Bold) != line[x].Modifications.HasFlag(ScreenCellModifications.Bold))
                        {
                            formatCodes.Append(@"\b");
                            if (!line[x].Modifications.HasFlag(ScreenCellModifications.Bold))
                            {
                                formatCodes.Append("0");
                            }
                        }

                        if (x == 0 || line[x - 1].Modifications.HasFlag(ScreenCellModifications.Underline) != line[x].Modifications.HasFlag(ScreenCellModifications.Underline))
                        {
                            formatCodes.Append(@"\ul");
                            if (!line[x].Modifications.HasFlag(ScreenCellModifications.Underline))
                            {
                                formatCodes.Append("0");
                            }
                        }

                        if (formatCodes.Length > 0)
                        {
                            rtf.WriteString(formatCodes.ToString());
                            formatCodes.Clear();
                            rtf.WriteString(" ");
                        }

                        if (line[x].Character == CjkWidth.UCSWIDE)
                        {
                            // don't write this
                        }
                        else if (line[x].Character == codepage1252.GetChars(codepage1252.GetBytes(new[] { line[x].Character }))[0])
                        {
                            rtf.WriteBytes(codepage1252.GetBytes(RtfEscape(line[x].Character.ToString())));
                        }
                        else
                        {
                            rtf.WriteString(@"\u" + ((int)line[x].Character).ToString() + "?");
                        }

                        Match endingMatch = hyperlinkMatches.Where(m => m.Index + m.Length == x + 1).SingleOrDefault();
                        if (endingMatch != null)
                        {
                            rtf.WriteString("}}");
                        }

                        if (x + 1 >= line.Length)
                        {
                            if (line[x].Modifications.HasFlag(ScreenCellModifications.Bold))
                            {
                                formatCodes.Append(@"\b0");
                            }
                            if (line[x].Modifications.HasFlag(ScreenCellModifications.Underline))
                            {
                                formatCodes.Append(@"\ul0");
                            }
                        }

                        if (line[x].Character != 0x0020)
                        {
                            rightmostNonSpace = Math.Max(rightmostNonSpace, x);
                        }
                    }

                    if (formatCodes.Length > 0)
                    {
                        rtf.WriteString(formatCodes.ToString());
                        formatCodes.Clear();
                    }

                    if (y + 1 < screenCopy.Cells.Length)
                    {
                        rtf.WriteString(@"\par" + Environment.NewLine);
                    }

                    columnCount = Math.Max(columnCount, line.Length);
                }

                rtf.WriteString(@"}");

                await rtf.StoreAsync();

                await rtf.FlushAsync();

                rtf.DetachStream();
            }

            rtfStream.Seek(0);

            float widthRatio = rightmostNonSpace >= 0 ? (rightmostNonSpace + 1f) / columnCount : -1f;

            return(new Tuple <InMemoryRandomAccessStream, float>(rtfStream, widthRatio));
        }
Пример #19
0
 /// <summary>
 /// Transforms a <see cref="ScreenColor"/> to the actual <see cref="Color"/> through the theme.
 /// </summary>
 /// <param name="screenColor">The screen color.</param>
 /// <returns>The actual <see cref="Color"/> to use.</returns>
 private Color GetColor(ScreenColor screenColor)
 {
     var color = this.screenDisplay.ColorTheme.ColorTable[screenColor];
     return new Color(color.R, color.G, color.B, color.A);
 }
Пример #20
0
 public void SetPixel(int x, int y, ScreenColor color)
 {
     _image.SetPixel(x, y, ToColor(color));
 }