public async Task PostWinnerToLive(CardGuess guess)
        {
            var old = connectionLabel.Text;

            connectionLabel.Text = "POST-ing Winner";

            var jsonDict = new Dictionary <string, object>()
            {
                { "user_id", guess.UserId },
                { "card", guess.Card },
                { "date", guess.Date },
                { "game_id", guess.GameId }
            };

            var json = JsonConvert.SerializeObject(jsonDict);

            var b = new UriBuilder(uriBuilder.Uri)
            {
                Path = Api[1] + "/game/victory"
            };

            var request = new HttpRequestMessage()
            {
                RequestUri = b.Uri,
                Method     = HttpMethod.Post
            };

            request.Content = new StringContent(json, Encoding.UTF8, "application/json");

            request.Headers.Add("Authorization", Auth);

            try
            {
                var res = await client.SendAsync(request);

                if (res.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var q = ClearQueue();

                    // Get the new game.
                    await GetCurrentGame();

                    await q;
                }
                else
                {
                    toolTip.ToolTipTitle = "POST Errored";
                    toolTip.Show("Failed to POST game winner to API. Check JSON data and API logs.", postWinner);
                }
            }
            catch (Exception ex)
            {
                toolTip.ToolTipTitle = "POST Errored";
                toolTip.Show("Failed to POST game winner to API. Check JSON data and API logs.\n" + ex.Message, postWinner);
            }
            finally
            {
                connectionLabel.Text = old;
            }
        }
示例#2
0
        private static string GetCommentsText(CardGuess guess)
        {
            var commentsText = "";

            ReviewDatabase.ReviewDataSource.CardReview review = guess.Review;
            Dictionary <string, string> commentsByReviewer    = review.CommentsByReviewer;
            Dictionary <string, string> ratingsByReviewer     = review.RatingsByReviewer;

            foreach (var reviewer in commentsByReviewer.Keys)
            {
                string comment = commentsByReviewer[reviewer];
                commentsText += reviewer + " (" + ratingsByReviewer[reviewer] + ")";
                if (!string.IsNullOrWhiteSpace(comment))
                {
                    commentsText += ":\n";
                    commentsText += "\"" + comment + "\"\n";
                }
                else
                {
                    commentsText += "\n";
                }
                commentsText += "\n";
            }

            return(commentsText);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
        public static float GetRatingForColor(CardGuess cardGuess)
        {
            if (Settings.Instance.TierListMode == Settings.USE_SUNYVEIL_TIER_LIST)
            {
                return(cardGuess.ReviewByTeam[Team.SUNYVEIL].AverageRatingForColor());
            }

            if (Settings.Instance.TierListMode == Settings.USE_BOTH_TIER_LIST)
            {
                float sunyveilRating = cardGuess.ReviewByTeam[Team.SUNYVEIL].AverageRatingForColor();
                float tdcRating      = cardGuess.ReviewByTeam[Team.TDC].AverageRatingForColor();

                return(sunyveilRating * 2 / 5 + tdcRating * 3 / 5);
            }

            //mode is TDC
            return(cardGuess.ReviewByTeam[Team.TDC].AverageRatingForColor());
        }
示例#6
0
        public static string GetCommentsText(CardGuess cardGuess)
        {
            if (Settings.Instance.TierListMode == Settings.USE_SUNYVEIL_TIER_LIST)
            {
                return(cardGuess.ReviewByTeam[Team.SUNYVEIL].GetCommentsText());
            }

            if (Settings.Instance.TierListMode == Settings.USE_BOTH_TIER_LIST)
            {
                string sunyveil = cardGuess.ReviewByTeam[Team.SUNYVEIL].GetCommentsText();
                string tdc      = cardGuess.ReviewByTeam[Team.TDC].GetCommentsText();

                return("TDC:" + "\n" + tdc + "\n" + sunyveil);
            }

            //mode is TDC
            return(cardGuess.ReviewByTeam[Team.TDC].GetCommentsText());
        }
示例#7
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);
        }
示例#8
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);
            }
        }
        public async Task SaveGuess(CardGuess?guess = null)
        {
            // Make sure all inputs are filled
            if (!await VerifyAllInputsAreFilled())
            {
                return;
            }
            if (CurrentGameId is null)
            {
                return;
            }

            if (winnerCheckBox.Checked)
            {
                // Make sure this is the winning card.
                var res = MessageBox.Show("Are you sure this is the Winning Guess?\n" +
                                          "Marking this guess as the winner will close this game, sync queue data to the server, and make the data un-editibale from the API.\n\n" +
                                          "Press No to store guess in Queue as a noral guess.\n" +
                                          "Press Cancel to remove this guess.\n" +
                                          "Press Yes to continue.\n\n" +
                                          "Guess:\n" +
                                          $"{cardSelector.Text} - {userIdInput.Text} [{dateInput.Text} - {timeInput.Text}]"
                                          , "Confirm Winner", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);

                if (res == DialogResult.No)
                {
                    winnerCheckBox.Checked = false;
                }
                else if (res == DialogResult.No)
                {
                    return;
                }
            }

            // Build the CardGuess object
            if (guess is null)
            {
                guess = new CardGuess();
                Queue.Add(guess);
            }

            // Save values to the guess object.
            guess.Team   = teamSelector.Text;
            guess.Card   = cardSelector.Text;
            guess.Date   = dateInput.Text;
            guess.Time   = timeInput.Text;
            guess.UserId = userIdInput.Text;
            guess.GameId = CurrentGameId ?? -1;

            // And update the queue box.
            await UpdateQueueBox();

            // This time we are sure this is correct, so lets execute the code.
            if (winnerCheckBox.Checked)
            {
                using var lockout = new ToolLockout(this);
                // POST updates
                await PostQueueToLive();

                // POST winner
                await PostWinnerToLive(guess);

                // Then clear the queue data
                var q = ClearQueue();
                // GET the new current game
                await GetCurrentGame();

                await q;
            }

            await ClearEditFields();
        }