128 lines
4.2 KiB
C#
128 lines
4.2 KiB
C#
#nullable enable
|
|
using Cysharp.Threading.Tasks;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UVC.Core;
|
|
using UVC.Studio.Config;
|
|
using UVC.UI.Tab;
|
|
|
|
namespace UVC.Studio.Modal.Settings
|
|
{
|
|
public class SettingDatabaseTabContent : MonoBehaviour, ITabContent
|
|
{
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? ipTxt;
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? portTxt;
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? idTxt;
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? pwTxt;
|
|
|
|
[Inject]
|
|
private Setting? setting;
|
|
|
|
private bool changedValue = false;
|
|
|
|
/// <summary>
|
|
/// 탭 콘텐츠에 데이터를 전달합니다.
|
|
/// </summary>
|
|
/// <param name="data">전달할 데이터 객체</param>
|
|
public async void SetContentData(object? data)
|
|
{
|
|
Debug.Log($"SettingDatabaseTabContent SetContentData: {data} {setting == null}");
|
|
|
|
if (setting == null)
|
|
{
|
|
await InjectorAppContext.Instance.WaitForInitializationAsync();
|
|
setting = InjectorAppContext.Instance.Get<Setting>();
|
|
}
|
|
|
|
Debug.Log($"SettingDatabaseTabContent SetContentData: {data} {setting == null}");
|
|
|
|
if (setting != null)
|
|
{
|
|
changedValue = false;
|
|
|
|
DatabaseSetting database = setting.Data.database;
|
|
if (ipTxt != null)
|
|
{
|
|
ipTxt.text = database.ip;
|
|
ipTxt.onEndEdit.AddListener((value) =>
|
|
{
|
|
setting.Data.database.ip = value;
|
|
changedValue = true;
|
|
});
|
|
}
|
|
if (portTxt != null)
|
|
{
|
|
portTxt.text = database.port.ToString();
|
|
portTxt.onEndEdit.AddListener((value) =>
|
|
{
|
|
if (int.TryParse(value, out int intValue))
|
|
{
|
|
setting.Data.database.port = intValue;
|
|
changedValue = true;
|
|
}
|
|
});
|
|
}
|
|
if (idTxt != null)
|
|
{
|
|
idTxt.text = database.id;
|
|
idTxt.onEndEdit.AddListener((value) =>
|
|
{
|
|
setting.Data.database.id = value;
|
|
changedValue = true;
|
|
});
|
|
}
|
|
if (pwTxt != null)
|
|
{
|
|
pwTxt.text = database.password;
|
|
pwTxt.onEndEdit.AddListener((value) =>
|
|
{
|
|
setting.Data.database.password = value;
|
|
changedValue = true;
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 탭 전환 시 데이터가 있는 경우 전달 되는 데이터. SetContentData 이후 호출 됨
|
|
/// </summary>
|
|
/// <param name="data">전달할 데이터 객체</param>
|
|
public void UpdateContentData(object? data)
|
|
{
|
|
if (data != null && data is string content)
|
|
{
|
|
Debug.Log($"UpdateContentData: {content}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 닫힐 때 실행되는 로직을 처리합니다.
|
|
/// </summary>
|
|
/// <returns>비동기 닫기 작업을 나타내는 <see cref="UniTask"/>입니다.</returns>
|
|
public async UniTask OnCloseAsync()
|
|
{
|
|
if (ipTxt != null) ipTxt.onEndEdit.RemoveAllListeners();
|
|
if (portTxt != null) portTxt.onEndEdit.RemoveAllListeners();
|
|
if (idTxt != null) idTxt.onEndEdit.RemoveAllListeners();
|
|
if (pwTxt != null) pwTxt.onEndEdit.RemoveAllListeners();
|
|
|
|
Debug.Log($"SettingDatabaseTabContent OnCloseAsync: changedValue={changedValue} setting == null:{setting == null}");
|
|
if (changedValue && setting != null)
|
|
{
|
|
await setting.SaveAsync();
|
|
Debug.Log("Database settings saved.");
|
|
}
|
|
}
|
|
}
|
|
} |