219 lines
7.1 KiB
C#
219 lines
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Samkwang
|
|
{
|
|
public class UI_MachineStatusIcon : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
public RectTransform rectTransform;
|
|
public CompleteInfo data;
|
|
private List<AlarmInfo> alarmInfos = new();
|
|
|
|
public RectTransform Default_KPI;
|
|
public RectTransform Expand_KPI;
|
|
|
|
private TMP_Text DefaultMachineName;
|
|
private TMP_Text ExpandMachineName;
|
|
private Image Default_Status;
|
|
private Image Expand_Status;
|
|
|
|
private Image Default_Alarm;
|
|
private Image Expand_Alarm;
|
|
|
|
//private TMP_Text eorate;
|
|
private TMP_Text pvp;
|
|
private TMP_Text workcd;
|
|
//private TMP_Text porate;
|
|
private TMP_Text goodqtyrate;
|
|
private TMP_Text workdt;
|
|
private TMP_Text wordno;
|
|
|
|
public bool isExpand;
|
|
|
|
public Action<UI_MachineStatusIcon> onClickIcon;
|
|
|
|
private void Awake()
|
|
{
|
|
var rectDict = transform.GetChildComponentsByName<RectTransform>();
|
|
var textDict = transform.GetChildComponentsByName<TMP_Text>();
|
|
var imageDict = transform.GetChildComponentsByName<Image>();
|
|
|
|
rectTransform = GetComponent<RectTransform>();
|
|
Default_KPI = rectDict.GetOrNull(nameof(Default_KPI));
|
|
Expand_KPI = rectDict.GetOrNull(nameof(Expand_KPI));
|
|
|
|
DefaultMachineName = textDict.GetOrNull(nameof(DefaultMachineName));
|
|
ExpandMachineName = textDict.GetOrNull(nameof(ExpandMachineName));
|
|
Default_Status = imageDict.GetOrNull(nameof(Default_Status));
|
|
Expand_Status = imageDict.GetOrNull(nameof(Expand_Status));
|
|
Default_Alarm = imageDict.GetOrNull(nameof(Default_Alarm));
|
|
Expand_Alarm = imageDict.GetOrNull(nameof(Expand_Alarm));
|
|
|
|
//eorate = textDict.GetOrNull(nameof(eorate));
|
|
pvp = textDict.GetOrNull(nameof(pvp));
|
|
workcd = textDict.GetOrNull(nameof(workcd));
|
|
//porate = textDict.GetOrNull(nameof(porate));
|
|
goodqtyrate = textDict.GetOrNull(nameof(goodqtyrate));
|
|
workdt = textDict.GetOrNull(nameof(workdt));
|
|
wordno = textDict.GetOrNull(nameof(wordno));
|
|
}
|
|
|
|
public void SetData(CompleteInfo data, string machineName)
|
|
{
|
|
this.data = data;
|
|
|
|
//eorate.SetText(PercentCalculate(data.eorate).ToString() + "%");
|
|
pvp.SetText(PercentCalculate(data.pvp).ToString() + "%");
|
|
workcd.SetText(SetTextData(data.workcd));
|
|
goodqtyrate.SetText(DecimalPointPercentCalculate(data.goodqtyrate).ToString() + "%");
|
|
//porate.SetText(PercentCalculate(data.porate).ToString() + "%");
|
|
workdt.SetText(CorrectionTime(data.workdt, "yyyy-MM-dd"));
|
|
wordno.SetText(SetTextData(data.wordno));
|
|
|
|
DefaultMachineName.SetText(SetNameData(data.worknm, machineName));
|
|
ExpandMachineName.SetText(SetNameData(data.worknm, machineName));
|
|
|
|
Default_Status.color = SetStatusColor(data.statusnm);
|
|
Expand_Status.color = SetStatusColor(data.statusnm);
|
|
|
|
DefaultMachineName.color = SetStatusColor(data.statusnm) == Color.gray ? Color.gray : DefaultMachineName.color;
|
|
ExpandMachineName.color = SetStatusColor(data.statusnm) == Color.gray ? Color.gray : ExpandMachineName.color;
|
|
}
|
|
public void SetAlarmData(List<AlarmInfo> alarmInfos)
|
|
{
|
|
if (alarmInfos != null || alarmInfos.Count != 0)
|
|
{
|
|
this.alarmInfos = alarmInfos;
|
|
var isAlarm = alarmInfos.Any(a => a.state.Trim().Equals("SET", StringComparison.OrdinalIgnoreCase));
|
|
|
|
Default_Alarm.gameObject.SetActive(isAlarm);
|
|
Expand_Alarm.gameObject.SetActive(isAlarm);
|
|
}
|
|
else
|
|
{
|
|
Default_Alarm.gameObject.SetActive(false);
|
|
Expand_Alarm.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
private string SetNameData(string value, string machineName)
|
|
{
|
|
if (!CheckDataExists(value))
|
|
{
|
|
return machineName;
|
|
}
|
|
return value;
|
|
}
|
|
private float DecimalPointPercentCalculate(string value)
|
|
{
|
|
if (!CheckDataExists(value))
|
|
{
|
|
return 0f;
|
|
}
|
|
|
|
var originFloatValue = float.Parse(value);
|
|
var floatValue = originFloatValue * 100f;
|
|
|
|
return floatValue;
|
|
}
|
|
private float PercentCalculate(string value)
|
|
{
|
|
if (!CheckDataExists(value))
|
|
{
|
|
return 0f;
|
|
}
|
|
|
|
var originFloatValue = float.Parse(value);
|
|
return originFloatValue;
|
|
}
|
|
private string SetTextData(string value)
|
|
{
|
|
if (!CheckDataExists(value))
|
|
{
|
|
return "-";
|
|
}
|
|
return value;
|
|
}
|
|
private string CorrectionTime(string value, string dateForm)
|
|
{
|
|
if (DateTime.TryParseExact(value, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate))
|
|
{
|
|
return parsedDate.ToString(dateForm);
|
|
}
|
|
return "-";
|
|
}
|
|
|
|
private Color SetStatusColor(string value)
|
|
{
|
|
var newColor = Color.white;
|
|
|
|
switch (value)
|
|
{
|
|
case "°¡µ¿Áß":
|
|
newColor = Color.green;
|
|
break;
|
|
case "ºñ°¡µ¿Áß":
|
|
newColor = Color.gray;
|
|
break;
|
|
}
|
|
return newColor;
|
|
}
|
|
private bool CheckDataExists(string value)
|
|
{
|
|
if (value == null || value == string.Empty)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void Active()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
public void Deactive()
|
|
{
|
|
isExpand = false;
|
|
Default_KPI.gameObject.SetActive(true);
|
|
Expand_KPI.gameObject.SetActive(false);
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
onClickIcon?.Invoke(this);
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (!isExpand)
|
|
{
|
|
if (Expand_KPI == null && Default_KPI == null)
|
|
return;
|
|
|
|
Expand_KPI.gameObject.SetActive(true);
|
|
Default_KPI.gameObject.SetActive(false);
|
|
|
|
isExpand = true;
|
|
transform.SetAsLastSibling();
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (isExpand)
|
|
{
|
|
Default_KPI.gameObject.SetActive(true);
|
|
Expand_KPI.gameObject.SetActive(false);
|
|
isExpand = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|