Exemple #1
0
 // Raises the button click event, from the panel specified at the index (of children) specified.
 private void RaiseButtonClickEvent(PanelButton pButton)
 {
     if (pButton != null)
     {
         Button btn = (pButton.ChildrenButtonIndex < 0 ? FindName(pButton.PanelBaseName) :
                       this.FindPanel(pButton.PanelBaseName, GamePivot.HUMAN_INDEX).Children[pButton.ChildrenButtonIndex]) as Button;
         btn.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
     }
 }
Exemple #2
0
        // Restrict possible discards on the specified selection of tiles.
        private PanelButton RestrictDiscardWithTilesSelection(IDictionary <TilePivot, bool> tileChoices, RoutedEventHandler handler)
        {
            PanelButton result = null;

            SetActionButtonsVisibility();

            List <Button> buttons = StpHandP0.Children.OfType <Button>().ToList();

            if (StpPickP0.Children.Count > 0)
            {
                buttons.Add(StpPickP0.Children[0] as Button);
            }

            var clickableButtons = new List <Button>();

            foreach (TilePivot tileKey in tileChoices.Keys)
            {
                // Changes the event of every buttons concerned by the call...
                Button buttonClickable = buttons
                                         .Where(b => b.Tag as TilePivot == tileKey)
                                         .OrderBy(b => (b.Tag as TilePivot).IsRedDora) // in case of autoplay, we don't want the red dora discarded where there's a not-red tile
                                         .First();
                buttonClickable.Click += handler;
                buttonClickable.Click -= BtnDiscard_Click;
                if (handler == BtnChiiChoice_Click)
                {
                    buttonClickable.Tag = new Tuple <TilePivot, bool>(tileKey, tileChoices[tileKey]);
                }
                buttonClickable.Style = FindResource("StyleHighlightTile") as Style;
                clickableButtons.Add(buttonClickable);
            }

            // ...and disables every buttons not concerned.
            buttons.Where(b => !clickableButtons.Contains(b)).All(b => { b.IsEnabled = false; return(true); });

            if (clickableButtons.Count == 1)
            {
                // Only one possibility : initiates the auto-discard.
                int buttonIndexInHandPanel = StpHandP0.Children.IndexOf(clickableButtons[0]);
                if (buttonIndexInHandPanel >= 0)
                {
                    result = new PanelButton("StpHandP", buttonIndexInHandPanel);
                }
                else
                {
                    result = new PanelButton("StpPickP", 0);
                }
            }
            else
            {
                _waitForDecision = true;
                ActivateTimer(clickableButtons[0]);
            }

            return(result);
        }