105 lines
4.3 KiB
C#
105 lines
4.3 KiB
C#
using EnglewoodLAB.Extensions;
|
|
using EnglewoodLAB.Management;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace EnglewoodLAB.UI
|
|
{
|
|
public class WorkProgressContent : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI planqty;
|
|
public TextMeshProUGUI percentplanqty;
|
|
public Slider Slider_planqty;
|
|
|
|
public TextMeshProUGUI workqty;
|
|
public TextMeshProUGUI percentworkqty;
|
|
public Slider Slider_workqty;
|
|
|
|
public TextMeshProUGUI badqty;
|
|
public TextMeshProUGUI percentbadqty;
|
|
public Slider Slider_badqty;
|
|
|
|
public TextMeshProUGUI progressrate;
|
|
public TextMeshProUGUI percentprogressrate;
|
|
public Slider Slider_progressrate;
|
|
|
|
public void Init()
|
|
{
|
|
transform.TryGetComponentInChildren(nameof(planqty), out planqty);
|
|
transform.TryGetComponentInChildren(nameof(percentplanqty), out percentplanqty);
|
|
transform.TryGetComponentInChildren(nameof(Slider_planqty), out Slider_planqty);
|
|
|
|
transform.TryGetComponentInChildren(nameof(workqty), out workqty);
|
|
transform.TryGetComponentInChildren(nameof(percentworkqty), out percentworkqty);
|
|
transform.TryGetComponentInChildren(nameof(Slider_workqty), out Slider_workqty);
|
|
|
|
transform.TryGetComponentInChildren(nameof(badqty), out badqty);
|
|
transform.TryGetComponentInChildren(nameof(percentbadqty), out percentbadqty);
|
|
transform.TryGetComponentInChildren(nameof(Slider_badqty), out Slider_badqty);
|
|
|
|
transform.TryGetComponentInChildren(nameof(progressrate), out progressrate);
|
|
transform.TryGetComponentInChildren(nameof(percentprogressrate), out percentprogressrate);
|
|
transform.TryGetComponentInChildren(nameof(Slider_progressrate), out Slider_progressrate);
|
|
}
|
|
|
|
public void SetWorkProgressContent(WorkShopInfo workShopInfo)
|
|
{
|
|
SetWorkProgressItem(planqty, percentplanqty, Slider_planqty, workShopInfo.planqty, workShopInfo.planqty);
|
|
SetWorkProgressItem(workqty, percentworkqty, Slider_workqty, workShopInfo.planqty, workShopInfo.workqty);
|
|
SetWorkProgressItem(badqty, percentbadqty, Slider_badqty, workShopInfo.planqty, workShopInfo.badqty);
|
|
SetWorkProgressrateItem(progressrate, percentprogressrate, Slider_progressrate, workShopInfo.progressrate);
|
|
}
|
|
public void SetWorkProgressItem(TextMeshProUGUI value, TextMeshProUGUI percent, Slider slider, string maxValue, string currentValue)
|
|
{
|
|
value.SetText(currentValue);
|
|
|
|
var maxValueData = StringConvertFloat(maxValue);
|
|
var currentValueData = StringConvertFloat(currentValue);
|
|
percent.SetText(SetPercentData(maxValueData, currentValueData));
|
|
|
|
slider.maxValue = 1f;
|
|
slider.value = GetSliderData(maxValueData, currentValueData);
|
|
}
|
|
public void SetWorkProgressrateItem(TextMeshProUGUI value, TextMeshProUGUI percent, Slider slider, string currentValue)
|
|
{
|
|
value.SetText(currentValue);
|
|
|
|
var currentValueData = StringConvertFloat(currentValue);
|
|
percent.SetText(currentValue);
|
|
|
|
slider.maxValue = 1f;
|
|
slider.value = GetRateSliderData(currentValueData);
|
|
}
|
|
private string SetPercentData(float maxValue, float currentValue)
|
|
{
|
|
if (maxValue == 0f)
|
|
return "0.0";
|
|
|
|
var percentData = (currentValue / maxValue) * 100f;
|
|
var result = percentData >= 100 ? percentData.ToString("F0") : percentData > 0 && percentData <= 0.1 ? "0.1" : percentData.ToString("F1");
|
|
|
|
return result;
|
|
}
|
|
private float GetSliderData(float maxValue, float currentValue)
|
|
{
|
|
var percentData = currentValue / maxValue;
|
|
|
|
var percent = percentData > 0 && percentData <= 0.01f ? 0.01f : percentData;
|
|
return percent;
|
|
}
|
|
private float GetRateSliderData(float currentValue)
|
|
{
|
|
var percentData = currentValue * 0.01f;
|
|
var percent = percentData > 0 && percentData <= 0.01f ? 0.01f : percentData;
|
|
return percent;
|
|
}
|
|
private float StringConvertFloat(string value)
|
|
{
|
|
float.TryParse(value, out var floatValue);
|
|
return floatValue;
|
|
}
|
|
}
|
|
}
|
|
|