mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 09:37:03 +02:00
* Find PlacementModes by attribute * Let modes specify priority * Make some PlacementManager dependencies public so Content can use them * Space out the priorities a bit more * xmldoc for attribute * Revert "xmldoc for attribute" This reverts commitf1f0299c55. * Revert "Space out the priorities a bit more" This reverts commit549eac1eb2. * Revert "Make some PlacementManager dependencies public so Content can use them" This reverts commitc060f6cb2d. * Revert "Let modes specify priority" This reverts commitf113b40c7f. * Revert "Find PlacementModes by attribute" This reverts commit27efb6c5cf. * Completely redo to use PlacementManager's mode dictionary * Backwards compat * Cache the value of AllModeNames
77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Placement;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Graphics;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Robust.Client.UserInterface.CustomControls
|
|
{
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class EntitySpawnWindow : DefaultWindow
|
|
{
|
|
[Dependency] private readonly IPlacementManager _placement = default!;
|
|
|
|
public EntitySpawnButton? SelectedButton;
|
|
public EntityPrototype? SelectedPrototype;
|
|
|
|
[Obsolete("Use IPlacementManager.AllModeNames")]
|
|
public static string[] InitOpts =>IoCManager.Resolve<IPlacementManager>().AllModeNames;
|
|
public EntitySpawnWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
MeasureButton.Measure(Vector2Helpers.Infinity);
|
|
|
|
var modes = _placement.AllModeNames;
|
|
for (var i = 0; i < modes.Length; i++)
|
|
{
|
|
OverrideMenu.AddItem(modes[i], i);
|
|
}
|
|
}
|
|
|
|
// Create a spawn button and insert it into the start or end of the list.
|
|
public EntitySpawnButton InsertEntityButton(EntityPrototype prototype, bool insertFirst, int index)
|
|
{
|
|
var button = new EntitySpawnButton
|
|
{
|
|
Prototype = prototype,
|
|
Index = index // We track this index purely for debugging.
|
|
};
|
|
var entityLabelText = string.IsNullOrEmpty(prototype.Name) ? prototype.ID : prototype.Name;
|
|
|
|
if (!string.IsNullOrWhiteSpace(prototype.EditorSuffix))
|
|
{
|
|
entityLabelText += $" [{prototype.EditorSuffix}]";
|
|
}
|
|
|
|
button.EntityLabel.Text = entityLabelText;
|
|
button.ActualButton.ToolTip = prototype.Description;
|
|
|
|
if (prototype == SelectedPrototype)
|
|
{
|
|
SelectedButton = button;
|
|
SelectedButton.ActualButton.Pressed = true;
|
|
}
|
|
|
|
var rect = button.EntityTextureRects;
|
|
rect.SetPrototype(prototype.ID);
|
|
|
|
PrototypeList.AddChild(button);
|
|
if (insertFirst)
|
|
{
|
|
button.SetPositionInParent(0);
|
|
}
|
|
|
|
return button;
|
|
}
|
|
}
|
|
}
|