Change all of body system to use entities and components (#2074)
* Early commit * Early commit 2 * merging master broke my git * does anyone even read these * life is fleeting * it just works * this time passing integration tests * Remove hashset yaml serialization for now * You got a license for those nullables? * No examine, no context menu, part and mechanism parenting and visibility * Fix wrong brain sprite state * Removing layers was a mistake * just tear body system a new one and see if it still breathes * Remove redundant code * Add that comment back * Separate damage and body, component states, stomach rework * Add containers for body parts * Bring layers back pls * Fix parts magically changing color * Reimplement sprite layer visibility * Fix tests * Add leg test * Active legs is gone Crab rave * Merge fixes, rename DamageState to CurrentState * Remove IShowContextMenu and ICanExamine
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Body.Surgery
|
||||
{
|
||||
public class SurgeryWindow : SS14Window
|
||||
{
|
||||
public delegate void OptionSelectedCallback(int selectedOptionData);
|
||||
|
||||
private readonly VBoxContainer _optionsBox;
|
||||
private OptionSelectedCallback _optionSelectedCallback;
|
||||
|
||||
protected override Vector2? CustomSize => (300, 400);
|
||||
|
||||
public SurgeryWindow()
|
||||
{
|
||||
Title = Loc.GetString("Select surgery target...");
|
||||
RectClipContent = true;
|
||||
|
||||
var vSplitContainer = new VBoxContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new ScrollContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
HScrollEnabled = true,
|
||||
VScrollEnabled = true,
|
||||
Children =
|
||||
{
|
||||
(_optionsBox = new VBoxContainer
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Contents.AddChild(vSplitContainer);
|
||||
}
|
||||
|
||||
public void BuildDisplay(Dictionary<string, int> data, OptionSelectedCallback callback)
|
||||
{
|
||||
_optionsBox.DisposeAllChildren();
|
||||
_optionSelectedCallback = callback;
|
||||
|
||||
foreach (var (displayText, callbackData) in data)
|
||||
{
|
||||
var button = new SurgeryButton(callbackData);
|
||||
|
||||
button.SetOnToggleBehavior(OnButtonPressed);
|
||||
button.SetDisplayText(Loc.GetString(displayText));
|
||||
|
||||
_optionsBox.AddChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
if (args.Button.Parent is SurgeryButton surgery)
|
||||
{
|
||||
_optionSelectedCallback(surgery.CallbackData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SurgeryButton : PanelContainer
|
||||
{
|
||||
public Button Button { get; }
|
||||
|
||||
private SpriteView SpriteView { get; }
|
||||
|
||||
private Control EntityControl { get; }
|
||||
|
||||
private Label DisplayText { get; }
|
||||
|
||||
public int CallbackData { get; }
|
||||
|
||||
public SurgeryButton(int callbackData)
|
||||
{
|
||||
CallbackData = callbackData;
|
||||
|
||||
Button = new Button
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
ToggleMode = true,
|
||||
MouseFilter = MouseFilterMode.Stop
|
||||
};
|
||||
|
||||
AddChild(Button);
|
||||
|
||||
AddChild(new HBoxContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
(SpriteView = new SpriteView
|
||||
{
|
||||
CustomMinimumSize = new Vector2(32.0f, 32.0f)
|
||||
}),
|
||||
(DisplayText = new Label
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.ShrinkCenter,
|
||||
Text = "N/A",
|
||||
}),
|
||||
(new Control
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void SetDisplayText(string text)
|
||||
{
|
||||
DisplayText.Text = text;
|
||||
}
|
||||
|
||||
public void SetOnToggleBehavior(Action<BaseButton.ButtonToggledEventArgs> behavior)
|
||||
{
|
||||
Button.OnToggled += behavior;
|
||||
}
|
||||
|
||||
public void SetSprite()
|
||||
{
|
||||
//button.SpriteView.Sprite = sprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user