Beispiel #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);
        }
Beispiel #2
0
        private void HandleClicks(object sender, EventArgs e)
        {
            Control control = (Control)sender;

            if (control.Name.Contains("CustomButton"))
            {
                if (ruler.IsGameStarted)
                {
                    ruler.OpenCard(control.Name);
                }
                else
                {
                    var card            = buttonManager.ButtonsCollection().GetCustomButtonByName(control.Name);
                    var imageCollection = libManager.GetImageCollection();
                    var customImage     = imageCollection.FirstOrDefault(n => n.Image == card.Image);

                    if (customImage != null && customImage.AllowUpdate)
                    {
                        var newImage = customImageCollectionConfigurator.UpdateImage(customImage);
                        buttonManager.RefreshButtonImage(card, newImage);
                        SoundPlayer.PlayButtonSound();
                    }
                    else
                    {
                        SoundPlayer.PlayCannotOpenCardSound();
                        messageBar.Set("Нажмите ESC чтобы войти в меню");
                        messageBar.Show(3000, true);
                    }
                }
            }
        }
Beispiel #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);
        }
Beispiel #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();
            }
        }
Beispiel #5
0
        private async void BtnKick_Click(object sender, EventArgs e)
        {
            try
            {
                if (lbxUsers.SelectedIndex >= 0)
                {
                    for (int i = 0; i < clientList.Count; i++)
                    {
                        if (clientList[i].ClientNickname.Equals(lbxUsers.Items[lbxUsers.SelectedIndex])) //Find which client is selected for kicking
                        {
                            TcpClient client = clientList[i].Client;

                            byte[] message = Encoding.UTF8.GetBytes("K-D"); //Tell the client that they are getting kicked
                            await client.GetStream().WriteAsync(message, 0, message.Length);

                            client.Close(); //Close the connection, remove the client from the user-lists, and tell the others that the user has disconnected

                            //MessageBox.Show(this, clientList[i].ClientNickname + " has been kicked from the server.", "User Kicked", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            asyncPopUp.Set(clientList[i].ClientNickname + " has been kicked from the server.", "User Kicked", 5000);
                            asyncPopUp.Show();

                            lbxConsole.Items.Add(DateTime.Now + ": Client with ip " + clientList[i].ClientIP + " and username " + clientList[i].ClientNickname + " disconnected");
                            clientList.RemoveAt(i);
                            clientListLight.RemoveAt(i);
                            UpdateUserList();

                            for (int m = 0; m < clientList.Count; m++)
                            {
                                SendUserList(clientList[m].Client);
                            }

                            break;
                        }
                    }
                }
                else
                {
                    //MessageBox.Show(this, "Please select a user to kick!", "Select User", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    asyncPopUp.Set("Please select a user to kick!", "Select User", 5000);
                    asyncPopUp.Show();
                }
            }
            catch (Exception e2)
            {
                ErrorHandle(e2);
            }
        }
        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();
            }
        }
Beispiel #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);
        }
Beispiel #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);
         }
     }
 }
Beispiel #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();
                }
            }
        }
Beispiel #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();
            }
        }
Beispiel #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);
                }
            }
        }
Beispiel #12
0
        private void IsBroadcastReceived(object sender, EventArgs e)
        {
            if (broadcastReceived) //Function is triggered by a periodic timer. If the broadcast is received, connect to the server and stop the timer
            {
                ConnectToServer();
                isBroadcastReceivedTimer.Stop();
                secondsSinceConnectAttempt = 0;
                broadcastReceived          = false;
            }
            else
            {
                secondsSinceConnectAttempt++;

                if (secondsSinceConnectAttempt >= 3)
                {
                    //MessageBox.Show(this, "Connecting to the server is taking longer than expected. Make sure that you are connected to the same network as the server, and that your firewall is not blocking the client or the server. The server might have joining turned off, or be turned off. Try again later, or after checking afforementioned factors.", "Delay in Joining", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    asyncPopUp.Set("Connecting to the server is taking longer than expected. Make sure that you are connected to the same network as the server, and that your firewall is not blocking the client or the server. The server might have joining turned off, or be turned off. Try again later, or after checking afforementioned factors.", "Delay in Joining", 5000);
                    asyncPopUp.Show();

                    secondsSinceConnectAttempt = -7;
                    btnLeave.Enabled           = true;
                }
            }
        }
Beispiel #13
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;
        }
Beispiel #14
0
 public void UpdateStatusMessage(string updateMessage)
 {
     messageBar?.HideForm();
     messageBar?.Set(updateMessage, FormStartPosition.CenterScreen);
     messageBar?.Show(autoHide: false);
 }