Draw editor terrain/resource preview as part of the world.

This commit is contained in:
Paul Chote
2020-01-12 12:28:06 +00:00
committed by abcdefg30
parent e74033bded
commit cc05621c10
8 changed files with 129 additions and 73 deletions

View File

@@ -12,6 +12,7 @@
using System;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
@@ -36,6 +37,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly TileSet tileset;
readonly TileSelectorTemplate[] allTemplates;
readonly EditorCursorLayer editorCursor;
[ObjectCreator.UseCtor]
public TileSelectorLogic(Widget widget, World world, WorldRenderer worldRenderer)
@@ -43,6 +45,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
tileset = world.Map.Rules.TileSet;
allTemplates = tileset.Templates.Values.Select(t => new TileSelectorTemplate(t)).ToArray();
editorCursor = world.WorldActor.Trait<EditorCursorLayer>();
allCategories = allTemplates.SelectMany(t => t.Categories)
.Distinct()
@@ -98,7 +101,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var tileId = t.Template.Id;
var item = ScrollItemWidget.Setup(ItemTemplate,
() => { var brush = Editor.CurrentBrush as EditorTileBrush; return brush != null && brush.Template == tileId; },
() => editorCursor.Type == EditorCursorType.TerrainTemplate && editorCursor.TerrainTemplate.Id == tileId,
() => Editor.SetBrush(new EditorTileBrush(Editor, tileId, WorldRenderer)));
var preview = item.Get<TerrainTemplatePreviewWidget>("TILE_PREVIEW");