130 lines
3.4 KiB
C#
130 lines
3.4 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityGameFramework.Runtime;
|
|
using SepCore.Event;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
public class DialogForm : UGuiForm
|
|
{
|
|
[SerializeField] private TMP_Text _titleText = null;
|
|
[SerializeField] private TMP_Text _messageText = null;
|
|
[SerializeField] private GameObject[] _modeObjects = null;
|
|
[SerializeField] private TMP_Text[] _confirmTexts = null;
|
|
[SerializeField] private TMP_Text[] _cancelTexts = null;
|
|
[SerializeField] private TMP_Text[] _otherTexts = null;
|
|
|
|
private int _dialogMode = 1;
|
|
private bool _pauseGame = false;
|
|
|
|
public void OnConfirmButtonClick()
|
|
{
|
|
GameEntry.Event.FireNow(this, DialogEventArgs.Create(1, null));
|
|
}
|
|
|
|
public void OnCancelButtonClick()
|
|
{
|
|
GameEntry.Event.FireNow(this, DialogEventArgs.Create(2, null));
|
|
}
|
|
|
|
public void OnOtherButtonClick()
|
|
{
|
|
GameEntry.Event.FireNow(this, DialogEventArgs.Create(3, null));
|
|
}
|
|
|
|
protected override void OnOpen(object userData)
|
|
{
|
|
base.OnOpen(userData);
|
|
|
|
if (userData is not DialogContext context)
|
|
{
|
|
Log.Warning("DialogContext is invalid.");
|
|
return;
|
|
}
|
|
|
|
RefreshUI(context);
|
|
}
|
|
|
|
public void RefreshUI(DialogContext context)
|
|
{
|
|
if (context == null)
|
|
{
|
|
Log.Warning("DialogContext is invalid.");
|
|
return;
|
|
}
|
|
|
|
_dialogMode = context.Mode;
|
|
RefreshDialogMode();
|
|
|
|
_titleText.text = context.Title;
|
|
_messageText.text = context.Message;
|
|
|
|
_pauseGame = context.PauseGame;
|
|
RefreshPauseGame();
|
|
|
|
RefreshConfirmText(context.ConfirmText);
|
|
RefreshCancelText(context.CancelText);
|
|
RefreshOtherText(context.OtherText);
|
|
}
|
|
|
|
protected override void OnClose(bool isShutdown, object userData)
|
|
{
|
|
if (_pauseGame)
|
|
{
|
|
GameEntry.Base.ResumeGame();
|
|
}
|
|
|
|
_dialogMode = 1;
|
|
_titleText.text = string.Empty;
|
|
_messageText.text = string.Empty;
|
|
_pauseGame = false;
|
|
|
|
RefreshConfirmText(string.Empty);
|
|
RefreshCancelText(string.Empty);
|
|
RefreshOtherText(string.Empty);
|
|
|
|
base.OnClose(isShutdown, userData);
|
|
}
|
|
|
|
private void RefreshDialogMode()
|
|
{
|
|
for (int i = 1; i <= _modeObjects.Length; i++)
|
|
{
|
|
_modeObjects[i - 1].SetActive(i == _dialogMode);
|
|
}
|
|
}
|
|
|
|
private void RefreshPauseGame()
|
|
{
|
|
if (_pauseGame)
|
|
{
|
|
GameEntry.Base.PauseGame();
|
|
}
|
|
}
|
|
|
|
private void RefreshConfirmText(string confirmText)
|
|
{
|
|
foreach (var text in _confirmTexts)
|
|
{
|
|
text.text = confirmText;
|
|
}
|
|
}
|
|
|
|
private void RefreshCancelText(string cancelText)
|
|
{
|
|
foreach (var text in _cancelTexts)
|
|
{
|
|
text.text = cancelText;
|
|
}
|
|
}
|
|
|
|
private void RefreshOtherText(string otherText)
|
|
{
|
|
foreach (var text in _otherTexts)
|
|
{
|
|
text.text = otherText;
|
|
}
|
|
}
|
|
}
|
|
}
|