示例#1
0
        public CustomImage UpdateImage(CustomImage customImage)
        {
            var width              = customImage.Image.Width;
            var height             = customImage.Image.Height;
            var category           = customImage.Category;
            var name               = customImage.Name;
            var newImageCollection = new List <CustomImage>();

            var popUp = new TimedPopUp();

            popUp.Set("Обновляю изображение...");
            popUp.Show(autoHide: false);

            Image image = imageProvider.SetDefaultSize(width, height).GetImageByCategory(category);

            popUp.HideForm();

            var newImage = new CustomImage
            {
                Name        = $"{name}",
                Category    = category,
                AllowUpdate = true,
                Image       = image
            };

            libManager.RemoveImageFromCollection(customImage);
            newImageCollection.Add(newImage);
            newImageCollection.Add(newImage);
            libManager.InitializeNewCollection(newImageCollection);
            return(newImage);
        }
 public static void CheckSettingsAndContinue()
 {
     if (!IsValid())
     {
         var popUp = new TimedPopUp();
         popUp.ShowCriticalError($"Cannot find appsettings.json" +
                                 $"\nApplication will be closed");
     }
 }
示例#3
0
        public void ShowStatusMessage(string message, bool error = false, bool autoHide = false)
        {
            if (error)
            {
                SoundPlayer.PlayFailedImageSound();
            }

            messageBar = null;
            messageBar = new TimedPopUp();
            messageBar.Set(message, FormStartPosition.CenterScreen);
            messageBar.Show(autoHide: autoHide);
        }
示例#4
0
        public void SaveNewCollection(List <CustomImage> imageCollection, string collectionName, string libPath)
        {
            var collectionPath = Path.Combine(libPath, collectionName);

            if (!IsDirectoryExist(collectionPath))
            {
                SaveImageCollection(libPath, collectionName, imageCollection);

                var popUp = new TimedPopUp();
                popUp.Set("СОХРАНЕНО");
                SoundPlayer.PlaySaveSound();
                popUp.Show();
            }
        }
示例#5
0
        public List <string> GetFiles(string dir)
        {
            List <string> files = null;

            try
            {
                files = Directory.GetFiles(dir).ToList();
            }
            catch (DirectoryNotFoundException e)
            {
                var popUp = new TimedPopUp();
                popUp.ShowCriticalError($"Cannot find directory: " +
                                        $"\n{dir}" +
                                        $"\nCreate the directory and restart app");
            }

            return(files);
        }
        public void UpdateScoreItem(Player player, int score, bool increaseScore)
        {
            try
            {
                var pl = playerScoreList?.FirstOrDefault(n => n.Player == player);

                if (pl.Scores.Count > score)
                {
                    pl.Scores[score].Visible = increaseScore;
                }
            }
            catch (Exception e)
            {
                var popUpNotification = new TimedPopUp();
                popUpNotification.Set(e.Message);
                popUpNotification.Show();
            }
        }
示例#7
0
        public List <string> GetSubDirectories(string dir)
        {
            List <string> subDirectories;

            try
            {
                subDirectories = Directory.GetDirectories(dir, "*.*", SearchOption.TopDirectoryOnly).ToList();
            }
            catch (DirectoryNotFoundException e)
            {
                var popUp = new TimedPopUp();
                popUp.Set("Images directory not found. Creating a new one...");
                popUp.Show();
                Directory.CreateDirectory(dir);
                subDirectories = Directory.GetDirectories(dir, "*.*", SearchOption.TopDirectoryOnly).ToList();
            }


            return(subDirectories);
        }
示例#8
0
 private void ValidateAndSet(List <CustomImage> collection, string category, IDictionary <int, CustomButton> buttons)
 {
     if (collection.Count < buttons.Count)
     {
         if (category != null)
         {
             var message      = $"Insufficient images with category {category}";
             var popUpMessage = new TimedPopUp();
             popUpMessage.Set(message);
             popUpMessage.Show(3500);
         }
     }
     else
     {
         foreach (var button in buttons)
         {
             var customImage = collection[button.Value.Id - 1];
             button.Value.SetImage(customImage.Image);
         }
     }
 }
示例#9
0
        public void DeleteCollection(string collectionName, string libPath)
        {
            var collectionPath = Path.Combine(libPath, collectionName);

            if (IsDirectoryExist(collectionPath))
            {
                try
                {
                    Directory.Delete(collectionPath, true);
                    var popUp = new TimedPopUp();
                    popUp.Set($"Удалено");
                    popUp.Show();
                }
                catch (Exception e)
                {
                    var popUp = new TimedPopUp();
                    popUp.Set($"Failed to delete file. {e.Message}");
                    popUp.ShowError();
                }
            }
        }
