public void Link(Pathnode other) { if (LinkedNodes.Contains(other)) return; LinkedNodes.Add(other); other.LinkedNodes.Add(this); }
public void EditorLink(Pathnode other) { if (LinkedNodes.Contains(other)) { LinkedNodes.Remove(other); other.LinkedNodes.Remove(this); } else { Link(other); } }
private void UpdateEditor() { switch (editMode) { case EditMode.Geometry: { if (RM.IsPressed(InputAction.Select) && IM.MousePos.X < 1024) { var stg = SnapToGridPos; points.Add(stg); } if (RM.IsPressed(InputAction.AltFire) && IM.MousePos.X < 1024) { if (points.Count == 3) { geometry.Add(new Geometry(points.ToList(), GeomType.Floor)); points.Clear(); } else if (points.Count == 2) { geometry.Add(new Geometry(points.ToList(), GeomType.Wall)); points.Clear(); } else { points.Clear(); } } } break; case EditMode.Entities: { if (RM.IsPressed(InputAction.Select) && IM.MousePos.X < 1024) { var mPos = SnapToGridPos8; if (entityToPlaceType == typeof(Human)) { entities.Add(new Human(this, mPos.ToVector2Rounded()) { World = this }); } if (entityToPlaceType == typeof(HorizontalDoor)) { var door = new HorizontalDoor(mPos.ToVector2Rounded()) { World = this }; var node = new Pathnode(this) { Location = door.Position }; Pathnodes.Add(node); door.Pathnode = node; entities.Add(door); } if (entityToPlaceType == typeof(VerticalDoor)) { var door = new VerticalDoor(mPos.ToVector2Rounded()) { World = this }; var node = new Pathnode(this) { Location = door.Position }; Pathnodes.Add(node); door.Pathnode = node; entities.Add(door); } if (entityToPlaceType == typeof(WorkTerminal)) { var workterm = new WorkTerminal(mPos.ToVector2Rounded()) { World = this }; var node = new Pathnode(this) { Location = workterm.Position }; Pathnodes.Add(node); workterm.Pathnode = node; entities.Add(workterm); } if (entityToPlaceType == typeof(AlarmPanel)) { var alarm = new AlarmPanel(mPos.ToVector2Rounded()) { World = this }; var node = new Pathnode(this) { Location = alarm.Position }; Pathnodes.Add(node); alarm.Pathnode = node; entities.Add(alarm); } if (entityToPlaceType == typeof(Robot)) { entities.Add(new Robot(this, mPos.ToVector2Rounded()) { World = this }); } if (entityToPlaceType == typeof(Crate)) { entities.Add(new Crate(mPos.ToVector2Rounded()) { World = this }); } if (entityToPlaceType == typeof(ExplosiveCrate)) { entities.Add(new ExplosiveCrate(mPos.ToVector2Rounded()) { World = this }); } if (entityToPlaceType == typeof(SentryGun)) { entities.Add(new SentryGun(mPos.ToVector2Rounded()) { World = this }); } if (entityToPlaceType == typeof(Camera)) { entities.Add(new Camera(mPos.ToVector2Rounded()) { World = this }); } if (entityToPlaceType == typeof(Incinerator)) { entities.Add(new Incinerator(mPos.ToVector2Rounded()) { World = this }); } } if (RM.IsPressed(InputAction.AltFire) && IM.MousePos.X < 1024) { var ray = Camera3d.c.MouseRay; SelectEntity(entities.Where(e => e.Intersects(ray)).OrderBy(e => (e.Position.ToVector3() - Camera3d.c.position).Length()).FirstOrDefault()); } if (allowEditor && IM.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.T)) { int index = entityTypes.IndexOf(entityToPlaceType); index++; if (index >= entityTypes.Count) { index = 0; } entityToPlaceType = entityTypes[index]; } if (SelectedEntity != null) { SelectedEntity.UpdateHudShit(); } } break; case EditMode.Pathing: { if (RM.IsPressed(InputAction.Select) && IM.MousePos.X < 1024) { var mPos = SnapToGridPos8; Pathnodes.Add(new Pathnode(this) { Location = mPos.ToVector2Rounded() }); } if (RM.IsPressed(InputAction.AltFire) && IM.MousePos.X < 1024) { var ray = Camera3d.c.MouseRay; SelectNode(Pathnodes.Where(e => e.Intersects(ray)).OrderBy(e => (e.Location.ToVector3() - Camera3d.c.position).Length()).FirstOrDefault()); } if (RM.IsPressed(InputAction.Select) && IM.MousePos.X > 1024 && SelectedNode != null) { SelectedNode.UpdateHudShit(); } } break; } if (allowEditor && IM.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Tab)) { switch (editMode) { case EditMode.Geometry: editMode = EditMode.Entities; break; case EditMode.Entities: editMode = EditMode.Pathing; break; case EditMode.Pathing: editMode = EditMode.Geometry; break; } } }
private void SelectNode(Pathnode pathnode) { if (pathnode != null) { if (SelectedNode == null) { SelectedNode = pathnode; SelectedNode.Selected = true; } else { if (pathnode != null) { pathnode.EditorLink(SelectedNode); } SelectedNode.Selected = false; SelectedNode = null; } } else if (SelectedNode != null) { SelectedNode.Selected = false; SelectedNode = null; } }