Exemple #1
0
 // Button für Rücksetzung aller Canvas Elemente
 private void Reset_Click(object sender, RoutedEventArgs e)
 {
     if (Player1.IsChecked == true)
     {
         foreach (CharakterToken unit in spielerFiguren)
         {
             GameMap.Children.Remove(unit);
             all.Remove(unit);
             Initiativetracker.RemoveInitElement(unit.InitiativeMember);
         }
         spielerFiguren.Clear();
     }
     if (Ally1.IsChecked == true)
     {
         foreach (CharakterToken unit in allies)
         {
             GameMap.Children.Remove(unit);
             all.Remove(unit);
             Initiativetracker.RemoveInitElement(unit.InitiativeMember);
         }
         allies.Clear();
     }
     if (Foes.IsChecked == true)
     {
         foreach (CharakterToken unit in monster)
         {
             GameMap.Children.Remove(unit);
             all.Remove(unit);
             Initiativetracker.RemoveInitElement(unit.InitiativeMember);
         }
         monster.Clear();
     }
     if (ArtDraw.IsChecked == true)
     {
         GameMap.Strokes.Clear();
     }
     InitiativeUpdate();
 }
Exemple #2
0
        // Button für Erstellung einer Spielfigur
        private void CharButton_Click(object sender, RoutedEventArgs e)
        {
            int   size             = 0;
            int   side             = 0;
            Brush affiliationColor = Brushes.Gray;

            // Check und Erstellung der Spielfiguren auf dem Canvas
            if ((bool)Player.IsChecked)
            {
                size             = (int)CreatureSize.Medium;
                side             = (int)Affiliation.Player;
                affiliationColor = Brushes.Green;
            }
            else if ((bool)Ally.IsChecked)
            {
                size             = (int)CreatureSize.Medium;
                side             = (int)Affiliation.Ally;
                affiliationColor = Brushes.SlateBlue;
            }
            else if ((bool)FoeM.IsChecked)
            {
                size             = (int)CreatureSize.Medium;
                side             = (int)Affiliation.Foe;
                affiliationColor = Brushes.Red;
            }
            else if ((bool)FoeL.IsChecked)
            {
                size             = (int)CreatureSize.Large;
                side             = (int)Affiliation.Foe;
                affiliationColor = Brushes.Red;
            }
            else
            {
                size             = (int)CreatureSize.ExtraLarge;
                side             = (int)Affiliation.Foe;
                affiliationColor = Brushes.Red;
            }

            CharakterToken Unit = new CharakterToken(MapSquareSize, ++IDStarter, UnitName.Text, side, size)
            {
                Background      = affiliationColor,
                BorderThickness = new Thickness(4, 4, 4, 4),
                BorderBrush     = UnitBorder,
                CornerRadius    = new CornerRadius(100),
            };

            Unit.InitiativeMember = Initiativetracker.InitiativeMemberCreator(Unit);

            Point startPunkt = new Point(180, 60);

            //Unit.TokenID = IDStarter++;

            // Check und Erstellung der Spielfiguren auf dem Canvas
            if ((bool)Player.IsChecked)
            {
                spielerFiguren.Add(Unit);
            }
            else if ((bool)Ally.IsChecked)
            {
                allies.Add(Unit);
            }
            else
            {
                monster.Add(Unit);
            }

            all.Add(Unit);

            // Drag&Drop Eventhandler für die Spielfiguren
            MouseButtonEventHandler mouseDown = (sendert, args) => {
                var element = (UIElement)sendert;
                distance.X1 = InkCanvas.GetLeft(element) + (element.RenderSize.Width / 2);
                distance.Y1 = InkCanvas.GetTop(element) + (element.RenderSize.Height / 2);
                dragStart   = args.GetPosition(element);
                element.CaptureMouse();
            };
            MouseButtonEventHandler mouseUp = (sendert, args) => {
                var element = (UIElement)sendert;
                distance.Visibility       = Visibility.Collapsed;
                distanceValue.Visibility  = Visibility.Collapsed;
                distanceValue2.Visibility = Visibility.Collapsed;
                dragStart   = null;
                distance.X1 = 0;
                distance.Y1 = 0;
                distance.X2 = 0;
                distance.Y2 = 0;
                element.ReleaseMouseCapture();
            };
            MouseEventHandler mouseMove = (sendert, args) => {
                if (dragStart != null && args.LeftButton == MouseButtonState.Pressed)
                {
                    string distanceText = (Math.Round(((Math.Sqrt(Math.Pow(Math.Abs(distance.X1 - distance.X2), 2) + Math.Pow(Math.Abs(distance.Y1 - distance.Y2), 2))) / 40), 2)).ToString() + " m";
                    var    element      = (UIElement)sendert;
                    var    p2           = args.GetPosition(GameMap);

                    InkCanvas.SetLeft(element, p2.X - dragStart.Value.X);
                    InkCanvas.SetTop(element, p2.Y - dragStart.Value.Y);
                    distance.Visibility = Visibility.Visible;
                    distance.X2         = InkCanvas.GetLeft(element) + (element.RenderSize.Width / 2);
                    distance.Y2         = InkCanvas.GetTop(element) + (element.RenderSize.Height / 2);

                    distanceValue.Text        = distanceText;
                    distanceValue2.Text       = distanceText;
                    distanceValue.FontSize    = 16;
                    distanceValue.Visibility  = Visibility.Visible;
                    distanceValue2.Visibility = Visibility.Visible;
                    InkCanvas.SetLeft(distanceValue, (Math.Abs(distance.X1 + distance.X2) / 2) + 15);
                    InkCanvas.SetTop(distanceValue, (Math.Abs(distance.Y1 + distance.Y2) / 2) - 30);
                }
            };
            MouseButtonEventHandler mouseRightClick = (sendert, args) =>
            {
                Initiativetracker.RemoveInitElement(((CharakterToken)sendert).InitiativeMember);
                all.Remove((CharakterToken)sendert);
                GameMap.Children.Remove((UIElement)sendert);
                InitiativeUpdate();
            };
            Action <UIElement> enableDrag = (element) => {
                element.MouseDown          += mouseDown;
                element.MouseMove          += mouseMove;
                element.MouseUp            += mouseUp;
                element.MouseRightButtonUp += mouseRightClick;
            };

            // Eventhandler für das neue Element aktivieren
            enableDrag(Unit);
            GameMap.Children.Add(Unit);

            // Position des neuen Element im Canvas setzen
            InkCanvas.SetTop(Unit, startPunkt.Y - 10);
            InkCanvas.SetLeft(Unit, startPunkt.X - 10);
        }