示例#10
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            SaveImage();

            var collection = paintLibrary.GetCollection();

            if (collection.Count == 32)
            {
                foreach (var customImage in collection)
                {
                    customImage.Image = new Bitmap(customImage.Image, new Size(170, 180));
                }

                imageCollection = collection;
                BackToSettings();
            }
            else
            {
                var popUp = new TimedPopUp();
                popUp.Set("Не все изображения готовы для коллекции");
                popUp.Show();
            }
        }
示例#11
0
        private void CheckGameStatus()
        {
            if (buttonManager.ExistingButtonsOnBoard() == 0)
            {
                var inGamePlayers = players.GetPlayers().Where(n => n.InGame).ToList();

                Player winner = inGamePlayers[0];
                bool   drawn  = false;

                foreach (var player in inGamePlayers)
                {
                    if (player.DiscoveredCards > winner.DiscoveredCards)
                    {
                        winner = player;
                        drawn  = false;
                    }
                    if (player != winner && player.DiscoveredCards == winner.DiscoveredCards)
                    {
                        drawn = true;
                    }
                }

                GameFinished = true;
                StopGame();

                if (!drawn)
                {
                    ShowWinnerScreen(winner);
                }
                else
                {
                    var popUp = new TimedPopUp();
                    popUp.Set("НИЧЬЯ !");
                    popUp.Show(waitTime: 4500, autoHide: true);
                }
            }
        }
示例#12
0
        private void CustomPaintButton_Click(object sender, EventArgs e)
        {
            SoundPlayer.PlaySettingsSound();

            bool needReset            = false;
            ConfirmDialogForm confirm = null;

            if (ruler.IsGameStarted)
            {
                confirm   = GetConfirmStatus("Сбросить игру?");
                needReset = confirm.Yes;
            }
            else
            {
                needReset = true;
            }

            if (needReset)
            {
                ResetGame();

                var collectionNameDialog = new CustomCollectionNameDialogForm();
                collectionNameDialog.StartPosition         = FormStartPosition.Manual;
                collectionNameDialog.Location              = this.Location;
                collectionNameDialog.StartPosition         = FormStartPosition.CenterParent;
                collectionNameDialog.BackgroundImageLayout = ImageLayout.Stretch;
                this.Enabled = false;
                collectionNameDialog.ShowDialog(this);
                this.Enabled = true;

                var newCollectionName = collectionNameDialog.GetCollectionName();

                if (libManager.GetCategories().Contains(newCollectionName))
                {
                    baseForm.ShowStatusMessage($"Коллекция {newCollectionName} уже существует", error: true, true);
                    return;
                }

                if (!string.IsNullOrEmpty(newCollectionName))
                {
                    var collectionPath = Path.Combine(libManager.LibraryPath, newCollectionName);
                    if (fileManager.IsDirectoryExist(collectionPath))
                    {
                        var popUpMessage = new TimedPopUp();
                        popUpMessage.Set($"Коллекция {newCollectionName} уже существует");
                        popUpMessage.ShowError(3000);
                        this.Invoke((Action)(() => this.Enabled = true));
                        return;
                    }

                    collectionNameDialog.Dispose();
                    collectionNameDialog = null;
                    paintForm            = new PaintForm(this, baseForm, newCollectionName);

                    new Thread(() =>
                    {
                        this.Invoke((Action)(() => paintForm.StartPosition = FormStartPosition.Manual));
                        this.Invoke((Action)(() => paintForm.Location = this.Location));
                        this.Invoke((Action)(() => paintForm.StartPosition = FormStartPosition.CenterParent));
                        this.Invoke((Action)(() => paintForm.BackgroundImageLayout = ImageLayout.Stretch));
                        this.Invoke((Action)(() => this.Enabled = false));
                        this.Invoke((Action)(() => paintForm.ShowDialog(this)));
                        List <CustomImage> newCollection = paintForm.GetCollection();
                        SaveCustomImageCollection(newCollectionName, newCollection);
                        this.Invoke((Action)(() => CategoryComboBox.DataSource = libManager.GetCategories().ToList()));
                        this.Invoke((Action)(() => CategoryComboBox.SelectedIndex = CategoryComboBox.FindStringExact(newCollectionName)));
                        paintForm.Dispose();
                        paintForm = null;
                        this.Invoke((Action)(() => this.Enabled = true));
                    }).Start();
                }
            }

            confirm?.Dispose();
            this.Enabled = true;
        }