CrabUI
Loading...
Searching...
No Matches
Style inheritance.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;
14using CrabUI;
15
16namespace CrabUITest
17{
18
19 public class StyleInheritance : UnitTest
20 {
21 public class TestClassA : CUIComponent
22 {
23 [CUISerializable] public Color prop0 { get; set; }
24 [CUISerializable] public Color prop1 { get; set; }
25 [CUISerializable] public Color prop2 { get; set; }
26 [CUISerializable] public Color prop3 { get; set; }
27 [CUISerializable] public Color prop4 { get; set; }
28 [CUISerializable] public Color prop5 { get; set; }
29 [CUISerializable] public Color prop6 { get; set; }
30 [CUISerializable] public Color prop7 { get; set; }
31
32 [CUISerializable] public Color prop8 { get; set; }
33 [CUISerializable] public Color prop9 { get; set; }
34 [CUISerializable] public Color prop10 { get; set; }
35 [CUISerializable] public Color prop11 { get; set; }
36 [CUISerializable] public Color prop12 { get; set; }
37 [CUISerializable] public Color prop13 { get; set; }
38 [CUISerializable] public Color prop14 { get; set; }
39 [CUISerializable] public Color prop15 { get; set; }
40 [CUISerializable] public Color guh { get; set; }
41
42 public TestClassA()
43 {
44
45 }
46 }
47
48 public class TestClassB : TestClassA
49 {
50 public TestClassB()
51 {
52
53 }
54 }
55
56
57 public void OneClassTest()
58 {
59 TestClassA testA = new TestClassA();
60
61 CUIStyle.DefaultFor<TestClassA>()["prop1"] = "red";
62
63 testA.Style["prop2"] = "blue";
64
65 CUIStyle.DefaultFor<TestClassA>()["prop3"] = "red";
66 testA.Style["prop3"] = "blue";
67
68 testA.prop4 = Color.Lime;
69
70 CUIStyle.DefaultFor<TestClassA>()["prop5"] = "red";
71 testA.prop5 = Color.Lime;
72
73 testA.Style["prop6"] = "blue";
74 testA.prop6 = Color.Lime;
75
76 CUIStyle.DefaultFor<TestClassA>()["prop7"] = "red";
77 testA.Style["prop7"] = "blue";
78 testA.prop7 = Color.Lime;
79
80 Expect(testA.prop0).ToBeEqual(Color.Transparent);
81 Expect(testA.prop1).ToBeEqual(Color.Red);
82 Expect(testA.prop2).ToBeEqual(Color.Blue);
83 Expect(testA.prop3).ToBeEqual(Color.Blue);
84 Expect(testA.prop4).ToBeEqual(Color.Lime);
85 Expect(testA.prop5).ToBeEqual(Color.Lime);
86 Expect(testA.prop6).ToBeEqual(Color.Lime);
87 Expect(testA.prop7).ToBeEqual(Color.Lime);
88
89 Describe("-------------------------------", () => { Expect("guh").ToNotThrow(); });
90 }
91
92
93
94
95 public void TwoClassTest()
96 {
97 TestClassB testB = new TestClassB();
98
99 for (int i = 0; i < 2; i++)
100 {
101 for (int j = 0; j < 2; j++)
102 {
103 for (int k = 0; k < 2; k++)
104 {
105 for (int l = 0; l < 2; l++)
106 {
107 int num = i + 2 * j + 4 * k + 8 * l;
108 string propName = $"prop{num}";
109 PropertyInfo pi = typeof(TestClassB).GetProperty(propName);
110
111 if (i == 1) CUIStyle.DefaultFor<TestClassA>()[propName] = "red";
112 if (j == 1) CUIStyle.DefaultFor<TestClassB>()[propName] = "blue";
113 if (k == 1) testB.Style[propName] = "lime";
114 if (l == 1) pi.SetValue(testB, Color.Yellow);
115
116 if (l == 1)
117 {
118 Expect(pi.GetValue(testB)).ToBeEqual(Color.Yellow);
119 }
120 else
121 {
122 if (k == 1)
123 {
124 Expect(pi.GetValue(testB)).ToBeEqual(Color.Lime);
125 }
126 else
127 {
128 if (j == 1)
129 {
130 Expect(pi.GetValue(testB)).ToBeEqual(Color.Blue);
131 }
132 else
133 {
134 if (i == 1)
135 {
136 Expect(pi.GetValue(testB)).ToBeEqual(Color.Red);
137 }
138 else
139 {
140 Expect(pi.GetValue(testB)).ToBeEqual(Color.Transparent);
141 }
142 }
143 }
144 }
145 }
146 }
147 }
148 }
149
150
151 }
152
153 public void SpecTest()
154 {
155 TestClassB testB = new TestClassB();
156
157 CUIStyle.DefaultFor<TestClassA>()["guh"] = "red";
158 //CUIStyle.DefaultFor<TestClassB>()["guh"] = "blue";
159 //testB.Style["guh"] = "lime";
160 //testB.guh = Color.Yellow;
161
162 Expect(testB.guh).ToBeEqual(Color.Red);
163 }
164
165 }
166}
Base class for all components.
In Fact just an observable dict.
Definition CUIStyle.cs:21