예제 #1
0
        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;
            world             = wr.World;
            editorLayer       = world.WorldActor.Trait <EditorActorLayer>();

            Actor      = actor;
            this.owner = owner;

            preview           = editorWidget.Get <ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
            preview.GetScale  = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var buildingInfo = actor.Traits.GetOrDefault <BuildingInfo>();

            if (buildingInfo != null)
            {
                locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo);
                previewOffset  = FootprintUtils.CenterOffset(world, buildingInfo);
            }

            var td = new TypeDictionary();

            td.Add(new FacingInit(facing));
            td.Add(new TurretFacingInit(facing));
            td.Add(new OwnerInit(owner.Name));
            td.Add(new RaceInit(owner.Race));
            preview.SetPreview(actor, td);

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
예제 #2
0
        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer = wr;
            world = wr.World;
            editorLayer = world.WorldActor.Trait<EditorActorLayer>();

            Actor = actor;
            this.owner = owner;

            preview = editorWidget.Get<ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
            preview.GetScale = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var buildingInfo = actor.Traits.GetOrDefault<BuildingInfo>();
            if (buildingInfo != null)
            {
                locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo);
                previewOffset = FootprintUtils.CenterOffset(world, buildingInfo);
            }

            var td = new TypeDictionary();
            td.Add(new FacingInit(facing));
            td.Add(new TurretFacingInit(facing));
            td.Add(new OwnerInit(owner.Name));
            td.Add(new RaceInit(owner.Race));
            preview.SetPreview(actor, td);

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
예제 #3
0
        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget   = editorWidget;
            worldRenderer       = wr;
            world               = wr.World;
            editorLayer         = world.WorldActor.Trait <EditorActorLayer>();
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();

            Actor      = actor;
            this.owner = owner;
            var ownerName = owner.Name;

            preview           = editorWidget.Get <ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
            preview.GetScale  = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var buildingInfo = actor.TraitInfoOrDefault <BuildingInfo>();

            if (buildingInfo != null)
            {
                centerOffset = buildingInfo.CenterOffset(world);
            }

            // Enforce first entry of ValidOwnerNames as owner if the actor has RequiresSpecificOwners
            var specificOwnerInfo = actor.TraitInfoOrDefault <RequiresSpecificOwnersInfo>();

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

            var td = new TypeDictionary();

            td.Add(new FacingInit(facing));
            td.Add(new TurretFacingInit(facing));
            td.Add(new OwnerInit(ownerName));
            td.Add(new FactionInit(owner.Faction));
            preview.SetPreview(actor, td);

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

            if (ios != null)
            {
                footprint = ios.OccupiedCells(actor, CPos.Zero)
                            .Select(c => c.Key - CPos.Zero)
                            .ToArray();
            }
            else
            {
                footprint = new CVec[0];
            }

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
예제 #4
0
        public EditorTileBrush(EditorViewportControllerWidget editorWidget, ushort template, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            Template = template;
            worldRenderer = wr;
            world = wr.World;

            preview = editorWidget.Get<TerrainTemplatePreviewWidget>("DRAG_TILE_PREVIEW");
            preview.GetScale = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            preview.Template = world.TileSet.Templates.First(t => t.Value.Id == template).Value;
            bounds = worldRenderer.Theater.TemplateBounds(preview.Template, Game.ModData.Manifest.TileSize, world.Map.TileShape);

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
예제 #5
0
        public EditorTileBrush(EditorViewportControllerWidget editorWidget, ushort template, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            Template          = template;
            worldRenderer     = wr;
            world             = wr.World;

            preview           = editorWidget.Get <TerrainTemplatePreviewWidget>("DRAG_TILE_PREVIEW");
            preview.GetScale  = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            preview.Template = world.TileSet.Templates.First(t => t.Value.Id == template).Value;
            bounds           = worldRenderer.Theater.TemplateBounds(preview.Template, Game.ModData.Manifest.TileSize, world.Map.TileShape);

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
예제 #6
0
        public EditorResourceBrush(EditorViewportControllerWidget editorWidget, ResourceTypeInfo resource, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            ResourceType = resource;
            worldRenderer = wr;
            world = wr.World;

            preview = editorWidget.Get<SpriteWidget>("DRAG_LAYER_PREVIEW");
            preview.Palette = resource.Palette;
            preview.GetScale = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var variant = resource.Sequences.FirstOrDefault();
            var sequence = wr.World.Map.Rules.Sequences.GetSequence("resources", variant);
            var sprite = sequence.GetSprite(resource.MaxDensity - 1);
            preview.GetSprite = () => sprite;

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
예제 #7
0
        public EditorResourceBrush(EditorViewportControllerWidget editorWidget, ResourceTypeInfo resource, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            ResourceType      = resource;
            worldRenderer     = wr;
            world             = wr.World;

            preview           = editorWidget.Get <SpriteWidget>("DRAG_LAYER_PREVIEW");
            preview.Palette   = resource.Palette;
            preview.GetScale  = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var variant  = resource.Variants.FirstOrDefault();
            var sequence = wr.World.Map.Rules.Sequences.GetSequence("resources", variant);
            var sprite   = sequence.GetSprite(resource.MaxDensity - 1);

            preview.GetSprite = () => sprite;

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }