Files
7d2dXG/Mods/zzz_REBIRTH__Utils/Scripts/XUIC/XUiC_StatsHUDRebirth.cs
Nathaniel Cosford e06f2bd282 Add All Mods
2025-05-29 23:33:28 +09:30

135 lines
6.9 KiB
C#

internal class XUiC_StatsHUDRebirth : XUiController
{
private readonly CachedStringFormatter<int> dayFormatter = new CachedStringFormatter<int>((int _i) => _i.ToString());
private readonly CachedStringFormatter<int, int> timeFormatter = new CachedStringFormatter<int, int>((int _hour, int _min) => string.Format("{0:00}:{1:00}", _hour, _min));
private float lastValueStamina = 0.0f;
private float lastValueHealth = 0.0f;
private float lastValueWater = 0.0f;
private float lastValueFood = 0.0f;
private float lastValueStaminaPerc = 0.0f;
private float lastValueHealthPerc = 0.0f;
private float lastValueWaterPerc = 0.0f;
private float lastValueFoodPerc = 0.0f;
private float deltaTime;
private EntityPlayerLocal LocalPlayer;
private readonly CachedStringFormatterXuiRgbaColor stealthColorFormatter = new CachedStringFormatterXuiRgbaColor();
private readonly CachedStringFormatter<float> statfillFormatter = new CachedStringFormatter<float>((Func<float, string>)(_i => _i.ToCultureInvariantString()));
private readonly CachedStringFormatter<int, int> statcurrentWMaxFormatterAOfB = new CachedStringFormatter<int, int>((Func<int, int, string>)((_i, _i1) => string.Format("{0}/{1}", (object)_i, (object)_i1)));
private readonly CachedStringFormatter<float, float> statmodifiedmaxFormatter = new CachedStringFormatter<float, float>((Func<float, float, string>)((_f1, _f2) => (_f1 / _f2).ToCultureInvariantString()));
public override bool GetBindingValue(ref string value, string bindingName)
{
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue START");
bool bHide = flUpdateTime < 80;
if (flUpdateTime < 80)
{
flUpdateTime = flUpdateTime + .1f;
}
/*Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 0 flShowStatsHUDHealth: " + flShowStatsHUDHealth);
Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 0 flShowStatsHUDStamina: " + flShowStatsHUDStamina);
Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 0 bindingName: " + bindingName);*/
switch (bindingName)
{
case "playerStaminaModifiedMax":
value = (this.LocalPlayer != null) ? (this.LocalPlayer.Stats.Stamina.ModifiedMax / this.LocalPlayer.Stats.Stamina.Max).ToString("0.##") : "0";
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 1 playerStaminaModifiedMax: " + value);
return true;
case "statStaminaFill":
if (this.LocalPlayer == null)
{
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 4");
value = "0";
return true;
}
value = this.statfillFormatter.Format(Math.Max(this.lastValueStamina, 0.0f) * 1.01f);
lastValueStaminaPerc = this.lastValueStamina * 100;
this.lastValueStamina = Mathf.Lerp(this.lastValueStamina, this.LocalPlayer.Stats.Stamina.ValuePercentUI, this.deltaTime * 3f);
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 3 statStaminaFill: " + value);
return true;
case "playerHealthModifiedMax":
value = (this.LocalPlayer != null) ? (this.LocalPlayer.Stats.Health.ModifiedMax / this.LocalPlayer.Stats.Health.Max).ToString("0.##") : "0";
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 1 playerHealthModifiedMax: " + value);
return true;
case "statHealthFill":
if (this.LocalPlayer == null)
{
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 4");
value = "0";
return true;
}
value = this.statfillFormatter.Format(Math.Max(this.lastValueHealth, 0.0f) * 1.01f);
this.lastValueHealth = Mathf.Lerp(this.lastValueHealth, this.LocalPlayer.Stats.Health.ValuePercentUI, this.deltaTime * 3f);
lastValueHealthPerc = this.lastValueHealth * 100;
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 3 statHealthFill: " + value);
return true;
case "playerWaterModifiedMax":
value = (this.LocalPlayer != null) ? (this.LocalPlayer.Stats.Water.ModifiedMax / this.LocalPlayer.Stats.Water.Max).ToString("0.##") : "0";
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 1 playerWaterModifiedMax: " + value);
return true;
case "statWaterFill":
if (this.LocalPlayer == null)
{
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 4");
value = "0";
return true;
}
value = this.statfillFormatter.Format(Math.Max(this.lastValueWater, 0.0f) * 1.01f);
this.lastValueWater = Mathf.Lerp(this.lastValueWater, this.LocalPlayer.Stats.Water.ValuePercentUI, this.deltaTime * 3f);
lastValueWaterPerc = this.lastValueWater * 100;
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 3 statWaterFill: " + value);
return true;
case "playerFoodModifiedMax":
value = (this.LocalPlayer != null) ? (this.LocalPlayer.Stats.Food.ModifiedMax / this.LocalPlayer.Stats.Food.Max).ToString("0.##") : "0";
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 1 playerFoodModifiedMax: " + value);
return true;
case "statFoodFill":
if (this.LocalPlayer == null)
{
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 4");
value = "0";
return true;
}
value = this.statfillFormatter.Format(Math.Max(this.lastValueFood, 0.0f) * 1.01f);
this.lastValueFood = Mathf.Lerp(this.lastValueFood, this.LocalPlayer.Stats.Food.ValuePercentUI, this.deltaTime * 3f);
lastValueFoodPerc = this.lastValueFood * 100;
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 3 statFoodFill: " + value);
return true;
default:
//Log.Out("XUiC_StatsHUDRebirth-GetBindingValue 12");
return false;
}
}
public override void OnOpen()
{
//Log.Out("XUiC_StatsHUDRebirth-OnOpen START");
base.OnOpen();
if (this.LocalPlayer == null && XUi.IsGameRunning())
{
//Log.Out("XUiC_StatsHUDRebirth-OnOpen 1");
this.LocalPlayer = this.xui.playerUI.entityPlayer;
}
this.IsDirty = true;
this.RefreshBindings(true);
}
public override void Update(float _dt)
{
//Log.Out("XUiC_StatsHUDRebirth-Update START");
base.Update(_dt);
if (this.LocalPlayer == null)
{
//Log.Out("XUiC_StatsHUDRebirth-Update 1");
return;
}
this.deltaTime = _dt;
this.RefreshBindings(true);
}
protected float flUpdateTime;
}