Inspector editor UI for a Dresser component. Provides title, sets the selected Dresser target from an inspector selection, and exposes Randomize and Clear buttons which call host RPCs to randomize or clear the dresser and refresh network state.
@using Sandbox;
@using Sandbox.UI;
@attribute [InspectorEditor(typeof(Dresser))]
@inherits Panel
@namespace Sandbox
@implements IInspectorEditor
<root>
<div class="body">
<Label>#ui.dresser.clothing_unavailable</Label>
</div>
<div class="footer">
<UIButton Text="#ui.common.randomize" Icon="🎲" onclick=@DoRandomize></UIButton>
<UIButton Text="#ui.common.clear" Icon="🧹" onclick=@DoClear></UIButton>
</div>
</root>
@code
{
/// <summary>
/// Localized title of the clothing inspector.
/// </summary>
public string Title => "👗 " + Game.Language.GetPhrase( "ui.dresser.title" );
public Dresser Target { get; private set; }
public bool TrySetTarget(List<GameObject> selection)
{
Dresser found = null;
foreach (var go in selection)
{
if ( go.Tags.Has( "player" ) ) continue;
found = go.GetComponentInChildren<Dresser>();
if (found != null) break;
}
if (found == Target) return Target != null;
Target = found;
StateHasChanged();
return Target != null;
}
void DoRandomize() => TryBroadcastRandomize( Target.GameObject );
void DoClear() => TryBroadcastClear( Target.GameObject );
[Rpc.Host]
private static void TryBroadcastRandomize(GameObject go)
{
if ( !go.IsValid() ) return;
var dresser = go.GetComponentInChildren<Dresser>();
if ( dresser is null ) return;
dresser.Randomize();
// Refresh the object to update the clothing items for everyone
go.Network.Refresh();
}
[Rpc.Host]
private static async void TryBroadcastClear(GameObject go)
{
if ( !go.IsValid() ) return;
var dresser = go.GetComponentInChildren<Dresser>();
if ( dresser is null ) return;
dresser.Clothing.Clear();
dresser.Clear();
await dresser.Apply();
// Refresh the object to update the clothing items for everyone
go.Network.Refresh();
}
}