Exemple #1
0
        public EditorActorPreview(WorldRenderer worldRenderer, string id, ActorReference reference, PlayerReference owner)
        {
            ID                 = id;
            this.reference     = reference;
            Owner              = owner;
            this.worldRenderer = worldRenderer;

            if (!reference.Contains <FactionInit>())
            {
                reference.Add(new FactionInit(owner.Faction));
            }

            if (!reference.Contains <OwnerInit>())
            {
                reference.Add(new OwnerInit(owner.Name));
            }

            var world = worldRenderer.World;

            if (!world.Map.Rules.Actors.TryGetValue(reference.Type.ToLowerInvariant(), out Info))
            {
                throw new InvalidDataException($"Actor {id} of unknown type {reference.Type.ToLowerInvariant()}");
            }

            CenterPosition = PreviewPosition(world, reference);

            var location = reference.Get <LocationInit>().Value;
            var ios      = Info.TraitInfoOrDefault <IOccupySpaceInfo>();

            var subCellInit = reference.GetOrDefault <SubCellInit>();
            var subCell     = subCellInit != null ? subCellInit.Value : SubCell.Any;

            var radarColorInfo = Info.TraitInfoOrDefault <RadarColorFromTerrainInfo>();

            RadarColor = radarColorInfo == null ? owner.Color : radarColorInfo.GetColorFromTerrain(world);

            Footprint = ios?.OccupiedCells(Info, location, subCell) ?? new Dictionary <CPos, SubCell>()
            {
                { location, SubCell.FullCell }
            };

            tooltip = Info.TraitInfos <EditorOnlyTooltipInfo>().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase
                      ?? Info.TraitInfos <TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);

            DescriptiveName = tooltip != null ? tooltip.Name : Info.Name;

            GeneratePreviews();

            // Bounds are fixed from the initial render.
            // If this is a problem, then we may need to fetch the area from somewhere else
            var r = previews.SelectMany(p => p.ScreenBounds(worldRenderer, CenterPosition));

            Bounds = r.Union();

            SelectionBox = new SelectionBoxAnnotationRenderable(new WPos(CenterPosition.X, CenterPosition.Y, 8192),
                                                                new Rectangle(Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height), Color.White);
        }
Exemple #2
0
 public bool Contains <T>(TraitInfo info) where T : ActorInit
 {
     return(reference.Contains <T>(info));
 }