Allow tools to disable themselves
This commit is contained in:
committed by
Matthias Mailänder
parent
f8921226b8
commit
42181d77a5
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.EditorWorld)]
|
||||
[Desc("A map generator that clears a map.")]
|
||||
public sealed class ClearMapGeneratorInfo : TraitInfo<ClearMapGenerator>, IEditorMapGeneratorInfo, IEditorToolInfo
|
||||
public sealed class ClearMapGeneratorInfo : TraitInfo, IEditorMapGeneratorInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[Desc("Human-readable name this generator uses.")]
|
||||
@@ -93,10 +93,26 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return map;
|
||||
}
|
||||
|
||||
string IEditorToolInfo.Label => Name;
|
||||
string IEditorToolInfo.PanelWidget => PanelWidget;
|
||||
public override object Create(ActorInitializer init)
|
||||
{
|
||||
return new ClearMapGenerator(this);
|
||||
}
|
||||
|
||||
string[] IEditorMapGeneratorInfo.Tilesets => Tilesets;
|
||||
}
|
||||
|
||||
public class ClearMapGenerator { /* we're only interested in the Info */ }
|
||||
public class ClearMapGenerator : IEditorTool
|
||||
{
|
||||
public string Label { get; }
|
||||
public string PanelWidget { get; }
|
||||
public TraitInfo TraitInfo { get; }
|
||||
public bool IsEnabled => true;
|
||||
|
||||
public ClearMapGenerator(ClearMapGeneratorInfo info)
|
||||
{
|
||||
Label = info.Name;
|
||||
PanelWidget = info.PanelWidget;
|
||||
TraitInfo = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ using static OpenRA.Mods.Common.Traits.ResourceLayerInfo;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.EditorWorld)]
|
||||
public sealed class ExperimentalMapGeneratorInfo : TraitInfo<ExperimentalMapGenerator>, IEditorMapGeneratorInfo, IEditorToolInfo
|
||||
public sealed class ExperimentalMapGeneratorInfo : TraitInfo, IEditorMapGeneratorInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
public readonly string Type = null;
|
||||
@@ -899,9 +899,25 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return map;
|
||||
}
|
||||
|
||||
string IEditorToolInfo.Label => Name;
|
||||
string IEditorToolInfo.PanelWidget => PanelWidget;
|
||||
public override object Create(ActorInitializer init)
|
||||
{
|
||||
return new ExperimentalMapGenerator(init, this);
|
||||
}
|
||||
}
|
||||
|
||||
public class ExperimentalMapGenerator { /* we're only interested in the Info */ }
|
||||
public class ExperimentalMapGenerator : IEditorTool
|
||||
{
|
||||
public string Label { get; }
|
||||
public string PanelWidget { get; }
|
||||
public TraitInfo TraitInfo { get; }
|
||||
public bool IsEnabled { get; }
|
||||
|
||||
public ExperimentalMapGenerator(ActorInitializer init, ExperimentalMapGeneratorInfo info)
|
||||
{
|
||||
Label = info.Name;
|
||||
PanelWidget = info.PanelWidget;
|
||||
TraitInfo = info;
|
||||
IsEnabled = info.Tilesets.Contains(init.Self.World.Map.Tileset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ using Color = OpenRA.Primitives.Color;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.EditorWorld)]
|
||||
public class MarkerLayerOverlayInfo : TraitInfo, IEditorToolInfo
|
||||
public class MarkerLayerOverlayInfo : TraitInfo
|
||||
{
|
||||
[FluentReference]
|
||||
[Desc("The label to show in the tools menu.")]
|
||||
@@ -53,13 +53,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
return new MarkerLayerOverlay(init.Self, this);
|
||||
}
|
||||
|
||||
string IEditorToolInfo.Label => Label;
|
||||
string IEditorToolInfo.PanelWidget => PanelWidget;
|
||||
}
|
||||
|
||||
public class MarkerLayerOverlay : IRenderAnnotations, INotifyActorDisposing, IWorldLoaded
|
||||
public class MarkerLayerOverlay : IEditorTool, IRenderAnnotations, INotifyActorDisposing, IWorldLoaded
|
||||
{
|
||||
public string Label { get; }
|
||||
public string PanelWidget { get; }
|
||||
public TraitInfo TraitInfo { get; }
|
||||
public bool IsEnabled => true;
|
||||
|
||||
public class MarkerLayer
|
||||
{
|
||||
public readonly Dictionary<int, CPos[]> Tiles;
|
||||
@@ -132,6 +134,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Info = info;
|
||||
world = self.World;
|
||||
var map = self.World.Map;
|
||||
Label = info.Label;
|
||||
PanelWidget = info.PanelWidget;
|
||||
|
||||
tileAlpha = info.Alpha;
|
||||
alphaBlendColors = new Color[info.Colors.Length];
|
||||
|
||||
@@ -23,14 +23,9 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.EditorWorld)]
|
||||
public sealed class TilingPathToolInfo : TraitInfo, IEditorToolInfo
|
||||
[IncludeStaticFluentReferences(typeof(TilingPathTool))]
|
||||
public sealed class TilingPathToolInfo : TraitInfo
|
||||
{
|
||||
[FluentReference]
|
||||
const string Label = "label-tool-tiling-path";
|
||||
|
||||
[Desc("The widget tree to open when the tool is selected.")]
|
||||
const string PanelWidget = "TILING_PATH_TOOL_PANEL";
|
||||
|
||||
[Desc("The preferred defaults for the start type.")]
|
||||
public readonly string[] DefaultStart = [];
|
||||
[Desc("The preferred defaults for the inner type.")]
|
||||
@@ -42,13 +37,22 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
return new TilingPathTool(init.Self, this);
|
||||
}
|
||||
|
||||
string IEditorToolInfo.Label => Label;
|
||||
string IEditorToolInfo.PanelWidget => PanelWidget;
|
||||
}
|
||||
|
||||
public sealed class TilingPathTool : IRenderAnnotations, INotifyActorDisposing, IWorldLoaded
|
||||
public sealed class TilingPathTool : IEditorTool, IRenderAnnotations, INotifyActorDisposing, IWorldLoaded
|
||||
{
|
||||
[FluentReference]
|
||||
const string Label = "label-tool-tiling-path";
|
||||
|
||||
[Desc("The widget tree to open when the tool is selected.")]
|
||||
const string PanelWidget = "TILING_PATH_TOOL_PANEL";
|
||||
|
||||
public bool IsEnabled { get; }
|
||||
|
||||
string IEditorTool.Label => Label;
|
||||
string IEditorTool.PanelWidget => PanelWidget;
|
||||
public TraitInfo TraitInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the shape of a path being planned out in the map editor.
|
||||
/// </summary>
|
||||
@@ -312,9 +316,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Whether the TilingPathTool can be used.</summary>
|
||||
public readonly bool Available;
|
||||
|
||||
public readonly World World;
|
||||
public WorldRenderer WorldRenderer = null;
|
||||
public readonly ImmutableArray<MultiBrush> SegmentedBrushes;
|
||||
@@ -338,6 +339,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public TilingPathTool(Actor self, TilingPathToolInfo info)
|
||||
{
|
||||
World = self.World;
|
||||
TraitInfo = info;
|
||||
|
||||
var templatedTerrainInfo = World.Map.Rules.TerrainInfo as ITemplatedTerrainInfo;
|
||||
SegmentedBrushes =
|
||||
@@ -347,9 +349,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.Where(multiBrush => multiBrush.Segment != null)
|
||||
.ToImmutableArray();
|
||||
|
||||
Available = SegmentedBrushes.Length > 0;
|
||||
|
||||
if (!Available)
|
||||
IsEnabled = SegmentedBrushes.Length > 0;
|
||||
if (!IsEnabled)
|
||||
return;
|
||||
|
||||
InnerTypes = SegmentedBrushes
|
||||
|
||||
Reference in New Issue
Block a user