* Loadouts redux * Loadout window mockup * More workout * rent * validation * Developments * bcs * More cleanup * Rebuild working * Fix model and loading * obsession * efcore * We got a stew goin * Cleanup * Optional + SeniorEngineering fix * Fixes * Update science.yml * add add * Automatic naming * Update nukeops * Coming together * Right now * stargate * rejig the UI * weh * Loadouts tweaks * Merge conflicts + ordering fix * yerba mate * chocolat * More updates * Add multi-selection support * test h * fikss * a * add tech assistant and hazard suit * huh * Latest changes * add medical loadouts * and science * finish security loadouts * cargo * service done * added wildcards * add command * Move restrictions * Finalising * Fix existing work * Localise next batch * clothing fix * Fix storage names * review * the scooping room * Test fixes * Xamlify * Xamlify this too * Update Resources/Prototypes/Loadouts/Jobs/Medical/paramedic.yml Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com> * Update Resources/Prototypes/Loadouts/loadout_groups.yml Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com> * Update Resources/Prototypes/Loadouts/Jobs/Civilian/clown.yml Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com> * Update Resources/Prototypes/Loadouts/Jobs/Civilian/clown.yml Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com> * Update Resources/Prototypes/Loadouts/loadout_groups.yml Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com> * Update Resources/Prototypes/Loadouts/Jobs/Security/detective.yml Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com> * Update Resources/Prototypes/Loadouts/loadout_groups.yml Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com> * ben * Margins --------- Co-authored-by: Firewatch <54725557+musicmanvr@users.noreply.github.com> Co-authored-by: Mr. 27 <koolthunder019@gmail.com> Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>
120 lines
4.3 KiB
C#
120 lines
4.3 KiB
C#
using System.Linq;
|
|
using Content.Shared.Preferences;
|
|
using Robust.Client;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.Preferences
|
|
{
|
|
/// <summary>
|
|
/// Receives <see cref="PlayerPreferences" /> and <see cref="GameSettings" /> from the server during the initial
|
|
/// connection.
|
|
/// Stores preferences on the server through <see cref="SelectCharacter" /> and <see cref="UpdateCharacter" />.
|
|
/// </summary>
|
|
public sealed class ClientPreferencesManager : IClientPreferencesManager
|
|
{
|
|
[Dependency] private readonly IClientNetManager _netManager = default!;
|
|
[Dependency] private readonly IBaseClient _baseClient = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
public event Action? OnServerDataLoaded;
|
|
|
|
public GameSettings Settings { get; private set; } = default!;
|
|
public PlayerPreferences Preferences { get; private set; } = default!;
|
|
|
|
public void Initialize()
|
|
{
|
|
_netManager.RegisterNetMessage<MsgPreferencesAndSettings>(HandlePreferencesAndSettings);
|
|
_netManager.RegisterNetMessage<MsgUpdateCharacter>();
|
|
_netManager.RegisterNetMessage<MsgSelectCharacter>();
|
|
_netManager.RegisterNetMessage<MsgDeleteCharacter>();
|
|
|
|
_baseClient.RunLevelChanged += BaseClientOnRunLevelChanged;
|
|
}
|
|
|
|
private void BaseClientOnRunLevelChanged(object? sender, RunLevelChangedEventArgs e)
|
|
{
|
|
if (e.NewLevel == ClientRunLevel.Initialize)
|
|
{
|
|
Settings = default!;
|
|
Preferences = default!;
|
|
}
|
|
}
|
|
|
|
public void SelectCharacter(ICharacterProfile profile)
|
|
{
|
|
SelectCharacter(Preferences.IndexOfCharacter(profile));
|
|
}
|
|
|
|
public void SelectCharacter(int slot)
|
|
{
|
|
Preferences = new PlayerPreferences(Preferences.Characters, slot, Preferences.AdminOOCColor);
|
|
var msg = new MsgSelectCharacter
|
|
{
|
|
SelectedCharacterIndex = slot
|
|
};
|
|
_netManager.ClientSendMessage(msg);
|
|
}
|
|
|
|
public void UpdateCharacter(ICharacterProfile profile, int slot)
|
|
{
|
|
var collection = IoCManager.Instance!;
|
|
profile.EnsureValid(_playerManager.LocalSession!, collection);
|
|
var characters = new Dictionary<int, ICharacterProfile>(Preferences.Characters) {[slot] = profile};
|
|
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
|
|
var msg = new MsgUpdateCharacter
|
|
{
|
|
Profile = profile,
|
|
Slot = slot
|
|
};
|
|
_netManager.ClientSendMessage(msg);
|
|
}
|
|
|
|
public void CreateCharacter(ICharacterProfile profile)
|
|
{
|
|
var characters = new Dictionary<int, ICharacterProfile>(Preferences.Characters);
|
|
var lowest = Enumerable.Range(0, Settings.MaxCharacterSlots)
|
|
.Except(characters.Keys)
|
|
.FirstOrNull();
|
|
|
|
if (lowest == null)
|
|
{
|
|
throw new InvalidOperationException("Out of character slots!");
|
|
}
|
|
|
|
var l = lowest.Value;
|
|
characters.Add(l, profile);
|
|
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
|
|
|
|
UpdateCharacter(profile, l);
|
|
}
|
|
|
|
public void DeleteCharacter(ICharacterProfile profile)
|
|
{
|
|
DeleteCharacter(Preferences.IndexOfCharacter(profile));
|
|
}
|
|
|
|
public void DeleteCharacter(int slot)
|
|
{
|
|
var characters = Preferences.Characters.Where(p => p.Key != slot);
|
|
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
|
|
var msg = new MsgDeleteCharacter
|
|
{
|
|
Slot = slot
|
|
};
|
|
_netManager.ClientSendMessage(msg);
|
|
}
|
|
|
|
private void HandlePreferencesAndSettings(MsgPreferencesAndSettings message)
|
|
{
|
|
Preferences = message.Preferences;
|
|
Settings = message.Settings;
|
|
|
|
OnServerDataLoaded?.Invoke();
|
|
}
|
|
}
|
|
}
|