Files
SAMKWANG/Assets/Scripts/Branch/UI/Panel_WorkProgress.cs
2025-10-21 18:47:48 +09:00

117 lines
3.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Samkwang
{
public class Panel_WorkProgress : UIPopupBase
{
public Dictionary<string, UI_WorkStatusItem> workStatuses = new Dictionary<string, UI_WorkStatusItem>();
private UI_WorkStatusItem prf_workStatusItem;
public ScrollRect ScrollView_StatusItems;
public RectTransform Image_Loading;
public Button Button_Close;
public TextMeshProUGUI CurrentDate;
public TextMeshProUGUI CurrentTime;
public float fadeTime;
public Action<string> onClose;
public void Init()
{
var textDict = transform.GetChildComponentsByName<TextMeshProUGUI>(transform);
var buttonDict = transform.GetChildComponentsByName<Button>(transform);
var rectDict = transform.GetChildComponentsByName<RectTransform>(transform);
CurrentDate = textDict.GetOrNull(nameof(CurrentDate));
CurrentTime = textDict.GetOrNull(nameof(CurrentTime));
ScrollView_StatusItems = transform.GetComponentInChildren<ScrollRect>();
Image_Loading = rectDict.GetOrNull(nameof(Image_Loading));
Button_Close = buttonDict.GetOrNull(nameof(Button_Close));
prf_workStatusItem = Resources.Load<UI_WorkStatusItem>("Prefabs/UI/UI_WorkStatusItem");
Button_Close.onClick.AddListener(OnClickCloseButton);
SetDate();
Image_Loading.gameObject.SetActive(true);
Close();
}
public void Update()
{
SetTime();
}
public override void Open()
{
gameObject.SetActive(true);
gameObject.transform.SetAsLastSibling();
StopAllCoroutines();
StartCoroutine(ScaleUp());
}
public override void Close()
{
onClose?.Invoke("WorkProgress");
gameObject.SetActive(false);
gameObject.transform.localScale = Vector3.zero;
}
private void OnClickCloseButton()
{
Close();
}
public void SetWorkProgressStatus(List<WorkShopInfo> workShopInfos)
{
Image_Loading.gameObject.SetActive(false);
bool odd = true;
foreach (var workShopInfo in workShopInfos)
{
if (!workStatuses.ContainsKey(workShopInfo.groupcd))
{
var workStatusItem = Instantiate(prf_workStatusItem, ScrollView_StatusItems.content);
workStatusItem.Init();
workStatuses.Add(workShopInfo.groupcd, workStatusItem);
}
if (odd)
{
workStatuses[workShopInfo.groupcd].SetStatusData(workShopInfo, new Color(0f, 0f, 0f, 0f));
}
else
{
workStatuses[workShopInfo.groupcd].SetStatusData(workShopInfo, new Color(0f, 0f, 0f, 0.7f));
}
odd = !odd;
}
}
public void SetDate()
{
CurrentDate.text = DateTime.Now.ToString("yyyy-MM-dd");
}
public void SetTime()
{
CurrentTime.text = DateTime.Now.ToString("HH:mm");
}
IEnumerator ScaleUp()
{
float timer = 0f;
float percent = 0f;
while (percent < 1)
{
timer += Time.deltaTime;
percent = timer / fadeTime;
transform.localScale = Vector3.Lerp(transform.localScale, Vector3.one, percent);
yield return null;
}
}
}
}