private void btnPatrolPoint_Click(object sender, RoutedEventArgs e) { PatrolPoint pp = new PatrolPoint(); pp.Init(this); canvasRoom.Children.Add(pp); stuffLayer.Add(pp); if (!(bool)radStuff.IsChecked) { EnableStuffLayer(); radStuff.IsChecked = true; } if (selected != null) { selected.Deselect(); } selected = pp; pp.Select(); pp.SnapToGrid(); }
private void LoadRoom(string file) { Clear(); window.Title = file; FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RoomDefinition)); RoomDefinition room = (RoomDefinition)serializer.ReadObject(fs); cmbRoomType.SelectedIndex = room.roomType; cmbRarity.SelectedIndex = room.roomRarity; cmbFloorType.SelectedIndex = room.roomFloor; if (room.northDoor) { //chkNorth_Checked(this, new RoutedEventArgs()); chkNorth.IsChecked = true; } if (room.eastDoor) { //chkEast_Checked(this, new RoutedEventArgs()); chkEast.IsChecked = true; } if (room.southDoor) { //chkSouth_Checked(this, new RoutedEventArgs()); chkSouth.IsChecked = true; } if (room.westDoor) { //chkWest_Checked(this, new RoutedEventArgs()); chkWest.IsChecked = true; } foreach (PatrolRouteDefinition prd in room.patrolRoutes) { ObservableCollection <PatrolPoint> pr = new ObservableCollection <PatrolPoint>(); patrolRoutes.Add(pr); patrolRouteIndices.Add(patrolRoutes.Count); foreach (PatrolPointDefinition ppd in prd.patrolPoints) { PatrolPoint pp = new PatrolPoint(); pp.Init(this); canvasRoom.Children.Add(pp); stuffLayer.Add(pp); pp.WorldOriginX = ppd.x; pp.WorldOriginY = ppd.y; pp.cmbRoutes.SelectedIndex = patrolRoutes.Count - 1; } } foreach (SpawnGroupDefinition sgd in room.spawnGroups) { foreach (MeshDefinition md in sgd.meshes) { if (md.staticMesh == "floor") { Mesh f = MeshFactory.MakeFloor(this); f.Init(this); canvasRoom.Children.Add(f); floorLayer.Add(f); f.WorldOriginX = md.x; f.WorldOriginY = md.y; f.Angle = md.rotation; } else if (md.staticMesh == "wall400") { Mesh w = MeshFactory.MakeHorizontalWall400(this); w.Init(this); canvasRoom.Children.Add(w); wallLayer.Add(w); w.WorldOriginX = md.x; w.WorldOriginY = md.y; w.Angle = md.rotation; if (w.Angle != 0.0) { w.snapMode = DraggableGridSnapper.SnapMode.VerticalLineSnap; } } else if (md.staticMesh == "wall200") { Mesh w = MeshFactory.MakeHorizontalWall200(this); w.Init(this); canvasRoom.Children.Add(w); wallLayer.Add(w); w.WorldOriginX = md.x; w.WorldOriginY = md.y; w.Angle = md.rotation; if (w.Angle != 0.0) { w.snapMode = DraggableGridSnapper.SnapMode.VerticalLineSnap; } } else if (md.staticMesh == "wall100") { Mesh w = MeshFactory.MakeHorizontalWall100(this); w.Init(this); canvasRoom.Children.Add(w); wallLayer.Add(w); w.WorldOriginX = md.x; w.WorldOriginY = md.y; w.Angle = md.rotation; if (w.Angle != 0.0) { w.snapMode = DraggableGridSnapper.SnapMode.VerticalLineSnap; } } else { foreach (CustomMesh cm in cmbObjects.Items) { if (cm.assetName == md.staticMesh) { Mesh m = MeshFactory.MakeCustomMesh(cm, this); canvasRoom.Children.Add(m); stuffLayer.Add(m); m.WorldOriginX = md.x; m.WorldOriginY = md.y; m.Angle = md.rotation; break; } } } } foreach (ItemDefinition id in sgd.items) { Item i = new Item(); i.Init(this); canvasRoom.Children.Add(i); stuffLayer.Add(i); i.WorldOriginX = id.x; i.WorldOriginY = id.y; } foreach (GuardDefinition gd in sgd.guards) { Guard g = new Guard(); g.Init(this); canvasRoom.Children.Add(g); stuffLayer.Add(g); g.WorldOriginX = gd.x; g.WorldOriginY = gd.y; g.Angle = gd.rotation; g.cmbRoutes.SelectedIndex = gd.patrolRouteIndex; g.cmbStart.SelectedIndex = gd.startIndex; } foreach (CameraDefinition cd in sgd.cameras) { Camera c = new Camera(); c.Init(this); canvasRoom.Children.Add(c); stuffLayer.Add(c); c.WorldOriginX = cd.x; c.WorldOriginY = cd.y; c.Angle = cd.rotation; } if (sgd.lights != null) { foreach (LightDefinition ld in sgd.lights) { Light l = new Light(); l.Init(this); canvasRoom.Children.Add(l); lightsLayer.Add(l); l.WorldOriginX = ld.x; l.WorldOriginY = ld.y; l.Radius = ld.radius; } } } fs.Close(); EnableStuffLayer(); }