Added error overlay which is used to display errors in a more user friendly way, currently only used if the CSharp compilation fails
This commit is contained in:
@@ -862,6 +862,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Screen.Selected.AddToGUIUpdateList();
|
Screen.Selected.AddToGUIUpdateList();
|
||||||
|
|
||||||
|
LuaCsLogger.AddToGUIUpdateList();
|
||||||
|
|
||||||
Client?.AddToGUIUpdateList();
|
Client?.AddToGUIUpdateList();
|
||||||
|
|
||||||
SubmarinePreview.AddToGUIUpdateList();
|
SubmarinePreview.AddToGUIUpdateList();
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
|
namespace Barotrauma
|
||||||
|
{
|
||||||
|
partial class LuaCsLogger
|
||||||
|
{
|
||||||
|
private static GUIFrame overlayFrame;
|
||||||
|
private static GUITextBlock textBlock;
|
||||||
|
private static double showTimer = 0;
|
||||||
|
|
||||||
|
private static void CreateOverlay(string message)
|
||||||
|
{
|
||||||
|
overlayFrame = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.03f), null), null, new Color(50, 50, 50, 100))
|
||||||
|
{
|
||||||
|
CanBeFocused = false
|
||||||
|
};
|
||||||
|
|
||||||
|
GUILayoutGroup layout = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 0.8f), overlayFrame.RectTransform, Anchor.CenterLeft), false, Anchor.Center)
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
textBlock = new GUITextBlock(new RectTransform(new Vector2(1f, 0f), layout.RectTransform), message);
|
||||||
|
overlayFrame.RectTransform.MinSize = new Point((int)(textBlock.TextSize.X * 1.2), 0);
|
||||||
|
|
||||||
|
layout.Recalculate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddToGUIUpdateList()
|
||||||
|
{
|
||||||
|
if (overlayFrame != null && Timing.TotalTime <= showTimer)
|
||||||
|
{
|
||||||
|
overlayFrame.AddToGUIUpdateList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ShowErrorOverlay(string message, float time = 5f, float duration = 1.5f)
|
||||||
|
{
|
||||||
|
if (Timing.TotalTime <= showTimer)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateOverlay(message);
|
||||||
|
|
||||||
|
overlayFrame.Flash(Color.Red, duration, true);
|
||||||
|
showTimer = Timing.TotalTime + time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,6 +56,19 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Disalbe Error GUI Overlay")
|
||||||
|
{
|
||||||
|
Selected = GameMain.LuaCs.Config.DisableErrorGUIOverlay,
|
||||||
|
ToolTip = "",
|
||||||
|
OnSelected = (GUITickBox tick) =>
|
||||||
|
{
|
||||||
|
GameMain.LuaCs.Config.DisableErrorGUIOverlay = tick.Selected;
|
||||||
|
GameMain.LuaCs.UpdateConfig();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
new GUIButton(new RectTransform(new Vector2(1f, 0.1f), list.Content.RectTransform), $"Remove Client-Side LuaCs", style: "GUIButtonSmall")
|
new GUIButton(new RectTransform(new Vector2(1f, 0.1f), list.Content.RectTransform), $"Remove Client-Side LuaCs", style: "GUIButtonSmall")
|
||||||
{
|
{
|
||||||
ToolTip = "Remove Client-Side LuaCs.",
|
ToolTip = "Remove Client-Side LuaCs.",
|
||||||
|
|||||||
@@ -6,6 +6,14 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
partial class LuaCsSetup
|
partial class LuaCsSetup
|
||||||
{
|
{
|
||||||
|
public void AddToGUIUpdateList()
|
||||||
|
{
|
||||||
|
if (!GameMain.LuaCs.Config.DisableErrorGUIOverlay)
|
||||||
|
{
|
||||||
|
LuaCsLogger.AddToGUIUpdateList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void CheckInitialize()
|
public void CheckInitialize()
|
||||||
{
|
{
|
||||||
List<ContentPackage> csharpMods = new List<ContentPackage>();
|
List<ContentPackage> csharpMods = new List<ContentPackage>();
|
||||||
|
|||||||
@@ -167,6 +167,25 @@ namespace Barotrauma
|
|||||||
return syntaxTrees;
|
return syntaxTrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ContentPackage FindSourcePackage(Diagnostic diagnostic)
|
||||||
|
{
|
||||||
|
if (diagnostic.Location.SourceTree == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string path = diagnostic.Location.SourceTree.FilePath;
|
||||||
|
foreach (var package in ContentPackageManager.AllPackages)
|
||||||
|
{
|
||||||
|
if (Path.GetFullPath(path).StartsWith(Path.GetFullPath(package.Dir)))
|
||||||
|
{
|
||||||
|
return package;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Type> Compile()
|
public List<Type> Compile()
|
||||||
{
|
{
|
||||||
IEnumerable<SyntaxTree> syntaxTrees = ParseSources();
|
IEnumerable<SyntaxTree> syntaxTrees = ParseSources();
|
||||||
@@ -188,6 +207,13 @@ namespace Barotrauma
|
|||||||
foreach (Diagnostic diagnostic in failures)
|
foreach (Diagnostic diagnostic in failures)
|
||||||
{
|
{
|
||||||
errStr += $"\n{diagnostic}";
|
errStr += $"\n{diagnostic}";
|
||||||
|
#if CLIENT
|
||||||
|
ContentPackage package = FindSourcePackage(diagnostic);
|
||||||
|
if (package != null)
|
||||||
|
{
|
||||||
|
LuaCsLogger.ShowErrorOverlay($"{package.Name} {package.ModVersion} is causing compilation errors. Check debug console for more details.", 7f, 7f);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
LuaCsLogger.LogError(errStr, LuaCsMessageOrigin.CSharpMod);
|
LuaCsLogger.LogError(errStr, LuaCsMessageOrigin.CSharpMod);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,16 @@ namespace Barotrauma
|
|||||||
CSharpMod,
|
CSharpMod,
|
||||||
}
|
}
|
||||||
|
|
||||||
class LuaCsLogger
|
partial class LuaCsLogger
|
||||||
{
|
{
|
||||||
#if SERVER
|
#if SERVER
|
||||||
private const string LogPrefix = "SV";
|
private const string LogPrefix = "SV";
|
||||||
private const int NetMaxLength = 1024;
|
private const int NetMaxLength = 1024;
|
||||||
private const int NetMaxMessages = 60;
|
private const int NetMaxMessages = 60;
|
||||||
|
|
||||||
|
// This is used so its possible to call logging functions inside the serverLog
|
||||||
|
// hook without creating an infinite loop
|
||||||
|
private static bool lockLog = false;
|
||||||
#else
|
#else
|
||||||
private const string LogPrefix = "CL";
|
private const string LogPrefix = "CL";
|
||||||
#endif
|
#endif
|
||||||
@@ -94,10 +98,6 @@ namespace Barotrauma
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is used so its possible to call logging functions inside the serverLog
|
|
||||||
// hook without creating an infinite loop
|
|
||||||
private static bool lockLog = false;
|
|
||||||
|
|
||||||
public static void Log(string message, Color? color = null, ServerLog.MessageType messageType = ServerLog.MessageType.ServerMessage)
|
public static void Log(string message, Color? color = null, ServerLog.MessageType messageType = ServerLog.MessageType.ServerMessage)
|
||||||
{
|
{
|
||||||
MessageLogger?.Invoke(message);
|
MessageLogger?.Invoke(message);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace Barotrauma
|
|||||||
public bool ForceCsScripting = false;
|
public bool ForceCsScripting = false;
|
||||||
public bool TreatForcedModsAsNormal = false;
|
public bool TreatForcedModsAsNormal = false;
|
||||||
public bool PreferToUseWorkshopLuaSetup = false;
|
public bool PreferToUseWorkshopLuaSetup = false;
|
||||||
|
public bool DisableErrorGUIOverlay = false;
|
||||||
|
|
||||||
public LuaCsSetupConfig() { }
|
public LuaCsSetupConfig() { }
|
||||||
}
|
}
|
||||||
@@ -91,14 +92,13 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
Config = new LuaCsSetupConfig();
|
Config = new LuaCsSetupConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateConfig()
|
public void UpdateConfig()
|
||||||
{
|
{
|
||||||
FileStream file;
|
FileStream file;
|
||||||
if (!File.Exists(configFileName)) file = File.Create(configFileName);
|
if (!File.Exists(configFileName)) { file = File.Create(configFileName); }
|
||||||
else file = File.Open(configFileName, FileMode.Truncate, FileAccess.Write);
|
else { file = File.Open(configFileName, FileMode.Truncate, FileAccess.Write); }
|
||||||
LuaCsConfig.Save(file, Config);
|
LuaCsConfig.Save(file, Config);
|
||||||
file.Close();
|
file.Close();
|
||||||
}
|
}
|
||||||
@@ -365,17 +365,12 @@ namespace Barotrauma
|
|||||||
Stopwatch compilationTime = new Stopwatch();
|
Stopwatch compilationTime = new Stopwatch();
|
||||||
compilationTime.Start();
|
compilationTime.Start();
|
||||||
var modTypes = CsScriptLoader.Compile();
|
var modTypes = CsScriptLoader.Compile();
|
||||||
|
|
||||||
modTypes.ForEach(t =>
|
modTypes.ForEach(t =>
|
||||||
{
|
{
|
||||||
try
|
t.GetConstructor(new Type[] { })?.Invoke(null);
|
||||||
{
|
|
||||||
t.GetConstructor(new Type[] { })?.Invoke(null);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
LuaCsLogger.HandleException(ex, LuaCsMessageOrigin.CSharpMod);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
compilationTime.Stop();
|
compilationTime.Stop();
|
||||||
LuaCsLogger.LogMessage($"Took {compilationTime.ElapsedMilliseconds}ms to compile and run Cs Scripts.");
|
LuaCsLogger.LogMessage($"Took {compilationTime.ElapsedMilliseconds}ms to compile and run Cs Scripts.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user