2using System.Collections.Generic;
4using System.Reflection;
5using System.Diagnostics;
6using System.Runtime.CompilerServices;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Input;
12using Microsoft.Xna.Framework.Graphics;
16using System.Threading;
17using Barotrauma.Extensions;
21 public class AutoTestGUI
31 get => RunButton.Text;
32 set => RunButton.Text = value;
35 public void UseReport(TestReport report)
37 RunButton.MasterColor = report.Status
switch
39 TestStatus.Passed => Color.Lime,
40 TestStatus.Unknown => Color.Yellow,
41 TestStatus.Stashed => Color.Lime,
42 TestStatus.Failed => Color.Red,
51 this[
"RunButton"] = RunButton =
new CUIButton()
56 {
"MasterColor",
"128,128,128" },
57 {
"TextAlign",
"[0,0]" },
58 {
"Border",
"Transparent" },
65 AddOnStateChange = (state) =>
70 {
"Border",
"Transparent" },
71 {
"OnColor",
"0,200,0"},
72 {
"OnHoverColor",
"0,255,255"},
76 this[
"StashButton"] = StashButton =
new CUIButton()
80 {
"MasterColor",
"255,0,255" },
81 {
"Border",
"Transparent" },
88 public TestButton(
string name) : this()
95 public AutomaticTestRunner Runner;
102 public Dictionary<MethodInfo, TestButton> TestButtons =
new();
109 OpenButton.Revealed = !value;
110 MainFrame.Revealed = value;
114 public void UseConfig(TestingConfig config)
116 if (config.Autorun ==
"")
return;
117 (Type testClass, MethodInfo testMethod) = AutomaticTestRunner.DeconstructFullName(config.Autorun);
119 if (TestButtons.ContainsKey(testMethod))
121 if (!TestButtons[testMethod].AutorunButton.State)
123 TestButtons[testMethod].AutorunButton.State =
true;
128 public void FindTests()
130 TestButtons?.Clear();
131 CUITestList?.RemoveAllChildren();
133 foreach (Type testClass
in Runner.GetAllTestClasses())
135 foreach (MethodInfo testMethod
in Runner.GetAllTestMethodsForAClass(testClass))
137 TestButtons[testMethod] =
new TestButton($
"{testClass.Name}.{testMethod.Name}");
138 TestButtons[testMethod].RunButton.OnMouseDown += (e) => Runner.RunTest(testClass, testMethod);
139 TestButtons[testMethod].StashButton.OnMouseDown += (e) => Runner.StashTest(testClass, testMethod);
141 CUITestList.
Append(TestButtons[testMethod]);
146 public void CreateUI()
152 AddOnMouseDown = (e) => Opened = !Opened,
153 Font = GUIStyle.MonospacedFont,
155 AKA =
"AutoTest open button",
163 AKA =
"AutoTest MainFrame"
166 MainFrame.SaveStateAs(
"init");
167 MainFrame.OnDClick += (e) => MainFrame.LoadState(
"init");
168 MainFrame.Revealed =
false;
183 FillEmptySpace =
new CUIBool2(
true,
false),
186 MainFrame[
"list"][
"header"][
"main"][
"caption"] =
new CUITextBlock(
"Test")
190 MainFrame[
"list"][
"header"][
"main"][
"runall"] =
new CUIButton(
"Run all")
192 AddOnMouseDown = (e) => Runner.RunAllTests(),
194 MainFrame[
"list"][
"header"][
"main"][
"end"] =
new CUIButton(
"End test")
196 AddOnMouseDown = (e) => Runner.StopTest(),
198 MainFrame[
"list"][
"header"][
"main"][
"clear"] =
new CUIButton(
"clear stash")
200 AddOnMouseDown = (e) => Runner.ClearStash(),
201 Style =
new CUIStyle() { {
"MasterColor",
"Red" } },
204 MainFrame[
"list"][
"header"][
"closebutton"] =
new CUIButton(
"X")
206 Style =
new CUIStyle() { {
"MasterColor",
"Red" } },
207 AddOnMouseDown = (e) => Opened =
false,
208 Font = GUIStyle.MonospacedFont,
215 FillEmptySpace =
new CUIBool2(
false,
true),
219 MainFrame.IgnoreDebug =
true;
220 OpenButton.IgnoreDebug =
true;
226 public AutoTestGUI(AutomaticTestRunner runner)
232 MainFrame.
AddCommand(
"set autorun", (o) => runner.Config.Autorun = (
string)o);
234 Runner.OnTestReport += (report) =>
236 TestButtons.GetValueOrDefault(report.TestMethod)?.UseReport(report);
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
CUIBool2 FillEmptySpace
Will be resized to fill empty space in list components.
bool Revealed
Visible + !IgnoreEvents.
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
void AddCommand(string name, Action< object > action)
Manually adds command.
CUIStyle Style
Allows you to assing parsable string or link to CUIPalette to any prop It's indexable,...
CUIBool2 FitContent
Will resize itself to fit components with absolute size, e.g. text.
void DispatchUp(CUICommand command)
Dispathes command up the component tree until someone consumes it.
Draggable and resizable container for other components.
Resizing components to it's Height and placing them sequentially.
In fact a static class managing static things.
static CUIMainComponent Main
Orchestrates Drawing and updates, there could be only one CUI.Main is located under vanilla GUI.
In Fact just an observable dict.
Resizing components to it's Width and placing them sequentially.
record CUICommand(string Name, object Data=null)
Can be dispatched up the component tree to notify parent about something add pass some event data wit...