Files
Net.Like.Xue.Tokyo/Packages-Local/Com.Project.B.Unity/UX/UXInitialize.cs
2025-06-24 23:49:13 +08:00

75 lines
2.2 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Mod;
using BITKit.UX;
using Cysharp.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Net.Project.B.UX;
using Project.B.Map;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;
using IUXDialogue = BITKit.UX.IUXDialogue;
namespace Project.B.UX
{
public class UXInitialize : UIToolKitPanel,ILogger<UXInitialize>, IUXInitialize
{
protected override string DocumentPath => "ui_initialize";
private readonly IGameMapService _gameMapService;
private readonly IUXDialogue _dialogue;
private readonly DoubleBuffer<string> _lastMessage = new();
[UXBindPath("state-label")] private Label _stateLabel;
public UXInitialize(IUXService uxService, IGameMapService gameMapService) : base(uxService)
{
_gameMapService = gameMapService;
OnInitiated +=Initiated;
}
private void Initiated()
{
if (_lastMessage.TryGetRelease(out var message))
{
_stateLabel.text = message;
}
}
[HideInCallstack]
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
switch (logLevel)
{
case LogLevel.Error:
Debug.LogError(state.ToString());
break;
case LogLevel.Warning:
Debug.LogWarning(state.ToString());
break;
case LogLevel.Critical:
Debug.LogException(exception);
break;
default:
Debug.Log(state.ToString());
break;
}
if (_stateLabel is null)
{
_lastMessage.Release(state.ToString());
}
else
{
_stateLabel.text = state.ToString();
}
}
public bool IsEnabled(LogLevel logLevel) => IsEntered;
public IDisposable BeginScope<TState>(TState state) where TState : notnull => null;
}
}