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 resourceUnderCursor = resourceLayer.GetResource(cell).Type; if (underCursor != null) { editorWidget.SetTooltip(underCursor.Tooltip); } else if (resourceUnderCursor != null) { editorWidget.SetTooltip(resourceUnderCursor); } 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) { editorActionManager.Add(new RemoveActorAction(editorLayer, underCursor)); } if (resourceUnderCursor != null) { editorActionManager.Add(new RemoveResourceAction(resourceLayer, cell, resourceUnderCursor)); } } return(true); }
void Delete() { if (CurrentActor != null) { editorActionManager.Add(new RemoveActorAction(editorActorLayer, CurrentActor)); } Close(); }
void PaintCell(CPos cell, bool isMoving) { var template = terrainInfo.Templates[Template]; if (isMoving && PlacementOverlapsSameTemplate(template, cell)) { return; } editorActionManager.Add(new PaintTileEditorAction(Template, world.Map, cell)); }
void PaintCell(CPos cell, bool isMoving) { var map = world.Map; var tileset = map.Rules.TileSet; var template = tileset.Templates[Template]; if (isMoving && PlacementOverlapsSameTemplate(template, cell)) { return; } editorActionManager.Add(new PaintTileEditorAction(Template, map, cell)); }
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, (TerrainTile, ResourceTile, byte)>(); var copyFilters = getCopyFilters(); foreach (var cell in source) { if (!mapTiles.Contains(cell) || !mapTiles.Contains(cell + offset)) { continue; } tiles.Add(cell + offset, (mapTiles[cell], mapResources[cell], mapHeight[cell])); if (copyFilters.HasFlag(MapCopyFilters.Actors)) { foreach (var preview in editorLayer.PreviewsAt(cell)) { if (previews.ContainsKey(preview.ID)) { continue; } var copy = preview.Export(); var locationInit = copy.GetOrDefault <LocationInit>(); if (locationInit != null) { copy.RemoveAll <LocationInit>(); copy.Add(new LocationInit(locationInit.Value + offset)); } previews.Add(preview.ID, copy); } } } var action = new CopyPasteEditorAction(copyFilters, worldRenderer.World.Map, tiles, previews, editorLayer, dest); editorActionManager.Add(action); }
public bool HandleMouseInput(MouseInput mi) { // Exclusively uses left and right mouse buttons, but nothing else if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right) { return(false); } if (mi.Button == MouseButton.Right) { if (mi.Event == MouseInputEvent.Up) { editorWidget.ClearBrush(); return(true); } return(false); } if (editorCursor.CurrentToken != cursorToken) { return(false); } var cell = worldRenderer.Viewport.ViewToWorld(mi.Location); if (mi.Button == MouseButton.Left && mi.Event != MouseInputEvent.Up && AllowResourceAt(cell)) { var type = (byte)ResourceType.ResourceType; var tile = world.Map.Resources[cell]; var index = (byte)Math.Min(tile.Index + 1, ResourceType.MaxDensity); action.Add(new CellResource(cell, tile, new ResourceTile(type, index))); resourceAdded = true; } else if (resourceAdded && mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up) { editorActionManager.Add(action); action = new AddResourcesEditorAction(world.Map, ResourceType); resourceAdded = false; } return(true); }
public bool HandleMouseInput(MouseInput mi) { // Exclusively uses left and right mouse buttons, but nothing else if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right) { return(false); } if (mi.Button == MouseButton.Right) { if (mi.Event == MouseInputEvent.Up) { editorWidget.ClearBrush(); return(true); } return(false); } if (editorCursor.CurrentToken != cursorToken) { return(false); } var cell = worldRenderer.Viewport.ViewToWorld(mi.Location); if (mi.Button == MouseButton.Left && mi.Event != MouseInputEvent.Up && resourceLayer.CanAddResource(ResourceType, cell)) { action.Add(new CellResource(cell, resourceLayer.GetResource(cell), ResourceType)); resourceAdded = true; } else if (resourceAdded && mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up) { editorActionManager.Add(action); action = new AddResourcesEditorAction(world.Map, ResourceType, resourceLayer); resourceAdded = false; } return(true); }
public bool HandleMouseInput(MouseInput mi) { // Exclusively uses left and right mouse buttons, but nothing else if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right) { return(false); } if (mi.Button == MouseButton.Right) { if (mi.Event == MouseInputEvent.Up) { editorWidget.ClearBrush(); return(true); } return(false); } if (editorCursor.CurrentToken != cursorToken) { return(false); } if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) { // Check the actor is inside the map var actor = editorCursor.Actor; if (!actor.Footprint.All(c => world.Map.Tiles.Contains(c.Key))) { return(true); } var action = new AddActorAction(editorLayer, actor.Export()); editorActionManager.Add(action); } return(true); }
public bool HandleMouseInput(MouseInput mi) { // Exclusively uses left and right mouse buttons, but nothing else if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right) { return(false); } if (mi.Button == MouseButton.Right) { if (mi.Event == MouseInputEvent.Up) { editorWidget.ClearBrush(); return(true); } return(false); } var cell = worldRenderer.Viewport.ViewToWorld(mi.Location - worldRenderer.ScreenPxOffset(centerOffset)); if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) { // Check the actor is inside the map if (!footprint.All(c => world.Map.Tiles.Contains(cell + c))) { return(true); } // Enforce first entry of ValidOwnerNames as owner if the actor has RequiresSpecificOwners var action = new AddActorAction(editorLayer, Actor, cell, owner, facing); editorActionManager.Add(action); } return(true); }
public void CleanEdges() { var action = new AutoConnectEditorAction(map); editorActionManager.Add(action); }