Make brush rendering self-contained
This commit is contained in:
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly DropDownButtonWidget ownersDropDown;
|
||||
readonly Ruleset mapRules;
|
||||
readonly ActorSelectorActor[] allActors;
|
||||
readonly EditorCursorLayer editorCursor;
|
||||
readonly EditorViewportControllerWidget editor;
|
||||
|
||||
PlayerReference selectedOwner;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
mapRules = world.Map.Rules;
|
||||
ownersDropDown = widget.Get<DropDownButtonWidget>("OWNERS_DROPDOWN");
|
||||
editorCursor = world.WorldActor.Trait<EditorCursorLayer>();
|
||||
editor = widget.Parent.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
|
||||
var editorLayer = world.WorldActor.Trait<EditorActorLayer>();
|
||||
|
||||
selectedOwner = editorLayer.Players.Players.Values.First();
|
||||
@@ -167,9 +167,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
ownersDropDown.TextColor = option.Color;
|
||||
InitializePreviews();
|
||||
|
||||
var actor = editorCursor.Actor;
|
||||
if (actor != null)
|
||||
if (editor.CurrentBrush is EditorActorBrush brush)
|
||||
{
|
||||
var actor = brush.Preview;
|
||||
actor.Owner = option;
|
||||
actor.ReplaceInit(new OwnerInit(option.Name));
|
||||
actor.ReplaceInit(new FactionInit(option.Faction));
|
||||
@@ -204,7 +204,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
try
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(ItemTemplate,
|
||||
() => editorCursor.Type == EditorCursorType.Actor && editorCursor.Actor.Info == actor,
|
||||
() => Editor.CurrentBrush is EditorActorBrush eab && eab.Preview.Info == actor,
|
||||
() => Editor.SetBrush(new EditorActorBrush(Editor, actor, selectedOwner, WorldRenderer)));
|
||||
|
||||
var preview = item.Get<ActorPreviewWidget>("ACTOR_PREVIEW");
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
readonly EditorViewportControllerWidget editor;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
readonly EditorCursorLayer editorCursor;
|
||||
|
||||
readonly ScrollPanelWidget layerTemplateList;
|
||||
readonly ScrollItemWidget layerPreviewTemplate;
|
||||
@@ -29,8 +28,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
this.worldRenderer = worldRenderer;
|
||||
editor = widget.Parent.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
|
||||
editorCursor = worldRenderer.World.WorldActor.Trait<EditorCursorLayer>();
|
||||
|
||||
layerTemplateList = widget.Get<ScrollPanelWidget>("LAYERTEMPLATE_LIST");
|
||||
layerTemplateList.Layout = new GridLayout(layerTemplateList);
|
||||
layerPreviewTemplate = layerTemplateList.Get<ScrollItemWidget>("LAYERPREVIEW_TEMPLATE");
|
||||
@@ -46,7 +43,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
foreach (var resourceType in resourceRenderer.ResourceTypes)
|
||||
{
|
||||
var newResourcePreviewTemplate = ScrollItemWidget.Setup(layerPreviewTemplate,
|
||||
() => editorCursor.Type == EditorCursorType.Resource && editorCursor.ResourceType == resourceType,
|
||||
() => editor.CurrentBrush is EditorResourceBrush brush && brush.ResourceType == resourceType,
|
||||
() => editor.SetBrush(new EditorResourceBrush(editor, resourceType, worldRenderer)));
|
||||
|
||||
newResourcePreviewTemplate.Bounds.X = 0;
|
||||
|
||||
@@ -15,7 +15,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Terrain;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -40,7 +39,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
readonly ITemplatedTerrainInfo terrainInfo;
|
||||
readonly TileSelectorTemplate[] allTemplates;
|
||||
readonly EditorCursorLayer editorCursor;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public TileSelectorLogic(Widget widget, ModData modData, World world, WorldRenderer worldRenderer)
|
||||
@@ -51,7 +49,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
throw new InvalidDataException("TileSelectorLogic requires a template-based tileset.");
|
||||
|
||||
allTemplates = terrainInfo.Templates.Values.Select(t => new TileSelectorTemplate(t)).ToArray();
|
||||
editorCursor = world.WorldActor.Trait<EditorCursorLayer>();
|
||||
|
||||
allCategories = allTemplates.SelectMany(t => t.Categories)
|
||||
.Distinct()
|
||||
@@ -108,7 +105,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var tileId = t.Template.Id;
|
||||
var item = ScrollItemWidget.Setup(ItemTemplate,
|
||||
() => editorCursor.Type == EditorCursorType.TerrainTemplate && editorCursor.TerrainTemplate.Id == tileId,
|
||||
() => Editor.CurrentBrush is EditorTileBrush editorCursor && editorCursor.TerrainTemplate.Id == tileId,
|
||||
() => Editor.SetBrush(new EditorTileBrush(Editor, tileId, WorldRenderer)));
|
||||
|
||||
var preview = item.Get<TerrainTemplatePreviewWidget>("TILE_PREVIEW");
|
||||
|
||||
Reference in New Issue
Block a user