Hud refactor (#7202)
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Jezithyr <jmaster9999@gmail.com> Co-authored-by: Jezithyr <Jezithyr@gmail.com> Co-authored-by: Visne <39844191+Visne@users.noreply.github.com> Co-authored-by: wrexbe <wrexbe@protonmail.com> Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
using Content.Client.CharacterInfo;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Client.UserInterface.Systems.Character.Controls;
|
||||
using Content.Client.UserInterface.Systems.Character.Windows;
|
||||
using Content.Client.UserInterface.Systems.Objectives.Controls;
|
||||
using Content.Shared.Input;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Utility;
|
||||
using static Content.Client.CharacterInfo.CharacterInfoSystem;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Character;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class CharacterUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>, IOnSystemChanged<CharacterInfoSystem>
|
||||
{
|
||||
[UISystemDependency] private readonly CharacterInfoSystem _characterInfo = default!;
|
||||
|
||||
private CharacterWindow? _window;
|
||||
private MenuButton? _characterButton;
|
||||
|
||||
public void OnStateEntered(GameplayState state)
|
||||
{
|
||||
DebugTools.Assert(_window == null);
|
||||
_characterButton = UIManager.GetActiveUIWidget<MenuBar.Widgets.GameTopMenuBar>().CharacterButton;
|
||||
_characterButton.OnPressed += CharacterButtonPressed;
|
||||
|
||||
_window = UIManager.CreateWindow<CharacterWindow>();
|
||||
LayoutContainer.SetAnchorPreset(_window, LayoutContainer.LayoutPreset.CenterTop);
|
||||
|
||||
_window.OnClose += () => { _characterButton.Pressed = false; };
|
||||
_window.OnOpen += () => { _characterButton.Pressed = true; };
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.OpenCharacterMenu,
|
||||
InputCmdHandler.FromDelegate(_ => ToggleWindow()))
|
||||
.Register<CharacterUIController>();
|
||||
}
|
||||
|
||||
public void OnStateExited(GameplayState state)
|
||||
{
|
||||
if (_window != null)
|
||||
{
|
||||
_window.Dispose();
|
||||
_window = null;
|
||||
}
|
||||
|
||||
if (_characterButton != null)
|
||||
{
|
||||
_characterButton.OnPressed -= CharacterButtonPressed;
|
||||
_characterButton.Pressed = false;
|
||||
_characterButton = null;
|
||||
}
|
||||
|
||||
CommandBinds.Unregister<CharacterUIController>();
|
||||
}
|
||||
|
||||
public void OnSystemLoaded(CharacterInfoSystem system)
|
||||
{
|
||||
system.OnCharacterUpdate += CharacterUpdated;
|
||||
system.OnCharacterDetached += CharacterDetached;
|
||||
}
|
||||
|
||||
public void OnSystemUnloaded(CharacterInfoSystem system)
|
||||
{
|
||||
system.OnCharacterUpdate -= CharacterUpdated;
|
||||
system.OnCharacterDetached -= CharacterDetached;
|
||||
}
|
||||
|
||||
private void CharacterUpdated(CharacterData data)
|
||||
{
|
||||
if (_window == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var (job, objectives, briefing, sprite, entityName) = data;
|
||||
|
||||
_window.SubText.Text = job;
|
||||
_window.Objectives.RemoveAllChildren();
|
||||
|
||||
foreach (var (groupId, conditions) in objectives)
|
||||
{
|
||||
var objectiveControl = new CharacterObjectiveControl
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
Modulate = Color.Gray
|
||||
};
|
||||
|
||||
objectiveControl.AddChild(new Label
|
||||
{
|
||||
Text = groupId,
|
||||
Modulate = Color.LightSkyBlue
|
||||
});
|
||||
|
||||
foreach (var condition in conditions)
|
||||
{
|
||||
var conditionControl = new ObjectiveConditionsControl();
|
||||
conditionControl.ProgressTexture.Texture = condition.SpriteSpecifier.Frame0();
|
||||
conditionControl.ProgressTexture.Progress = condition.Progress;
|
||||
|
||||
conditionControl.Title.Text = condition.Title;
|
||||
conditionControl.Description.Text = condition.Description;
|
||||
|
||||
objectiveControl.AddChild(conditionControl);
|
||||
}
|
||||
|
||||
var briefingControl = new ObjectiveBriefingControl();
|
||||
briefingControl.Label.Text = briefing;
|
||||
|
||||
objectiveControl.AddChild(briefingControl);
|
||||
_window.Objectives.AddChild(objectiveControl);
|
||||
}
|
||||
|
||||
_window.SpriteView.Sprite = sprite;
|
||||
_window.NameLabel.Text = entityName;
|
||||
}
|
||||
|
||||
private void CharacterDetached()
|
||||
{
|
||||
CloseWindow();
|
||||
}
|
||||
|
||||
private void CharacterButtonPressed(ButtonEventArgs args)
|
||||
{
|
||||
ToggleWindow();
|
||||
}
|
||||
|
||||
private void CloseWindow()
|
||||
{
|
||||
_window!.Close();
|
||||
}
|
||||
|
||||
private void ToggleWindow()
|
||||
{
|
||||
if (_window == null)
|
||||
return;
|
||||
if (_window.IsOpen)
|
||||
{
|
||||
CloseWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
_characterInfo.RequestCharacterInfo();
|
||||
_window.Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<controls:CharacterObjectiveControl
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:cc="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Systems.Character.Controls"
|
||||
Orientation="Vertical"
|
||||
Modulate="#808080">
|
||||
<Label Name="Group" Modulate="#87CEFA" Access="Public"/>
|
||||
</controls:CharacterObjectiveControl>
|
||||
@@ -0,0 +1,14 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Character.Controls;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class CharacterObjectiveControl : BoxContainer
|
||||
{
|
||||
public CharacterObjectiveControl()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<windows:CharacterWindow
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:cc="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:windows="clr-namespace:Content.Client.UserInterface.Systems.Character.Windows"
|
||||
Title="{Loc 'character-info-title'}"
|
||||
MinWidth="400"
|
||||
MinHeight="545">
|
||||
<ScrollContainer>
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<SpriteView OverrideDirection="South" Scale="2 2" Name="SpriteView" Access="Public"/>
|
||||
<BoxContainer Orientation="Vertical" VerticalAlignment="Top">
|
||||
<Label Name="NameLabel" Access="Public"/>
|
||||
<Label Name="SubText" VerticalAlignment="Top" StyleClasses="LabelSubText" Access="Public"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<Label Text="{Loc 'character-info-objectives-label'}" HorizontalAlignment="Center"/>
|
||||
<BoxContainer Orientation="Vertical" Name="Objectives" Access="Public"/>
|
||||
<cc:Placeholder PlaceholderText="{Loc 'character-info-roles-antagonist-text'}"/>
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
</windows:CharacterWindow>
|
||||
@@ -0,0 +1,14 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Character.Windows;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class CharacterWindow : DefaultWindow
|
||||
{
|
||||
public CharacterWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user