#pragma warning disable 1574 /// <summary> /// Get's input from the <see cref="Game.GetUserInput"/> method, and sets the returnValue to a parsed float. /// </summary> /// <param name="selectedItem">The menu item. If this is a list item, we will try to set the value of the index. If this /// is a regular <see cref="UIMenuItem"/> we will set the right badge of the item.</param> /// <param name="maxLetters">The maximum amount of letters the input box can recieve.</param> /// <param name="returnValue">The value from the user's input that will be returned as a <see cref="float"/>.</param> /// <param name="defaultText">The default text of the input box.</param> public void GetUserInput(UIMenuItem selectedItem, int maxLetters, ref float returnValue, string defaultText = "") { var input = Game.GetUserInput(defaultText, maxLetters); float value; if (!float.TryParse(input, out value)) { return; } returnValue = value; if (selectedItem.GetType() == typeof(CustomListItem)) { var uiListItem = selectedItem as CustomListItem; try { if (uiListItem != null) { uiListItem.Index = uiListItem.ItemToIndex(value); } } catch { UI.ShowSubtitle("Failed to set value."); } return; } selectedItem.SetRightLabel($"{returnValue}"); }
//This function is called every time a item is selected on the edit menu public static void EditMenuItemSelected(UIMenu Sender, UIMenuItem SelectedItem, int Index) { //Make sure it's not one of the list items being selected if (SelectedItem.GetType() == typeof(UIMenuItem)) { //Check the position (the same as it's index) of the item to see which one it is and trigger the appropriate event if (Sender.MenuItems.FindIndex(item => item == SelectedItem) == 3) { BaseScript.TriggerServerEvent("SimpleText:Server:MoveText", EditID, Game.Player.Character.Position); } if (Sender.MenuItems.FindIndex(item => item == SelectedItem) == 4) { Utils.OpenKeyboard((bool Success, string InputText) => { if (Success) { BaseScript.TriggerServerEvent("SimpleText:Server:EditText", EditID, InputText, ((UIMenuListItem)Sender.MenuItems[0]).Index, ((UIMenuListItem)Sender.MenuItems[1]).Index, ((UIMenuListItem)Sender.MenuItems[2]).Index); } else { Main.ShowNotification("~r~Something went wrong... ~s~Remember to press ~b~ENTER ~s~when you are done writing."); } }, Main.ActiveText[EditID].Text); } else if (Sender.MenuItems.FindIndex(item => item == SelectedItem) == 5) { BaseScript.TriggerServerEvent("SimpleText:Server:DeleteText", EditID); EditMenu.Visible = false; ListMenu.Visible = true; } } }
public static void CreateMenuItemSelected(UIMenu Sender, UIMenuItem SelectedItem, int Index) { if (SelectedItem.GetType() == typeof(UIMenuItem)) { //Open the keyboard and provide a callback (a action in this function) that will be called when the user has finished typing Utils.OpenKeyboard((bool Success, string InputText) => { if (Success) { BaseScript.TriggerServerEvent("SimpleText:Server:CreateText", InputText, Game.Player.Character.Position, ((UIMenuListItem)Sender.MenuItems[0]).Index, ((UIMenuListItem)Sender.MenuItems[1]).Index, ((UIMenuListItem)Sender.MenuItems[2]).Index); } else { Main.ShowNotification("~r~Something went wrong... ~s~Remember to press ~b~ENTER ~s~when you are done writing."); } }); } }