set player name to profile name

name is read-only while connected
This commit is contained in:
AmazingAlek 2020-03-06 19:01:16 +01:00 committed by GitHub
parent d33e7d46c7
commit 9840e0698f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
using System;
using System.Linq;
using OWML.ModHelper.Events;
using QSB.Animation;
using QSB.Events;
using QSB.TimeSync;
@ -40,6 +41,7 @@ namespace QSB
"Tuff"
};
private string _playerName;
private bool _canEditName;
private void Awake()
{
@ -56,7 +58,21 @@ namespace QSB
ConfigureNetworkManager();
_playerName = _defaultNames.OrderBy(x => Guid.NewGuid()).First();
_playerName = GetPlayerName();
_canEditName = true;
}
private string GetPlayerName()
{
var profileManager = StandaloneProfileManager.SharedInstance;
profileManager.Initialize();
var profile = profileManager.GetValue<StandaloneProfileManager.ProfileData>("_currentProfile");
var profileName = profile?.profileName;
if (!string.IsNullOrEmpty(profileName))
{
return profileName;
}
return _defaultNames.OrderBy(x => Guid.NewGuid()).First();
}
private void ConfigureNetworkManager()
@ -86,12 +102,27 @@ namespace QSB
DebugLog.Screen("OnClientConnect");
gameObject.AddComponent<SectorSync>();
gameObject.AddComponent<PlayerJoin>().Join(_playerName);
_canEditName = false;
}
public override void OnStopClient()
{
DebugLog.Screen("OnStopClient");
_canEditName = true;
}
private void OnGUI()
{
GUI.Label(new Rect(10, 10, 200f, 20f), "Name:");
_playerName = GUI.TextField(new Rect(60, 10, 145, 20f), _playerName);
if (_canEditName)
{
_playerName = GUI.TextField(new Rect(60, 10, 145, 20f), _playerName);
}
else
{
GUI.Label(new Rect(60, 10, 145, 20f), _playerName);
}
}
}