//-------------------------------------------------------------------------\\ // Copywrite: Underworld Entertainment // Script: input_box // Arguments: // X1 Y1 // Width Height // Max Characters Font // Text Col Text Fade Alpha // Text Type | Position ( Usually -4 to 0) //-------------------------------------------------------------------------\\ // Makes sure that any variables that have not yet been set are set to defaults. // This is so you do not have to initiate any variables in 'Create' for this to work. if !(variable_local_exists("text")) { text = ""; } if !(variable_local_exists("focus")) { focus = false; } if !(variable_local_exists("extra")) { extra = ""; } if !(variable_local_exists("e_count")) { e_count = fps /5 *6; } if !(variable_local_exists("pos")) { pos = 1; } if !(variable_local_exists("go_right")) { go_right = 0; } if !(variable_local_exists("go_left")) { go_left = 0; } if !(variable_local_exists("go_back")) { go_back = 0; } // Setting the variables user inputs that are needed for script. // Argument0 - X1(Text) // Argument1 - Y1(Text) // Argument2 - Width // Argument3 - Height // Argument4 - Max Amount Of Characters For Text // Argument5 - The Font For Text (-1 To Not Set Font) // Argument6 - The Color Of The Text Inside Box // Argument7 - The Alpha When Text Fades // Argument8 - The Type Of Text (1 = String | 2 = Letters | 3 = Digits | 4 = LettersDigits | 5/6 = Upper/Lowercase // Argument9 - The gap of the "|" in text. What this does is fix the position // of the "|" of where the text will be inputed. For different texts // you need a different number. Eg (Cosmic Sans Ms = -4) But then // (Niagra Engraved = 0). x1 = argument0; y1 = argument1; x2 = argument2; y2 = argument3; max_chr = argument4; font = argument5; color1 = argument6; tfalpha = argument7; type = argument8; xgap = argument9; // Checks if the player is clicking inside the rectangle. If so setting so he/she // can type, if not sets it so they cannot. You can replace 'textbox_mir with // your own 'mouse_in_rect'' script if you wish. mx = mouse_x; my = mouse_y; if (mouse_check_button_pressed(mb_left) && (mx>x1&&my>y1&&mx0) { pos -= 1; go_left = fps/5; } } // Checks if the player is pressing the right key on keyboard. If so trys to // set the "|" forward one character. Delays the repeat of this by 6 steps. if (keyboard_check_pressed(vk_right)&&focus) { if (pos<=string_length(text)) { pos += 1; go_right = fps/5; } } // Checks if the player is pressing the backspace key on keyboard. If so // trys to delete the character left of the "|". if (keyboard_check_pressed(vk_backspace)&&focus) { if (pos>0) { text = string_delete(text,pos-1,1); pos -= 1; go_back = fps/5; } } // Checks if the player is pressing the enter key on keyboard. If so will // set it so the player cannot type until re focused. (Done Typing) if (keyboard_check_pressed(vk_enter)&&focus) { focus = false; } // Checks if the player is holding down the left key on keyboard. If so // will try to move back the "|" one character every 3 steps. if (keyboard_check(vk_left)&&focus) { if (go_left <= 0) { if (pos>0) { pos -= 1; go_left = fps/10; } } } // Checks if the player is holding down the right key on keyboard. If so // will try to move the "|" forward one character every 3 steps. if (keyboard_check(vk_right)&&focus) { if (go_right <= 0) { if (pos<=string_length(text)) { pos += 1; go_right = fps/10; } } } // Checks if the player is holding down the backspace key on keyboard. // if so will try to delete 1 character behind the "|" every 6 steps. if (keyboard_check(vk_backspace)&&focus) { if (go_back <= 0) { if (pos>0) { text = string_delete(text,pos-1,1); pos -= 1; go_back = fps/10; } } } // Will count down the repeat variables every step. if (go_right > 0) { go_right -= 1; } if (go_left > 0) { go_left -= 1; } if (go_back > 0) { go_back -= 1; } // Checks if the player has typed anything. If so it will try to add it to the // text according to the input type (String/Letters/Digits/LettersDigits/Lowercase/Uppercase). if (focus) { if !(keyboard_string == "") { if (pos == 0) { pos = 1; } switch type { case 1: string1 = keyboard_string; break; case 2: string1 = string_letters(keyboard_string); break; case 3: string1 = string_digits(keyboard_string); break; case 4: string1 = string_lettersdigits(keyboard_string); break; case 5: string1 = string_lower(keyboard_string); break; case 6: string1 = string_upper(keyboard_string); break; } keyboard_string = ""; text = string_insert(string1,text,pos); pos += string_length(string1); } } // Checks to see if the text is longer than the max inputed. // If so will delete extra text and move "|" to end so player notices. l = string_length(text); if (l>max_chr) { text = string_delete(text,max_chr+1,l-max_chr); pos = max_chr+1; } // Counts down the "|"/"" variable. Once reaches zero it will change // to "|" if it is "" or "" if it is "|". Giving a flashing "|". e_count -= 1; if (e_count<=0) { e_count = fps/5*2; if (extra = "") { extra = "|"; } else { extra = ""; } } // This sets boundary boxes for each character in the text for later use // with clicking. text3 = text+" "; xx = x1+2; for (i=1;i<=string_length(text3);i+=1) { sca = string_char_at(text3,i); rectx1[i-1] = xx; recty1[i-1] = y1; rectx2[i-1] = xx+string_width(sca); recty2[i-1] = y1+string_height(sca); xx += string_width(sca); } // If the player clicks inside one of the characters bounding boxes it will // jump the "|" to the position in the text the mouse is closest to. (Before // Or After Character) if (mouse_check_button_pressed(mb_left)) { for (i=0;irectx1[i] && my>recty1[i] && mx