Ejemplo n.º 1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            // Update the local settings
            ChessUtils.Settings.Color.darkSquareColor  = darkColor.BackColor;
            ChessUtils.Settings.Color.lightSquareColor = lightColor.BackColor;

            redLightComponent   = lightColor.BackColor.R;
            greenLightComponent = lightColor.BackColor.G;
            blueLightComponent  = lightColor.BackColor.B;
            redDarkComponent    = darkColor.BackColor.R;
            greenDarkComponent  = darkColor.BackColor.G;
            blueDarkComponent   = darkColor.BackColor.B;

            ChessUtils.Settings.Image.BlackKing   = BlackKing;
            ChessUtils.Settings.Image.BlackQueen  = BlackQueen;
            ChessUtils.Settings.Image.BlackRook   = BlackRook;
            ChessUtils.Settings.Image.BlackBishop = BlackBishop;
            ChessUtils.Settings.Image.BlackKnight = BlackKnight;
            ChessUtils.Settings.Image.BlackPawn   = BlackPawn;
            ChessUtils.Settings.Image.WhiteKing   = WhiteKing;
            ChessUtils.Settings.Image.WhiteQueen  = WhiteQueen;
            ChessUtils.Settings.Image.WhiteRook   = WhiteRook;
            ChessUtils.Settings.Image.WhiteBishop = WhiteBishop;
            ChessUtils.Settings.Image.WhiteKnight = WhiteKnight;
            ChessUtils.Settings.Image.WhitePawn   = WhitePawn;

            // Send the settings to the database
            SquareColorSettings settings = new SquareColorSettings()
            {
                Username = me.Username,
                Red1     = redDarkComponent,
                Green1   = greenDarkComponent,
                Blue1    = blueDarkComponent,
                Red2     = redLightComponent,
                Green2   = greenLightComponent,
                Blue2    = blueLightComponent
            };

            DataApiController <SquareColorSettings> .PostData(ChessUtils.IPAddressWithPort + "EditCustomChessboard", settings);

            // Send the piece images to the database
            List <PieceImageSettings> images = new List <PieceImageSettings>()
            {
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "wKing",
                    Image     = ImageToByteArray(WhiteKing)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "wQueen",
                    Image     = ImageToByteArray(WhiteQueen)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "wRook",
                    Image     = ImageToByteArray(WhiteRook)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "wBishop",
                    Image     = ImageToByteArray(WhiteBishop)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "wKnight",
                    Image     = ImageToByteArray(WhiteKnight)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "wPawn",
                    Image     = ImageToByteArray(WhitePawn)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "bKing",
                    Image     = ImageToByteArray(BlackKing)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "bQueen",
                    Image     = ImageToByteArray(BlackQueen)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "bRook",
                    Image     = ImageToByteArray(BlackRook)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "bBishop",
                    Image     = ImageToByteArray(BlackBishop)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "bKnight",
                    Image     = ImageToByteArray(BlackKnight)
                },
                new PieceImageSettings()
                {
                    Username  = me.Username,
                    PieceName = "bPawn",
                    Image     = ImageToByteArray(BlackPawn)
                }
            };

            DataApiController <object> .PostData(ChessUtils.IPAddressWithPort + "DeleteUsersCustomPieceImages/" + me.Username, null);

            DataApiController <List <PieceImageSettings> > .PostData(ChessUtils.IPAddressWithPort + "AddCustomPieceImages", images);

            // Close this form
            Close();
        }
Ejemplo n.º 2
0
        private void SetupSettings()
        {
            SquareColorSettings colors = DataApiController <SquareColorSettings> .GetData(ChessUtils.IPAddressWithPort + "GetCustomChessboardForUser/" + me.Username);

            ChessUtils.Settings.Color.darkSquareColor  = Color.FromArgb(colors.Red1, colors.Green1, colors.Blue1);
            ChessUtils.Settings.Color.lightSquareColor = Color.FromArgb(colors.Red2, colors.Green2, colors.Blue2);

            List <PieceImageSettings> images = DataApiController <List <PieceImageSettings> > .GetData(ChessUtils.IPAddressWithPort + "GetCustomPieceImagesForUser/" + me.Username);

            if (images != null)
            {
                foreach (PieceImageSettings image in images)
                {
                    switch (image.PieceName)
                    {
                    case "wKing":
                        ChessUtils.Settings.Image.WhiteKing = GetImageFromByteArray(image.Image);
                        break;

                    case "wQueen":
                        ChessUtils.Settings.Image.WhiteQueen = GetImageFromByteArray(image.Image);
                        break;

                    case "wRook":
                        ChessUtils.Settings.Image.WhiteRook = GetImageFromByteArray(image.Image);
                        break;

                    case "wBishop":
                        ChessUtils.Settings.Image.WhiteBishop = GetImageFromByteArray(image.Image);
                        break;

                    case "wKnight":
                        ChessUtils.Settings.Image.WhiteKnight = GetImageFromByteArray(image.Image);
                        break;

                    case "wPawn":
                        ChessUtils.Settings.Image.WhitePawn = GetImageFromByteArray(image.Image);
                        break;

                    case "bKing":
                        ChessUtils.Settings.Image.BlackKing = GetImageFromByteArray(image.Image);
                        break;

                    case "bQueen":
                        ChessUtils.Settings.Image.BlackQueen = GetImageFromByteArray(image.Image);
                        break;

                    case "bRook":
                        ChessUtils.Settings.Image.BlackRook = GetImageFromByteArray(image.Image);
                        break;

                    case "bBishop":
                        ChessUtils.Settings.Image.BlackBishop = GetImageFromByteArray(image.Image);
                        break;

                    case "bKnight":
                        ChessUtils.Settings.Image.BlackKnight = GetImageFromByteArray(image.Image);
                        break;

                    case "bPawn":
                        ChessUtils.Settings.Image.BlackPawn = GetImageFromByteArray(image.Image);
                        break;
                    }
                }
            }
        }