Fix speed label not disappearing on machine edit

This commit is contained in:
Norbi Peti 2022-02-24 00:43:05 +01:00
parent 1f94cf1608
commit 8223447319
2 changed files with 33 additions and 17 deletions

View file

@ -20,7 +20,7 @@ namespace BuildingTools
private readonly CommandUtils _commandUtils;
private readonly BlockSelections _blockSelections;
private readonly MirrorModeEngine _mirrorModeEngine = new MirrorModeEngine();
//private readonly MirrorModeEngine _mirrorModeEngine = new MirrorModeEngine();
public BuildingTools()
{
@ -250,7 +250,7 @@ namespace BuildingTools
}
TweakPropertyInfo[] stats;
if (stat is null)
if (stat is null || stat.Length == 0)
{
stats = data.Stats;
}
@ -271,10 +271,10 @@ namespace BuildingTools
statInfo.max = value == 0 ? 1000 : value;
}
Logging.CommandLog($"{(stat is null ? "All stats" : $"Stat {stat}")} max changed to {(value == 0 ? 1000 : value)}");
Logging.CommandLog($"{(stat is null || stat.Length == 0 ? "All stats" : $"Stat {stat}")} max changed to {(value == 0 ? 1000 : value)} on {bl}");
}).Build();
_mirrorModeEngine.Init();
//_mirrorModeEngine.Init();
UI.Init();
new Harmony("BuildTools").PatchAll(Assembly.GetExecutingAssembly());
@ -335,7 +335,7 @@ namespace BuildingTools
$"- Rotation: {rot.x:F}° {rot.y:F}° {rot.z:F}°\n" +
$"- Velocity: {vel.x:F} {vel.y:F} {vel.z:F}\n" +
$"- Angular velocity: {ave.x:F} {ave.y:F} {ave.z:F}\n" +
$"- {(body.Static ? "Static body" : $"Mass: {body.Mass:F} center: {com.x:F} {com.y:F} {com.z:F}")}\n" +
$"- {(body.Static ? "Static body" : $"Center of mass: {com.x:F} {com.y:F} {com.z:F}")}\n" +
$"- Volume: {body.Volume:F}\n" +
$"- Chunk health: {body.CurrentHealth:F} / {body.InitialHealth:F} - Multiplier: {body.HealthMultiplier:F}\n" +
(cluster == null
@ -357,7 +357,6 @@ namespace BuildingTools
$"- Rotation: {rot.x:F}° {rot.y:F}° {rot.z:F}°\n" +
$"- Velocity: {vel.x:F} {vel.y:F} {vel.z:F}\n" +
$"- Angular velocity: {ave.x:F} {ave.y:F} {ave.z:F}\n" +
$"- Mass: {player.Mass:F}\n" +
$"- Health: {player.CurrentHealth:F} / {player.InitialHealth:F}";
}

View file

@ -9,20 +9,37 @@ namespace BuildingTools
{
public class UI
{
private static Label _speedLabel;
private static Label _speedLabel = new Label(new Rect(Screen.width - 200, 0, 200, 20), "Speed: ", "SpeedLabel")
{
Enabled = false
};
public static void Init()
{
Game.Simulate += (sender, args) =>
{
_speedLabel = new Label(new Rect(Screen.width - 200, 0, 200, 20), "Speed: ", "SpeedLabel");
Scheduler.Schedule(new Repeatable(
() => _speedLabel.Text = $"Speed: {math.length(Player.LocalPlayer?.Velocity ?? 0) * 3.6:F} km/h",
() => _speedLabel != null));
};
Game.Edit += (sender, args) => _speedLabel = null;
Game.Exit += (sender, args) => _speedLabel = null;
Game.Simulate += OnGameOnSimulate;
Game.Edit += OnGameOnEditOrExit;
Game.Exit += OnGameOnEditOrExit;
}
private static void OnGameOnSimulate(object sender, GameEventArgs args)
{
_speedLabel.Enabled = true;
Scheduler.Schedule(new Repeatable(UpdateTask, ShouldLabelBeUpdated));
}
private static void OnGameOnEditOrExit(object sender, GameEventArgs args)
{
_speedLabel.Enabled = false;
}
private static void UpdateTask()
{
_speedLabel.Text = $"Speed: {math.length(Player.LocalPlayer?.Velocity ?? 0) * 3.6:F} km/h";
}
private static bool ShouldLabelBeUpdated()
{
return _speedLabel.Enabled;
}
}
}