void UserControl_Loaded(object sender, RoutedEventArgs e) { Region = (Region)DataContext; foreach (var unit in MainWindow.Instance.Mission.AllUnits) { UnitIcon.PlaceSimplifiedUnit(canvas, unit); } foreach (var area in Region.Areas) { if (area is Cylinder) { var cylinder = (Cylinder)area; AddCylinder(cylinder); } else if (area is RectangularArea) { AddRectangle((RectangularArea)area); } else throw new Exception("Unexpected Area"); } }
void CreateNewRegion() { var region = new Region { Name = GetNewRegionName() }; Mission.Regions.Add(region); }
void RenameRegion(Region region) { if (region == null) return; var dialog = new StringRequest { Title = "Rename Region", TextBox = { Text = region.Name }, Owner = this }; if (dialog.ShowDialog() == true) { region.Name = dialog.TextBox.Text; region.RaisePropertyChanged(String.Empty); Mission.RaisePropertyChanged("Regions"); } }
// manual drag and drop implementation - ugh /* private void triggerItem_Drop(object sender, DragEventArgs e) { if (draggedItem == null) return; bool handled = false; bool toEnd = true; Point pt = e.GetPosition(logicGrid); object hit = logicGrid.InputHitTest(pt); Border border; if (hit is Border) border = (Border)e.Source; else if (hit is TextBlock) border = (Border)((TextBlock)e.Source).Parent; // dropped on to the grid; if this is a trigger or region, move to the end of its list else if (hit == logicGrid) { if (draggedItem is Trigger) { var myIndex = Mission.Triggers.IndexOf((Trigger)draggedItem); Mission.Triggers.Move(myIndex, Mission.Triggers.Count); handled = true; } draggedItem = null; return; } else { MessageBox.Show(string.Format("{0}, {1}", hit.ToString(), hit.GetType())); //debug draggedItem = null; return; } object hitDataContext = border.DataContext; if (draggedItem is Trigger) { var myIndex = Mission.Triggers.IndexOf((Trigger)draggedItem); foreach (object item in logicGrid.Items) { if (item == hitDataContext) { toEnd = false; Trigger target = (Trigger)draggedItem; if (item is Trigger) { target = (Trigger)item; } else if (item is ActionsFolder) { target = ((ActionsFolder)item).Trigger; } else if (item is ConditionsFolder) { target = ((ConditionsFolder)item).Trigger; } else if (item is TriggerLogic) { target = Mission.FindLogicOwner((TriggerLogic)item); } if (target != draggedItem) { var newIndex = Mission.Triggers.IndexOf(target); Mission.Triggers.Move(myIndex, newIndex); handled = true; break; } } } if (!handled) { //Mission.Triggers.Move(myIndex, Mission.Triggers.Count - 1); //handled = true; } } else if (draggedItem is TriggerLogic) { var myTrigger = Mission.FindLogicOwner((TriggerLogic)draggedItem); var myIndex = myTrigger.Logic.IndexOf((TriggerLogic)draggedItem); foreach (object item in logicGrid.Items) { if (item == hitDataContext) { Trigger targetTrigger = (Trigger)item; int newIndex = myIndex; if (item is Trigger) { targetTrigger = (Trigger)item; } else if (item is ActionsFolder && draggedItem is Action) { targetTrigger = ((ActionsFolder)item).Trigger; } else if (item is ConditionsFolder && draggedItem is Condition) { targetTrigger = ((ConditionsFolder)item).Trigger; } else if (item is Action && draggedItem is Action) { targetTrigger = Mission.FindLogicOwner((TriggerLogic)item); newIndex = targetTrigger.Logic.IndexOf((Action)item); toEnd = false; } else if (item is Condition && draggedItem is Condition) { targetTrigger = Mission.FindLogicOwner((TriggerLogic)item); newIndex = targetTrigger.Logic.IndexOf((Condition)item); toEnd = false; } //MessageBox.Show(string.Format("{0}, {1}, {2}", targetTrigger == myTrigger, myIndex, newIndex)); //debug if (targetTrigger != myTrigger) { if (toEnd) targetTrigger.Logic.Add((TriggerLogic)draggedItem); else targetTrigger.Logic.Insert(newIndex, (TriggerLogic)draggedItem); myTrigger.Logic.Remove((TriggerLogic)draggedItem); handled = true; break; } else if(newIndex != myIndex) { targetTrigger.Logic.Move(myIndex, newIndex); handled = true; break; } } } } e.Handled = handled; if (handled) Mission.RaisePropertyChanged("AllLogic"); draggedItem = null; }*/ void DeleteRegion(Region region) { Mission.Regions.Remove(region); }