Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,56 @@
using System;
using Content.Shared.Body.Scanner;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables;
namespace Content.Client.Body.UI
{
[UsedImplicitly]
public class BodyScannerBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private BodyScannerDisplay? _display;
[ViewVariables]
private IEntity? _entity;
public BodyScannerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { }
protected override void Open()
{
base.Open();
_display = new BodyScannerDisplay(this);
_display.OnClose += Close;
_display.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not BodyScannerUIState scannerState)
{
return;
}
if (!Owner.Owner.EntityManager.TryGetEntity(scannerState.Uid, out _entity))
{
throw new ArgumentException($"Received an invalid entity with id {scannerState.Uid} for body scanner with id {Owner.Owner.Uid} at {Owner.Owner.Transform.MapPosition}");
}
_display?.UpdateDisplay(_entity);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_display?.Dispose();
}
}
}
}

View File

@@ -0,0 +1,181 @@
using System.Linq;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Content.Shared.Damage.Components;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using static Robust.Client.UserInterface.Controls.ItemList;
namespace Content.Client.Body.UI
{
public sealed class BodyScannerDisplay : SS14Window
{
private IEntity? _currentEntity;
private IBodyPart? _currentBodyPart;
private IBody? CurrentBody => _currentEntity?.GetComponentOrNull<IBody>();
public BodyScannerDisplay(BodyScannerBoundUserInterface owner)
{
IoCManager.InjectDependencies(this);
Owner = owner;
Title = Loc.GetString("Body Scanner");
var hSplit = new HBoxContainer
{
Children =
{
// Left half
new ScrollContainer
{
HorizontalExpand = true,
Children =
{
(BodyPartList = new ItemList())
}
},
// Right half
new VBoxContainer
{
HorizontalExpand = true,
Children =
{
// Top half of the right half
new VBoxContainer
{
VerticalExpand = true,
Children =
{
(BodyPartLabel = new Label()),
new HBoxContainer
{
Children =
{
new Label
{
Text = "Health: "
},
(BodyPartHealth = new Label())
}
},
new ScrollContainer
{
VerticalExpand = true,
Children =
{
(MechanismList = new ItemList())
}
}
}
},
// Bottom half of the right half
(MechanismInfoLabel = new RichTextLabel
{
VerticalExpand = true
})
}
}
}
};
Contents.AddChild(hSplit);
BodyPartList.OnItemSelected += BodyPartOnItemSelected;
MechanismList.OnItemSelected += MechanismOnItemSelected;
MinSize = SetSize = (800, 600);
}
public BodyScannerBoundUserInterface Owner { get; }
private ItemList BodyPartList { get; }
private Label BodyPartLabel { get; }
private Label BodyPartHealth { get; }
private ItemList MechanismList { get; }
private RichTextLabel MechanismInfoLabel { get; }
public void UpdateDisplay(IEntity entity)
{
_currentEntity = entity;
BodyPartList.Clear();
var body = CurrentBody;
if (body == null)
{
return;
}
foreach (var (part, _) in body.Parts)
{
BodyPartList.AddItem(Loc.GetString(part.Name));
}
}
public void BodyPartOnItemSelected(ItemListSelectedEventArgs args)
{
var body = CurrentBody;
if (body == null)
{
return;
}
var slot = body.SlotAt(args.ItemIndex);
_currentBodyPart = body.PartAt(args.ItemIndex).Key;
if (slot.Part != null)
{
UpdateBodyPartBox(slot.Part, slot.Id);
}
}
private void UpdateBodyPartBox(IBodyPart part, string slotName)
{
BodyPartLabel.Text = $"{Loc.GetString(slotName)}: {Loc.GetString(part.Owner.Name)}";
// TODO BODY Part damage
if (part.Owner.TryGetComponent(out IDamageableComponent? damageable))
{
BodyPartHealth.Text = Loc.GetString("{0} damage", damageable.TotalDamage);
}
MechanismList.Clear();
foreach (var mechanism in part.Mechanisms)
{
MechanismList.AddItem(mechanism.Name);
}
}
// TODO BODY Guaranteed this is going to crash when a part's mechanisms change. This part is left as an exercise for the reader.
public void MechanismOnItemSelected(ItemListSelectedEventArgs args)
{
UpdateMechanismBox(_currentBodyPart?.Mechanisms.ElementAt(args.ItemIndex));
}
private void UpdateMechanismBox(IMechanism? mechanism)
{
// TODO BODY Improve UI
if (mechanism == null)
{
MechanismInfoLabel.SetMessage("");
return;
}
// TODO BODY Mechanism description
var message =
Loc.GetString(
$"{mechanism.Name}\nHealth: {mechanism.CurrentDurability}/{mechanism.MaxDurability}");
MechanismInfoLabel.SetMessage(message);
}
}
}

View File

@@ -0,0 +1,85 @@
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();
}
}
}
}

View File

@@ -0,0 +1,133 @@
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.Body.UI
{
public class SurgeryWindow : SS14Window
{
public delegate void OptionSelectedCallback(int selectedOptionData);
private readonly VBoxContainer _optionsBox;
private OptionSelectedCallback? _optionSelectedCallback;
public SurgeryWindow()
{
MinSize = SetSize = (300, 400);
Title = Loc.GetString("Surgery");
RectClipContent = true;
var vSplitContainer = new VBoxContainer
{
Children =
{
new ScrollContainer
{
VerticalExpand = true,
HorizontalExpand = true,
HScrollEnabled = true,
VScrollEnabled = true,
Children =
{
(_optionsBox = new VBoxContainer
{
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 HBoxContainer
{
Children =
{
(SpriteView = new SpriteView
{
MinSize = new Vector2(32.0f, 32.0f)
}),
(DisplayText = new Label
{
VerticalAlignment = VAlignment.Center,
Text = "N/A",
}),
(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;
}
}
}