mirror of
https://github.com/corvax-team/ss14-wl.git
synced 2026-02-14 19:29:57 +01:00
95 lines
2.8 KiB
C#
95 lines
2.8 KiB
C#
using Content.Client._WL.Skills.Ui;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared._WL.Skills;
|
|
using Content.Shared._WL.Skills.UI;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
namespace Content.Client._WL.Administration.UI;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class SkillsAdminWindow : FancyWindow
|
|
{
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
private readonly SharedSkillsSystem _skillsSystem;
|
|
|
|
public event Action<byte, int>? OnSkillChanged;
|
|
public event Action<int>? OnPointsChanged;
|
|
public event Action? OnResetAll;
|
|
|
|
private Dictionary<byte, int> _currentSkills = new();
|
|
private int _bonusPoints;
|
|
private int _spentPoints;
|
|
|
|
public SkillsAdminWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_skillsSystem = _entMan.System<SharedSkillsSystem>();
|
|
|
|
CloseButton.OnPressed += _ => Close();
|
|
ApplyPointsButton.OnPressed += OnApplyPoints;
|
|
ResetButton.OnPressed += _ => OnResetAll?.Invoke();
|
|
}
|
|
|
|
public void UpdateState(SkillsAdminEuiState state)
|
|
{
|
|
TargetNameLabel.Text = state.EntityName;
|
|
JobLabel.Text = state.CurrentJob;
|
|
|
|
_currentSkills = new Dictionary<byte, int>(state.CurrentSkills);
|
|
_bonusPoints = state.BonusPoints;
|
|
_spentPoints = state.SpentPoints;
|
|
|
|
UpdatePointsDisplay();
|
|
PopulateSkills();
|
|
}
|
|
|
|
private void UpdatePointsDisplay()
|
|
{
|
|
BonusPointsEdit.Text = _bonusPoints.ToString();
|
|
SpentPointsLabel.Text = _spentPoints.ToString();
|
|
}
|
|
|
|
private void PopulateSkills()
|
|
{
|
|
SkillsContainer.RemoveAllChildren();
|
|
|
|
foreach (var skillType in Enum.GetValues<SkillType>())
|
|
{
|
|
var costs = _skillsSystem.GetSkillCost(skillType);
|
|
var color = _skillsSystem.GetSkillColor(skillType);
|
|
byte skillKey = (byte)skillType;
|
|
|
|
var currentLevel = _currentSkills.GetValueOrDefault(skillKey, 1);
|
|
|
|
var skillSelector = new SkillSelector(skillType, currentLevel, costs, color, 1)
|
|
{
|
|
Margin = new Thickness(0, 5),
|
|
HorizontalExpand = true
|
|
};
|
|
|
|
skillSelector.IsLocked = false;
|
|
skillSelector.UpdateAvailability(int.MaxValue, _skillsSystem);
|
|
|
|
skillSelector.OnSkillLevelChanged += (newLevel) =>
|
|
{
|
|
_currentSkills[skillKey] = newLevel;
|
|
OnSkillChanged?.Invoke(skillKey, newLevel);
|
|
};
|
|
|
|
SkillsContainer.AddChild(skillSelector);
|
|
}
|
|
}
|
|
|
|
private void OnApplyPoints(BaseButton.ButtonEventArgs args)
|
|
{
|
|
if (int.TryParse(BonusPointsEdit.Text, out var newBonus))
|
|
{
|
|
OnPointsChanged?.Invoke(newBonus);
|
|
}
|
|
}
|
|
}
|