Make brush rendering self-contained
This commit is contained in:
@@ -11,12 +11,23 @@
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Widgets;
|
||||
using Color = OpenRA.Primitives.Color;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
public class EditorViewportControllerWidget : Widget
|
||||
{
|
||||
[Desc("Main color of the selection grid.")]
|
||||
public readonly Color SelectionMainColor = Color.White;
|
||||
|
||||
[Desc("Alternate color of the selection grid.")]
|
||||
public readonly Color SelectionAltColor = Color.Black;
|
||||
|
||||
[Desc("Main color of the copy / paste grid.")]
|
||||
public readonly Color PasteColor = Color.FromArgb(0xFF4CFF00);
|
||||
|
||||
public IEditorBrush CurrentBrush { get; private set; }
|
||||
|
||||
public readonly string TooltipContainer;
|
||||
@@ -27,6 +38,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
readonly Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
readonly EditorCursorLayer editorCursor;
|
||||
public int2 SelectionAltOffset { get; }
|
||||
|
||||
bool enableTooltips;
|
||||
|
||||
@@ -37,8 +50,15 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
CurrentBrush = DefaultBrush = new EditorDefaultBrush(this, worldRenderer);
|
||||
|
||||
editorCursor = worldRenderer.World.WorldActor.Trait<EditorCursorLayer>();
|
||||
editorCursor.SetBrush(CurrentBrush);
|
||||
|
||||
// Allow zooming out to full map size
|
||||
worldRenderer.Viewport.UnlockMinimumZoom(0.25f);
|
||||
|
||||
SelectionAltOffset = worldRenderer.World.Map.Grid.Type == MapGridType.Rectangular
|
||||
? new int2(1, 1)
|
||||
: new int2(0, 1);
|
||||
}
|
||||
|
||||
public void ClearBrush() { SetBrush(null); }
|
||||
@@ -50,6 +70,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
CurrentBrush = brush ?? DefaultBrush;
|
||||
|
||||
BrushChanged?.Invoke();
|
||||
editorCursor.SetBrush(CurrentBrush);
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
|
||||
@@ -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