Kill bobby 2.0 (#6023)
This commit is contained in:
@@ -161,7 +161,7 @@ namespace Content.Client.Body.UI
|
||||
UpdateMechanismBox(_currentBodyPart?.Mechanisms.ElementAt(args.ItemIndex));
|
||||
}
|
||||
|
||||
private void UpdateMechanismBox(SharedMechanismComponent? mechanism)
|
||||
private void UpdateMechanismBox(MechanismComponent? mechanism)
|
||||
{
|
||||
// TODO BODY Improve UI
|
||||
if (mechanism == null)
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
using Content.Shared.Body.Surgery;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Body.UI
|
||||
{
|
||||
// TODO BODY Make window close if target or surgery tool gets too far away from user.
|
||||
|
||||
/// <summary>
|
||||
/// Generic client-side UI list popup that allows users to choose from an option
|
||||
/// of limbs or organs to operate on.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public class SurgeryBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private SurgeryWindow? _window;
|
||||
|
||||
public SurgeryBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { }
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
_window = new SurgeryWindow();
|
||||
|
||||
_window.OpenCentered();
|
||||
_window.OnClose += Close;
|
||||
}
|
||||
|
||||
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case RequestBodyPartSurgeryUIMessage msg:
|
||||
HandleBodyPartRequest(msg);
|
||||
break;
|
||||
case RequestMechanismSurgeryUIMessage msg:
|
||||
HandleMechanismRequest(msg);
|
||||
break;
|
||||
case RequestBodyPartSlotSurgeryUIMessage msg:
|
||||
HandleBodyPartSlotRequest(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleBodyPartRequest(RequestBodyPartSurgeryUIMessage msg)
|
||||
{
|
||||
_window?.BuildDisplay(msg.Targets, BodyPartSelectedCallback);
|
||||
}
|
||||
|
||||
private void HandleMechanismRequest(RequestMechanismSurgeryUIMessage msg)
|
||||
{
|
||||
_window?.BuildDisplay(msg.Targets, MechanismSelectedCallback);
|
||||
}
|
||||
|
||||
private void HandleBodyPartSlotRequest(RequestBodyPartSlotSurgeryUIMessage msg)
|
||||
{
|
||||
_window?.BuildDisplay(msg.Targets, BodyPartSlotSelectedCallback);
|
||||
}
|
||||
|
||||
private void BodyPartSelectedCallback(int selectedOptionData)
|
||||
{
|
||||
SendMessage(new ReceiveBodyPartSurgeryUIMessage(selectedOptionData));
|
||||
}
|
||||
|
||||
private void MechanismSelectedCallback(int selectedOptionData)
|
||||
{
|
||||
SendMessage(new ReceiveMechanismSurgeryUIMessage(selectedOptionData));
|
||||
}
|
||||
|
||||
private void BodyPartSlotSelectedCallback(int selectedOptionData)
|
||||
{
|
||||
SendMessage(new ReceiveBodyPartSlotSurgeryUIMessage(selectedOptionData));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
_window?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
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;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Body.UI
|
||||
{
|
||||
public class SurgeryWindow : SS14Window
|
||||
{
|
||||
public delegate void OptionSelectedCallback(int selectedOptionData);
|
||||
|
||||
private readonly BoxContainer _optionsBox;
|
||||
private OptionSelectedCallback? _optionSelectedCallback;
|
||||
|
||||
public SurgeryWindow()
|
||||
{
|
||||
MinSize = SetSize = (300, 400);
|
||||
Title = Loc.GetString("surgery-window-title");
|
||||
RectClipContent = true;
|
||||
|
||||
var vSplitContainer = new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
Children =
|
||||
{
|
||||
new ScrollContainer
|
||||
{
|
||||
VerticalExpand = true,
|
||||
HorizontalExpand = true,
|
||||
HScrollEnabled = true,
|
||||
VScrollEnabled = true,
|
||||
Children =
|
||||
{
|
||||
(_optionsBox = new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
HorizontalExpand = true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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?.Invoke(surgery.CallbackData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SurgeryButton : PanelContainer
|
||||
{
|
||||
public Button Button { get; }
|
||||
|
||||
private SpriteView SpriteView { get; }
|
||||
|
||||
private Label DisplayText { get; }
|
||||
|
||||
public int CallbackData { get; }
|
||||
|
||||
public SurgeryButton(int callbackData)
|
||||
{
|
||||
CallbackData = callbackData;
|
||||
|
||||
Button = new Button
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
VerticalExpand = true,
|
||||
ToggleMode = true,
|
||||
MouseFilter = MouseFilterMode.Stop
|
||||
};
|
||||
|
||||
AddChild(Button);
|
||||
|
||||
AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
(SpriteView = new SpriteView
|
||||
{
|
||||
MinSize = new Vector2(32.0f, 32.0f)
|
||||
}),
|
||||
(DisplayText = new Label
|
||||
{
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
Text = Loc.GetString("surgery-window-not-available-button-text"),
|
||||
}),
|
||||
(new Control
|
||||
{
|
||||
HorizontalExpand = true
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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