예제 #1
0
        // Methode zur Erstellung der Spielfigur im InitiativenTracker
        public Border InitiativeMemberCreator(CharakterToken Unit)
        {
            Border initiativeMember = new Border()
            {
                Width           = 120,
                Height          = 23,
                BorderThickness = new Thickness(2),
                BorderBrush     = Brushes.Black,
                Background      = Unit.getColor(),
                Child           = new TextBlock()
                {
                    Text                = Unit.Name,
                    TextAlignment       = TextAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center
                }
            };

            // Drag&Drop Eventhandler für die Reihenfolge im Initiativetracker
            MouseButtonEventHandler mouseDown = (sendert, args) => {
                var element = (Border)sendert;
                dragStart = args.GetPosition(element);
                element.CaptureMouse();
            };
            MouseButtonEventHandler mouseUp = (sendert, args) => {
                var element = (Border)sendert;
                dragStart = null;
                element.ReleaseMouseCapture();

                if (initPosition.TryGetValue(element, out int result))
                {
                    InitiativeTracker.SetTop(element, 10 + (result * 23));
                    InitiativeTracker.SetLeft(element, 15);
                }
            };
            MouseEventHandler mouseMove = (sendert, args) => {
                if (dragStart != null && args.LeftButton == MouseButtonState.Pressed)
                {
                    var element = (Border)sendert;
                    var p2      = args.GetPosition(this.Parent as UIElement);

                    InitiativeTracker.SetLeft(element, p2.X - dragStart.Value.X);
                    InitiativeTracker.SetTop(element, p2.Y - dragStart.Value.Y);

                    if (initPosition.TryGetValue(element, out int result))
                    {
                        foreach (KeyValuePair <Border, int> item in initPosition)
                        {
                            if (item.Key.Equals(element))
                            {
                                continue;
                            }

                            if ((result > item.Value && InitiativeTracker.GetTop(element) < InitiativeTracker.GetTop(item.Key)) || (result < item.Value && InitiativeTracker.GetTop(element) > InitiativeTracker.GetTop(item.Key)))
                            {
                                int temp = item.Value;
                                initPosition[item.Key] = result;
                                initPosition[element]  = temp;
                                break;
                            }
                        }
                    }

                    foreach (KeyValuePair <Border, int> item in initPosition)
                    {
                        if (item.Key.Equals(element))
                        {
                            continue;
                        }

                        InitiativeTracker.SetTop(item.Key, 10 + (item.Value * 23));
                        InitiativeTracker.SetLeft(item.Key, 15);
                    }
                }
            };
            Action <UIElement> enableDrag = (element) => {
                element.MouseDown += mouseDown;
                element.MouseMove += mouseMove;
                element.MouseUp   += mouseUp;
            };

            enableDrag(initiativeMember);

            initPosition.Add(initiativeMember, Children.Count);

            Children.Add(initiativeMember);

            InitiativeTracker.SetTop(initiativeMember, 10 + ((Children.Count - 1) * 23));
            InitiativeTracker.SetLeft(initiativeMember, 15);

            return(initiativeMember);
        }
예제 #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);
        }