CrabUI
Loading...
Searching...
No Matches
CUICommands.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Diagnostics;
6using System.Runtime.CompilerServices;
7using System.IO;
8
9using Barotrauma;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Input;
12using Microsoft.Xna.Framework.Graphics;
13using HarmonyLib;
14
15namespace CrabUI
16{
17 public partial class CUI
18 {
19 internal static List<DebugConsole.Command> AddedCommands = new List<DebugConsole.Command>();
20 internal static void AddCommands()
21 {
22 AddedCommands.Add(new DebugConsole.Command("cuicreatepalette",
23 "cuicreatepalette name frontcolor [backcolor]", CUICreatePalette_Command)
24 );
25 AddedCommands.Add(new DebugConsole.Command("printkeys", "", PrintSprites_Command));
26 AddedCommands.Add(new DebugConsole.Command("printcolors", "", PrintColors_Command));
27 AddedCommands.Add(new DebugConsole.Command("cuipalette", "load palette as primary", Palette_Command, () => new string[][] { CUIPalette.LoadedPalettes.Keys.ToArray() }));
28 AddedCommands.Add(new DebugConsole.Command("cuipalettedemo", "", PaletteDemo_Command));
29 AddedCommands.Add(new DebugConsole.Command("cuicreatepaletteset", "cuicreatepaletteset name primaty secondary tertiary quaternary", CUICreatePaletteSet_Command, () => new string[][] {
30 new string[]{},
31 CUIPalette.LoadedPalettes.Keys.ToArray(),
32 CUIPalette.LoadedPalettes.Keys.ToArray(),
33 CUIPalette.LoadedPalettes.Keys.ToArray(),
34 CUIPalette.LoadedPalettes.Keys.ToArray(),
35 }));
36 AddedCommands.Add(new DebugConsole.Command("cuiloadpaletteset", "", CUILoadPaletteSet_Command));
37 AddedCommands.Add(new DebugConsole.Command("cuicreateluatypesfile", "", CUICreateLuaTypesFile_Command));
38
39 DebugConsole.Commands.InsertRange(0, AddedCommands);
40 }
41
42 public static void PrintColors_Command(string[] args)
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 }
49
50 public static void CUICreateLuaTypesFile_Command(string[] args)
51 {
52 CUI.LuaRegistrar.ConstructLuaStaticsFile();
53 }
54
55
56 public static void CUICreatePalette_Command(string[] args)
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 }
64
65 public static void CUICreatePaletteSet_Command(string[] args)
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 }
75
76 public static void CUILoadPaletteSet_Command(string[] args)
77 {
78 CUIPalette.LoadSet(Path.Combine(CUIPalette.PaletteSetsPath, args.ElementAtOrDefault(0)));
79 }
80
81 public static void PrintKeysCommand(string[] args)
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 }
95
96 public static void PaletteDemo_Command(string[] args)
97 {
98 try { CUIPalette.PaletteDemo(); } catch (Exception e) { CUI.Warning(e); }
99 }
100
101 public static void Palette_Command(string[] args)
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 }
110
111
112 internal static void RemoveCommands()
113 {
114 AddedCommands.ForEach(c => DebugConsole.Commands.Remove(c));
115 AddedCommands.Clear();
116 }
117
118 // public static void PermitCommands(Identifier command, ref bool __result)
119 // {
120 // if (AddedCommands.Any(c => c.Names.Contains(command.Value))) __result = true;
121 // }
122 }
123}