diff --git a/BuildingTools/BuildingTools.cs b/BuildingTools/BuildingTools.cs index c787d25..0af81ab 100644 --- a/BuildingTools/BuildingTools.cs +++ b/BuildingTools/BuildingTools.cs @@ -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}"; } diff --git a/BuildingTools/UI.cs b/BuildingTools/UI.cs index 560993d..ed47bad 100644 --- a/BuildingTools/UI.cs +++ b/BuildingTools/UI.cs @@ -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; } } } \ No newline at end of file