Example #1
0
        /// <summary>
        ///     Removes the selected image from queue.
        /// </summary>
        private void RemoveSelectedImageFromQueue()
        {
            if (DataGridImgConvertQueue?.SelectedRows.Count == 0)
            {
                Log.Debug("Remove input queue item failed because no grid view items where selected.");
                return;
            }


            var messageQueue = EventMessageQueue.CreateEventMessageQueue();
            var selectedRows = DataGridImgConvertQueue.SelectedRows;

            foreach (DataGridViewRow row in selectedRows)
            {
                if (row.DataBoundItem is ImageModel model)
                {
                    if (!_userConfigService.RemoveImageFromProcessQueue(model.UniqueId, ref messageQueue))
                    {
                        foreach (string message in messageQueue.GetMessageEnumerable())
                        {
                            MessageBox.Show(message, "Failed to remove enqueued item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }

            imageModelBindingSource.SuspendBinding();
            imageModelBindingSource.DataSource = _userConfigService.Config.ImageModels;
            imageModelBindingSource.Sort       = "SortOrder";
            imageModelBindingSource.ResetBindings(true);
            imageModelBindingSource.ResumeBinding();
        }
Example #2
0
        /// <summary>
        ///     Adds the images using file open dialog.
        /// </summary>
        private void AddImagesUsingFileOpenDialog()
        {
            var settings = _applicationSettingsService.Settings;

            if (!string.IsNullOrEmpty(settings.InputDirectory) && Directory.Exists(settings.InputDirectory))
            {
                openFileDialog.InitialDirectory = settings.InputDirectory;
            }

            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                var selectedFiles = openFileDialog.FileNames.ToList();
                var messageQueue  = EventMessageQueue.CreateEventMessageQueue();

                foreach (string filePath in selectedFiles)
                {
                    // validation for filepath being unique.
                    bool isValid = _userConfigService.AddImageToProcessQueue(filePath, ref messageQueue);

                    if (!isValid)
                    {
                        foreach (string message in messageQueue.GetMessageEnumerable())
                        {
                            MessageBox.Show(message, "Failed to add image", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }

                if (selectedFiles.Count > 0)
                {
                    string inputDir = settings.InputDirectory;
                    settings.InputDirectory = Path.GetDirectoryName(selectedFiles[selectedFiles.Count - 1]);

                    if (inputDir != settings.InputDirectory)
                    {
                        _applicationSettingsService.SaveSettings();
                    }
                }

                imageModelBindingSource.SuspendBinding();
                imageModelBindingSource.DataSource = _userConfigService.Config.ImageModels;
                imageModelBindingSource.Sort       = "SortOrder";
                imageModelBindingSource.ResumeBinding();
                imageModelBindingSource.ResetBindings(true);
            }
        }
Example #3
0
        /// <summary>
        /// Adds the image to process queue.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="eventMessageQueue">The event message queue.</param>
        /// <returns></returns>
        public bool AddImageToProcessQueue(string filePath, ref EventMessageQueue eventMessageQueue)
        {
            try
            {
                // Validate access and existence
                if (!File.Exists(filePath))
                {
                    eventMessageQueue.AddMessage($"{filePath} - A file with specified path does not exist");
                    return(false);
                }

                // Validate uniqueness
                if (_userConfig.ImageModels.Any(x => x.FilePath.Equals(filePath, StringComparison.CurrentCultureIgnoreCase)))
                {
                    eventMessageQueue.AddMessage($"{filePath} - Is already added to the process queue.");
                    return(false);
                }


                var model = ImageModel.CreateImageModel(filePath);
                var fi    = new FileInfo(filePath);

                model.SortOrder     = GetNextSortOrder();
                model.FileName      = fi.Name;
                model.CreationTime  = fi.CreationTime;
                model.Extension     = fi.Extension;
                model.DirectoryName = fi.DirectoryName;
                model.FileSize      = fi.Length;
                model.Size          = FileNameParser.GetFileSizeWithPrefix(model.FileSize);

                model.DisplayName = $"FileName: {model.FileName}, Size{model.Size}";
                _userConfig.ImageModels.Add(model);

                RebuildSortIndex();

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "AddImageToProcessQueue threw an exception", nameof(filePath));
                eventMessageQueue.AddMessage(ex.Message);
            }

            return(false);
        }
Example #4
0
        /// <summary>
        /// Removes the image from process queue.
        /// </summary>
        /// <param name="imageGuid">The image unique identifier.</param>
        /// <param name="messageQueue">The message queue.</param>
        /// <returns></returns>
        public bool RemoveImageFromProcessQueue(Guid imageGuid, ref EventMessageQueue messageQueue)
        {
            if (_userConfig.ImageModels.All(x => x.UniqueId != imageGuid))
            {
                messageQueue.AddMessage($"Could not remove item from list, list sync error?");
                return(false);
            }

            var  model  = _userConfig.ImageModels.First(x => x.UniqueId == imageGuid);
            bool result = _userConfig.ImageModels.Remove(model);

            if (result)
            {
                RebuildSortIndex();
            }

            return(result);
        }
Example #5
0
        public void Update(GameTime gameTime)
        {
            _previouseMouseState = _currentMouseState;
            _currentMouseState   = Mouse.GetState();
            _mousePos            = Mouse.GetState().Position.ToVector2();

            // clicked on undo button.
            if (_currentMouseState.LeftButton == ButtonState.Pressed &&
                _previouseMouseState.LeftButton == ButtonState.Released &&
                _undoButtonRec.Contains(_currentMouseState.Position))
            {
                EventMessageQueue.Add(new QueueMessage()
                {
                    DisplayTime = 1.5f,
                    Message     = "Removed tower"
                });
                BuildManager.RemoveLastBuiltTower(GetTowerCostFromType(_towerType));
            }

            if (!_dragging)
            {
                if (_currentMouseState.LeftButton == ButtonState.Pressed &&
                    _previouseMouseState.LeftButton == ButtonState.Released &&
                    _basicTowerSelectBox.Contains(_currentMouseState.Position))
                {
                    EventMessageQueue.Add(new QueueMessage()
                    {
                        DisplayTime = 1.5f,
                        Message     = "Creating basic tower"
                    });
                    _dragging  = true;
                    _towerType = TowerType.Basic;
                    CreateNewTower(_basicTowerExample);
                }
                else if (_currentMouseState.LeftButton == ButtonState.Pressed &&
                         _previouseMouseState.LeftButton == ButtonState.Released &&
                         _fireTowerSelectBox.Contains(_currentMouseState.Position))
                {
                    EventMessageQueue.Add(new QueueMessage()
                    {
                        DisplayTime = 1.5f,
                        Message     = "Creating fire tower"
                    });
                    _dragging  = true;
                    _towerType = TowerType.Fire;
                    CreateNewTower(_fireTowerExample);
                }
            }

            if (_dragging)
            {
                _draggedSprite.Position = _mousePos;

                if (_currentMouseState.LeftButton == ButtonState.Released &&
                    _previouseMouseState.LeftButton == ButtonState.Pressed)
                {
                    if (Level.Buy(GetTowerCostFromType(_towerType)))
                    {
                        BuildManager.CreateTower(_towerType, GetTextureFromType(_towerType), _mousePos);
                    }
                    else
                    {
                        EventMessageQueue.Add(new QueueMessage()
                        {
                            DisplayTime = 2.5f,
                            Message     = "Not enough gold to buy this tower.",
                        });
                    }

                    _draggedSprite = null;
                    _dragging      = false;
                }
            }
        }
Example #6
0
        public override void LoadContent()
        {
            // load textures.
            _gameMap            = _content.Load <Texture2D>("bg");
            _basicTowerTexture  = _content.Load <Texture2D>("tower1");
            _fireTowerTexture   = _content.Load <Texture2D>("firetower");
            _missileTexture     = _content.Load <Texture2D>("missile");
            _fireMissileTexture = _content.Load <Texture2D>("firemissile");
            _hudTexture         = _content.Load <Texture2D>("builderhud");
            _undoButton         = _content.Load <Texture2D>("undo");
            _healthTexture      = _content.Load <Texture2D>("health");

            // load animation textures.
            _enemy1WalkingTextures = new List <Texture2D>
            {
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_000"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_001"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_002"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_003"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_004"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_005"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_006"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_007"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_008"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_009"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_010"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_011"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_012"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_013"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_014"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_015"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_016"),
                _content.Load <Texture2D>("Golem_01_Walking/Golem_01_Walking_017")
            };
            _enemy2WalkingTextures = new List <Texture2D>
            {
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_000"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_001"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_002"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_003"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_004"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_005"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_006"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_007"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_008"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_009"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_010"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_011"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_012"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_013"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_014"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_015"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_016"),
                _content.Load <Texture2D>("Golem_02_Walking/Golem_02_Walking_017")
            };
            _explosionTextures = new List <Texture2D>
            {
                _content.Load <Texture2D>("Explosion/explosion_1"),
                _content.Load <Texture2D>("Explosion/explosion_2"),
                _content.Load <Texture2D>("Explosion/explosion_3"),
                _content.Load <Texture2D>("Explosion/explosion_4"),
                _content.Load <Texture2D>("Explosion/explosion_5"),
                _content.Load <Texture2D>("Explosion/explosion_6"),
                _content.Load <Texture2D>("Explosion/explosion_7"),
            };

            // load fonts.
            _font = _content.Load <SpriteFont>("game");

            // set textures to use throughout the game.
            TextureHelper.HealthTexture      = _healthTexture;
            TextureHelper.BasicTowerTexture  = _basicTowerTexture;
            TextureHelper.FireTowerTexture   = _fireTowerTexture;
            TextureHelper.HudTexture         = _hudTexture;
            TextureHelper.UndoButtonTexture  = _undoButton;
            TextureHelper.MissileTexture     = _missileTexture;
            TextureHelper.FireMissileTexture = _fireMissileTexture;

            // animation textures
            TextureHelper.Enemy1WalkingTextures = _enemy1WalkingTextures;
            TextureHelper.Enemy2WalkingTextures = _enemy2WalkingTextures;
            TextureHelper.ExplosionTextures     = _explosionTextures;

            // initialize managers.
            _enemyManager     = new EnemyManager();
            _missileManager   = new MissileManager();
            _buildManager     = new BuildManager();
            _explosionManager = new ExplosionManager();

            // initialize helpers
            _builderHud         = new LevelBuilderHUD();
            _collisionDetection = new CollisionDetection();
            _eventMessageQueue  = new EventMessageQueue();

            var storage = _sessionStorageProvider.GetFromSessionStorage(TowerDefence.GameKey);

            storage.GoldEarned = Level.Level1.Gold;

            Init();
        }