CrabUI
Loading...
Searching...
No Matches
CrabUI.CUI Class Reference

In fact a static class managing static things. More...

Static Public Member Functions

static void InvokeOnPauseMenuToggled ()
 
static void ReEmitWindowTextInput (object sender, TextInputEventArgs e)
 
static void ReEmitWindowKeyDown (object sender, TextInputEventArgs e)
 
static void Initialize ()
 Should be called in IAssemblyPlugin.Initialize.
 
static void OnLoadCompleted ()
 
static void Dispose ()
 Should be called in IAssemblyPlugin.Dispose.
 
static void CUIDebug_Command (string[] args)
 
static void CUIDebugProps_Command (string[] args)
 
static void CUIMG_Command (string[] args)
 
static void CUIDrawOrder_Command (string[] args)
 
static void CUIPrintTree_Command (string[] args)
 
static void PrintSprites_Command (string[] args)
 
static string WrapInColor (object msg, string color)
 $"‖color:{color}‖{msg}‖end‖"
 
static string ArrayToString (IEnumerable< object > array)
 Serializes the array.
 
static void Log (object msg, Color? color=null, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
 Prints a message to console.
 
static void Warning (object msg, Color? color=null, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
 
static string GetCallerFolderPath ([CallerFilePath] string source="")
 xd
 
static void Info (object msg, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
 Prints debug message with source path Works only if debug is true.
 
static void CheckOtherPatches (string msg="")
 
static void CheckPatches (string typeName, string methodName)
 
static void GUI_InputBlockingMenuOpen_Postfix (ref bool __result)
 
static void GUI_TogglePauseMenu_Postfix ()
 
static CUIComponent Create (string componentName)
 Just an experimant Creates empty CUIComponent from class name.
 
static void PrintColors_Command (string[] args)
 
static void CUICreateLuaTypesFile_Command (string[] args)
 
static void CUICreatePalette_Command (string[] args)
 
static void CUICreatePaletteSet_Command (string[] args)
 
static void CUILoadPaletteSet_Command (string[] args)
 
static void PrintKeysCommand (string[] args)
 
static void PaletteDemo_Command (string[] args)
 
static void Palette_Command (string[] args)
 
static void DrawTexture (SpriteBatch sb, CUIRect cuirect, Texture2D texture, Color cl, CUISpriteDrawMode drawMode=CUISpriteDrawMode.Resize)
 
static void DrawRectangle (SpriteBatch sb, CUIRect cuirect, Color cl, CUISprite sprite, float depth=0.0f)
 
static void DrawBorders (SpriteBatch sb, CUIComponent component, float depth=0.0f)
 
static void Error (object msg, int maxPrints=1, int tolerate=5, bool silent=false)
 

Static Public Attributes

static string CUITexturePath = "CUI.png"
 
static CUI Instance
 A singleton.
 
static bool Debug
 This affects logging.
 
static Harmony harmony
 
static Random Random = new Random()
 
static int UserCount = 0
 In theory multiple mods could use same CUI instance, i clean it up when UserCount drops to 0.
 
const float Pi2 = (float)(Math.PI / 2.0)
 
static SamplerState NoSmoothing
 
static Dictionary< string, int > Errors = new()
 

Properties

static Vector2 GameScreenSize [get]
 
static Rectangle GameScreenRect [get]
 
static string ModDir [get, set]
 Root folder of the mod, used to deduce lua folder location.
 
static bool UseLua = true [get, set]
 If false CUI won't waste time on registering lua types and creating types file.
 
static string LuaFolder [get, set]
 Should point to lua folder, if you want lua types file.
 
static string AssetsPath [get, set]
 Path to assets folder with all CUI stuff.
 
static string PalettesPath [get, set]
 
static string PGNAssets [get, set]
 If set CUI will also check this folder when loading textures.
 
static CUIMainComponent Main [get]
 Orchestrates Drawing and updates, there could be only one CUI.Main is located under vanilla GUI.
 
static CUIMainComponent TopMain [get]
 Orchestrates Drawing and updates, there could be only one CUI.TopMain is located above vanilla GUI.
 
static CUIInput Input [get]
 Snapshot of mouse and keyboard state.
 
static CUITextureManager TextureManager [get]
 Safe texture manager </summary.
 
static CUIFocusResolver FocusResolver [get]
 Adapter to vanilla focus system, don't use.
 
static CUILuaRegistrar LuaRegistrar [get]
 
static CUIComponent FocusedComponent [get, set]
 
static bool UseCursedPatches = true [get, set]
 If true other compiled mods that use CUI will break But if false then you'll have to setup hooks with lua or separate compiled plugin.
 
static string HookIdentifier [get, set]
 It's used as harmony id and lua hooks id, it's deduced automatically from calling assembly name
It's should be unique per mod or there will be conflicts
You can set it to any string if you want.
 
static string CUIHookID [get]
 
static bool Disposed = true [get, set]
 
static bool InputBlockingMenuOpen [get]
 
static List< Func< bool > > IsBlockingPredicates [get]
 

Events

static Action OnInit
 Called on first Initialize.
 
static Action OnDispose
 Called on last Dispose.
 
static Action< TextInputEventArgs > OnWindowTextInput
 
static Action< TextInputEventArgs > OnWindowKeyDown
 
static Action OnPauseMenuToggled
 

Detailed Description

In fact a static class managing static things.

Definition at line 15 of file CUIErrors.cs.

Member Function Documentation

◆ ArrayToString()

static string CrabUI.CUI.ArrayToString ( IEnumerable< object > array)
static

Serializes the array.

Definition at line 29 of file CUI Logging.cs.

30 {
31 return $"[{String.Join(", ", array.Select(o => o.ToString()))}]";
32 }

◆ CheckOtherPatches()

static void CrabUI.CUI.CheckOtherPatches ( string msg = "")
static

Definition at line 20 of file CUI Patches.cs.

21 {
22 CUI.Log(msg);
23 CUI.Log($"Harmony.GetAllPatchedMethods:", Color.Lime);
24 foreach (MethodBase mb in Harmony.GetAllPatchedMethods())
25 {
26 Patches patches = Harmony.GetPatchInfo(mb);
27
28 if (patches.Prefixes.Count() > 0 || patches.Postfixes.Count() > 0)
29 {
30 CUI.Log($"{mb.DeclaringType}.{mb.Name}:");
31 if (patches.Prefixes.Count() > 0)
32 {
33 CUI.Log($" Prefixes:");
34 foreach (Patch patch in patches.Prefixes) { CUI.Log($" {patch.owner}"); }
35 }
36
37 if (patches.Postfixes.Count() > 0)
38 {
39 CUI.Log($" Postfixes:");
40 foreach (Patch patch in patches.Postfixes) { CUI.Log($" {patch.owner}"); }
41 }
42 }
43 }
44 }

◆ CheckPatches()

static void CrabUI.CUI.CheckPatches ( string typeName,
string methodName )
static

Definition at line 46 of file CUI Patches.cs.

47 {
48 CUI.Log($"Harmony.GetAllPatchedMethods:", Color.Lime);
49 foreach (MethodBase mb in Harmony.GetAllPatchedMethods())
50 {
51 if (
52 !string.Equals(typeName, mb.DeclaringType.Name, StringComparison.OrdinalIgnoreCase) ||
53 !string.Equals(methodName, mb.Name, StringComparison.OrdinalIgnoreCase)
54 ) continue;
55
56 Patches patches = Harmony.GetPatchInfo(mb);
57
58 if (patches.Prefixes.Count() > 0 || patches.Postfixes.Count() > 0)
59 {
60 CUI.Log($"{mb.DeclaringType}.{mb.Name}:");
61 if (patches.Prefixes.Count() > 0)
62 {
63 CUI.Log($" Prefixes:");
64 foreach (Patch patch in patches.Prefixes) { CUI.Log($" {patch.owner}"); }
65 }
66
67 if (patches.Postfixes.Count() > 0)
68 {
69 CUI.Log($" Postfixes:");
70 foreach (Patch patch in patches.Postfixes) { CUI.Log($" {patch.owner}"); }
71 }
72 }
73 }
74 }

◆ Create()

static CUIComponent CrabUI.CUI.Create ( string componentName)
static

Just an experimant Creates empty CUIComponent from class name.

Parameters
componentName
Returns

Definition at line 24 of file CUIBuilder.cs.

25 {
26 return (CUIComponent)Activator.CreateInstance(CUIReflection.GetComponentTypeByName(componentName));
27 }

◆ CUICreateLuaTypesFile_Command()

static void CrabUI.CUI.CUICreateLuaTypesFile_Command ( string[] args)
static

Definition at line 50 of file CUICommands.cs.

51 {
52 CUI.LuaRegistrar.ConstructLuaStaticsFile();
53 }

◆ CUICreatePalette_Command()

static void CrabUI.CUI.CUICreatePalette_Command ( string[] args)
static

Definition at line 56 of file CUICommands.cs.

57 {
58 string name = args.ElementAtOrDefault(0);
59 Color colorA = CUIExtensions.ParseColor((args.ElementAtOrDefault(1) ?? "white"));
60 Color colorB = CUIExtensions.ParseColor((args.ElementAtOrDefault(2) ?? "black"));
61 CUIPalette palette = CUIPalette.CreatePaletteFromColors(name, colorA, colorB);
62 CUIPalette.Primary = palette;
63 }

◆ CUICreatePaletteSet_Command()

static void CrabUI.CUI.CUICreatePaletteSet_Command ( string[] args)
static

Definition at line 65 of file CUICommands.cs.

66 {
67 CUIPalette.SaveSet(
68 args.ElementAtOrDefault(0),
69 args.ElementAtOrDefault(1),
70 args.ElementAtOrDefault(2),
71 args.ElementAtOrDefault(3),
72 args.ElementAtOrDefault(4)
73 );
74 }

◆ CUIDebug_Command()

static void CrabUI.CUI.CUIDebug_Command ( string[] args)
static

Definition at line 31 of file Debug Commands.cs.

32 {
33 if (CUIDebugWindow.Main == null) CUIDebugWindow.Open();
34 else CUIDebugWindow.Close();
35 }

◆ CUIDebugProps_Command()

static void CrabUI.CUI.CUIDebugProps_Command ( string[] args)
static

Definition at line 37 of file Debug Commands.cs.

38 {
39 if (CUIPropsDebug.Opened) CUI.Log($"Already opened");
40 else CUIPropsDebug.Open();
41 }

◆ CUIDrawOrder_Command()

static void CrabUI.CUI.CUIDrawOrder_Command ( string[] args)
static

Definition at line 44 of file Debug Commands.cs.

45 {
46 foreach (CUIComponent c in CUI.Main.Flat) { CUI.Log(c); }
47 }

◆ CUILoadPaletteSet_Command()

static void CrabUI.CUI.CUILoadPaletteSet_Command ( string[] args)
static

Definition at line 76 of file CUICommands.cs.

77 {
78 CUIPalette.LoadSet(Path.Combine(CUIPalette.PaletteSetsPath, args.ElementAtOrDefault(0)));
79 }

◆ CUIPrintTree_Command()

static void CrabUI.CUI.CUIPrintTree_Command ( string[] args)
static

Definition at line 49 of file Debug Commands.cs.

50 {
51 CUI.Main?.PrintTree();
52 CUI.TopMain?.PrintTree();
53 }

◆ Dispose()

static void CrabUI.CUI.Dispose ( )
static

Should be called in IAssemblyPlugin.Dispose.

Definition at line 250 of file CUI.cs.

251 {
252 GhostDetector.Deactivate();
253 CUIDebug.Log($"CUI.Dispose {HookIdentifier} Instance:[{Instance?.GetHashCode()}] UserCount:{UserCount}", Color.Lime);
254
255 UserCount--;
256
257 if (UserCount <= 0)
258 {
259 RemoveCommands();
260 // harmony.UnpatchAll(harmony.Id);
261 harmony.UnpatchAll();
262
263 TextureManager.Dispose();
264 CUIDebugEventComponent.CapturedIDs.Clear();
265 OnDispose?.Invoke();
266 Disposed = true;
267
268 Instance.isBlockingPredicates.Clear();
269 Errors.Clear();
270
271 LuaRegistrar.Deregister();
272
273 Instance = null;
274 UserCount = 0;
275
276 CUIDebug.Log($"CUI.Disposed {HookIdentifier} Instance:[{Instance?.GetHashCode()}] UserCount:{UserCount}", Color.Lime);
277 }
278
279 GameMain.Instance.Window.TextInput -= ReEmitWindowTextInput;
280 GameMain.Instance.Window.KeyDown -= ReEmitWindowKeyDown;
281 //GameMain.Instance.Window.KeyUp -= ReEmitWindowKeyUp;
282 }
static Action OnDispose
Called on last Dispose.
Definition CUI.cs:144
static int UserCount
In theory multiple mods could use same CUI instance, i clean it up when UserCount drops to 0.
Definition CUI.cs:168
static CUITextureManager TextureManager
Safe texture manager </summary.
Definition CUI.cs:97
static void Log(object msg, Color? color=null, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
Prints a message to console.
static CUI Instance
A singleton.
Definition CUI.cs:79

◆ DrawBorders()

static void CrabUI.CUI.DrawBorders ( SpriteBatch sb,
CUIComponent component,
float depth = 0::0f )
static

Definition at line 72 of file CUIDrawing.cs.

73 {
74 Texture2D texture = component.BorderSprite.Texture;
75 Rectangle sourceRect = texture.Bounds;
76
77 Rectangle targetRect;
78 Color cl;
79 float rotation = 0.0f;
80 float thickness = 1.0f;
81 bool visible = false;
82
83 // Right
84 visible = component.RigthBorder?.Visible ?? component.Border?.Visible ?? false;
85 thickness = component.RigthBorder?.Thickness ?? component.Border?.Thickness ?? 0;
86 cl = component.RigthBorder?.Color ?? component.Border?.Color ?? Color.Transparent;
87 targetRect = CUIRect.CreateRect(
88 component.Real.Left + component.Real.Width,
89 component.Real.Top,
90 component.Real.Height,
91 thickness
92 );
93 sourceRect = CUIRect.CreateRect(
94 0, 0,
95 targetRect.Width, texture.Height
96 );
97 rotation = Pi2;
98 sb.Draw(texture, targetRect, sourceRect, cl, rotation, Vector2.Zero, SpriteEffects.None, depth);
99
100 //Left
101 visible = component.LeftBorder?.Visible ?? component.Border?.Visible ?? false;
102 thickness = component.LeftBorder?.Thickness ?? component.Border?.Thickness ?? 0;
103 cl = component.LeftBorder?.Color ?? component.Border?.Color ?? Color.Transparent;
104 targetRect = CUIRect.CreateRect(
105 component.Real.Left + thickness,
106 component.Real.Top,
107 component.Real.Height,
108 thickness
109 );
110 sourceRect = CUIRect.CreateRect(
111 0, 0,
112 targetRect.Width, texture.Height
113 );
114 rotation = Pi2;
115 sb.Draw(texture, targetRect, sourceRect, cl, rotation, Vector2.Zero, SpriteEffects.FlipVertically, depth);
116
117
118 //Top
119 visible = component.TopBorder?.Visible ?? component.Border?.Visible ?? false;
120 thickness = component.TopBorder?.Thickness ?? component.Border?.Thickness ?? 0;
121 cl = component.TopBorder?.Color ?? component.Border?.Color ?? Color.Transparent;
122 targetRect = CUIRect.CreateRect(
123 component.Real.Left,
124 component.Real.Top,
125 component.Real.Width,
126 thickness
127 );
128 sourceRect = CUIRect.CreateRect(
129 0, 0,
130 targetRect.Width, texture.Height
131 );
132 rotation = 0.0f;
133 sb.Draw(texture, targetRect, sourceRect, cl, rotation, Vector2.Zero, SpriteEffects.None, depth);
134
135
136
137 //Bottom
138 visible = component.BottomBorder?.Visible ?? component.Border?.Visible ?? false;
139 thickness = component.BottomBorder?.Thickness ?? component.Border?.Thickness ?? 0;
140 cl = component.BottomBorder?.Color ?? component.Border?.Color ?? Color.Transparent;
141 targetRect = CUIRect.CreateRect(
142 component.Real.Left,
143 component.Real.Bottom - thickness,
144 component.Real.Width,
145 thickness
146 );
147 sourceRect = CUIRect.CreateRect(
148 0, 0,
149 targetRect.Width, texture.Height
150 );
151 rotation = 0;
152 sb.Draw(texture, targetRect, sourceRect, cl, rotation, Vector2.Zero, SpriteEffects.FlipVertically, depth);
153
154
155 }

◆ DrawRectangle()

static void CrabUI.CUI.DrawRectangle ( SpriteBatch sb,
CUIRect cuirect,
Color cl,
CUISprite sprite,
float depth = 0::0f )
static

Definition at line 47 of file CUIDrawing.cs.

48 {
49 Rectangle sourceRect = sprite.DrawMode switch
50 {
51 CUISpriteDrawMode.Resize => sprite.SourceRect,
52 CUISpriteDrawMode.Wrap => new Rectangle(0, 0, (int)cuirect.Width, (int)cuirect.Height),
53 CUISpriteDrawMode.Static => cuirect.Box,
54 CUISpriteDrawMode.StaticDeep => cuirect.Zoom(0.9f),
55 _ => sprite.SourceRect,
56 };
57
58 Rectangle rect = new Rectangle(
59 (int)(cuirect.Left + sprite.Offset.X * cuirect.Width),
60 (int)(cuirect.Top + sprite.Offset.Y * cuirect.Height),
61 (int)(cuirect.Width),
62 (int)(cuirect.Height)
63 );
64
65 //rect = cuirect.Box;
66
67 sb.Draw(sprite.Texture, rect, sourceRect, cl, sprite.Rotation, sprite.Origin, sprite.Effects, depth);
68 }

◆ DrawTexture()

static void CrabUI.CUI.DrawTexture ( SpriteBatch sb,
CUIRect cuirect,
Texture2D texture,
Color cl,
CUISpriteDrawMode drawMode = CUISpriteDrawMode::Resize )
static

Definition at line 34 of file CUIDrawing.cs.

35 {
36 Rectangle sourceRect = drawMode switch
37 {
38 CUISpriteDrawMode.Resize => texture.Bounds,
39 CUISpriteDrawMode.Wrap => new Rectangle(0, 0, (int)cuirect.Width, (int)cuirect.Height),
40 CUISpriteDrawMode.Static => cuirect.Box,
41 CUISpriteDrawMode.StaticDeep => cuirect.Zoom(0.9f),
42 _ => texture.Bounds,
43 };
44
45 sb.Draw(texture, cuirect.Box, sourceRect, cl, 0.0f, Vector2.Zero, SpriteEffects.None, 0);
46 }

◆ Error()

static void CrabUI.CUI.Error ( object msg,
int maxPrints = 1,
int tolerate = 5,
bool silent = false )
static

Definition at line 18 of file CUIErrors.cs.

19 {
20 string s = $"{msg}";
21 if (!Errors.ContainsKey(s)) Errors[s] = 1;
22 else Errors[s] = Errors[s] + 1;
23 if (silent) return;
24 if (tolerate < Errors[s] && Errors[s] <= maxPrints) Log($"CUI: {s} x{Errors[s]}", Color.Orange);
25 }

◆ GetCallerFolderPath()

static string CrabUI.CUI.GetCallerFolderPath ( [CallerFilePath] string source = "")
static

xd

Parameters
sourceThis should be injected by compiler, don't set

◆ GUI_InputBlockingMenuOpen_Postfix()

static void CrabUI.CUI.GUI_InputBlockingMenuOpen_Postfix ( ref bool __result)
static

Definition at line 262 of file CUI Patches.cs.

263 {
264 if (GhostDetector.Check()) return;
265 __result = __result || CUI.InputBlockingMenuOpen;
266 }

◆ GUI_TogglePauseMenu_Postfix()

static void CrabUI.CUI.GUI_TogglePauseMenu_Postfix ( )
static

Definition at line 268 of file CUI Patches.cs.

269 {
270 if (GhostDetector.Check()) return;
271 try
272 {
273 if (GUI.PauseMenu != null)
274 {
275 GUIFrame frame = GUI.PauseMenu;
276 GUIComponent pauseMenuInner = frame.GetChild(1);
277 GUIComponent list = frame.GetChild(1).GetChild(0);
278 GUIButton resumeButton = (GUIButton)list.GetChild(0);
279
280 GUIButton.OnClickedHandler oldHandler = resumeButton.OnClicked;
281
282 resumeButton.OnClicked = (GUIButton button, object obj) =>
283 {
284 bool guh = oldHandler(button, obj);
285 CUI.InvokeOnPauseMenuToggled();
286 return guh;
287 };
288 }
289 }
290 catch (Exception e) { CUI.Warning(e); }
291
292 CUI.InvokeOnPauseMenuToggled();
293 }

◆ Info()

static void CrabUI.CUI.Info ( object msg,
[CallerFilePath] string source = "",
[CallerLineNumber] int lineNumber = 0 )
static

Prints debug message with source path Works only if debug is true.

Definition at line 66 of file CUI Logging.cs.

67 {
68 if (Debug == true)
69 {
70 var fi = new FileInfo(source);
71
72 Log($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", Color.Yellow * 0.5f);
73 Log(msg, Color.Yellow);
74 }
75 }
static bool Debug
This affects logging.
Definition CUI.cs:113

◆ Initialize()

static void CrabUI.CUI.Initialize ( )
static

Should be called in IAssemblyPlugin.Initialize.

Definition at line 196 of file CUI.cs.

197 {
198 CUIDebug.Log($"CUI.Initialize {HookIdentifier} Instance:[{Instance?.GetHashCode()}] UserCount:{UserCount}", Color.Lime);
199 if (Instance == null)
200 {
201 GhostDetector.Activate();
202 Disposed = false;
203 HookIdentifier ??= Assembly.GetCallingAssembly().GetName().Name ?? "";
204
205 Instance = new CUI();
206
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");
209
210 InitStatic();
211 // this should init only static stuff that doesn't depend on instance
212 OnInit?.Invoke();
213
214 Instance.CreateMains();
215
216 GameMain.Instance.Window.TextInput += ReEmitWindowTextInput;
217 GameMain.Instance.Window.KeyDown += ReEmitWindowKeyDown;
218 //GameMain.Instance.Window.KeyUp += ReEmitWindowKeyUp;
219 CUIDebug.Log($"CUI.OnInit?.Invoke took {sw.ElapsedMilliseconds}ms");
220
221 sw.Restart();
222
223 harmony = new Harmony(CUIHookID);
224 PatchAll();
225 CUIDebug.Log($"CUI.PatchAll took {sw.ElapsedMilliseconds}ms");
226
227 AddCommands();
228 AddDebugCommands();
229
230 sw.Restart();
231 LuaRegistrar.Register();
232 CUIDebug.Log($"CUI.LuaRegistrar.Register took {sw.ElapsedMilliseconds}ms");
233 }
234
235 UserCount++;
236
237 CUIDebug.Log($"CUI.Initialized {HookIdentifier} Instance:[{Instance?.GetHashCode()}] UserCount:{UserCount}", Color.Lime);
238 }
static string HookIdentifier
It's used as harmony id and lua hooks id, it's deduced automatically from calling assembly name It'...
Definition CUI.cs:125
static Action OnInit
Called on first Initialize.
Definition CUI.cs:140

◆ Log()

static void CrabUI.CUI.Log ( object msg,
Color? color = null,
[CallerFilePath] string source = "",
[CallerLineNumber] int lineNumber = 0 )
static

Prints a message to console.

Definition at line 37 of file CUI Logging.cs.

38 {
39 color ??= Color.Cyan;
40
41 // var fi = new FileInfo(source);
42 // LuaCsLogger.LogMessage($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", color * 0.6f, color * 0.6f);
43
44 LuaCsLogger.LogMessage($"{msg ?? "null"}", color * 0.8f, color);
45 }

◆ OnLoadCompleted()

static void CrabUI.CUI.OnLoadCompleted ( )
static

Definition at line 240 of file CUI.cs.

241 {
242 //Idk doesn't work
243 //CUIMultiModResolver.FindOtherInputs();
244 }

◆ Palette_Command()

static void CrabUI.CUI.Palette_Command ( string[] args)
static

Definition at line 101 of file CUICommands.cs.

102 {
103 try
104 {
105 CUIPalette palette = CUIPalette.LoadedPalettes?.GetValueOrDefault(args.ElementAtOrDefault(0) ?? "");
106 if (palette != null) CUIPalette.Primary = palette;
107 }
108 catch (Exception e) { CUI.Warning(e); }
109 }

◆ PaletteDemo_Command()

static void CrabUI.CUI.PaletteDemo_Command ( string[] args)
static

Definition at line 96 of file CUICommands.cs.

97 {
98 try { CUIPalette.PaletteDemo(); } catch (Exception e) { CUI.Warning(e); }
99 }

◆ PrintColors_Command()

static void CrabUI.CUI.PrintColors_Command ( string[] args)
static

Definition at line 42 of file CUICommands.cs.

43 {
44 foreach (PropertyInfo prop in typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.Public))
45 {
46 CUI.Log($"{prop} {prop.GetValue(null)}", (Color)prop.GetValue(null));
47 }
48 }

◆ PrintKeysCommand()

static void CrabUI.CUI.PrintKeysCommand ( string[] args)
static

Definition at line 81 of file CUICommands.cs.

82 {
83 CUIDebug.PrintKeys = !CUIDebug.PrintKeys;
84
85 if (CUIDebug.PrintKeys)
86 {
87 var values = typeof(Keys).GetEnumValues();
88 foreach (var v in values)
89 {
90 Log($"{(int)v} {v}");
91 }
92 Log("---------------------------");
93 }
94 }

◆ PrintSprites_Command()

static void CrabUI.CUI.PrintSprites_Command ( string[] args)
static

Definition at line 55 of file Debug Commands.cs.

56 {
57 foreach (GUIComponentStyle style in GUIStyle.ComponentStyles)
58 {
59 CUI.Log($"{style.Name} {style.Sprites.Count}");
60 }
61 }

◆ Warning()

static void CrabUI.CUI.Warning ( object msg,
Color? color = null,
[CallerFilePath] string source = "",
[CallerLineNumber] int lineNumber = 0 )
static

Definition at line 47 of file CUI Logging.cs.

48 {
49 color ??= Color.Yellow;
50 // var fi = new FileInfo(source);
51 // LuaCsLogger.LogMessage($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", color * 0.6f, color * 0.6f);
52 LuaCsLogger.LogMessage($"{msg ?? "null"}", color * 0.8f, color);
53 }

◆ WrapInColor()

static string CrabUI.CUI.WrapInColor ( object msg,
string color )
static

$"‖color:{color}‖{msg}‖end‖"

Definition at line 20 of file CUI Logging.cs.

21 {
22 return $"‖color:{color}‖{msg}‖end‖";
23 }

Member Data Documentation

◆ CUITexturePath

string CrabUI.CUI.CUITexturePath = "CUI.png"
static

Definition at line 66 of file CUI.cs.

◆ Debug

bool CrabUI.CUI.Debug
static

This affects logging.

Definition at line 113 of file CUI.cs.

◆ Errors

Dictionary<string, int> CrabUI.CUI.Errors = new()
static

Definition at line 17 of file CUIErrors.cs.

◆ harmony

Harmony CrabUI.CUI.harmony
static

Definition at line 134 of file CUI.cs.

◆ Instance

CUI CrabUI.CUI.Instance
static

A singleton.

Definition at line 79 of file CUI.cs.

◆ NoSmoothing

SamplerState CrabUI.CUI.NoSmoothing
static
Initial value:
= new SamplerState()
{
Filter = TextureFilter.Point,
AddressU = TextureAddressMode.Clamp,
AddressV = TextureAddressMode.Clamp,
AddressW = TextureAddressMode.Clamp,
BorderColor = Color.White,
MaxAnisotropy = 4,
MaxMipLevel = 0,
MipMapLevelOfDetailBias = -0.8f,
ComparisonFunction = CompareFunction.Never,
FilterMode = TextureFilterMode.Default,
}

Definition at line 20 of file CUIDrawing.cs.

21 {
22 Filter = TextureFilter.Point,
23 AddressU = TextureAddressMode.Clamp,
24 AddressV = TextureAddressMode.Clamp,
25 AddressW = TextureAddressMode.Clamp,
26 BorderColor = Color.White,
27 MaxAnisotropy = 4,
28 MaxMipLevel = 0,
29 MipMapLevelOfDetailBias = -0.8f,
30 ComparisonFunction = CompareFunction.Never,
31 FilterMode = TextureFilterMode.Default,
32 };

◆ Pi2

const float CrabUI.CUI.Pi2 = (float)(Math.PI / 2.0)
static

Definition at line 17 of file CUIDrawing.cs.

◆ Random

Random CrabUI.CUI.Random = new Random()
static

Definition at line 135 of file CUI.cs.

◆ UserCount

int CrabUI.CUI.UserCount = 0
static

In theory multiple mods could use same CUI instance, i clean it up when UserCount drops to 0.

Definition at line 168 of file CUI.cs.

Property Documentation

◆ AssetsPath

string CrabUI.CUI.AssetsPath
staticgetset

Path to assets folder with all CUI stuff.

Definition at line 57 of file CUI.cs.

58 {
59 get => assetsPath;
60 set
61 {
62 assetsPath = value;
63 PalettesPath = Path.Combine(value, @"Palettes");
64 }
65 }

◆ CUIHookID

string CrabUI.CUI.CUIHookID
staticget

Definition at line 133 of file CUI.cs.

◆ Disposed

bool CrabUI.CUI.Disposed = true
staticgetset

Definition at line 145 of file CUI.cs.

145{ get; set; } = true;

◆ FocusedComponent

CUIComponent CrabUI.CUI.FocusedComponent
staticgetset

Definition at line 104 of file CUI.cs.

105 {
106 get => FocusResolver.FocusedCUIComponent;
107 set => FocusResolver.FocusedCUIComponent = value;
108 }
static CUIFocusResolver FocusResolver
Adapter to vanilla focus system, don't use.
Definition CUI.cs:101

◆ FocusResolver

CUIFocusResolver CrabUI.CUI.FocusResolver
staticget

Adapter to vanilla focus system, don't use.

Definition at line 101 of file CUI.cs.

◆ GameScreenRect

Rectangle CrabUI.CUI.GameScreenRect
staticget

Definition at line 27 of file CUI.cs.

◆ GameScreenSize

Vector2 CrabUI.CUI.GameScreenSize
staticget

Definition at line 26 of file CUI.cs.

◆ HookIdentifier

string CrabUI.CUI.HookIdentifier
staticgetset

It's used as harmony id and lua hooks id, it's deduced automatically from calling assembly name
It's should be unique per mod or there will be conflicts
You can set it to any string if you want.

Definition at line 124 of file CUI.cs.

125 {
126 get => hookIdentifier;
127 set
128 {
129 hookIdentifier = value?.Replace(' ', '_');
130 }
131 }

◆ Input

CUIInput CrabUI.CUI.Input
staticget

Snapshot of mouse and keyboard state.

Definition at line 93 of file CUI.cs.

◆ InputBlockingMenuOpen

bool CrabUI.CUI.InputBlockingMenuOpen
staticget

Definition at line 154 of file CUI.cs.

155 {
156 get
157 {
158 if (IsBlockingPredicates == null) return false;
159 return IsBlockingPredicates.Any(p => p());
160 }
161 }

◆ IsBlockingPredicates

List<Func<bool> > CrabUI.CUI.IsBlockingPredicates
staticget

Definition at line 162 of file CUI.cs.

◆ LuaFolder

string CrabUI.CUI.LuaFolder
staticgetset

Should point to lua folder, if you want lua types file.

Definition at line 51 of file CUI.cs.

51{ get; set; }

◆ LuaRegistrar

CUILuaRegistrar CrabUI.CUI.LuaRegistrar
staticget

Definition at line 102 of file CUI.cs.

◆ Main

CUIMainComponent CrabUI.CUI.Main
staticget

Orchestrates Drawing and updates, there could be only one CUI.Main is located under vanilla GUI.

Definition at line 84 of file CUI.cs.

◆ ModDir

string CrabUI.CUI.ModDir
staticgetset

Root folder of the mod, used to deduce lua folder location.

Definition at line 34 of file CUI.cs.

35 {
36 get => modDir;
37 set
38 {
39 modDir = value;
40 LuaFolder = Path.Combine(value, @"Lua");
41 }
42 }
static string LuaFolder
Should point to lua folder, if you want lua types file.
Definition CUI.cs:51

◆ PalettesPath

string CrabUI.CUI.PalettesPath
staticgetset

Definition at line 67 of file CUI.cs.

67{ get; set; }

◆ PGNAssets

string CrabUI.CUI.PGNAssets
staticgetset

If set CUI will also check this folder when loading textures.

Definition at line 74 of file CUI.cs.

74{ get; set; }

◆ TextureManager

CUITextureManager CrabUI.CUI.TextureManager
staticget

Safe texture manager </summary.

Definition at line 97 of file CUI.cs.

◆ TopMain

CUIMainComponent CrabUI.CUI.TopMain
staticget

Orchestrates Drawing and updates, there could be only one CUI.TopMain is located above vanilla GUI.

Definition at line 89 of file CUI.cs.

◆ UseCursedPatches

bool CrabUI.CUI.UseCursedPatches = true
staticgetset

If true other compiled mods that use CUI will break But if false then you'll have to setup hooks with lua or separate compiled plugin.

Definition at line 118 of file CUI.cs.

118{ get; set; } = true;

◆ UseLua

bool CrabUI.CUI.UseLua = true
staticgetset

If false CUI won't waste time on registering lua types and creating types file.

Definition at line 47 of file CUI.cs.

47{ get; set; } = true;

Event Documentation

◆ OnDispose

Action CrabUI.CUI.OnDispose
static

Called on last Dispose.

Definition at line 144 of file CUI.cs.

◆ OnInit

Action CrabUI.CUI.OnInit
static

Called on first Initialize.

Definition at line 140 of file CUI.cs.

◆ OnPauseMenuToggled

Action CrabUI.CUI.OnPauseMenuToggled
static

Definition at line 151 of file CUI.cs.

◆ OnWindowKeyDown

Action<TextInputEventArgs> CrabUI.CUI.OnWindowKeyDown
static

Definition at line 147 of file CUI.cs.

◆ OnWindowTextInput

Action<TextInputEventArgs> CrabUI.CUI.OnWindowTextInput
static

Definition at line 146 of file CUI.cs.


The documentation for this class was generated from the following files: