Merge remote-tracking branch 'upstream/master' into 20-11-19-sandboxing

This commit is contained in:
Pieter-Jan Briers
2020-11-24 08:39:05 +01:00
3195 changed files with 17920 additions and 17354 deletions

View File

@@ -1,26 +1,30 @@
#nullable enable
using System.Drawing;
using Content.Client.GameObjects.Components.Mobs;
using Content.Client.UserInterface;
using Content.Client.UserInterface.Stylesheets;
using Content.Shared.GameObjects.Components.Actor;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Players;
namespace Content.Client.GameObjects.Components.Actor
{
[RegisterComponent]
public sealed class CharacterInfoComponent : Component, ICharacterUI
public sealed class CharacterInfoComponent : SharedCharacterInfoComponent, ICharacterUI
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
private CharacterInfoControl _control;
private CharacterInfoControl _control = default!;
public override string Name => "CharacterInfo";
public Control Scene { get; private set; }
public Control Scene { get; private set; } = default!;
public UIPriority Priority => UIPriority.Info;
public override void OnAdd()
@@ -30,18 +34,29 @@ namespace Content.Client.GameObjects.Components.Actor
Scene = _control = new CharacterInfoControl(_resourceCache);
}
public override void Initialize()
public void Opened()
{
base.Initialize();
SendNetworkMessage(new RequestCharacterInfoMessage());
}
if (Owner.TryGetComponent(out ISpriteComponent spriteComponent))
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, netChannel, session);
if(session?.AttachedEntity != Owner) return;
switch (message)
{
_control.SpriteView.Sprite = spriteComponent;
}
case CharacterInfoMessage characterInfoMessage:
_control.UpdateUI(characterInfoMessage);
if (Owner.TryGetComponent(out ISpriteComponent? spriteComponent))
{
_control.SpriteView.Sprite = spriteComponent;
}
_control.NameLabel.Text = Owner.Name;
// ReSharper disable once StringLiteralTypo
_control.SubText.Text = Loc.GetString("Professional Greyshirt");
_control.NameLabel.Text = Owner.Name;
break;
}
}
private sealed class CharacterInfoControl : VBoxContainer
@@ -50,8 +65,12 @@ namespace Content.Client.GameObjects.Components.Actor
public Label NameLabel { get; }
public Label SubText { get; }
public VBoxContainer ObjectivesContainer { get; }
public CharacterInfoControl(IResourceCache resourceCache)
{
IoCManager.InjectDependencies(this);
AddChild(new HBoxContainer
{
Children =
@@ -66,7 +85,8 @@ namespace Content.Client.GameObjects.Components.Actor
(SubText = new Label
{
SizeFlagsVertical = SizeFlags.None,
StyleClasses = {StyleNano.StyleClassLabelSubText}
StyleClasses = {StyleNano.StyleClassLabelSubText},
})
}
}
@@ -78,16 +98,65 @@ namespace Content.Client.GameObjects.Components.Actor
PlaceholderText = Loc.GetString("Health & status effects")
});
AddChild(new Placeholder(resourceCache)
AddChild(new Label
{
PlaceholderText = Loc.GetString("Objectives")
Text = Loc.GetString("Objectives"),
SizeFlagsHorizontal = SizeFlags.ShrinkCenter
});
ObjectivesContainer = new VBoxContainer();
AddChild(ObjectivesContainer);
AddChild(new Placeholder(resourceCache)
{
PlaceholderText = Loc.GetString("Antagonist Roles")
});
}
public void UpdateUI(CharacterInfoMessage characterInfoMessage)
{
SubText.Text = characterInfoMessage.JobTitle;
ObjectivesContainer.RemoveAllChildren();
foreach (var (groupId, objectiveConditions) in characterInfoMessage.Objectives)
{
var vbox = new VBoxContainer
{
Modulate = Color.Gray
};
vbox.AddChild(new Label
{
Text = groupId,
Modulate = Color.LightSkyBlue
});
foreach (var objectiveCondition in objectiveConditions)
{
var hbox = new HBoxContainer();
hbox.AddChild(new ProgressTextureRect
{
Texture = objectiveCondition.SpriteSpecifier.Frame0(),
Progress = objectiveCondition.Progress,
SizeFlagsVertical = SizeFlags.ShrinkCenter
});
hbox.AddChild(new Control
{
CustomMinimumSize = (10,0)
});
hbox.AddChild(new VBoxContainer
{
Children =
{
new Label{Text = objectiveCondition.Title},
new Label{Text = objectiveCondition.Description}
}
}
);
vbox.AddChild(hbox);
}
ObjectivesContainer.AddChild(vbox);
}
}
}
}
}

View File

@@ -116,6 +116,7 @@ namespace Content.Client.GameObjects.Components.Actor
public class CharacterWindow : SS14Window
{
private readonly VBoxContainer _contentsVBox;
private readonly List<ICharacterUI> _windowComponents;
public CharacterWindow(List<ICharacterUI> windowComponents)
{
@@ -129,6 +130,17 @@ namespace Content.Client.GameObjects.Components.Actor
{
_contentsVBox.AddChild(element.Scene);
}
_windowComponents = windowComponents;
}
protected override void Opened()
{
base.Opened();
foreach (var windowComponent in _windowComponents)
{
windowComponent.Opened();
}
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using Content.Client.GameObjects.EntitySystems.DoAfter;
using Robust.Client.Graphics.Drawing;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Maths;
namespace Content.Client.GameObjects.Components.Actor
{
public class ProgressTextureRect : TextureRect
{
public float Progress;
protected override void Draw(DrawingHandleScreen handle)
{
var dims = Texture != null ? GetDrawDimensions(Texture) : UIBox2.FromDimensions(Vector2.Zero, PixelSize);
dims.Top = Math.Max(dims.Bottom - dims.Bottom * Progress,0);
handle.DrawRect(dims, DoAfterHelpers.GetProgressColor(Progress));
base.Draw(handle);
}
}
}

View File

@@ -1,9 +1,13 @@
using Content.Client.GameObjects.Components.Items;
#nullable enable
using Content.Client.GameObjects.Components.HUD.Inventory;
using Content.Client.GameObjects.Components.Items;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.Components.Items;
using Robust.Client.Graphics;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -18,8 +22,29 @@ namespace Content.Client.GameObjects.Components.Clothing
public override string Name => "Clothing";
public override uint? NetID => ContentNetIDs.CLOTHING;
private string? _clothingEquippedPrefix;
[ViewVariables(VVAccess.ReadWrite)]
public string ClothingEquippedPrefix { get; set; }
public string? ClothingEquippedPrefix
{
get => _clothingEquippedPrefix;
set
{
if (_clothingEquippedPrefix == value)
return;
_clothingEquippedPrefix = value;
if (!Owner.TryGetContainer(out IContainer? container))
return;
if (!container.Owner.TryGetComponent(out ClientInventoryComponent? inventory))
return;
if (!inventory.TryFindItemSlots(Owner, out EquipmentSlotDefines.Slots? slots))
return;
inventory.SetSlotVisuals(slots.Value, Owner);
}
}
[ViewVariables(VVAccess.ReadWrite)]
public FemaleClothingMask FemaleMask
@@ -54,7 +79,7 @@ namespace Content.Client.GameObjects.Components.Clothing
return null;
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState == null)
return;

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Client.GameObjects.Components.Clothing;
using Content.Shared.GameObjects.Components.Inventory;
@@ -22,10 +24,9 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
{
private readonly Dictionary<Slots, IEntity> _slots = new Dictionary<Slots, IEntity>();
[ViewVariables]
public InventoryInterfaceController InterfaceController { get; private set; }
[ViewVariables] public InventoryInterfaceController InterfaceController { get; private set; } = default!;
private ISpriteComponent _sprite;
private ISpriteComponent? _sprite;
private bool _playerAttached = false;
@@ -69,7 +70,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
}
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
@@ -126,7 +127,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
return;
}
if (entity != null && entity.TryGetComponent(out ClothingComponent clothing))
if (entity.TryGetComponent(out ClothingComponent? clothing))
{
var flag = SlotMasks[slot];
var data = clothing.GetEquippedStateInfo(flag);
@@ -155,6 +156,9 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
internal void ClearAllSlotVisuals()
{
if (_sprite == null)
return;
foreach (var slot in InventoryInstance.SlotMasks)
{
if (slot != Slots.NONE)
@@ -192,7 +196,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
SendNetworkMessage(new OpenSlotStorageUIMessage(slot));
}
public override void HandleMessage(ComponentMessage message, IComponent component)
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
@@ -210,9 +214,25 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
}
}
public bool TryGetSlot(Slots slot, out IEntity item)
public bool TryGetSlot(Slots slot, out IEntity? item)
{
return _slots.TryGetValue(slot, out item);
}
public bool TryFindItemSlots(IEntity item, [NotNullWhen(true)] out Slots? slots)
{
slots = null;
foreach (var (slot, entity) in _slots)
{
if (entity == item)
{
slots = slot;
return true;
}
}
return false;
}
}
}

View File

@@ -17,5 +17,10 @@ namespace Content.Client.GameObjects.Components.Mobs
/// The order it will appear in the character UI, higher is lower
/// </summary>
UIPriority Priority { get; }
/// <summary>
/// Called when the CharacterUi was opened
/// </summary>
void Opened(){}
}
}