CrabUI
Loading...
Searching...
No Matches
SaveLoadIntegrity.cs
1using System;
2using System.Reflection;
3using System.Runtime.CompilerServices;
4using System.Collections.Generic;
5using System.Collections.Immutable;
6using System.Linq;
7
8using Barotrauma;
9using HarmonyLib;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Graphics;
12using System.IO;
13
14using CrabUI;
15
16namespace CrabUITest
17{
18 public partial class SerializationTest : FillMethods
19 {
20
21 public static void SaveLoadIntegrity(CUIComponent Main)
22 {
23 string savePath = Path.Combine(CUITest.IgnoredDataPath, "123.xml");
24
25 CUIFrame frame;
26 frame = new CUIFrame()
27 {
28 Absolute = new CUINullRect(0, 0, 500, 500),
29 Anchor = CUIAnchor.Center,
30 };
31
32 frame["list"] = new CUIVerticalList()
33 {
34 Relative = new CUINullRect(0, 0, 1, 1),
35 };
36
37 frame["list"]["header"] = new CUIHorizontalList()
38 {
39 FitContent = new CUIBool2(false, true),
40 Direction = CUIDirection.Reverse,
41 };
42 frame["list"]["header"]["close"] = new CUICloseButton()
43 {
44 Absolute = new CUINullRect(0, 0, 15, 15),
45 };
46 frame["list"]["content"] = new CUIVerticalList()
47 {
48 FillEmptySpace = new CUIBool2(false, true),
49 Scrollable = true,
50 };
51
52 CUIComponent AddComponent(Type T)
53 {
54 CUIComponent wrapper = new CUIHorizontalList()
55 {
56 Absolute = new CUINullRect(h: 20),
57 CullChildren = false,
58 };
59
60 wrapper.Append(new CUITextBlock(T.Name)
61 {
62 Absolute = new CUINullRect(w: 130),
63 });
64
65 CUIComponent target = (CUIComponent)Activator.CreateInstance(T);
66 target.FillEmptySpace = new CUIBool2(true, false);
67 wrapper.Append(target);
68
69 frame["list"]["content"].Append(wrapper);
70 return target;
71 }
72
73 AddComponent(typeof(CUIComponent));
74 AddComponent(typeof(CUIButton));
75 AddComponent(typeof(CUIToggleButton));
76 AddComponent(typeof(CUIMultiButton));
77 CUIDropDown dd = (CUIDropDown)AddComponent(typeof(CUIDropDown));
78 dd.Add("123");
79 dd.Add("321");
80 AddComponent(typeof(CUITextBlock));
81 AddComponent(typeof(CUITextInput));
82 AddComponent(typeof(CUIHorizontalList));
83 AddComponent(typeof(CUIVerticalList));
84
85
86
87 frame.SaveToFile(savePath);
88 CUIFrame loaded = CUIComponent.LoadFromFile<CUIFrame>(savePath);
89
90 CUIComponent.DeepCompareVerbose(frame, loaded);
91
92 frame.AddCommand("Close", (o) => frame.RemoveSelf());
93 loaded.AddCommand("Close", (o) => loaded.RemoveSelf());
94
95 Main.Append(frame);
96 Main.Append(loaded);
97 }
98
99
100 }
101}
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
A button It's derived from CUITextBlock and has all its props.
Definition CUIButton.cs:19
Base class for all components.
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.
Drop down list, aka Select.
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
Resizing components to it's Height and placing them sequentially.
Button with multiple options which are rotating when you click.
Passive block of text.
A button which can be on and off It's derived from CUITextBlock and has all its props.
Resizing components to it's Width and placing them sequentially.
This class contains filling methods An Action<CUIComponent> that creates some GUI and attaches it t...
Vector2 but with bools.
Definition CUIBool2.cs:17
Rectangle with float?
Definition CUIRect.cs:104