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:
EvilFactory
2023-01-06 19:58:15 -03:00
parent 9fcab5ff60
commit 94c68b9fe6
7 changed files with 110 additions and 16 deletions
@@ -862,6 +862,8 @@ namespace Barotrauma
Screen.Selected.AddToGUIUpdateList();
LuaCsLogger.AddToGUIUpdateList();
Client?.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")
{
ToolTip = "Remove Client-Side LuaCs.",
@@ -6,6 +6,14 @@ namespace Barotrauma
{
partial class LuaCsSetup
{
public void AddToGUIUpdateList()
{
if (!GameMain.LuaCs.Config.DisableErrorGUIOverlay)
{
LuaCsLogger.AddToGUIUpdateList();
}
}
public void CheckInitialize()
{
List<ContentPackage> csharpMods = new List<ContentPackage>();