private TextMeshProButton CreateKeyboardButton(int childTransformIndex, bool duplicate = false) { RectTransform parent = this.transform.GetChild(childTransformIndex) as RectTransform; TextMeshProButton textMeshProButton = parent.GetComponentInChildren <TextMeshProButton>(); if (duplicate) { textMeshProButton = Instantiate(textMeshProButton, parent, false); } RectTransform rectTransform = textMeshProButton.transform as RectTransform; rectTransform.localPosition = Vector2.zero; rectTransform.localScale = Vector3.one; rectTransform.anchoredPosition = Vector2.zero; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector3.one; rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; Navigation navigation = textMeshProButton.button.navigation; navigation.mode = Navigation.Mode.None; textMeshProButton.button.navigation = navigation; textMeshProButton.button.onClick.RemoveAllListeners(); return(textMeshProButton); }
protected TextMeshProButton CreateKeyboardButton(Vector2 anchoredPosition, Vector2 sizeDelta, float fontSize = -1f, Transform parent = null, string name = null) { if (_buttonPrefab == null) { _buttonPrefab = Resources.FindObjectsOfTypeAll <TextMeshProButton>().First(x => x.name == "KeyboardButton"); } TextMeshProButton button = Instantiate(_buttonPrefab, parent != null ? parent : this.transform, false); // use bottom left edge as origin RectTransform rt = button.transform as RectTransform; rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.zero; rt.pivot = Vector2.zero; rt.anchoredPosition = anchoredPosition; rt.sizeDelta = sizeDelta; Navigation nav = button.button.navigation; nav.mode = Navigation.Mode.None; button.button.navigation = nav; button.text.fontSize = fontSize > 0f ? fontSize : DefaultFontSize; button.button.onClick.RemoveAllListeners(); if (!string.IsNullOrEmpty(name)) { button.gameObject.name = name; } UIUtilities.ScaleButton(button.button, DefaultButtonScale); return(button); }
private TextMeshProButton CreateKeyboardButton(Vector2 anchoredPosition, Vector2 sizeDelta) { TextMeshProButton button = Instantiate(_buttonPrefab, this.transform, false); // use bottom left edge as origin RectTransform rt = button.transform as RectTransform; rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.zero; rt.pivot = Vector2.zero; rt.anchoredPosition = anchoredPosition; rt.sizeDelta = sizeDelta; Navigation nav = button.button.navigation; nav.mode = Navigation.Mode.None; button.button.navigation = nav; button.text.fontSize = 3.5f; button.button.onClick.RemoveAllListeners(); return(button); }
protected override void CreateBottomButtons() { // Backspace TextMeshProButton button = CreateKeyboardButton(new Vector2(68f, YOffset + DefaultKeySize.y + 1f), new Vector2(16f, DefaultKeySize.y), this.transform, "Backspace"); button.text.text = "<-"; button.button.onClick.AddListener(InvokeDeleteButtonPressed); // Symbols _symbolButton = CreateKeyboardButton(new Vector2(0f, YOffset), new Vector2(16f, DefaultKeySize.y), this.transform, "Symbols"); _symbolButton.text.text = "Symbols"; _symbolButton.text.fontSize = 3f; _symbolButton.button.onClick.AddListener(() => SetSymbolMode(!_symbolModeActive)); // Space bar button = CreateKeyboardButton(new Vector2(17f, YOffset), new Vector2(51f, DefaultKeySize.y), this.transform, "Spacebar"); button.text.text = "Space"; button.button.onClick.AddListener(() => InvokeTextButtonPressed(' ')); // Clear button = CreateKeyboardButton(new Vector2(69f, YOffset), new Vector2(16f, DefaultKeySize.y), this.transform, "Clear"); button.text.text = "Clear"; button.button.onClick.AddListener(InvokeClearButtonPressed); }
public void Awake() { _keyButtonPrefab = Resources.FindObjectsOfTypeAll <TextMeshProButton>().First(x => x.name == "KeyboardButton"); string[] array = new string[] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m", "<-", "space", "OK", "Cancel" }; for (int i = 0; i < array.Length; i++) { RectTransform parent = transform.GetChild(i) as RectTransform; //TextMeshProButton textMeshProButton = Instantiate(_keyButtonPrefab, parent); TextMeshProButton textMeshProButton = parent.GetComponentInChildren <TextMeshProButton>(); textMeshProButton.text.text = array[i]; RectTransform rectTransform = textMeshProButton.transform as RectTransform; rectTransform.localPosition = Vector2.zero; rectTransform.localScale = Vector3.one; rectTransform.anchoredPosition = Vector2.zero; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector3.one; rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; Navigation navigation = textMeshProButton.button.navigation; navigation.mode = Navigation.Mode.None; textMeshProButton.button.navigation = navigation; textMeshProButton.button.onClick.RemoveAllListeners(); if (i < array.Length - 4) { string key = array[i]; textMeshProButton.button.onClick.AddListener(delegate() { textKeyWasPressedEvent?.Invoke(key[0]); }); } else if (i == array.Length - 4) { textMeshProButton.button.onClick.AddListener(delegate() { deleteButtonWasPressedEvent?.Invoke(); }); } else if (i == array.Length - 1) { (textMeshProButton.transform as RectTransform).sizeDelta = new Vector2(7f, 1.5f); _cancelButton = textMeshProButton.button; _cancelButton.gameObject.SetActive(!HideCancelButton); textMeshProButton.button.onClick.AddListener(delegate() { cancelButtonWasPressedEvent?.Invoke(); }); } else if (i == array.Length - 2) { _okButton = textMeshProButton.button; _okButton.interactable = OkButtonInteractivity; textMeshProButton.button.onClick.AddListener(delegate() { okButtonWasPressedEvent?.Invoke(); }); } else { textMeshProButton.button.onClick.AddListener(delegate() { textKeyWasPressedEvent?.Invoke(' '); }); } } name = "CustomUIKeyboard"; (transform as RectTransform).anchoredPosition -= new Vector2(0f, 0f); for (int i = 1; i <= 10; i++) { TextMeshProButton textButton = Instantiate(_keyButtonPrefab); textButton.text.text = i.ToString().Last().ToString(); string key = i.ToString().Last().ToString(); textButton.button.onClick.AddListener(delegate() { textKeyWasPressedEvent?.Invoke(key[0]); }); RectTransform buttonRect = textButton.GetComponent <RectTransform>(); RectTransform component2 = transform.GetChild(i - 1).gameObject.GetComponent <RectTransform>(); RectTransform buttonHolder = Instantiate(component2, component2.parent, false); Destroy(buttonHolder.GetComponentInChildren <Button>().gameObject); buttonHolder.anchoredPosition -= new Vector2(0f, -10.5f); buttonRect.SetParent(buttonHolder, false); buttonRect.localPosition = Vector2.zero; buttonRect.localScale = Vector3.one; buttonRect.anchoredPosition = Vector2.zero; buttonRect.anchorMin = Vector2.zero; buttonRect.anchorMax = Vector3.one; buttonRect.offsetMin = Vector2.zero; buttonRect.offsetMax = Vector2.zero; } }
public void Awake() { // create buttons for letters and their respective symbols string[] keyArray = new string[] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m", "<-", "Space", /*"OK", "Cancel",*/ "Symbols", "Clear" }; string[] symbolArray = new string[] { "[", "]", "{", "}", "\\", "|", "-", "_", "=", "+", "", "", "", "", "", ";", ":", "'", "\"", "", ",", ".", "<", ">", "/", "?" }; for (int i = 0; i < keyArray.Length; i++) { TextMeshProButton textMeshProButton; if (i < keyArray.Length - 2) { textMeshProButton = CreateKeyboardButton(i); } else if (i == keyArray.Length - 2) { // Symbol button adapted from Cancel button textMeshProButton = CreateKeyboardButton(29); } else { // Clear button adapted from Delete button textMeshProButton = CreateKeyboardButton(26, true); } textMeshProButton.text.text = keyArray[i]; if (i < keyArray.Length - 4) { string key = keyArray[i]; string symbolKey = symbolArray[i]; _keyPairs[i].button = textMeshProButton; _keyPairs[i].key = key; _keyPairs[i].symKey = symbolArray[i]; textMeshProButton.button.onClick.AddListener(delegate() { if (_symbolModeActive) { if (!string.IsNullOrEmpty(symbolKey)) { TextKeyPressed?.Invoke(symbolKey[0]); } } else { TextKeyPressed?.Invoke(key[0]); } }); } else if (i == keyArray.Length - 4) { // Delete/Backspace button textMeshProButton.button.onClick.AddListener(delegate() { DeleteButtonPressed?.Invoke(); }); } else if (i == keyArray.Length - 3) { // Space key (textMeshProButton.button.transform as RectTransform).sizeDelta = new Vector2(10f, 0f); (textMeshProButton.button.transform as RectTransform).anchoredPosition += new Vector2(5f, 0f); textMeshProButton.button.onClick.AddListener(delegate() { TextKeyPressed?.Invoke(' '); }); } //else if (i == keyArray.Length - 3) //{ // // Search button // (textMeshProButton.transform as RectTransform).sizeDelta = new Vector2(4f, 2f); // (textMeshProButton.transform as RectTransform).anchoredPosition += new Vector2(26f, -1f); // textMeshProButton.text.fontSize = 6f; // _searchButton = textMeshProButton.button; // _searchButton.onClick.AddListener(delegate () // { // SearchButtonPressed?.Invoke(); // }); // SearchButtonInteractivity = false; //} else if (i == keyArray.Length - 2) { // Symbols button (textMeshProButton.transform as RectTransform).sizeDelta = new Vector2(10f, 0f); (textMeshProButton.transform as RectTransform).anchoredPosition += new Vector2(-2f, 0f); _symbolButton = textMeshProButton; _symbolButton.button.onClick.AddListener(delegate() { SetSymbolMode(!_symbolModeActive); }); } else { // Clear button (textMeshProButton.transform as RectTransform).sizeDelta = new Vector2(6f, 0); (textMeshProButton.transform as RectTransform).anchoredPosition += new Vector2(2f, -10f); textMeshProButton.button.onClick.AddListener(delegate() { ClearButtonPressed?.Invoke(); }); } } // destroy the existing "OK" button Destroy(this.transform.GetChild(28).gameObject); // create buttons for numbers and their respective symbols TextMeshProButton keyButtonPrefab = Resources.FindObjectsOfTypeAll <TextMeshProButton>().First(x => x.name == "KeyboardButton"); string[] numSymbolArray = new string[] { "!", "@", "#", "$", "%", "^", "&", "*", "(", ")" }; for (int i = 1; i <= 10; i++) { TextMeshProButton textButton = Instantiate(keyButtonPrefab); string key = i.ToString().Last().ToString(); string symbolKey = numSymbolArray[i - 1]; int index = (i % 10) + 26; _keyPairs[index].key = key; _keyPairs[index].symKey = symbolKey; _keyPairs[index].button = textButton; textButton.text.text = key; textButton.button.onClick.AddListener(delegate() { if (_symbolModeActive) { TextKeyPressed?.Invoke(symbolKey[0]); } else { TextKeyPressed?.Invoke(key[0]); } }); RectTransform buttonRect = textButton.GetComponent <RectTransform>(); RectTransform component2 = this.transform.GetChild(i - 1).gameObject.GetComponent <RectTransform>(); RectTransform buttonHolder = Instantiate(component2, component2.parent, false); Destroy(buttonHolder.GetComponentInChildren <Button>().gameObject); buttonHolder.anchoredPosition -= new Vector2(0f, -10.5f); buttonRect.SetParent(buttonHolder, false); buttonRect.localPosition = Vector2.zero; buttonRect.localScale = Vector3.one; buttonRect.anchoredPosition = Vector2.zero; buttonRect.anchorMin = Vector2.zero; buttonRect.anchorMax = Vector3.one; buttonRect.offsetMin = Vector2.zero; buttonRect.offsetMax = Vector2.zero; } name = "EnhancedSearchKeyboard"; }
protected override void CreateBottomButtons() { // Backspace TextMeshProButton button = CreateKeyboardButton(new Vector2(64f, YOffset + DefaultKeySize.y + 1f), new Vector2(15f, DefaultKeySize.y), 4f, this.transform, "Backspace"); button.text.text = "<-"; button.button.onClick.AddListener(InvokeDeleteButtonPressed); // Symbols _symbolButton = CreateKeyboardButton(new Vector2(0f, YOffset), new Vector2(15f, DefaultKeySize.y), 3.4f, this.transform, "Symbols"); _symbolButton.text.text = "Symbols"; _symbolButton.button.onClick.AddListener(() => SetSymbolMode(!_symbolModeActive)); // Space bar button = CreateKeyboardButton(new Vector2(16f, YOffset), new Vector2(32f, DefaultKeySize.y), this.transform, "Spacebar"); button.text.text = "Space"; button.button.onClick.AddListener(() => InvokeTextButtonPressed(' ')); // To Filter key _filterButton = CreateKeyboardButton(new Vector2(49f, YOffset), new Vector2(16f, DefaultKeySize.y), 3.2f, this.transform, "To Filter"); _filterButton.text.text = "To\nFilter"; Image filterIcon = new GameObject("FilterIcon").AddComponent <Image>(); filterIcon.sprite = BSUIUtilities.LoadSpriteFromResources("EnhancedSearchAndFilters.Assets.filter.png"); filterIcon.preserveAspect = true; var layout = filterIcon.gameObject.AddComponent <LayoutElement>(); layout.preferredHeight = 3.5f; layout.preferredWidth = 3.5f; filterIcon.transform.SetParent(_filterButton.text.transform.parent, false); (_filterButton.text.transform.parent as RectTransform).sizeDelta += new Vector2(0f, 1.5f); _filterButton.button.onClick.AddListener(delegate() { filterIcon.color = Color.white; InvokeFilterButtonPressed(); }); if (PluginConfig.DisableFilters) { _filterButton.button.interactable = false; filterIcon.color = Color.gray; } else { var handler = _filterButton.button.gameObject.AddComponent <EnterExitEventHandler>(); handler.PointerEntered += () => filterIcon.color = _filterButton.button.interactable ? Color.black : Color.gray; handler.PointerExited += () => filterIcon.color = _filterButton.button.interactable ? Color.white : Color.gray; BeatmapDetailsLoader.instance.CachingStarted += OnCachingStarted; if (BeatmapDetailsLoader.instance.SongsAreCached) { _filterButton.button.interactable = true; } else { _filterButton.button.interactable = false; filterIcon.color = Color.gray; BeatmapDetailsLoader.instance.CachingFinished += OnCachingFinished; } } // Clear button = CreateKeyboardButton(new Vector2(66f, YOffset), new Vector2(13f, DefaultKeySize.y), this.transform, "Clear"); button.text.text = "Clear"; button.button.onClick.AddListener(InvokeClearButtonPressed); }
public void Awake() { // clear all existing buttons int childCount = this.transform.childCount; for (int i = 0; i < childCount; ++i) { Destroy(this.transform.GetChild(i).gameObject); } _buttonPrefab = Resources.FindObjectsOfTypeAll <TextMeshProButton>().First(x => x.name == "KeyboardButton"); // work under the assumption that the box we can draw on is of size 80u x 60u TextMeshProButton button; string[] keyArray = new string[] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m" }; string[] symbolArray = new string[] { "[", "]", "{", "}", "\\", "|", "-", "_", "=", "+", "", "", "", "", "", ";", ":", "'", "\"", "", ",", ".", "<", ">", "/", "?" }; for (int i = 0; i < keyArray.Length; ++i) { Vector2 anchoredPos; if (i < 10) { anchoredPos = new Vector2(i * 8f, 29f); } else if (i < 19) { anchoredPos = new Vector2((i - 10) * 8f + 4f, 21f); } else { anchoredPos = new Vector2((i - 19) * 8f + 8f, 13f); } button = CreateKeyboardButton(anchoredPos); button.text.text = keyArray[i]; string key = keyArray[i]; string symbol = symbolArray[i]; _keyPairs[i].button = button; _keyPairs[i].key = key; _keyPairs[i].symKey = symbol; button.button.onClick.AddListener(delegate() { if (_symbolModeActive) { if (!string.IsNullOrEmpty(symbol)) { TextKeyPressed?.Invoke(symbol[0]); } } else { TextKeyPressed?.Invoke(key[0]); } }); } // Backspace button = CreateKeyboardButton(new Vector2(64f, 13f), new Vector2(15f, 7f)); button.text.text = "<-"; button.button.onClick.AddListener(delegate() { DeleteButtonPressed?.Invoke(); }); // Space bar button = CreateKeyboardButton(new Vector2(16f, 5f), new Vector2(47f, 7f)); button.text.text = "Space"; button.button.onClick.AddListener(delegate() { TextKeyPressed?.Invoke(' '); }); // Symbols _symbolButton = CreateKeyboardButton(new Vector2(0f, 5f), new Vector2(15f, 7f)); _symbolButton.text.text = "Symbols"; _symbolButton.text.fontSize = 3f; _symbolButton.button.onClick.AddListener(delegate() { SetSymbolMode(!_symbolModeActive); }); // Clear button = CreateKeyboardButton(new Vector2(64f, 5f), new Vector2(15f, 7f)); button.text.text = "Clear"; button.button.onClick.AddListener(delegate() { ClearButtonPressed?.Invoke(); }); // Numbers string[] numSymbolArray = new string[] { "!", "@", "#", "$", "%", "^", "&", "*", "(", ")" }; for (int i = 1; i <= 10; ++i) { button = CreateKeyboardButton(new Vector2((i - 1) * 8f, 37f)); string key = i.ToString().Last().ToString(); string symbol = numSymbolArray[i - 1]; int index = (i % 10) + 26; _keyPairs[index].key = key; _keyPairs[index].symKey = symbol; _keyPairs[index].button = button; button.text.text = key; button.button.onClick.AddListener(delegate() { if (_symbolModeActive) { TextKeyPressed?.Invoke(symbol[0]); } else { TextKeyPressed?.Invoke(key[0]); } }); } }