private void MageViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == nameof(IMageKnightBattleViewModel.ActionMode)) { try { var m = sender as IMageKnightBattleViewModel; this.activeMageKnights.Remove(this.activeMageKnights.FirstOrDefault(x => x.Name == "temp" + m.Model.InstantiatedId.ToString())); } catch { ; } IMageKnightBattleViewModel data = sender as IMageKnightBattleViewModel; if (data.ActionMode == ActionMode.Move || data.ActionMode == ActionMode.MoveFormation) { var boundry = new MageKnightBattleViewModel(data); this.ActiveMageKnights.Add(boundry); } this.SyncBaseContactCollections(); } if (e.PropertyName == nameof(IMageKnightBattleViewModel.IsSelected)) { var mage = sender as IMageKnightBattleViewModel; if (mage.IsSelected) { this.User1SelectedMageKnight = this.ActiveMageKnights.FirstOrDefault(x => x.Model.InstantiatedId == mage.Model.InstantiatedId); } } }
private void Dial_Loaded(object sender, RoutedEventArgs e) { var mage = this.FindAncestor <MageKnightBattleView>(); IMageKnightBattleViewModel data = mage.DataContext as IMageKnightBattleViewModel; if (data.IsMovingBorder) { this.grid.Visibility = Visibility.Hidden; } }
private void SpeedBoundary_Loaded(object sender, RoutedEventArgs e) { IMageKnightBattleViewModel data = this.DataContext as IMageKnightBattleViewModel; if (data.IsMovingBorder) { this.speedBorder.Visibility = Visibility.Visible; this.IsHitTestVisible = false; } }
private void RangeSector_Loaded(object sender, RoutedEventArgs e) { IMageKnightBattleViewModel data = this.DataContext as IMageKnightBattleViewModel; if (data.IsMovingBorder) { this.rangeBorder.Visibility = Visibility.Collapsed; this.rangeSector.Visibility = Visibility.Collapsed; this.dialProxy.Visibility = Visibility.Collapsed; } }
private void BattleViewData_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == nameof(IMageKnightBattleViewModel.ActionMode)) { IMageKnightBattleViewModel data = sender as IMageKnightBattleViewModel; if (data.ActionMode == ActionMode.Attack || data.ActionMode == ActionMode.MoveFormation) { this.TargetingMage = data; } else if (this.TargetingMage != null && this.TargetingMage.ActionMode == ActionMode.Pass) { this.TargetingMage = null; } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { IMageKnightBattleViewModel data = value as IMageKnightBattleViewModel; if (data == null) { return(Visibility.Collapsed); } if (data.ActionCount == 1 && !data.IsPushed) { return(Visibility.Visible); } return(Visibility.Collapsed); }
// this is a hack to initialize the propertychanged handler. The content is null on load thats why private void BattleCanvas_MouseMove(object sender, MouseEventArgs e) { if (this.initialize) { return; } this.initialize = true; for (int i = 0; i < VisualTreeHelper.GetChildrenCount(this); i++) { ContentPresenter child = VisualTreeHelper.GetChild(this, i) as ContentPresenter; MageKnightBattleView mage = FindFirstGenericChild.FindFirstChild <MageKnightBattleView>(child); mage.dial.MouseLeftButtonDown += Dial_MouseLeftButtonDown; IMageKnightBattleViewModel battleViewData = mage.DataContext as IMageKnightBattleViewModel; battleViewData.PropertyChanged += BattleViewData_PropertyChanged; } }
public void AddMage(IMageKnightBattleViewModel mage) { //mage.UserId = this.UserId; //mage.PropertyChanged += Mage_PropertyChanged; //int i = this.model.ActiveArmy.Count; //double range = mage.Range; //double speed = mage.Dial.Click.Speed.Value; //double max = Math.Max(range, speed); //double height = max * 100; //double x = height - 50 - 1100; //double y = height - 50 - 200; //mage.XCord = -x + 100 * i; //mage.YCord = -y; //this.model.ActiveArmies.Add(mage); }
public MageKnightBattleViewModel(IMageKnightBattleViewModel clone) { MageData data = new MageData("temp" + clone.Model.InstantiatedId.ToString()); data.Range = clone.Model.Range; data.Dial = new DialData(data); data.Dial.Click.Speed.Value = clone.Dial.Click.Speed.Value; this.model = new MageDataForMovingBoundry(data); if (clone.ActionMode == ActionMode.Move || clone.ActionMode == ActionMode.MoveFormation) { this.IsMovingBorder = true; } this.RaisePropertyChanged(nameof(this.IsMovingBorder)); this.XCord = clone.XCord; this.YCord = clone.YCord; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { IMageKnightBattleViewModel data = value as IMageKnightBattleViewModel; if (data == null) { return(Visibility.Collapsed); } if (data.IsPushed && data.ActionCount == 1) { return(true); } else if (!data.IsPushed && data.ActionCount == 1 || data.ActionCount == 2) { return(false); } else { return(true); } }
private void Dial_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var draggableControl = sender as UserControl; var mageKnightBattleView = draggableControl.FindAncestor <MageKnightBattleView>(); IMageKnightBattleViewModel battleViewData = mageKnightBattleView.DataContext as IMageKnightBattleViewModel; if (this.TargetingMage != null && this.TargetingMage.Index != battleViewData.Index) { if (this.TargetingMage.ActionMode == ActionMode.Attack) { this.TargetingMage.AddTarget(battleViewData); } else if (this.TargetingMage.ActionMode == ActionMode.MoveFormation) { if (!this.TargetingMage.MoveFormationParticipants.Contains(battleViewData) && TargetingMage.FrendlyBaseContact.Contains(battleViewData) && TargetingMage.Faction == battleViewData.Faction) { this.TargetingMage.MoveFormationParticipants.Add(battleViewData); battleViewData.Move.Execute(null); } } } }
private void MageKnightBattleView_Loaded(object sender, RoutedEventArgs e) { this.canvas = this.FindAncestor <Canvas>(); IMageKnightBattleViewModel data = this.DataContext as IMageKnightBattleViewModel; }
public void AddMageKnightToInventory(IMageKnightBattleViewModel mage) { //this.model.AddMageKnightToInventory(mage); }
private static void Canvas_PreviewMouseMove(object sender, MouseEventArgs e) { if (Keyboard.IsKeyDown(Key.LeftShift)) { return; } if (Mouse.LeftButton != MouseButtonState.Pressed) { return; } FrameworkElement element = sender as FrameworkElement; if (draggingDial == null) { return; } var mageKnightBattleView = FindFirstGenericChild.FindFirstChild <MageKnightBattleView>(draggingDial); IMageKnightBattleViewModel myBattleViewData = mageKnightBattleView.DataContext as IMageKnightBattleViewModel; if (myBattleViewData.ActionMode == ActionMode.Move || myBattleViewData.ActionMode == ActionMode.MoveFormation) { Point mouseDownPoint = canvasMouseDownOffset; Point mouseDragPoint = e.GetPosition(canvas); Vector dragDiff = mouseDragPoint - mouseDownPoint; Point centerOfMyDial = myBattleViewData.CenterPoint; Point newCenterOfDial = mouseDragPoint; Point centerOfMoveBoundary = new Point(myBattleViewData.MoveStartingPoint.X, myBattleViewData.MoveStartingPoint.Y); Vector centerDifference = mouseDragPoint - centerOfMoveBoundary; bool moveLimitReached = false; bool isTouchingAtLeastOneOtherMage = false; if (Math.Abs(centerDifference.Length) > myBattleViewData.Model.Dial.Click.Speed.Value * 100.0) { moveLimitReached = true; } foreach (ContentPresenter mage in canvas.Children) { var view = FindFirstGenericChild.FindFirstChild <MageKnightBattleView>(mage); IMageKnightBattleViewModel data = view.DataContext as IMageKnightBattleViewModel; if (data.Name.StartsWith("temp") || data.Model.InstantiatedId == myBattleViewData.Model.InstantiatedId) { continue; } Vector diff = newCenterOfDial - data.CenterPoint; if (Math.Abs(diff.Length) < 100 || moveLimitReached) { isTouchingAtLeastOneOtherMage = true; data.IsInRange = true; } if (Math.Abs(diff.Length) >= 100 && Math.Abs(diff.Length) < myBattleViewData.Range * 100) { data.IsInRange = true; } else { data.IsInRange = false; } } if (!moveLimitReached && !isTouchingAtLeastOneOtherMage) { draggingDial.SetValue(Canvas.LeftProperty, mouseDragPoint.X - myBattleViewData.Size); draggingDial.SetValue(Canvas.TopProperty, mouseDragPoint.Y - myBattleViewData.Size); } } }
private void Button_Click(object sender, MouseButtonEventArgs e) { Button button = sender as Button; string commandName = button.Name; IMageKnightBattleViewModel viewModel = this.DataContext as IMageKnightBattleViewModel; if (viewModel != null) { switch (commandName) { case "Command": viewModel.Command.Execute(null); break; case "Charge": viewModel.Charge.Execute(null); break; case "Healing": viewModel.Healing.Execute(null); break; case "Magic Levitation": viewModel.MagicLevitation.Execute(null); break; case "Magic Blast": viewModel.MagicBlast.Execute(null); break; case "Regeneration": viewModel.Regeneration.Execute(null); break; case "Stealth": viewModel.Stealth.Execute(null); break; case "Necromancy": viewModel.Necromancy.Execute(null); break; case "WheaponMaster": viewModel.WheaponMaster.Execute(null); break; case "Quickness": viewModel.Quickness.Execute(null); break; case "Shockwave": viewModel.ShockWave.Execute(null); break; case "Magic Healing": viewModel.MagicHealing.Execute(null); break; case "Bound": viewModel.Bound.Execute(null); break; case "Flight": viewModel.Flight.Execute(null); break; case "Flame Lightning": viewModel.FlameLightining.Execute(null); break; } } }
private void MageDataView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { IMageKnightBattleViewModel viewModel = this.DataContext as IMageKnightBattleViewModel; this.clicksList.ItemsSource = viewModel.Dial.Clicks; }
private void ArcControl_Loaded(object sender, RoutedEventArgs e) { IMageKnightBattleViewModel data = this.DataContext as IMageKnightBattleViewModel; }