139 lines
4.7 KiB
C#
139 lines
4.7 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Samkwang
|
|
{
|
|
public class Panel_TotalProgress : UIPopupBase
|
|
{
|
|
private string dataOrder;
|
|
|
|
public TextMeshProUGUI CurrentDate;
|
|
public TextMeshProUGUI CurrentTime;
|
|
public RectTransform ContentArea;
|
|
public RectTransform Image_Loading;
|
|
public Button Button_Close;
|
|
|
|
public float changeDataTime;
|
|
public float fadeTime;
|
|
|
|
private UI_WorkProgressContent WorkProgressContent;
|
|
private BranchInfo branchInfo;
|
|
|
|
public Dictionary<string, UI_MachineStatusItem> machineStatuses = new Dictionary<string, UI_MachineStatusItem>();
|
|
private UI_MachineStatusItem prf_machineStatus;
|
|
public RectTransform MachineStatusContent;
|
|
|
|
public Action<string> onClose;
|
|
|
|
public void Init()
|
|
{
|
|
dataOrder = Resources.Load<TextAsset>("DataOrder").text;
|
|
|
|
var textDict = transform.GetChildComponentsByName<TextMeshProUGUI>();
|
|
var buttonDict = transform.GetChildComponentsByName<Button>();
|
|
var rectDict = transform.GetChildComponentsByName<RectTransform>();
|
|
|
|
CurrentDate = textDict.GetOrNull(nameof(CurrentDate));
|
|
CurrentTime = textDict.GetOrNull(nameof(CurrentTime));
|
|
ContentArea = rectDict.GetOrNull(nameof(ContentArea));
|
|
Image_Loading = rectDict.GetOrNull(nameof(Image_Loading));
|
|
Button_Close = buttonDict.GetOrNull(nameof(Button_Close));
|
|
|
|
MachineStatusContent = rectDict.GetOrNull(nameof(MachineStatusContent));
|
|
|
|
prf_machineStatus = Resources.Load<UI_MachineStatusItem>("Prefabs/UI/PRF_UI_MachineStatusItem");
|
|
WorkProgressContent = ContentArea.GetComponentInChildren<UI_WorkProgressContent>(true);
|
|
|
|
WorkProgressContent.Init();
|
|
Button_Close.onClick.AddListener(Close);
|
|
|
|
SetDate();
|
|
}
|
|
private void Update()
|
|
{
|
|
SetTime();
|
|
}
|
|
public override void Open()
|
|
{
|
|
gameObject.SetActive(true);
|
|
StopAllCoroutines();
|
|
StartCoroutine(ScaleUp());
|
|
|
|
gameObject.transform.SetAsLastSibling();
|
|
}
|
|
public override void Close()
|
|
{
|
|
onClose?.Invoke("TotalProgress");
|
|
gameObject.SetActive(false);
|
|
gameObject.transform.localScale = Vector3.zero;
|
|
}
|
|
|
|
#region WorkProgressUI
|
|
public void SetWorkProgressStatus(List<BranchInfo> workshopInfos)
|
|
{
|
|
branchInfo = workshopInfos[0];
|
|
WorkProgressContent.SetWorkProgressContent(branchInfo);
|
|
}
|
|
#endregion
|
|
|
|
#region MachineStatusUI
|
|
public void SetTotalProductionStatus(List<CompleteInfo> machineInfos)
|
|
{
|
|
Image_Loading.gameObject.SetActive(false);
|
|
|
|
var sortMachineInfos = SortListByWorknm(machineInfos);
|
|
|
|
SetProductionStatusItem(sortMachineInfos);
|
|
}
|
|
public List<CompleteInfo> SortListByWorknm(List<CompleteInfo> machineInfos)
|
|
{
|
|
var workcdOrder = JsonConvert.DeserializeObject<List<string>>(dataOrder);
|
|
var orderMap = workcdOrder.Select((workcd, index) => new { workcd, index }).ToDictionary(x => x.workcd, x => x.index);
|
|
|
|
return machineInfos.Where(field => orderMap.ContainsKey(field.worknm)).OrderBy(field => orderMap[field.worknm]).ToList();
|
|
}
|
|
public void SetProductionStatusItem(List<CompleteInfo> machineInfos)
|
|
{
|
|
foreach (var machineInfo in machineInfos)
|
|
{
|
|
if (!machineStatuses.ContainsKey(machineInfo.worknm))
|
|
{
|
|
var machineStatus = Instantiate(prf_machineStatus, MachineStatusContent);
|
|
machineStatus.Init();
|
|
machineStatuses.Add(machineInfo.worknm, machineStatus);
|
|
}
|
|
|
|
machineStatuses[machineInfo.worknm].SetStatusData(machineInfo);
|
|
}
|
|
}
|
|
#endregion
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |