159 lines
4.5 KiB
C#
159 lines
4.5 KiB
C#
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Cysharp.Threading.Tasks;
|
|
using UVC.Command;
|
|
using UVC.UI.Modal;
|
|
using EnglewoodLAB.Modal.View;
|
|
using EnglewoodLAB.UI.Controller;
|
|
using TMPro;
|
|
|
|
namespace EnglewoodLAB.Modal
|
|
{
|
|
public class ContentModalView : ModalView
|
|
{
|
|
private ScrollRect rectScroll;
|
|
private RectTransform contentRect;
|
|
|
|
private GameObject contentSelectprefab;
|
|
private ContentButtonController controller;
|
|
|
|
public override async UniTask OnOpen(ModalContent content)
|
|
{
|
|
if (contentSelectprefab == null)
|
|
{
|
|
contentSelectprefab = Resources.Load<GameObject>("UI/Prefab/Button/ContentSelectButton");
|
|
}
|
|
SetUI();
|
|
await base.OnOpen(content);
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
gameObject.SetActive(true);
|
|
//항상 첫 페이지가 보여야함
|
|
}
|
|
|
|
private void SetUI()
|
|
{
|
|
var textmeshpros = GetComponentsInChildren<TextMeshProUGUI>();
|
|
var rectItems = GetComponentsInChildren<RectTransform>();
|
|
var btns = GetComponentsInChildren<Button>();
|
|
|
|
if (titleText == null)
|
|
{
|
|
titleText = textmeshpros.FirstOrDefault(x => x.name.Equals("Text_Title"));
|
|
}
|
|
|
|
if (confirmButton == null)
|
|
{
|
|
confirmButton = btns.FirstOrDefault(x => x.name.Equals("Button_Save"));
|
|
if (confirmButton != null)
|
|
confirmButtonText = confirmButton.GetComponentInChildren<TextMeshProUGUI>();
|
|
}
|
|
|
|
if (cancelButton == null)
|
|
{
|
|
cancelButton = btns.FirstOrDefault(x => x.name.Equals("Button_Cancel"));
|
|
if (cancelButton != null)
|
|
cancelButtonText = cancelButton.GetComponentInChildren<TextMeshProUGUI>();
|
|
}
|
|
|
|
if (closeButton == null)
|
|
{
|
|
closeButton = btns.FirstOrDefault(x => x.name.Equals("Button_Close"));
|
|
}
|
|
|
|
if (rectScroll == null)
|
|
{
|
|
rectScroll = GetComponentInChildren<ScrollRect>();
|
|
}
|
|
|
|
if (contentRect == null)
|
|
{
|
|
contentRect = rectItems.FirstOrDefault(x => x.name.Equals("ContentView"));
|
|
}
|
|
|
|
confirmButton.onClick.AddListener(OnConfirmButtonClicked);
|
|
closeButton.onClick.AddListener(OnCloseButtonClicked);
|
|
cancelButton.onClick.AddListener(OnCancelButtonClicked);
|
|
|
|
controller = new();
|
|
}
|
|
|
|
public void AddContent(List<ModalContent> contents)
|
|
{
|
|
foreach (var content in contents)
|
|
{
|
|
//둘중 하나라도 없으면 생성안함.
|
|
if (string.IsNullOrEmpty(content.Title))
|
|
continue;
|
|
if (string.IsNullOrEmpty(content.PrefabPath))
|
|
continue;
|
|
//커텐츠 생성
|
|
var asset = Resources.Load<SettingModalView>(content.PrefabPath);
|
|
var item = Instantiate<SettingModalView>(asset, contentRect);
|
|
item.OnOpen(content).Forget();
|
|
//컨텐츠 버튼 생성
|
|
AddScrollItem(content, item.gameObject);
|
|
}
|
|
}
|
|
|
|
//버튼 컨트롤러도 만들어야 함...
|
|
|
|
|
|
private void AddScrollItem(ModalContent content, GameObject contentItem)
|
|
{
|
|
var item = Instantiate(contentSelectprefab, rectScroll.content);
|
|
|
|
if (item == null)
|
|
return;
|
|
|
|
var csb = new ContentSelectButton
|
|
{
|
|
Title = content.Title,
|
|
IconSpritePath = "Prefabs/UI/images/ic_select_btn",
|
|
ClickCommand = new ContentOpenCommand(contentItem)
|
|
};
|
|
|
|
var btn = item.GetComponent<Button>();
|
|
|
|
btn.onClick.AddListener(
|
|
() => controller.OnClickBtn(csb)
|
|
);
|
|
|
|
controller.AddItem(csb, btn);
|
|
}
|
|
|
|
|
|
public override async UniTask OnClose(ModalContent content)
|
|
{
|
|
await base.OnClose(content);
|
|
}
|
|
|
|
public override void OnConfirmButtonClicked()
|
|
{
|
|
//저장
|
|
Hide();
|
|
}
|
|
|
|
public override void OnCancelButtonClicked()
|
|
{
|
|
Hide();
|
|
}
|
|
|
|
public override void OnCloseButtonClicked()
|
|
{
|
|
Hide();
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
gameObject.SetActive(false);
|
|
controller.Reset();
|
|
}
|
|
}
|
|
|
|
}
|