Example #1
0
        private void InternalUpdateCardReview(CardNameLocation location, List <CardGuess> cardGuesses)
        {
            currentCardGuessesByLocation[location] = cardGuesses;

            var name      = GetBestGuessLabelName(location);
            var myTextBox = (Button)this.FindName(name);

            myTextBox.Visibility = Visibility.Visible;

            var commentsButton = (Button)this.FindName(GetSearchButtonName(location));

            commentsButton.Visibility = Visibility.Visible;

            float rating = float.Parse(cardGuesses.Last().Review.AverageRating, CultureInfo.InvariantCulture.NumberFormat);

            myTextBox.Background = backgroundBrush;
            myTextBox.Foreground = new SolidColorBrush(Utils.GetMediaColorFromDrawingColor(Utils.GetColorForRating((decimal)rating)));


            myTextBox.Content = cardGuesses.Last().Review.ToString() + (cardGuesses.Count > 1 ? "*" : "");
            Utils.UpdateFontSizeToFit(myTextBox);

            if (DraftScreen.GetCardNameLocationsAvailable(draftPickNumber).Last().Equals(location))
            {
                latestStoryboardRefreshButton.Stop(this);
            }
        }
Example #2
0
        private void MakeCardReviewLabel(CardNameLocation location)
        {
            Button bestGuessLabel = new Button
            {
                Name                = GetBestGuessLabelName(location),
                Style               = (Style)Resources["MyButtonStyle"],
                Content             = "Loading..",
                HorizontalAlignment = HorizontalAlignment.Left,
                Width               = 175,
                Height              = 30,
                Background          = new SolidColorBrush(Colors.White)
                {
                    Opacity = 0.1f
                },
                Foreground      = new SolidColorBrush(Colors.White),
                BorderThickness = new Thickness(0),
                FontSize        = 13,
                Visibility      = Visibility.Hidden,
                FontWeight      = FontWeights.Bold
            };

            Canvas.SetLeft(bestGuessLabel, location.Rect.Left - 10);
            Canvas.SetTop(bestGuessLabel, location.Rect.Top - 200);
            MainCanvas.Children.Add(bestGuessLabel);
            MainCanvas.RegisterName(bestGuessLabel.Name, bestGuessLabel);
            bestGuessLabel.PreviewMouseDown += OnMainLabelClick;
        }
Example #3
0
        public CardRecognitionTask(CardNameLocation nameLoc)
        {
            nameLocation = nameLoc;

            scaleFactor = INITIAL_SCALE_FACTOR;

            locationString = $"{nameLoc.Row}x{nameLoc.Column}";
            scaledTempFile = string.Format(TEMP_FILE_PATTERN, locationString);
        }
Example #4
0
 private void UpdateCardReview(CardNameLocation location, List <CardGuess> cardGuesses)
 {
     try
     {
         Application.Current.Dispatcher.BeginInvoke(
             DispatcherPriority.Normal,
             (Action)(() => InternalUpdateCardReview(location, cardGuesses)));
     }
     catch { /*do nothing*/ }
 }
Example #5
0
        private void UnmakeCardReviewLabel(CardNameLocation location)
        {
            var btn = FindName(GetBestGuessLabelName(location)) as Button;

            if (btn == null)
            {
                return;
            }
            btn.PreviewMouseDown -= OnMainLabelClick;
            MainCanvas.UnregisterName(btn.Name);
            MainCanvas.Children.Remove(btn);
        }
Example #6
0
        private void OnGuessSelected(CardNameLocation location, List <CardGuess> guesses, CardGuess guessSelected)
        {
            guesses.Remove(guessSelected);
            guesses.Add(guessSelected);

            var searchButton = ((Button)this.FindName(GetSearchButtonName(location)));

            OnSearchButtonClick(searchButton, null);

            var mainGuessLabel = ((Button)this.FindName(GetBestGuessLabelName(location)));

            UpdateCardReview(location, guesses);
        }
