Files
OldThink/Content.Client/UserInterface/Systems/Character/CharacterUIController.cs
Remuchi 3cfa1890b0 Tweaks: разные мелкие исправления и корректировки (#22)
* add: система улучшения зрения для слепых

* tweak: повышен урон дробовиков, повышен разброс

* tweak: скорость снарядов лазеров увеличена вдвое

* fix: фикс отображение веревки крюка-кошки

* fix: исправлено отображение воспоминаний

* tweak: перевод геймпресета революции

* fix: фикс отображения цели и рефактор правила культа

* add: Теперь помповые ружья нужно перезаряжать вручную

* tweak: повышен урон других снарядов дробовиков

* tweak: вещмешок синдиката больше не замедляет

* fix: исправлено отображение слота хранилища костюма в инвентаре
2024-02-03 10:49:33 +00:00

225 lines
6.7 KiB
C#

using System.Linq;
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.GameObjects;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
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>
{
[Dependency] private readonly IPlayerManager _player = default!;
[UISystemDependency] private readonly CharacterInfoSystem _characterInfo = default!;
[UISystemDependency] private readonly SpriteSystem _sprite = default!;
private CharacterWindow? _window;
private MenuButton? CharacterButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.CharacterButton;
public void OnStateEntered(GameplayState state)
{
DebugTools.Assert(_window == null);
_window = UIManager.CreateWindow<CharacterWindow>();
LayoutContainer.SetAnchorPreset(_window, LayoutContainer.LayoutPreset.CenterTop);
CommandBinds.Builder
.Bind(ContentKeyFunctions.OpenCharacterMenu,
InputCmdHandler.FromDelegate(_ => ToggleWindow()))
.Register<CharacterUIController>();
}
public void OnStateExited(GameplayState state)
{
if (_window != null)
{
_window.Dispose();
_window = null;
}
CommandBinds.Unregister<CharacterUIController>();
}
public void OnSystemLoaded(CharacterInfoSystem system)
{
system.OnCharacterUpdate += CharacterUpdated;
_player.LocalPlayerDetached += CharacterDetached;
}
public void OnSystemUnloaded(CharacterInfoSystem system)
{
system.OnCharacterUpdate -= CharacterUpdated;
_player.LocalPlayerDetached -= CharacterDetached;
}
public void UnloadButton()
{
if (CharacterButton == null)
{
return;
}
CharacterButton.OnPressed -= CharacterButtonPressed;
}
public void LoadButton()
{
if (CharacterButton == null)
{
return;
}
CharacterButton.OnPressed += CharacterButtonPressed;
if (_window == null)
{
return;
}
_window.OnClose += DeactivateButton;
_window.OnOpen += ActivateButton;
}
private void DeactivateButton() => CharacterButton!.Pressed = false;
private void ActivateButton() => CharacterButton!.Pressed = true;
private void CharacterUpdated(CharacterData data)
{
if (_window == null)
{
return;
}
var (entity, job, objectives, briefing, entityName, memories) = data;
_window.SpriteView.SetEntity(entity);
_window.NameLabel.Text = entityName;
_window.SubText.Text = job;
_window.Objectives.RemoveAllChildren();
_window.Memories.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 = _sprite.Frame0(condition.Icon);
conditionControl.ProgressTexture.Progress = condition.Progress;
var titleMessage = new FormattedMessage();
var descriptionMessage = new FormattedMessage();
titleMessage.AddText(condition.Title);
descriptionMessage.AddText(condition.Description);
conditionControl.Title.SetMessage(titleMessage);
conditionControl.Description.SetMessage(descriptionMessage);
objectiveControl.AddChild(conditionControl);
}
_window.Objectives.AddChild(objectiveControl);
}
//WD EDIT
foreach (var (memoryName, memoryValue) in memories)
{
var memoryControl = new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
Modulate = Color.Gray
};
var text = Loc.TryGetString(memoryName, out var t, ("value", memoryValue))
? t
: $"{memoryName}: {memoryValue}";
memoryControl.AddChild(new Label
{
Text = text,
});
_window.Memories.AddChild(memoryControl);
}
//WD EDIT END
if (briefing != null)
{
var briefingControl = new ObjectiveBriefingControl();
var text = new FormattedMessage();
text.PushColor(Color.Yellow);
text.AddText(briefing);
briefingControl.Label.SetMessage(text);
_window.Objectives.AddChild(briefingControl);
}
var controls = _characterInfo.GetCharacterInfoControls(entity);
foreach (var control in controls)
{
_window.Objectives.AddChild(control);
}
_window.RolePlaceholder.Visible = briefing == null && controls.Count == 0 && objectives.Count == 0;
_window.MemoriesPlaceholder.Visible = memories.Count == 0;
}
private void CharacterDetached(EntityUid uid)
{
CloseWindow();
}
private void CharacterButtonPressed(ButtonEventArgs args)
{
ToggleWindow();
}
private void CloseWindow()
{
_window?.Close();
}
private void ToggleWindow()
{
if (_window == null)
return;
if (CharacterButton != null)
{
CharacterButton.SetClickPressed(!_window.IsOpen);
}
if (_window.IsOpen)
{
CloseWindow();
}
else
{
_characterInfo.RequestCharacterInfo();
_window.Open();
}
}
}