125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Cysharp.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static MQTT;
|
|
using EnglewoodLAB.UI;
|
|
using EnglewoodLAB.Constants;
|
|
using EnglewoodLAB.Management;
|
|
|
|
namespace EnglewoodLAB.UI
|
|
{
|
|
public class WorkProgressPanel : UIPanel
|
|
{
|
|
private TextMeshProUGUI selectedData;
|
|
private List<WorkShopInfo> data = new();
|
|
|
|
public Dictionary<string, WorkProgressItem> workStatuses = new Dictionary<string, WorkProgressItem>();
|
|
public Panel_Effect effect;
|
|
private WorkProgressItem workProgressItem;
|
|
public RectTransform StatusContent;
|
|
|
|
public float maxBarHeight;
|
|
private Image barChart_plan;
|
|
private Image barChart_actual;
|
|
private Image barChart_passed;
|
|
private Image barChart_rejected;
|
|
|
|
public Button Button_Close;
|
|
public TextMeshProUGUI CurrentDate;
|
|
public TextMeshProUGUI CurrentTime;
|
|
|
|
public override async UniTask Init()
|
|
{
|
|
selectedData = GetElement<TextMeshProUGUI>(nameof(selectedData));
|
|
StatusContent = GetElement<RectTransform>(nameof(StatusContent));
|
|
workProgressItem = Resources.Load<WorkProgressItem>($"{ResourceURL.UIPrefabFolderPath}{nameof(WorkProgressItem)}");
|
|
|
|
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));
|
|
|
|
CurrentDate = GetElement<TextMeshProUGUI>(nameof(CurrentDate));
|
|
CurrentTime = GetElement<TextMeshProUGUI>(nameof(CurrentTime));
|
|
Button_Close = GetElement<Button>(nameof(Button_Close));
|
|
|
|
|
|
|
|
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();
|
|
|
|
SelectedGrounpData(data[0]);
|
|
}
|
|
public override void Close()
|
|
{
|
|
effect.DeactivePanel();
|
|
gameObject.SetActive(false);
|
|
}
|
|
private void OnClickCloseButton()
|
|
{
|
|
Close();
|
|
}
|
|
public void SetWorkProgressStatus(List<WorkShopInfo> workShopInfos)
|
|
{
|
|
foreach (var workShopInfo in workShopInfos)
|
|
{
|
|
if (!workStatuses.ContainsKey(workShopInfo.groupcd))
|
|
{
|
|
var workStatusItem = Instantiate(workProgressItem, StatusContent);
|
|
workStatusItem.Init();
|
|
workStatusItem.onClickItem += SelectedGrounpData;
|
|
|
|
workStatuses.Add(workShopInfo.groupcd, workStatusItem);
|
|
data.Add(workShopInfo);
|
|
}
|
|
workStatuses[workShopInfo.groupcd].SetStatusData(workShopInfo);
|
|
}
|
|
}
|
|
private void SelectedGrounpData(WorkShopInfo info)
|
|
{
|
|
selectedData.SetText(info.groupnm);
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|