Files
crystall-punk-14/Content.Client/CharacterInfo/Components/CharacterInfoComponent.cs

172 lines
6.1 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
using Content.Client.CharacterInterface;
using Content.Client.HUD.UI;
using Content.Client.Stylesheets;
using Content.Shared.CharacterInfo;
using Robust.Client.GameObjects;
using Robust.Client.ResourceManagement;
2019-07-20 14:06:54 +02:00
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
2019-07-20 14:06:54 +02:00
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Players;
2019-07-20 14:06:54 +02:00
2021-06-09 22:19:39 +02:00
namespace Content.Client.CharacterInfo.Components
2019-07-20 14:06:54 +02:00
{
2019-07-31 15:02:36 +02:00
[RegisterComponent]
public sealed class CharacterInfoComponent : SharedCharacterInfoComponent, ICharacterUI
2019-07-20 14:06:54 +02:00
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
2019-07-20 14:06:54 +02:00
private CharacterInfoControl _control = default!;
2019-07-20 14:06:54 +02:00
public Control Scene { get; private set; } = default!;
2019-07-20 14:06:54 +02:00
public UIPriority Priority => UIPriority.Info;
protected override void OnAdd()
2019-07-20 14:06:54 +02:00
{
base.OnAdd();
Scene = _control = new CharacterInfoControl(_resourceCache);
2019-07-20 14:06:54 +02:00
}
public void Opened()
{
SendNetworkMessage(new RequestCharacterInfoMessage());
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
2019-07-20 14:06:54 +02:00
{
base.HandleNetworkMessage(message, netChannel, session);
2019-07-20 14:06:54 +02:00
switch (message)
2019-07-20 14:06:54 +02:00
{
case CharacterInfoMessage characterInfoMessage:
_control.UpdateUI(characterInfoMessage);
if (Owner.TryGetComponent(out ISpriteComponent? spriteComponent))
{
_control.SpriteView.Sprite = spriteComponent;
}
2019-07-20 14:06:54 +02:00
_control.NameLabel.Text = Owner.Name;
break;
}
2019-07-20 14:06:54 +02:00
}
private sealed class CharacterInfoControl : BoxContainer
2019-07-20 14:06:54 +02:00
{
public SpriteView SpriteView { get; }
public Label NameLabel { get; }
public Label SubText { get; }
public BoxContainer ObjectivesContainer { get; }
public CharacterInfoControl(IResourceCache resourceCache)
2019-07-20 14:06:54 +02:00
{
IoCManager.InjectDependencies(this);
Orientation = LayoutOrientation.Vertical;
AddChild(new BoxContainer
2019-07-20 14:06:54 +02:00
{
Orientation = LayoutOrientation.Horizontal,
2019-07-20 14:06:54 +02:00
Children =
{
2019-07-20 16:01:01 +02:00
(SpriteView = new SpriteView { Scale = (2, 2)}),
new BoxContainer
2019-07-20 14:06:54 +02:00
{
Orientation = LayoutOrientation.Vertical,
2021-02-21 12:38:56 +01:00
VerticalAlignment = VAlignment.Top,
2019-07-20 14:06:54 +02:00
Children =
{
(NameLabel = new Label()),
(SubText = new Label
{
2021-02-21 12:38:56 +01:00
VerticalAlignment = VAlignment.Top,
StyleClasses = {StyleNano.StyleClassLabelSubText},
2019-07-20 14:06:54 +02:00
})
}
}
}
});
AddChild(new Placeholder()
2019-07-20 14:06:54 +02:00
{
PlaceholderText = Loc.GetString("character-info-health-and-status-effects-text")
2019-07-20 14:06:54 +02:00
});
AddChild(new Label
2019-07-20 14:06:54 +02:00
{
Text = Loc.GetString("character-info-objectives-label"),
2021-02-21 12:38:56 +01:00
HorizontalAlignment = HAlignment.Center
2019-07-20 14:06:54 +02:00
});
ObjectivesContainer = new BoxContainer
{
Orientation = LayoutOrientation.Vertical
};
AddChild(ObjectivesContainer);
2019-07-20 14:06:54 +02:00
AddChild(new Placeholder()
2019-07-20 14:06:54 +02:00
{
PlaceholderText = Loc.GetString("character-info-roles-antagonist-text")
2019-07-20 14:06:54 +02:00
});
}
public void UpdateUI(CharacterInfoMessage characterInfoMessage)
{
SubText.Text = characterInfoMessage.JobTitle;
ObjectivesContainer.RemoveAllChildren();
foreach (var (groupId, objectiveConditions) in characterInfoMessage.Objectives)
{
var vbox = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Modulate = Color.Gray
};
vbox.AddChild(new Label
{
Text = groupId,
Modulate = Color.LightSkyBlue
});
foreach (var objectiveCondition in objectiveConditions)
{
var hbox = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal
};
hbox.AddChild(new ProgressTextureRect
{
Texture = objectiveCondition.SpriteSpecifier.Frame0(),
Progress = objectiveCondition.Progress,
2021-02-21 12:38:56 +01:00
VerticalAlignment = VAlignment.Center
});
hbox.AddChild(new Control
{
2021-02-21 12:38:56 +01:00
MinSize = (10,0)
});
hbox.AddChild(new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Children =
{
new Label{Text = objectiveCondition.Title},
new Label{Text = objectiveCondition.Description}
}
}
);
vbox.AddChild(hbox);
}
ObjectivesContainer.AddChild(vbox);
}
}
2019-07-20 14:06:54 +02:00
}
}
}