202 lines
6.8 KiB
C#
202 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.UI;
|
|
using EnglewoodLAB.Constants;
|
|
using EnglewoodLAB.Management;
|
|
|
|
namespace EnglewoodLAB.UI
|
|
{
|
|
public class FinalInspectionPanel : UIPanel
|
|
{
|
|
private TextMeshProUGUI selectedData;
|
|
private List<CompleteInfo> data = new();
|
|
|
|
public TextMeshProUGUI CurrentDate;
|
|
public TextMeshProUGUI CurrentTime;
|
|
public Button Button_Close;
|
|
public RectTransform Content;
|
|
|
|
public float maxBarHeight;
|
|
public Image barChart_plan;
|
|
public Image barChart_actual;
|
|
public Image barChart_passed;
|
|
public Image barChart_rejected;
|
|
|
|
public Panel_Effect effect;
|
|
|
|
public Dictionary<int, ProgressContent> progressContents = new Dictionary<int, ProgressContent>();
|
|
private ProgressContent progressContent;
|
|
|
|
public int statusItemsCount;
|
|
private int currentContentIndex;
|
|
private bool isChangedData;
|
|
|
|
public float changeDataTime;
|
|
|
|
public override async UniTask Init()
|
|
{
|
|
selectedData = GetElement<TextMeshProUGUI>(nameof(selectedData));
|
|
CurrentDate = GetElement<TextMeshProUGUI>(nameof(CurrentDate));
|
|
CurrentTime = GetElement<TextMeshProUGUI>(nameof(CurrentTime));
|
|
Button_Close = GetElement<Button>(nameof(Button_Close));
|
|
Content = GetElement<RectTransform>(nameof(Content));
|
|
|
|
barChart_plan = GetElement<Image>(nameof(barChart_plan));
|
|
barChart_actual = GetElement<Image>(nameof(barChart_actual));
|
|
barChart_passed = GetElement<Image>(nameof(barChart_passed));
|
|
barChart_rejected = GetElement<Image>(nameof(barChart_rejected));
|
|
|
|
progressContent = Resources.Load<ProgressContent>($"{ResourceURL.UIPrefabFolderPath}{nameof(ProgressContent)}");
|
|
|
|
Button_Close.onClick.AddListener(OnClickCloseButton);
|
|
SetDate();
|
|
|
|
await UniTask.CompletedTask;
|
|
}
|
|
public void Update()
|
|
{
|
|
SetTime();
|
|
}
|
|
public override void Open()
|
|
{
|
|
gameObject.SetActive(true);
|
|
effect.ActivePanel();
|
|
gameObject.transform.SetAsLastSibling();
|
|
|
|
if (progressContents.Count <= 0)
|
|
{
|
|
isChangedData = false;
|
|
return;
|
|
}
|
|
|
|
StartCoroutine(ChageStatusContent());
|
|
SelectedMachineData(data[0]);
|
|
}
|
|
public override void Close()
|
|
{
|
|
effect.DeactivePanel();
|
|
gameObject.SetActive(false);
|
|
ResetStatusContentOrder();
|
|
isChangedData = false;
|
|
}
|
|
private void OnClickCloseButton()
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private IEnumerator ChageStatusContent()
|
|
{
|
|
isChangedData = true;
|
|
currentContentIndex = 0;
|
|
|
|
progressContents[currentContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
currentContentIndex++;
|
|
|
|
while (true)
|
|
{
|
|
yield return new WaitForSeconds(changeDataTime);
|
|
|
|
if (currentContentIndex >= progressContents.Values.Count)
|
|
{
|
|
currentContentIndex = 0;
|
|
}
|
|
|
|
progressContents[currentContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
currentContentIndex++;
|
|
}
|
|
}
|
|
private void ResetStatusContentOrder()
|
|
{
|
|
foreach (var statusContent in progressContents.Values)
|
|
{
|
|
statusContent.gameObject.transform.SetAsFirstSibling();
|
|
}
|
|
}
|
|
|
|
public void SetProductionStatus(List<CompleteInfo> machineInfos)
|
|
{
|
|
var splitCompleteInfo = SplitArray(machineInfos, statusItemsCount);
|
|
SetProductionContent(splitCompleteInfo);
|
|
}
|
|
public void SetProductionContent(List<List<CompleteInfo>> splitCompleteInfo)
|
|
{
|
|
for (int i = 0; i < splitCompleteInfo.Count; i++)
|
|
{
|
|
if (!progressContents.ContainsKey(i))
|
|
{
|
|
var statusContent = Instantiate(progressContent, Content);
|
|
statusContent.Init();
|
|
statusContent.onClickContentClildItem += SelectedMachineData;
|
|
statusContent.SetProductionStatusItem(splitCompleteInfo[i]);
|
|
|
|
progressContents.Add(i, statusContent);
|
|
data.AddRange(splitCompleteInfo[i]);
|
|
}
|
|
else
|
|
{
|
|
progressContents[i].SetProductionStatusItem(splitCompleteInfo[i]);
|
|
}
|
|
}
|
|
if (!isChangedData && gameObject.activeSelf)
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(ChageStatusContent());
|
|
}
|
|
}
|
|
private List<List<CompleteInfo>> SplitArray(List<CompleteInfo> machineInfos, int groupSize)
|
|
{
|
|
List<List<CompleteInfo>> result = new List<List<CompleteInfo>>();
|
|
int totalGroups = Mathf.CeilToInt(machineInfos.Count / (float)groupSize);
|
|
|
|
for (int i = 0; i < totalGroups; i++)
|
|
{
|
|
int startIndex = i * groupSize;
|
|
int endIndex = Mathf.Min(startIndex + groupSize, machineInfos.Count);
|
|
|
|
List<CompleteInfo> group = new List<CompleteInfo>();
|
|
for (int j = startIndex; j < endIndex; j++)
|
|
{
|
|
group.Add(machineInfos[j]);
|
|
}
|
|
|
|
result.Add(group);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
private void SelectedMachineData(CompleteInfo info)
|
|
{
|
|
selectedData.SetText(info.worknm);
|
|
|
|
SetBarchart(barChart_plan, info.planqty, info.planqty);
|
|
SetBarchart(barChart_actual, info.workqty, info.planqty);
|
|
SetBarchart(barChart_passed, info.goodqty, info.planqty);
|
|
SetBarchart(barChart_rejected, info.badqty, info.planqty);
|
|
}
|
|
public void SetDate()
|
|
{
|
|
CurrentDate.text = DateTime.Now.ToString("yyyy.MM.dd");
|
|
}
|
|
public void SetTime()
|
|
{
|
|
CurrentTime.text = DateTime.Now.ToString("HH:mm");
|
|
}
|
|
private void SetBarchart(Image barchart, string value, string maxValue)
|
|
{
|
|
var height = (StringConvertFloat(value) / StringConvertFloat(maxValue)) * maxBarHeight;
|
|
barchart.rectTransform.sizeDelta = new Vector2(barchart.rectTransform.sizeDelta.x, height);
|
|
}
|
|
private float StringConvertFloat(string value)
|
|
{
|
|
float.TryParse(value, out var floatValue);
|
|
return floatValue;
|
|
}
|
|
}
|
|
}
|
|
|