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
|
||||
|
||||
@@ -977,10 +977,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
bool PathMightExistForLocomotorBlockedByImmovable(Locomotor locomotor, CPos source, CPos target);
|
||||
}
|
||||
|
||||
public interface IEditorToolInfo : ITraitInfoInterface
|
||||
public interface IEditorTool
|
||||
{
|
||||
string Label { get; }
|
||||
string PanelWidget { get; }
|
||||
bool IsEnabled { get; }
|
||||
TraitInfo TraitInfo { get; }
|
||||
}
|
||||
|
||||
public class MapGenerationException : Exception
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -72,7 +73,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
if (tabType == MenuType.Tools)
|
||||
{
|
||||
var toolsAvailable = world.Map.Rules.Actors[SystemActors.EditorWorld].HasTraitInfo<IEditorToolInfo>();
|
||||
var toolsAvailable = world.WorldActor.TraitsImplementing<IEditorTool>().Any();
|
||||
tab.IsDisabled = () => !toolsAvailable;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,15 +44,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly Widget dropDownSettingTemplate;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public MapGeneratorToolLogic(Widget widget, World world, WorldRenderer worldRenderer, ModData modData,
|
||||
IEditorMapGeneratorInfo tool)
|
||||
public MapGeneratorToolLogic(Widget widget, World world, WorldRenderer worldRenderer, ModData modData, IEditorTool tool)
|
||||
{
|
||||
editorActionManager = world.WorldActor.Trait<EditorActionManager>();
|
||||
|
||||
this.world = world;
|
||||
this.worldRenderer = worldRenderer;
|
||||
this.modData = modData;
|
||||
generator = tool;
|
||||
generator = tool.TraitInfo as IEditorMapGeneratorInfo;
|
||||
settings = generator.GetSettings();
|
||||
|
||||
settingsPanel = widget.Get<ScrollPanelWidget>("SETTINGS_PANEL");
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public MapToolsLogic(Widget widget, World world)
|
||||
{
|
||||
var toolDropdownWidget = widget.Get<DropDownButtonWidget>("TOOLS_DROPDOWN");
|
||||
var tools = world.Map.Rules.Actors[SystemActors.EditorWorld].TraitInfos<IEditorToolInfo>();
|
||||
var tools = world.WorldActor.TraitsImplementing<IEditorTool>();
|
||||
foreach (var tool in tools)
|
||||
{
|
||||
if (tool is IEditorMapGeneratorInfo gi && !gi.Tilesets.Contains(world.Map.Tileset))
|
||||
if (!tool.IsEnabled)
|
||||
continue;
|
||||
|
||||
var panel = Game.LoadWidget(world, tool.PanelWidget, widget, new WidgetArgs() { { "tool", tool } });
|
||||
|
||||
@@ -40,10 +40,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
((ScrollPanelWidget)widget).Layout.AdjustChildren();
|
||||
|
||||
var editCheckbox = widget.Get<CheckboxWidget>("EDIT");
|
||||
editCheckbox.Disabled = !tool.Available;
|
||||
if (!tool.Available)
|
||||
return;
|
||||
|
||||
editCheckbox.IsChecked = () => editorWidget.CurrentBrush is EditorTilingPathBrush;
|
||||
editCheckbox.OnClick = () =>
|
||||
editorWidget.SetBrush(
|
||||
|
||||
@@ -23,7 +23,7 @@ using static OpenRA.Mods.Common.Traits.ResourceLayerInfo;
|
||||
namespace OpenRA.Mods.D2k.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.EditorWorld)]
|
||||
public sealed class D2kMapGeneratorInfo : TraitInfo<D2kMapGenerator>, IEditorMapGeneratorInfo, IEditorToolInfo
|
||||
public sealed class D2kMapGeneratorInfo : TraitInfo, IEditorMapGeneratorInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
public readonly string Type = null;
|
||||
@@ -614,9 +614,24 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
return map;
|
||||
}
|
||||
|
||||
string IEditorToolInfo.Label => Name;
|
||||
string IEditorToolInfo.PanelWidget => PanelWidget;
|
||||
public override object Create(ActorInitializer init)
|
||||
{
|
||||
return new D2kMapGenerator(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class D2kMapGenerator { /* we're only interested in the Info */ }
|
||||
public class D2kMapGenerator : IEditorTool
|
||||
{
|
||||
public string Label { get; }
|
||||
public string PanelWidget { get; }
|
||||
public TraitInfo TraitInfo { get; }
|
||||
public bool IsEnabled => true;
|
||||
|
||||
public D2kMapGenerator(D2kMapGeneratorInfo info)
|
||||
{
|
||||
Label = info.Name;
|
||||
PanelWidget = info.PanelWidget;
|
||||
TraitInfo = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user