195 lines
6.8 KiB
C#
195 lines
6.8 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using EnglewoodLAB.Management;
|
|
using EnglewoodLAB.Constants;
|
|
|
|
namespace EnglewoodLAB.UI
|
|
{
|
|
public class TotalProgressPanel : UIPanel
|
|
{
|
|
public TextMeshProUGUI CurrentDate;
|
|
public TextMeshProUGUI CurrentTime;
|
|
public Button Button_Close;
|
|
|
|
private RectTransform StatusContent;
|
|
private RectTransform EffectivenessContent;
|
|
|
|
public Panel_Effect effect;
|
|
|
|
private WorkProgressContent WorkProgressContent;
|
|
private WorkShopInfo assemblyWorkShopInfo;
|
|
private WorkShopInfo injectionWorkShopInfo;
|
|
|
|
private Dictionary<int, MachineStatusContent> statusContents = new Dictionary<int, MachineStatusContent>();
|
|
private MachineStatusContent MachineStatusContent;
|
|
|
|
public Dictionary<int, MachineEffectivenessContent> effectivenessContents = new Dictionary<int, MachineEffectivenessContent>();
|
|
private MachineEffectivenessContent MachineEffectivenessContent;
|
|
|
|
public float changeDataTime;
|
|
public int statusItemsCount;
|
|
private int currentContentIndex;
|
|
private bool isChangedData;
|
|
|
|
public override async UniTask Init()
|
|
{
|
|
CurrentDate = GetElement<TextMeshProUGUI>(nameof(CurrentDate));
|
|
CurrentTime = GetElement<TextMeshProUGUI>(nameof(CurrentTime));
|
|
Button_Close = GetElement<Button>(nameof(Button_Close));
|
|
StatusContent = GetElement<RectTransform>(nameof(StatusContent));
|
|
EffectivenessContent = GetElement<RectTransform>(nameof(EffectivenessContent));
|
|
|
|
MachineStatusContent = Resources.Load<MachineStatusContent>($"{ResourceURL.UIPrefabFolderPath}{nameof(MachineStatusContent)}");
|
|
MachineEffectivenessContent = Resources.Load<MachineEffectivenessContent>($"{ResourceURL.UIPrefabFolderPath}{nameof(MachineEffectivenessContent)}");
|
|
WorkProgressContent = transform.GetComponentInChildren<WorkProgressContent>(true);
|
|
WorkProgressContent.Init();
|
|
|
|
Button_Close.onClick.AddListener(OnClickCloseButton);
|
|
|
|
SetDate();
|
|
await UniTask.CompletedTask;
|
|
}
|
|
private void Update()
|
|
{
|
|
SetTime();
|
|
}
|
|
public override void Open()
|
|
{
|
|
gameObject.SetActive(true);
|
|
effect.ActivePanel();
|
|
gameObject.transform.SetAsLastSibling();
|
|
|
|
if (statusContents.Count <= 0)
|
|
{
|
|
isChangedData = false;
|
|
return;
|
|
}
|
|
StartCoroutine(ChageStatusContent());
|
|
}
|
|
public override void Close()
|
|
{
|
|
effect.DeactivePanel();
|
|
gameObject.SetActive(false);
|
|
ResetStatusContentOrder();
|
|
isChangedData = false;
|
|
}
|
|
private void OnClickCloseButton()
|
|
{
|
|
Close();
|
|
}
|
|
private IEnumerator ChageStatusContent()
|
|
{
|
|
isChangedData = true;
|
|
|
|
currentContentIndex = 0;
|
|
|
|
statusContents[currentContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
effectivenessContents[currentContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
WorkProgressContent.SetWorkProgressContent(injectionWorkShopInfo);
|
|
effectivenessContents[currentContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
|
|
currentContentIndex++;
|
|
|
|
while (true)
|
|
{
|
|
yield return new WaitForSeconds(changeDataTime);
|
|
|
|
if (currentContentIndex >= statusContents.Values.Count)
|
|
{
|
|
currentContentIndex = 0;
|
|
}
|
|
|
|
statusContents[currentContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
|
|
var content = statusContents[currentContentIndex];
|
|
var workprogressContentData = content.dataType == MachineType.Injection ? injectionWorkShopInfo : assemblyWorkShopInfo;
|
|
WorkProgressContent.SetWorkProgressContent(workprogressContentData);
|
|
|
|
var effectivenessContentIndex = content.dataType == MachineType.Injection ? 0 : 1;
|
|
effectivenessContents[effectivenessContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
|
|
currentContentIndex++;
|
|
}
|
|
}
|
|
private void ResetStatusContentOrder()
|
|
{
|
|
foreach (var statusContent in statusContents.Values)
|
|
{
|
|
statusContent.gameObject.transform.SetAsFirstSibling();
|
|
}
|
|
}
|
|
#region WorkProgressUI
|
|
public void SetWorkProgressStatus(List<WorkShopInfo> workshopInfos)
|
|
{
|
|
injectionWorkShopInfo = workshopInfos[0];
|
|
assemblyWorkShopInfo = workshopInfos[1];
|
|
}
|
|
#endregion
|
|
|
|
#region MachineStatusUI
|
|
|
|
public void SetProductionContent(List<MachineStatusGroup> groupedInfos)
|
|
{
|
|
for (int i = 0; i < groupedInfos.Count; i++)
|
|
{
|
|
var group = groupedInfos[i];
|
|
|
|
if (!statusContents.ContainsKey(i))
|
|
{
|
|
var content = Instantiate(MachineStatusContent, StatusContent);
|
|
content.Init();
|
|
content.SetProductionStatusItem(group.Infos, group.Type);
|
|
statusContents.Add(i, content);
|
|
}
|
|
else
|
|
{
|
|
statusContents[i].SetProductionStatusItem(group.Infos, group.Type);
|
|
}
|
|
}
|
|
|
|
if (!isChangedData && gameObject.activeSelf)
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(ChageStatusContent());
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region MachineEffectivenessUI
|
|
|
|
public void SetEffectivenessContent(List<MachineEffectivenessGroup> groupedInfos)
|
|
{
|
|
for (int i = 0; i < groupedInfos.Count; i++)
|
|
{
|
|
var group = groupedInfos[i];
|
|
|
|
if (!effectivenessContents.ContainsKey(i))
|
|
{
|
|
var content = Instantiate(MachineEffectivenessContent, EffectivenessContent);
|
|
content.Init();
|
|
content.SetProductionStatusItem(group.Infos, group.Type);
|
|
effectivenessContents.Add(i, content);
|
|
}
|
|
else
|
|
{
|
|
effectivenessContents[i].SetProductionStatusItem(group.Infos, group.Type);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public void SetDate()
|
|
{
|
|
CurrentDate.text = DateTime.Now.ToString("yyyy.MM.dd");
|
|
}
|
|
public void SetTime()
|
|
{
|
|
CurrentTime.text = DateTime.Now.ToString("HH:mm");
|
|
}
|
|
}
|
|
} |