Example #7
0
        private void OnGuessLabelClick(object sender, MouseButtonEventArgs e)
        {
            TextBox textBox     = ((TextBox)sender);
            string  name        = textBox.Name;
            string  indexString = name.Split(new[] { "guess" }, StringSplitOptions.None).Last();
            int     guessIndex  = Int32.Parse(indexString);

            name = name.Remove(name.Length - indexString.Length);

            CardNameLocation location      = GetLocationFromSecondaryLabelName(name);
            List <CardGuess> guesses       = currentCardGuessesByLocation[location];
            CardGuess        guessSelected = guesses[guessIndex];

            OnGuessSelected(location, guesses, guessSelected);
        }
Example #8
0
        private void SearchCardByName(CardNameLocation location, TextBox editTextSearch)
        {
            string searchedCardName = editTextSearch.Text;

            ReviewDataSource.Instance.cardReviewsByName.TryGetValue(new CardName(searchedCardName), out CardReview reviewFromTextWritten);
            if (reviewFromTextWritten == null)
            {
                return;
            }

            var newGuess = new CardGuess
            {
                Review    = reviewFromTextWritten,
                Certainty = CardGuess.UNCLEAR_CERTAINTY
            };

            OnGuessSelected(location, currentCardGuessesByLocation[location], newGuess);
        }
Example #9
0
        private Action RecognizeForLocation(CardNameLocation location, Screen recognizingScreen, int recognizingPickNumber)
        {
            return(() =>
            {
                var cardGuesses = CardRecognitionManager.Instance.ReadCardName(location);

                if ((cardGuesses == null || cardGuesses.Count == 0) &&
                    currentScreen == recognizingScreen &&
                    recognizingPickNumber == draftPickNumber &&
                    !isPaused &&
                    currentScreen != ForgeScreen.Instance)
                {
                    //we failed the recognition, set a new task for this location for later:
                    Console.WriteLine(Utils.GetSecondsSinceEpoch() + " - we failed the recognition, set a new task for this location for later");
                    Task.Delay(1000).ContinueWith((obj) =>
                    {
                        Console.WriteLine(Utils.GetSecondsSinceEpoch() + " - starting now!");
                        Task.Run(RecognizeForLocation(location, recognizingScreen, recognizingPickNumber));
                    });
                }
                UpdateCardReview(location, cardGuesses);
            });
        }
Example #10
0
        private void InternalUpdateCardReview(CardNameLocation location, HashSet <CardGuess> cardGuesses)
        {
            currentCardGuessesByLocation[location] = cardGuesses;

            var name      = GetBestGuessLabelName(location);
            var myTextBox = FindName(name) as Button;

            if (myTextBox == null)
            {
                return;
            }
            myTextBox.Visibility = Visibility.Visible;

            if (cardGuesses != null)
            {
                float rating = CardReviewForUiUtils.GetRatingForColor(cardGuesses.Last());
                myTextBox.Background = backgroundBrush;
                myTextBox.Foreground = new SolidColorBrush(Utils.GetMediaColorFromDrawingColor(Utils.GetColorForRating((decimal)rating)));

                myTextBox.Content = CardReviewForUiUtils.GetRatingLabel(cardGuesses);
            }
            else
            {
                myTextBox.Background = backgroundBrush;
                myTextBox.Foreground = new SolidColorBrush(Colors.Red);

                myTextBox.Content = (currentScreen.IsForge() ? "N/A or " : "") + "FAILED RECOGNITION";
            }

            Utils.UpdateFontSizeToFit(myTextBox);

            if (currentScreen.GetCardNameLocationsAvailable(draftPickNumber).Last().Equals(location))
            {
                latestStoryboardRefreshButton.Stop(this);
            }
        }
Example #11
0
 private CardNameLocation GetLocationFromSearchCanvasName(string searchCanvasName)
 {
     return(CardNameLocation.FromString(searchCanvasName.Replace("searchCanvas", "")));
 }
Example #12
0
 private static CardNameLocation GetLocationFromSearchButtonName(string btnName)
 {
     return(CardNameLocation.FromString(btnName.Replace("button", "").Replace("search", "")));
 }
Example #13
0
 private static CardNameLocation GetLocationFromBestGuessLabelName(string labelName)
 {
     return(CardNameLocation.FromString(labelName.Replace("label", "").Replace("bestGuess", "")));
 }
