public void Do() { foreach (var kv in tiles) { undoCopyPastes.Enqueue(new UndoCopyPaste(kv.Key, mapTiles[kv.Key], mapResources[kv.Key], mapHeight[kv.Key])); if (copyFilters.HasFlag(MapCopyFilters.Terrain)) { mapTiles[kv.Key] = kv.Value.Item1; } if (copyFilters.HasFlag(MapCopyFilters.Resources)) { mapResources[kv.Key] = kv.Value.Item2; } mapHeight[kv.Key] = kv.Value.Item3; } if (copyFilters.HasFlag(MapCopyFilters.Actors)) { var removeActors = dest.SelectMany(editorLayer.PreviewsAt).Distinct().ToList(); foreach (var preview in removeActors) { removedActors.Enqueue(preview); editorLayer.Remove(preview); } } foreach (var kv in previews) { addedActorPreviews.Enqueue(editorLayer.Add(kv.Value)); } }
void Copy(CellRegion source, CVec offset) { var gridType = worldRenderer.World.Map.Grid.Type; var mapTiles = worldRenderer.World.Map.Tiles; var mapHeight = worldRenderer.World.Map.Height; var mapResources = worldRenderer.World.Map.Resources; var dest = new CellRegion(gridType, source.TopLeft + offset, source.BottomRight + offset); var previews = new Dictionary <string, ActorReference>(); var tiles = new Dictionary <CPos, Tuple <TerrainTile, ResourceTile, byte> >(); foreach (var cell in source) { if (!mapTiles.Contains(cell) || !mapTiles.Contains(cell + offset)) { continue; } tiles.Add(cell + offset, Tuple.Create(mapTiles[cell], mapResources[cell], mapHeight[cell])); foreach (var preview in editorLayer.PreviewsAt(cell)) { if (previews.ContainsKey(preview.ID)) { continue; } var copy = preview.Export(); if (copy.InitDict.Contains <LocationInit>()) { var location = copy.InitDict.Get <LocationInit>(); copy.InitDict.Remove(location); copy.InitDict.Add(new LocationInit(location.Value(worldRenderer.World) + offset)); } previews.Add(preview.ID, copy); } } foreach (var kv in tiles) { mapTiles[kv.Key] = kv.Value.Item1; mapResources[kv.Key] = kv.Value.Item2; mapHeight[kv.Key] = kv.Value.Item3; } var removeActors = dest.SelectMany(editorLayer.PreviewsAt).Distinct().ToList(); foreach (var preview in removeActors) { editorLayer.Remove(preview); } foreach (var kv in previews) { editorLayer.Add(kv.Value); } }
void Delete() { if (CurrentActor != null) { editorActorLayer.Remove(CurrentActor); } Close(); }
public void Do() { editorActorLayer.Remove(actor); }
public void Undo() { editorLayer.Remove(editorActorPreview); }
public bool HandleMouseInput(MouseInput mi) { // Exclusively uses left and right mouse buttons, but nothing else // Mouse move events are important for tooltips, so we always allow these through if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right && mi.Event != MouseInputEvent.Move) { return(false); } var cell = worldRenderer.Viewport.ViewToWorld(mi.Location); if (mi.Event == MouseInputEvent.Up) { return(true); } var underCursor = editorLayer.PreviewsAt(worldRenderer.Viewport.ViewToWorldPx(mi.Location)) .FirstOrDefault(); var mapResources = world.Map.MapResources.Value; ResourceType type; if (underCursor != null) { editorWidget.SetTooltip(underCursor.Tooltip); } else if (mapResources.Contains(cell) && resources.TryGetValue(mapResources[cell].Type, out type)) { editorWidget.SetTooltip(type.Info.Name); } else { editorWidget.SetTooltip(null); } // Finished with mouse move events, so let them bubble up the widget tree if (mi.Event == MouseInputEvent.Move) { return(false); } if (mi.Button == MouseButton.Right) { editorWidget.SetTooltip(null); if (underCursor != null) { editorLayer.Remove(underCursor); } if (mapResources.Contains(cell) && mapResources[cell].Type != 0) { mapResources[cell] = new ResourceTile(); } } else if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) { if (underCursor != null) { // Test case / demonstration of how to edit an existing actor var facing = underCursor.Init <FacingInit>(); if (facing != null) { underCursor.ReplaceInit(new FacingInit((facing.Value(world) + 32) % 256)); } else if (underCursor.Info.Traits.WithInterface <UsesInit <FacingInit> >().Any()) { underCursor.ReplaceInit(new FacingInit(32)); } var turret = underCursor.Init <TurretFacingInit>(); if (turret != null) { underCursor.ReplaceInit(new TurretFacingInit((turret.Value(world) + 32) % 256)); } else if (underCursor.Info.Traits.WithInterface <UsesInit <TurretFacingInit> >().Any()) { underCursor.ReplaceInit(new TurretFacingInit(32)); } } } return(true); }
public bool HandleMouseInput(MouseInput mi) { // Exclusively uses mouse wheel and both mouse buttons, but nothing else // Mouse move events are important for tooltips, so we always allow these through if ((mi.Button != MouseButton.Left && mi.Button != MouseButton.Right && mi.Event != MouseInputEvent.Move && mi.Event != MouseInputEvent.Scroll) || mi.Event == MouseInputEvent.Down) { return(false); } worldPixel = worldRenderer.Viewport.ViewToWorldPx(mi.Location); var cell = worldRenderer.Viewport.ViewToWorld(mi.Location); var underCursor = editorLayer.PreviewsAt(worldPixel).MinByOrDefault(CalculateActorSelectionPriority); var mapResources = world.Map.Resources; ResourceType type; if (underCursor != null) { editorWidget.SetTooltip(underCursor.Tooltip); } else if (mapResources.Contains(cell) && resources.TryGetValue(mapResources[cell].Type, out type)) { editorWidget.SetTooltip(type.Info.Type); } else { editorWidget.SetTooltip(null); } // Finished with mouse move events, so let them bubble up the widget tree if (mi.Event == MouseInputEvent.Move) { return(false); } if (mi.Button == MouseButton.Left) { editorWidget.SetTooltip(null); SelectedActor = underCursor; } if (mi.Button == MouseButton.Right) { editorWidget.SetTooltip(null); if (underCursor != null && underCursor != SelectedActor) { editorLayer.Remove(underCursor); } if (mapResources.Contains(cell) && mapResources[cell].Type != 0) { mapResources[cell] = default(ResourceTile); } } return(true); }