CrabUI
Loading...
Searching...
No Matches
Piano.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;
12
13using CrabUI;
14
15namespace CrabUITest
16{
17 /// <summary>
18 /// Random complex tests
19 /// </summary>
20 public partial class ComplexTest : FillMethods
21 {
22 /// <summary>
23 /// Class for piano test
24 /// </summary>
25 public class PianoKey : CUIButton
26 {
27 public PianoKey(Color color, string text = "") : base("")
28 {
29 Absolute = new CUINullRect(w: 20, h: 50);
30 Border = new CUIBorder();
31 MasterColorOpaque = color;
32 PlaySound = false;
33
34 // stupid workaround, GhostText seems to do nothing and needs fixing
35 this["text"] = new CUITextBlock(text)
36 {
37 Relative = new CUINullRect(0, 0, 1, 1),
38 Anchor = CUIAnchor.Center,
39 TextAlign = CUIAnchor.Center,
40 };
41 }
42 }
43
44 public static void Piano(CUIComponent Main)
45 {
46 CUIFrame Piano = new CUIFrame()
47 {
48 FitContent = new CUIBool2(true, true),
49 Anchor = CUIAnchor.Center,
50 Resizible = false,
51 OutlineColor = Color.SaddleBrown,
52 OutlineThickness = 4.0f,
53 BackgroundColor = new Color(0, 0, 0),
54 };
55
56 Piano["layout"] = new CUIVerticalList() { FitContent = new CUIBool2(true, true), };
57 Piano["layout"]["header"] = new CUITextBlock("Piano")
58 {
59 TextAlign = CUIAnchor.Center,
60 BackgroundColor = Color.SaddleBrown,
61 };
62
63 Piano["layout"]["black keys"] = new CUIHorizontalList()
64 {
65 FitContent = new CUIBool2(true, true),
66 Gap = 1.0f,
67 ConsumeDragAndDrop = true,
68 };
69
70 Piano["layout"]["white keys"] = new CUIHorizontalList()
71 {
72 FitContent = new CUIBool2(true, true),
73 Gap = 1.0f,
74 ConsumeDragAndDrop = true,
75 };
76
77 for (int i = 0; i < 30; i++)
78 {
79 Piano["layout"]["white keys"].Append(new PianoKey(Color.White, $"{i}"));
80 }
81
82 Piano["layout"]["black keys"]["offset"] = new CUIComponent()
83 {
84 Absolute = new CUINullRect(w: 10, h: 50),
85 };
86
87 for (int i = 0; i < 29; i++)
88 {
89 if (CUI.Random.Next(4) == 0)
90 {
91 Piano["layout"]["black keys"].Append(new CUIComponent()
92 {
93 Absolute = new CUINullRect(w: 20, h: 50),
94 });
95 }
96 else
97 {
98 Piano["layout"]["black keys"].Append(new PianoKey(new Color(64, 64, 64), $"{i}"));
99 }
100 }
101
102 Main.Append(Piano);
103 }
104 }
105}
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.
CUINullRect Relative
Relative to parent size and position, [0..1].
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
CUIBorder Border
Container for Color and Thickness Border is drawn inside the component and will eat space from cont...
Vector2 Anchor
this point of this component
CUINullRect Absolute
Absolute size and position in pixels.
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
Resizing components to it's Height and placing them sequentially.
In fact a static class managing static things.
Definition CUIErrors.cs:16
Passive block of text.
Vector2 TextAlign
A Vector2 ([0..1],[0..1])
Resizing components to it's Width and placing them sequentially.
Class for piano test.
Definition Piano.cs:26
Random complex tests.
Definition Piano.cs:21
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