From 33c3dbb5c6622bba6281225a79c8b44ffcd231ca Mon Sep 17 00:00:00 2001 From: Harry Min Khant <118270468+harrymkt@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:23:59 +0630 Subject: [PATCH] Include Script Modifications (#79) Audio Form modifications: * You can use `audioform_keyboard_echo` property to save in your game data file, and then retrieve it when the game loads the data etc. * Once an input field is popped out, You can use the F2 key to change between echo modes. The changed echo mode will be spoken out loud, as well as setting `audioform_keyboard_echo` property to match with the changed echo (fixes #77). * The `reset` method now takes a new parameter, true by default, which resets the form's echo mode to default. This is useful to retrieve the value of the `audioform_keyboard_echo` property. * The go to line functionality can now be used on non multiline input fields as well. In non multiline fields, the line number field will be invisible (references #62). * Added a new property in `control` class called `enable_go_to_index`, which is true by default, which allows setting to enable or disable the go to line functionality. This is natively used in `go_to_index` class to disable the ability to promt the dialog on go to line dialog over and over. * Added a new method that allows you to toggle the go to line functionality. `bool set_enable_go_to_index(int control_index, bool enabled);` Sound Pool modifications: * Added a new parameter in `update_listener_3d` function called `refresh_y_is_elevation` (bool) which toggles whether the sound pool should refresh the global `sound_pool_default_y_is_elevation` property. This makes it possible to constantly change the global property for the sound elevation. Token Gen modifications: * A new parameter has been added, `mode`, which you can choose the mode to generate, see `token_gen_flag` enum constants for possible modes. Default mode is `token_gen_flag_all` --- release/include/form.nvgt | 68 +++++++++++++++++++++++++++------ release/include/sound_pool.nvgt | 37 +++++++++--------- release/include/token_gen.nvgt | 21 +++++++++- 3 files changed, 94 insertions(+), 32 deletions(-) diff --git a/release/include/form.nvgt b/release/include/form.nvgt index 6592dc07..7bb51edf 100644 --- a/release/include/form.nvgt +++ b/release/include/form.nvgt @@ -107,7 +107,7 @@ funcdef int on_control_event_callback(audio_form@ f, int c, control_event_type e //can make this a member of the audio form class as soon as even one person suggests seriously wanting to change on a form by form basis I guess bool audioform_input_disable_ralt = true; - +int audioform_keyboard_echo = textflag_characters; //main window class class audio_form { bool active; @@ -1065,6 +1065,23 @@ class audio_form { c_form[control_index].visible = visible; return true; } + bool set_enable_go_to_index(int control_index, bool enabled) { + form_error = 0; + if (!active) { + form_error = form_error_no_window; + return false; + } + if ((control_index < 0) || (control_index > c_form.length() - 1)) { + form_error = form_error_invalid_control; + return false; + } + if (!c_form[control_index].active) { + form_error = form_error_invalid_control; + return false; + } + c_form[control_index].enable_go_to_index = enabled; + return true; + } bool set_disallowed_chars(int control_index, string chars, bool use_only_disallowed_chars = false, string char_disallowed_description = "") { form_error = 0; if (!active) { @@ -1929,8 +1946,9 @@ class audio_form { @ui_speech = @handle; return true; } - void reset() { + void reset(bool reset_to_default_keyboard_echo = true) { form_error = 0; + if (reset_to_default_keyboard_echo) default_echo_flag = audioform_keyboard_echo; active = false; control_focus = -1; control_counter = -1; @@ -2005,8 +2023,8 @@ class audio_form { return true; } private void check(int tab_index) { - if (c_form[tab_index].multiline or c_form[tab_index].type == ct_list) { - if (keyboard_modifiers & KEYMOD_CTRL != 0 and key_pressed(KEY_G)) + if (c_form[tab_index].type == ct_input or c_form[tab_index].type == ct_list) { + if (keyboard_modifiers & KEYMOD_CTRL != 0 and key_pressed(KEY_G) and c_form[tab_index].enable_go_to_index) go_to_index(this, tab_index); } if ((c_form[tab_index].type == ct_input && c_form[tab_index].multiline && c_form[tab_index].text != "") or c_form[tab_index].type == ct_list) { @@ -2020,6 +2038,15 @@ class audio_form { search_for(this, tab_index); } } + if (c_form[tab_index].type == ct_input) { + if (key_pressed(KEY_F2)) { + int dir = 1; + if (keyboard_modifiers & KEYMOD_SHIFT != 0) dir = -1; + audioform_keyboard_echo = audioform_change_keyboard_echo(audioform_keyboard_echo, dir); + this.set_default_keyboard_echo(audioform_keyboard_echo); + speak(audioform_keyboard_echo_string(audioform_keyboard_echo)); + } + } if (@utility_form == null) c_form[tab_index].check(this, tab_index); } @@ -2197,7 +2224,7 @@ class audio_form { //internal properties bool subform = false; private int speech_output; - int default_echo_flag = textflag_characters; + int default_echo_flag = audioform_keyboard_echo; private control[] c_form; private int form_error; private int control_counter; @@ -2266,6 +2293,7 @@ class control { string[] disallowed_chars; bool use_only_disallowed_chars; string char_disallowed_description; + bool enable_go_to_index; //This is mostly used on go to index field where it prevents the key from pressing again. control() { progress_time.restart(); progress_time.pause(); @@ -2316,6 +2344,7 @@ class control { this.disallowed_chars.resize(0); this.use_only_disallowed_chars = false; this.char_disallowed_description = ""; + this.enable_go_to_index = true; } void focus(bool interrupt_previous_speech, bool separate_attributes, bool silent = false) { if (silent == true) { @@ -2709,7 +2738,7 @@ class control { return col; } bool set_line(int line, int col = 1, bool silent = false) { - if (type != ct_input or !multiline) return false; + if (type != ct_input) return false; if (col < 1) col = 1; int max_col = col; int pos = 0; @@ -3621,22 +3650,26 @@ class go_to_index : utility_form { int type = parent.get_control_type(control_index); if (type < 0) return; this.control_index = control_index; - if (!parent.is_multiline(control_index) and type != ct_list) { - if (type == ct_input) - speak("not a multiline text field"); + if (type != ct_input and type != ct_list) return; - } int current = type == ct_list ? parent.get_list_position(control_index) + 1 : parent.get_line_number(control_index); f.create_window((type == ct_list ? "go to item" : "go to line"), false, true); f_index = f.create_input_box((type == ct_list ? "item number" : "line number"), current, "", 6); + f.set_enable_go_to_index(f_index, false); f.select_text(f_index, 0, -1); + int index_to_focus = f_index; if (type == ct_input) { f_col = f.create_input_box("line column", parent.get_line_column(control_index), "", 6); f.select_text(f_col, 0, -1); + f.set_enable_go_to_index(f_col, false); + if (!parent.is_multiline(control_index)) { + index_to_focus = f_col; + f.set_state(f_index, false, false); //Set to hidden because not multiline input. + } } f_ok = f.create_button("ok", true); f_cancel = f.create_button("cancel", false, true); - f.focus(f_index); + f.focus(index_to_focus); @parent.utility_form = this; } void monitor() { @@ -3771,3 +3804,16 @@ shared int bgt_string_contains(const string& in str, const string& in search, in } return c == occurance ? pos : -1; } +//Wrapper functions for keyboard echo changing. +shared uint audioform_change_keyboard_echo(int keyboard_echo, int dir = 1) { + keyboard_echo += dir; + if (keyboard_echo < textflag_none) keyboard_echo = textflag_characters_words; + else if (keyboard_echo > textflag_characters_words) keyboard_echo = textflag_none; + return keyboard_echo; +} +shared string audioform_keyboard_echo_string(int keyboard_echo) { + if (keyboard_echo == textflag_characters) return "characters"; + else if (keyboard_echo == textflag_words) return "words"; + else if (keyboard_echo == textflag_characters_words) return "characters and words"; + else return "none"; +} diff --git a/release/include/sound_pool.nvgt b/release/include/sound_pool.nvgt index cd4d2648..b7b87a22 100644 --- a/release/include/sound_pool.nvgt +++ b/release/include/sound_pool.nvgt @@ -6,7 +6,7 @@ sound Pool Class This class provides a convenient way of managing sounds in an environment, both with 1 and 2 dimensions. It uses the functions found in sound_positioning.bgt to do the actual sound adjustments, so modifying these functions will affect the entire system. The sound_pool_item class holds all the information necessary for one single sound in the game world. Note that you should not make instances of the sound_pool_item class directly but always use the methods and properties provided in the sound_pool class. */ #include "rotation.nvgt" -bool sound_pool_default_y_elevation=false; +bool sound_pool_default_y_elevation = false; class sound_pool_item { sound@ handle; string filename; @@ -92,7 +92,7 @@ class sound_pool_item { return; } if (total_distance <= max_distance and handle.active == false) { - handle.load(filename, @packfile != null? @packfile : @sound_default_pack); + handle.load(filename, @packfile != null ? @packfile : @sound_default_pack); if (handle.active == true) { if (start_offset > 0) handle.seek(start_offset); @@ -157,7 +157,7 @@ class sound_pool_item { while (rotation < 0) rotation += 2 * pi; //if(theta!=0) //speak("old_listener="+listener_x+", "+listener_y+". new_listener="+r_listener.x+", "+r_listener.y+". pivit="+pivit.x+", "+pivit.y); - handle.set_position(r_listener.x, y_is_elevation==false?r_listener.y:listener_z, y_is_elevation==false?listener_z:r_listener.y, true_x, y_is_elevation==false?true_y:true_z, y_is_elevation==false?true_z:true_y, rotation, pan_step, volume_step); + handle.set_position(r_listener.x, y_is_elevation == false ? r_listener.y : listener_z, y_is_elevation == false ? listener_z : r_listener.y, true_x, y_is_elevation == false ? true_y : true_z, y_is_elevation == false ? true_z : true_y, rotation, pan_step, volume_step); /*if(occlude) { int[] factors=occlusion_factors(r_listener.x, r_listener.y, listener_z, true_x, true_y, true_z); @@ -243,7 +243,7 @@ class sound_pool_item { This is the actual sound_pool class. For more information on how to use the class, please see the BGT documentation. */ class sound_pool { - bool y_is_elevation=sound_pool_default_y_elevation; + bool y_is_elevation = sound_pool_default_y_elevation; int max_distance; float pan_step; float volume_step; @@ -273,7 +273,7 @@ class sound_pool { int slot = reserve_slot(); if (slot == -1) return -1; - items[slot].y_is_elevation=y_is_elevation; + items[slot].y_is_elevation = y_is_elevation; items[slot].filename = filename; items[slot].x = sound_x; items[slot].y = sound_y; @@ -319,23 +319,21 @@ class sound_pool { items[slot].reset(); return -2; } else { - if (dimension > 0){ + if (dimension > 0) last_listener_x = listener_x; - } - if (dimension > 1){ + if (dimension > 1) { last_listener_y = listener_y; last_listener_rotation = rotation; items[slot].update(listener_x, listener_y, (dimension == 2 ? 0 : listener_z), rotation, max_distance); } - if (dimension > 2){ + if (dimension > 2) last_listener_z = listener_z; - } if (slot > highest_slot) highest_slot = slot; return slot; } } - items[slot].handle.load(items[slot].filename, @items[slot].packfile != null? @items[slot].packfile : @sound_default_pack); + items[slot].handle.load(items[slot].filename, @items[slot].packfile != null ? @items[slot].packfile : @sound_default_pack); if (items[slot].handle.active == false) { items[slot].reset(); return -1; @@ -348,16 +346,14 @@ class sound_pool { items[slot].handle.set_volume(start_volume); items[slot].handle.set_pitch(start_pitch); } - if (dimension > 0){ + if (dimension > 0) last_listener_x = listener_x; -} - if (dimension > 1){ + if (dimension > 1) { last_listener_y = listener_y; last_listener_rotation = rotation; -} - if (dimension > 2){ + } + if (dimension > 2) last_listener_z = listener_z; -} if (filename != "") { items[slot].update(listener_x, listener_y, listener_z, rotation, max_distance); if (!start_playing) @@ -550,15 +546,18 @@ class sound_pool { void update_listener_2d(float listener_x, float listener_y, double rotation = 0.0) { update_listener_3d(listener_x, listener_y, 0, rotation); } - void update_listener_3d(float listener_x, float listener_y, float listener_z, double rotation = 0.0) { + void update_listener_3d(float listener_x, float listener_y, float listener_z, double rotation = 0.0, bool refresh_y_is_elevation = true) { if (items.length() == 0) return; last_listener_x = listener_x; last_listener_y = listener_y; last_listener_z = listener_z; last_listener_rotation = rotation; - for (uint i = 0; i <= highest_slot; i++) + if (refresh_y_is_elevation) this.y_is_elevation = sound_pool_default_y_elevation; + for (uint i = 0; i <= highest_slot; i++) { + if (refresh_y_is_elevation) items[i].y_is_elevation = this.y_is_elevation; items[i].update(listener_x, listener_y, listener_z, rotation, max_distance); + } } bool set_sound_owner(int slot, string owner, int priority = 0) { diff --git a/release/include/token_gen.nvgt b/release/include/token_gen.nvgt index 1b49a520..f6ef8b92 100644 --- a/release/include/token_gen.nvgt +++ b/release/include/token_gen.nvgt @@ -9,9 +9,26 @@ * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ +//Possible token mode. +enum token_gen_flag { + token_gen_flag_all = 0, + token_gen_flag_characters, + token_gen_flag_numbers, + token_gen_flag_symbols, + token_gen_flag_numbers_symbols, + token_gen_flag_characters_symbols +} +string generate_token(int token_length, int mode = token_gen_flag_all) { + string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + string numbers = "1234567890"; + string symbols = "`~!@#$%^&*()_+=-[]{}/.,;:|?><"; + string token_sims = chars + numbers + symbols; + if (mode == token_gen_flag_characters) token_sims = chars; + else if (mode == token_gen_flag_numbers) token_sims = numbers; + else if (mode == token_gen_flag_symbols) token_sims = symbols; + else if (mode == token_gen_flag_numbers_symbols) token_sims = numbers + symbols; + else if (mode == token_gen_flag_characters_symbols) token_sims = chars + symbols; -string generate_token(int token_length) { - string token_sims = "1234567890abcdefthijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; string final_token; for (uint i = 0; i < token_length; i++) final_token += token_sims[random(0, token_sims.length() - 1)];