Example #1
0
        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));
            }
        }
Example #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);
            }
        }
Example #3
0
        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)
            {
                editorWidget.ClearBrush();
                return(true);
            }

            var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);

            if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
            {
                // Check the actor is inside the map
                if (!footprint.All(c => world.Map.MapTiles.Value.Contains(cell + locationOffset + c)))
                {
                    return(true);
                }

                var newActorReference = new ActorReference(Actor.Name);
                newActorReference.Add(new OwnerInit(owner.Name));

                cell += locationOffset;
                newActorReference.Add(new LocationInit(cell));

                var ios = Actor.Traits.GetOrDefault <IOccupySpaceInfo>();
                if (ios != null && ios.SharesCell)
                {
                    var subcell = editorLayer.FreeSubCellAt(cell);
                    if (subcell != SubCell.Invalid)
                    {
                        newActorReference.Add(new SubCellInit(subcell));
                    }
                }

                var initDict = newActorReference.InitDict;

                if (Actor.Traits.Contains <IFacingInfo>())
                {
                    initDict.Add(new FacingInit(facing));
                }

                if (Actor.Traits.Contains <TurretedInfo>())
                {
                    initDict.Add(new TurretFacingInit(facing));
                }

                editorLayer.Add(newActorReference);
            }

            return(true);
        }
Example #4
0
        public void Do()
        {
            var ownerName         = owner.Name;
            var specificOwnerInfo = actor.TraitInfoOrDefault <RequiresSpecificOwnersInfo>();

            if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerNames.Contains(ownerName))
            {
                ownerName = specificOwnerInfo.ValidOwnerNames.First();
            }

            var newActorReference = new ActorReference(actor.Name);

            newActorReference.Add(new OwnerInit(ownerName));

            newActorReference.Add(new LocationInit(cell));

            var ios = actor.TraitInfoOrDefault <IOccupySpaceInfo>();

            if (ios != null && ios.SharesCell)
            {
                var subcell = editorLayer.FreeSubCellAt(cell);
                if (subcell != SubCell.Invalid)
                {
                    newActorReference.Add(new SubCellInit(subcell));
                }
            }

            var initDict = newActorReference.InitDict;

            if (actor.HasTraitInfo <IFacingInfo>())
            {
                initDict.Add(new FacingInit(facing));
            }

            if (actor.HasTraitInfo <TurretedInfo>())
            {
                initDict.Add(new TurretFacingInit(facing));
            }

            editorActorPreview = editorLayer.Add(newActorReference);

            Text = "Added {0} ({1})".F(editorActorPreview.Info.Name, editorActorPreview.ID);
        }
Example #5
0
 public void Undo()
 {
     editorActorLayer.Add(actor);
 }
Example #6
0
 public void Do()
 {
     editorActorPreview = editorLayer.Add(actor);
     Text = "Added {0} ({1})".F(editorActorPreview.Info.Name, editorActorPreview.ID);
 }
Example #7
0
 public void Do()
 {
     editorActorPreview = editorLayer.Add(actor);
     Text = $"Added {editorActorPreview.Info.Name} ({editorActorPreview.ID})";
 }
Example #8
0
        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 ownerName         = owner.Name;
                var specificOwnerInfo = Actor.TraitInfoOrDefault <RequiresSpecificOwnersInfo>();
                if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerNames.Contains(ownerName))
                {
                    ownerName = specificOwnerInfo.ValidOwnerNames.First();
                }

                var newActorReference = new ActorReference(Actor.Name);
                newActorReference.Add(new OwnerInit(ownerName));

                newActorReference.Add(new LocationInit(cell));

                var ios = Actor.TraitInfoOrDefault <IOccupySpaceInfo>();
                if (ios != null && ios.SharesCell)
                {
                    var subcell = editorLayer.FreeSubCellAt(cell);
                    if (subcell != SubCell.Invalid)
                    {
                        newActorReference.Add(new SubCellInit(subcell));
                    }
                }

                var initDict = newActorReference.InitDict;

                if (Actor.HasTraitInfo <IFacingInfo>())
                {
                    initDict.Add(new FacingInit(facing));
                }

                if (Actor.HasTraitInfo <TurretedInfo>())
                {
                    initDict.Add(new TurretFacingInit(facing));
                }

                editorLayer.Add(newActorReference);
            }

            return(true);
        }