CrabUI
Loading...
Searching...
No Matches
AttachedItemTest.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 public partial class RandomTest : FillMethods
18 {
19 public class RevolverOverlay : CUIComponent
20 {
21 public void Open()
22 {
23 if (Parent != null) return;
24 CUI.Main.Append(this);
25 Animation.SetToStart();
26 Animation.Forward();
27 }
28
29 public void Remove()
30 {
31 CUI.Main.RemoveChild(this);
32 Animation.Stop();
33 }
34
35 public CUIAnimation Animation;
36
37 public RevolverOverlay()
38 {
39 Relative = new CUINullRect(0, 0, 1, 1);
40 BackgroundColor = new Color(255, 0, 0, 64);
41 IgnoreEvents = true;
42
43 Animation = new CUIAnimation()
44 {
45 Target = this,
46 Property = "BackgroundColor",
47 StartValue = new Color(255, 0, 0, 0),
48 EndValue = new Color(255, 0, 0, 64),
49 Repeat = true,
50 Duration = 0.8,
51 };
52
53
55 {
56 Component = this,
57 AddOnSelect = (item, c) => Open(),
58 AddOnDeselect = (item, c) => Remove(),
59 };
60 }
61 }
62
63
64 public class PeriscopeOverlay : CUITextBlock
65 {
66 public void Open()
67 {
68 if (Parent != null) return;
69 CUI.Main.Append(this);
70 }
71
72 public void Remove()
73 {
74 CUI.Main.RemoveChild(this);
75 }
76
77 public PeriscopeOverlay()
78 {
79 Relative = new CUINullRect(0.5f, 0.0f, 0.5f, 1.0f);
80 Text = "It's not wired you dummy";
81 TextAlign = CUIAnchor.Center;
82 textScale = 2;
83 BackgroundSprite = CUI.TextureManager.GetCUISprite(4, 1, effects: SpriteEffects.FlipHorizontally);
84 BackgroundColor = Color.White;
85 IgnoreEvents = true;
86
88 {
89 Component = this,
90 AddOnSelect = (item, c) => Open(),
91 AddOnDeselect = (item, c) => Remove(),
92 };
93 }
94 }
95
96 public static void AttachedItemTest(CUIComponent Main)
97 {
98 AttachedItems.ConnectPrefabs("revolver", typeof(RevolverOverlay));
99 AttachedItems.ConnectPrefabs("periscope", typeof(PeriscopeOverlay));
100 CUITest.CloseTestChamber();
101 }
102 }
103}
Link between Item and CUIComponent.
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
WIP, can animate any property on any object Can run back and forth in [0..1] interval and interpolate...
void SetToStart()
Set Lambda to 0.
void Forward()
Set Direction to Straight and Start.
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.
Color BackgroundColor
Color of BackgroundSprite, default is black If you're using custom sprite and don't see it make sur...
bool IgnoreEvents
Won't react to mouse events.
CUISprite BackgroundSprite
Will be drawn in background with BackgroundColor Default is solid white 1x1 texture.
In fact a static class managing static things.
Definition CUIErrors.cs:16
static CUITextureManager TextureManager
Safe texture manager </summary.
Definition CUI.cs:97
static CUIMainComponent Main
Orchestrates Drawing and updates, there could be only one CUI.Main is located under vanilla GUI.
Definition CUI.cs:84
Passive block of text.
Vector2 TextAlign
A Vector2 ([0..1],[0..1])
CUISprite GetCUISprite(int x, int y, CUISpriteDrawMode? drawMode=null, SpriteEffects? effects=null)
32x32 square on (x,y) position from CUI.png
Rectangle with float?
Definition CUIRect.cs:104