2using System.Collections.Generic;
4using System.Reflection;
5using System.Diagnostics;
9using Microsoft.Xna.Framework;
10using Microsoft.Xna.Framework.Input;
11using Microsoft.Xna.Framework.Graphics;
14using System.Runtime.CompilerServices;
15[assembly: IgnoresAccessChecksTo(
"Barotrauma")]
16[assembly: IgnoresAccessChecksTo(
"DedicatedServer")]
17[assembly: IgnoresAccessChecksTo(
"BarotraumaCore")]
24 public partial class CUI
26 public static Vector2 GameScreenSize =>
new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
27 public static Rectangle GameScreenRect =>
new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
30 private static string modDir;
47 public static bool UseLua {
get;
set; } =
true;
53 private static string assetsPath;
63 PalettesPath = Path.Combine(value,
@"Palettes");
66 public static string CUITexturePath =
"CUI.png";
67 public static string PalettesPath {
get;
set; }
102 public static CUILuaRegistrar LuaRegistrar =>
Instance?.luaRegistrar;
107 set => FocusResolver.FocusedCUIComponent = value;
126 get => hookIdentifier;
129 hookIdentifier = value?.Replace(
' ',
'_');
132 private static string hookIdentifier;
133 public static string CUIHookID => $
"CrabUI.{HookIdentifier}";
134 public static Harmony harmony;
135 public static Random Random =
new Random();
145 public static bool Disposed {
get;
set; } =
true;
146 public static event Action<TextInputEventArgs> OnWindowTextInput;
147 public static event Action<TextInputEventArgs> OnWindowKeyDown;
151 public static event Action OnPauseMenuToggled;
152 public static void InvokeOnPauseMenuToggled() => OnPauseMenuToggled?.Invoke();
154 public static bool InputBlockingMenuOpen
158 if (IsBlockingPredicates ==
null)
return false;
159 return IsBlockingPredicates.Any(p => p());
162 public static List<Func<bool>> IsBlockingPredicates =>
Instance?.isBlockingPredicates;
163 private List<Func<bool>> isBlockingPredicates =
new List<Func<bool>>();
178 private CUIFocusResolver focusResolver =
new CUIFocusResolver();
179 private CUILuaRegistrar luaRegistrar =
new CUILuaRegistrar();
181 public static void ReEmitWindowTextInput(
object sender, TextInputEventArgs e) => OnWindowTextInput?.Invoke(e);
182 public static void ReEmitWindowKeyDown(
object sender, TextInputEventArgs e) => OnWindowKeyDown?.Invoke(e);
186 private void CreateMains()
198 CUIDebug.Log($
"CUI.Initialize {HookIdentifier} Instance:[{Instance?.GetHashCode()}] UserCount:{UserCount}", Color.Lime);
201 GhostDetector.Activate();
203 HookIdentifier ??= Assembly.GetCallingAssembly().GetName().Name ??
"";
207 Stopwatch sw = Stopwatch.StartNew();
208 if (
HookIdentifier ==
null ||
HookIdentifier ==
"")
CUI.Warning($
"Warning: CUI.HookIdentifier is not set, this mod may conflict with other mods that use CUI");
216 GameMain.Instance.Window.TextInput += ReEmitWindowTextInput;
217 GameMain.Instance.Window.KeyDown += ReEmitWindowKeyDown;
219 CUIDebug.Log($
"CUI.OnInit?.Invoke took {sw.ElapsedMilliseconds}ms");
223 harmony =
new Harmony(CUIHookID);
225 CUIDebug.Log($
"CUI.PatchAll took {sw.ElapsedMilliseconds}ms");
231 LuaRegistrar.Register();
232 CUIDebug.Log($
"CUI.LuaRegistrar.Register took {sw.ElapsedMilliseconds}ms");
237 CUIDebug.Log($
"CUI.Initialized {HookIdentifier} Instance:[{Instance?.GetHashCode()}] UserCount:{UserCount}", Color.Lime);
240 public static void OnLoadCompleted()
252 GhostDetector.Deactivate();
253 CUIDebug.Log($
"CUI.Dispose {HookIdentifier} Instance:[{Instance?.GetHashCode()}] UserCount:{UserCount}", Color.Lime);
261 harmony.UnpatchAll();
264 CUIDebugEventComponent.CapturedIDs.Clear();
268 Instance.isBlockingPredicates.Clear();
271 LuaRegistrar.Deregister();
276 CUIDebug.
Log($
"CUI.Disposed {HookIdentifier} Instance:[{Instance?.GetHashCode()}] UserCount:{UserCount}", Color.Lime);
279 GameMain.Instance.Window.TextInput -= ReEmitWindowTextInput;
280 GameMain.Instance.Window.KeyDown -= ReEmitWindowKeyDown;
288 internal static void InitStatic()
293 CUIReflection.InitStatic();
294 CUIMultiModResolver.InitStatic();
295 CUIPalette.InitStatic();
297 CUIMenu.InitStatic();
299 CUITypeMetaData.InitStatic();
300 CUIStyleLoader.InitStatic();
301 AttachedItems.InitStatic();
WIP, can animate any property on any object Can run back and forth in [0..1] interval and interpolate...
Base class for all components.
In fact a static class managing static things.
static Action OnDispose
Called on last Dispose.
static int UserCount
In theory multiple mods could use same CUI instance, i clean it up when UserCount drops to 0.
static bool Debug
This affects logging.
static string HookIdentifier
It's used as harmony id and lua hooks id, it's deduced automatically from calling assembly name It'...
static Action OnInit
Called on first Initialize.
static CUIMainComponent TopMain
Orchestrates Drawing and updates, there could be only one CUI.TopMain is located above vanilla GUI.
static CUITextureManager TextureManager
Safe texture manager </summary.
static void Dispose()
Should be called in IAssemblyPlugin.Dispose.
static string PGNAssets
If set CUI will also check this folder when loading textures.
static string AssetsPath
Path to assets folder with all CUI stuff.
static string ModDir
Root folder of the mod, used to deduce lua folder location.
static CUIMainComponent Main
Orchestrates Drawing and updates, there could be only one CUI.Main is located under vanilla GUI.
static string LuaFolder
Should point to lua folder, if you want lua types file.
static void Log(object msg, Color? color=null, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
Prints a message to console.
static bool UseCursedPatches
If true other compiled mods that use CUI will break But if false then you'll have to setup hooks with...
static CUI Instance
A singleton.
static CUIFocusResolver FocusResolver
Adapter to vanilla focus system, don't use.
static bool UseLua
If false CUI won't waste time on registering lua types and creating types file.
static void Initialize()
Should be called in IAssemblyPlugin.Initialize.
Class containing a few interpolate functions for CUIAnimation.
Orchestrating drawing and updating of it's children Also a CUIComponent, but it's draw and update m...
Swipable and zoomable plane Allows you to place components in a plane and connect them with lines l...
Class for loading textures without duplicates Also disposes all loaded textures automatically.