Example #14
0
 private CardNameLocation GetLocationFromSecondaryLabelName(string labelName)
 {
     return(CardNameLocation.FromString(labelName.Replace("textbox", "").Replace("guess", "")));
 }
Example #15
0
 private static string GetBestGuessLabelName(CardNameLocation location)
 {
     return("label" + location.ToString() + "bestGuess");
 }
Example #16
0
 private static string GetSearchButtonName(CardNameLocation location)
 {
     return("button" + location.ToString() + "search");
 }
 public List <CardGuess> ReadCardName(CardNameLocation nameLocation, Bitmap bitmap)
 {
     return(ReadCardName(nameLocation, bitmap, 1.59f));
 }
        private List <CardGuess> ReadCardName(CardNameLocation nameLocation, Bitmap bitmap, float scaleFactor)
        {
            //var watch = System.Diagnostics.Stopwatch.StartNew();
            //Console.WriteLine("____________________________________________");
            List <CardGuess> foundCardReviews = new List <CardGuess>();

            string locationString = $"{nameLocation.Row}x{nameLocation.Column}";
            var    scaledTempFile = string.Format(TEMP_FILE_PATTERN, locationString);

            try
            {
                using (var engine = new TesseractEngine(@"tessdata", "eng", EngineMode.Default))
                {
                    Bitmap scaledBitmap = Utils.ScaleBitmap(bitmap, scaleFactor);

                    Directory.CreateDirectory("temp");
                    scaledBitmap.Save(scaledTempFile, System.Drawing.Imaging.ImageFormat.Jpeg);

                    using (var img = Pix.LoadFromFile(scaledTempFile))
                    {
                        using (var page = engine.Process(img))
                        {
                            var found = page.GetText();
                            Console.WriteLine("ORC directly = " + found);
                            var stringResult = Utils.RemoveNewlines(found);

                            if (string.IsNullOrWhiteSpace(stringResult) && scaleFactor < 1.62f)
                            {
                                Console.WriteLine("ORC retrying with more scale");
                                return(ReadCardName(nameLocation, bitmap, scaleFactor + 0.01f));
                            }

                            foundCardReviews = FindBestCardReviewMatches(stringResult);

                            if (foundCardReviews[0].Certainty < 0.5f && scaleFactor < 1.62f)
                            {
                                Console.WriteLine("ORC retrying with more scale");
                                return(ReadCardName(nameLocation, bitmap, scaleFactor + 0.01f));
                            }

                            foreach (var cardReview in foundCardReviews)
                            {
                                if (!string.IsNullOrWhiteSpace(stringResult))
                                {
                                    Console.WriteLine($"{locationString}, OCR= {stringResult}, got possibility || { cardReview }");// || \n{cardReview.getStringOfAllComments()}");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error= {ex.StackTrace}");
            }
            finally
            {
                File.Delete(scaledTempFile);
                //watch.Stop();
                //var elapsedMs = watch.ElapsedMilliseconds;
                //Console.WriteLine($"____________________ {elapsedMs}ms ________________________");
            }
            return(foundCardReviews);
        }
Example #19
0
 public HashSet <CardGuess> ReadCardName(CardNameLocation nameLocation)
 {
     return(new CardRecognitionTask(nameLocation).Recognize());
 }
Example #20
0
        private void OnSearchButtonClick(object sender, RoutedEventArgs e)
        {
            ProcessWindowManager.Instance.ReleaseFocus();
            string           name     = ((Button)sender).Name;
            CardNameLocation location = GetLocationFromSearchButtonName(name);
            List <CardGuess> guesses  = currentCardGuessesByLocation[location];

            StackPanel panel        = this.FindName("panel" + location.ToString() + "otherGuesses") as StackPanel;
            Canvas     searchCanvas = this.FindName("searchCanvas" + location.ToString()) as Canvas;

            if (panel == null)
            {
                if (searchCanvas == null)
                {
                    searchCanvas = new Canvas
                    {
                        Name       = "searchCanvas" + location.ToString(),
                        Width      = 210,
                        Height     = 300,
                        Background = new SolidColorBrush(Colors.Transparent)
                        {
                            Opacity = 0.3f
                        },
                    };
                    Canvas.SetLeft(searchCanvas, location.Rect.Left - 30);
                    Canvas.SetTop(searchCanvas, location.Rect.Top - 175);
                    MainCanvas.Children.Add(searchCanvas);
                    MainCanvas.RegisterName(searchCanvas.Name, searchCanvas);
                }

                panel = new StackPanel
                {
                    Orientation = Orientation.Vertical,
                    Name        = "panel" + location.ToString() + "otherGuesses"
                };
                Canvas.SetLeft(panel, 5); //location.Rect.Left - 30);
                Canvas.SetTop(panel, 5);  // location.Rect.Top - 170);
                searchCanvas.Children.Add(panel);
                searchCanvas.RegisterName(panel.Name, panel);

                StackPanel searchPanel = new StackPanel
                {
                    Orientation = Orientation.Horizontal,
                    Background  = backgroundBrush,
                };
                panel.Children.Add(searchPanel);

                TextBox editTextSearch = new TextBox
                {
                    Width  = 180,
                    Height = 20,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Background          = backgroundBrush,
                    Foreground          = Brushes.Gray,
                    Text            = "Search",
                    BorderThickness = new Thickness(0),
                    Name            = "editText" + location.ToString() + "guess_search",
                };
                editTextSearch.GotKeyboardFocus  += new KeyboardFocusChangedEventHandler(tb_GotKeyboardFocus);
                editTextSearch.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(tb_LostKeyboardFocus);
                editTextSearch.PreviewKeyDown    += (s, eventArgs) =>
                {
                    if (eventArgs.Key == Key.Return)
                    {
                        SearchCardByName(location, editTextSearch);
                        eventArgs.Handled = true;
                    }
                };
                searchPanel.Children.Add(editTextSearch);
                searchPanel.RegisterName(editTextSearch.Name, editTextSearch);
                editTextSearch.Focus();
                ProcessWindowManager.Instance.ForceFocus();

                searchCanvas.MouseLeave     += OnMouseLeaveSearchCanvasEvent;
                ((Button)sender).MouseLeave += OnMouseLeaveSearchCanvasEvent;
                ((Button)FindName(GetBestGuessLabelName(location))).MouseLeave += OnMouseLeaveSearchCanvasEvent;

                var brush = new ImageBrush();
                brush.ImageSource = new BitmapImage(new Uri("Images/search_icon.png", UriKind.Relative));

                Button searchCorrectCardBtn = new Button
                {
                    Name            = "button" + location.ToString() + "search_with_name",
                    Width           = 20,
                    Height          = 20,
                    Background      = brush,
                    BorderThickness = new Thickness(0),
                };
                searchCorrectCardBtn.Click += delegate {
                    SearchCardByName(location, editTextSearch);
                };
                searchPanel.Children.Add(searchCorrectCardBtn);
                searchPanel.RegisterName(searchCorrectCardBtn.Name, searchCorrectCardBtn);

                if (guesses.Count > 1)
                {
                    Border separator = new Border()
                    {
                        Background      = new SolidColorBrush(Colors.White),
                        BorderBrush     = new SolidColorBrush(Colors.White),
                        Height          = 1f,
                        BorderThickness = new Thickness(0.5)
                    };
                    panel.Children.Add(separator);
                }

                for (int i = 0; i < guesses.Count; i++)
                {
                    if (i == guesses.Count - 1)
                    {
                        continue;
                    }
                    CardGuess guess = guesses[i];

                    TextBox guessLabel = this.FindName("textbox" + location.ToString() + "guess" + i) as TextBox;
                    if (guessLabel == null)
                    {
                        guessLabel = new TextBox
                        {
                            Width  = 200,
                            Height = 20,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            TextWrapping        = TextWrapping.Wrap,
                            Background          = backgroundBrush,
                            Foreground          = new SolidColorBrush(Colors.White),
                            CaretBrush          = new SolidColorBrush(Colors.Transparent),
                            BorderThickness     = new Thickness(0),
                            Name = "textbox" + location.ToString() + "guess" + i,
                        };
                        guessLabel.PreviewMouseDown += OnGuessLabelClick;
                    }
                    panel.Children.Add(guessLabel);
                    panel.RegisterName(guessLabel.Name, guessLabel);
                    guessLabel.Text = guess.Review.ToString();
                }
            }
            else
            {
                searchCanvas.MouseLeave     -= OnMouseLeaveSearchCanvasEvent;
                ((Button)sender).MouseLeave -= OnMouseLeaveSearchCanvasEvent;
                ((Button)FindName(GetBestGuessLabelName(location))).MouseLeave -= OnMouseLeaveSearchCanvasEvent;

                foreach (var child in panel.Children)
                {
                    if (child is StackPanel)
                    {
                        foreach (var childDeep in ((StackPanel)child).Children)
                        {
                            if (string.IsNullOrEmpty(((FrameworkElement)childDeep).Name))
                            {
                                continue;
                            }
                            ((StackPanel)child).UnregisterName(((FrameworkElement)childDeep).Name);
                        }
                        continue;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(((FrameworkElement)child).Name))
                        {
                            continue;
                        }
                    }
                    panel.UnregisterName(((FrameworkElement)child).Name);
                }
                panel.Children.Clear();

                MainCanvas.UnregisterName(searchCanvas.Name);
                MainCanvas.Children.Remove(searchCanvas);

                MainCanvas.Children.Remove(panel);
                MainCanvas.UnregisterName(panel.Name);
            }
        }
Example #21
0
        private void MakeCardReviewLabel(CardNameLocation location)
        {
            Button bestGuessLabel = new Button
            {
                Name                = GetBestGuessLabelName(location),
                Style               = (Style)Resources["MyButtonStyle"],
                Content             = "Loading..",
                HorizontalAlignment = HorizontalAlignment.Left,
                Width               = 175,
                Height              = 30,
                Background          = new SolidColorBrush(Colors.White)
                {
                    Opacity = 0.1f
                },
                Foreground      = new SolidColorBrush(Colors.White),
                BorderThickness = new Thickness(0),
                FontSize        = 13,
                Visibility      = Visibility.Hidden,
                FontWeight      = FontWeights.Bold
            };

            Canvas.SetLeft(bestGuessLabel, location.Rect.Left - 10);
            Canvas.SetTop(bestGuessLabel, location.Rect.Top - 200);
            MainCanvas.Children.Add(bestGuessLabel);
            MainCanvas.RegisterName(bestGuessLabel.Name, bestGuessLabel);
            bestGuessLabel.PreviewMouseDown += OnMainLabelClick;

            var brush = new ImageBrush();

            brush.ImageSource = new BitmapImage(new Uri("Images/search_icon.png", UriKind.Relative));

            Canvas searchCorrectCardBtnCanvas = new Canvas()
            {
                Width      = 20,
                Height     = 20,
                Background = new SolidColorBrush(Colors.Black)
                {
                    Opacity = 0.01f
                }
            };

            Canvas.SetLeft(searchCorrectCardBtnCanvas, location.Rect.Left - 30);
            Canvas.SetTop(searchCorrectCardBtnCanvas, location.Rect.Top - 190);
            MainCanvas.Children.Add(searchCorrectCardBtnCanvas);
            searchCorrectCardBtnCanvas.MouseEnter += (s, args) =>
            {
                var btn = searchCorrectCardBtnCanvas.Children[0] as Button;
                btn.Opacity = 1;
            };
            searchCorrectCardBtnCanvas.MouseLeave += (s, args) =>
            {
                var btn = searchCorrectCardBtnCanvas.Children[0] as Button;
                btn.Opacity = 0.2f;
            };

            Button searchCorrectCardBtn = new Button
            {
                Name            = GetSearchButtonName(location),
                Style           = (Style)Resources["MyButtonStyle"],
                Background      = brush,
                Width           = 20,
                Height          = 20,
                Visibility      = Visibility.Hidden,
                BorderThickness = new Thickness(0),
            };

            searchCorrectCardBtn.Click  += OnSearchButtonClick;
            searchCorrectCardBtn.Opacity = 0.2f;

            searchCorrectCardBtnCanvas.Children.Add(searchCorrectCardBtn);
            searchCorrectCardBtnCanvas.RegisterName(searchCorrectCardBtn.Name, searchCorrectCardBtn);
        }