140 lines
3.9 KiB
C#
140 lines
3.9 KiB
C#
using System;
|
|
|
|
namespace Thousandto.Launcher.Form
|
|
{
|
|
/// <summary>
|
|
/// 进度基础面板
|
|
/// </summary>
|
|
public class UILoadingBasePanel : IUIInnerPanelBase
|
|
{
|
|
#region //UI控件
|
|
UIProgressBar ProgressBar;
|
|
UILabel ProgressMinToMaxLabel;
|
|
UILabel StepLabel;
|
|
UILabel PercentageLabel;
|
|
#endregion
|
|
|
|
private bool _isUseDownload = false;
|
|
private int _speed = 0;
|
|
private float _value = 0;
|
|
private int _min = 0;
|
|
private int _max = 0;
|
|
|
|
private string _stepName = "";
|
|
private string _minToMaxText = "";
|
|
private string _precentageText = "";
|
|
|
|
/// <summary>
|
|
/// 控件复位
|
|
/// </summary>
|
|
public void Reset()
|
|
{
|
|
_isUseDownload = false;
|
|
_speed = 0;
|
|
_min = 0;
|
|
_max = 0;
|
|
_value = 0;
|
|
_stepName = "";
|
|
_minToMaxText = "";
|
|
_precentageText = "";
|
|
OnRefresh();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置流程名字
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
public void SetStepName(string str)
|
|
{
|
|
_stepName = NGUIText.StripLanSymbol(str);
|
|
}
|
|
|
|
//设置速度
|
|
public void SetSpeed(int speed = 0)
|
|
{
|
|
if (_speed != speed)
|
|
{
|
|
_speed = speed;
|
|
_precentageText = GetPercentageText();
|
|
_minToMaxText = GetMinToMaxText();
|
|
}
|
|
}
|
|
|
|
public void SetUseDownload(bool isUseDownload)
|
|
{
|
|
if (_isUseDownload != isUseDownload)
|
|
{
|
|
_isUseDownload = isUseDownload;
|
|
_precentageText = GetPercentageText();
|
|
_minToMaxText = GetMinToMaxText();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置进度
|
|
/// </summary>
|
|
/// <param name="percatage"></param>
|
|
public void SetProgress(float percatage)
|
|
{
|
|
if (percatage != _value)
|
|
{
|
|
_value = Math.Max(0, Math.Min(1, percatage));
|
|
_precentageText = GetPercentageText();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进度显示
|
|
/// </summary>
|
|
/// <param name="min"></param>
|
|
/// <param name="max"></param>
|
|
/// <param name="useDownload"></param>
|
|
public void SetProgressMinToMax(int min, int max)
|
|
{
|
|
if (_min != min || _max != max)
|
|
{
|
|
_min = min;
|
|
_max = max;
|
|
_minToMaxText = GetMinToMaxText();
|
|
}
|
|
}
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
ProgressBar = Trans.Find("Progress").GetComponent<UIProgressBar>();
|
|
ProgressMinToMaxLabel = Trans.Find("Progress/ProgressMinToMaxLabel").GetComponent<UILabel>();
|
|
StepLabel = Trans.Find("Progress/StepLabel").GetComponent<UILabel>();
|
|
PercentageLabel = Trans.Find("Progress/PercentageLabel").GetComponent<UILabel>();
|
|
Reset();
|
|
base.OnInitialize();
|
|
}
|
|
|
|
protected override void OnRefresh()
|
|
{
|
|
ProgressBar.value = _value;
|
|
ProgressMinToMaxLabel.text = _minToMaxText;
|
|
StepLabel.text = _stepName;
|
|
PercentageLabel.text = _precentageText;
|
|
base.OnRefresh();
|
|
}
|
|
|
|
private string GetMinToMaxText()
|
|
{
|
|
if (_max == 0)
|
|
return "";
|
|
else if (_isUseDownload)
|
|
return string.Format("{0}kb/{1}kb", _min / 1024, _max / 1024);
|
|
else
|
|
return string.Format("{0}/{1}", _min, _max);
|
|
}
|
|
|
|
private string GetPercentageText()
|
|
{
|
|
if (_isUseDownload)
|
|
return (string.Format("{0:F1}% ({1} kb/s)", _value * 100, _speed));
|
|
else
|
|
return (string.Format("{0:F1}%", _value * 100));
|
|
}
|
|
}
|
|
}
|