Modal 개발 완료. Toolbar 개발 중
This commit is contained in:
@@ -1,74 +1,138 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UVC.Locale; // ConfirmButtonText의 기본값을 위해 추가
|
||||
using UVC.Log; // ULog 사용 예시를 위해 추가 (필요에 따라)
|
||||
|
||||
namespace UVC.UI.Modal
|
||||
{
|
||||
/// <summary>
|
||||
/// 간단한 알림 메시지를 표시하는 정적 클래스입니다.
|
||||
/// 확인 버튼만 있으며, 사용자의 확인을 기다립니다.
|
||||
/// 📢 간단한 알림 메시지를 화면에 보여주는 친구예요.
|
||||
/// 이 친구는 "확인" 버튼만 가지고 있어서, 사용자가 내용을 읽고 확인 버튼을 누를 때까지 기다려줘요.
|
||||
/// 복잡한 선택 없이, 간단한 정보 전달이나 경고를 보여줄 때 사용하면 좋아요.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // 가장 기본적인 알림창 사용법
|
||||
/// async UniTask ShowMyFirstAlert()
|
||||
/// {
|
||||
/// await Alert.Show("알림", "게임 데이터가 성공적으로 저장되었습니다!");
|
||||
/// ULog.Debug("사용자가 알림을 확인했습니다.");
|
||||
/// }
|
||||
///
|
||||
/// // 버튼 글자도 바꿔볼까요?
|
||||
/// async UniTask ShowCustomButtonAlert()
|
||||
/// {
|
||||
/// await Alert.Show("레벨 업!", "축하합니다! 레벨 5를 달성했어요!", confirmButtonText: "야호!");
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public static class Alert
|
||||
{
|
||||
/// <summary>
|
||||
/// Alert 모달 프리팹의 기본 경로입니다.
|
||||
/// 🎨 알림창의 기본 디자인(프리팹) 파일이 어디 있는지 알려주는 경로예요.
|
||||
/// 특별히 다른 디자인을 쓰고 싶지 않으면 이 기본 디자인을 사용해요.
|
||||
/// </summary>
|
||||
private const string DefaultAlertPrefabPath = "Prefabs/UI/Modal/Alert";
|
||||
private const string DefaultPrefabPath = "Prefabs/UI/Modal/Alert";
|
||||
|
||||
/// <summary>
|
||||
/// 지정된 제목과 메시지로 알림창을 표시합니다.
|
||||
/// 사용자가 확인 버튼을 누를 때까지 기다립니다.
|
||||
/// ✨ 지정된 제목과 메시지로 알림창을 화면에 뿅! 하고 보여줘요.
|
||||
/// 사용자가 "확인" 버튼을 누를 때까지 코드는 여기서 잠시 멈춰 기다려요.
|
||||
/// </summary>
|
||||
/// <param name="title">알림창의 제목입니다.</param>
|
||||
/// <param name="message">알림창에 표시될 메시지입니다.</param>
|
||||
/// <param name="confirmButtonText">확인 버튼에 표시될 텍스트입니다. null일 경우 LocalizationManager에서 "modal_confirm_button" 키로 조회합니다.</param>
|
||||
/// <param name="customPrefabPath">사용자 정의 알림 프리팹 경로입니다. null일 경우 기본 경로를 사용합니다.</param>
|
||||
/// <returns>모달이 닫힐 때 완료되는 UniTask입니다.</returns>
|
||||
/// <param name="title">알림창 맨 위에 크게 보일 '제목'이에요.</param>
|
||||
/// <param name="message">알림창에 보여줄 '메시지 내용'이에요.</param>
|
||||
/// <param name="confirmButtonText">"확인" 버튼에 보여줄 글자예요. 아무것도 안 적으면 기본 글자("확인" 또는 설정된 언어)가 나와요.</param>
|
||||
/// <param name="customPrefabPath">만약 특별히 만들어둔 알림창 디자인이 있다면, 그 파일 경로를 여기에 적어주세요. 없으면 기본 디자인을 사용해요.</param>
|
||||
/// <returns>사용자가 확인 버튼을 누르면 완료되는 작업(UniTask)이에요. 특별한 값을 돌려주진 않아요.</returns>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// public class GameManager : MonoBehaviour
|
||||
/// {
|
||||
/// public async void OnPlayerSaveGame()
|
||||
/// {
|
||||
/// // (게임 저장 로직...)
|
||||
/// bool success = true; // 저장 성공했다고 가정
|
||||
///
|
||||
/// if (success)
|
||||
/// {
|
||||
/// await Alert.Show("저장 완료", "게임 진행 상황이 안전하게 저장되었습니다.", "알겠습니다");
|
||||
/// ULog.Debug("저장 완료 알림을 플레이어가 확인했습니다.");
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// await Alert.Show("저장 실패", "오류가 발생하여 저장하지 못했습니다.", "다시 시도");
|
||||
/// // (다시 시도 로직 또는 다른 처리...)
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public static async UniTask Show(
|
||||
string title,
|
||||
string message,
|
||||
string confirmButtonText = null,
|
||||
string customPrefabPath = null)
|
||||
{
|
||||
string prefabPath = string.IsNullOrEmpty(customPrefabPath) ? DefaultAlertPrefabPath : customPrefabPath;
|
||||
string prefabPath = string.IsNullOrEmpty(customPrefabPath) ? DefaultPrefabPath : customPrefabPath;
|
||||
|
||||
// ModalContent 설정
|
||||
// ModalContent 레시피를 만들어요. 알림창은 취소 버튼이 필요 없으니 숨겨요.
|
||||
ModalContent content = new ModalContent(prefabPath)
|
||||
{
|
||||
Title = title,
|
||||
Message = message,
|
||||
ShowCancelButton = false, // Alert에서는 취소 버튼 숨김
|
||||
// ConfirmButtonText는 null이면 ModalContent의 getter가 LocalizationManager를 사용함
|
||||
};
|
||||
|
||||
// 확인 버튼 글자를 따로 정해줬다면 그걸로 설정해요.
|
||||
if (!string.IsNullOrEmpty(confirmButtonText))
|
||||
{
|
||||
content.ConfirmButtonText = confirmButtonText;
|
||||
}
|
||||
// else인 경우, ModalContent의 ConfirmButtonText getter가
|
||||
// LocalizationManager.Instance.GetString("modal_confirm_button")을 사용합니다.
|
||||
// 만약 이 키가 아닌 다른 키를 기본값으로 사용하고 싶다면 여기서 설정할 수 있습니다.
|
||||
// 예: content.ConfirmButtonText = LocalizationManager.Instance.GetString("alert_ok_button");
|
||||
// 아니면 ModalContent의 기본 설정(다국어 지원 "button_confirm" 키)을 따라요.
|
||||
// 만약 다른 기본 키를 쓰고 싶다면 여기서 설정할 수도 있어요.
|
||||
// 예: content.ConfirmButtonText = LocalizationManager.Instance.GetString("alert_default_ok_button");
|
||||
|
||||
// Modal.Open<T> 호출. Alert은 별도의 결과를 반환하지 않으므로 T는 bool 또는 object 같은 기본 타입을 사용할 수 있습니다.
|
||||
// 여기서는 bool을 사용하고, 확인 버튼은 true를 반환하도록 Modal 시스템이 되어있다고 가정합니다.
|
||||
// 실제 반환값은 사용하지 않으므로, UniTask<bool>을 받고 무시합니다.
|
||||
// Modal 시스템에게 "이 레시피대로 모달 창 열어줘!" 라고 부탁해요.
|
||||
// Alert은 사용자의 선택 결과(true/false)가 중요하지 않으므로, bool 타입으로 받고 결과는 무시해요.
|
||||
await Modal.Open<bool>(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 다국어 키를 사용하여 제목과 메시지를 표시하는 알림창을 엽니다.
|
||||
/// 🌍 다국어(여러 나라 언어)를 지원하는 알림창을 보여줘요.
|
||||
/// 미리 준비된 '언어 키'를 알려주면, 게임 설정 언어에 맞는 글자를 자동으로 찾아서 보여줘요.
|
||||
/// </summary>
|
||||
/// <param name="titleLocalizationKey">제목으로 사용할 다국어 키입니다.</param>
|
||||
/// <param name="messageLocalizationKey">메시지로 사용할 다국어 키입니다.</param>
|
||||
/// <param name="confirmButtonLocalizationKey">확인 버튼 텍스트로 사용할 다국어 키입니다. null일 경우 "modal_confirm_button"을 사용합니다.</param>
|
||||
/// <param name="customPrefabPath">사용자 정의 알림 프리팹 경로입니다. null일 경우 기본 경로를 사용합니다.</param>
|
||||
/// <returns>모달이 닫힐 때 완료되는 UniTask입니다.</returns>
|
||||
/// <param name="titleLocalizationKey">제목에 사용할 '언어 키'예요. (예: "alert_title_welcome")</param>
|
||||
/// <param name="messageLocalizationKey">메시지 내용에 사용할 '언어 키'예요. (예: "alert_message_item_acquired")</param>
|
||||
/// <param name="confirmButtonLocalizationKey">확인 버튼 글자에 사용할 '언어 키'예요. 안 적으면 기본 키("button_confirm")를 사용해요.</param>
|
||||
/// <param name="customPrefabPath">특별한 알림창 디자인 파일 경로예요. 없으면 기본 디자인을 사용해요.</param>
|
||||
/// <returns>사용자가 확인 버튼을 누르면 완료되는 작업(UniTask)이에요.</returns>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// public class QuestManager : MonoBehaviour
|
||||
/// {
|
||||
/// public async void OnQuestCompleted(string questNameKey)
|
||||
/// {
|
||||
/// // 예시: 퀘스트 완료 메시지를 현재 설정된 언어로 보여줍니다.
|
||||
/// // titleLocalizationKey: "quest_completed_title" -> "퀘스트 완료" (한국어), "Quest Complete" (영어)
|
||||
/// // messageLocalizationKey: "quest_completed_message" -> "{0} 퀘스트를 완료했습니다!" (한국어), "You have completed the {0} quest!" (영어)
|
||||
/// // 여기서 {0} 부분은 실제 퀘스트 이름으로 바뀔 수 있도록 LocalizationManager에서 처리한다고 가정합니다.
|
||||
///
|
||||
/// string localizedQuestName = LocalizationManager.Instance.GetString(questNameKey); // 예: "main_quest_01" -> "첫 번째 임무"
|
||||
/// string formattedMessageKey = "quest_completed_message"; // 실제로는 메시지 포맷팅이 필요할 수 있음
|
||||
///
|
||||
/// // 실제 메시지는 LocalizationManager에서 포맷팅을 지원해야 함
|
||||
/// // 여기서는 간단히 키만 전달하는 것으로 가정
|
||||
/// await Alert.ShowLocalized("quest_completed_title", formattedMessageKey, confirmButtonLocalizationKey: "ui_button_great");
|
||||
/// ULog.Debug("퀘스트 완료 알림을 플레이어가 확인했습니다.");
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public static async UniTask ShowLocalized(
|
||||
string titleLocalizationKey,
|
||||
string messageLocalizationKey,
|
||||
string confirmButtonLocalizationKey = null,
|
||||
string customPrefabPath = null)
|
||||
{
|
||||
// 언어 키를 사용해서 실제 보여줄 글자들을 가져와요.
|
||||
string title = LocalizationManager.Instance.GetString(titleLocalizationKey);
|
||||
string message = LocalizationManager.Instance.GetString(messageLocalizationKey);
|
||||
string confirmText = null;
|
||||
@@ -77,8 +141,9 @@ namespace UVC.UI.Modal
|
||||
{
|
||||
confirmText = LocalizationManager.Instance.GetString(confirmButtonLocalizationKey);
|
||||
}
|
||||
// confirmText가 null이면 Show 메서드 내부에서 ModalContent의 기본 로직(modal_confirm_button 키 사용)이 적용됩니다.
|
||||
// confirmText가 null (따로 안 정해줬으면)이면, Show() 메서드 안에서 ModalContent의 기본 글자 로직이 알아서 처리해줘요.
|
||||
|
||||
// 준비된 글자들로 알림창을 보여달라고 Show()에게 다시 부탁해요.
|
||||
await Show(title, message, confirmText, customPrefabPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user