BodySystem stuff 2: overused boogaloo (#1174)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -1,166 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Players;
|
||||
using Content.Shared.BodySystem;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Content.Client.BodySystem
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ClientSurgeryToolComponent : SharedSurgeryToolComponent
|
||||
{
|
||||
private SurgeryToolWindow Window;
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null)
|
||||
{
|
||||
base.HandleNetworkMessage(message, channel, session);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case OpenSurgeryUIMessage msg:
|
||||
HandleOpenSurgeryUIMessage();
|
||||
break;
|
||||
case CloseSurgeryUIMessage msg:
|
||||
HandleCloseSurgeryUIMessage();
|
||||
break;
|
||||
case UpdateSurgeryUIMessage msg:
|
||||
HandleUpdateSurgeryUIMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public override void OnAdd()
|
||||
{
|
||||
base.OnAdd();
|
||||
Window = new SurgeryToolWindow() { SurgeryToolEntity = this };
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
Window.Dispose();
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void HandleOpenSurgeryUIMessage()
|
||||
{
|
||||
Window.Open();
|
||||
}
|
||||
private void HandleCloseSurgeryUIMessage()
|
||||
{
|
||||
Window.Close();
|
||||
}
|
||||
private void HandleUpdateSurgeryUIMessage(UpdateSurgeryUIMessage surgeryUIState)
|
||||
{
|
||||
Window.BuildDisplay(surgeryUIState.Targets);
|
||||
}
|
||||
private class SurgeryToolWindow : SS14Window
|
||||
{
|
||||
private Control _VSplitContainer;
|
||||
private VBoxContainer _bodyPartList;
|
||||
public ClientSurgeryToolComponent SurgeryToolEntity;
|
||||
|
||||
protected override Vector2? CustomSize => (300, 400);
|
||||
|
||||
public SurgeryToolWindow()
|
||||
{
|
||||
Title = "Select surgery target...";
|
||||
RectClipContent = true;
|
||||
|
||||
_VSplitContainer = new VBoxContainer();
|
||||
var listScrollContainer = new ScrollContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
HScrollEnabled = true,
|
||||
VScrollEnabled = true
|
||||
};
|
||||
_bodyPartList = new VBoxContainer
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand
|
||||
};
|
||||
listScrollContainer.AddChild(_bodyPartList);
|
||||
_VSplitContainer.AddChild(listScrollContainer);
|
||||
Contents.AddChild(_VSplitContainer);
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
SurgeryToolEntity.SendNetworkMessage(new CloseSurgeryUIMessage());
|
||||
base.Close();
|
||||
}
|
||||
|
||||
public void BuildDisplay(Dictionary<string, string> targets)
|
||||
{
|
||||
_bodyPartList.DisposeAllChildren();
|
||||
foreach (var(slotName, partname) in targets)
|
||||
{
|
||||
var button = new BodyPartButton(slotName);
|
||||
button.ActualButton.OnToggled += OnButtonPressed;
|
||||
button.LimbName.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(slotName + " - " + partname);
|
||||
|
||||
//button.SpriteView.Sprite = sprite;
|
||||
|
||||
_bodyPartList.AddChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
var parent = (BodyPartButton) args.Button.Parent;
|
||||
SurgeryToolEntity.SendNetworkMessage(new SelectSurgeryUIMessage(parent.LimbSlotName));
|
||||
}
|
||||
}
|
||||
|
||||
private class BodyPartButton : PanelContainer
|
||||
{
|
||||
public Button ActualButton { get; }
|
||||
public SpriteView SpriteView { get; }
|
||||
public Control EntityControl { get; }
|
||||
public Label LimbName { get; }
|
||||
public string LimbSlotName { get; }
|
||||
|
||||
public BodyPartButton(string slotName)
|
||||
{
|
||||
LimbSlotName = slotName;
|
||||
ActualButton = new Button
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
ToggleMode = true,
|
||||
MouseFilter = MouseFilterMode.Stop
|
||||
};
|
||||
AddChild(ActualButton);
|
||||
|
||||
var hBoxContainer = new HBoxContainer();
|
||||
SpriteView = new SpriteView
|
||||
{
|
||||
CustomMinimumSize = new Vector2(32.0f, 32.0f)
|
||||
};
|
||||
LimbName = new Label
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.ShrinkCenter,
|
||||
Text = "N/A",
|
||||
};
|
||||
hBoxContainer.AddChild(SpriteView);
|
||||
hBoxContainer.AddChild(LimbName);
|
||||
|
||||
EntityControl = new Control
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand
|
||||
};
|
||||
hBoxContainer.AddChild(EntityControl);
|
||||
AddChild(hBoxContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Content.Shared.BodySystem;
|
||||
|
||||
namespace Content.Client.BodySystem
|
||||
{
|
||||
|
||||
//TODO : 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>
|
||||
public class GenericSurgeryBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
|
||||
private GenericSurgeryWindow _window;
|
||||
|
||||
public GenericSurgeryBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
_window = new GenericSurgeryWindow();
|
||||
_window.OpenCentered();
|
||||
}
|
||||
|
||||
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)
|
||||
return;
|
||||
_window.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
124
Content.Client/Health/BodySystem/Surgery/GenericSurgeryWindow.cs
Normal file
124
Content.Client/Health/BodySystem/Surgery/GenericSurgeryWindow.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Content.Client.BodySystem
|
||||
{
|
||||
public class GenericSurgeryWindow : SS14Window
|
||||
{
|
||||
public delegate void CloseCallback();
|
||||
public delegate void OptionSelectedCallback(int selectedOptionData);
|
||||
|
||||
private Control _vSplitContainer;
|
||||
private VBoxContainer _optionsBox;
|
||||
private OptionSelectedCallback _optionSelectedCallback;
|
||||
|
||||
|
||||
protected override Vector2? CustomSize => (300, 400);
|
||||
|
||||
public GenericSurgeryWindow()
|
||||
{
|
||||
Title = Loc.GetString("Select surgery target...");
|
||||
RectClipContent = true;
|
||||
_vSplitContainer = new VBoxContainer();
|
||||
var listScrollContainer = new ScrollContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
HScrollEnabled = true,
|
||||
VScrollEnabled = true
|
||||
};
|
||||
_optionsBox = new VBoxContainer
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand
|
||||
};
|
||||
listScrollContainer.AddChild(_optionsBox);
|
||||
_vSplitContainer.AddChild(listScrollContainer);
|
||||
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(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(displayText));
|
||||
|
||||
|
||||
_optionsBox.AddChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
var pressedButton = (SurgeryButton)args.Button.Parent;
|
||||
_optionSelectedCallback(pressedButton.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);
|
||||
var hBoxContainer = new HBoxContainer();
|
||||
SpriteView = new SpriteView
|
||||
{
|
||||
CustomMinimumSize = new Vector2(32.0f, 32.0f)
|
||||
};
|
||||
DisplayText = new Label
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.ShrinkCenter,
|
||||
Text = "N/A",
|
||||
};
|
||||
hBoxContainer.AddChild(SpriteView);
|
||||
hBoxContainer.AddChild(DisplayText);
|
||||
EntityControl = new Control
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand
|
||||
};
|
||||
hBoxContainer.AddChild(EntityControl);
|
||||
AddChild(hBoxContainer);
|
||||
}
|
||||
|
||||
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