/// <summary> /// Construct the chat box in the given group and with the given mod settings. /// </summary> /// <param name="chatBoxGroup">The component group it should be in.</param> /// <param name="modSettings">The current mod settings.</param> public ChatBox(ComponentGroup chatBoxGroup, ModSettings modSettings) { _chatBoxGroup = chatBoxGroup; _textGenerator = new TextGenerator(); _messages = new ChatMessage[MaxMessages]; _chatInput = new ChatInputComponent( chatBoxGroup, new Vector2(ChatWidth / 2f + MarginLeft, InputMarginBottom + InputHeight / 2f), new Vector2(ChatWidth, InputHeight), UiManager.ChatFontSize ); _chatInput.SetActive(false); _chatInput.OnSubmit += chatInput => { if (chatInput.Length > 0) { ChatInputEvent?.Invoke(chatInput); } HideChatInput(); }; _isOpen = false; // Calculate these values beforehand so we can use them for each message MessageSize = new Vector2(ChatWidth + TextMargin, MessageHeight); _textGenSettings = new TextGenerationSettings { font = FontManager.UIFontRegular, color = Color.white, fontSize = UiManager.ChatFontSize, lineSpacing = 1, richText = true, scaleFactor = 1, fontStyle = FontStyle.Normal, textAnchor = TextAnchor.LowerLeft, alignByGeometry = false, resizeTextForBestFit = false, resizeTextMinSize = 10, resizeTextMaxSize = 40, updateBounds = false, verticalOverflow = VerticalWrapMode.Overflow, horizontalOverflow = HorizontalWrapMode.Wrap, generationExtents = MessageSize, pivot = new Vector2(0.5f, 0.5f), generateOutOfBounds = false }; // Register the update event so we can check key binds MonoBehaviourUtil.Instance.OnUpdateEvent += () => CheckKeyBinds(modSettings); }