Accounting/Assets/Scripts/Logger.cs

61 lines
1.2 KiB
C#

using DragonSoul.UI;
namespace DragonSoul;
public class Logger
{
private UI_MainUI _uiMainUI;
private List<string> _logItmes;
private bool _logDirty;
public Logger()
{
_logItmes = new List<string>();
_logDirty = true;
__Log.SetOutput(this.Print);
}
public void Info(string str)
{
__Log.Info(str);
}
public void Error(string str)
{
__Log.Error(str);
}
private void Print(string msg)
{
_logItmes.Add(msg);
while (this._logItmes.Count > 100)
_logItmes.RemoveAt(0);
_logDirty = true;
}
public void Update()
{
if (_logDirty)
{
_logDirty = false;
this.RefreshLog();
}
}
private void RefreshLog()
{
this._uiMainUI.m_listLog.RemoveChildrenToPool();
foreach (var logItme in this._logItmes)
{
var asButton = this._uiMainUI.m_listLog.AddItemFromPool().asButton;
asButton.title = logItme;
}
this._uiMainUI.m_listLog.ScrollToView(this._uiMainUI.m_listLog.numItems - 1);
}
public void SetUI(UI_MainUI uiMainUI)
{
this._uiMainUI = uiMainUI;
}
}