Inheritance: OpenRA.Widgets.Widget
Example #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();
        }
Example #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();
        }
Example #3
0
        public EditorCopyPasteBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;

            selectionLayer = wr.World.WorldActor.Trait <EditorSelectionLayer>();
            editorLayer    = wr.World.WorldActor.Trait <EditorActorLayer>();
        }
Example #4
0
        public EditorCopyPasteBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer = wr;

            selectionLayer = wr.World.WorldActor.Trait<EditorSelectionLayer>();
            editorLayer = wr.World.WorldActor.Trait<EditorActorLayer>();
        }
Example #5
0
        public EditorCopyPasteBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr, Func <MapCopyFilters> getCopyFilters)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;

            selectionLayer      = wr.World.WorldActor.Trait <EditorSelectionLayer>();
            editorLayer         = wr.World.WorldActor.Trait <EditorActorLayer>();
            this.getCopyFilters = getCopyFilters;
        }
Example #6
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();
        }
Example #7
0
        public EditorDefaultBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer = wr;
            world = wr.World;

            editorLayer = world.WorldActor.Trait<EditorActorLayer>();
            resources = world.WorldActor.TraitsImplementing<ResourceType>()
                .ToDictionary(r => r.Info.ResourceType, r => r);
        }
Example #8
0
        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget   = editorWidget;
            world               = wr.World;
            editorLayer         = world.WorldActor.Trait <EditorActorLayer>();
            editorCursor        = world.WorldActor.Trait <EditorCursorLayer>();
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();

            cursorToken = editorCursor.SetActor(wr, actor, owner);
        }
Example #9
0
        public EditorDefaultBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;
            world             = wr.World;

            editorLayer         = world.WorldActor.Trait <EditorActorLayer>();
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();
            resourceLayer       = world.WorldActor.Trait <IResourceLayer>();
        }
Example #10
0
        public EditorDefaultBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;
            world             = wr.World;

            editorLayer = world.WorldActor.Trait <EditorActorLayer>();
            resources   = world.WorldActor.TraitsImplementing <ResourceType>()
                          .ToDictionary(r => r.Info.ResourceType, r => r);
        }
Example #11
0
        public EditorResourceBrush(EditorViewportControllerWidget editorWidget, ResourceTypeInfo resource, WorldRenderer wr)
        {
            this.editorWidget   = editorWidget;
            ResourceType        = resource;
            worldRenderer       = wr;
            world               = wr.World;
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();
            editorCursor        = world.WorldActor.Trait <EditorCursorLayer>();
            action              = new AddResourcesEditorAction(world.Map, ResourceType);

            cursorToken = editorCursor.SetResource(wr, resource);
        }
Example #12
0
        public EditorTileBrush(EditorViewportControllerWidget editorWidget, ushort id, WorldRenderer wr)
        {
            this.editorWidget   = editorWidget;
            worldRenderer       = wr;
            world               = wr.World;
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();
            editorCursor        = world.WorldActor.Trait <EditorCursorLayer>();

            Template      = id;
            worldRenderer = wr;
            world         = wr.World;

            var template = world.Map.Rules.TileSet.Templates.First(t => t.Value.Id == id).Value;

            cursorToken = editorCursor.SetTerrainTemplate(wr, template);
        }
Example #13
0
		public ActorSelectorLogic(Widget widget, World world, WorldRenderer worldRenderer, Ruleset modRules)
		{
			this.modRules = modRules;
			this.world = world;
			this.worldRenderer = worldRenderer;

			editor = widget.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
			ownersDropDown = widget.Get<DropDownButtonWidget>("OWNERS_DROPDOWN");

			panel = widget.Get<ScrollPanelWidget>("ACTORTEMPLATE_LIST");
			itemTemplate = panel.Get<ScrollItemWidget>("ACTORPREVIEW_TEMPLATE");
			panel.Layout = new GridLayout(panel);

			var editorLayer = world.WorldActor.Trait<EditorActorLayer>();

			selectedOwner = editorLayer.Players.Players.Values.First();
			Func<PlayerReference, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
			{
				var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () =>
				{
					selectedOwner = option;

					ownersDropDown.Text = selectedOwner.Name;
					ownersDropDown.TextColor = selectedOwner.Color.RGB;

					IntializeActorPreviews();
				});

				item.Get<LabelWidget>("LABEL").GetText = () => option.Name;
				item.GetColor = () => option.Color.RGB;

				return item;
			};

			ownersDropDown.OnClick = () =>
			{
				var owners = editorLayer.Players.Players.Values.OrderBy(p => p.Name);
				ownersDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem);
			};

			ownersDropDown.Text = selectedOwner.Name;
			ownersDropDown.TextColor = selectedOwner.Color.RGB;

			IntializeActorPreviews();
		}
Example #14
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();
        }
Example #15
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();
        }
Example #16
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();
        }
Example #17
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();
        }
Example #18
0
        public EditorTileBrush(EditorViewportControllerWidget editorWidget, ushort id, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;
            world             = wr.World;
            terrainInfo       = world.Map.Rules.TerrainInfo as ITemplatedTerrainInfo;
            if (terrainInfo == null)
            {
                throw new InvalidDataException("EditorTileBrush can only be used with template-based tilesets");
            }

            editorActionManager = world.WorldActor.Trait <EditorActionManager>();
            editorCursor        = world.WorldActor.Trait <EditorCursorLayer>();

            Template      = id;
            worldRenderer = wr;
            world         = wr.World;

            var template = terrainInfo.Templates.First(t => t.Value.Id == id).Value;

            cursorToken = editorCursor.SetTerrainTemplate(wr, template);
        }