Esempio n. 1
0
        private void MiddleViewLoadButton_Click(object sender, RoutedEventArgs e)
        {
            var         size = VisualTreeHelper.GetContentBounds(LeftViewContainer.Children[0]);
            ImageSource src  = ImageExtensions.BitmapToImageSource(
                ImageExtensions.CanvasToBitmap(LeftViewContainer, true, Convert.ToInt32(size.Width), Convert.ToInt32(size.Height))
                );
            var newtiles = src.MapImageToTiles(Game.Get.TileManager.Tiles);

            #region first moveable test

            /*var image = ImageExtensions.ConstructSensorDataBackground(Tile.GetDebugTiles(2, 8, 8, 8, 4, 4));
             * var img = new CustomImage
             * {
             *  Source = ImageExtensions.BitmapToImageSource(image)
             * };
             * img.SetValue(DraggableExtender.CanDragProperty, true);
             *
             * var secondImage = ImageExtensions.BuildImage(Tile.GetDebugTiles(6, 6, 8, 8, 4, 4));
             * var secondImg = new CustomImage
             * {
             *  Source = ImageExtensions.BitmapToImageSource(secondImage)
             * };
             * secondImg.SetValue(DraggableExtender.CanDragProperty, true);*/
            #endregion

            var imgList = ImageExtensions.GetIndividualSensorVisuals(Game.Get.TileManager.Tiles);
            Main.GetDispatcher.Invoke(PopulateCanvasControlDelegate, MiddleViewContainer, imgList, true);
        }
        public void Init()
        {
            isClosing = false;
            MainDockPanel.Children.Clear();

            var gameNames = (GameName[])Enum.GetValues(typeof(GameName));
            var games     = new List <ActiveGameData>();

            foreach (var gameName in gameNames)
            {
                var activeGameData = new ActiveGameData
                {
                    EnumValue         = gameName,
                    GameName          = gameName.ToString(),
                    GameDescription   = GameList.GetGameDescription(gameName),
                    GameIcon          = GameList.GetGameIcon(gameName),
                    GameCustomControl = GameList.GetGameControls(gameName)
                };
                games.Add(activeGameData);
            }

            foreach (var game in games)
            {
                #region Generate Elements

                var sp = new StackPanel
                {
                    Name   = $"{game.GameName}_StackPanel",
                    Width  = 80,
                    Height = 90
                };
                var lb = new Label
                {
                    Content             = game.GameName,
                    HorizontalAlignment = HorizontalAlignment.Center
                };
                var imgBrush = new ImageBrush
                {
                    ImageSource = ImageExtensions.BitmapToImageSource(game.GameIcon)
                };
                var btn = new Button
                {
                    Height     = 64,
                    Width      = 64,
                    Background = imgBrush
                };

                #endregion

                btn.Click += (sender, args) => LoadGame(game);
                sp.Children.Add(lb);
                sp.Children.Add(btn);
                MainDockPanel.Children.Add(sp);
            }
        }
Esempio n. 3
0
        public void LoadGame(ref ActiveGameData newGameData)
        {
            gameData    = newGameData;
            newGameData = null;
            this.Title  = gameData.GameName;
            DescriptionTextBlock.Text = gameData.GameDescription;
            this.Icon = ImageExtensions.BitmapToImageSource(gameData.GameIcon);
            CustomControlArea.Content = gameData.GameCustomControl;
            SetStartButton(gameData.EnumValue);

            Game.Get.SetRunningGameBehavior(GameList.GetGameBehavior(gameData.EnumValue));
        }
Esempio n. 4
0
        private void LeftViewLoadButton_Click(object sender, RoutedEventArgs e)
        {
            #region drawing extension functions test

            var img = ImageExtensions.BuildImage(Game.Get.TileManager.Tiles);
            img.DrawLine(new Vector2(10, 10), new Vector2(20, 15), 1, Colors.Blue());

            img.DrawRectangle(new Vector2(18, 18), 5, 7, false, 1, Colors.MediumPurple());
            img.DrawRectangle(new Vector2(14, 13), 2, 4, true, 1, Colors.HotPink());

            img.DrawCircle(new Vector2(25, 25), 5, false, 1, Colors.Black());
            img.DrawCircle(new Vector2(25, 10), 5, true, 1, Colors.White());

            var polygonPoints1 = new List <Vector2>()
            {
                new Vector2(10, 1), new Vector2(10, 30), new Vector2(30, 3)
            };
            var polygonPoints2 = new List <Vector2>()
            {
                new Vector2(4, 4), new Vector2(4, 7), new Vector2(7, 7)
            };
            img.DrawPolygon(polygonPoints1, false, 1, Colors.BrightBlue());
            img.DrawPolygon(polygonPoints2, true, 1, Colors.Green());

            img.DrawText(new Vector2(12, 20), "1", 15, Colors.Red());

            var bitmapImage = ImageExtensions.GetBitmapFromPath("Media/Testing/TestDrawnImage2.png");
            img.DrawImage(new Vector2(3, 20), bitmapImage);

            #endregion

            //img.Save("image.png",ImageFormat.Png);
            //Variable used to load the image in online so it can be copied and checked using https://codebeautify.org/base64-to-image-converter.
            //var strval = Convert.ToBase64String(ImageExtensions.ToByteArray(img));
            //LeftViewContainer.Source = ImageExtensions.BitmapToImageSource(img);
            var controlImage = new CustomImage
            {
                Source = ImageExtensions.BitmapToImageSource(img)
            };
            Main.GetDispatcher.Invoke(PopulateCanvasControlDelegate, LeftViewContainer, new List <CustomImage> {
                controlImage
            }, false);
        }
Esempio n. 5
0
        public void SelectTile(CustomImage customImage)
        {
            if (selectedImage != null && selectedImage.TileData.TileId == customImage.TileData.TileId)
            {
                var customImg = ImageExtensions.GetIndividualSensorVisual(selectedImage.TileData, true);
                selectedImage.Source = customImg.Source;
                selectedImage        = null;
            }
            else if (selectedImage != null)
            {
                var selectedX   = Convert.ToInt32(selectedImage.InCanvasPosition.X);
                var selectedY   = Convert.ToInt32(selectedImage.InCanvasPosition.Y);
                var selectedPos = selectedImage.TileData.Position;
                var customX     = Convert.ToInt32(customImage.InCanvasPosition.X);
                var customY     = Convert.ToInt32(customImage.InCanvasPosition.Y);
                var customPos   = customImage.TileData.Position;

                imagesList[selectedX][selectedY] = customImage;
                imagesList[selectedX][selectedY].InCanvasPosition = new Point(selectedX, selectedY);
                tileDataList[selectedX, selectedY]          = customImage.TileData;
                tileDataList[selectedX, selectedY].Position = customPos;

                imagesList[customX][customY] = selectedImage;
                imagesList[customX][customY].InCanvasPosition = new Point(customX, customY);
                tileDataList[customX, customY]          = selectedImage.TileData;
                tileDataList[customX, customY].Position = selectedPos;

                var customImg = ImageExtensions.GetIndividualSensorVisual(selectedImage.TileData, true);
                imagesList[customX][customY].Source = customImg.Source;
                selectedImage = null;
            }
            else
            {
                selectedImage = customImage;
                var bmp = new Bitmap(12, 12);
                bmp.DrawRectangle(Vector2.Zero(), 15, 15, true, 2, Color.Red);
                bmp.DrawText(new Vector2(0, 0), customImage.TileData.TileId.ToString(), 8, Color.Blue);
                selectedImage.Source = ImageExtensions.BitmapToImageSource(bmp);
            }
        }
Esempio n. 6
0
 public CustomImage(Bitmap bitmap) : base()
 {
     Source = ImageExtensions.BitmapToImageSource(bitmap);
 }