/// <summary> /// Called when the edit button on the entity list is clicked /// </summary> /// <param name="sender">Sender of the event</param> /// <param name="e">Event arguments</param> private void EditClicked(object sender, RoutedEventArgs e) { // Get the button Button button = (Button)sender; // Grab the index int index = (int)button.CommandParameter; // Copy the entity ent existingEntity = ServiceLocator.Instance.Level.Entities[index]; ent entity = new ent { ID = existingEntity.ID, Type = existingEntity.Type, Graphic = existingEntity.Graphic, X = existingEntity.X, Y = existingEntity.Y, DestinationX = existingEntity.DestinationX, DestinationY = existingEntity.DestinationY, Speed = existingEntity.Speed, Delay = existingEntity.Delay }; // Load the entity ServiceLocator.Instance.Entity.Index = index; ServiceLocator.Instance.Entity.Entity = entity; Open(); }
/// <summary> /// Called when the save button is clicked /// </summary> /// <param name="sender">Sender of the event</param> /// <param name="e">Event arguments</param> private void SaveClicked(object sender, RoutedEventArgs e) { // Get the index int index = ServiceLocator.Instance.Entity.Index; // Copy the entity ent existingEntity = ServiceLocator.Instance.Entity.Entity; ent entity = new ent { ID = existingEntity.ID, Type = existingEntity.Type, Graphic = existingEntity.Graphic, X = existingEntity.X, Y = existingEntity.Y, DestinationX = existingEntity.DestinationX, DestinationY = existingEntity.DestinationY, Speed = existingEntity.Speed, Delay = existingEntity.Delay }; // Save the entity if (index == -1) { ServiceLocator.Instance.Level.Level.Entities.Add(entity); ServiceLocator.Instance.Entity.Index = ServiceLocator.Instance.Level.Level.Entities.Count - 1; } else { ServiceLocator.Instance.Level.Level.Entities[index].ID = existingEntity.ID; ServiceLocator.Instance.Level.Level.Entities[index].Type = existingEntity.Type; ServiceLocator.Instance.Level.Level.Entities[index].Graphic = existingEntity.Graphic; ServiceLocator.Instance.Level.Level.Entities[index].X = existingEntity.X; ServiceLocator.Instance.Level.Level.Entities[index].Y = existingEntity.Y; ServiceLocator.Instance.Level.Level.Entities[index].DestinationX = existingEntity.DestinationX; ServiceLocator.Instance.Level.Level.Entities[index].DestinationY = existingEntity.DestinationY; ServiceLocator.Instance.Level.Level.Entities[index].Speed = existingEntity.Speed; ServiceLocator.Instance.Level.Level.Entities[index].Delay = existingEntity.Delay; } // Ensure the entities are kept in the right order ServiceLocator.Instance.Level.Level.Entities = ServiceLocator.Instance.Level.Level.Entities .OrderBy(ent => ent.Delay.HasValue ? ent.Delay.Value : 0) .ThenBy(ent => ent.Type).ToList(); ServiceLocator.Instance.Level.Update(); ServiceLocator.Instance.Entity.Update(); }