diff --git a/Torch.API/Plugins/ITorchPlugin.cs b/Torch.API/Plugins/ITorchPlugin.cs index 35a34df..fd7c83f 100644 --- a/Torch.API/Plugins/ITorchPlugin.cs +++ b/Torch.API/Plugins/ITorchPlugin.cs @@ -34,5 +34,22 @@ namespace Torch.API.Plugins /// This is called on the game thread after each tick. /// void Update(); + + /// + /// Plugin's enabled state. Mainly for UI niceness + /// + PluginState State { get; } + } + + public enum PluginState + { + NotInitialized, + DisabledError, + DisabledUser, + UpdateRequired, + UninstallRequested, + NotInstalled, + MissingDependency, + Enabled } } diff --git a/Torch.Server/ViewModels/PluginViewModel.cs b/Torch.Server/ViewModels/PluginViewModel.cs index dca7c27..561bfce 100644 --- a/Torch.Server/ViewModels/PluginViewModel.cs +++ b/Torch.Server/ViewModels/PluginViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -51,5 +52,55 @@ namespace Torch.Server.ViewModels this.Control.Resources.MergedDictionaries.Clear(); this.Control.Resources.MergedDictionaries.Add(dictionary); } + + public Brush Color + { + get { + switch (Plugin.State) + { + case PluginState.NotInitialized: + case PluginState.MissingDependency: + case PluginState.DisabledError: + return Brushes.Red; + case PluginState.UpdateRequired: + return Brushes.DodgerBlue; + case PluginState.UninstallRequested: + return Brushes.Gold; + case PluginState.NotInstalled: + case PluginState.DisabledUser: + return Brushes.Gray; + case PluginState.Enabled: + return Brushes.Transparent; + default: + throw new ArgumentOutOfRangeException(); + } + } + } + + public string ToolTip + { + get { switch (Plugin.State) + { + case PluginState.NotInitialized: + return "Error during load."; + case PluginState.DisabledError: + return "Disabled due to error on load."; + case PluginState.DisabledUser: + return "Disabled."; + case PluginState.UpdateRequired: + return "Update required."; + case PluginState.UninstallRequested: + return "Marked for uninstall."; + case PluginState.NotInstalled: + return "Not installed. Click 'Enable'"; + case PluginState.Enabled: + return string.Empty; + case PluginState.MissingDependency: + return "Dependency missing. Check the log."; + default: + throw new ArgumentOutOfRangeException(); + } + } + } } } diff --git a/Torch.Server/Views/PluginsControl.xaml b/Torch.Server/Views/PluginsControl.xaml index 8885eba..3232454 100644 --- a/Torch.Server/Views/PluginsControl.xaml +++ b/Torch.Server/Views/PluginsControl.xaml @@ -22,7 +22,7 @@ - + diff --git a/Torch/Managers/PatchManager/PatchContext.cs b/Torch/Managers/PatchManager/PatchContext.cs index a36225a..354c217 100644 --- a/Torch/Managers/PatchManager/PatchContext.cs +++ b/Torch/Managers/PatchManager/PatchContext.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using NLog; namespace Torch.Managers.PatchManager { @@ -10,6 +11,7 @@ namespace Torch.Managers.PatchManager public sealed class PatchContext { private readonly Dictionary _rewritePatterns = new Dictionary(); + private static readonly Logger Log = LogManager.GetCurrentClassLogger(); internal PatchContext() { diff --git a/Torch/TorchPluginBase.cs b/Torch/TorchPluginBase.cs index 64859d9..5e0b59f 100644 --- a/Torch/TorchPluginBase.cs +++ b/Torch/TorchPluginBase.cs @@ -28,6 +28,7 @@ namespace Torch } public virtual void Update() { } + public PluginState State { get; } public virtual void Dispose() { } }