/// <summary>Turns data into a CuiTextComponent.</summary> /// <param name="data">The data to base the CuiTextComponent on.</param> /// <returns>A CuiTextComponent based on the data.</returns> public static CuiTextComponent ToTextComponent(Dictionary <string, object> data) { CuiTextComponent textComponent = new CuiTextComponent(); if (data.ContainsKey(TextProperties.align)) { textComponent.Align = EnumPlus.ToEnum <TextAnchor>(data[TextProperties.align].ToString()); } if (data.ContainsKey(TextProperties.color)) { textComponent.Color = data[TextProperties.color].ToString(); } if (data.ContainsKey(TextProperties.font)) { textComponent.Font = data[TextProperties.font].ToString(); } if (data.ContainsKey(TextProperties.fontSize)) { int fontSize = textComponent.FontSize; if (!int.TryParse(data[TextProperties.fontSize].ToString(), out fontSize)) { instance.PrintWarning("Could not succesfully parse " + data[TextProperties.fontSize].ToString() + ", a value retrieved from the configuration file, as a font size. Returned a default value of " + fontSize + " instead."); } textComponent.FontSize = fontSize; } if (data.ContainsKey(TextProperties.text)) { textComponent.Text = data[TextProperties.text].ToString(); } return(textComponent); }
public UILabel(Vector2 min = default(Vector2), Vector2 max = default(Vector2), string labelText = "", int fontSize = 12, string fontColor = "1 1 1 1", UIBaseElement parent = null, TextAnchor alignment = TextAnchor.MiddleCenter) : base(min, max, parent) { if (min == Vector2.zero && max == Vector2.zero) { max = Vector2.one; } text = new CuiTextComponent(); text.Text = labelText; text.Color = fontColor; text.Align = alignment; text.FontSize = fontSize; Element.Components.Insert(0, text); }
public UILabel(UIContainer container, string labelText, int fontSize = 12, string fontColor = "1 1 1 1", TextAnchor alignment = TextAnchor.MiddleCenter, string parent = "") : base(container) { text = new CuiTextComponent(); text.Text = labelText; text.Color = fontColor; text.Align = alignment; text.FontSize = fontSize; if (!string.IsNullOrEmpty(parent)) { Element.Parent = parent; } Element.Components.Insert(0, text); }
private void Start() { for (var i = 0; i < _config.MaxFeedMessages; i++) { _rectTransformStatic[i] = new CuiRectTransformComponent { AnchorMax = $"{_config.AnchorMax.Split(Convert.ToChar(' '))[0]} {float.Parse(_config.AnchorMax.Split(Convert.ToChar(' '))[1]) - (_config.HeightIdent * i)}", AnchorMin = $"{_config.AnchorMin.Split(Convert.ToChar(' '))[0]} {float.Parse(_config.AnchorMin.Split(Convert.ToChar(' '))[1]) - (_config.HeightIdent * i)}" }; _textStatic[i] = new CuiTextComponent { Align = TextAnchor.MiddleRight, FontSize = _config.FontSize, Text = string.Empty }; } StartCoroutine(ProccessQueue()); }
// initialize GUI elements void InitGUI() { GUIContainer = new CuiElementContainer(); GUIElement = new CuiElement() { Name = GUIName, FadeOut = data.ui.fadeOut, Components = { (GUIText = new CuiTextComponent() { Text = "", FontSize = data.ui.fontSize, Color = data.ui.boostTextColor, FadeIn = data.ui.fadeIn, Align = TextAnchor.MiddleCenter }), (GUIPosition = new CuiRectTransformComponent() { AnchorMin = data.ui.anchorMin, AnchorMax = data.ui.anchorMax }) } }; LockBackground = new CuiElement() { Name = GUIName, FadeOut = data.ui.fadeOut, Components = { new CuiImageComponent() { Sprite = "assets/icons/lock.png", Color = data.ui.lockIconColor, FadeIn = data.ui.fadeIn }, new CuiRectTransformComponent() { AnchorMin = data.ui.lockAnchorMin, AnchorMax = data.ui.lockAnchorMax } } }; }
static bool EqualComponent(CuiTextComponent e1, CuiTextComponent e2) { if (e1.Align != e2.Align) { return(false); } if (e1.Color != e2.Color) { return(false); } if (e1.Font != e2.Font) { return(false); } if (e1.Text != e2.Text) { return(false); } return(!(Math.Abs(e1.FadeIn - e2.FadeIn) > 0.01)); }
void GenerateContents(KitUI kit, float colms, float colSize, float sizeX, float sizeY, CuiElementContainer container, string parent, string AnchorMin = "0.1 0.5", string AnchorMax = "0.1 0.5", int fontS = 0) { var i = 0; var itemsOnLine = (colms * colSize) / sizeX; var originalX = 0f; var originalY = 0f; var startX = originalX; var startY = originalY; foreach (var pair in kit.items) { var url = $"https://rustlabs.com/img/items180/{pair.Key}.png"; var amount = pair.Value; // Icon container.Add(new CuiElement { Name = elemInfo + pair.Key, Parent = parent, Components = { new CuiRawImageComponent { Png = GetImage(url), Color = "1 1 1 1" }, new CuiRectTransformComponent { AnchorMin = AnchorMin, AnchorMax = AnchorMax, OffsetMin = $"{startX} {startY - sizeY}", OffsetMax = $"{startX + sizeX} {startY}" } } }); // Amount CuiTextComponent cuiTC = new CuiTextComponent { Text = amount.ToString(), Align = TextAnchor.LowerRight }; CuiTextComponent cuiTCF = new CuiTextComponent { Text = amount.ToString(), Align = TextAnchor.LowerRight, FontSize = fontS }; container.Add(new CuiElement { Parent = elemInfo + pair.Key, Components = { fontS > 0 ? cuiTCF : cuiTC, new CuiOutlineComponent { Color = config.outlineColor, Distance = config.outlineDistance }, new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" } } }); startX += sizeX + config.ContentoffsetX; i++; if (i > 0 && i % colms == 0) { startX = originalX; startY -= sizeY + config.ContentoffsetY; } } }