2025-10-15 20:28:33 +04:00

82 lines
2.1 KiB
C#

using UnityEngine;
namespace TPSBR.UI
{
public class MenuUI : SceneUI
{
// SceneUI INTERFACE
protected override void OnInitializeInternal()
{
base.OnInitializeInternal();
Context.Input.RequestCursorVisibility(true, ECursorStateSource.Menu);
OnWalletConnected(PlayerPrefs.GetString("WALLET_ADDRESS"));
//if (Context.PlayerData.Nickname.HasValue() == false)
//{
// var changeNicknameView = Open<UIChangeNicknameView>();
// changeNicknameView.SetData("ENTER NICKNAME", true);
//}
}
protected override void OnDeinitializeInternal()
{
Context.Input.RequestCursorVisibility(false, ECursorStateSource.Menu);
base.OnDeinitializeInternal();
}
protected override void OnActivate()
{
base.OnActivate();
if (Global.Networking.ErrorStatus.HasValue() == true)
{
Open<UIMultiplayerView>();
var errorDialog = Open<UIErrorDialogView>();
errorDialog.Title.text = "Connection Issue";
if (Global.Networking.ErrorStatus == Networking.STATUS_SERVER_CLOSED)
{
errorDialog.Description.text = $"Server was closed.";
}
else
{
errorDialog.Description.text = $"Failed to start network game\n\nReason:\n{Global.Networking.ErrorStatus}";
}
Global.Networking.ClearErrorStatus();
}
}
public async void OnWalletConnected(string wallet) // call this from your wallet SDK
{
try
{
// makes sure the row exists (display_name = "" on first create)
string playername= await GameDb.GetPlayerNameAsync(wallet);
if (playername == "")
{
var changeNicknameView = Open<UIChangeNicknameView>();
changeNicknameView.SetData("ENTER NICKNAME", true);
}
else
{
Context.PlayerData.Nickname = playername.ToString();
Debug.Log($"Player ensured for {wallet}");
}
}
catch (System.Exception e)
{
Debug.LogError(e);
}
}
}
}