示例#1
0
        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);
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
        }
示例#4
0
        bool IsValidVeinNeighbour(CPos cell, CPos neighbour)
        {
            // Cell is automatically valid if it contains a veinhole actor
            if (actorLayer.PreviewsAt(neighbour).Any(a => info.VeinholeActors.Contains(a.Info.Name)))
            {
                return(true);
            }

            // Neighbour must be flat or a cardinal slope, unless the resource cell itself is a slope
            if (Map.Ramp[cell] == 0 && Map.Ramp[neighbour] > 4)
            {
                return(false);
            }

            var terrainInfo = Map.Rules.TerrainInfo;
            var terrainType = terrainInfo.TerrainTypes[terrainInfo.GetTerrainInfo(Map.Tiles[neighbour]).TerrainType].Type;

            return(info.ResourceTypes[info.VeinType].AllowedTerrainTypes.Contains(terrainType));
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }