public UIVirtualKeyboard(string labelText, string startingText, KeyboardSubmitEvent submitAction, Action cancelAction, int inputMode = 0, bool allowEmpty = false) { _keyboardContext = inputMode; _allowEmpty = allowEmpty; OffsetDown = 0; ShouldHideText = false; _lastOffsetDown = 0; _edittingSign = _keyboardContext == 1; _edittingChest = _keyboardContext == 2; _currentInstance = this; _submitAction = submitAction; _cancelAction = cancelAction; _textureShift = Main.Assets.Request <Texture2D>("Images/UI/VK_Shift", Main.content, (AssetRequestMode)1); _textureBackspace = Main.Assets.Request <Texture2D>("Images/UI/VK_Backspace", Main.content, (AssetRequestMode)1); Top.Pixels = _lastOffsetDown; float num = 0.5f; float num2 = -20f; float num3 = -5000 * _edittingSign.ToInt(); num2 = 270f; num = 0f; float num4 = 516f; UIElement uIElement = new UIElement(); uIElement.Width.Pixels = num4 + 8f + 16f; uIElement.Top.Precent = num; uIElement.Top.Pixels = num2; uIElement.Height.Pixels = 266f; uIElement.HAlign = 0.5f; uIElement.SetPadding(0f); outerLayer1 = uIElement; UIElement uIElement2 = new UIElement(); uIElement2.Width.Pixels = num4 + 8f + 16f; uIElement2.Top.Precent = num; uIElement2.Top.Pixels = num2; uIElement2.Height.Pixels = 266f; uIElement2.HAlign = 0.5f; uIElement2.SetPadding(0f); outerLayer2 = uIElement2; UIPanel uIPanel = new UIPanel { Width = { Precent = 1f }, Height = { Pixels = 225f }, BackgroundColor = new Color(23, 33, 69) * 0.7f }; uIElement.Append(uIPanel); float num5 = -50f; _textBox = new UITextBox("", 0.78f, large: true); _textBox.BackgroundColor = Color.Transparent; _textBox.BorderColor = Color.Transparent; _textBox.HAlign = 0.5f; _textBox.Width.Pixels = num4; _textBox.Top.Pixels = num5 + num2 - 10f + num3; _textBox.Top.Precent = num; _textBox.Height.Pixels = 37f; Append(_textBox); for (int i = 0; i < 10; i++) { for (int j = 0; j < 4; j++) { int index = j * 10 + i; UITextPanel <object> uITextPanel = CreateKeyboardButton("1234567890qwertyuiopasdfghjkl'zxcvbnm,.?"[index].ToString(), i, j); uITextPanel.OnClick += TypeText; uIPanel.Append(uITextPanel); } } _shiftButton = CreateKeyboardButton("", 0, 4, 1, style: false); _shiftButton.PaddingLeft = 0f; _shiftButton.PaddingRight = 0f; _shiftButton.PaddingBottom = (_shiftButton.PaddingTop = 0f); _shiftButton.BackgroundColor = new Color(63, 82, 151) * 0.7f; _shiftButton.BorderColor = _internalBorderColor * 0.7f; _shiftButton.OnMouseOver += delegate { _shiftButton.BorderColor = _internalBorderColorSelected; if (_keyState != KeyState.Shift) { _shiftButton.BackgroundColor = new Color(73, 94, 171); } }; _shiftButton.OnMouseOut += delegate { _shiftButton.BorderColor = _internalBorderColor * 0.7f; if (_keyState != KeyState.Shift) { _shiftButton.BackgroundColor = new Color(63, 82, 151) * 0.7f; } }; _shiftButton.OnClick += delegate { SoundEngine.PlaySound(12); SetKeyState((_keyState != KeyState.Shift) ? KeyState.Shift : KeyState.Default); }; UIImage element = new UIImage(_textureShift) { HAlign = 0.5f, VAlign = 0.5f, ImageScale = 0.85f }; _shiftButton.Append(element); uIPanel.Append(_shiftButton); _symbolButton = CreateKeyboardButton("@%", 1, 4, 1, style: false); _symbolButton.PaddingLeft = 0f; _symbolButton.PaddingRight = 0f; _symbolButton.BackgroundColor = new Color(63, 82, 151) * 0.7f; _symbolButton.BorderColor = _internalBorderColor * 0.7f; _symbolButton.OnMouseOver += delegate { _symbolButton.BorderColor = _internalBorderColorSelected; if (_keyState != KeyState.Symbol) { _symbolButton.BackgroundColor = new Color(73, 94, 171); } }; _symbolButton.OnMouseOut += delegate { _symbolButton.BorderColor = _internalBorderColor * 0.7f; if (_keyState != KeyState.Symbol) { _symbolButton.BackgroundColor = new Color(63, 82, 151) * 0.7f; } }; _symbolButton.OnClick += delegate { SoundEngine.PlaySound(12); SetKeyState((_keyState != KeyState.Symbol) ? KeyState.Symbol : KeyState.Default); }; uIPanel.Append(_symbolButton); BuildSpaceBarArea(uIPanel); _submitButton = new UITextPanel <LocalizedText>((_edittingSign || _edittingChest) ? Language.GetText("UI.Save") : Language.GetText("UI.Submit"), 0.4f, large: true); _submitButton.Height.Pixels = 37f; _submitButton.Width.Precent = 0.4f; _submitButton.HAlign = 1f; _submitButton.VAlign = 1f; _submitButton.PaddingLeft = 0f; _submitButton.PaddingRight = 0f; ValidateText(); _submitButton.OnMouseOver += FadedMouseOver; _submitButton.OnMouseOut += FadedMouseOut; _submitButton.OnMouseOver += delegate { ValidateText(); }; _submitButton.OnMouseOut += delegate { ValidateText(); }; _submitButton.OnClick += delegate { Submit(); }; uIElement.Append(_submitButton); _cancelButton = new UITextPanel <LocalizedText>(Language.GetText("UI.Cancel"), 0.4f, large: true); StyleKey(_cancelButton, external: true); _cancelButton.Height.Pixels = 37f; _cancelButton.Width.Precent = 0.4f; _cancelButton.VAlign = 1f; _cancelButton.OnClick += delegate { SoundEngine.PlaySound(11); _cancelAction(); }; _cancelButton.OnMouseOver += FadedMouseOver; _cancelButton.OnMouseOut += FadedMouseOut; uIElement.Append(_cancelButton); _submitButton2 = new UITextPanel <LocalizedText>((_edittingSign || _edittingChest) ? Language.GetText("UI.Save") : Language.GetText("UI.Submit"), 0.72f, large: true); _submitButton2.TextColor = Color.Silver; _submitButton2.DrawPanel = false; _submitButton2.Height.Pixels = 60f; _submitButton2.Width.Precent = 0.4f; _submitButton2.HAlign = 0.5f; _submitButton2.VAlign = 0f; _submitButton2.OnMouseOver += delegate(UIMouseEvent a, UIElement b) { ((UITextPanel <LocalizedText>)b).TextScale = 0.85f; ((UITextPanel <LocalizedText>)b).TextColor = Color.White; }; _submitButton2.OnMouseOut += delegate(UIMouseEvent a, UIElement b) { ((UITextPanel <LocalizedText>)b).TextScale = 0.72f; ((UITextPanel <LocalizedText>)b).TextColor = Color.Silver; }; _submitButton2.Top.Pixels = 50f; _submitButton2.PaddingLeft = 0f; _submitButton2.PaddingRight = 0f; ValidateText(); _submitButton2.OnMouseOver += delegate { ValidateText(); }; _submitButton2.OnMouseOut += delegate { ValidateText(); }; _submitButton2.OnMouseOver += FadedMouseOver; _submitButton2.OnMouseOut += FadedMouseOut; _submitButton2.OnClick += delegate { string text = Text.Trim(); if (text.Length > 0 || _edittingSign || _edittingChest || _allowEmpty) { SoundEngine.PlaySound(10); _submitAction(text); } }; outerLayer2.Append(_submitButton2); _cancelButton2 = new UITextPanel <LocalizedText>(Language.GetText("UI.Cancel"), 0.72f, large: true); _cancelButton2.TextColor = Color.Silver; _cancelButton2.DrawPanel = false; _cancelButton2.OnMouseOver += delegate(UIMouseEvent a, UIElement b) { ((UITextPanel <LocalizedText>)b).TextScale = 0.85f; ((UITextPanel <LocalizedText>)b).TextColor = Color.White; }; _cancelButton2.OnMouseOut += delegate(UIMouseEvent a, UIElement b) { ((UITextPanel <LocalizedText>)b).TextScale = 0.72f; ((UITextPanel <LocalizedText>)b).TextColor = Color.Silver; }; _cancelButton2.Height.Pixels = 60f; _cancelButton2.Width.Precent = 0.4f; _cancelButton2.Top.Pixels = 114f; _cancelButton2.VAlign = 0f; _cancelButton2.HAlign = 0.5f; _cancelButton2.OnClick += delegate { SoundEngine.PlaySound(11); _cancelAction(); }; outerLayer2.Append(_cancelButton2); UITextPanel <object> uITextPanel2 = CreateKeyboardButton("", 8, 4, 2); uITextPanel2.OnClick += delegate { SoundEngine.PlaySound(12); _textBox.Backspace(); ValidateText(); }; uITextPanel2.PaddingLeft = 0f; uITextPanel2.PaddingRight = 0f; uITextPanel2.PaddingBottom = (uITextPanel2.PaddingTop = 0f); uITextPanel2.Append(new UIImage(_textureBackspace) { HAlign = 0.5f, VAlign = 0.5f, ImageScale = 0.92f }); uIPanel.Append(uITextPanel2); UIText uIText = new UIText(labelText, 0.75f, large: true) { HAlign = 0.5f, Width = { Pixels = num4 }, Top = { Pixels = num5 - 37f - 4f + num2 + num3, Precent = num }, Height = { Pixels = 37f } }; Append(uIText); _label = uIText; Append(uIElement); int textMaxLength = (_edittingSign ? 1200 : 20); _textBox.SetTextMaxLength(textMaxLength); Text = startingText; if (Text.Length == 0) { SetKeyState(KeyState.Shift); } ShouldHideText = true; OffsetDown = 9999; UpdateOffsetDown(); }